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 5*c97ad5cdSakolb * Common Development and Distribution License (the "License"). 6*c97ad5cdSakolb * 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*c97ad5cdSakolb 227c478bd9Sstevel@tonic-gate /* 23*c97ad5cdSakolb * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 24*c97ad5cdSakolb * 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 317c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" /* from SVr4.0 1.12 */ 327c478bd9Sstevel@tonic-gate 337c478bd9Sstevel@tonic-gate #include <sys/types.h> 347c478bd9Sstevel@tonic-gate #include <sys/param.h> 357c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h> 367c478bd9Sstevel@tonic-gate #include <sys/signal.h> 377c478bd9Sstevel@tonic-gate #include <sys/pcb.h> 387c478bd9Sstevel@tonic-gate #include <sys/user.h> 397c478bd9Sstevel@tonic-gate #include <sys/systm.h> 407c478bd9Sstevel@tonic-gate #include <sys/sysinfo.h> 417c478bd9Sstevel@tonic-gate #include <sys/var.h> 427c478bd9Sstevel@tonic-gate #include <sys/errno.h> 437c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h> 447c478bd9Sstevel@tonic-gate #include <sys/proc.h> 457c478bd9Sstevel@tonic-gate #include <sys/debug.h> 467c478bd9Sstevel@tonic-gate #include <sys/inline.h> 477c478bd9Sstevel@tonic-gate #include <sys/disp.h> 487c478bd9Sstevel@tonic-gate #include <sys/class.h> 497c478bd9Sstevel@tonic-gate #include <sys/kmem.h> 507c478bd9Sstevel@tonic-gate #include <sys/cpuvar.h> 517c478bd9Sstevel@tonic-gate #include <sys/priocntl.h> 527c478bd9Sstevel@tonic-gate 537c478bd9Sstevel@tonic-gate /* 547c478bd9Sstevel@tonic-gate * Class specific code for the sys class. There are no 557c478bd9Sstevel@tonic-gate * class specific data structures associated with 567c478bd9Sstevel@tonic-gate * the sys class and the scheduling policy is trivially 577c478bd9Sstevel@tonic-gate * simple. There is no time slicing. 587c478bd9Sstevel@tonic-gate */ 597c478bd9Sstevel@tonic-gate 607c478bd9Sstevel@tonic-gate pri_t sys_init(id_t, int, classfuncs_t **); 617c478bd9Sstevel@tonic-gate static int sys_getclpri(pcpri_t *); 627c478bd9Sstevel@tonic-gate static int sys_fork(kthread_id_t, kthread_id_t, void *); 637c478bd9Sstevel@tonic-gate static int sys_enterclass(kthread_id_t, id_t, void *, cred_t *, void *); 647c478bd9Sstevel@tonic-gate static int sys_canexit(kthread_id_t, cred_t *); 657c478bd9Sstevel@tonic-gate static int sys_nosys(); 667c478bd9Sstevel@tonic-gate static int sys_donice(kthread_id_t, cred_t *, int, int *); 677c478bd9Sstevel@tonic-gate static void sys_forkret(kthread_id_t, kthread_id_t); 687c478bd9Sstevel@tonic-gate static void sys_nullsys(); 697c478bd9Sstevel@tonic-gate static pri_t sys_swappri(kthread_id_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 */ 101*c97ad5cdSakolb 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 */ 1107c478bd9Sstevel@tonic-gate } 1117c478bd9Sstevel@tonic-gate 1127c478bd9Sstevel@tonic-gate }; 1137c478bd9Sstevel@tonic-gate 1147c478bd9Sstevel@tonic-gate 1157c478bd9Sstevel@tonic-gate /* ARGSUSED */ 1167c478bd9Sstevel@tonic-gate pri_t 1177c478bd9Sstevel@tonic-gate sys_init(cid, clparmsz, clfuncspp) 1187c478bd9Sstevel@tonic-gate id_t cid; 1197c478bd9Sstevel@tonic-gate int clparmsz; 1207c478bd9Sstevel@tonic-gate classfuncs_t **clfuncspp; 1217c478bd9Sstevel@tonic-gate { 1227c478bd9Sstevel@tonic-gate *clfuncspp = &sys_classfuncs; 1237c478bd9Sstevel@tonic-gate return ((pri_t)v.v_maxsyspri); 1247c478bd9Sstevel@tonic-gate } 1257c478bd9Sstevel@tonic-gate 1267c478bd9Sstevel@tonic-gate /* 1277c478bd9Sstevel@tonic-gate * Get maximum and minimum priorities enjoyed by sysclass threads 1287c478bd9Sstevel@tonic-gate */ 1297c478bd9Sstevel@tonic-gate static int 1307c478bd9Sstevel@tonic-gate sys_getclpri(pcpri_t *pcprip) 1317c478bd9Sstevel@tonic-gate { 1327c478bd9Sstevel@tonic-gate pcprip->pc_clpmax = maxclsyspri; 1337c478bd9Sstevel@tonic-gate pcprip->pc_clpmin = 0; 1347c478bd9Sstevel@tonic-gate return (0); 1357c478bd9Sstevel@tonic-gate } 1367c478bd9Sstevel@tonic-gate 1377c478bd9Sstevel@tonic-gate /* ARGSUSED */ 1387c478bd9Sstevel@tonic-gate static int 1397c478bd9Sstevel@tonic-gate sys_enterclass(t, cid, parmsp, reqpcredp, bufp) 1407c478bd9Sstevel@tonic-gate kthread_id_t t; 1417c478bd9Sstevel@tonic-gate id_t cid; 1427c478bd9Sstevel@tonic-gate void *parmsp; 1437c478bd9Sstevel@tonic-gate cred_t *reqpcredp; 1447c478bd9Sstevel@tonic-gate void *bufp; 1457c478bd9Sstevel@tonic-gate { 1467c478bd9Sstevel@tonic-gate return (0); 1477c478bd9Sstevel@tonic-gate } 1487c478bd9Sstevel@tonic-gate 1497c478bd9Sstevel@tonic-gate /* ARGSUSED */ 1507c478bd9Sstevel@tonic-gate static int 1517c478bd9Sstevel@tonic-gate sys_canexit(kthread_id_t t, cred_t *reqpcredp) 1527c478bd9Sstevel@tonic-gate { 1537c478bd9Sstevel@tonic-gate return (0); 1547c478bd9Sstevel@tonic-gate } 1557c478bd9Sstevel@tonic-gate 1567c478bd9Sstevel@tonic-gate /* ARGSUSED */ 1577c478bd9Sstevel@tonic-gate static int 1587c478bd9Sstevel@tonic-gate sys_fork(t, ct, bufp) 1597c478bd9Sstevel@tonic-gate kthread_id_t t; 1607c478bd9Sstevel@tonic-gate kthread_id_t ct; 1617c478bd9Sstevel@tonic-gate void *bufp; 1627c478bd9Sstevel@tonic-gate { 1637c478bd9Sstevel@tonic-gate /* 1647c478bd9Sstevel@tonic-gate * No class specific data structure 1657c478bd9Sstevel@tonic-gate */ 1667c478bd9Sstevel@tonic-gate return (0); 1677c478bd9Sstevel@tonic-gate } 1687c478bd9Sstevel@tonic-gate 1697c478bd9Sstevel@tonic-gate 1707c478bd9Sstevel@tonic-gate /* ARGSUSED */ 1717c478bd9Sstevel@tonic-gate static void 1727c478bd9Sstevel@tonic-gate sys_forkret(t, ct) 1737c478bd9Sstevel@tonic-gate kthread_id_t t; 1747c478bd9Sstevel@tonic-gate kthread_id_t ct; 1757c478bd9Sstevel@tonic-gate { 1767c478bd9Sstevel@tonic-gate register proc_t *pp = ttoproc(t); 1777c478bd9Sstevel@tonic-gate register proc_t *cp = ttoproc(ct); 1787c478bd9Sstevel@tonic-gate 1797c478bd9Sstevel@tonic-gate ASSERT(t == curthread); 1807c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&pidlock)); 1817c478bd9Sstevel@tonic-gate 1827c478bd9Sstevel@tonic-gate /* 1837c478bd9Sstevel@tonic-gate * Grab the child's p_lock before dropping pidlock to ensure 1847c478bd9Sstevel@tonic-gate * the process does not disappear before we set it running. 1857c478bd9Sstevel@tonic-gate */ 1867c478bd9Sstevel@tonic-gate mutex_enter(&cp->p_lock); 1877c478bd9Sstevel@tonic-gate mutex_exit(&pidlock); 1887c478bd9Sstevel@tonic-gate continuelwps(cp); 1897c478bd9Sstevel@tonic-gate mutex_exit(&cp->p_lock); 1907c478bd9Sstevel@tonic-gate 1917c478bd9Sstevel@tonic-gate mutex_enter(&pp->p_lock); 1927c478bd9Sstevel@tonic-gate continuelwps(pp); 1937c478bd9Sstevel@tonic-gate mutex_exit(&pp->p_lock); 1947c478bd9Sstevel@tonic-gate } 1957c478bd9Sstevel@tonic-gate 1967c478bd9Sstevel@tonic-gate /* ARGSUSED */ 1977c478bd9Sstevel@tonic-gate static pri_t 1987c478bd9Sstevel@tonic-gate sys_swappri(t, flags) 1997c478bd9Sstevel@tonic-gate kthread_id_t t; 2007c478bd9Sstevel@tonic-gate int flags; 2017c478bd9Sstevel@tonic-gate { 2027c478bd9Sstevel@tonic-gate return (-1); 2037c478bd9Sstevel@tonic-gate } 2047c478bd9Sstevel@tonic-gate 2057c478bd9Sstevel@tonic-gate static int 2067c478bd9Sstevel@tonic-gate sys_nosys() 2077c478bd9Sstevel@tonic-gate { 2087c478bd9Sstevel@tonic-gate return (ENOSYS); 2097c478bd9Sstevel@tonic-gate } 2107c478bd9Sstevel@tonic-gate 2117c478bd9Sstevel@tonic-gate 2127c478bd9Sstevel@tonic-gate static void 2137c478bd9Sstevel@tonic-gate sys_nullsys() 2147c478bd9Sstevel@tonic-gate { 2157c478bd9Sstevel@tonic-gate } 2167c478bd9Sstevel@tonic-gate 2177c478bd9Sstevel@tonic-gate /* ARGSUSED */ 2187c478bd9Sstevel@tonic-gate static int 2197c478bd9Sstevel@tonic-gate sys_donice(t, cr, incr, retvalp) 2207c478bd9Sstevel@tonic-gate kthread_id_t t; 2217c478bd9Sstevel@tonic-gate cred_t *cr; 2227c478bd9Sstevel@tonic-gate int incr; 2237c478bd9Sstevel@tonic-gate int *retvalp; 2247c478bd9Sstevel@tonic-gate { 2257c478bd9Sstevel@tonic-gate return (EINVAL); 2267c478bd9Sstevel@tonic-gate } 2277c478bd9Sstevel@tonic-gate 2287c478bd9Sstevel@tonic-gate /* ARGSUSED */ 2297c478bd9Sstevel@tonic-gate static int 2307c478bd9Sstevel@tonic-gate sys_alloc(void **p, int flag) 2317c478bd9Sstevel@tonic-gate { 2327c478bd9Sstevel@tonic-gate *p = NULL; 2337c478bd9Sstevel@tonic-gate return (0); 2347c478bd9Sstevel@tonic-gate } 235