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