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