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 */ 21d4204c85Sraf 227c478bd9Sstevel@tonic-gate /* 23*35a5a358SJonathan Adams * Copyright 2009 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 #include <sys/t_lock.h> 347c478bd9Sstevel@tonic-gate #include <sys/cred.h> 357c478bd9Sstevel@tonic-gate #include <sys/thread.h> 367c478bd9Sstevel@tonic-gate #include <sys/priocntl.h> 377c478bd9Sstevel@tonic-gate #include <sys/mutex.h> 389acbbeafSnn35248 #include <sys/uio.h> 397c478bd9Sstevel@tonic-gate 407c478bd9Sstevel@tonic-gate #ifdef __cplusplus 417c478bd9Sstevel@tonic-gate extern "C" { 427c478bd9Sstevel@tonic-gate #endif 437c478bd9Sstevel@tonic-gate 447c478bd9Sstevel@tonic-gate /* 457c478bd9Sstevel@tonic-gate * NOTE: Developers making use of the scheduler class switch mechanism 467c478bd9Sstevel@tonic-gate * to develop scheduling class modules should be aware that the 477c478bd9Sstevel@tonic-gate * architecture is not frozen and the kernel interface for scheduling 487c478bd9Sstevel@tonic-gate * class modules may change in future releases of System V. Support 497c478bd9Sstevel@tonic-gate * for the current interface is not guaranteed and class modules 507c478bd9Sstevel@tonic-gate * developed to this interface may require changes in order to work 517c478bd9Sstevel@tonic-gate * with future releases of the system. 527c478bd9Sstevel@tonic-gate */ 537c478bd9Sstevel@tonic-gate 547c478bd9Sstevel@tonic-gate /* 557c478bd9Sstevel@tonic-gate * three different ops vectors are bundled together, here. 567c478bd9Sstevel@tonic-gate * one is for each of the fundamental objects acted upon 577c478bd9Sstevel@tonic-gate * by these operators: procs, threads, and the class manager itself. 587c478bd9Sstevel@tonic-gate */ 597c478bd9Sstevel@tonic-gate 607c478bd9Sstevel@tonic-gate typedef struct class_ops { 617c478bd9Sstevel@tonic-gate int (*cl_admin)(caddr_t, cred_t *); 627c478bd9Sstevel@tonic-gate int (*cl_getclinfo)(void *); 637c478bd9Sstevel@tonic-gate int (*cl_parmsin)(void *); 647c478bd9Sstevel@tonic-gate int (*cl_parmsout)(void *, pc_vaparms_t *); 657c478bd9Sstevel@tonic-gate int (*cl_vaparmsin)(void *, pc_vaparms_t *); 667c478bd9Sstevel@tonic-gate int (*cl_vaparmsout)(void *, pc_vaparms_t *); 677c478bd9Sstevel@tonic-gate int (*cl_getclpri)(pcpri_t *); 687c478bd9Sstevel@tonic-gate int (*cl_alloc)(void **, int); 697c478bd9Sstevel@tonic-gate void (*cl_free)(void *); 707c478bd9Sstevel@tonic-gate } class_ops_t; 717c478bd9Sstevel@tonic-gate 727c478bd9Sstevel@tonic-gate typedef struct thread_ops { 73d4204c85Sraf int (*cl_enterclass)(kthread_t *, id_t, void *, cred_t *, void *); 747c478bd9Sstevel@tonic-gate void (*cl_exitclass)(void *); 75d4204c85Sraf int (*cl_canexit)(kthread_t *, cred_t *); 76d4204c85Sraf int (*cl_fork)(kthread_t *, kthread_t *, void *); 77d4204c85Sraf void (*cl_forkret)(kthread_t *, kthread_t *); 78d4204c85Sraf void (*cl_parmsget)(kthread_t *, void *); 79d4204c85Sraf int (*cl_parmsset)(kthread_t *, void *, id_t, cred_t *); 80d4204c85Sraf void (*cl_stop)(kthread_t *, int, int); 81d4204c85Sraf void (*cl_exit)(kthread_t *); 82d4204c85Sraf void (*cl_active)(kthread_t *); 83d4204c85Sraf void (*cl_inactive)(kthread_t *); 84d4204c85Sraf pri_t (*cl_swapin)(kthread_t *, int); 85d4204c85Sraf pri_t (*cl_swapout)(kthread_t *, int); 86d4204c85Sraf void (*cl_trapret)(kthread_t *); 87d4204c85Sraf void (*cl_preempt)(kthread_t *); 88d4204c85Sraf void (*cl_setrun)(kthread_t *); 89d4204c85Sraf void (*cl_sleep)(kthread_t *); 90d4204c85Sraf void (*cl_tick)(kthread_t *); 91d4204c85Sraf void (*cl_wakeup)(kthread_t *); 92d4204c85Sraf int (*cl_donice)(kthread_t *, cred_t *, int, int *); 93d4204c85Sraf pri_t (*cl_globpri)(kthread_t *); 947c478bd9Sstevel@tonic-gate void (*cl_set_process_group)(pid_t, pid_t, pid_t); 95d4204c85Sraf void (*cl_yield)(kthread_t *); 96d4204c85Sraf int (*cl_doprio)(kthread_t *, cred_t *, int, int *); 977c478bd9Sstevel@tonic-gate } thread_ops_t; 987c478bd9Sstevel@tonic-gate 997c478bd9Sstevel@tonic-gate typedef struct classfuncs { 1007c478bd9Sstevel@tonic-gate class_ops_t sclass; 1017c478bd9Sstevel@tonic-gate thread_ops_t thread; 1027c478bd9Sstevel@tonic-gate } classfuncs_t; 1037c478bd9Sstevel@tonic-gate 1047c478bd9Sstevel@tonic-gate typedef struct sclass { 1057c478bd9Sstevel@tonic-gate char *cl_name; /* class name */ 1067c478bd9Sstevel@tonic-gate /* class specific initialization function */ 1077c478bd9Sstevel@tonic-gate pri_t (*cl_init)(id_t, int, classfuncs_t **); 1087c478bd9Sstevel@tonic-gate classfuncs_t *cl_funcs; /* pointer to classfuncs structure */ 1097c478bd9Sstevel@tonic-gate krwlock_t *cl_lock; /* class structure read/write lock */ 1107c478bd9Sstevel@tonic-gate int cl_count; /* # of threads trying to load class */ 1117c478bd9Sstevel@tonic-gate } sclass_t; 1127c478bd9Sstevel@tonic-gate 1137c478bd9Sstevel@tonic-gate #define STATIC_SCHED (krwlock_t *)0xffffffff 1147c478bd9Sstevel@tonic-gate #define LOADABLE_SCHED(s) ((s)->cl_lock != STATIC_SCHED) 1157c478bd9Sstevel@tonic-gate #define SCHED_INSTALLED(s) ((s)->cl_funcs != NULL) 1167c478bd9Sstevel@tonic-gate #define ALLOCATED_SCHED(s) ((s)->cl_lock != NULL) 1177c478bd9Sstevel@tonic-gate 1187c478bd9Sstevel@tonic-gate #ifdef _KERNEL 1197c478bd9Sstevel@tonic-gate 120*35a5a358SJonathan Adams #define CLASS_KERNEL(cid) ((cid) == syscid || (cid) == sysdccid) 121*35a5a358SJonathan Adams 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 */ 130*35a5a358SJonathan Adams extern id_t sysdccid; /* system duty-cycle scheduling class ID */ 1317c478bd9Sstevel@tonic-gate extern id_t defaultcid; /* "default" class id; see dispadmin(1M) */ 1327c478bd9Sstevel@tonic-gate 1337c478bd9Sstevel@tonic-gate extern int alloc_cid(char *, id_t *); 1347c478bd9Sstevel@tonic-gate extern int scheduler_load(char *, sclass_t *); 1357c478bd9Sstevel@tonic-gate extern int getcid(char *, id_t *); 1367c478bd9Sstevel@tonic-gate extern int getcidbyname(char *, id_t *); 1377c478bd9Sstevel@tonic-gate extern int parmsin(pcparms_t *, pc_vaparms_t *); 1387c478bd9Sstevel@tonic-gate extern int parmsout(pcparms_t *, pc_vaparms_t *); 139d4204c85Sraf extern int parmsset(pcparms_t *, kthread_t *); 140d4204c85Sraf extern void parmsget(kthread_t *, pcparms_t *); 1419acbbeafSnn35248 extern int vaparmsout(char *, pcparms_t *, pc_vaparms_t *, uio_seg_t); 1427c478bd9Sstevel@tonic-gate 1437c478bd9Sstevel@tonic-gate #endif 1447c478bd9Sstevel@tonic-gate 1457c478bd9Sstevel@tonic-gate #define CL_ADMIN(clp, uaddr, reqpcredp) \ 1467c478bd9Sstevel@tonic-gate (*(clp)->cl_funcs->sclass.cl_admin)(uaddr, reqpcredp) 1477c478bd9Sstevel@tonic-gate 1487c478bd9Sstevel@tonic-gate #define CL_ENTERCLASS(t, cid, clparmsp, credp, bufp) \ 1497c478bd9Sstevel@tonic-gate (sclass[cid].cl_funcs->thread.cl_enterclass) (t, cid, \ 1507c478bd9Sstevel@tonic-gate (void *)clparmsp, credp, bufp) 1517c478bd9Sstevel@tonic-gate 1527c478bd9Sstevel@tonic-gate #define CL_EXITCLASS(cid, clprocp)\ 1537c478bd9Sstevel@tonic-gate (sclass[cid].cl_funcs->thread.cl_exitclass) ((void *)clprocp) 1547c478bd9Sstevel@tonic-gate 1557c478bd9Sstevel@tonic-gate #define CL_CANEXIT(t, cr) (*(t)->t_clfuncs->cl_canexit)(t, cr) 1567c478bd9Sstevel@tonic-gate 1577c478bd9Sstevel@tonic-gate #define CL_FORK(tp, ct, bufp) (*(tp)->t_clfuncs->cl_fork)(tp, ct, bufp) 1587c478bd9Sstevel@tonic-gate 1597c478bd9Sstevel@tonic-gate #define CL_FORKRET(t, ct) (*(t)->t_clfuncs->cl_forkret)(t, ct) 1607c478bd9Sstevel@tonic-gate 1617c478bd9Sstevel@tonic-gate #define CL_GETCLINFO(clp, clinfop) \ 1627c478bd9Sstevel@tonic-gate (*(clp)->cl_funcs->sclass.cl_getclinfo)((void *)clinfop) 1637c478bd9Sstevel@tonic-gate 1647c478bd9Sstevel@tonic-gate #define CL_GETCLPRI(clp, clprip) \ 1657c478bd9Sstevel@tonic-gate (*(clp)->cl_funcs->sclass.cl_getclpri)(clprip) 1667c478bd9Sstevel@tonic-gate 1677c478bd9Sstevel@tonic-gate #define CL_PARMSGET(t, clparmsp) \ 1687c478bd9Sstevel@tonic-gate (*(t)->t_clfuncs->cl_parmsget)(t, (void *)clparmsp) 1697c478bd9Sstevel@tonic-gate 1707c478bd9Sstevel@tonic-gate #define CL_PARMSIN(clp, clparmsp) \ 1717c478bd9Sstevel@tonic-gate (clp)->cl_funcs->sclass.cl_parmsin((void *)clparmsp) 1727c478bd9Sstevel@tonic-gate 1737c478bd9Sstevel@tonic-gate #define CL_PARMSOUT(clp, clparmsp, vaparmsp) \ 1747c478bd9Sstevel@tonic-gate (clp)->cl_funcs->sclass.cl_parmsout((void *)clparmsp, vaparmsp) 1757c478bd9Sstevel@tonic-gate 1767c478bd9Sstevel@tonic-gate #define CL_VAPARMSIN(clp, clparmsp, vaparmsp) \ 1777c478bd9Sstevel@tonic-gate (clp)->cl_funcs->sclass.cl_vaparmsin((void *)clparmsp, vaparmsp) 1787c478bd9Sstevel@tonic-gate 1797c478bd9Sstevel@tonic-gate #define CL_VAPARMSOUT(clp, clparmsp, vaparmsp) \ 1807c478bd9Sstevel@tonic-gate (clp)->cl_funcs->sclass.cl_vaparmsout((void *)clparmsp, vaparmsp) 1817c478bd9Sstevel@tonic-gate 1827c478bd9Sstevel@tonic-gate #define CL_PARMSSET(t, clparmsp, cid, curpcredp) \ 1837c478bd9Sstevel@tonic-gate (*(t)->t_clfuncs->cl_parmsset)(t, (void *)clparmsp, cid, curpcredp) 1847c478bd9Sstevel@tonic-gate 1857c478bd9Sstevel@tonic-gate #define CL_PREEMPT(tp) (*(tp)->t_clfuncs->cl_preempt)(tp) 1867c478bd9Sstevel@tonic-gate 1877c478bd9Sstevel@tonic-gate #define CL_SETRUN(tp) (*(tp)->t_clfuncs->cl_setrun)(tp) 1887c478bd9Sstevel@tonic-gate 1897c478bd9Sstevel@tonic-gate #define CL_SLEEP(tp) (*(tp)->t_clfuncs->cl_sleep)(tp) 1907c478bd9Sstevel@tonic-gate 1917c478bd9Sstevel@tonic-gate #define CL_STOP(t, why, what) (*(t)->t_clfuncs->cl_stop)(t, why, what) 1927c478bd9Sstevel@tonic-gate 1937c478bd9Sstevel@tonic-gate #define CL_EXIT(t) (*(t)->t_clfuncs->cl_exit)(t) 1947c478bd9Sstevel@tonic-gate 1957c478bd9Sstevel@tonic-gate #define CL_ACTIVE(t) (*(t)->t_clfuncs->cl_active)(t) 1967c478bd9Sstevel@tonic-gate 1977c478bd9Sstevel@tonic-gate #define CL_INACTIVE(t) (*(t)->t_clfuncs->cl_inactive)(t) 1987c478bd9Sstevel@tonic-gate 1997c478bd9Sstevel@tonic-gate #define CL_SWAPIN(t, flags) (*(t)->t_clfuncs->cl_swapin)(t, flags) 2007c478bd9Sstevel@tonic-gate 2017c478bd9Sstevel@tonic-gate #define CL_SWAPOUT(t, flags) (*(t)->t_clfuncs->cl_swapout)(t, flags) 2027c478bd9Sstevel@tonic-gate 2037c478bd9Sstevel@tonic-gate #define CL_TICK(t) (*(t)->t_clfuncs->cl_tick)(t) 2047c478bd9Sstevel@tonic-gate 2057c478bd9Sstevel@tonic-gate #define CL_TRAPRET(t) (*(t)->t_clfuncs->cl_trapret)(t) 2067c478bd9Sstevel@tonic-gate 2077c478bd9Sstevel@tonic-gate #define CL_WAKEUP(t) (*(t)->t_clfuncs->cl_wakeup)(t) 2087c478bd9Sstevel@tonic-gate 2097c478bd9Sstevel@tonic-gate #define CL_DONICE(t, cr, inc, ret) \ 2107c478bd9Sstevel@tonic-gate (*(t)->t_clfuncs->cl_donice)(t, cr, inc, ret) 2117c478bd9Sstevel@tonic-gate 212d4204c85Sraf #define CL_DOPRIO(t, cr, inc, ret) \ 213d4204c85Sraf (*(t)->t_clfuncs->cl_doprio)(t, cr, inc, ret) 214d4204c85Sraf 2157c478bd9Sstevel@tonic-gate #define CL_GLOBPRI(t) (*(t)->t_clfuncs->cl_globpri)(t) 2167c478bd9Sstevel@tonic-gate 2177c478bd9Sstevel@tonic-gate #define CL_SET_PROCESS_GROUP(t, s, b, f) \ 2187c478bd9Sstevel@tonic-gate (*(t)->t_clfuncs->cl_set_process_group)(s, b, f) 2197c478bd9Sstevel@tonic-gate 2207c478bd9Sstevel@tonic-gate #define CL_YIELD(tp) (*(tp)->t_clfuncs->cl_yield)(tp) 2217c478bd9Sstevel@tonic-gate 2227c478bd9Sstevel@tonic-gate #define CL_ALLOC(pp, cid, flag) \ 2237c478bd9Sstevel@tonic-gate (sclass[cid].cl_funcs->sclass.cl_alloc) (pp, flag) 2247c478bd9Sstevel@tonic-gate 2257c478bd9Sstevel@tonic-gate #define CL_FREE(cid, bufp) (sclass[cid].cl_funcs->sclass.cl_free) (bufp) 2267c478bd9Sstevel@tonic-gate 2277c478bd9Sstevel@tonic-gate #ifdef __cplusplus 2287c478bd9Sstevel@tonic-gate } 2297c478bd9Sstevel@tonic-gate #endif 2307c478bd9Sstevel@tonic-gate 2317c478bd9Sstevel@tonic-gate #endif /* _SYS_CLASS_H */ 232