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