111066Srafael.vanoni@sun.com /* 211066Srafael.vanoni@sun.com * CDDL HEADER START 311066Srafael.vanoni@sun.com * 411066Srafael.vanoni@sun.com * The contents of this file are subject to the terms of the 511066Srafael.vanoni@sun.com * Common Development and Distribution License (the "License"). 611066Srafael.vanoni@sun.com * You may not use this file except in compliance with the License. 711066Srafael.vanoni@sun.com * 811066Srafael.vanoni@sun.com * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 911066Srafael.vanoni@sun.com * or http://www.opensolaris.org/os/licensing. 1011066Srafael.vanoni@sun.com * See the License for the specific language governing permissions 1111066Srafael.vanoni@sun.com * and limitations under the License. 1211066Srafael.vanoni@sun.com * 1311066Srafael.vanoni@sun.com * When distributing Covered Code, include this CDDL HEADER in each 1411066Srafael.vanoni@sun.com * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 1511066Srafael.vanoni@sun.com * If applicable, add the following below this CDDL HEADER, with the 1611066Srafael.vanoni@sun.com * fields enclosed by brackets "[]" replaced with your own identifying 1711066Srafael.vanoni@sun.com * information: Portions Copyright [yyyy] [name of copyright owner] 1811066Srafael.vanoni@sun.com * 1911066Srafael.vanoni@sun.com * CDDL HEADER END 2011066Srafael.vanoni@sun.com */ 2111066Srafael.vanoni@sun.com 2211066Srafael.vanoni@sun.com /* 23*12233Srafael.vanoni@oracle.com * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. 2411066Srafael.vanoni@sun.com */ 2511066Srafael.vanoni@sun.com 2611066Srafael.vanoni@sun.com #ifndef _SYS_CLOCK_IMPL_H 2711066Srafael.vanoni@sun.com #define _SYS_CLOCK_IMPL_H 2811066Srafael.vanoni@sun.com 2911066Srafael.vanoni@sun.com #ifdef __cplusplus 3011066Srafael.vanoni@sun.com extern "C" { 3111066Srafael.vanoni@sun.com #endif 3211066Srafael.vanoni@sun.com 3311066Srafael.vanoni@sun.com #if (defined(_KERNEL) || defined(_KMEMUSER)) 3411066Srafael.vanoni@sun.com #include <sys/types.h> 3511066Srafael.vanoni@sun.com #include <sys/cpuvar.h> 3611066Srafael.vanoni@sun.com #include <sys/cyclic.h> 3711066Srafael.vanoni@sun.com #include <sys/time.h> 3811066Srafael.vanoni@sun.com 3911066Srafael.vanoni@sun.com /* 4011066Srafael.vanoni@sun.com * Default clock rate in Hz. 4111066Srafael.vanoni@sun.com */ 4211151Srafael.vanoni@sun.com #define HZ_DEFAULT (100) 4311066Srafael.vanoni@sun.com 4411066Srafael.vanoni@sun.com /* 4511066Srafael.vanoni@sun.com * Thresholds over which we switch between event and cyclic driven lbolt. The 4611066Srafael.vanoni@sun.com * current default values were derived experimentally and will keep the 4711066Srafael.vanoni@sun.com * system on event driven mode when idle and respond to activity around the 4811066Srafael.vanoni@sun.com * lbolt DDI functions by switching to cyclic mode. 4911066Srafael.vanoni@sun.com */ 5011066Srafael.vanoni@sun.com #define LBOLT_THRESH_CALLS (75) 5111066Srafael.vanoni@sun.com #define LBOLT_THRESH_INTERVAL (1) 5211066Srafael.vanoni@sun.com 5311066Srafael.vanoni@sun.com /* 5411066Srafael.vanoni@sun.com * Both lbolt_cpu_t and lbolt_info_t are cache line sized and aligned, 5511066Srafael.vanoni@sun.com * please take that in consideration if modifying these. 5611066Srafael.vanoni@sun.com */ 5711066Srafael.vanoni@sun.com typedef struct lbolt_cpu { 5811066Srafael.vanoni@sun.com int64_t lbc_counter; /* number of calls to the DDI lbolt routines */ 5911066Srafael.vanoni@sun.com int64_t lbc_cnt_start; /* beggining of the cnt interval (in ticks) */ 6011066Srafael.vanoni@sun.com char lbc_pad[CPU_CACHE_COHERENCE_SIZE - (2 * sizeof (int64_t))]; 6111066Srafael.vanoni@sun.com } lbolt_cpu_t; 6211066Srafael.vanoni@sun.com 6311066Srafael.vanoni@sun.com typedef struct lbolt_info { 6411151Srafael.vanoni@sun.com union { 6511151Srafael.vanoni@sun.com cyclic_id_t lbi_cyclic_id; /* lbolt's cyclic id */ 6611151Srafael.vanoni@sun.com int64_t lbi_id_pad; /* 64bit padding */ 6711151Srafael.vanoni@sun.com } id; 6811066Srafael.vanoni@sun.com int64_t lbi_thresh_calls; /* max calls per interval */ 6911066Srafael.vanoni@sun.com int64_t lbi_thresh_interval; /* interval window for the # of calls */ 70*12233Srafael.vanoni@oracle.com int64_t lbi_debug_ts; /* last time we dropped into kmdb */ 71*12233Srafael.vanoni@oracle.com int64_t lbi_debug_time; /* time spent in the debugger */ 72*12233Srafael.vanoni@oracle.com int64_t lbi_internal; /* lbolt source when on cyclic mode */ 7311066Srafael.vanoni@sun.com uint32_t lbi_token; /* synchronize cyclic mode switch */ 7411066Srafael.vanoni@sun.com boolean_t lbi_cyc_deactivate; /* lbolt_cyclic self deactivation */ 7511066Srafael.vanoni@sun.com int64_t lbi_cyc_deac_start; /* deactivation interval */ 7611066Srafael.vanoni@sun.com } lbolt_info_t; 7711066Srafael.vanoni@sun.com 7811226Srafael.vanoni@sun.com extern int64_t lbolt_bootstrap(void); 7911066Srafael.vanoni@sun.com extern int64_t lbolt_event_driven(void); 8011066Srafael.vanoni@sun.com extern int64_t lbolt_cyclic_driven(void); 8111066Srafael.vanoni@sun.com extern int64_t (*lbolt_hybrid)(void); 8211066Srafael.vanoni@sun.com extern uint_t lbolt_ev_to_cyclic(caddr_t, caddr_t); 8311066Srafael.vanoni@sun.com 8411066Srafael.vanoni@sun.com extern void lbolt_softint_add(void); 8511066Srafael.vanoni@sun.com extern void lbolt_softint_post(void); 8611066Srafael.vanoni@sun.com 8711066Srafael.vanoni@sun.com extern void lbolt_debug_entry(void); 8811066Srafael.vanoni@sun.com extern void lbolt_debug_return(void); 8911066Srafael.vanoni@sun.com 9011066Srafael.vanoni@sun.com extern lbolt_info_t *lb_info; 9111066Srafael.vanoni@sun.com 9211066Srafael.vanoni@sun.com /* 9311099Srafael.vanoni@sun.com * LBOLT_WAITFREE{,64} provide a non-waiting version of lbolt. 9411066Srafael.vanoni@sun.com */ 9511099Srafael.vanoni@sun.com #define LBOLT_WAITFREE64 \ 9611226Srafael.vanoni@sun.com (lbolt_hybrid == lbolt_bootstrap ? 0 : \ 9711066Srafael.vanoni@sun.com (lbolt_hybrid == lbolt_event_driven ? \ 9811066Srafael.vanoni@sun.com ((gethrtime_waitfree()/nsec_per_tick) - \ 9911066Srafael.vanoni@sun.com lb_info->lbi_debug_time) : \ 10011226Srafael.vanoni@sun.com (lb_info->lbi_internal - lb_info->lbi_debug_time))) 10111066Srafael.vanoni@sun.com 10211099Srafael.vanoni@sun.com #define LBOLT_WAITFREE (clock_t)LBOLT_WAITFREE64 10311066Srafael.vanoni@sun.com 10411066Srafael.vanoni@sun.com /* 10511099Srafael.vanoni@sun.com * LBOLT_FASTPATH{,64} should *only* be used where the cost of calling the 10611099Srafael.vanoni@sun.com * DDI lbolt routines affects performance. This is currently only used by 10711099Srafael.vanoni@sun.com * the TCP/IP code and will be removed once it's no longer required. 10811099Srafael.vanoni@sun.com */ 10911099Srafael.vanoni@sun.com #define LBOLT_FASTPATH64 \ 11011226Srafael.vanoni@sun.com (lbolt_hybrid == lbolt_cyclic_driven ? \ 11111226Srafael.vanoni@sun.com (lb_info->lbi_internal - lb_info->lbi_debug_time) : \ 112*12233Srafael.vanoni@oracle.com lbolt_event_driven()) 11311099Srafael.vanoni@sun.com 11411099Srafael.vanoni@sun.com #define LBOLT_FASTPATH (clock_t)LBOLT_FASTPATH64 11511099Srafael.vanoni@sun.com 11611099Srafael.vanoni@sun.com /* 11711099Srafael.vanoni@sun.com * LBOLT_NO_ACCOUNT{,64} is used by lbolt consumers who fire at a periodic 11811099Srafael.vanoni@sun.com * rate, such as clock(), for which the lbolt usage statistics are not updated. 11911099Srafael.vanoni@sun.com * This is especially important for consumers whose rate may be modified by 12011066Srafael.vanoni@sun.com * the user, resulting in an unaccounted for increase in activity around the 12111066Srafael.vanoni@sun.com * lbolt routines that could cause a mode switch. 12211066Srafael.vanoni@sun.com */ 12311099Srafael.vanoni@sun.com #define LBOLT_NO_ACCOUNT64 \ 12411226Srafael.vanoni@sun.com (lbolt_hybrid == lbolt_bootstrap ? 0 : \ 12511066Srafael.vanoni@sun.com (lbolt_hybrid == lbolt_event_driven ? \ 12611066Srafael.vanoni@sun.com ((gethrtime()/nsec_per_tick) - lb_info->lbi_debug_time) : \ 12711226Srafael.vanoni@sun.com (lb_info->lbi_internal - lb_info->lbi_debug_time))) 12811066Srafael.vanoni@sun.com 12911099Srafael.vanoni@sun.com #define LBOLT_NO_ACCOUNT (clock_t)LBOLT_NO_ACCOUNT64 13011099Srafael.vanoni@sun.com 13111066Srafael.vanoni@sun.com #endif /* _KERNEL || _KMEMUSER */ 13211066Srafael.vanoni@sun.com 13311066Srafael.vanoni@sun.com #ifdef __cplusplus 13411066Srafael.vanoni@sun.com } 13511066Srafael.vanoni@sun.com #endif 13611066Srafael.vanoni@sun.com 13711066Srafael.vanoni@sun.com #endif /* _SYS_CLOCK_IMPL_H */ 138