xref: /titanic_53/usr/src/uts/common/sys/class.h (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate /*	Copyright (c) 1988 AT&T	*/
28*7c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate 
31*7c478bd9Sstevel@tonic-gate #ifndef _SYS_CLASS_H
32*7c478bd9Sstevel@tonic-gate #define	_SYS_CLASS_H
33*7c478bd9Sstevel@tonic-gate 
34*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
35*7c478bd9Sstevel@tonic-gate 
36*7c478bd9Sstevel@tonic-gate #include <sys/t_lock.h>
37*7c478bd9Sstevel@tonic-gate #include <sys/cred.h>
38*7c478bd9Sstevel@tonic-gate #include <sys/thread.h>
39*7c478bd9Sstevel@tonic-gate #include <sys/priocntl.h>
40*7c478bd9Sstevel@tonic-gate #include <sys/mutex.h>
41*7c478bd9Sstevel@tonic-gate 
42*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
43*7c478bd9Sstevel@tonic-gate extern "C" {
44*7c478bd9Sstevel@tonic-gate #endif
45*7c478bd9Sstevel@tonic-gate 
46*7c478bd9Sstevel@tonic-gate /*
47*7c478bd9Sstevel@tonic-gate  * NOTE: Developers making use of the scheduler class switch mechanism
48*7c478bd9Sstevel@tonic-gate  * to develop scheduling class modules should be aware that the
49*7c478bd9Sstevel@tonic-gate  * architecture is not frozen and the kernel interface for scheduling
50*7c478bd9Sstevel@tonic-gate  * class modules may change in future releases of System V.  Support
51*7c478bd9Sstevel@tonic-gate  * for the current interface is not guaranteed and class modules
52*7c478bd9Sstevel@tonic-gate  * developed to this interface may require changes in order to work
53*7c478bd9Sstevel@tonic-gate  * with future releases of the system.
54*7c478bd9Sstevel@tonic-gate  */
55*7c478bd9Sstevel@tonic-gate 
56*7c478bd9Sstevel@tonic-gate /*
57*7c478bd9Sstevel@tonic-gate  * three different ops vectors are bundled together, here.
58*7c478bd9Sstevel@tonic-gate  * one is for each of the fundamental objects acted upon
59*7c478bd9Sstevel@tonic-gate  * by these operators: procs, threads, and the class manager itself.
60*7c478bd9Sstevel@tonic-gate  */
61*7c478bd9Sstevel@tonic-gate 
62*7c478bd9Sstevel@tonic-gate typedef struct class_ops {
63*7c478bd9Sstevel@tonic-gate 	int	(*cl_admin)(caddr_t, cred_t *);
64*7c478bd9Sstevel@tonic-gate 	int	(*cl_getclinfo)(void *);
65*7c478bd9Sstevel@tonic-gate 	int	(*cl_parmsin)(void *);
66*7c478bd9Sstevel@tonic-gate 	int	(*cl_parmsout)(void *, pc_vaparms_t *);
67*7c478bd9Sstevel@tonic-gate 	int	(*cl_vaparmsin)(void *, pc_vaparms_t *);
68*7c478bd9Sstevel@tonic-gate 	int	(*cl_vaparmsout)(void *, pc_vaparms_t *);
69*7c478bd9Sstevel@tonic-gate 	int	(*cl_getclpri)(pcpri_t *);
70*7c478bd9Sstevel@tonic-gate 	int	(*cl_alloc)(void **, int);
71*7c478bd9Sstevel@tonic-gate 	void	(*cl_free)(void *);
72*7c478bd9Sstevel@tonic-gate } class_ops_t;
73*7c478bd9Sstevel@tonic-gate 
74*7c478bd9Sstevel@tonic-gate typedef struct thread_ops {
75*7c478bd9Sstevel@tonic-gate 	int	(*cl_enterclass)(kthread_id_t, id_t, void *, cred_t *, void *);
76*7c478bd9Sstevel@tonic-gate 	void	(*cl_exitclass)(void *);
77*7c478bd9Sstevel@tonic-gate 	int	(*cl_canexit)(kthread_id_t, cred_t *);
78*7c478bd9Sstevel@tonic-gate 	int	(*cl_fork)(kthread_id_t, kthread_id_t, void *);
79*7c478bd9Sstevel@tonic-gate 	void	(*cl_forkret)(kthread_id_t, kthread_id_t);
80*7c478bd9Sstevel@tonic-gate 	void	(*cl_parmsget)(kthread_id_t, void *);
81*7c478bd9Sstevel@tonic-gate 	int	(*cl_parmsset)(kthread_id_t, void *, id_t, cred_t *);
82*7c478bd9Sstevel@tonic-gate 	void	(*cl_stop)(kthread_id_t, int, int);
83*7c478bd9Sstevel@tonic-gate 	void	(*cl_exit)(kthread_id_t);
84*7c478bd9Sstevel@tonic-gate 	void	(*cl_active)(kthread_id_t);
85*7c478bd9Sstevel@tonic-gate 	void	(*cl_inactive)(kthread_id_t);
86*7c478bd9Sstevel@tonic-gate 	pri_t	(*cl_swapin)(kthread_id_t, int);
87*7c478bd9Sstevel@tonic-gate 	pri_t 	(*cl_swapout)(kthread_id_t, int);
88*7c478bd9Sstevel@tonic-gate 	void 	(*cl_trapret)(kthread_id_t);
89*7c478bd9Sstevel@tonic-gate 	void	(*cl_preempt)(kthread_id_t);
90*7c478bd9Sstevel@tonic-gate 	void	(*cl_setrun)(kthread_id_t);
91*7c478bd9Sstevel@tonic-gate 	void	(*cl_sleep)(kthread_id_t);
92*7c478bd9Sstevel@tonic-gate 	void	(*cl_tick)(kthread_id_t);
93*7c478bd9Sstevel@tonic-gate 	void	(*cl_wakeup)(kthread_id_t);
94*7c478bd9Sstevel@tonic-gate 	int	(*cl_donice)(kthread_id_t, cred_t *, int, int *);
95*7c478bd9Sstevel@tonic-gate 	pri_t	(*cl_globpri)(kthread_id_t);
96*7c478bd9Sstevel@tonic-gate 	void	(*cl_set_process_group)(pid_t, pid_t, pid_t);
97*7c478bd9Sstevel@tonic-gate 	void	(*cl_yield)(kthread_id_t);
98*7c478bd9Sstevel@tonic-gate } thread_ops_t;
99*7c478bd9Sstevel@tonic-gate 
100*7c478bd9Sstevel@tonic-gate typedef struct classfuncs {
101*7c478bd9Sstevel@tonic-gate 	class_ops_t	sclass;
102*7c478bd9Sstevel@tonic-gate 	thread_ops_t	thread;
103*7c478bd9Sstevel@tonic-gate } classfuncs_t;
104*7c478bd9Sstevel@tonic-gate 
105*7c478bd9Sstevel@tonic-gate typedef struct sclass {
106*7c478bd9Sstevel@tonic-gate 	char		*cl_name;	/* class name */
107*7c478bd9Sstevel@tonic-gate 	/* class specific initialization function */
108*7c478bd9Sstevel@tonic-gate 	pri_t		(*cl_init)(id_t, int, classfuncs_t **);
109*7c478bd9Sstevel@tonic-gate 	classfuncs_t	*cl_funcs;	/* pointer to classfuncs structure */
110*7c478bd9Sstevel@tonic-gate 	krwlock_t	*cl_lock;	/* class structure read/write lock */
111*7c478bd9Sstevel@tonic-gate 	int		cl_count;	/* # of threads trying to load class */
112*7c478bd9Sstevel@tonic-gate } sclass_t;
113*7c478bd9Sstevel@tonic-gate 
114*7c478bd9Sstevel@tonic-gate #define	STATIC_SCHED		(krwlock_t *)0xffffffff
115*7c478bd9Sstevel@tonic-gate #define	LOADABLE_SCHED(s)	((s)->cl_lock != STATIC_SCHED)
116*7c478bd9Sstevel@tonic-gate #define	SCHED_INSTALLED(s)	((s)->cl_funcs != NULL)
117*7c478bd9Sstevel@tonic-gate #define	ALLOCATED_SCHED(s)	((s)->cl_lock != NULL)
118*7c478bd9Sstevel@tonic-gate 
119*7c478bd9Sstevel@tonic-gate #ifdef	_KERNEL
120*7c478bd9Sstevel@tonic-gate 
121*7c478bd9Sstevel@tonic-gate extern int	nclass;		/* number of configured scheduling classes */
122*7c478bd9Sstevel@tonic-gate extern char	*defaultclass;	/* default class for newproc'd processes */
123*7c478bd9Sstevel@tonic-gate extern struct sclass sclass[];	/* the class table */
124*7c478bd9Sstevel@tonic-gate extern kmutex_t	class_lock;	/* lock protecting class table */
125*7c478bd9Sstevel@tonic-gate extern int	loaded_classes;	/* number of classes loaded */
126*7c478bd9Sstevel@tonic-gate 
127*7c478bd9Sstevel@tonic-gate extern pri_t	minclsyspri;
128*7c478bd9Sstevel@tonic-gate extern id_t	syscid;		/* system scheduling class ID */
129*7c478bd9Sstevel@tonic-gate extern id_t	defaultcid;	/* "default" class id; see dispadmin(1M) */
130*7c478bd9Sstevel@tonic-gate 
131*7c478bd9Sstevel@tonic-gate extern int		alloc_cid(char *, id_t *);
132*7c478bd9Sstevel@tonic-gate extern int		scheduler_load(char *, sclass_t *);
133*7c478bd9Sstevel@tonic-gate extern int		getcid(char *, id_t *);
134*7c478bd9Sstevel@tonic-gate extern int		getcidbyname(char *, id_t *);
135*7c478bd9Sstevel@tonic-gate extern int		parmsin(pcparms_t *, pc_vaparms_t *);
136*7c478bd9Sstevel@tonic-gate extern int		parmsout(pcparms_t *, pc_vaparms_t *);
137*7c478bd9Sstevel@tonic-gate extern int		parmsset(pcparms_t *, kthread_id_t);
138*7c478bd9Sstevel@tonic-gate extern void		parmsget(kthread_id_t, pcparms_t *);
139*7c478bd9Sstevel@tonic-gate extern int		vaparmsout(char *, pcparms_t *, pc_vaparms_t *);
140*7c478bd9Sstevel@tonic-gate 
141*7c478bd9Sstevel@tonic-gate #endif
142*7c478bd9Sstevel@tonic-gate 
143*7c478bd9Sstevel@tonic-gate #define	CL_ADMIN(clp, uaddr, reqpcredp) \
144*7c478bd9Sstevel@tonic-gate 	(*(clp)->cl_funcs->sclass.cl_admin)(uaddr, reqpcredp)
145*7c478bd9Sstevel@tonic-gate 
146*7c478bd9Sstevel@tonic-gate #define	CL_ENTERCLASS(t, cid, clparmsp, credp, bufp) \
147*7c478bd9Sstevel@tonic-gate 	(sclass[cid].cl_funcs->thread.cl_enterclass) (t, cid, \
148*7c478bd9Sstevel@tonic-gate 	    (void *)clparmsp, credp, bufp)
149*7c478bd9Sstevel@tonic-gate 
150*7c478bd9Sstevel@tonic-gate #define	CL_EXITCLASS(cid, clprocp)\
151*7c478bd9Sstevel@tonic-gate 	(sclass[cid].cl_funcs->thread.cl_exitclass) ((void *)clprocp)
152*7c478bd9Sstevel@tonic-gate 
153*7c478bd9Sstevel@tonic-gate #define	CL_CANEXIT(t, cr)	(*(t)->t_clfuncs->cl_canexit)(t, cr)
154*7c478bd9Sstevel@tonic-gate 
155*7c478bd9Sstevel@tonic-gate #define	CL_FORK(tp, ct, bufp)	(*(tp)->t_clfuncs->cl_fork)(tp, ct, bufp)
156*7c478bd9Sstevel@tonic-gate 
157*7c478bd9Sstevel@tonic-gate #define	CL_FORKRET(t, ct)	(*(t)->t_clfuncs->cl_forkret)(t, ct)
158*7c478bd9Sstevel@tonic-gate 
159*7c478bd9Sstevel@tonic-gate #define	CL_GETCLINFO(clp, clinfop) \
160*7c478bd9Sstevel@tonic-gate 	(*(clp)->cl_funcs->sclass.cl_getclinfo)((void *)clinfop)
161*7c478bd9Sstevel@tonic-gate 
162*7c478bd9Sstevel@tonic-gate #define	CL_GETCLPRI(clp, clprip) \
163*7c478bd9Sstevel@tonic-gate 	(*(clp)->cl_funcs->sclass.cl_getclpri)(clprip)
164*7c478bd9Sstevel@tonic-gate 
165*7c478bd9Sstevel@tonic-gate #define	CL_PARMSGET(t, clparmsp) \
166*7c478bd9Sstevel@tonic-gate 	(*(t)->t_clfuncs->cl_parmsget)(t, (void *)clparmsp)
167*7c478bd9Sstevel@tonic-gate 
168*7c478bd9Sstevel@tonic-gate #define	CL_PARMSIN(clp, clparmsp) \
169*7c478bd9Sstevel@tonic-gate 	(clp)->cl_funcs->sclass.cl_parmsin((void *)clparmsp)
170*7c478bd9Sstevel@tonic-gate 
171*7c478bd9Sstevel@tonic-gate #define	CL_PARMSOUT(clp, clparmsp, vaparmsp) \
172*7c478bd9Sstevel@tonic-gate 	(clp)->cl_funcs->sclass.cl_parmsout((void *)clparmsp, vaparmsp)
173*7c478bd9Sstevel@tonic-gate 
174*7c478bd9Sstevel@tonic-gate #define	CL_VAPARMSIN(clp, clparmsp, vaparmsp) \
175*7c478bd9Sstevel@tonic-gate 	(clp)->cl_funcs->sclass.cl_vaparmsin((void *)clparmsp, vaparmsp)
176*7c478bd9Sstevel@tonic-gate 
177*7c478bd9Sstevel@tonic-gate #define	CL_VAPARMSOUT(clp, clparmsp, vaparmsp) \
178*7c478bd9Sstevel@tonic-gate 	(clp)->cl_funcs->sclass.cl_vaparmsout((void *)clparmsp, vaparmsp)
179*7c478bd9Sstevel@tonic-gate 
180*7c478bd9Sstevel@tonic-gate #define	CL_PARMSSET(t, clparmsp, cid, curpcredp) \
181*7c478bd9Sstevel@tonic-gate 	(*(t)->t_clfuncs->cl_parmsset)(t, (void *)clparmsp, cid, curpcredp)
182*7c478bd9Sstevel@tonic-gate 
183*7c478bd9Sstevel@tonic-gate #define	CL_PREEMPT(tp)		(*(tp)->t_clfuncs->cl_preempt)(tp)
184*7c478bd9Sstevel@tonic-gate 
185*7c478bd9Sstevel@tonic-gate #define	CL_SETRUN(tp)		(*(tp)->t_clfuncs->cl_setrun)(tp)
186*7c478bd9Sstevel@tonic-gate 
187*7c478bd9Sstevel@tonic-gate #define	CL_SLEEP(tp)		(*(tp)->t_clfuncs->cl_sleep)(tp)
188*7c478bd9Sstevel@tonic-gate 
189*7c478bd9Sstevel@tonic-gate #define	CL_STOP(t, why, what)	(*(t)->t_clfuncs->cl_stop)(t, why, what)
190*7c478bd9Sstevel@tonic-gate 
191*7c478bd9Sstevel@tonic-gate #define	CL_EXIT(t)		(*(t)->t_clfuncs->cl_exit)(t)
192*7c478bd9Sstevel@tonic-gate 
193*7c478bd9Sstevel@tonic-gate #define	CL_ACTIVE(t)		(*(t)->t_clfuncs->cl_active)(t)
194*7c478bd9Sstevel@tonic-gate 
195*7c478bd9Sstevel@tonic-gate #define	CL_INACTIVE(t)		(*(t)->t_clfuncs->cl_inactive)(t)
196*7c478bd9Sstevel@tonic-gate 
197*7c478bd9Sstevel@tonic-gate #define	CL_SWAPIN(t, flags)	(*(t)->t_clfuncs->cl_swapin)(t, flags)
198*7c478bd9Sstevel@tonic-gate 
199*7c478bd9Sstevel@tonic-gate #define	CL_SWAPOUT(t, flags)	(*(t)->t_clfuncs->cl_swapout)(t, flags)
200*7c478bd9Sstevel@tonic-gate 
201*7c478bd9Sstevel@tonic-gate #define	CL_TICK(t)		(*(t)->t_clfuncs->cl_tick)(t)
202*7c478bd9Sstevel@tonic-gate 
203*7c478bd9Sstevel@tonic-gate #define	CL_TRAPRET(t)		(*(t)->t_clfuncs->cl_trapret)(t)
204*7c478bd9Sstevel@tonic-gate 
205*7c478bd9Sstevel@tonic-gate #define	CL_WAKEUP(t)		(*(t)->t_clfuncs->cl_wakeup)(t)
206*7c478bd9Sstevel@tonic-gate 
207*7c478bd9Sstevel@tonic-gate #define	CL_DONICE(t, cr, inc, ret) \
208*7c478bd9Sstevel@tonic-gate 	(*(t)->t_clfuncs->cl_donice)(t, cr, inc, ret)
209*7c478bd9Sstevel@tonic-gate 
210*7c478bd9Sstevel@tonic-gate #define	CL_GLOBPRI(t)		(*(t)->t_clfuncs->cl_globpri)(t)
211*7c478bd9Sstevel@tonic-gate 
212*7c478bd9Sstevel@tonic-gate #define	CL_SET_PROCESS_GROUP(t, s, b, f) \
213*7c478bd9Sstevel@tonic-gate 	(*(t)->t_clfuncs->cl_set_process_group)(s, b, f)
214*7c478bd9Sstevel@tonic-gate 
215*7c478bd9Sstevel@tonic-gate #define	CL_YIELD(tp)		(*(tp)->t_clfuncs->cl_yield)(tp)
216*7c478bd9Sstevel@tonic-gate 
217*7c478bd9Sstevel@tonic-gate #define	CL_ALLOC(pp, cid, flag)	\
218*7c478bd9Sstevel@tonic-gate 	(sclass[cid].cl_funcs->sclass.cl_alloc) (pp, flag)
219*7c478bd9Sstevel@tonic-gate 
220*7c478bd9Sstevel@tonic-gate #define	CL_FREE(cid, bufp)	(sclass[cid].cl_funcs->sclass.cl_free) (bufp)
221*7c478bd9Sstevel@tonic-gate 
222*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
223*7c478bd9Sstevel@tonic-gate }
224*7c478bd9Sstevel@tonic-gate #endif
225*7c478bd9Sstevel@tonic-gate 
226*7c478bd9Sstevel@tonic-gate #endif	/* _SYS_CLASS_H */
227