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 5c97ad5cdSakolb * Common Development and Distribution License (the "License"). 6c97ad5cdSakolb * 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 */ 21c97ad5cdSakolb 227c478bd9Sstevel@tonic-gate /* 23*d4204c85Sraf * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 24c97ad5cdSakolb * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 287c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" /* from SVr4.0 1.12 */ 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate #include <sys/types.h> 337c478bd9Sstevel@tonic-gate #include <sys/param.h> 347c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h> 357c478bd9Sstevel@tonic-gate #include <sys/signal.h> 367c478bd9Sstevel@tonic-gate #include <sys/pcb.h> 377c478bd9Sstevel@tonic-gate #include <sys/user.h> 387c478bd9Sstevel@tonic-gate #include <sys/systm.h> 397c478bd9Sstevel@tonic-gate #include <sys/sysinfo.h> 407c478bd9Sstevel@tonic-gate #include <sys/var.h> 417c478bd9Sstevel@tonic-gate #include <sys/errno.h> 427c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h> 437c478bd9Sstevel@tonic-gate #include <sys/proc.h> 447c478bd9Sstevel@tonic-gate #include <sys/debug.h> 457c478bd9Sstevel@tonic-gate #include <sys/inline.h> 467c478bd9Sstevel@tonic-gate #include <sys/disp.h> 477c478bd9Sstevel@tonic-gate #include <sys/class.h> 487c478bd9Sstevel@tonic-gate #include <sys/kmem.h> 497c478bd9Sstevel@tonic-gate #include <sys/cpuvar.h> 507c478bd9Sstevel@tonic-gate #include <sys/priocntl.h> 517c478bd9Sstevel@tonic-gate 527c478bd9Sstevel@tonic-gate /* 537c478bd9Sstevel@tonic-gate * Class specific code for the sys class. There are no 547c478bd9Sstevel@tonic-gate * class specific data structures associated with 557c478bd9Sstevel@tonic-gate * the sys class and the scheduling policy is trivially 567c478bd9Sstevel@tonic-gate * simple. There is no time slicing. 577c478bd9Sstevel@tonic-gate */ 587c478bd9Sstevel@tonic-gate 597c478bd9Sstevel@tonic-gate pri_t sys_init(id_t, int, classfuncs_t **); 607c478bd9Sstevel@tonic-gate static int sys_getclpri(pcpri_t *); 61*d4204c85Sraf static int sys_fork(kthread_t *, kthread_t *, void *); 62*d4204c85Sraf static int sys_enterclass(kthread_t *, id_t, void *, cred_t *, void *); 63*d4204c85Sraf static int sys_canexit(kthread_t *, cred_t *); 647c478bd9Sstevel@tonic-gate static int sys_nosys(); 65*d4204c85Sraf static int sys_donice(kthread_t *, cred_t *, int, int *); 66*d4204c85Sraf static int sys_doprio(kthread_t *, cred_t *, int, int *); 67*d4204c85Sraf static void sys_forkret(kthread_t *, kthread_t *); 687c478bd9Sstevel@tonic-gate static void sys_nullsys(); 69*d4204c85Sraf static pri_t sys_swappri(kthread_t *, int); 707c478bd9Sstevel@tonic-gate static int sys_alloc(void **, int); 717c478bd9Sstevel@tonic-gate 727c478bd9Sstevel@tonic-gate struct classfuncs sys_classfuncs = { 737c478bd9Sstevel@tonic-gate /* messages to class manager */ 747c478bd9Sstevel@tonic-gate { 757c478bd9Sstevel@tonic-gate sys_nosys, /* admin */ 767c478bd9Sstevel@tonic-gate sys_nosys, /* getclinfo */ 777c478bd9Sstevel@tonic-gate sys_nosys, /* parmsin */ 787c478bd9Sstevel@tonic-gate sys_nosys, /* parmsout */ 797c478bd9Sstevel@tonic-gate sys_nosys, /* vaparmsin */ 807c478bd9Sstevel@tonic-gate sys_nosys, /* vaparmsout */ 817c478bd9Sstevel@tonic-gate sys_getclpri, /* getclpri */ 827c478bd9Sstevel@tonic-gate sys_alloc, 837c478bd9Sstevel@tonic-gate sys_nullsys, /* free */ 847c478bd9Sstevel@tonic-gate }, 857c478bd9Sstevel@tonic-gate /* operations on threads */ 867c478bd9Sstevel@tonic-gate { 877c478bd9Sstevel@tonic-gate sys_enterclass, /* enterclass */ 887c478bd9Sstevel@tonic-gate sys_nullsys, /* exitclass */ 897c478bd9Sstevel@tonic-gate sys_canexit, 907c478bd9Sstevel@tonic-gate sys_fork, 917c478bd9Sstevel@tonic-gate sys_forkret, /* forkret */ 927c478bd9Sstevel@tonic-gate sys_nullsys, /* parmsget */ 937c478bd9Sstevel@tonic-gate sys_nosys, /* parmsset */ 947c478bd9Sstevel@tonic-gate sys_nullsys, /* stop */ 957c478bd9Sstevel@tonic-gate sys_nullsys, /* exit */ 967c478bd9Sstevel@tonic-gate sys_nullsys, /* active */ 977c478bd9Sstevel@tonic-gate sys_nullsys, /* inactive */ 987c478bd9Sstevel@tonic-gate sys_swappri, /* swapin */ 997c478bd9Sstevel@tonic-gate sys_swappri, /* swapout */ 1007c478bd9Sstevel@tonic-gate sys_nullsys, /* trapret */ 101c97ad5cdSakolb setfrontdq, /* preempt */ 1027c478bd9Sstevel@tonic-gate setbackdq, /* setrun */ 1037c478bd9Sstevel@tonic-gate sys_nullsys, /* sleep */ 1047c478bd9Sstevel@tonic-gate sys_nullsys, /* tick */ 1057c478bd9Sstevel@tonic-gate setbackdq, /* wakeup */ 1067c478bd9Sstevel@tonic-gate sys_donice, 1077c478bd9Sstevel@tonic-gate (pri_t (*)())sys_nosys, /* globpri */ 1087c478bd9Sstevel@tonic-gate sys_nullsys, /* set_process_group */ 1097c478bd9Sstevel@tonic-gate sys_nullsys, /* yield */ 110*d4204c85Sraf sys_doprio, 1117c478bd9Sstevel@tonic-gate } 1127c478bd9Sstevel@tonic-gate 1137c478bd9Sstevel@tonic-gate }; 1147c478bd9Sstevel@tonic-gate 1157c478bd9Sstevel@tonic-gate 1167c478bd9Sstevel@tonic-gate /* ARGSUSED */ 1177c478bd9Sstevel@tonic-gate pri_t 1187c478bd9Sstevel@tonic-gate sys_init(cid, clparmsz, clfuncspp) 1197c478bd9Sstevel@tonic-gate id_t cid; 1207c478bd9Sstevel@tonic-gate int clparmsz; 1217c478bd9Sstevel@tonic-gate classfuncs_t **clfuncspp; 1227c478bd9Sstevel@tonic-gate { 1237c478bd9Sstevel@tonic-gate *clfuncspp = &sys_classfuncs; 1247c478bd9Sstevel@tonic-gate return ((pri_t)v.v_maxsyspri); 1257c478bd9Sstevel@tonic-gate } 1267c478bd9Sstevel@tonic-gate 1277c478bd9Sstevel@tonic-gate /* 1287c478bd9Sstevel@tonic-gate * Get maximum and minimum priorities enjoyed by sysclass threads 1297c478bd9Sstevel@tonic-gate */ 1307c478bd9Sstevel@tonic-gate static int 1317c478bd9Sstevel@tonic-gate sys_getclpri(pcpri_t *pcprip) 1327c478bd9Sstevel@tonic-gate { 1337c478bd9Sstevel@tonic-gate pcprip->pc_clpmax = maxclsyspri; 134*d4204c85Sraf pcprip->pc_clpmin = minclsyspri; 1357c478bd9Sstevel@tonic-gate return (0); 1367c478bd9Sstevel@tonic-gate } 1377c478bd9Sstevel@tonic-gate 1387c478bd9Sstevel@tonic-gate /* ARGSUSED */ 1397c478bd9Sstevel@tonic-gate static int 1407c478bd9Sstevel@tonic-gate sys_enterclass(t, cid, parmsp, reqpcredp, bufp) 141*d4204c85Sraf kthread_t *t; 1427c478bd9Sstevel@tonic-gate id_t cid; 1437c478bd9Sstevel@tonic-gate void *parmsp; 1447c478bd9Sstevel@tonic-gate cred_t *reqpcredp; 1457c478bd9Sstevel@tonic-gate void *bufp; 1467c478bd9Sstevel@tonic-gate { 1477c478bd9Sstevel@tonic-gate return (0); 1487c478bd9Sstevel@tonic-gate } 1497c478bd9Sstevel@tonic-gate 1507c478bd9Sstevel@tonic-gate /* ARGSUSED */ 1517c478bd9Sstevel@tonic-gate static int 152*d4204c85Sraf sys_canexit(kthread_t *t, cred_t *reqpcredp) 1537c478bd9Sstevel@tonic-gate { 1547c478bd9Sstevel@tonic-gate return (0); 1557c478bd9Sstevel@tonic-gate } 1567c478bd9Sstevel@tonic-gate 1577c478bd9Sstevel@tonic-gate /* ARGSUSED */ 1587c478bd9Sstevel@tonic-gate static int 1597c478bd9Sstevel@tonic-gate sys_fork(t, ct, bufp) 160*d4204c85Sraf kthread_t *t; 161*d4204c85Sraf kthread_t *ct; 1627c478bd9Sstevel@tonic-gate void *bufp; 1637c478bd9Sstevel@tonic-gate { 1647c478bd9Sstevel@tonic-gate /* 1657c478bd9Sstevel@tonic-gate * No class specific data structure 1667c478bd9Sstevel@tonic-gate */ 1677c478bd9Sstevel@tonic-gate return (0); 1687c478bd9Sstevel@tonic-gate } 1697c478bd9Sstevel@tonic-gate 1707c478bd9Sstevel@tonic-gate 1717c478bd9Sstevel@tonic-gate /* ARGSUSED */ 1727c478bd9Sstevel@tonic-gate static void 1737c478bd9Sstevel@tonic-gate sys_forkret(t, ct) 174*d4204c85Sraf kthread_t *t; 175*d4204c85Sraf kthread_t *ct; 1767c478bd9Sstevel@tonic-gate { 1777c478bd9Sstevel@tonic-gate register proc_t *pp = ttoproc(t); 1787c478bd9Sstevel@tonic-gate register proc_t *cp = ttoproc(ct); 1797c478bd9Sstevel@tonic-gate 1807c478bd9Sstevel@tonic-gate ASSERT(t == curthread); 1817c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&pidlock)); 1827c478bd9Sstevel@tonic-gate 1837c478bd9Sstevel@tonic-gate /* 1847c478bd9Sstevel@tonic-gate * Grab the child's p_lock before dropping pidlock to ensure 1857c478bd9Sstevel@tonic-gate * the process does not disappear before we set it running. 1867c478bd9Sstevel@tonic-gate */ 1877c478bd9Sstevel@tonic-gate mutex_enter(&cp->p_lock); 1887c478bd9Sstevel@tonic-gate mutex_exit(&pidlock); 1897c478bd9Sstevel@tonic-gate continuelwps(cp); 1907c478bd9Sstevel@tonic-gate mutex_exit(&cp->p_lock); 1917c478bd9Sstevel@tonic-gate 1927c478bd9Sstevel@tonic-gate mutex_enter(&pp->p_lock); 1937c478bd9Sstevel@tonic-gate continuelwps(pp); 1947c478bd9Sstevel@tonic-gate mutex_exit(&pp->p_lock); 1957c478bd9Sstevel@tonic-gate } 1967c478bd9Sstevel@tonic-gate 1977c478bd9Sstevel@tonic-gate /* ARGSUSED */ 1987c478bd9Sstevel@tonic-gate static pri_t 1997c478bd9Sstevel@tonic-gate sys_swappri(t, flags) 200*d4204c85Sraf kthread_t *t; 2017c478bd9Sstevel@tonic-gate int flags; 2027c478bd9Sstevel@tonic-gate { 2037c478bd9Sstevel@tonic-gate return (-1); 2047c478bd9Sstevel@tonic-gate } 2057c478bd9Sstevel@tonic-gate 2067c478bd9Sstevel@tonic-gate static int 2077c478bd9Sstevel@tonic-gate sys_nosys() 2087c478bd9Sstevel@tonic-gate { 2097c478bd9Sstevel@tonic-gate return (ENOSYS); 2107c478bd9Sstevel@tonic-gate } 2117c478bd9Sstevel@tonic-gate 2127c478bd9Sstevel@tonic-gate 2137c478bd9Sstevel@tonic-gate static void 2147c478bd9Sstevel@tonic-gate sys_nullsys() 2157c478bd9Sstevel@tonic-gate { 2167c478bd9Sstevel@tonic-gate } 2177c478bd9Sstevel@tonic-gate 2187c478bd9Sstevel@tonic-gate /* ARGSUSED */ 2197c478bd9Sstevel@tonic-gate static int 220*d4204c85Sraf sys_donice(kthread_t *t, cred_t *cr, int incr, int *retvalp) 221*d4204c85Sraf { 222*d4204c85Sraf return (EINVAL); 223*d4204c85Sraf } 224*d4204c85Sraf 225*d4204c85Sraf /* ARGSUSED */ 226*d4204c85Sraf static int 227*d4204c85Sraf sys_doprio(kthread_t *t, cred_t *cr, int incr, int *retvalp) 2287c478bd9Sstevel@tonic-gate { 2297c478bd9Sstevel@tonic-gate return (EINVAL); 2307c478bd9Sstevel@tonic-gate } 2317c478bd9Sstevel@tonic-gate 2327c478bd9Sstevel@tonic-gate /* ARGSUSED */ 2337c478bd9Sstevel@tonic-gate static int 2347c478bd9Sstevel@tonic-gate sys_alloc(void **p, int flag) 2357c478bd9Sstevel@tonic-gate { 2367c478bd9Sstevel@tonic-gate *p = NULL; 2377c478bd9Sstevel@tonic-gate return (0); 2387c478bd9Sstevel@tonic-gate } 239