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 /* 2311066Srafael.vanoni@sun.com * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 2411066Srafael.vanoni@sun.com * Use is subject to license terms. 2511066Srafael.vanoni@sun.com */ 2611066Srafael.vanoni@sun.com 2711066Srafael.vanoni@sun.com #ifndef _SYS_CLOCK_IMPL_H 2811066Srafael.vanoni@sun.com #define _SYS_CLOCK_IMPL_H 2911066Srafael.vanoni@sun.com 3011066Srafael.vanoni@sun.com #ifdef __cplusplus 3111066Srafael.vanoni@sun.com extern "C" { 3211066Srafael.vanoni@sun.com #endif 3311066Srafael.vanoni@sun.com 3411066Srafael.vanoni@sun.com #if (defined(_KERNEL) || defined(_KMEMUSER)) 3511066Srafael.vanoni@sun.com #include <sys/types.h> 3611066Srafael.vanoni@sun.com #include <sys/cpuvar.h> 3711066Srafael.vanoni@sun.com #include <sys/cyclic.h> 3811066Srafael.vanoni@sun.com #include <sys/time.h> 3911066Srafael.vanoni@sun.com 4011066Srafael.vanoni@sun.com /* 4111066Srafael.vanoni@sun.com * Default clock rate in Hz. 4211066Srafael.vanoni@sun.com */ 4311066Srafael.vanoni@sun.com #define HZ_DEFAULT 100 4411066Srafael.vanoni@sun.com 4511066Srafael.vanoni@sun.com /* 4611066Srafael.vanoni@sun.com * Thresholds over which we switch between event and cyclic driven lbolt. The 4711066Srafael.vanoni@sun.com * current default values were derived experimentally and will keep the 4811066Srafael.vanoni@sun.com * system on event driven mode when idle and respond to activity around the 4911066Srafael.vanoni@sun.com * lbolt DDI functions by switching to cyclic mode. 5011066Srafael.vanoni@sun.com */ 5111066Srafael.vanoni@sun.com #define LBOLT_THRESH_CALLS (75) 5211066Srafael.vanoni@sun.com #define LBOLT_THRESH_INTERVAL (1) 5311066Srafael.vanoni@sun.com 5411066Srafael.vanoni@sun.com /* 5511066Srafael.vanoni@sun.com * Both lbolt_cpu_t and lbolt_info_t are cache line sized and aligned, 5611066Srafael.vanoni@sun.com * please take that in consideration if modifying these. 5711066Srafael.vanoni@sun.com */ 5811066Srafael.vanoni@sun.com typedef struct lbolt_cpu { 5911066Srafael.vanoni@sun.com int64_t lbc_counter; /* number of calls to the DDI lbolt routines */ 6011066Srafael.vanoni@sun.com int64_t lbc_cnt_start; /* beggining of the cnt interval (in ticks) */ 6111066Srafael.vanoni@sun.com char lbc_pad[CPU_CACHE_COHERENCE_SIZE - (2 * sizeof (int64_t))]; 6211066Srafael.vanoni@sun.com } lbolt_cpu_t; 6311066Srafael.vanoni@sun.com 6411066Srafael.vanoni@sun.com typedef struct lbolt_info { 6511066Srafael.vanoni@sun.com cyclic_id_t lbi_cyclic_id; /* lbolt's cyclic id */ 6611066Srafael.vanoni@sun.com int64_t lbi_internal; /* lbolt source when on cyclic mode */ 6711066Srafael.vanoni@sun.com int64_t lbi_debug_time; /* time spent in the debugger */ 6811066Srafael.vanoni@sun.com int64_t lbi_debug_ts; /* last time we dropped into kmdb */ 6911066Srafael.vanoni@sun.com int64_t lbi_thresh_calls; /* max calls per interval */ 7011066Srafael.vanoni@sun.com int64_t lbi_thresh_interval; /* interval window for the # of calls */ 7111066Srafael.vanoni@sun.com uint32_t lbi_token; /* synchronize cyclic mode switch */ 7211066Srafael.vanoni@sun.com boolean_t lbi_cyc_deactivate; /* lbolt_cyclic self deactivation */ 7311066Srafael.vanoni@sun.com int64_t lbi_cyc_deac_start; /* deactivation interval */ 7411066Srafael.vanoni@sun.com } lbolt_info_t; 7511066Srafael.vanoni@sun.com 7611066Srafael.vanoni@sun.com extern int64_t lbolt_event_driven(void); 7711066Srafael.vanoni@sun.com extern int64_t lbolt_cyclic_driven(void); 7811066Srafael.vanoni@sun.com extern int64_t (*lbolt_hybrid)(void); 7911066Srafael.vanoni@sun.com extern uint_t lbolt_ev_to_cyclic(caddr_t, caddr_t); 8011066Srafael.vanoni@sun.com 8111066Srafael.vanoni@sun.com extern void lbolt_softint_add(void); 8211066Srafael.vanoni@sun.com extern void lbolt_softint_post(void); 8311066Srafael.vanoni@sun.com 8411066Srafael.vanoni@sun.com extern void lbolt_debug_entry(void); 8511066Srafael.vanoni@sun.com extern void lbolt_debug_return(void); 8611066Srafael.vanoni@sun.com 8711066Srafael.vanoni@sun.com extern lbolt_info_t *lb_info; 8811066Srafael.vanoni@sun.com 8911066Srafael.vanoni@sun.com /* 90*11099Srafael.vanoni@sun.com * LBOLT_WAITFREE{,64} provide a non-waiting version of lbolt. 9111066Srafael.vanoni@sun.com */ 92*11099Srafael.vanoni@sun.com #define LBOLT_WAITFREE64 \ 9311066Srafael.vanoni@sun.com (lbolt_hybrid == lbolt_event_driven ? \ 9411066Srafael.vanoni@sun.com ((gethrtime_waitfree()/nsec_per_tick) - \ 9511066Srafael.vanoni@sun.com lb_info->lbi_debug_time) : \ 9611066Srafael.vanoni@sun.com (lb_info->lbi_internal - lb_info->lbi_debug_time)) 9711066Srafael.vanoni@sun.com 98*11099Srafael.vanoni@sun.com #define LBOLT_WAITFREE (clock_t)LBOLT_WAITFREE64 9911066Srafael.vanoni@sun.com 10011066Srafael.vanoni@sun.com /* 101*11099Srafael.vanoni@sun.com * LBOLT_FASTPATH{,64} should *only* be used where the cost of calling the 102*11099Srafael.vanoni@sun.com * DDI lbolt routines affects performance. This is currently only used by 103*11099Srafael.vanoni@sun.com * the TCP/IP code and will be removed once it's no longer required. 104*11099Srafael.vanoni@sun.com */ 105*11099Srafael.vanoni@sun.com #define LBOLT_FASTPATH64 \ 106*11099Srafael.vanoni@sun.com (lbolt_hybrid == lbolt_event_driven ? ddi_get_lbolt64() : \ 107*11099Srafael.vanoni@sun.com (lb_info->lbi_internal - lb_info->lbi_debug_time)) 108*11099Srafael.vanoni@sun.com 109*11099Srafael.vanoni@sun.com #define LBOLT_FASTPATH (clock_t)LBOLT_FASTPATH64 110*11099Srafael.vanoni@sun.com 111*11099Srafael.vanoni@sun.com /* 112*11099Srafael.vanoni@sun.com * LBOLT_NO_ACCOUNT{,64} is used by lbolt consumers who fire at a periodic 113*11099Srafael.vanoni@sun.com * rate, such as clock(), for which the lbolt usage statistics are not updated. 114*11099Srafael.vanoni@sun.com * This is especially important for consumers whose rate may be modified by 11511066Srafael.vanoni@sun.com * the user, resulting in an unaccounted for increase in activity around the 11611066Srafael.vanoni@sun.com * lbolt routines that could cause a mode switch. 11711066Srafael.vanoni@sun.com */ 118*11099Srafael.vanoni@sun.com #define LBOLT_NO_ACCOUNT64 \ 11911066Srafael.vanoni@sun.com (lbolt_hybrid == lbolt_event_driven ? \ 12011066Srafael.vanoni@sun.com ((gethrtime()/nsec_per_tick) - lb_info->lbi_debug_time) : \ 12111066Srafael.vanoni@sun.com (lb_info->lbi_internal - lb_info->lbi_debug_time)) 12211066Srafael.vanoni@sun.com 123*11099Srafael.vanoni@sun.com #define LBOLT_NO_ACCOUNT (clock_t)LBOLT_NO_ACCOUNT64 124*11099Srafael.vanoni@sun.com 12511066Srafael.vanoni@sun.com #endif /* _KERNEL || _KMEMUSER */ 12611066Srafael.vanoni@sun.com 12711066Srafael.vanoni@sun.com #ifdef __cplusplus 12811066Srafael.vanoni@sun.com } 12911066Srafael.vanoni@sun.com #endif 13011066Srafael.vanoni@sun.com 13111066Srafael.vanoni@sun.com #endif /* _SYS_CLOCK_IMPL_H */ 132