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 /* 2335a5a358SJonathan Adams * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*b819cea2SGordon Ross * 26*b819cea2SGordon Ross * Copyright 2013 Nexenta Systems, Inc. All rights reserved. 277c478bd9Sstevel@tonic-gate */ 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate /* Copyright (c) 1988 AT&T */ 307c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate #ifndef _SYS_CLASS_H 337c478bd9Sstevel@tonic-gate #define _SYS_CLASS_H 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 { 75d4204c85Sraf int (*cl_enterclass)(kthread_t *, id_t, void *, cred_t *, void *); 767c478bd9Sstevel@tonic-gate void (*cl_exitclass)(void *); 77d4204c85Sraf int (*cl_canexit)(kthread_t *, cred_t *); 78d4204c85Sraf int (*cl_fork)(kthread_t *, kthread_t *, void *); 79d4204c85Sraf void (*cl_forkret)(kthread_t *, kthread_t *); 80d4204c85Sraf void (*cl_parmsget)(kthread_t *, void *); 81d4204c85Sraf int (*cl_parmsset)(kthread_t *, void *, id_t, cred_t *); 82d4204c85Sraf void (*cl_stop)(kthread_t *, int, int); 83d4204c85Sraf void (*cl_exit)(kthread_t *); 84d4204c85Sraf void (*cl_active)(kthread_t *); 85d4204c85Sraf void (*cl_inactive)(kthread_t *); 86d4204c85Sraf pri_t (*cl_swapin)(kthread_t *, int); 87d4204c85Sraf pri_t (*cl_swapout)(kthread_t *, int); 88d4204c85Sraf void (*cl_trapret)(kthread_t *); 89d4204c85Sraf void (*cl_preempt)(kthread_t *); 90d4204c85Sraf void (*cl_setrun)(kthread_t *); 91d4204c85Sraf void (*cl_sleep)(kthread_t *); 92d4204c85Sraf void (*cl_tick)(kthread_t *); 93d4204c85Sraf void (*cl_wakeup)(kthread_t *); 94d4204c85Sraf int (*cl_donice)(kthread_t *, cred_t *, int, int *); 95d4204c85Sraf pri_t (*cl_globpri)(kthread_t *); 967c478bd9Sstevel@tonic-gate void (*cl_set_process_group)(pid_t, pid_t, pid_t); 97d4204c85Sraf void (*cl_yield)(kthread_t *); 98d4204c85Sraf 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 120*b819cea2SGordon Ross #if defined(_KERNEL) || defined(_FAKE_KERNEL) 1217c478bd9Sstevel@tonic-gate 12235a5a358SJonathan Adams #define CLASS_KERNEL(cid) ((cid) == syscid || (cid) == sysdccid) 12335a5a358SJonathan Adams 1247c478bd9Sstevel@tonic-gate extern int nclass; /* number of configured scheduling classes */ 1257c478bd9Sstevel@tonic-gate extern char *defaultclass; /* default class for newproc'd processes */ 1267c478bd9Sstevel@tonic-gate extern struct sclass sclass[]; /* the class table */ 1277c478bd9Sstevel@tonic-gate extern kmutex_t class_lock; /* lock protecting class table */ 1287c478bd9Sstevel@tonic-gate extern int loaded_classes; /* number of classes loaded */ 1297c478bd9Sstevel@tonic-gate 1307c478bd9Sstevel@tonic-gate extern pri_t minclsyspri; 1317c478bd9Sstevel@tonic-gate extern id_t syscid; /* system scheduling class ID */ 13235a5a358SJonathan Adams extern id_t sysdccid; /* system duty-cycle scheduling class ID */ 1337c478bd9Sstevel@tonic-gate extern id_t defaultcid; /* "default" class id; see dispadmin(1M) */ 1347c478bd9Sstevel@tonic-gate 1357c478bd9Sstevel@tonic-gate extern int alloc_cid(char *, id_t *); 1367c478bd9Sstevel@tonic-gate extern int scheduler_load(char *, sclass_t *); 1377c478bd9Sstevel@tonic-gate extern int getcid(char *, id_t *); 1387c478bd9Sstevel@tonic-gate extern int getcidbyname(char *, id_t *); 1397c478bd9Sstevel@tonic-gate extern int parmsin(pcparms_t *, pc_vaparms_t *); 1407c478bd9Sstevel@tonic-gate extern int parmsout(pcparms_t *, pc_vaparms_t *); 141d4204c85Sraf extern int parmsset(pcparms_t *, kthread_t *); 142d4204c85Sraf extern void parmsget(kthread_t *, pcparms_t *); 1439acbbeafSnn35248 extern int vaparmsout(char *, pcparms_t *, pc_vaparms_t *, uio_seg_t); 1447c478bd9Sstevel@tonic-gate 1457c478bd9Sstevel@tonic-gate #endif 1467c478bd9Sstevel@tonic-gate 1477c478bd9Sstevel@tonic-gate #define CL_ADMIN(clp, uaddr, reqpcredp) \ 1487c478bd9Sstevel@tonic-gate (*(clp)->cl_funcs->sclass.cl_admin)(uaddr, reqpcredp) 1497c478bd9Sstevel@tonic-gate 1507c478bd9Sstevel@tonic-gate #define CL_ENTERCLASS(t, cid, clparmsp, credp, bufp) \ 1517c478bd9Sstevel@tonic-gate (sclass[cid].cl_funcs->thread.cl_enterclass) (t, cid, \ 1527c478bd9Sstevel@tonic-gate (void *)clparmsp, credp, bufp) 1537c478bd9Sstevel@tonic-gate 1547c478bd9Sstevel@tonic-gate #define CL_EXITCLASS(cid, clprocp)\ 1557c478bd9Sstevel@tonic-gate (sclass[cid].cl_funcs->thread.cl_exitclass) ((void *)clprocp) 1567c478bd9Sstevel@tonic-gate 1577c478bd9Sstevel@tonic-gate #define CL_CANEXIT(t, cr) (*(t)->t_clfuncs->cl_canexit)(t, cr) 1587c478bd9Sstevel@tonic-gate 1597c478bd9Sstevel@tonic-gate #define CL_FORK(tp, ct, bufp) (*(tp)->t_clfuncs->cl_fork)(tp, ct, bufp) 1607c478bd9Sstevel@tonic-gate 1617c478bd9Sstevel@tonic-gate #define CL_FORKRET(t, ct) (*(t)->t_clfuncs->cl_forkret)(t, ct) 1627c478bd9Sstevel@tonic-gate 1637c478bd9Sstevel@tonic-gate #define CL_GETCLINFO(clp, clinfop) \ 1647c478bd9Sstevel@tonic-gate (*(clp)->cl_funcs->sclass.cl_getclinfo)((void *)clinfop) 1657c478bd9Sstevel@tonic-gate 1667c478bd9Sstevel@tonic-gate #define CL_GETCLPRI(clp, clprip) \ 1677c478bd9Sstevel@tonic-gate (*(clp)->cl_funcs->sclass.cl_getclpri)(clprip) 1687c478bd9Sstevel@tonic-gate 1697c478bd9Sstevel@tonic-gate #define CL_PARMSGET(t, clparmsp) \ 1707c478bd9Sstevel@tonic-gate (*(t)->t_clfuncs->cl_parmsget)(t, (void *)clparmsp) 1717c478bd9Sstevel@tonic-gate 1727c478bd9Sstevel@tonic-gate #define CL_PARMSIN(clp, clparmsp) \ 1737c478bd9Sstevel@tonic-gate (clp)->cl_funcs->sclass.cl_parmsin((void *)clparmsp) 1747c478bd9Sstevel@tonic-gate 1757c478bd9Sstevel@tonic-gate #define CL_PARMSOUT(clp, clparmsp, vaparmsp) \ 1767c478bd9Sstevel@tonic-gate (clp)->cl_funcs->sclass.cl_parmsout((void *)clparmsp, vaparmsp) 1777c478bd9Sstevel@tonic-gate 1787c478bd9Sstevel@tonic-gate #define CL_VAPARMSIN(clp, clparmsp, vaparmsp) \ 1797c478bd9Sstevel@tonic-gate (clp)->cl_funcs->sclass.cl_vaparmsin((void *)clparmsp, vaparmsp) 1807c478bd9Sstevel@tonic-gate 1817c478bd9Sstevel@tonic-gate #define CL_VAPARMSOUT(clp, clparmsp, vaparmsp) \ 1827c478bd9Sstevel@tonic-gate (clp)->cl_funcs->sclass.cl_vaparmsout((void *)clparmsp, vaparmsp) 1837c478bd9Sstevel@tonic-gate 1847c478bd9Sstevel@tonic-gate #define CL_PARMSSET(t, clparmsp, cid, curpcredp) \ 1857c478bd9Sstevel@tonic-gate (*(t)->t_clfuncs->cl_parmsset)(t, (void *)clparmsp, cid, curpcredp) 1867c478bd9Sstevel@tonic-gate 1877c478bd9Sstevel@tonic-gate #define CL_PREEMPT(tp) (*(tp)->t_clfuncs->cl_preempt)(tp) 1887c478bd9Sstevel@tonic-gate 1897c478bd9Sstevel@tonic-gate #define CL_SETRUN(tp) (*(tp)->t_clfuncs->cl_setrun)(tp) 1907c478bd9Sstevel@tonic-gate 1917c478bd9Sstevel@tonic-gate #define CL_SLEEP(tp) (*(tp)->t_clfuncs->cl_sleep)(tp) 1927c478bd9Sstevel@tonic-gate 1937c478bd9Sstevel@tonic-gate #define CL_STOP(t, why, what) (*(t)->t_clfuncs->cl_stop)(t, why, what) 1947c478bd9Sstevel@tonic-gate 1957c478bd9Sstevel@tonic-gate #define CL_EXIT(t) (*(t)->t_clfuncs->cl_exit)(t) 1967c478bd9Sstevel@tonic-gate 1977c478bd9Sstevel@tonic-gate #define CL_ACTIVE(t) (*(t)->t_clfuncs->cl_active)(t) 1987c478bd9Sstevel@tonic-gate 1997c478bd9Sstevel@tonic-gate #define CL_INACTIVE(t) (*(t)->t_clfuncs->cl_inactive)(t) 2007c478bd9Sstevel@tonic-gate 2017c478bd9Sstevel@tonic-gate #define CL_SWAPIN(t, flags) (*(t)->t_clfuncs->cl_swapin)(t, flags) 2027c478bd9Sstevel@tonic-gate 2037c478bd9Sstevel@tonic-gate #define CL_SWAPOUT(t, flags) (*(t)->t_clfuncs->cl_swapout)(t, flags) 2047c478bd9Sstevel@tonic-gate 2057c478bd9Sstevel@tonic-gate #define CL_TICK(t) (*(t)->t_clfuncs->cl_tick)(t) 2067c478bd9Sstevel@tonic-gate 2077c478bd9Sstevel@tonic-gate #define CL_TRAPRET(t) (*(t)->t_clfuncs->cl_trapret)(t) 2087c478bd9Sstevel@tonic-gate 2097c478bd9Sstevel@tonic-gate #define CL_WAKEUP(t) (*(t)->t_clfuncs->cl_wakeup)(t) 2107c478bd9Sstevel@tonic-gate 2117c478bd9Sstevel@tonic-gate #define CL_DONICE(t, cr, inc, ret) \ 2127c478bd9Sstevel@tonic-gate (*(t)->t_clfuncs->cl_donice)(t, cr, inc, ret) 2137c478bd9Sstevel@tonic-gate 214d4204c85Sraf #define CL_DOPRIO(t, cr, inc, ret) \ 215d4204c85Sraf (*(t)->t_clfuncs->cl_doprio)(t, cr, inc, ret) 216d4204c85Sraf 2177c478bd9Sstevel@tonic-gate #define CL_GLOBPRI(t) (*(t)->t_clfuncs->cl_globpri)(t) 2187c478bd9Sstevel@tonic-gate 2197c478bd9Sstevel@tonic-gate #define CL_SET_PROCESS_GROUP(t, s, b, f) \ 2207c478bd9Sstevel@tonic-gate (*(t)->t_clfuncs->cl_set_process_group)(s, b, f) 2217c478bd9Sstevel@tonic-gate 2227c478bd9Sstevel@tonic-gate #define CL_YIELD(tp) (*(tp)->t_clfuncs->cl_yield)(tp) 2237c478bd9Sstevel@tonic-gate 2247c478bd9Sstevel@tonic-gate #define CL_ALLOC(pp, cid, flag) \ 2257c478bd9Sstevel@tonic-gate (sclass[cid].cl_funcs->sclass.cl_alloc) (pp, flag) 2267c478bd9Sstevel@tonic-gate 2277c478bd9Sstevel@tonic-gate #define CL_FREE(cid, bufp) (sclass[cid].cl_funcs->sclass.cl_free) (bufp) 2287c478bd9Sstevel@tonic-gate 2297c478bd9Sstevel@tonic-gate #ifdef __cplusplus 2307c478bd9Sstevel@tonic-gate } 2317c478bd9Sstevel@tonic-gate #endif 2327c478bd9Sstevel@tonic-gate 2337c478bd9Sstevel@tonic-gate #endif /* _SYS_CLASS_H */ 234