xref: /illumos-gate/usr/src/uts/common/sys/sysdc_impl.h (revision 915894ef19890baaed00080f85f6b69e225cda98)
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  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_SYS_SYSDC_IMPL_H
27 #define	_SYS_SYSDC_IMPL_H
28 
29 #include <sys/types.h>
30 #include <sys/time.h>
31 #include <sys/list.h>
32 
33 #include <sys/sysdc.h>
34 
35 #ifdef	__cplusplus
36 extern "C" {
37 #endif
38 
39 struct _kthread;
40 struct cpupart;
41 
42 /*
43  * Tracks per-processor-set information for SDC.  Its main use is to
44  * implement per-processor-set breaks.
45  */
46 typedef struct sysdc_pset {
47 	list_node_t	sdp_node;	/* node on sysdc_psets list */
48 	struct cpupart	*sdp_cpupart;	/* associated cpu partition */
49 	size_t		sdp_nthreads;	/* reference count */
50 
51 	/* The remainder is only touched by sysdc_update() */
52 	hrtime_t	sdp_onproc_time; /* time onproc at last update */
53 	boolean_t	sdp_need_break;	/* threads forced to minpri */
54 	uint_t		sdp_should_break; /* # updates need_break is set */
55 	uint_t		sdp_dont_break;	/* after break, # updates until next */
56 
57 	/* debugging fields */
58 	uint_t		sdp_onproc_threads;
59 	hrtime_t	sdp_vtime_last_interval;
60 	uint_t		sdp_DC_last_interval;
61 } sysdc_pset_t;
62 
63 /*
64  * Per-thread information, pointed to by t_cldata.
65  */
66 typedef struct sysdc {
67 	uint_t		sdc_target_DC;	/* target duty cycle */
68 	uint_t		sdc_minpri;	/* our minimum priority */
69 	uint_t		sdc_maxpri;	/* our maximum priority */
70 
71 	sysdc_pset_t	*sdc_pset;	/* the processor set bound to */
72 
73 	/* protected by sdl_lock */
74 	struct _kthread	*sdc_thread;	/* back-pointer, or NULL if freeable */
75 
76 	/* protected by arrangement between thread and sysdc_update() */
77 	struct sysdc	*sdc_next;	/* next in hash table, NULL if not in */
78 
79 	/* protected by thread_lock() */
80 	uint_t		sdc_nupdates;	/* number of sysdc_update_times() */
81 
82 	hrtime_t	sdc_base_O;	/* on-cpu time at last reset */
83 	hrtime_t	sdc_base_R;	/* runnable time at last reset */
84 
85 	uint_t		sdc_sleep_updates; /* 0, or nupdates when we slept */
86 	clock_t		sdc_ticks;	/* sdc_tick() calls */
87 	clock_t		sdc_update_ticks; /* value of ticks for forced update */
88 	clock_t		sdc_pri_check;	/* lbolt when we checked our priority */
89 	hrtime_t	sdc_last_base_O; /* onproc time at sysdc_update() */
90 
91 	uint_t		sdc_pri;	/* our last computed priority */
92 	uint_t		sdc_epri;	/* our actual thread priority */
93 
94 	/* for debugging only */
95 	clock_t		sdc_reset;	/* lbolt when we reset our bases */
96 	hrtime_t	sdc_cur_O;	/* on-cpu time at last prio check */
97 	hrtime_t	sdc_cur_R;	/* runnable time at last prio check */
98 	hrtime_t	sdc_last_O;	/* onproc time at thread update */
99 	uint_t		sdc_cur_DC;	/* our actual duty cycle at last chk */
100 } sysdc_t;
101 
102 /*
103  * Hash bucket of active SDC threads.
104  */
105 typedef struct sysdc_list {
106 	kmutex_t	sdl_lock;	/* lock keeping threads from exiting */
107 	sysdc_t	*volatile sdl_list;	/* list of active threads in bucket */
108 	char		sdl_pad[64 - sizeof (kmutex_t) - sizeof (sysdc_t *)];
109 } sysdc_list_t;
110 
111 /*
112  * Args to CL_ENTERCLASS().
113  */
114 typedef struct sysdc_params {
115 	uint_t		sdp_minpri;
116 	uint_t		sdp_maxpri;
117 	uint_t		sdp_DC;
118 } sysdc_params_t;
119 
120 /*
121  * Duty cycles are percentages in the range [1,100].
122  */
123 #define	SYSDC_DC_MAX		100u	/* 1 <= DC <= DC_MAX */
124 
125 #ifdef	__cplusplus
126 }
127 #endif
128 
129 #endif	/* _SYS_SYSDC_IMPL_H */
130