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