xref: /onnv-gate/usr/src/uts/common/sys/clock_impl.h (revision 11226:320a31f24ec3)
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  */
4311151Srafael.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 {
6511151Srafael.vanoni@sun.com 	union {
6611151Srafael.vanoni@sun.com 		cyclic_id_t lbi_cyclic_id;	/* lbolt's cyclic id */
6711151Srafael.vanoni@sun.com 		int64_t lbi_id_pad;		/* 64bit padding */
6811151Srafael.vanoni@sun.com 	} id;
6911066Srafael.vanoni@sun.com 	int64_t lbi_internal;		/* lbolt source when on cyclic mode */
7011066Srafael.vanoni@sun.com 	int64_t lbi_debug_time;		/* time spent in the debugger */
7111066Srafael.vanoni@sun.com 	int64_t lbi_debug_ts;		/* last time we dropped into kmdb */
7211066Srafael.vanoni@sun.com 	int64_t lbi_thresh_calls;	/* max calls per interval */
7311066Srafael.vanoni@sun.com 	int64_t lbi_thresh_interval;	/* interval window for the # of calls */
7411066Srafael.vanoni@sun.com 	uint32_t lbi_token;		/* synchronize cyclic mode switch */
7511066Srafael.vanoni@sun.com 	boolean_t lbi_cyc_deactivate;	/* lbolt_cyclic self deactivation */
7611066Srafael.vanoni@sun.com 	int64_t lbi_cyc_deac_start;	/* deactivation interval */
7711066Srafael.vanoni@sun.com } lbolt_info_t;
7811066Srafael.vanoni@sun.com 
79*11226Srafael.vanoni@sun.com extern int64_t lbolt_bootstrap(void);
8011066Srafael.vanoni@sun.com extern int64_t lbolt_event_driven(void);
8111066Srafael.vanoni@sun.com extern int64_t lbolt_cyclic_driven(void);
8211066Srafael.vanoni@sun.com extern int64_t (*lbolt_hybrid)(void);
8311066Srafael.vanoni@sun.com extern uint_t lbolt_ev_to_cyclic(caddr_t, caddr_t);
8411066Srafael.vanoni@sun.com 
8511066Srafael.vanoni@sun.com extern void lbolt_softint_add(void);
8611066Srafael.vanoni@sun.com extern void lbolt_softint_post(void);
8711066Srafael.vanoni@sun.com 
8811066Srafael.vanoni@sun.com extern void lbolt_debug_entry(void);
8911066Srafael.vanoni@sun.com extern void lbolt_debug_return(void);
9011066Srafael.vanoni@sun.com 
9111066Srafael.vanoni@sun.com extern lbolt_info_t *lb_info;
9211066Srafael.vanoni@sun.com 
9311066Srafael.vanoni@sun.com /*
9411099Srafael.vanoni@sun.com  * LBOLT_WAITFREE{,64} provide a non-waiting version of lbolt.
9511066Srafael.vanoni@sun.com  */
9611099Srafael.vanoni@sun.com #define	LBOLT_WAITFREE64						\
97*11226Srafael.vanoni@sun.com 	(lbolt_hybrid == lbolt_bootstrap ? 0 :				\
9811066Srafael.vanoni@sun.com 	(lbolt_hybrid == lbolt_event_driven ?                           \
9911066Srafael.vanoni@sun.com 	    ((gethrtime_waitfree()/nsec_per_tick) -			\
10011066Srafael.vanoni@sun.com 	    lb_info->lbi_debug_time) :					\
101*11226Srafael.vanoni@sun.com 	    (lb_info->lbi_internal - lb_info->lbi_debug_time)))
10211066Srafael.vanoni@sun.com 
10311099Srafael.vanoni@sun.com #define	LBOLT_WAITFREE		(clock_t)LBOLT_WAITFREE64
10411066Srafael.vanoni@sun.com 
10511066Srafael.vanoni@sun.com /*
10611099Srafael.vanoni@sun.com  * LBOLT_FASTPATH{,64} should *only* be used where the cost of calling the
10711099Srafael.vanoni@sun.com  * DDI lbolt routines affects performance. This is currently only used by
10811099Srafael.vanoni@sun.com  * the TCP/IP code and will be removed once it's no longer required.
10911099Srafael.vanoni@sun.com  */
11011099Srafael.vanoni@sun.com #define	LBOLT_FASTPATH64						\
111*11226Srafael.vanoni@sun.com 	(lbolt_hybrid == lbolt_cyclic_driven ?				\
112*11226Srafael.vanoni@sun.com 	    (lb_info->lbi_internal - lb_info->lbi_debug_time) :		\
113*11226Srafael.vanoni@sun.com 	    ddi_get_lbolt64())
11411099Srafael.vanoni@sun.com 
11511099Srafael.vanoni@sun.com #define	LBOLT_FASTPATH		(clock_t)LBOLT_FASTPATH64
11611099Srafael.vanoni@sun.com 
11711099Srafael.vanoni@sun.com /*
11811099Srafael.vanoni@sun.com  * LBOLT_NO_ACCOUNT{,64} is used by lbolt consumers who fire at a periodic
11911099Srafael.vanoni@sun.com  * rate, such as clock(), for which the lbolt usage statistics are not updated.
12011099Srafael.vanoni@sun.com  * This is especially important for consumers whose rate may be modified by
12111066Srafael.vanoni@sun.com  * the user, resulting in an unaccounted for increase in activity around the
12211066Srafael.vanoni@sun.com  * lbolt routines that could cause a mode switch.
12311066Srafael.vanoni@sun.com  */
12411099Srafael.vanoni@sun.com #define	LBOLT_NO_ACCOUNT64						\
125*11226Srafael.vanoni@sun.com 	(lbolt_hybrid == lbolt_bootstrap ? 0 :				\
12611066Srafael.vanoni@sun.com 	(lbolt_hybrid == lbolt_event_driven ?				\
12711066Srafael.vanoni@sun.com 	    ((gethrtime()/nsec_per_tick) - lb_info->lbi_debug_time) :	\
128*11226Srafael.vanoni@sun.com 	    (lb_info->lbi_internal - lb_info->lbi_debug_time)))
12911066Srafael.vanoni@sun.com 
13011099Srafael.vanoni@sun.com #define	LBOLT_NO_ACCOUNT	(clock_t)LBOLT_NO_ACCOUNT64
13111099Srafael.vanoni@sun.com 
13211066Srafael.vanoni@sun.com #endif	/* _KERNEL || _KMEMUSER */
13311066Srafael.vanoni@sun.com 
13411066Srafael.vanoni@sun.com #ifdef	__cplusplus
13511066Srafael.vanoni@sun.com }
13611066Srafael.vanoni@sun.com #endif
13711066Srafael.vanoni@sun.com 
13811066Srafael.vanoni@sun.com #endif /* _SYS_CLOCK_IMPL_H */
139