1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
29
30 #include <sys/types.h>
31 #include <sys/param.h>
32 #include <sys/sysmacros.h>
33 #include <sys/signal.h>
34 #include <sys/pcb.h>
35 #include <sys/user.h>
36 #include <sys/systm.h>
37 #include <sys/sysinfo.h>
38 #include <sys/var.h>
39 #include <sys/errno.h>
40 #include <sys/cmn_err.h>
41 #include <sys/proc.h>
42 #include <sys/debug.h>
43 #include <sys/inline.h>
44 #include <sys/disp.h>
45 #include <sys/class.h>
46 #include <sys/kmem.h>
47 #include <sys/cpuvar.h>
48 #include <sys/priocntl.h>
49
50 /*
51 * Class specific code for the sys class. There are no
52 * class specific data structures associated with
53 * the sys class and the scheduling policy is trivially
54 * simple. There is no time slicing.
55 */
56
57 pri_t sys_init(id_t, int, classfuncs_t **);
58 static int sys_getclpri(pcpri_t *);
59 static int sys_fork(kthread_t *, kthread_t *, void *);
60 static int sys_enterclass(kthread_t *, id_t, void *, cred_t *, void *);
61 static int sys_canexit(kthread_t *, cred_t *);
62 static int sys_nosys();
63 static int sys_donice(kthread_t *, cred_t *, int, int *);
64 static int sys_doprio(kthread_t *, cred_t *, int, int *);
65 static void sys_forkret(kthread_t *, kthread_t *);
66 static void sys_nullsys();
67 static pri_t sys_swappri(kthread_t *, int);
68 static pri_t sys_globpri(kthread_t *);
69 static int sys_alloc(void **, int);
70
71 struct classfuncs sys_classfuncs = {
72 /* messages to class manager */
73 {
74 sys_nosys, /* admin */
75 sys_nosys, /* getclinfo */
76 sys_nosys, /* parmsin */
77 sys_nosys, /* parmsout */
78 sys_nosys, /* vaparmsin */
79 sys_nosys, /* vaparmsout */
80 sys_getclpri, /* getclpri */
81 sys_alloc,
82 sys_nullsys, /* free */
83 },
84 /* operations on threads */
85 {
86 sys_enterclass, /* enterclass */
87 sys_nullsys, /* exitclass */
88 sys_canexit,
89 sys_fork,
90 sys_forkret, /* forkret */
91 sys_nullsys, /* parmsget */
92 sys_nosys, /* parmsset */
93 sys_nullsys, /* stop */
94 sys_nullsys, /* exit */
95 sys_nullsys, /* active */
96 sys_nullsys, /* inactive */
97 sys_swappri, /* swapin */
98 sys_swappri, /* swapout */
99 sys_nullsys, /* trapret */
100 setfrontdq, /* preempt */
101 setbackdq, /* setrun */
102 sys_nullsys, /* sleep */
103 sys_nullsys, /* tick */
104 setbackdq, /* wakeup */
105 sys_donice,
106 sys_globpri, /* globpri */
107 sys_nullsys, /* set_process_group */
108 sys_nullsys, /* yield */
109 sys_doprio,
110 }
111
112 };
113
114
115 /* ARGSUSED */
116 pri_t
sys_init(cid,clparmsz,clfuncspp)117 sys_init(cid, clparmsz, clfuncspp)
118 id_t cid;
119 int clparmsz;
120 classfuncs_t **clfuncspp;
121 {
122 *clfuncspp = &sys_classfuncs;
123 return ((pri_t)v.v_maxsyspri);
124 }
125
126 /*
127 * Get maximum and minimum priorities enjoyed by sysclass threads
128 */
129 static int
sys_getclpri(pcpri_t * pcprip)130 sys_getclpri(pcpri_t *pcprip)
131 {
132 pcprip->pc_clpmax = maxclsyspri;
133 pcprip->pc_clpmin = minclsyspri;
134 return (0);
135 }
136
137 /* ARGSUSED */
138 static int
sys_enterclass(t,cid,parmsp,reqpcredp,bufp)139 sys_enterclass(t, cid, parmsp, reqpcredp, bufp)
140 kthread_t *t;
141 id_t cid;
142 void *parmsp;
143 cred_t *reqpcredp;
144 void *bufp;
145 {
146 return (0);
147 }
148
149 /* ARGSUSED */
150 static int
sys_canexit(kthread_t * t,cred_t * reqpcredp)151 sys_canexit(kthread_t *t, cred_t *reqpcredp)
152 {
153 return (0);
154 }
155
156 /* ARGSUSED */
157 static int
sys_fork(t,ct,bufp)158 sys_fork(t, ct, bufp)
159 kthread_t *t;
160 kthread_t *ct;
161 void *bufp;
162 {
163 /*
164 * No class specific data structure
165 */
166 return (0);
167 }
168
169
170 /* ARGSUSED */
171 static void
sys_forkret(t,ct)172 sys_forkret(t, ct)
173 kthread_t *t;
174 kthread_t *ct;
175 {
176 register proc_t *pp = ttoproc(t);
177 register proc_t *cp = ttoproc(ct);
178
179 ASSERT(t == curthread);
180 ASSERT(MUTEX_HELD(&pidlock));
181
182 /*
183 * Grab the child's p_lock before dropping pidlock to ensure
184 * the process does not disappear before we set it running.
185 */
186 mutex_enter(&cp->p_lock);
187 mutex_exit(&pidlock);
188 continuelwps(cp);
189 mutex_exit(&cp->p_lock);
190
191 mutex_enter(&pp->p_lock);
192 continuelwps(pp);
193 mutex_exit(&pp->p_lock);
194 }
195
196 /* ARGSUSED */
197 static pri_t
sys_swappri(t,flags)198 sys_swappri(t, flags)
199 kthread_t *t;
200 int flags;
201 {
202 return (-1);
203 }
204
205 /* ARGSUSED */
206 static pri_t
sys_globpri(kthread_t * t __unused)207 sys_globpri(kthread_t *t __unused)
208 {
209 return (-1);
210 }
211
212 static int
sys_nosys()213 sys_nosys()
214 {
215 return (ENOSYS);
216 }
217
218
219 static void
sys_nullsys()220 sys_nullsys()
221 {
222 }
223
224 /* ARGSUSED */
225 static int
sys_donice(kthread_t * t,cred_t * cr,int incr,int * retvalp)226 sys_donice(kthread_t *t, cred_t *cr, int incr, int *retvalp)
227 {
228 return (EINVAL);
229 }
230
231 /* ARGSUSED */
232 static int
sys_doprio(kthread_t * t,cred_t * cr,int incr,int * retvalp)233 sys_doprio(kthread_t *t, cred_t *cr, int incr, int *retvalp)
234 {
235 return (EINVAL);
236 }
237
238 /* ARGSUSED */
239 static int
sys_alloc(void ** p,int flag)240 sys_alloc(void **p, int flag)
241 {
242 *p = NULL;
243 return (0);
244 }
245