xref: /illumos-gate/usr/src/uts/common/sys/clock_tick.h (revision 2d6eb4a5e0a47d30189497241345dc5466bb68ab)
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 2008 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_SYS_CLOCK_TICK_H
28 #define	_SYS_CLOCK_TICK_H
29 
30 #include <sys/types.h>
31 #include <sys/mutex.h>
32 #include <sys/cpuvar.h>
33 #include <sys/systm.h>
34 #include <sys/cyclic.h>
35 
36 #ifdef	__cplusplus
37 extern "C" {
38 #endif
39 
40 #define	CLOCK_TICK_NCPUS	32
41 
42 /*
43  * Per-CPU structure to facilitate multi-threaded tick accounting.
44  *
45  * ct_lock
46  *	Mutex for the structure. Used to lock the structure to pass
47  *	arguments to the tick processing softint handler.
48  * ct_intr
49  *	Tick processing softint handle. For parallelism, each CPU
50  *	needs to have its own softint handle.
51  * ct_lbolt
52  *	Copy of the lbolt at the time of tick scheduling.
53  * ct_pending
54  *	Number of ticks to be processed by one invocation of the tick
55  *	processing softint.
56  * ct_start
57  *	First CPU to do tick processing for.
58  * ct_end
59  *	Last CPU to do tick processing for.
60  * ct_scan
61  *	CPU to start the tick processing from. Rotated every tick.
62  */
63 typedef struct clock_tick_cpu {
64 	kmutex_t		ct_lock;
65 	ulong_t			ct_intr;
66 	clock_t			ct_lbolt;
67 	int			ct_pending;
68 	int			ct_start;
69 	int			ct_end;
70 	int			ct_scan;
71 } clock_tick_cpu_t;
72 
73 /*
74  * Per-set structure to facilitate multi-threaded tick accounting.
75  * clock_tick_lock protects this.
76  *
77  * ct_start
78  *	First CPU to do tick processing for.
79  * ct_end
80  *	Last CPU to do tick processing for.
81  * ct_scan
82  *	CPU to start the tick processing from. Rotated every tick.
83  */
84 typedef struct clock_tick_set {
85 	int			ct_start;
86 	int			ct_end;
87 	int			ct_scan;
88 } clock_tick_set_t;
89 
90 #define	CLOCK_TICK_CPU_OFFLINE(cp)	\
91 	(((cp) != cpu_active) && ((cp)->cpu_next_onln == (cp)))
92 
93 #define	CLOCK_TICK_XCALL_SAFE(cp)	\
94 		CPU_IN_SET(clock_tick_online_cpuset, cp->cpu_id)
95 
96 #define	CLOCK_TICK_PROC_MAX		10
97 
98 #ifdef	_KERNEL
99 #pragma weak		create_softint
100 extern ulong_t		create_softint(uint_t, uint_t (*)(caddr_t, caddr_t),
101 				caddr_t);
102 #pragma weak		invoke_softint
103 extern void		invoke_softint(processorid_t, ulong_t);
104 #pragma weak		sync_softint
105 extern void		sync_softint(cpuset_t);
106 extern void		clock_tick(kthread_t *, int);
107 extern void		membar_sync(void);
108 
109 extern int		hires_tick;
110 #endif	/* _KERNEL */
111 
112 #ifdef	__cplusplus
113 }
114 #endif
115 
116 #endif /* _SYS_CLOCK_TICK_H */
117