xref: /onnv-gate/usr/src/uts/common/sys/class.h (revision 2712:f74a135872bc)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*2712Snn35248  * Common Development and Distribution License (the "License").
6*2712Snn35248  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*2712Snn35248  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate /*	Copyright (c) 1988 AT&T	*/
270Sstevel@tonic-gate /*	  All Rights Reserved  	*/
280Sstevel@tonic-gate 
290Sstevel@tonic-gate 
300Sstevel@tonic-gate #ifndef _SYS_CLASS_H
310Sstevel@tonic-gate #define	_SYS_CLASS_H
320Sstevel@tonic-gate 
330Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
340Sstevel@tonic-gate 
350Sstevel@tonic-gate #include <sys/t_lock.h>
360Sstevel@tonic-gate #include <sys/cred.h>
370Sstevel@tonic-gate #include <sys/thread.h>
380Sstevel@tonic-gate #include <sys/priocntl.h>
390Sstevel@tonic-gate #include <sys/mutex.h>
40*2712Snn35248 #include <sys/uio.h>
410Sstevel@tonic-gate 
420Sstevel@tonic-gate #ifdef	__cplusplus
430Sstevel@tonic-gate extern "C" {
440Sstevel@tonic-gate #endif
450Sstevel@tonic-gate 
460Sstevel@tonic-gate /*
470Sstevel@tonic-gate  * NOTE: Developers making use of the scheduler class switch mechanism
480Sstevel@tonic-gate  * to develop scheduling class modules should be aware that the
490Sstevel@tonic-gate  * architecture is not frozen and the kernel interface for scheduling
500Sstevel@tonic-gate  * class modules may change in future releases of System V.  Support
510Sstevel@tonic-gate  * for the current interface is not guaranteed and class modules
520Sstevel@tonic-gate  * developed to this interface may require changes in order to work
530Sstevel@tonic-gate  * with future releases of the system.
540Sstevel@tonic-gate  */
550Sstevel@tonic-gate 
560Sstevel@tonic-gate /*
570Sstevel@tonic-gate  * three different ops vectors are bundled together, here.
580Sstevel@tonic-gate  * one is for each of the fundamental objects acted upon
590Sstevel@tonic-gate  * by these operators: procs, threads, and the class manager itself.
600Sstevel@tonic-gate  */
610Sstevel@tonic-gate 
620Sstevel@tonic-gate typedef struct class_ops {
630Sstevel@tonic-gate 	int	(*cl_admin)(caddr_t, cred_t *);
640Sstevel@tonic-gate 	int	(*cl_getclinfo)(void *);
650Sstevel@tonic-gate 	int	(*cl_parmsin)(void *);
660Sstevel@tonic-gate 	int	(*cl_parmsout)(void *, pc_vaparms_t *);
670Sstevel@tonic-gate 	int	(*cl_vaparmsin)(void *, pc_vaparms_t *);
680Sstevel@tonic-gate 	int	(*cl_vaparmsout)(void *, pc_vaparms_t *);
690Sstevel@tonic-gate 	int	(*cl_getclpri)(pcpri_t *);
700Sstevel@tonic-gate 	int	(*cl_alloc)(void **, int);
710Sstevel@tonic-gate 	void	(*cl_free)(void *);
720Sstevel@tonic-gate } class_ops_t;
730Sstevel@tonic-gate 
740Sstevel@tonic-gate typedef struct thread_ops {
750Sstevel@tonic-gate 	int	(*cl_enterclass)(kthread_id_t, id_t, void *, cred_t *, void *);
760Sstevel@tonic-gate 	void	(*cl_exitclass)(void *);
770Sstevel@tonic-gate 	int	(*cl_canexit)(kthread_id_t, cred_t *);
780Sstevel@tonic-gate 	int	(*cl_fork)(kthread_id_t, kthread_id_t, void *);
790Sstevel@tonic-gate 	void	(*cl_forkret)(kthread_id_t, kthread_id_t);
800Sstevel@tonic-gate 	void	(*cl_parmsget)(kthread_id_t, void *);
810Sstevel@tonic-gate 	int	(*cl_parmsset)(kthread_id_t, void *, id_t, cred_t *);
820Sstevel@tonic-gate 	void	(*cl_stop)(kthread_id_t, int, int);
830Sstevel@tonic-gate 	void	(*cl_exit)(kthread_id_t);
840Sstevel@tonic-gate 	void	(*cl_active)(kthread_id_t);
850Sstevel@tonic-gate 	void	(*cl_inactive)(kthread_id_t);
860Sstevel@tonic-gate 	pri_t	(*cl_swapin)(kthread_id_t, int);
870Sstevel@tonic-gate 	pri_t 	(*cl_swapout)(kthread_id_t, int);
880Sstevel@tonic-gate 	void 	(*cl_trapret)(kthread_id_t);
890Sstevel@tonic-gate 	void	(*cl_preempt)(kthread_id_t);
900Sstevel@tonic-gate 	void	(*cl_setrun)(kthread_id_t);
910Sstevel@tonic-gate 	void	(*cl_sleep)(kthread_id_t);
920Sstevel@tonic-gate 	void	(*cl_tick)(kthread_id_t);
930Sstevel@tonic-gate 	void	(*cl_wakeup)(kthread_id_t);
940Sstevel@tonic-gate 	int	(*cl_donice)(kthread_id_t, cred_t *, int, int *);
950Sstevel@tonic-gate 	pri_t	(*cl_globpri)(kthread_id_t);
960Sstevel@tonic-gate 	void	(*cl_set_process_group)(pid_t, pid_t, pid_t);
970Sstevel@tonic-gate 	void	(*cl_yield)(kthread_id_t);
980Sstevel@tonic-gate } thread_ops_t;
990Sstevel@tonic-gate 
1000Sstevel@tonic-gate typedef struct classfuncs {
1010Sstevel@tonic-gate 	class_ops_t	sclass;
1020Sstevel@tonic-gate 	thread_ops_t	thread;
1030Sstevel@tonic-gate } classfuncs_t;
1040Sstevel@tonic-gate 
1050Sstevel@tonic-gate typedef struct sclass {
1060Sstevel@tonic-gate 	char		*cl_name;	/* class name */
1070Sstevel@tonic-gate 	/* class specific initialization function */
1080Sstevel@tonic-gate 	pri_t		(*cl_init)(id_t, int, classfuncs_t **);
1090Sstevel@tonic-gate 	classfuncs_t	*cl_funcs;	/* pointer to classfuncs structure */
1100Sstevel@tonic-gate 	krwlock_t	*cl_lock;	/* class structure read/write lock */
1110Sstevel@tonic-gate 	int		cl_count;	/* # of threads trying to load class */
1120Sstevel@tonic-gate } sclass_t;
1130Sstevel@tonic-gate 
1140Sstevel@tonic-gate #define	STATIC_SCHED		(krwlock_t *)0xffffffff
1150Sstevel@tonic-gate #define	LOADABLE_SCHED(s)	((s)->cl_lock != STATIC_SCHED)
1160Sstevel@tonic-gate #define	SCHED_INSTALLED(s)	((s)->cl_funcs != NULL)
1170Sstevel@tonic-gate #define	ALLOCATED_SCHED(s)	((s)->cl_lock != NULL)
1180Sstevel@tonic-gate 
1190Sstevel@tonic-gate #ifdef	_KERNEL
1200Sstevel@tonic-gate 
1210Sstevel@tonic-gate extern int	nclass;		/* number of configured scheduling classes */
1220Sstevel@tonic-gate extern char	*defaultclass;	/* default class for newproc'd processes */
1230Sstevel@tonic-gate extern struct sclass sclass[];	/* the class table */
1240Sstevel@tonic-gate extern kmutex_t	class_lock;	/* lock protecting class table */
1250Sstevel@tonic-gate extern int	loaded_classes;	/* number of classes loaded */
1260Sstevel@tonic-gate 
1270Sstevel@tonic-gate extern pri_t	minclsyspri;
1280Sstevel@tonic-gate extern id_t	syscid;		/* system scheduling class ID */
1290Sstevel@tonic-gate extern id_t	defaultcid;	/* "default" class id; see dispadmin(1M) */
1300Sstevel@tonic-gate 
131*2712Snn35248 extern int	alloc_cid(char *, id_t *);
132*2712Snn35248 extern int	scheduler_load(char *, sclass_t *);
133*2712Snn35248 extern int	getcid(char *, id_t *);
134*2712Snn35248 extern int	getcidbyname(char *, id_t *);
135*2712Snn35248 extern int	parmsin(pcparms_t *, pc_vaparms_t *);
136*2712Snn35248 extern int	parmsout(pcparms_t *, pc_vaparms_t *);
137*2712Snn35248 extern int	parmsset(pcparms_t *, kthread_id_t);
138*2712Snn35248 extern void	parmsget(kthread_id_t, pcparms_t *);
139*2712Snn35248 extern int	vaparmsout(char *, pcparms_t *, pc_vaparms_t *, uio_seg_t);
1400Sstevel@tonic-gate 
1410Sstevel@tonic-gate #endif
1420Sstevel@tonic-gate 
1430Sstevel@tonic-gate #define	CL_ADMIN(clp, uaddr, reqpcredp) \
1440Sstevel@tonic-gate 	(*(clp)->cl_funcs->sclass.cl_admin)(uaddr, reqpcredp)
1450Sstevel@tonic-gate 
1460Sstevel@tonic-gate #define	CL_ENTERCLASS(t, cid, clparmsp, credp, bufp) \
1470Sstevel@tonic-gate 	(sclass[cid].cl_funcs->thread.cl_enterclass) (t, cid, \
1480Sstevel@tonic-gate 	    (void *)clparmsp, credp, bufp)
1490Sstevel@tonic-gate 
1500Sstevel@tonic-gate #define	CL_EXITCLASS(cid, clprocp)\
1510Sstevel@tonic-gate 	(sclass[cid].cl_funcs->thread.cl_exitclass) ((void *)clprocp)
1520Sstevel@tonic-gate 
1530Sstevel@tonic-gate #define	CL_CANEXIT(t, cr)	(*(t)->t_clfuncs->cl_canexit)(t, cr)
1540Sstevel@tonic-gate 
1550Sstevel@tonic-gate #define	CL_FORK(tp, ct, bufp)	(*(tp)->t_clfuncs->cl_fork)(tp, ct, bufp)
1560Sstevel@tonic-gate 
1570Sstevel@tonic-gate #define	CL_FORKRET(t, ct)	(*(t)->t_clfuncs->cl_forkret)(t, ct)
1580Sstevel@tonic-gate 
1590Sstevel@tonic-gate #define	CL_GETCLINFO(clp, clinfop) \
1600Sstevel@tonic-gate 	(*(clp)->cl_funcs->sclass.cl_getclinfo)((void *)clinfop)
1610Sstevel@tonic-gate 
1620Sstevel@tonic-gate #define	CL_GETCLPRI(clp, clprip) \
1630Sstevel@tonic-gate 	(*(clp)->cl_funcs->sclass.cl_getclpri)(clprip)
1640Sstevel@tonic-gate 
1650Sstevel@tonic-gate #define	CL_PARMSGET(t, clparmsp) \
1660Sstevel@tonic-gate 	(*(t)->t_clfuncs->cl_parmsget)(t, (void *)clparmsp)
1670Sstevel@tonic-gate 
1680Sstevel@tonic-gate #define	CL_PARMSIN(clp, clparmsp) \
1690Sstevel@tonic-gate 	(clp)->cl_funcs->sclass.cl_parmsin((void *)clparmsp)
1700Sstevel@tonic-gate 
1710Sstevel@tonic-gate #define	CL_PARMSOUT(clp, clparmsp, vaparmsp) \
1720Sstevel@tonic-gate 	(clp)->cl_funcs->sclass.cl_parmsout((void *)clparmsp, vaparmsp)
1730Sstevel@tonic-gate 
1740Sstevel@tonic-gate #define	CL_VAPARMSIN(clp, clparmsp, vaparmsp) \
1750Sstevel@tonic-gate 	(clp)->cl_funcs->sclass.cl_vaparmsin((void *)clparmsp, vaparmsp)
1760Sstevel@tonic-gate 
1770Sstevel@tonic-gate #define	CL_VAPARMSOUT(clp, clparmsp, vaparmsp) \
1780Sstevel@tonic-gate 	(clp)->cl_funcs->sclass.cl_vaparmsout((void *)clparmsp, vaparmsp)
1790Sstevel@tonic-gate 
1800Sstevel@tonic-gate #define	CL_PARMSSET(t, clparmsp, cid, curpcredp) \
1810Sstevel@tonic-gate 	(*(t)->t_clfuncs->cl_parmsset)(t, (void *)clparmsp, cid, curpcredp)
1820Sstevel@tonic-gate 
1830Sstevel@tonic-gate #define	CL_PREEMPT(tp)		(*(tp)->t_clfuncs->cl_preempt)(tp)
1840Sstevel@tonic-gate 
1850Sstevel@tonic-gate #define	CL_SETRUN(tp)		(*(tp)->t_clfuncs->cl_setrun)(tp)
1860Sstevel@tonic-gate 
1870Sstevel@tonic-gate #define	CL_SLEEP(tp)		(*(tp)->t_clfuncs->cl_sleep)(tp)
1880Sstevel@tonic-gate 
1890Sstevel@tonic-gate #define	CL_STOP(t, why, what)	(*(t)->t_clfuncs->cl_stop)(t, why, what)
1900Sstevel@tonic-gate 
1910Sstevel@tonic-gate #define	CL_EXIT(t)		(*(t)->t_clfuncs->cl_exit)(t)
1920Sstevel@tonic-gate 
1930Sstevel@tonic-gate #define	CL_ACTIVE(t)		(*(t)->t_clfuncs->cl_active)(t)
1940Sstevel@tonic-gate 
1950Sstevel@tonic-gate #define	CL_INACTIVE(t)		(*(t)->t_clfuncs->cl_inactive)(t)
1960Sstevel@tonic-gate 
1970Sstevel@tonic-gate #define	CL_SWAPIN(t, flags)	(*(t)->t_clfuncs->cl_swapin)(t, flags)
1980Sstevel@tonic-gate 
1990Sstevel@tonic-gate #define	CL_SWAPOUT(t, flags)	(*(t)->t_clfuncs->cl_swapout)(t, flags)
2000Sstevel@tonic-gate 
2010Sstevel@tonic-gate #define	CL_TICK(t)		(*(t)->t_clfuncs->cl_tick)(t)
2020Sstevel@tonic-gate 
2030Sstevel@tonic-gate #define	CL_TRAPRET(t)		(*(t)->t_clfuncs->cl_trapret)(t)
2040Sstevel@tonic-gate 
2050Sstevel@tonic-gate #define	CL_WAKEUP(t)		(*(t)->t_clfuncs->cl_wakeup)(t)
2060Sstevel@tonic-gate 
2070Sstevel@tonic-gate #define	CL_DONICE(t, cr, inc, ret) \
2080Sstevel@tonic-gate 	(*(t)->t_clfuncs->cl_donice)(t, cr, inc, ret)
2090Sstevel@tonic-gate 
2100Sstevel@tonic-gate #define	CL_GLOBPRI(t)		(*(t)->t_clfuncs->cl_globpri)(t)
2110Sstevel@tonic-gate 
2120Sstevel@tonic-gate #define	CL_SET_PROCESS_GROUP(t, s, b, f) \
2130Sstevel@tonic-gate 	(*(t)->t_clfuncs->cl_set_process_group)(s, b, f)
2140Sstevel@tonic-gate 
2150Sstevel@tonic-gate #define	CL_YIELD(tp)		(*(tp)->t_clfuncs->cl_yield)(tp)
2160Sstevel@tonic-gate 
2170Sstevel@tonic-gate #define	CL_ALLOC(pp, cid, flag)	\
2180Sstevel@tonic-gate 	(sclass[cid].cl_funcs->sclass.cl_alloc) (pp, flag)
2190Sstevel@tonic-gate 
2200Sstevel@tonic-gate #define	CL_FREE(cid, bufp)	(sclass[cid].cl_funcs->sclass.cl_free) (bufp)
2210Sstevel@tonic-gate 
2220Sstevel@tonic-gate #ifdef	__cplusplus
2230Sstevel@tonic-gate }
2240Sstevel@tonic-gate #endif
2250Sstevel@tonic-gate 
2260Sstevel@tonic-gate #endif	/* _SYS_CLASS_H */
227