xref: /titanic_41/usr/src/uts/common/sys/fss.h (revision d89fccd8788afe1e920f842edd883fe192a1b8fe)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 
23 /*
24  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
25  * Use is subject to license terms.
26  */
27 
28 #ifndef	_SYS_FSS_H
29 #define	_SYS_FSS_H
30 
31 #pragma ident	"%Z%%M%	%I%	%E% SMI"
32 
33 #include <sys/types.h>
34 #include <sys/thread.h>
35 #include <sys/project.h>
36 
37 #ifdef	__cplusplus
38 extern "C" {
39 #endif
40 
41 typedef uint64_t fsspri_t;
42 typedef	uint64_t fssusage_t;
43 struct cpupart;
44 struct zone;
45 
46 /*
47  * Valid arg1's for fss_allocbuf()
48  */
49 #define	FSS_NPSET_BUF	1
50 #define	FSS_NPROJ_BUF	2
51 #define	FSS_ONE_BUF	3
52 
53 /*
54  * Valid arg2's for fss_allocbuf()
55  */
56 #define	FSS_ALLOC_PROJ	1
57 #define	FSS_ALLOC_ZONE	2
58 
59 #define	FSS_MAXSHARES	65535
60 
61 typedef struct fssbuf {
62 	int	fssb_size;
63 	void	**fssb_list;
64 } fssbuf_t;
65 
66 void *fss_allocbuf(int, int);
67 void fss_freebuf(fssbuf_t *, int);
68 void fss_changeproj(kthread_id_t, void *, void *, fssbuf_t *, fssbuf_t *);
69 void fss_changepset(kthread_id_t, void *, fssbuf_t *, fssbuf_t *);
70 
71 /*
72  * Fair share scheduling class specific cpu partition structure
73  */
74 typedef struct fsspset {
75 	kmutex_t	fssps_lock;	/* lock to protect per-pset	*/
76 					/* list of fssproj structures	*/
77 	disp_lock_t	fssps_displock;	/* lock for fsps_maxfspri	*/
78 	struct cpupart	*fssps_cpupart;	/* ptr to our cpu partition	*/
79 					/* protected by fsspsets_lock	*/
80 	fsspri_t	fssps_maxfsspri; /* maximum fsspri value among	*/
81 					/* all projects on this pset	*/
82 	uint32_t	fssps_shares;	/* number of active shares	*/
83 	uint32_t	fssps_nproj;	/* number of fssproj structures */
84 					/* on the list			*/
85 	struct fssproj	*fssps_list;	/* list of project parts	*/
86 	struct fsszone	*fssps_zones;	/* list of fsszone_t's in pset	*/
87 } fsspset_t;
88 
89 /*
90  * One of these structures is allocated to each project running within each
91  * active cpu partition.
92  */
93 typedef struct fssproj {
94 	kproject_t	*fssp_proj;	/* ptr to our project structure	*/
95 	fsspset_t	*fssp_pset;	/* ptr to our fsspset structure	*/
96 	uint32_t	fssp_threads;	/* total number of threads here */
97 					/* protected by fssps_lock	*/
98 	uint32_t	fssp_runnable;	/* number of runnable threads	*/
99 					/* protected by fssps_lock	*/
100 	uint32_t	fssp_shares;	/* copy of our kpj_shares	*/
101 					/* protected by fssps_displock	*/
102 	uint32_t	fssp_ticks;	/* total of all ticks		*/
103 					/* protected by fssps_displock	*/
104 	fssusage_t	fssp_usage;	/* this project's decayed usage */
105 	fssusage_t	fssp_shusage;	/* normalized usage		*/
106 	struct fssproj	*fssp_next;	/* next project on this pset	*/
107 	struct fssproj	*fssp_prev;	/* prev project on this pset	*/
108 	struct fsszone	*fssp_fsszone;	/* fsszone_t for this fssproj	*/
109 } fssproj_t;
110 
111 /*
112  * Fair share scheduling class specific thread structure
113  */
114 typedef struct fssproc {
115 	kthread_t *fss_tp;	/* pointer back to our thread		*/
116 	fssproj_t *fss_proj;	/* pointer to our project FS data	*/
117 	uchar_t fss_flags;	/* flags defined below			*/
118 	int	fss_timeleft;	/* time remaining in procs quantum	*/
119 	uint32_t fss_ticks;	/* ticks accumulated by this thread	*/
120 	pri_t	fss_upri;	/* user supplied priority (to priocntl)	*/
121 	pri_t	fss_uprilim;	/* user priority limit			*/
122 	pri_t	fss_umdpri;	/* user mode priority within fs class	*/
123 	pri_t	fss_scpri;	/* remembered priority, for schedctl	*/
124 	int	fss_nice;	/* nice value for compatibility with ts	*/
125 	fsspri_t fss_fsspri;	/* internal fair share priority		*/
126 	int	fss_runnable;	/* to indicate runnable/sleeping thread	*/
127 	struct fssproc *fss_next; /* pointer to next fssproc_t struct	*/
128 	struct fssproc *fss_prev; /* pointer to prev fssproc_t sturct	*/
129 } fssproc_t;
130 
131 /*
132  * One of these structures is allocated to each zone running within each active
133  * cpu partition.
134  */
135 typedef struct fsszone {
136 	struct zone 	*fssz_zone;	/* ptr to our zone structure */
137 	struct fsszone	*fssz_next;	/* ptr to next fsszone in fsspset */
138 	struct fsszone	*fssz_prev;	/* ptr to prev fsszone in fsspset */
139 	uint32_t	fssz_shares;	/* total #shares for projs in zone */
140 	uint32_t	fssz_nproj;	/* # fssproj_t's in this fsszone */
141 	uint32_t	fssz_rshares;	/* "real" shares given to zone */
142 	uint32_t	fssz_runnable;	/* # projects with runnable threads */
143 } fsszone_t;
144 
145 #define	FSSPROC(tx)		((fssproc_t *)(tx->t_cldata))
146 #define	FSSPROC2FSSPROJ(fssx)	((fssx)->fss_proj);
147 #define	FSSPROC2FSSPSET(fssx)	(FSSPROC2FSSPROJ(fssx)->fssp_pset)
148 #define	FSSPROJ(tx)		(FSSPROC(tx)->fss_proj)
149 #define	FSSPROJ2FSSPSET(fssx)	((fssx)->fssp_pset)
150 #define	FSSPROJ2KPROJ(fssx)	((fssx)->fssp_proj)
151 #define	FSSPROJ2FSSZONE(fssx)	((fssx)->fssp_fsszone)
152 
153 /*
154  * fss_flags
155  */
156 #define	FSSKPRI		0x01	/* the thread is in kernel mode	*/
157 #define	FSSBACKQ	0x02	/* thread should be placed at the back of */
158 				/* the dispatch queue if preempted */
159 #define	FSSRESTORE	0x04	/* thread was not preempted, due to schedctl */
160 				/* restore priority from fss_scpri */
161 #ifdef	__cplusplus
162 }
163 #endif
164 
165 #endif	/* _SYS_FSS_H */
166