xref: /onnv-gate/usr/src/uts/common/sys/clock_impl.h (revision 11066:cebb50cbe4f9)
1*11066Srafael.vanoni@sun.com /*
2*11066Srafael.vanoni@sun.com  * CDDL HEADER START
3*11066Srafael.vanoni@sun.com  *
4*11066Srafael.vanoni@sun.com  * The contents of this file are subject to the terms of the
5*11066Srafael.vanoni@sun.com  * Common Development and Distribution License (the "License").
6*11066Srafael.vanoni@sun.com  * You may not use this file except in compliance with the License.
7*11066Srafael.vanoni@sun.com  *
8*11066Srafael.vanoni@sun.com  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*11066Srafael.vanoni@sun.com  * or http://www.opensolaris.org/os/licensing.
10*11066Srafael.vanoni@sun.com  * See the License for the specific language governing permissions
11*11066Srafael.vanoni@sun.com  * and limitations under the License.
12*11066Srafael.vanoni@sun.com  *
13*11066Srafael.vanoni@sun.com  * When distributing Covered Code, include this CDDL HEADER in each
14*11066Srafael.vanoni@sun.com  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*11066Srafael.vanoni@sun.com  * If applicable, add the following below this CDDL HEADER, with the
16*11066Srafael.vanoni@sun.com  * fields enclosed by brackets "[]" replaced with your own identifying
17*11066Srafael.vanoni@sun.com  * information: Portions Copyright [yyyy] [name of copyright owner]
18*11066Srafael.vanoni@sun.com  *
19*11066Srafael.vanoni@sun.com  * CDDL HEADER END
20*11066Srafael.vanoni@sun.com  */
21*11066Srafael.vanoni@sun.com 
22*11066Srafael.vanoni@sun.com /*
23*11066Srafael.vanoni@sun.com  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24*11066Srafael.vanoni@sun.com  * Use is subject to license terms.
25*11066Srafael.vanoni@sun.com  */
26*11066Srafael.vanoni@sun.com 
27*11066Srafael.vanoni@sun.com #ifndef	_SYS_CLOCK_IMPL_H
28*11066Srafael.vanoni@sun.com #define	_SYS_CLOCK_IMPL_H
29*11066Srafael.vanoni@sun.com 
30*11066Srafael.vanoni@sun.com #ifdef	__cplusplus
31*11066Srafael.vanoni@sun.com extern "C" {
32*11066Srafael.vanoni@sun.com #endif
33*11066Srafael.vanoni@sun.com 
34*11066Srafael.vanoni@sun.com #if (defined(_KERNEL) || defined(_KMEMUSER))
35*11066Srafael.vanoni@sun.com #include <sys/types.h>
36*11066Srafael.vanoni@sun.com #include <sys/cpuvar.h>
37*11066Srafael.vanoni@sun.com #include <sys/cyclic.h>
38*11066Srafael.vanoni@sun.com #include <sys/time.h>
39*11066Srafael.vanoni@sun.com 
40*11066Srafael.vanoni@sun.com /*
41*11066Srafael.vanoni@sun.com  * Default clock rate in Hz.
42*11066Srafael.vanoni@sun.com  */
43*11066Srafael.vanoni@sun.com #define	HZ_DEFAULT		100
44*11066Srafael.vanoni@sun.com 
45*11066Srafael.vanoni@sun.com /*
46*11066Srafael.vanoni@sun.com  * Thresholds over which we switch between event and cyclic driven lbolt. The
47*11066Srafael.vanoni@sun.com  * current default values were derived experimentally and will keep the
48*11066Srafael.vanoni@sun.com  * system on event driven mode when idle and respond to activity around the
49*11066Srafael.vanoni@sun.com  * lbolt DDI functions by switching to cyclic mode.
50*11066Srafael.vanoni@sun.com  */
51*11066Srafael.vanoni@sun.com #define	LBOLT_THRESH_CALLS		(75)
52*11066Srafael.vanoni@sun.com #define	LBOLT_THRESH_INTERVAL		(1)
53*11066Srafael.vanoni@sun.com 
54*11066Srafael.vanoni@sun.com /*
55*11066Srafael.vanoni@sun.com  * Both lbolt_cpu_t and lbolt_info_t are cache line sized and aligned,
56*11066Srafael.vanoni@sun.com  * please take that in consideration if modifying these.
57*11066Srafael.vanoni@sun.com  */
58*11066Srafael.vanoni@sun.com typedef struct lbolt_cpu {
59*11066Srafael.vanoni@sun.com 	int64_t lbc_counter;	/* number of calls to the DDI lbolt routines */
60*11066Srafael.vanoni@sun.com 	int64_t lbc_cnt_start;	/* beggining of the cnt interval (in ticks) */
61*11066Srafael.vanoni@sun.com 	char lbc_pad[CPU_CACHE_COHERENCE_SIZE - (2 * sizeof (int64_t))];
62*11066Srafael.vanoni@sun.com } lbolt_cpu_t;
63*11066Srafael.vanoni@sun.com 
64*11066Srafael.vanoni@sun.com typedef struct lbolt_info {
65*11066Srafael.vanoni@sun.com 	cyclic_id_t lbi_cyclic_id;	/* lbolt's cyclic id */
66*11066Srafael.vanoni@sun.com 	int64_t lbi_internal;		/* lbolt source when on cyclic mode */
67*11066Srafael.vanoni@sun.com 	int64_t lbi_debug_time;		/* time spent in the debugger */
68*11066Srafael.vanoni@sun.com 	int64_t lbi_debug_ts;		/* last time we dropped into kmdb */
69*11066Srafael.vanoni@sun.com 	int64_t lbi_thresh_calls;	/* max calls per interval */
70*11066Srafael.vanoni@sun.com 	int64_t lbi_thresh_interval;	/* interval window for the # of calls */
71*11066Srafael.vanoni@sun.com 	uint32_t lbi_token;		/* synchronize cyclic mode switch */
72*11066Srafael.vanoni@sun.com 	boolean_t lbi_cyc_deactivate;	/* lbolt_cyclic self deactivation */
73*11066Srafael.vanoni@sun.com 	int64_t lbi_cyc_deac_start;	/* deactivation interval */
74*11066Srafael.vanoni@sun.com } lbolt_info_t;
75*11066Srafael.vanoni@sun.com 
76*11066Srafael.vanoni@sun.com extern int64_t lbolt_event_driven(void);
77*11066Srafael.vanoni@sun.com extern int64_t lbolt_cyclic_driven(void);
78*11066Srafael.vanoni@sun.com extern int64_t (*lbolt_hybrid)(void);
79*11066Srafael.vanoni@sun.com extern uint_t lbolt_ev_to_cyclic(caddr_t, caddr_t);
80*11066Srafael.vanoni@sun.com 
81*11066Srafael.vanoni@sun.com extern void lbolt_softint_add(void);
82*11066Srafael.vanoni@sun.com extern void lbolt_softint_post(void);
83*11066Srafael.vanoni@sun.com 
84*11066Srafael.vanoni@sun.com extern void lbolt_debug_entry(void);
85*11066Srafael.vanoni@sun.com extern void lbolt_debug_return(void);
86*11066Srafael.vanoni@sun.com 
87*11066Srafael.vanoni@sun.com extern lbolt_info_t *lb_info;
88*11066Srafael.vanoni@sun.com 
89*11066Srafael.vanoni@sun.com /*
90*11066Srafael.vanoni@sun.com  * LBOLT_WAITFREE provides a non-waiting version of lbolt.
91*11066Srafael.vanoni@sun.com  */
92*11066Srafael.vanoni@sun.com #define	LBOLT_WAITFREE							\
93*11066Srafael.vanoni@sun.com 	(lbolt_hybrid == lbolt_event_driven ?                           \
94*11066Srafael.vanoni@sun.com 	    ((gethrtime_waitfree()/nsec_per_tick) -			\
95*11066Srafael.vanoni@sun.com 	    lb_info->lbi_debug_time) :					\
96*11066Srafael.vanoni@sun.com 	    (lb_info->lbi_internal - lb_info->lbi_debug_time))
97*11066Srafael.vanoni@sun.com 
98*11066Srafael.vanoni@sun.com /*
99*11066Srafael.vanoni@sun.com  * LBOLT_FASTPATH should *only* be used where the cost of calling
100*11066Srafael.vanoni@sun.com  * ddi_get_lbolt() affects performance. This is currently only used by the
101*11066Srafael.vanoni@sun.com  * TCP/IP code and will be removed once it's no longer required.
102*11066Srafael.vanoni@sun.com  */
103*11066Srafael.vanoni@sun.com #define	LBOLT_FASTPATH							\
104*11066Srafael.vanoni@sun.com 	(lbolt_hybrid == lbolt_event_driven ? ddi_get_lbolt() :		\
105*11066Srafael.vanoni@sun.com 	    (clock_t)(lb_info->lbi_internal - lb_info->lbi_debug_time))
106*11066Srafael.vanoni@sun.com 
107*11066Srafael.vanoni@sun.com /*
108*11066Srafael.vanoni@sun.com  * LBOLT_NO_ACCOUNT is used by lbolt consumers who fire at a periodic rate,
109*11066Srafael.vanoni@sun.com  * such as clock(), for which the lbolt usage statistics are not updated.
110*11066Srafael.vanoni@sun.com  * This is specially important for consumers whose rate may be modified by
111*11066Srafael.vanoni@sun.com  * the user, resulting in an unaccounted for increase in activity around the
112*11066Srafael.vanoni@sun.com  * lbolt routines that could cause a mode switch.
113*11066Srafael.vanoni@sun.com  */
114*11066Srafael.vanoni@sun.com #define	LBOLT_NO_ACCOUNT						\
115*11066Srafael.vanoni@sun.com 	(lbolt_hybrid == lbolt_event_driven ?				\
116*11066Srafael.vanoni@sun.com 	    ((gethrtime()/nsec_per_tick) - lb_info->lbi_debug_time) :	\
117*11066Srafael.vanoni@sun.com 	    (lb_info->lbi_internal - lb_info->lbi_debug_time))
118*11066Srafael.vanoni@sun.com 
119*11066Srafael.vanoni@sun.com #endif	/* _KERNEL || _KMEMUSER */
120*11066Srafael.vanoni@sun.com 
121*11066Srafael.vanoni@sun.com #ifdef	__cplusplus
122*11066Srafael.vanoni@sun.com }
123*11066Srafael.vanoni@sun.com #endif
124*11066Srafael.vanoni@sun.com 
125*11066Srafael.vanoni@sun.com #endif /* _SYS_CLOCK_IMPL_H */
126