xref: /titanic_54/usr/src/uts/common/sys/class.h (revision 9acbbeaf2a1ffe5c14b244867d427714fab43c5c)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*9acbbeafSnn35248  * Common Development and Distribution License (the "License").
6*9acbbeafSnn35248  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*9acbbeafSnn35248  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate /*	Copyright (c) 1988 AT&T	*/
277c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #ifndef _SYS_CLASS_H
317c478bd9Sstevel@tonic-gate #define	_SYS_CLASS_H
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate #include <sys/t_lock.h>
367c478bd9Sstevel@tonic-gate #include <sys/cred.h>
377c478bd9Sstevel@tonic-gate #include <sys/thread.h>
387c478bd9Sstevel@tonic-gate #include <sys/priocntl.h>
397c478bd9Sstevel@tonic-gate #include <sys/mutex.h>
40*9acbbeafSnn35248 #include <sys/uio.h>
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
437c478bd9Sstevel@tonic-gate extern "C" {
447c478bd9Sstevel@tonic-gate #endif
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate /*
477c478bd9Sstevel@tonic-gate  * NOTE: Developers making use of the scheduler class switch mechanism
487c478bd9Sstevel@tonic-gate  * to develop scheduling class modules should be aware that the
497c478bd9Sstevel@tonic-gate  * architecture is not frozen and the kernel interface for scheduling
507c478bd9Sstevel@tonic-gate  * class modules may change in future releases of System V.  Support
517c478bd9Sstevel@tonic-gate  * for the current interface is not guaranteed and class modules
527c478bd9Sstevel@tonic-gate  * developed to this interface may require changes in order to work
537c478bd9Sstevel@tonic-gate  * with future releases of the system.
547c478bd9Sstevel@tonic-gate  */
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate /*
577c478bd9Sstevel@tonic-gate  * three different ops vectors are bundled together, here.
587c478bd9Sstevel@tonic-gate  * one is for each of the fundamental objects acted upon
597c478bd9Sstevel@tonic-gate  * by these operators: procs, threads, and the class manager itself.
607c478bd9Sstevel@tonic-gate  */
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate typedef struct class_ops {
637c478bd9Sstevel@tonic-gate 	int	(*cl_admin)(caddr_t, cred_t *);
647c478bd9Sstevel@tonic-gate 	int	(*cl_getclinfo)(void *);
657c478bd9Sstevel@tonic-gate 	int	(*cl_parmsin)(void *);
667c478bd9Sstevel@tonic-gate 	int	(*cl_parmsout)(void *, pc_vaparms_t *);
677c478bd9Sstevel@tonic-gate 	int	(*cl_vaparmsin)(void *, pc_vaparms_t *);
687c478bd9Sstevel@tonic-gate 	int	(*cl_vaparmsout)(void *, pc_vaparms_t *);
697c478bd9Sstevel@tonic-gate 	int	(*cl_getclpri)(pcpri_t *);
707c478bd9Sstevel@tonic-gate 	int	(*cl_alloc)(void **, int);
717c478bd9Sstevel@tonic-gate 	void	(*cl_free)(void *);
727c478bd9Sstevel@tonic-gate } class_ops_t;
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate typedef struct thread_ops {
757c478bd9Sstevel@tonic-gate 	int	(*cl_enterclass)(kthread_id_t, id_t, void *, cred_t *, void *);
767c478bd9Sstevel@tonic-gate 	void	(*cl_exitclass)(void *);
777c478bd9Sstevel@tonic-gate 	int	(*cl_canexit)(kthread_id_t, cred_t *);
787c478bd9Sstevel@tonic-gate 	int	(*cl_fork)(kthread_id_t, kthread_id_t, void *);
797c478bd9Sstevel@tonic-gate 	void	(*cl_forkret)(kthread_id_t, kthread_id_t);
807c478bd9Sstevel@tonic-gate 	void	(*cl_parmsget)(kthread_id_t, void *);
817c478bd9Sstevel@tonic-gate 	int	(*cl_parmsset)(kthread_id_t, void *, id_t, cred_t *);
827c478bd9Sstevel@tonic-gate 	void	(*cl_stop)(kthread_id_t, int, int);
837c478bd9Sstevel@tonic-gate 	void	(*cl_exit)(kthread_id_t);
847c478bd9Sstevel@tonic-gate 	void	(*cl_active)(kthread_id_t);
857c478bd9Sstevel@tonic-gate 	void	(*cl_inactive)(kthread_id_t);
867c478bd9Sstevel@tonic-gate 	pri_t	(*cl_swapin)(kthread_id_t, int);
877c478bd9Sstevel@tonic-gate 	pri_t 	(*cl_swapout)(kthread_id_t, int);
887c478bd9Sstevel@tonic-gate 	void 	(*cl_trapret)(kthread_id_t);
897c478bd9Sstevel@tonic-gate 	void	(*cl_preempt)(kthread_id_t);
907c478bd9Sstevel@tonic-gate 	void	(*cl_setrun)(kthread_id_t);
917c478bd9Sstevel@tonic-gate 	void	(*cl_sleep)(kthread_id_t);
927c478bd9Sstevel@tonic-gate 	void	(*cl_tick)(kthread_id_t);
937c478bd9Sstevel@tonic-gate 	void	(*cl_wakeup)(kthread_id_t);
947c478bd9Sstevel@tonic-gate 	int	(*cl_donice)(kthread_id_t, cred_t *, int, int *);
957c478bd9Sstevel@tonic-gate 	pri_t	(*cl_globpri)(kthread_id_t);
967c478bd9Sstevel@tonic-gate 	void	(*cl_set_process_group)(pid_t, pid_t, pid_t);
977c478bd9Sstevel@tonic-gate 	void	(*cl_yield)(kthread_id_t);
987c478bd9Sstevel@tonic-gate } thread_ops_t;
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate typedef struct classfuncs {
1017c478bd9Sstevel@tonic-gate 	class_ops_t	sclass;
1027c478bd9Sstevel@tonic-gate 	thread_ops_t	thread;
1037c478bd9Sstevel@tonic-gate } classfuncs_t;
1047c478bd9Sstevel@tonic-gate 
1057c478bd9Sstevel@tonic-gate typedef struct sclass {
1067c478bd9Sstevel@tonic-gate 	char		*cl_name;	/* class name */
1077c478bd9Sstevel@tonic-gate 	/* class specific initialization function */
1087c478bd9Sstevel@tonic-gate 	pri_t		(*cl_init)(id_t, int, classfuncs_t **);
1097c478bd9Sstevel@tonic-gate 	classfuncs_t	*cl_funcs;	/* pointer to classfuncs structure */
1107c478bd9Sstevel@tonic-gate 	krwlock_t	*cl_lock;	/* class structure read/write lock */
1117c478bd9Sstevel@tonic-gate 	int		cl_count;	/* # of threads trying to load class */
1127c478bd9Sstevel@tonic-gate } sclass_t;
1137c478bd9Sstevel@tonic-gate 
1147c478bd9Sstevel@tonic-gate #define	STATIC_SCHED		(krwlock_t *)0xffffffff
1157c478bd9Sstevel@tonic-gate #define	LOADABLE_SCHED(s)	((s)->cl_lock != STATIC_SCHED)
1167c478bd9Sstevel@tonic-gate #define	SCHED_INSTALLED(s)	((s)->cl_funcs != NULL)
1177c478bd9Sstevel@tonic-gate #define	ALLOCATED_SCHED(s)	((s)->cl_lock != NULL)
1187c478bd9Sstevel@tonic-gate 
1197c478bd9Sstevel@tonic-gate #ifdef	_KERNEL
1207c478bd9Sstevel@tonic-gate 
1217c478bd9Sstevel@tonic-gate extern int	nclass;		/* number of configured scheduling classes */
1227c478bd9Sstevel@tonic-gate extern char	*defaultclass;	/* default class for newproc'd processes */
1237c478bd9Sstevel@tonic-gate extern struct sclass sclass[];	/* the class table */
1247c478bd9Sstevel@tonic-gate extern kmutex_t	class_lock;	/* lock protecting class table */
1257c478bd9Sstevel@tonic-gate extern int	loaded_classes;	/* number of classes loaded */
1267c478bd9Sstevel@tonic-gate 
1277c478bd9Sstevel@tonic-gate extern pri_t	minclsyspri;
1287c478bd9Sstevel@tonic-gate extern id_t	syscid;		/* system scheduling class ID */
1297c478bd9Sstevel@tonic-gate extern id_t	defaultcid;	/* "default" class id; see dispadmin(1M) */
1307c478bd9Sstevel@tonic-gate 
1317c478bd9Sstevel@tonic-gate extern int	alloc_cid(char *, id_t *);
1327c478bd9Sstevel@tonic-gate extern int	scheduler_load(char *, sclass_t *);
1337c478bd9Sstevel@tonic-gate extern int	getcid(char *, id_t *);
1347c478bd9Sstevel@tonic-gate extern int	getcidbyname(char *, id_t *);
1357c478bd9Sstevel@tonic-gate extern int	parmsin(pcparms_t *, pc_vaparms_t *);
1367c478bd9Sstevel@tonic-gate extern int	parmsout(pcparms_t *, pc_vaparms_t *);
1377c478bd9Sstevel@tonic-gate extern int	parmsset(pcparms_t *, kthread_id_t);
1387c478bd9Sstevel@tonic-gate extern void	parmsget(kthread_id_t, pcparms_t *);
139*9acbbeafSnn35248 extern int	vaparmsout(char *, pcparms_t *, pc_vaparms_t *, uio_seg_t);
1407c478bd9Sstevel@tonic-gate 
1417c478bd9Sstevel@tonic-gate #endif
1427c478bd9Sstevel@tonic-gate 
1437c478bd9Sstevel@tonic-gate #define	CL_ADMIN(clp, uaddr, reqpcredp) \
1447c478bd9Sstevel@tonic-gate 	(*(clp)->cl_funcs->sclass.cl_admin)(uaddr, reqpcredp)
1457c478bd9Sstevel@tonic-gate 
1467c478bd9Sstevel@tonic-gate #define	CL_ENTERCLASS(t, cid, clparmsp, credp, bufp) \
1477c478bd9Sstevel@tonic-gate 	(sclass[cid].cl_funcs->thread.cl_enterclass) (t, cid, \
1487c478bd9Sstevel@tonic-gate 	    (void *)clparmsp, credp, bufp)
1497c478bd9Sstevel@tonic-gate 
1507c478bd9Sstevel@tonic-gate #define	CL_EXITCLASS(cid, clprocp)\
1517c478bd9Sstevel@tonic-gate 	(sclass[cid].cl_funcs->thread.cl_exitclass) ((void *)clprocp)
1527c478bd9Sstevel@tonic-gate 
1537c478bd9Sstevel@tonic-gate #define	CL_CANEXIT(t, cr)	(*(t)->t_clfuncs->cl_canexit)(t, cr)
1547c478bd9Sstevel@tonic-gate 
1557c478bd9Sstevel@tonic-gate #define	CL_FORK(tp, ct, bufp)	(*(tp)->t_clfuncs->cl_fork)(tp, ct, bufp)
1567c478bd9Sstevel@tonic-gate 
1577c478bd9Sstevel@tonic-gate #define	CL_FORKRET(t, ct)	(*(t)->t_clfuncs->cl_forkret)(t, ct)
1587c478bd9Sstevel@tonic-gate 
1597c478bd9Sstevel@tonic-gate #define	CL_GETCLINFO(clp, clinfop) \
1607c478bd9Sstevel@tonic-gate 	(*(clp)->cl_funcs->sclass.cl_getclinfo)((void *)clinfop)
1617c478bd9Sstevel@tonic-gate 
1627c478bd9Sstevel@tonic-gate #define	CL_GETCLPRI(clp, clprip) \
1637c478bd9Sstevel@tonic-gate 	(*(clp)->cl_funcs->sclass.cl_getclpri)(clprip)
1647c478bd9Sstevel@tonic-gate 
1657c478bd9Sstevel@tonic-gate #define	CL_PARMSGET(t, clparmsp) \
1667c478bd9Sstevel@tonic-gate 	(*(t)->t_clfuncs->cl_parmsget)(t, (void *)clparmsp)
1677c478bd9Sstevel@tonic-gate 
1687c478bd9Sstevel@tonic-gate #define	CL_PARMSIN(clp, clparmsp) \
1697c478bd9Sstevel@tonic-gate 	(clp)->cl_funcs->sclass.cl_parmsin((void *)clparmsp)
1707c478bd9Sstevel@tonic-gate 
1717c478bd9Sstevel@tonic-gate #define	CL_PARMSOUT(clp, clparmsp, vaparmsp) \
1727c478bd9Sstevel@tonic-gate 	(clp)->cl_funcs->sclass.cl_parmsout((void *)clparmsp, vaparmsp)
1737c478bd9Sstevel@tonic-gate 
1747c478bd9Sstevel@tonic-gate #define	CL_VAPARMSIN(clp, clparmsp, vaparmsp) \
1757c478bd9Sstevel@tonic-gate 	(clp)->cl_funcs->sclass.cl_vaparmsin((void *)clparmsp, vaparmsp)
1767c478bd9Sstevel@tonic-gate 
1777c478bd9Sstevel@tonic-gate #define	CL_VAPARMSOUT(clp, clparmsp, vaparmsp) \
1787c478bd9Sstevel@tonic-gate 	(clp)->cl_funcs->sclass.cl_vaparmsout((void *)clparmsp, vaparmsp)
1797c478bd9Sstevel@tonic-gate 
1807c478bd9Sstevel@tonic-gate #define	CL_PARMSSET(t, clparmsp, cid, curpcredp) \
1817c478bd9Sstevel@tonic-gate 	(*(t)->t_clfuncs->cl_parmsset)(t, (void *)clparmsp, cid, curpcredp)
1827c478bd9Sstevel@tonic-gate 
1837c478bd9Sstevel@tonic-gate #define	CL_PREEMPT(tp)		(*(tp)->t_clfuncs->cl_preempt)(tp)
1847c478bd9Sstevel@tonic-gate 
1857c478bd9Sstevel@tonic-gate #define	CL_SETRUN(tp)		(*(tp)->t_clfuncs->cl_setrun)(tp)
1867c478bd9Sstevel@tonic-gate 
1877c478bd9Sstevel@tonic-gate #define	CL_SLEEP(tp)		(*(tp)->t_clfuncs->cl_sleep)(tp)
1887c478bd9Sstevel@tonic-gate 
1897c478bd9Sstevel@tonic-gate #define	CL_STOP(t, why, what)	(*(t)->t_clfuncs->cl_stop)(t, why, what)
1907c478bd9Sstevel@tonic-gate 
1917c478bd9Sstevel@tonic-gate #define	CL_EXIT(t)		(*(t)->t_clfuncs->cl_exit)(t)
1927c478bd9Sstevel@tonic-gate 
1937c478bd9Sstevel@tonic-gate #define	CL_ACTIVE(t)		(*(t)->t_clfuncs->cl_active)(t)
1947c478bd9Sstevel@tonic-gate 
1957c478bd9Sstevel@tonic-gate #define	CL_INACTIVE(t)		(*(t)->t_clfuncs->cl_inactive)(t)
1967c478bd9Sstevel@tonic-gate 
1977c478bd9Sstevel@tonic-gate #define	CL_SWAPIN(t, flags)	(*(t)->t_clfuncs->cl_swapin)(t, flags)
1987c478bd9Sstevel@tonic-gate 
1997c478bd9Sstevel@tonic-gate #define	CL_SWAPOUT(t, flags)	(*(t)->t_clfuncs->cl_swapout)(t, flags)
2007c478bd9Sstevel@tonic-gate 
2017c478bd9Sstevel@tonic-gate #define	CL_TICK(t)		(*(t)->t_clfuncs->cl_tick)(t)
2027c478bd9Sstevel@tonic-gate 
2037c478bd9Sstevel@tonic-gate #define	CL_TRAPRET(t)		(*(t)->t_clfuncs->cl_trapret)(t)
2047c478bd9Sstevel@tonic-gate 
2057c478bd9Sstevel@tonic-gate #define	CL_WAKEUP(t)		(*(t)->t_clfuncs->cl_wakeup)(t)
2067c478bd9Sstevel@tonic-gate 
2077c478bd9Sstevel@tonic-gate #define	CL_DONICE(t, cr, inc, ret) \
2087c478bd9Sstevel@tonic-gate 	(*(t)->t_clfuncs->cl_donice)(t, cr, inc, ret)
2097c478bd9Sstevel@tonic-gate 
2107c478bd9Sstevel@tonic-gate #define	CL_GLOBPRI(t)		(*(t)->t_clfuncs->cl_globpri)(t)
2117c478bd9Sstevel@tonic-gate 
2127c478bd9Sstevel@tonic-gate #define	CL_SET_PROCESS_GROUP(t, s, b, f) \
2137c478bd9Sstevel@tonic-gate 	(*(t)->t_clfuncs->cl_set_process_group)(s, b, f)
2147c478bd9Sstevel@tonic-gate 
2157c478bd9Sstevel@tonic-gate #define	CL_YIELD(tp)		(*(tp)->t_clfuncs->cl_yield)(tp)
2167c478bd9Sstevel@tonic-gate 
2177c478bd9Sstevel@tonic-gate #define	CL_ALLOC(pp, cid, flag)	\
2187c478bd9Sstevel@tonic-gate 	(sclass[cid].cl_funcs->sclass.cl_alloc) (pp, flag)
2197c478bd9Sstevel@tonic-gate 
2207c478bd9Sstevel@tonic-gate #define	CL_FREE(cid, bufp)	(sclass[cid].cl_funcs->sclass.cl_free) (bufp)
2217c478bd9Sstevel@tonic-gate 
2227c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
2237c478bd9Sstevel@tonic-gate }
2247c478bd9Sstevel@tonic-gate #endif
2257c478bd9Sstevel@tonic-gate 
2267c478bd9Sstevel@tonic-gate #endif	/* _SYS_CLASS_H */
227