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 52712Snn35248 * Common Development and Distribution License (the "License"). 62712Snn35248 * 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 */ 216247Sraf 220Sstevel@tonic-gate /* 23*11173SJonathan.Adams@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate /* Copyright (c) 1988 AT&T */ 280Sstevel@tonic-gate /* All Rights Reserved */ 290Sstevel@tonic-gate 300Sstevel@tonic-gate #ifndef _SYS_CLASS_H 310Sstevel@tonic-gate #define _SYS_CLASS_H 320Sstevel@tonic-gate 330Sstevel@tonic-gate #include <sys/t_lock.h> 340Sstevel@tonic-gate #include <sys/cred.h> 350Sstevel@tonic-gate #include <sys/thread.h> 360Sstevel@tonic-gate #include <sys/priocntl.h> 370Sstevel@tonic-gate #include <sys/mutex.h> 382712Snn35248 #include <sys/uio.h> 390Sstevel@tonic-gate 400Sstevel@tonic-gate #ifdef __cplusplus 410Sstevel@tonic-gate extern "C" { 420Sstevel@tonic-gate #endif 430Sstevel@tonic-gate 440Sstevel@tonic-gate /* 450Sstevel@tonic-gate * NOTE: Developers making use of the scheduler class switch mechanism 460Sstevel@tonic-gate * to develop scheduling class modules should be aware that the 470Sstevel@tonic-gate * architecture is not frozen and the kernel interface for scheduling 480Sstevel@tonic-gate * class modules may change in future releases of System V. Support 490Sstevel@tonic-gate * for the current interface is not guaranteed and class modules 500Sstevel@tonic-gate * developed to this interface may require changes in order to work 510Sstevel@tonic-gate * with future releases of the system. 520Sstevel@tonic-gate */ 530Sstevel@tonic-gate 540Sstevel@tonic-gate /* 550Sstevel@tonic-gate * three different ops vectors are bundled together, here. 560Sstevel@tonic-gate * one is for each of the fundamental objects acted upon 570Sstevel@tonic-gate * by these operators: procs, threads, and the class manager itself. 580Sstevel@tonic-gate */ 590Sstevel@tonic-gate 600Sstevel@tonic-gate typedef struct class_ops { 610Sstevel@tonic-gate int (*cl_admin)(caddr_t, cred_t *); 620Sstevel@tonic-gate int (*cl_getclinfo)(void *); 630Sstevel@tonic-gate int (*cl_parmsin)(void *); 640Sstevel@tonic-gate int (*cl_parmsout)(void *, pc_vaparms_t *); 650Sstevel@tonic-gate int (*cl_vaparmsin)(void *, pc_vaparms_t *); 660Sstevel@tonic-gate int (*cl_vaparmsout)(void *, pc_vaparms_t *); 670Sstevel@tonic-gate int (*cl_getclpri)(pcpri_t *); 680Sstevel@tonic-gate int (*cl_alloc)(void **, int); 690Sstevel@tonic-gate void (*cl_free)(void *); 700Sstevel@tonic-gate } class_ops_t; 710Sstevel@tonic-gate 720Sstevel@tonic-gate typedef struct thread_ops { 736247Sraf int (*cl_enterclass)(kthread_t *, id_t, void *, cred_t *, void *); 740Sstevel@tonic-gate void (*cl_exitclass)(void *); 756247Sraf int (*cl_canexit)(kthread_t *, cred_t *); 766247Sraf int (*cl_fork)(kthread_t *, kthread_t *, void *); 776247Sraf void (*cl_forkret)(kthread_t *, kthread_t *); 786247Sraf void (*cl_parmsget)(kthread_t *, void *); 796247Sraf int (*cl_parmsset)(kthread_t *, void *, id_t, cred_t *); 806247Sraf void (*cl_stop)(kthread_t *, int, int); 816247Sraf void (*cl_exit)(kthread_t *); 826247Sraf void (*cl_active)(kthread_t *); 836247Sraf void (*cl_inactive)(kthread_t *); 846247Sraf pri_t (*cl_swapin)(kthread_t *, int); 856247Sraf pri_t (*cl_swapout)(kthread_t *, int); 866247Sraf void (*cl_trapret)(kthread_t *); 876247Sraf void (*cl_preempt)(kthread_t *); 886247Sraf void (*cl_setrun)(kthread_t *); 896247Sraf void (*cl_sleep)(kthread_t *); 906247Sraf void (*cl_tick)(kthread_t *); 916247Sraf void (*cl_wakeup)(kthread_t *); 926247Sraf int (*cl_donice)(kthread_t *, cred_t *, int, int *); 936247Sraf pri_t (*cl_globpri)(kthread_t *); 940Sstevel@tonic-gate void (*cl_set_process_group)(pid_t, pid_t, pid_t); 956247Sraf void (*cl_yield)(kthread_t *); 966247Sraf int (*cl_doprio)(kthread_t *, cred_t *, int, int *); 970Sstevel@tonic-gate } thread_ops_t; 980Sstevel@tonic-gate 990Sstevel@tonic-gate typedef struct classfuncs { 1000Sstevel@tonic-gate class_ops_t sclass; 1010Sstevel@tonic-gate thread_ops_t thread; 1020Sstevel@tonic-gate } classfuncs_t; 1030Sstevel@tonic-gate 1040Sstevel@tonic-gate typedef struct sclass { 1050Sstevel@tonic-gate char *cl_name; /* class name */ 1060Sstevel@tonic-gate /* class specific initialization function */ 1070Sstevel@tonic-gate pri_t (*cl_init)(id_t, int, classfuncs_t **); 1080Sstevel@tonic-gate classfuncs_t *cl_funcs; /* pointer to classfuncs structure */ 1090Sstevel@tonic-gate krwlock_t *cl_lock; /* class structure read/write lock */ 1100Sstevel@tonic-gate int cl_count; /* # of threads trying to load class */ 1110Sstevel@tonic-gate } sclass_t; 1120Sstevel@tonic-gate 1130Sstevel@tonic-gate #define STATIC_SCHED (krwlock_t *)0xffffffff 1140Sstevel@tonic-gate #define LOADABLE_SCHED(s) ((s)->cl_lock != STATIC_SCHED) 1150Sstevel@tonic-gate #define SCHED_INSTALLED(s) ((s)->cl_funcs != NULL) 1160Sstevel@tonic-gate #define ALLOCATED_SCHED(s) ((s)->cl_lock != NULL) 1170Sstevel@tonic-gate 1180Sstevel@tonic-gate #ifdef _KERNEL 1190Sstevel@tonic-gate 120*11173SJonathan.Adams@Sun.COM #define CLASS_KERNEL(cid) ((cid) == syscid || (cid) == sysdccid) 121*11173SJonathan.Adams@Sun.COM 1220Sstevel@tonic-gate extern int nclass; /* number of configured scheduling classes */ 1230Sstevel@tonic-gate extern char *defaultclass; /* default class for newproc'd processes */ 1240Sstevel@tonic-gate extern struct sclass sclass[]; /* the class table */ 1250Sstevel@tonic-gate extern kmutex_t class_lock; /* lock protecting class table */ 1260Sstevel@tonic-gate extern int loaded_classes; /* number of classes loaded */ 1270Sstevel@tonic-gate 1280Sstevel@tonic-gate extern pri_t minclsyspri; 1290Sstevel@tonic-gate extern id_t syscid; /* system scheduling class ID */ 130*11173SJonathan.Adams@Sun.COM extern id_t sysdccid; /* system duty-cycle scheduling class ID */ 1310Sstevel@tonic-gate extern id_t defaultcid; /* "default" class id; see dispadmin(1M) */ 1320Sstevel@tonic-gate 1332712Snn35248 extern int alloc_cid(char *, id_t *); 1342712Snn35248 extern int scheduler_load(char *, sclass_t *); 1352712Snn35248 extern int getcid(char *, id_t *); 1362712Snn35248 extern int getcidbyname(char *, id_t *); 1372712Snn35248 extern int parmsin(pcparms_t *, pc_vaparms_t *); 1382712Snn35248 extern int parmsout(pcparms_t *, pc_vaparms_t *); 1396247Sraf extern int parmsset(pcparms_t *, kthread_t *); 1406247Sraf extern void parmsget(kthread_t *, pcparms_t *); 1412712Snn35248 extern int vaparmsout(char *, pcparms_t *, pc_vaparms_t *, uio_seg_t); 1420Sstevel@tonic-gate 1430Sstevel@tonic-gate #endif 1440Sstevel@tonic-gate 1450Sstevel@tonic-gate #define CL_ADMIN(clp, uaddr, reqpcredp) \ 1460Sstevel@tonic-gate (*(clp)->cl_funcs->sclass.cl_admin)(uaddr, reqpcredp) 1470Sstevel@tonic-gate 1480Sstevel@tonic-gate #define CL_ENTERCLASS(t, cid, clparmsp, credp, bufp) \ 1490Sstevel@tonic-gate (sclass[cid].cl_funcs->thread.cl_enterclass) (t, cid, \ 1500Sstevel@tonic-gate (void *)clparmsp, credp, bufp) 1510Sstevel@tonic-gate 1520Sstevel@tonic-gate #define CL_EXITCLASS(cid, clprocp)\ 1530Sstevel@tonic-gate (sclass[cid].cl_funcs->thread.cl_exitclass) ((void *)clprocp) 1540Sstevel@tonic-gate 1550Sstevel@tonic-gate #define CL_CANEXIT(t, cr) (*(t)->t_clfuncs->cl_canexit)(t, cr) 1560Sstevel@tonic-gate 1570Sstevel@tonic-gate #define CL_FORK(tp, ct, bufp) (*(tp)->t_clfuncs->cl_fork)(tp, ct, bufp) 1580Sstevel@tonic-gate 1590Sstevel@tonic-gate #define CL_FORKRET(t, ct) (*(t)->t_clfuncs->cl_forkret)(t, ct) 1600Sstevel@tonic-gate 1610Sstevel@tonic-gate #define CL_GETCLINFO(clp, clinfop) \ 1620Sstevel@tonic-gate (*(clp)->cl_funcs->sclass.cl_getclinfo)((void *)clinfop) 1630Sstevel@tonic-gate 1640Sstevel@tonic-gate #define CL_GETCLPRI(clp, clprip) \ 1650Sstevel@tonic-gate (*(clp)->cl_funcs->sclass.cl_getclpri)(clprip) 1660Sstevel@tonic-gate 1670Sstevel@tonic-gate #define CL_PARMSGET(t, clparmsp) \ 1680Sstevel@tonic-gate (*(t)->t_clfuncs->cl_parmsget)(t, (void *)clparmsp) 1690Sstevel@tonic-gate 1700Sstevel@tonic-gate #define CL_PARMSIN(clp, clparmsp) \ 1710Sstevel@tonic-gate (clp)->cl_funcs->sclass.cl_parmsin((void *)clparmsp) 1720Sstevel@tonic-gate 1730Sstevel@tonic-gate #define CL_PARMSOUT(clp, clparmsp, vaparmsp) \ 1740Sstevel@tonic-gate (clp)->cl_funcs->sclass.cl_parmsout((void *)clparmsp, vaparmsp) 1750Sstevel@tonic-gate 1760Sstevel@tonic-gate #define CL_VAPARMSIN(clp, clparmsp, vaparmsp) \ 1770Sstevel@tonic-gate (clp)->cl_funcs->sclass.cl_vaparmsin((void *)clparmsp, vaparmsp) 1780Sstevel@tonic-gate 1790Sstevel@tonic-gate #define CL_VAPARMSOUT(clp, clparmsp, vaparmsp) \ 1800Sstevel@tonic-gate (clp)->cl_funcs->sclass.cl_vaparmsout((void *)clparmsp, vaparmsp) 1810Sstevel@tonic-gate 1820Sstevel@tonic-gate #define CL_PARMSSET(t, clparmsp, cid, curpcredp) \ 1830Sstevel@tonic-gate (*(t)->t_clfuncs->cl_parmsset)(t, (void *)clparmsp, cid, curpcredp) 1840Sstevel@tonic-gate 1850Sstevel@tonic-gate #define CL_PREEMPT(tp) (*(tp)->t_clfuncs->cl_preempt)(tp) 1860Sstevel@tonic-gate 1870Sstevel@tonic-gate #define CL_SETRUN(tp) (*(tp)->t_clfuncs->cl_setrun)(tp) 1880Sstevel@tonic-gate 1890Sstevel@tonic-gate #define CL_SLEEP(tp) (*(tp)->t_clfuncs->cl_sleep)(tp) 1900Sstevel@tonic-gate 1910Sstevel@tonic-gate #define CL_STOP(t, why, what) (*(t)->t_clfuncs->cl_stop)(t, why, what) 1920Sstevel@tonic-gate 1930Sstevel@tonic-gate #define CL_EXIT(t) (*(t)->t_clfuncs->cl_exit)(t) 1940Sstevel@tonic-gate 1950Sstevel@tonic-gate #define CL_ACTIVE(t) (*(t)->t_clfuncs->cl_active)(t) 1960Sstevel@tonic-gate 1970Sstevel@tonic-gate #define CL_INACTIVE(t) (*(t)->t_clfuncs->cl_inactive)(t) 1980Sstevel@tonic-gate 1990Sstevel@tonic-gate #define CL_SWAPIN(t, flags) (*(t)->t_clfuncs->cl_swapin)(t, flags) 2000Sstevel@tonic-gate 2010Sstevel@tonic-gate #define CL_SWAPOUT(t, flags) (*(t)->t_clfuncs->cl_swapout)(t, flags) 2020Sstevel@tonic-gate 2030Sstevel@tonic-gate #define CL_TICK(t) (*(t)->t_clfuncs->cl_tick)(t) 2040Sstevel@tonic-gate 2050Sstevel@tonic-gate #define CL_TRAPRET(t) (*(t)->t_clfuncs->cl_trapret)(t) 2060Sstevel@tonic-gate 2070Sstevel@tonic-gate #define CL_WAKEUP(t) (*(t)->t_clfuncs->cl_wakeup)(t) 2080Sstevel@tonic-gate 2090Sstevel@tonic-gate #define CL_DONICE(t, cr, inc, ret) \ 2100Sstevel@tonic-gate (*(t)->t_clfuncs->cl_donice)(t, cr, inc, ret) 2110Sstevel@tonic-gate 2126247Sraf #define CL_DOPRIO(t, cr, inc, ret) \ 2136247Sraf (*(t)->t_clfuncs->cl_doprio)(t, cr, inc, ret) 2146247Sraf 2150Sstevel@tonic-gate #define CL_GLOBPRI(t) (*(t)->t_clfuncs->cl_globpri)(t) 2160Sstevel@tonic-gate 2170Sstevel@tonic-gate #define CL_SET_PROCESS_GROUP(t, s, b, f) \ 2180Sstevel@tonic-gate (*(t)->t_clfuncs->cl_set_process_group)(s, b, f) 2190Sstevel@tonic-gate 2200Sstevel@tonic-gate #define CL_YIELD(tp) (*(tp)->t_clfuncs->cl_yield)(tp) 2210Sstevel@tonic-gate 2220Sstevel@tonic-gate #define CL_ALLOC(pp, cid, flag) \ 2230Sstevel@tonic-gate (sclass[cid].cl_funcs->sclass.cl_alloc) (pp, flag) 2240Sstevel@tonic-gate 2250Sstevel@tonic-gate #define CL_FREE(cid, bufp) (sclass[cid].cl_funcs->sclass.cl_free) (bufp) 2260Sstevel@tonic-gate 2270Sstevel@tonic-gate #ifdef __cplusplus 2280Sstevel@tonic-gate } 2290Sstevel@tonic-gate #endif 2300Sstevel@tonic-gate 2310Sstevel@tonic-gate #endif /* _SYS_CLASS_H */ 232