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 59acbbeafSnn35248 * Common Development and Distribution License (the "License"). 69acbbeafSnn35248 * 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 */ 21*d4204c85Sraf 227c478bd9Sstevel@tonic-gate /* 23*d4204c85Sraf * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate /* Copyright (c) 1988 AT&T */ 287c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 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> 409acbbeafSnn35248 #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 { 75*d4204c85Sraf int (*cl_enterclass)(kthread_t *, id_t, void *, cred_t *, void *); 767c478bd9Sstevel@tonic-gate void (*cl_exitclass)(void *); 77*d4204c85Sraf int (*cl_canexit)(kthread_t *, cred_t *); 78*d4204c85Sraf int (*cl_fork)(kthread_t *, kthread_t *, void *); 79*d4204c85Sraf void (*cl_forkret)(kthread_t *, kthread_t *); 80*d4204c85Sraf void (*cl_parmsget)(kthread_t *, void *); 81*d4204c85Sraf int (*cl_parmsset)(kthread_t *, void *, id_t, cred_t *); 82*d4204c85Sraf void (*cl_stop)(kthread_t *, int, int); 83*d4204c85Sraf void (*cl_exit)(kthread_t *); 84*d4204c85Sraf void (*cl_active)(kthread_t *); 85*d4204c85Sraf void (*cl_inactive)(kthread_t *); 86*d4204c85Sraf pri_t (*cl_swapin)(kthread_t *, int); 87*d4204c85Sraf pri_t (*cl_swapout)(kthread_t *, int); 88*d4204c85Sraf void (*cl_trapret)(kthread_t *); 89*d4204c85Sraf void (*cl_preempt)(kthread_t *); 90*d4204c85Sraf void (*cl_setrun)(kthread_t *); 91*d4204c85Sraf void (*cl_sleep)(kthread_t *); 92*d4204c85Sraf void (*cl_tick)(kthread_t *); 93*d4204c85Sraf void (*cl_wakeup)(kthread_t *); 94*d4204c85Sraf int (*cl_donice)(kthread_t *, cred_t *, int, int *); 95*d4204c85Sraf pri_t (*cl_globpri)(kthread_t *); 967c478bd9Sstevel@tonic-gate void (*cl_set_process_group)(pid_t, pid_t, pid_t); 97*d4204c85Sraf void (*cl_yield)(kthread_t *); 98*d4204c85Sraf int (*cl_doprio)(kthread_t *, cred_t *, int, int *); 997c478bd9Sstevel@tonic-gate } thread_ops_t; 1007c478bd9Sstevel@tonic-gate 1017c478bd9Sstevel@tonic-gate typedef struct classfuncs { 1027c478bd9Sstevel@tonic-gate class_ops_t sclass; 1037c478bd9Sstevel@tonic-gate thread_ops_t thread; 1047c478bd9Sstevel@tonic-gate } classfuncs_t; 1057c478bd9Sstevel@tonic-gate 1067c478bd9Sstevel@tonic-gate typedef struct sclass { 1077c478bd9Sstevel@tonic-gate char *cl_name; /* class name */ 1087c478bd9Sstevel@tonic-gate /* class specific initialization function */ 1097c478bd9Sstevel@tonic-gate pri_t (*cl_init)(id_t, int, classfuncs_t **); 1107c478bd9Sstevel@tonic-gate classfuncs_t *cl_funcs; /* pointer to classfuncs structure */ 1117c478bd9Sstevel@tonic-gate krwlock_t *cl_lock; /* class structure read/write lock */ 1127c478bd9Sstevel@tonic-gate int cl_count; /* # of threads trying to load class */ 1137c478bd9Sstevel@tonic-gate } sclass_t; 1147c478bd9Sstevel@tonic-gate 1157c478bd9Sstevel@tonic-gate #define STATIC_SCHED (krwlock_t *)0xffffffff 1167c478bd9Sstevel@tonic-gate #define LOADABLE_SCHED(s) ((s)->cl_lock != STATIC_SCHED) 1177c478bd9Sstevel@tonic-gate #define SCHED_INSTALLED(s) ((s)->cl_funcs != NULL) 1187c478bd9Sstevel@tonic-gate #define ALLOCATED_SCHED(s) ((s)->cl_lock != NULL) 1197c478bd9Sstevel@tonic-gate 1207c478bd9Sstevel@tonic-gate #ifdef _KERNEL 1217c478bd9Sstevel@tonic-gate 1227c478bd9Sstevel@tonic-gate extern int nclass; /* number of configured scheduling classes */ 1237c478bd9Sstevel@tonic-gate extern char *defaultclass; /* default class for newproc'd processes */ 1247c478bd9Sstevel@tonic-gate extern struct sclass sclass[]; /* the class table */ 1257c478bd9Sstevel@tonic-gate extern kmutex_t class_lock; /* lock protecting class table */ 1267c478bd9Sstevel@tonic-gate extern int loaded_classes; /* number of classes loaded */ 1277c478bd9Sstevel@tonic-gate 1287c478bd9Sstevel@tonic-gate extern pri_t minclsyspri; 1297c478bd9Sstevel@tonic-gate extern id_t syscid; /* system scheduling class ID */ 1307c478bd9Sstevel@tonic-gate extern id_t defaultcid; /* "default" class id; see dispadmin(1M) */ 1317c478bd9Sstevel@tonic-gate 1327c478bd9Sstevel@tonic-gate extern int alloc_cid(char *, id_t *); 1337c478bd9Sstevel@tonic-gate extern int scheduler_load(char *, sclass_t *); 1347c478bd9Sstevel@tonic-gate extern int getcid(char *, id_t *); 1357c478bd9Sstevel@tonic-gate extern int getcidbyname(char *, id_t *); 1367c478bd9Sstevel@tonic-gate extern int parmsin(pcparms_t *, pc_vaparms_t *); 1377c478bd9Sstevel@tonic-gate extern int parmsout(pcparms_t *, pc_vaparms_t *); 138*d4204c85Sraf extern int parmsset(pcparms_t *, kthread_t *); 139*d4204c85Sraf extern void parmsget(kthread_t *, pcparms_t *); 1409acbbeafSnn35248 extern int vaparmsout(char *, pcparms_t *, pc_vaparms_t *, uio_seg_t); 1417c478bd9Sstevel@tonic-gate 1427c478bd9Sstevel@tonic-gate #endif 1437c478bd9Sstevel@tonic-gate 1447c478bd9Sstevel@tonic-gate #define CL_ADMIN(clp, uaddr, reqpcredp) \ 1457c478bd9Sstevel@tonic-gate (*(clp)->cl_funcs->sclass.cl_admin)(uaddr, reqpcredp) 1467c478bd9Sstevel@tonic-gate 1477c478bd9Sstevel@tonic-gate #define CL_ENTERCLASS(t, cid, clparmsp, credp, bufp) \ 1487c478bd9Sstevel@tonic-gate (sclass[cid].cl_funcs->thread.cl_enterclass) (t, cid, \ 1497c478bd9Sstevel@tonic-gate (void *)clparmsp, credp, bufp) 1507c478bd9Sstevel@tonic-gate 1517c478bd9Sstevel@tonic-gate #define CL_EXITCLASS(cid, clprocp)\ 1527c478bd9Sstevel@tonic-gate (sclass[cid].cl_funcs->thread.cl_exitclass) ((void *)clprocp) 1537c478bd9Sstevel@tonic-gate 1547c478bd9Sstevel@tonic-gate #define CL_CANEXIT(t, cr) (*(t)->t_clfuncs->cl_canexit)(t, cr) 1557c478bd9Sstevel@tonic-gate 1567c478bd9Sstevel@tonic-gate #define CL_FORK(tp, ct, bufp) (*(tp)->t_clfuncs->cl_fork)(tp, ct, bufp) 1577c478bd9Sstevel@tonic-gate 1587c478bd9Sstevel@tonic-gate #define CL_FORKRET(t, ct) (*(t)->t_clfuncs->cl_forkret)(t, ct) 1597c478bd9Sstevel@tonic-gate 1607c478bd9Sstevel@tonic-gate #define CL_GETCLINFO(clp, clinfop) \ 1617c478bd9Sstevel@tonic-gate (*(clp)->cl_funcs->sclass.cl_getclinfo)((void *)clinfop) 1627c478bd9Sstevel@tonic-gate 1637c478bd9Sstevel@tonic-gate #define CL_GETCLPRI(clp, clprip) \ 1647c478bd9Sstevel@tonic-gate (*(clp)->cl_funcs->sclass.cl_getclpri)(clprip) 1657c478bd9Sstevel@tonic-gate 1667c478bd9Sstevel@tonic-gate #define CL_PARMSGET(t, clparmsp) \ 1677c478bd9Sstevel@tonic-gate (*(t)->t_clfuncs->cl_parmsget)(t, (void *)clparmsp) 1687c478bd9Sstevel@tonic-gate 1697c478bd9Sstevel@tonic-gate #define CL_PARMSIN(clp, clparmsp) \ 1707c478bd9Sstevel@tonic-gate (clp)->cl_funcs->sclass.cl_parmsin((void *)clparmsp) 1717c478bd9Sstevel@tonic-gate 1727c478bd9Sstevel@tonic-gate #define CL_PARMSOUT(clp, clparmsp, vaparmsp) \ 1737c478bd9Sstevel@tonic-gate (clp)->cl_funcs->sclass.cl_parmsout((void *)clparmsp, vaparmsp) 1747c478bd9Sstevel@tonic-gate 1757c478bd9Sstevel@tonic-gate #define CL_VAPARMSIN(clp, clparmsp, vaparmsp) \ 1767c478bd9Sstevel@tonic-gate (clp)->cl_funcs->sclass.cl_vaparmsin((void *)clparmsp, vaparmsp) 1777c478bd9Sstevel@tonic-gate 1787c478bd9Sstevel@tonic-gate #define CL_VAPARMSOUT(clp, clparmsp, vaparmsp) \ 1797c478bd9Sstevel@tonic-gate (clp)->cl_funcs->sclass.cl_vaparmsout((void *)clparmsp, vaparmsp) 1807c478bd9Sstevel@tonic-gate 1817c478bd9Sstevel@tonic-gate #define CL_PARMSSET(t, clparmsp, cid, curpcredp) \ 1827c478bd9Sstevel@tonic-gate (*(t)->t_clfuncs->cl_parmsset)(t, (void *)clparmsp, cid, curpcredp) 1837c478bd9Sstevel@tonic-gate 1847c478bd9Sstevel@tonic-gate #define CL_PREEMPT(tp) (*(tp)->t_clfuncs->cl_preempt)(tp) 1857c478bd9Sstevel@tonic-gate 1867c478bd9Sstevel@tonic-gate #define CL_SETRUN(tp) (*(tp)->t_clfuncs->cl_setrun)(tp) 1877c478bd9Sstevel@tonic-gate 1887c478bd9Sstevel@tonic-gate #define CL_SLEEP(tp) (*(tp)->t_clfuncs->cl_sleep)(tp) 1897c478bd9Sstevel@tonic-gate 1907c478bd9Sstevel@tonic-gate #define CL_STOP(t, why, what) (*(t)->t_clfuncs->cl_stop)(t, why, what) 1917c478bd9Sstevel@tonic-gate 1927c478bd9Sstevel@tonic-gate #define CL_EXIT(t) (*(t)->t_clfuncs->cl_exit)(t) 1937c478bd9Sstevel@tonic-gate 1947c478bd9Sstevel@tonic-gate #define CL_ACTIVE(t) (*(t)->t_clfuncs->cl_active)(t) 1957c478bd9Sstevel@tonic-gate 1967c478bd9Sstevel@tonic-gate #define CL_INACTIVE(t) (*(t)->t_clfuncs->cl_inactive)(t) 1977c478bd9Sstevel@tonic-gate 1987c478bd9Sstevel@tonic-gate #define CL_SWAPIN(t, flags) (*(t)->t_clfuncs->cl_swapin)(t, flags) 1997c478bd9Sstevel@tonic-gate 2007c478bd9Sstevel@tonic-gate #define CL_SWAPOUT(t, flags) (*(t)->t_clfuncs->cl_swapout)(t, flags) 2017c478bd9Sstevel@tonic-gate 2027c478bd9Sstevel@tonic-gate #define CL_TICK(t) (*(t)->t_clfuncs->cl_tick)(t) 2037c478bd9Sstevel@tonic-gate 2047c478bd9Sstevel@tonic-gate #define CL_TRAPRET(t) (*(t)->t_clfuncs->cl_trapret)(t) 2057c478bd9Sstevel@tonic-gate 2067c478bd9Sstevel@tonic-gate #define CL_WAKEUP(t) (*(t)->t_clfuncs->cl_wakeup)(t) 2077c478bd9Sstevel@tonic-gate 2087c478bd9Sstevel@tonic-gate #define CL_DONICE(t, cr, inc, ret) \ 2097c478bd9Sstevel@tonic-gate (*(t)->t_clfuncs->cl_donice)(t, cr, inc, ret) 2107c478bd9Sstevel@tonic-gate 211*d4204c85Sraf #define CL_DOPRIO(t, cr, inc, ret) \ 212*d4204c85Sraf (*(t)->t_clfuncs->cl_doprio)(t, cr, inc, ret) 213*d4204c85Sraf 2147c478bd9Sstevel@tonic-gate #define CL_GLOBPRI(t) (*(t)->t_clfuncs->cl_globpri)(t) 2157c478bd9Sstevel@tonic-gate 2167c478bd9Sstevel@tonic-gate #define CL_SET_PROCESS_GROUP(t, s, b, f) \ 2177c478bd9Sstevel@tonic-gate (*(t)->t_clfuncs->cl_set_process_group)(s, b, f) 2187c478bd9Sstevel@tonic-gate 2197c478bd9Sstevel@tonic-gate #define CL_YIELD(tp) (*(tp)->t_clfuncs->cl_yield)(tp) 2207c478bd9Sstevel@tonic-gate 2217c478bd9Sstevel@tonic-gate #define CL_ALLOC(pp, cid, flag) \ 2227c478bd9Sstevel@tonic-gate (sclass[cid].cl_funcs->sclass.cl_alloc) (pp, flag) 2237c478bd9Sstevel@tonic-gate 2247c478bd9Sstevel@tonic-gate #define CL_FREE(cid, bufp) (sclass[cid].cl_funcs->sclass.cl_free) (bufp) 2257c478bd9Sstevel@tonic-gate 2267c478bd9Sstevel@tonic-gate #ifdef __cplusplus 2277c478bd9Sstevel@tonic-gate } 2287c478bd9Sstevel@tonic-gate #endif 2297c478bd9Sstevel@tonic-gate 2307c478bd9Sstevel@tonic-gate #endif /* _SYS_CLASS_H */ 231