xref: /illumos-gate/usr/src/uts/common/disp/fx.c (revision 2570281c)
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  */
21d4204c85Sraf 
227c478bd9Sstevel@tonic-gate /*
23d5493db7SPramod Batni  * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
2424d819e6SJerry Jelinek  * Copyright 2013, Joyent, Inc. All rights reserved.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #include <sys/types.h>
287c478bd9Sstevel@tonic-gate #include <sys/param.h>
297c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
307c478bd9Sstevel@tonic-gate #include <sys/cred.h>
317c478bd9Sstevel@tonic-gate #include <sys/proc.h>
327c478bd9Sstevel@tonic-gate #include <sys/session.h>
337c478bd9Sstevel@tonic-gate #include <sys/strsubr.h>
347c478bd9Sstevel@tonic-gate #include <sys/user.h>
357c478bd9Sstevel@tonic-gate #include <sys/priocntl.h>
367c478bd9Sstevel@tonic-gate #include <sys/class.h>
377c478bd9Sstevel@tonic-gate #include <sys/disp.h>
387c478bd9Sstevel@tonic-gate #include <sys/procset.h>
397c478bd9Sstevel@tonic-gate #include <sys/debug.h>
407c478bd9Sstevel@tonic-gate #include <sys/kmem.h>
417c478bd9Sstevel@tonic-gate #include <sys/errno.h>
427c478bd9Sstevel@tonic-gate #include <sys/fx.h>
437c478bd9Sstevel@tonic-gate #include <sys/fxpriocntl.h>
447c478bd9Sstevel@tonic-gate #include <sys/cpuvar.h>
457c478bd9Sstevel@tonic-gate #include <sys/systm.h>
467c478bd9Sstevel@tonic-gate #include <sys/vtrace.h>
477c478bd9Sstevel@tonic-gate #include <sys/schedctl.h>
487c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
497c478bd9Sstevel@tonic-gate #include <sys/spl.h>
507c478bd9Sstevel@tonic-gate #include <sys/modctl.h>
517c478bd9Sstevel@tonic-gate #include <sys/policy.h>
527c478bd9Sstevel@tonic-gate #include <sys/sdt.h>
537c478bd9Sstevel@tonic-gate #include <sys/cpupart.h>
54c97ad5cdSakolb #include <sys/cpucaps.h>
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate static pri_t fx_init(id_t, int, classfuncs_t **);
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate static struct sclass csw = {
597c478bd9Sstevel@tonic-gate 	"FX",
607c478bd9Sstevel@tonic-gate 	fx_init,
617c478bd9Sstevel@tonic-gate 	0
627c478bd9Sstevel@tonic-gate };
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate static struct modlsched modlsched = {
657c478bd9Sstevel@tonic-gate 	&mod_schedops, "Fixed priority sched class", &csw
667c478bd9Sstevel@tonic-gate };
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate static struct modlinkage modlinkage = {
697c478bd9Sstevel@tonic-gate 	MODREV_1, (void *)&modlsched, NULL
707c478bd9Sstevel@tonic-gate };
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate /*
747c478bd9Sstevel@tonic-gate  * control flags (kparms->fx_cflags).
757c478bd9Sstevel@tonic-gate  */
767c478bd9Sstevel@tonic-gate #define	FX_DOUPRILIM	0x01    /* change user priority limit */
777c478bd9Sstevel@tonic-gate #define	FX_DOUPRI	0x02    /* change user priority */
787c478bd9Sstevel@tonic-gate #define	FX_DOTQ		0x04    /* change FX time quantum */
797c478bd9Sstevel@tonic-gate 
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate #define	FXMAXUPRI 60		/* maximum user priority setting */
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate #define	FX_MAX_UNPRIV_PRI	0	/* maximum unpriviledge priority */
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate /*
867c478bd9Sstevel@tonic-gate  * The fxproc_t structures that have a registered callback vector,
877c478bd9Sstevel@tonic-gate  * are also kept in an array of circular doubly linked lists. A hash on
887c478bd9Sstevel@tonic-gate  * the thread id (from ddi_get_kt_did()) is used to determine which list
897c478bd9Sstevel@tonic-gate  * each of such fxproc structures should be placed. Each list has a dummy
907c478bd9Sstevel@tonic-gate  * "head" which is never removed, so the list is never empty.
917c478bd9Sstevel@tonic-gate  */
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate #define	FX_CB_LISTS 16		/* number of lists, must be power of 2 */
947c478bd9Sstevel@tonic-gate #define	FX_CB_LIST_HASH(ktid)	((uint_t)ktid & (FX_CB_LISTS - 1))
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate /* Insert fxproc into callback list */
977c478bd9Sstevel@tonic-gate #define	FX_CB_LIST_INSERT(fxpp)						\
987c478bd9Sstevel@tonic-gate {									\
997c478bd9Sstevel@tonic-gate 	int index = FX_CB_LIST_HASH(fxpp->fx_ktid);			\
1007c478bd9Sstevel@tonic-gate 	kmutex_t *lockp = &fx_cb_list_lock[index];			\
1017c478bd9Sstevel@tonic-gate 	fxproc_t *headp = &fx_cb_plisthead[index];			\
1027c478bd9Sstevel@tonic-gate 	mutex_enter(lockp);						\
1037c478bd9Sstevel@tonic-gate 	fxpp->fx_cb_next = headp->fx_cb_next;				\
1047c478bd9Sstevel@tonic-gate 	fxpp->fx_cb_prev = headp;					\
1057c478bd9Sstevel@tonic-gate 	headp->fx_cb_next->fx_cb_prev = fxpp;				\
1067c478bd9Sstevel@tonic-gate 	headp->fx_cb_next = fxpp;					\
1077c478bd9Sstevel@tonic-gate 	mutex_exit(lockp);						\
1087c478bd9Sstevel@tonic-gate }
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate /*
1117c478bd9Sstevel@tonic-gate  * Remove thread from callback list.
1127c478bd9Sstevel@tonic-gate  */
1137c478bd9Sstevel@tonic-gate #define	FX_CB_LIST_DELETE(fxpp)						\
1147c478bd9Sstevel@tonic-gate {									\
1157c478bd9Sstevel@tonic-gate 	int index = FX_CB_LIST_HASH(fxpp->fx_ktid);			\
1167c478bd9Sstevel@tonic-gate 	kmutex_t *lockp = &fx_cb_list_lock[index];			\
1177c478bd9Sstevel@tonic-gate 	mutex_enter(lockp);						\
1187c478bd9Sstevel@tonic-gate 	fxpp->fx_cb_prev->fx_cb_next = fxpp->fx_cb_next;		\
1197c478bd9Sstevel@tonic-gate 	fxpp->fx_cb_next->fx_cb_prev = fxpp->fx_cb_prev;		\
1207c478bd9Sstevel@tonic-gate 	mutex_exit(lockp);						\
1217c478bd9Sstevel@tonic-gate }
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate #define	FX_HAS_CB(fxpp)	(fxpp->fx_callback != NULL)
1247c478bd9Sstevel@tonic-gate 
1257c478bd9Sstevel@tonic-gate /* adjust x to be between 0 and fx_maxumdpri */
1267c478bd9Sstevel@tonic-gate 
1277c478bd9Sstevel@tonic-gate #define	FX_ADJUST_PRI(pri)						\
1287c478bd9Sstevel@tonic-gate {									\
1297c478bd9Sstevel@tonic-gate 	if (pri < 0)							\
13034b7c4d5SToomas Soome 		pri = 0;						\
13134b7c4d5SToomas Soome 	else if (pri > fx_maxumdpri)					\
13234b7c4d5SToomas Soome 		pri = fx_maxumdpri;					\
1337c478bd9Sstevel@tonic-gate }
1347c478bd9Sstevel@tonic-gate 
1357c478bd9Sstevel@tonic-gate #define	FX_ADJUST_QUANTUM(q)						\
1367c478bd9Sstevel@tonic-gate {									\
1377c478bd9Sstevel@tonic-gate 	if (q > INT_MAX)						\
1387c478bd9Sstevel@tonic-gate 		q = INT_MAX;						\
1397c478bd9Sstevel@tonic-gate 	else if (q <= 0)						\
1407c478bd9Sstevel@tonic-gate 		q = FX_TQINF;						\
1417c478bd9Sstevel@tonic-gate }
1427c478bd9Sstevel@tonic-gate 
1437c478bd9Sstevel@tonic-gate #define	FX_ISVALID(pri, quantum) \
1447c478bd9Sstevel@tonic-gate 	(((pri >= 0) || (pri == FX_CB_NOCHANGE)) &&			\
1457c478bd9Sstevel@tonic-gate 	    ((quantum >= 0) || (quantum == FX_NOCHANGE) ||		\
1467c478bd9Sstevel@tonic-gate 		(quantum == FX_TQDEF) || (quantum == FX_TQINF)))
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate 
1497c478bd9Sstevel@tonic-gate static id_t	fx_cid;		/* fixed priority class ID */
1507c478bd9Sstevel@tonic-gate static fxdpent_t *fx_dptbl;	/* fixed priority disp parameter table */
1517c478bd9Sstevel@tonic-gate 
1527c478bd9Sstevel@tonic-gate static pri_t	fx_maxupri = FXMAXUPRI;
1537c478bd9Sstevel@tonic-gate static pri_t	fx_maxumdpri;	/* max user mode fixed priority */
1547c478bd9Sstevel@tonic-gate 
1557c478bd9Sstevel@tonic-gate static pri_t	fx_maxglobpri;	/* maximum global priority used by fx class */
1567c478bd9Sstevel@tonic-gate static kmutex_t	fx_dptblock;	/* protects fixed priority dispatch table */
1577c478bd9Sstevel@tonic-gate 
1587c478bd9Sstevel@tonic-gate 
1597c478bd9Sstevel@tonic-gate static kmutex_t	fx_cb_list_lock[FX_CB_LISTS];	/* protects list of fxprocs */
1607c478bd9Sstevel@tonic-gate 						/* that have callbacks */
1617c478bd9Sstevel@tonic-gate static fxproc_t	fx_cb_plisthead[FX_CB_LISTS];	/* dummy fxproc at head of */
1627c478bd9Sstevel@tonic-gate 						/* list of fxprocs with */
1637c478bd9Sstevel@tonic-gate 						/* callbacks */
1647c478bd9Sstevel@tonic-gate 
1657c478bd9Sstevel@tonic-gate static int	fx_admin(caddr_t, cred_t *);
1667c478bd9Sstevel@tonic-gate static int	fx_getclinfo(void *);
1677c478bd9Sstevel@tonic-gate static int	fx_parmsin(void *);
1687c478bd9Sstevel@tonic-gate static int	fx_parmsout(void *, pc_vaparms_t *);
1697c478bd9Sstevel@tonic-gate static int	fx_vaparmsin(void *, pc_vaparms_t *);
1707c478bd9Sstevel@tonic-gate static int	fx_vaparmsout(void *, pc_vaparms_t *);
1717c478bd9Sstevel@tonic-gate static int	fx_getclpri(pcpri_t *);
1727c478bd9Sstevel@tonic-gate static int	fx_alloc(void **, int);
1737c478bd9Sstevel@tonic-gate static void	fx_free(void *);
1747c478bd9Sstevel@tonic-gate static int	fx_enterclass(kthread_t *, id_t, void *, cred_t *, void *);
1757c478bd9Sstevel@tonic-gate static void	fx_exitclass(void *);
1767c478bd9Sstevel@tonic-gate static int	fx_canexit(kthread_t *, cred_t *);
1777c478bd9Sstevel@tonic-gate static int	fx_fork(kthread_t *, kthread_t *, void *);
1787c478bd9Sstevel@tonic-gate static void	fx_forkret(kthread_t *, kthread_t *);
1797c478bd9Sstevel@tonic-gate static void	fx_parmsget(kthread_t *, void *);
1807c478bd9Sstevel@tonic-gate static int	fx_parmsset(kthread_t *, void *, id_t, cred_t *);
1817c478bd9Sstevel@tonic-gate static void	fx_stop(kthread_t *, int, int);
1827c478bd9Sstevel@tonic-gate static void	fx_exit(kthread_t *);
1837c478bd9Sstevel@tonic-gate static pri_t	fx_swapin(kthread_t *, int);
1847c478bd9Sstevel@tonic-gate static pri_t	fx_swapout(kthread_t *, int);
1857c478bd9Sstevel@tonic-gate static void	fx_trapret(kthread_t *);
1867c478bd9Sstevel@tonic-gate static void	fx_preempt(kthread_t *);
1877c478bd9Sstevel@tonic-gate static void	fx_setrun(kthread_t *);
1887c478bd9Sstevel@tonic-gate static void	fx_sleep(kthread_t *);
1897c478bd9Sstevel@tonic-gate static void	fx_tick(kthread_t *);
1907c478bd9Sstevel@tonic-gate static void	fx_wakeup(kthread_t *);
1917c478bd9Sstevel@tonic-gate static int	fx_donice(kthread_t *, cred_t *, int, int *);
192d4204c85Sraf static int	fx_doprio(kthread_t *, cred_t *, int, int *);
1937c478bd9Sstevel@tonic-gate static pri_t	fx_globpri(kthread_t *);
1947c478bd9Sstevel@tonic-gate static void	fx_yield(kthread_t *);
1957c478bd9Sstevel@tonic-gate static void	fx_nullsys();
1967c478bd9Sstevel@tonic-gate 
1977c478bd9Sstevel@tonic-gate extern fxdpent_t *fx_getdptbl(void);
1987c478bd9Sstevel@tonic-gate 
1997c478bd9Sstevel@tonic-gate static void	fx_change_priority(kthread_t *, fxproc_t *);
2007c478bd9Sstevel@tonic-gate static fxproc_t *fx_list_lookup(kt_did_t);
2017c478bd9Sstevel@tonic-gate static void fx_list_release(fxproc_t *);
2027c478bd9Sstevel@tonic-gate 
2037c478bd9Sstevel@tonic-gate 
2047c478bd9Sstevel@tonic-gate static struct classfuncs fx_classfuncs = {
2057c478bd9Sstevel@tonic-gate 	/* class functions */
2067c478bd9Sstevel@tonic-gate 	fx_admin,
2077c478bd9Sstevel@tonic-gate 	fx_getclinfo,
2087c478bd9Sstevel@tonic-gate 	fx_parmsin,
2097c478bd9Sstevel@tonic-gate 	fx_parmsout,
2107c478bd9Sstevel@tonic-gate 	fx_vaparmsin,
2117c478bd9Sstevel@tonic-gate 	fx_vaparmsout,
2127c478bd9Sstevel@tonic-gate 	fx_getclpri,
2137c478bd9Sstevel@tonic-gate 	fx_alloc,
2147c478bd9Sstevel@tonic-gate 	fx_free,
2157c478bd9Sstevel@tonic-gate 
2167c478bd9Sstevel@tonic-gate 	/* thread functions */
2177c478bd9Sstevel@tonic-gate 	fx_enterclass,
2187c478bd9Sstevel@tonic-gate 	fx_exitclass,
2197c478bd9Sstevel@tonic-gate 	fx_canexit,
2207c478bd9Sstevel@tonic-gate 	fx_fork,
2217c478bd9Sstevel@tonic-gate 	fx_forkret,
2227c478bd9Sstevel@tonic-gate 	fx_parmsget,
2237c478bd9Sstevel@tonic-gate 	fx_parmsset,
2247c478bd9Sstevel@tonic-gate 	fx_stop,
2257c478bd9Sstevel@tonic-gate 	fx_exit,
2267c478bd9Sstevel@tonic-gate 	fx_nullsys,	/* active */
2277c478bd9Sstevel@tonic-gate 	fx_nullsys,	/* inactive */
2287c478bd9Sstevel@tonic-gate 	fx_swapin,
2297c478bd9Sstevel@tonic-gate 	fx_swapout,
2307c478bd9Sstevel@tonic-gate 	fx_trapret,
2317c478bd9Sstevel@tonic-gate 	fx_preempt,
2327c478bd9Sstevel@tonic-gate 	fx_setrun,
2337c478bd9Sstevel@tonic-gate 	fx_sleep,
2347c478bd9Sstevel@tonic-gate 	fx_tick,
2357c478bd9Sstevel@tonic-gate 	fx_wakeup,
2367c478bd9Sstevel@tonic-gate 	fx_donice,
2377c478bd9Sstevel@tonic-gate 	fx_globpri,
2387c478bd9Sstevel@tonic-gate 	fx_nullsys,	/* set_process_group */
2397c478bd9Sstevel@tonic-gate 	fx_yield,
240d4204c85Sraf 	fx_doprio,
2417c478bd9Sstevel@tonic-gate };
2427c478bd9Sstevel@tonic-gate 
2437c478bd9Sstevel@tonic-gate 
2447c478bd9Sstevel@tonic-gate int
_init()2457c478bd9Sstevel@tonic-gate _init()
2467c478bd9Sstevel@tonic-gate {
2477c478bd9Sstevel@tonic-gate 	return (mod_install(&modlinkage));
2487c478bd9Sstevel@tonic-gate }
2497c478bd9Sstevel@tonic-gate 
2507c478bd9Sstevel@tonic-gate int
_fini()2517c478bd9Sstevel@tonic-gate _fini()
2527c478bd9Sstevel@tonic-gate {
2537c478bd9Sstevel@tonic-gate 	return (EBUSY);
2547c478bd9Sstevel@tonic-gate }
2557c478bd9Sstevel@tonic-gate 
2567c478bd9Sstevel@tonic-gate int
_info(struct modinfo * modinfop)2577c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop)
2587c478bd9Sstevel@tonic-gate {
2597c478bd9Sstevel@tonic-gate 	return (mod_info(&modlinkage, modinfop));
2607c478bd9Sstevel@tonic-gate }
2617c478bd9Sstevel@tonic-gate 
2627c478bd9Sstevel@tonic-gate /*
2637c478bd9Sstevel@tonic-gate  * Fixed priority class initialization. Called by dispinit() at boot time.
2647c478bd9Sstevel@tonic-gate  * We can ignore the clparmsz argument since we know that the smallest
2657c478bd9Sstevel@tonic-gate  * possible parameter buffer is big enough for us.
2667c478bd9Sstevel@tonic-gate  */
2677c478bd9Sstevel@tonic-gate /* ARGSUSED */
2687c478bd9Sstevel@tonic-gate static pri_t
fx_init(id_t cid,int clparmsz,classfuncs_t ** clfuncspp)2697c478bd9Sstevel@tonic-gate fx_init(id_t cid, int clparmsz, classfuncs_t **clfuncspp)
2707c478bd9Sstevel@tonic-gate {
2717c478bd9Sstevel@tonic-gate 	int i;
2727c478bd9Sstevel@tonic-gate 	extern pri_t fx_getmaxumdpri(void);
2737c478bd9Sstevel@tonic-gate 
2747c478bd9Sstevel@tonic-gate 	fx_dptbl = fx_getdptbl();
2757c478bd9Sstevel@tonic-gate 	fx_maxumdpri = fx_getmaxumdpri();
2767c478bd9Sstevel@tonic-gate 	fx_maxglobpri = fx_dptbl[fx_maxumdpri].fx_globpri;
2777c478bd9Sstevel@tonic-gate 
2787c478bd9Sstevel@tonic-gate 	fx_cid = cid;		/* Record our class ID */
2797c478bd9Sstevel@tonic-gate 
2807c478bd9Sstevel@tonic-gate 	/*
2817c478bd9Sstevel@tonic-gate 	 * Initialize the hash table for fxprocs with callbacks
2827c478bd9Sstevel@tonic-gate 	 */
2837c478bd9Sstevel@tonic-gate 	for (i = 0; i < FX_CB_LISTS; i++) {
2847c478bd9Sstevel@tonic-gate 		fx_cb_plisthead[i].fx_cb_next = fx_cb_plisthead[i].fx_cb_prev =
285d4204c85Sraf 		    &fx_cb_plisthead[i];
2867c478bd9Sstevel@tonic-gate 	}
2877c478bd9Sstevel@tonic-gate 
2887c478bd9Sstevel@tonic-gate 	/*
2897c478bd9Sstevel@tonic-gate 	 * We're required to return a pointer to our classfuncs
2907c478bd9Sstevel@tonic-gate 	 * structure and the highest global priority value we use.
2917c478bd9Sstevel@tonic-gate 	 */
2927c478bd9Sstevel@tonic-gate 	*clfuncspp = &fx_classfuncs;
2937c478bd9Sstevel@tonic-gate 	return (fx_maxglobpri);
2947c478bd9Sstevel@tonic-gate }
2957c478bd9Sstevel@tonic-gate 
2967c478bd9Sstevel@tonic-gate /*
2977c478bd9Sstevel@tonic-gate  * Get or reset the fx_dptbl values per the user's request.
2987c478bd9Sstevel@tonic-gate  */
2997c478bd9Sstevel@tonic-gate static int
fx_admin(caddr_t uaddr,cred_t * reqpcredp)3007c478bd9Sstevel@tonic-gate fx_admin(caddr_t uaddr, cred_t *reqpcredp)
3017c478bd9Sstevel@tonic-gate {
3027c478bd9Sstevel@tonic-gate 	fxadmin_t	fxadmin;
3037c478bd9Sstevel@tonic-gate 	fxdpent_t	*tmpdpp;
3047c478bd9Sstevel@tonic-gate 	int		userdpsz;
3057c478bd9Sstevel@tonic-gate 	int		i;
3067c478bd9Sstevel@tonic-gate 	size_t		fxdpsz;
3077c478bd9Sstevel@tonic-gate 
3087c478bd9Sstevel@tonic-gate 	if (get_udatamodel() == DATAMODEL_NATIVE) {
3097c478bd9Sstevel@tonic-gate 		if (copyin(uaddr, &fxadmin, sizeof (fxadmin_t)))
3107c478bd9Sstevel@tonic-gate 			return (EFAULT);
3117c478bd9Sstevel@tonic-gate 	}
3127c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32_IMPL
3137c478bd9Sstevel@tonic-gate 	else {
3147c478bd9Sstevel@tonic-gate 		/* get fxadmin struct from ILP32 caller */
3157c478bd9Sstevel@tonic-gate 		fxadmin32_t fxadmin32;
3167c478bd9Sstevel@tonic-gate 		if (copyin(uaddr, &fxadmin32, sizeof (fxadmin32_t)))
3177c478bd9Sstevel@tonic-gate 			return (EFAULT);
3187c478bd9Sstevel@tonic-gate 		fxadmin.fx_dpents =
3197c478bd9Sstevel@tonic-gate 		    (struct fxdpent *)(uintptr_t)fxadmin32.fx_dpents;
3207c478bd9Sstevel@tonic-gate 		fxadmin.fx_ndpents = fxadmin32.fx_ndpents;
3217c478bd9Sstevel@tonic-gate 		fxadmin.fx_cmd = fxadmin32.fx_cmd;
3227c478bd9Sstevel@tonic-gate 	}
3237c478bd9Sstevel@tonic-gate #endif /* _SYSCALL32_IMPL */
3247c478bd9Sstevel@tonic-gate 
3257c478bd9Sstevel@tonic-gate 	fxdpsz = (fx_maxumdpri + 1) * sizeof (fxdpent_t);
3267c478bd9Sstevel@tonic-gate 
3277c478bd9Sstevel@tonic-gate 	switch (fxadmin.fx_cmd) {
3287c478bd9Sstevel@tonic-gate 	case FX_GETDPSIZE:
3297c478bd9Sstevel@tonic-gate 		fxadmin.fx_ndpents = fx_maxumdpri + 1;
3307c478bd9Sstevel@tonic-gate 
3317c478bd9Sstevel@tonic-gate 		if (get_udatamodel() == DATAMODEL_NATIVE) {
3327c478bd9Sstevel@tonic-gate 			if (copyout(&fxadmin, uaddr, sizeof (fxadmin_t)))
3337c478bd9Sstevel@tonic-gate 				return (EFAULT);
3347c478bd9Sstevel@tonic-gate 		}
3357c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32_IMPL
3367c478bd9Sstevel@tonic-gate 		else {
3377c478bd9Sstevel@tonic-gate 			/* return fxadmin struct to ILP32 caller */
3387c478bd9Sstevel@tonic-gate 			fxadmin32_t fxadmin32;
3397c478bd9Sstevel@tonic-gate 			fxadmin32.fx_dpents =
3407c478bd9Sstevel@tonic-gate 			    (caddr32_t)(uintptr_t)fxadmin.fx_dpents;
3417c478bd9Sstevel@tonic-gate 			fxadmin32.fx_ndpents = fxadmin.fx_ndpents;
3427c478bd9Sstevel@tonic-gate 			fxadmin32.fx_cmd = fxadmin.fx_cmd;
3437c478bd9Sstevel@tonic-gate 			if (copyout(&fxadmin32, uaddr, sizeof (fxadmin32_t)))
3447c478bd9Sstevel@tonic-gate 				return (EFAULT);
3457c478bd9Sstevel@tonic-gate 		}
3467c478bd9Sstevel@tonic-gate #endif /* _SYSCALL32_IMPL */
3477c478bd9Sstevel@tonic-gate 		break;
3487c478bd9Sstevel@tonic-gate 
3497c478bd9Sstevel@tonic-gate 	case FX_GETDPTBL:
3507c478bd9Sstevel@tonic-gate 		userdpsz = MIN(fxadmin.fx_ndpents * sizeof (fxdpent_t),
3517c478bd9Sstevel@tonic-gate 		    fxdpsz);
3527c478bd9Sstevel@tonic-gate 		if (copyout(fx_dptbl, fxadmin.fx_dpents, userdpsz))
3537c478bd9Sstevel@tonic-gate 			return (EFAULT);
3547c478bd9Sstevel@tonic-gate 
3557c478bd9Sstevel@tonic-gate 		fxadmin.fx_ndpents = userdpsz / sizeof (fxdpent_t);
3567c478bd9Sstevel@tonic-gate 
3577c478bd9Sstevel@tonic-gate 		if (get_udatamodel() == DATAMODEL_NATIVE) {
3587c478bd9Sstevel@tonic-gate 			if (copyout(&fxadmin, uaddr, sizeof (fxadmin_t)))
3597c478bd9Sstevel@tonic-gate 				return (EFAULT);
3607c478bd9Sstevel@tonic-gate 		}
3617c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32_IMPL
3627c478bd9Sstevel@tonic-gate 		else {
3637c478bd9Sstevel@tonic-gate 			/* return fxadmin struct to ILP32 callers */
3647c478bd9Sstevel@tonic-gate 			fxadmin32_t fxadmin32;
3657c478bd9Sstevel@tonic-gate 			fxadmin32.fx_dpents =
3667c478bd9Sstevel@tonic-gate 			    (caddr32_t)(uintptr_t)fxadmin.fx_dpents;
3677c478bd9Sstevel@tonic-gate 			fxadmin32.fx_ndpents = fxadmin.fx_ndpents;
3687c478bd9Sstevel@tonic-gate 			fxadmin32.fx_cmd = fxadmin.fx_cmd;
3697c478bd9Sstevel@tonic-gate 			if (copyout(&fxadmin32, uaddr, sizeof (fxadmin32_t)))
3707c478bd9Sstevel@tonic-gate 				return (EFAULT);
3717c478bd9Sstevel@tonic-gate 		}
3727c478bd9Sstevel@tonic-gate #endif /* _SYSCALL32_IMPL */
3737c478bd9Sstevel@tonic-gate 		break;
3747c478bd9Sstevel@tonic-gate 
3757c478bd9Sstevel@tonic-gate 	case FX_SETDPTBL:
3767c478bd9Sstevel@tonic-gate 		/*
3777c478bd9Sstevel@tonic-gate 		 * We require that the requesting process has sufficient
3787c478bd9Sstevel@tonic-gate 		 * privileges. We also require that the table supplied by
3797c478bd9Sstevel@tonic-gate 		 * the user exactly match the current fx_dptbl in size.
3807c478bd9Sstevel@tonic-gate 		 */
3817c478bd9Sstevel@tonic-gate 		if (secpolicy_dispadm(reqpcredp) != 0) {
3827c478bd9Sstevel@tonic-gate 			return (EPERM);
3837c478bd9Sstevel@tonic-gate 		}
3847c478bd9Sstevel@tonic-gate 		if (fxadmin.fx_ndpents * sizeof (fxdpent_t) != fxdpsz) {
3857c478bd9Sstevel@tonic-gate 			return (EINVAL);
3867c478bd9Sstevel@tonic-gate 		}
3877c478bd9Sstevel@tonic-gate 
3887c478bd9Sstevel@tonic-gate 		/*
3897c478bd9Sstevel@tonic-gate 		 * We read the user supplied table into a temporary buffer
3907c478bd9Sstevel@tonic-gate 		 * where it is validated before being copied over the
3917c478bd9Sstevel@tonic-gate 		 * fx_dptbl.
3927c478bd9Sstevel@tonic-gate 		 */
3937c478bd9Sstevel@tonic-gate 		tmpdpp = kmem_alloc(fxdpsz, KM_SLEEP);
3947c478bd9Sstevel@tonic-gate 		if (copyin(fxadmin.fx_dpents, tmpdpp, fxdpsz)) {
3957c478bd9Sstevel@tonic-gate 			kmem_free(tmpdpp, fxdpsz);
3967c478bd9Sstevel@tonic-gate 			return (EFAULT);
3977c478bd9Sstevel@tonic-gate 		}
3987c478bd9Sstevel@tonic-gate 		for (i = 0; i < fxadmin.fx_ndpents; i++) {
3997c478bd9Sstevel@tonic-gate 
4007c478bd9Sstevel@tonic-gate 			/*
4017c478bd9Sstevel@tonic-gate 			 * Validate the user supplied values. All we are doing
4027c478bd9Sstevel@tonic-gate 			 * here is verifying that the values are within their
4037c478bd9Sstevel@tonic-gate 			 * allowable ranges and will not panic the system. We
4047c478bd9Sstevel@tonic-gate 			 * make no attempt to ensure that the resulting
4057c478bd9Sstevel@tonic-gate 			 * configuration makes sense or results in reasonable
4067c478bd9Sstevel@tonic-gate 			 * performance.
4077c478bd9Sstevel@tonic-gate 			 */
4087c478bd9Sstevel@tonic-gate 			if (tmpdpp[i].fx_quantum <= 0 &&
4097c478bd9Sstevel@tonic-gate 			    tmpdpp[i].fx_quantum != FX_TQINF) {
4107c478bd9Sstevel@tonic-gate 				kmem_free(tmpdpp, fxdpsz);
4117c478bd9Sstevel@tonic-gate 				return (EINVAL);
4127c478bd9Sstevel@tonic-gate 			}
4137c478bd9Sstevel@tonic-gate 		}
4147c478bd9Sstevel@tonic-gate 
4157c478bd9Sstevel@tonic-gate 		/*
4167c478bd9Sstevel@tonic-gate 		 * Copy the user supplied values over the current fx_dptbl
4177c478bd9Sstevel@tonic-gate 		 * values. The fx_globpri member is read-only so we don't
4187c478bd9Sstevel@tonic-gate 		 * overwrite it.
4197c478bd9Sstevel@tonic-gate 		 */
4207c478bd9Sstevel@tonic-gate 		mutex_enter(&fx_dptblock);
4217c478bd9Sstevel@tonic-gate 		for (i = 0; i < fxadmin.fx_ndpents; i++) {
4227c478bd9Sstevel@tonic-gate 			fx_dptbl[i].fx_quantum = tmpdpp[i].fx_quantum;
4237c478bd9Sstevel@tonic-gate 		}
4247c478bd9Sstevel@tonic-gate 		mutex_exit(&fx_dptblock);
4257c478bd9Sstevel@tonic-gate 		kmem_free(tmpdpp, fxdpsz);
4267c478bd9Sstevel@tonic-gate 		break;
4277c478bd9Sstevel@tonic-gate 
4287c478bd9Sstevel@tonic-gate 	default:
4297c478bd9Sstevel@tonic-gate 		return (EINVAL);
4307c478bd9Sstevel@tonic-gate 	}
4317c478bd9Sstevel@tonic-gate 	return (0);
4327c478bd9Sstevel@tonic-gate }
4337c478bd9Sstevel@tonic-gate 
4347c478bd9Sstevel@tonic-gate /*
4357c478bd9Sstevel@tonic-gate  * Allocate a fixed priority class specific thread structure and
4367c478bd9Sstevel@tonic-gate  * initialize it with the parameters supplied. Also move the thread
4377c478bd9Sstevel@tonic-gate  * to specified priority.
4387c478bd9Sstevel@tonic-gate  */
4397c478bd9Sstevel@tonic-gate static int
fx_enterclass(kthread_t * t,id_t cid,void * parmsp,cred_t * reqpcredp,void * bufp)4407c478bd9Sstevel@tonic-gate fx_enterclass(kthread_t *t, id_t cid, void *parmsp, cred_t *reqpcredp,
4417c478bd9Sstevel@tonic-gate     void *bufp)
4427c478bd9Sstevel@tonic-gate {
4437c478bd9Sstevel@tonic-gate 	fxkparms_t	*fxkparmsp = (fxkparms_t *)parmsp;
4447c478bd9Sstevel@tonic-gate 	fxproc_t	*fxpp;
4457c478bd9Sstevel@tonic-gate 	pri_t		reqfxupri;
4467c478bd9Sstevel@tonic-gate 	pri_t		reqfxuprilim;
4477c478bd9Sstevel@tonic-gate 
4487c478bd9Sstevel@tonic-gate 	fxpp = (fxproc_t *)bufp;
4497c478bd9Sstevel@tonic-gate 	ASSERT(fxpp != NULL);
4507c478bd9Sstevel@tonic-gate 
4517c478bd9Sstevel@tonic-gate 	/*
4527c478bd9Sstevel@tonic-gate 	 * Initialize the fxproc structure.
4537c478bd9Sstevel@tonic-gate 	 */
4547c478bd9Sstevel@tonic-gate 	fxpp->fx_flags = 0;
4557c478bd9Sstevel@tonic-gate 	fxpp->fx_callback = NULL;
45634b7c4d5SToomas Soome 	fxpp->fx_cookie = 0;
4577c478bd9Sstevel@tonic-gate 
4587c478bd9Sstevel@tonic-gate 	if (fxkparmsp == NULL) {
4597c478bd9Sstevel@tonic-gate 		/*
4607c478bd9Sstevel@tonic-gate 		 * Use default values.
4617c478bd9Sstevel@tonic-gate 		 */
4627c478bd9Sstevel@tonic-gate 		fxpp->fx_pri = fxpp->fx_uprilim = 0;
4637c478bd9Sstevel@tonic-gate 		fxpp->fx_pquantum = fx_dptbl[fxpp->fx_pri].fx_quantum;
4647c478bd9Sstevel@tonic-gate 		fxpp->fx_nice =  NZERO;
4657c478bd9Sstevel@tonic-gate 	} else {
4667c478bd9Sstevel@tonic-gate 		/*
4677c478bd9Sstevel@tonic-gate 		 * Use supplied values.
4687c478bd9Sstevel@tonic-gate 		 */
4697c478bd9Sstevel@tonic-gate 
4707c478bd9Sstevel@tonic-gate 		if ((fxkparmsp->fx_cflags & FX_DOUPRILIM) == 0) {
4717c478bd9Sstevel@tonic-gate 			reqfxuprilim = 0;
4727c478bd9Sstevel@tonic-gate 		} else {
4737c478bd9Sstevel@tonic-gate 			if (fxkparmsp->fx_uprilim > FX_MAX_UNPRIV_PRI &&
4747c478bd9Sstevel@tonic-gate 			    secpolicy_setpriority(reqpcredp) != 0)
4757c478bd9Sstevel@tonic-gate 				return (EPERM);
4767c478bd9Sstevel@tonic-gate 			reqfxuprilim = fxkparmsp->fx_uprilim;
4777c478bd9Sstevel@tonic-gate 			FX_ADJUST_PRI(reqfxuprilim);
4787c478bd9Sstevel@tonic-gate 		}
4797c478bd9Sstevel@tonic-gate 
4807c478bd9Sstevel@tonic-gate 		if ((fxkparmsp->fx_cflags & FX_DOUPRI) == 0) {
4817c478bd9Sstevel@tonic-gate 			reqfxupri = reqfxuprilim;
4827c478bd9Sstevel@tonic-gate 		} else {
4837c478bd9Sstevel@tonic-gate 			if (fxkparmsp->fx_upri > FX_MAX_UNPRIV_PRI &&
4847c478bd9Sstevel@tonic-gate 			    secpolicy_setpriority(reqpcredp) != 0)
4857c478bd9Sstevel@tonic-gate 				return (EPERM);
4867c478bd9Sstevel@tonic-gate 			/*
4877c478bd9Sstevel@tonic-gate 			 * Set the user priority to the requested value
4887c478bd9Sstevel@tonic-gate 			 * or the upri limit, whichever is lower.
4897c478bd9Sstevel@tonic-gate 			 */
4907c478bd9Sstevel@tonic-gate 			reqfxupri = fxkparmsp->fx_upri;
4917c478bd9Sstevel@tonic-gate 			FX_ADJUST_PRI(reqfxupri);
4927c478bd9Sstevel@tonic-gate 
4937c478bd9Sstevel@tonic-gate 			if (reqfxupri > reqfxuprilim)
4947c478bd9Sstevel@tonic-gate 				reqfxupri = reqfxuprilim;
4957c478bd9Sstevel@tonic-gate 		}
4967c478bd9Sstevel@tonic-gate 
4977c478bd9Sstevel@tonic-gate 
4987c478bd9Sstevel@tonic-gate 		fxpp->fx_uprilim = reqfxuprilim;
4997c478bd9Sstevel@tonic-gate 		fxpp->fx_pri = reqfxupri;
5007c478bd9Sstevel@tonic-gate 
501d4204c85Sraf 		fxpp->fx_nice = NZERO - (NZERO * reqfxupri) / fx_maxupri;
5027c478bd9Sstevel@tonic-gate 
5037c478bd9Sstevel@tonic-gate 		if (((fxkparmsp->fx_cflags & FX_DOTQ) == 0) ||
5047c478bd9Sstevel@tonic-gate 		    (fxkparmsp->fx_tqntm == FX_TQDEF)) {
5057c478bd9Sstevel@tonic-gate 			fxpp->fx_pquantum = fx_dptbl[fxpp->fx_pri].fx_quantum;
5067c478bd9Sstevel@tonic-gate 		} else {
5077c478bd9Sstevel@tonic-gate 			if (secpolicy_setpriority(reqpcredp) != 0)
5087c478bd9Sstevel@tonic-gate 				return (EPERM);
5097c478bd9Sstevel@tonic-gate 
5107c478bd9Sstevel@tonic-gate 			if (fxkparmsp->fx_tqntm == FX_TQINF)
5117c478bd9Sstevel@tonic-gate 				fxpp->fx_pquantum = FX_TQINF;
5127c478bd9Sstevel@tonic-gate 			else {
5137c478bd9Sstevel@tonic-gate 				fxpp->fx_pquantum = fxkparmsp->fx_tqntm;
5147c478bd9Sstevel@tonic-gate 			}
5157c478bd9Sstevel@tonic-gate 		}
5167c478bd9Sstevel@tonic-gate 
5177c478bd9Sstevel@tonic-gate 	}
5187c478bd9Sstevel@tonic-gate 
5197c478bd9Sstevel@tonic-gate 	fxpp->fx_timeleft = fxpp->fx_pquantum;
520c97ad5cdSakolb 	cpucaps_sc_init(&fxpp->fx_caps);
5217c478bd9Sstevel@tonic-gate 	fxpp->fx_tp = t;
5227c478bd9Sstevel@tonic-gate 
5237c478bd9Sstevel@tonic-gate 	thread_lock(t);			/* get dispatcher lock on thread */
5247c478bd9Sstevel@tonic-gate 	t->t_clfuncs = &(sclass[cid].cl_funcs->thread);
5257c478bd9Sstevel@tonic-gate 	t->t_cid = cid;
5267c478bd9Sstevel@tonic-gate 	t->t_cldata = (void *)fxpp;
5277c478bd9Sstevel@tonic-gate 	t->t_schedflag &= ~TS_RUNQMATCH;
5287c478bd9Sstevel@tonic-gate 	fx_change_priority(t, fxpp);
5297c478bd9Sstevel@tonic-gate 	thread_unlock(t);
5307c478bd9Sstevel@tonic-gate 
5317c478bd9Sstevel@tonic-gate 	return (0);
5327c478bd9Sstevel@tonic-gate }
5337c478bd9Sstevel@tonic-gate 
5347c478bd9Sstevel@tonic-gate /*
5357c478bd9Sstevel@tonic-gate  * The thread is exiting.
5367c478bd9Sstevel@tonic-gate  */
5377c478bd9Sstevel@tonic-gate static void
fx_exit(kthread_t * t)5387c478bd9Sstevel@tonic-gate fx_exit(kthread_t *t)
5397c478bd9Sstevel@tonic-gate {
5407c478bd9Sstevel@tonic-gate 	fxproc_t *fxpp;
5417c478bd9Sstevel@tonic-gate 
5427c478bd9Sstevel@tonic-gate 	thread_lock(t);
5437c478bd9Sstevel@tonic-gate 	fxpp = (fxproc_t *)(t->t_cldata);
5447c478bd9Sstevel@tonic-gate 
5458c34bbb7Sakolb 	/*
5468c34bbb7Sakolb 	 * A thread could be exiting in between clock ticks, so we need to
5478c34bbb7Sakolb 	 * calculate how much CPU time it used since it was charged last time.
5488c34bbb7Sakolb 	 *
5498c34bbb7Sakolb 	 * CPU caps are not enforced on exiting processes - it is usually
5508c34bbb7Sakolb 	 * desirable to exit as soon as possible to free resources.
5518c34bbb7Sakolb 	 */
552c97ad5cdSakolb 	(void) CPUCAPS_CHARGE(t, &fxpp->fx_caps, CPUCAPS_CHARGE_ONLY);
553c97ad5cdSakolb 
5547c478bd9Sstevel@tonic-gate 	if (FX_HAS_CB(fxpp)) {
5557c478bd9Sstevel@tonic-gate 		FX_CB_EXIT(FX_CALLB(fxpp), fxpp->fx_cookie);
5567c478bd9Sstevel@tonic-gate 		fxpp->fx_callback = NULL;
55734b7c4d5SToomas Soome 		fxpp->fx_cookie = 0;
5587c478bd9Sstevel@tonic-gate 		thread_unlock(t);
5597c478bd9Sstevel@tonic-gate 		FX_CB_LIST_DELETE(fxpp);
5607c478bd9Sstevel@tonic-gate 		return;
5617c478bd9Sstevel@tonic-gate 	}
562c97ad5cdSakolb 
5637c478bd9Sstevel@tonic-gate 	thread_unlock(t);
5647c478bd9Sstevel@tonic-gate }
5657c478bd9Sstevel@tonic-gate 
5667c478bd9Sstevel@tonic-gate /*
5677c478bd9Sstevel@tonic-gate  * Exiting the class. Free fxproc structure of thread.
5687c478bd9Sstevel@tonic-gate  */
5697c478bd9Sstevel@tonic-gate static void
fx_exitclass(void * procp)5707c478bd9Sstevel@tonic-gate fx_exitclass(void *procp)
5717c478bd9Sstevel@tonic-gate {
5727c478bd9Sstevel@tonic-gate 	fxproc_t *fxpp = (fxproc_t *)procp;
5737c478bd9Sstevel@tonic-gate 
5747c478bd9Sstevel@tonic-gate 	thread_lock(fxpp->fx_tp);
5757c478bd9Sstevel@tonic-gate 	if (FX_HAS_CB(fxpp)) {
5767c478bd9Sstevel@tonic-gate 
5777c478bd9Sstevel@tonic-gate 		FX_CB_EXIT(FX_CALLB(fxpp), fxpp->fx_cookie);
5787c478bd9Sstevel@tonic-gate 
5797c478bd9Sstevel@tonic-gate 		fxpp->fx_callback = NULL;
58034b7c4d5SToomas Soome 		fxpp->fx_cookie = 0;
5817c478bd9Sstevel@tonic-gate 		thread_unlock(fxpp->fx_tp);
5827c478bd9Sstevel@tonic-gate 		FX_CB_LIST_DELETE(fxpp);
5837c478bd9Sstevel@tonic-gate 	} else
5847c478bd9Sstevel@tonic-gate 		thread_unlock(fxpp->fx_tp);
5857c478bd9Sstevel@tonic-gate 
5867c478bd9Sstevel@tonic-gate 	kmem_free(fxpp, sizeof (fxproc_t));
5877c478bd9Sstevel@tonic-gate }
5887c478bd9Sstevel@tonic-gate 
5897c478bd9Sstevel@tonic-gate /* ARGSUSED */
5907c478bd9Sstevel@tonic-gate static int
fx_canexit(kthread_t * t,cred_t * cred)5917c478bd9Sstevel@tonic-gate fx_canexit(kthread_t *t, cred_t *cred)
5927c478bd9Sstevel@tonic-gate {
5937c478bd9Sstevel@tonic-gate 	/*
5947c478bd9Sstevel@tonic-gate 	 * A thread can always leave the FX class
5957c478bd9Sstevel@tonic-gate 	 */
5967c478bd9Sstevel@tonic-gate 	return (0);
5977c478bd9Sstevel@tonic-gate }
5987c478bd9Sstevel@tonic-gate 
5997c478bd9Sstevel@tonic-gate /*
6007c478bd9Sstevel@tonic-gate  * Initialize fixed-priority class specific proc structure for a child.
6017c478bd9Sstevel@tonic-gate  * callbacks are not inherited upon fork.
6027c478bd9Sstevel@tonic-gate  */
6037c478bd9Sstevel@tonic-gate static int
fx_fork(kthread_t * t,kthread_t * ct,void * bufp)6047c478bd9Sstevel@tonic-gate fx_fork(kthread_t *t, kthread_t *ct, void *bufp)
6057c478bd9Sstevel@tonic-gate {
6067c478bd9Sstevel@tonic-gate 	fxproc_t	*pfxpp;		/* ptr to parent's fxproc structure */
6077c478bd9Sstevel@tonic-gate 	fxproc_t	*cfxpp;		/* ptr to child's fxproc structure */
6087c478bd9Sstevel@tonic-gate 
6097c478bd9Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&ttoproc(t)->p_lock));
6107c478bd9Sstevel@tonic-gate 
6117c478bd9Sstevel@tonic-gate 	cfxpp = (fxproc_t *)bufp;
6127c478bd9Sstevel@tonic-gate 	ASSERT(cfxpp != NULL);
6137c478bd9Sstevel@tonic-gate 	thread_lock(t);
6147c478bd9Sstevel@tonic-gate 	pfxpp = (fxproc_t *)t->t_cldata;
6157c478bd9Sstevel@tonic-gate 	/*
6167c478bd9Sstevel@tonic-gate 	 * Initialize child's fxproc structure.
6177c478bd9Sstevel@tonic-gate 	 */
6187c478bd9Sstevel@tonic-gate 	cfxpp->fx_timeleft = cfxpp->fx_pquantum = pfxpp->fx_pquantum;
6197c478bd9Sstevel@tonic-gate 	cfxpp->fx_pri = pfxpp->fx_pri;
6207c478bd9Sstevel@tonic-gate 	cfxpp->fx_uprilim = pfxpp->fx_uprilim;
6217c478bd9Sstevel@tonic-gate 	cfxpp->fx_nice = pfxpp->fx_nice;
6227c478bd9Sstevel@tonic-gate 	cfxpp->fx_callback = NULL;
62334b7c4d5SToomas Soome 	cfxpp->fx_cookie = 0;
6247c478bd9Sstevel@tonic-gate 	cfxpp->fx_flags = pfxpp->fx_flags & ~(FXBACKQ);
625c97ad5cdSakolb 	cpucaps_sc_init(&cfxpp->fx_caps);
6267c478bd9Sstevel@tonic-gate 
6277c478bd9Sstevel@tonic-gate 	cfxpp->fx_tp = ct;
6287c478bd9Sstevel@tonic-gate 	ct->t_cldata = (void *)cfxpp;
6297c478bd9Sstevel@tonic-gate 	thread_unlock(t);
6307c478bd9Sstevel@tonic-gate 
6317c478bd9Sstevel@tonic-gate 	/*
6327c478bd9Sstevel@tonic-gate 	 * Link new structure into fxproc list.
6337c478bd9Sstevel@tonic-gate 	 */
6347c478bd9Sstevel@tonic-gate 	return (0);
6357c478bd9Sstevel@tonic-gate }
6367c478bd9Sstevel@tonic-gate 
6377c478bd9Sstevel@tonic-gate 
6387c478bd9Sstevel@tonic-gate /*
6397c478bd9Sstevel@tonic-gate  * Child is placed at back of dispatcher queue and parent gives
6407c478bd9Sstevel@tonic-gate  * up processor so that the child runs first after the fork.
6417c478bd9Sstevel@tonic-gate  * This allows the child immediately execing to break the multiple
6427c478bd9Sstevel@tonic-gate  * use of copy on write pages with no disk home. The parent will
6437c478bd9Sstevel@tonic-gate  * get to steal them back rather than uselessly copying them.
6447c478bd9Sstevel@tonic-gate  */
6457c478bd9Sstevel@tonic-gate static void
fx_forkret(kthread_t * t,kthread_t * ct)6467c478bd9Sstevel@tonic-gate fx_forkret(kthread_t *t, kthread_t *ct)
6477c478bd9Sstevel@tonic-gate {
6487c478bd9Sstevel@tonic-gate 	proc_t	*pp = ttoproc(t);
6497c478bd9Sstevel@tonic-gate 	proc_t	*cp = ttoproc(ct);
6507c478bd9Sstevel@tonic-gate 	fxproc_t *fxpp;
6517c478bd9Sstevel@tonic-gate 
6527c478bd9Sstevel@tonic-gate 	ASSERT(t == curthread);
6537c478bd9Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&pidlock));
6547c478bd9Sstevel@tonic-gate 
6557c478bd9Sstevel@tonic-gate 	/*
6567c478bd9Sstevel@tonic-gate 	 * Grab the child's p_lock before dropping pidlock to ensure
6577c478bd9Sstevel@tonic-gate 	 * the process does not disappear before we set it running.
6587c478bd9Sstevel@tonic-gate 	 */
6597c478bd9Sstevel@tonic-gate 	mutex_enter(&cp->p_lock);
6607c478bd9Sstevel@tonic-gate 	continuelwps(cp);
6617c478bd9Sstevel@tonic-gate 	mutex_exit(&cp->p_lock);
6627c478bd9Sstevel@tonic-gate 
6637c478bd9Sstevel@tonic-gate 	mutex_enter(&pp->p_lock);
664d5493db7SPramod Batni 	mutex_exit(&pidlock);
6657c478bd9Sstevel@tonic-gate 	continuelwps(pp);
6667c478bd9Sstevel@tonic-gate 
6677c478bd9Sstevel@tonic-gate 	thread_lock(t);
6687c478bd9Sstevel@tonic-gate 	fxpp = (fxproc_t *)(t->t_cldata);
6697c478bd9Sstevel@tonic-gate 	t->t_pri = fx_dptbl[fxpp->fx_pri].fx_globpri;
6707c478bd9Sstevel@tonic-gate 	ASSERT(t->t_pri >= 0 && t->t_pri <= fx_maxglobpri);
6717c478bd9Sstevel@tonic-gate 	THREAD_TRANSITION(t);
6727c478bd9Sstevel@tonic-gate 	fx_setrun(t);
6737c478bd9Sstevel@tonic-gate 	thread_unlock(t);
674d5493db7SPramod Batni 	/*
675d5493db7SPramod Batni 	 * Safe to drop p_lock now since it is safe to change
676d5493db7SPramod Batni 	 * the scheduling class after this point.
677d5493db7SPramod Batni 	 */
678d5493db7SPramod Batni 	mutex_exit(&pp->p_lock);
6797c478bd9Sstevel@tonic-gate 
6807c478bd9Sstevel@tonic-gate 	swtch();
6817c478bd9Sstevel@tonic-gate }
6827c478bd9Sstevel@tonic-gate 
6837c478bd9Sstevel@tonic-gate 
6847c478bd9Sstevel@tonic-gate /*
6857c478bd9Sstevel@tonic-gate  * Get information about the fixed-priority class into the buffer
6867c478bd9Sstevel@tonic-gate  * pointed to by fxinfop. The maximum configured user priority
6877c478bd9Sstevel@tonic-gate  * is the only information we supply.
6887c478bd9Sstevel@tonic-gate  */
6897c478bd9Sstevel@tonic-gate static int
fx_getclinfo(void * infop)6907c478bd9Sstevel@tonic-gate fx_getclinfo(void *infop)
6917c478bd9Sstevel@tonic-gate {
6927c478bd9Sstevel@tonic-gate 	fxinfo_t *fxinfop = (fxinfo_t *)infop;
6937c478bd9Sstevel@tonic-gate 	fxinfop->fx_maxupri = fx_maxupri;
6947c478bd9Sstevel@tonic-gate 	return (0);
6957c478bd9Sstevel@tonic-gate }
6967c478bd9Sstevel@tonic-gate 
6977c478bd9Sstevel@tonic-gate 
6987c478bd9Sstevel@tonic-gate 
6997c478bd9Sstevel@tonic-gate /*
700d4204c85Sraf  * Return the user mode scheduling priority range.
7017c478bd9Sstevel@tonic-gate  */
7027c478bd9Sstevel@tonic-gate static int
fx_getclpri(pcpri_t * pcprip)7037c478bd9Sstevel@tonic-gate fx_getclpri(pcpri_t *pcprip)
7047c478bd9Sstevel@tonic-gate {
705d4204c85Sraf 	pcprip->pc_clpmax = fx_maxupri;
706d4204c85Sraf 	pcprip->pc_clpmin = 0;
7077c478bd9Sstevel@tonic-gate 	return (0);
7087c478bd9Sstevel@tonic-gate }
7097c478bd9Sstevel@tonic-gate 
7107c478bd9Sstevel@tonic-gate 
7117c478bd9Sstevel@tonic-gate static void
fx_nullsys()7127c478bd9Sstevel@tonic-gate fx_nullsys()
7137c478bd9Sstevel@tonic-gate {}
7147c478bd9Sstevel@tonic-gate 
7157c478bd9Sstevel@tonic-gate 
7167c478bd9Sstevel@tonic-gate /*
7177c478bd9Sstevel@tonic-gate  * Get the fixed-priority parameters of the thread pointed to by
7187c478bd9Sstevel@tonic-gate  * fxprocp into the buffer pointed to by fxparmsp.
7197c478bd9Sstevel@tonic-gate  */
7207c478bd9Sstevel@tonic-gate static void
fx_parmsget(kthread_t * t,void * parmsp)7217c478bd9Sstevel@tonic-gate fx_parmsget(kthread_t *t, void *parmsp)
7227c478bd9Sstevel@tonic-gate {
7237c478bd9Sstevel@tonic-gate 	fxproc_t *fxpp = (fxproc_t *)t->t_cldata;
7247c478bd9Sstevel@tonic-gate 	fxkparms_t *fxkparmsp = (fxkparms_t *)parmsp;
7257c478bd9Sstevel@tonic-gate 
7267c478bd9Sstevel@tonic-gate 	fxkparmsp->fx_upri = fxpp->fx_pri;
7277c478bd9Sstevel@tonic-gate 	fxkparmsp->fx_uprilim = fxpp->fx_uprilim;
7287c478bd9Sstevel@tonic-gate 	fxkparmsp->fx_tqntm = fxpp->fx_pquantum;
7297c478bd9Sstevel@tonic-gate }
7307c478bd9Sstevel@tonic-gate 
7317c478bd9Sstevel@tonic-gate 
7327c478bd9Sstevel@tonic-gate 
7337c478bd9Sstevel@tonic-gate /*
7347c478bd9Sstevel@tonic-gate  * Check the validity of the fixed-priority parameters in the buffer
7357c478bd9Sstevel@tonic-gate  * pointed to by fxparmsp.
7367c478bd9Sstevel@tonic-gate  */
7377c478bd9Sstevel@tonic-gate static int
fx_parmsin(void * parmsp)7387c478bd9Sstevel@tonic-gate fx_parmsin(void *parmsp)
7397c478bd9Sstevel@tonic-gate {
7407c478bd9Sstevel@tonic-gate 	fxparms_t	*fxparmsp = (fxparms_t *)parmsp;
7417c478bd9Sstevel@tonic-gate 	uint_t		cflags;
7427c478bd9Sstevel@tonic-gate 	longlong_t	ticks;
7437c478bd9Sstevel@tonic-gate 	/*
7447c478bd9Sstevel@tonic-gate 	 * Check validity of parameters.
7457c478bd9Sstevel@tonic-gate 	 */
7467c478bd9Sstevel@tonic-gate 
7477c478bd9Sstevel@tonic-gate 	if ((fxparmsp->fx_uprilim > fx_maxupri ||
7487c478bd9Sstevel@tonic-gate 	    fxparmsp->fx_uprilim < 0) &&
7497c478bd9Sstevel@tonic-gate 	    fxparmsp->fx_uprilim != FX_NOCHANGE)
7507c478bd9Sstevel@tonic-gate 		return (EINVAL);
7517c478bd9Sstevel@tonic-gate 
7527c478bd9Sstevel@tonic-gate 	if ((fxparmsp->fx_upri > fx_maxupri ||
7537c478bd9Sstevel@tonic-gate 	    fxparmsp->fx_upri < 0) &&
7547c478bd9Sstevel@tonic-gate 	    fxparmsp->fx_upri != FX_NOCHANGE)
7557c478bd9Sstevel@tonic-gate 		return (EINVAL);
7567c478bd9Sstevel@tonic-gate 
7577c478bd9Sstevel@tonic-gate 	if ((fxparmsp->fx_tqsecs == 0 && fxparmsp->fx_tqnsecs == 0) ||
758d4204c85Sraf 	    fxparmsp->fx_tqnsecs >= NANOSEC)
7597c478bd9Sstevel@tonic-gate 		return (EINVAL);
7607c478bd9Sstevel@tonic-gate 
7617c478bd9Sstevel@tonic-gate 	cflags = (fxparmsp->fx_upri != FX_NOCHANGE ? FX_DOUPRI : 0);
7627c478bd9Sstevel@tonic-gate 
7637c478bd9Sstevel@tonic-gate 	if (fxparmsp->fx_uprilim != FX_NOCHANGE) {
7647c478bd9Sstevel@tonic-gate 		cflags |= FX_DOUPRILIM;
7657c478bd9Sstevel@tonic-gate 	}
7667c478bd9Sstevel@tonic-gate 
7677c478bd9Sstevel@tonic-gate 	if (fxparmsp->fx_tqnsecs != FX_NOCHANGE)
7687c478bd9Sstevel@tonic-gate 		cflags |= FX_DOTQ;
7697c478bd9Sstevel@tonic-gate 
7707c478bd9Sstevel@tonic-gate 	/*
7717c478bd9Sstevel@tonic-gate 	 * convert the buffer to kernel format.
7727c478bd9Sstevel@tonic-gate 	 */
7737c478bd9Sstevel@tonic-gate 
7747c478bd9Sstevel@tonic-gate 	if (fxparmsp->fx_tqnsecs >= 0) {
7757c478bd9Sstevel@tonic-gate 		if ((ticks = SEC_TO_TICK((longlong_t)fxparmsp->fx_tqsecs) +
7767c478bd9Sstevel@tonic-gate 		    NSEC_TO_TICK_ROUNDUP(fxparmsp->fx_tqnsecs)) > INT_MAX)
7777c478bd9Sstevel@tonic-gate 			return (ERANGE);
7787c478bd9Sstevel@tonic-gate 
7797c478bd9Sstevel@tonic-gate 		((fxkparms_t *)fxparmsp)->fx_tqntm = (int)ticks;
7807c478bd9Sstevel@tonic-gate 	} else {
7817c478bd9Sstevel@tonic-gate 		if ((fxparmsp->fx_tqnsecs != FX_NOCHANGE) &&
7827c478bd9Sstevel@tonic-gate 		    (fxparmsp->fx_tqnsecs != FX_TQINF) &&
7837c478bd9Sstevel@tonic-gate 		    (fxparmsp->fx_tqnsecs != FX_TQDEF))
7847c478bd9Sstevel@tonic-gate 			return (EINVAL);
7857c478bd9Sstevel@tonic-gate 		((fxkparms_t *)fxparmsp)->fx_tqntm = fxparmsp->fx_tqnsecs;
7867c478bd9Sstevel@tonic-gate 	}
7877c478bd9Sstevel@tonic-gate 
7887c478bd9Sstevel@tonic-gate 	((fxkparms_t *)fxparmsp)->fx_cflags = cflags;
7897c478bd9Sstevel@tonic-gate 
7907c478bd9Sstevel@tonic-gate 	return (0);
7917c478bd9Sstevel@tonic-gate }
7927c478bd9Sstevel@tonic-gate 
7937c478bd9Sstevel@tonic-gate 
7947c478bd9Sstevel@tonic-gate /*
7957c478bd9Sstevel@tonic-gate  * Check the validity of the fixed-priority parameters in the pc_vaparms_t
7967c478bd9Sstevel@tonic-gate  * structure vaparmsp and put them in the buffer pointed to by fxprmsp.
7977c478bd9Sstevel@tonic-gate  * pc_vaparms_t contains (key, value) pairs of parameter.
7987c478bd9Sstevel@tonic-gate  */
7997c478bd9Sstevel@tonic-gate static int
fx_vaparmsin(void * prmsp,pc_vaparms_t * vaparmsp)8007c478bd9Sstevel@tonic-gate fx_vaparmsin(void *prmsp, pc_vaparms_t *vaparmsp)
8017c478bd9Sstevel@tonic-gate {
8027c478bd9Sstevel@tonic-gate 	uint_t		secs = 0;
8037c478bd9Sstevel@tonic-gate 	uint_t		cnt;
8047c478bd9Sstevel@tonic-gate 	int		nsecs = 0;
8057c478bd9Sstevel@tonic-gate 	int		priflag, secflag, nsecflag, limflag;
8067c478bd9Sstevel@tonic-gate 	longlong_t	ticks;
8077c478bd9Sstevel@tonic-gate 	fxkparms_t	*fxprmsp = (fxkparms_t *)prmsp;
8087c478bd9Sstevel@tonic-gate 	pc_vaparm_t	*vpp = &vaparmsp->pc_parms[0];
8097c478bd9Sstevel@tonic-gate 
8107c478bd9Sstevel@tonic-gate 
8117c478bd9Sstevel@tonic-gate 	/*
8127c478bd9Sstevel@tonic-gate 	 * First check the validity of parameters and convert them
8137c478bd9Sstevel@tonic-gate 	 * from the user supplied format to the internal format.
8147c478bd9Sstevel@tonic-gate 	 */
8157c478bd9Sstevel@tonic-gate 	priflag = secflag = nsecflag = limflag = 0;
8167c478bd9Sstevel@tonic-gate 
8177c478bd9Sstevel@tonic-gate 	fxprmsp->fx_cflags = 0;
8187c478bd9Sstevel@tonic-gate 
8197c478bd9Sstevel@tonic-gate 	if (vaparmsp->pc_vaparmscnt > PC_VAPARMCNT)
8207c478bd9Sstevel@tonic-gate 		return (EINVAL);
8217c478bd9Sstevel@tonic-gate 
8227c478bd9Sstevel@tonic-gate 	for (cnt = 0; cnt < vaparmsp->pc_vaparmscnt; cnt++, vpp++) {
8237c478bd9Sstevel@tonic-gate 
8247c478bd9Sstevel@tonic-gate 		switch (vpp->pc_key) {
8257c478bd9Sstevel@tonic-gate 		case FX_KY_UPRILIM:
8267c478bd9Sstevel@tonic-gate 			if (limflag++)
8277c478bd9Sstevel@tonic-gate 				return (EINVAL);
8287c478bd9Sstevel@tonic-gate 			fxprmsp->fx_cflags |= FX_DOUPRILIM;
8297c478bd9Sstevel@tonic-gate 			fxprmsp->fx_uprilim = (pri_t)vpp->pc_parm;
8307c478bd9Sstevel@tonic-gate 			if (fxprmsp->fx_uprilim > fx_maxupri ||
8317c478bd9Sstevel@tonic-gate 			    fxprmsp->fx_uprilim < 0)
8327c478bd9Sstevel@tonic-gate 				return (EINVAL);
8337c478bd9Sstevel@tonic-gate 			break;
8347c478bd9Sstevel@tonic-gate 
8357c478bd9Sstevel@tonic-gate 		case FX_KY_UPRI:
8367c478bd9Sstevel@tonic-gate 			if (priflag++)
8377c478bd9Sstevel@tonic-gate 				return (EINVAL);
8387c478bd9Sstevel@tonic-gate 			fxprmsp->fx_cflags |= FX_DOUPRI;
8397c478bd9Sstevel@tonic-gate 			fxprmsp->fx_upri = (pri_t)vpp->pc_parm;
8407c478bd9Sstevel@tonic-gate 			if (fxprmsp->fx_upri > fx_maxupri ||
8417c478bd9Sstevel@tonic-gate 			    fxprmsp->fx_upri < 0)
8427c478bd9Sstevel@tonic-gate 				return (EINVAL);
8437c478bd9Sstevel@tonic-gate 			break;
8447c478bd9Sstevel@tonic-gate 
8457c478bd9Sstevel@tonic-gate 		case FX_KY_TQSECS:
8467c478bd9Sstevel@tonic-gate 			if (secflag++)
8477c478bd9Sstevel@tonic-gate 				return (EINVAL);
8487c478bd9Sstevel@tonic-gate 			fxprmsp->fx_cflags |= FX_DOTQ;
8497c478bd9Sstevel@tonic-gate 			secs = (uint_t)vpp->pc_parm;
8507c478bd9Sstevel@tonic-gate 			break;
8517c478bd9Sstevel@tonic-gate 
8527c478bd9Sstevel@tonic-gate 		case FX_KY_TQNSECS:
8537c478bd9Sstevel@tonic-gate 			if (nsecflag++)
8547c478bd9Sstevel@tonic-gate 				return (EINVAL);
8557c478bd9Sstevel@tonic-gate 			fxprmsp->fx_cflags |= FX_DOTQ;
8567c478bd9Sstevel@tonic-gate 			nsecs = (int)vpp->pc_parm;
8577c478bd9Sstevel@tonic-gate 			break;
8587c478bd9Sstevel@tonic-gate 
8597c478bd9Sstevel@tonic-gate 		default:
8607c478bd9Sstevel@tonic-gate 			return (EINVAL);
8617c478bd9Sstevel@tonic-gate 		}
8627c478bd9Sstevel@tonic-gate 	}
8637c478bd9Sstevel@tonic-gate 
8647c478bd9Sstevel@tonic-gate 	if (vaparmsp->pc_vaparmscnt == 0) {
8657c478bd9Sstevel@tonic-gate 		/*
8667c478bd9Sstevel@tonic-gate 		 * Use default parameters.
8677c478bd9Sstevel@tonic-gate 		 */
8687c478bd9Sstevel@tonic-gate 		fxprmsp->fx_upri = 0;
8697c478bd9Sstevel@tonic-gate 		fxprmsp->fx_uprilim = 0;
8707c478bd9Sstevel@tonic-gate 		fxprmsp->fx_tqntm = FX_TQDEF;
8717c478bd9Sstevel@tonic-gate 		fxprmsp->fx_cflags = FX_DOUPRI | FX_DOUPRILIM | FX_DOTQ;
8727c478bd9Sstevel@tonic-gate 	} else if ((fxprmsp->fx_cflags & FX_DOTQ) != 0) {
8737c478bd9Sstevel@tonic-gate 		if ((secs == 0 && nsecs == 0) || nsecs >= NANOSEC)
8747c478bd9Sstevel@tonic-gate 			return (EINVAL);
8757c478bd9Sstevel@tonic-gate 
8767c478bd9Sstevel@tonic-gate 		if (nsecs >= 0) {
8777c478bd9Sstevel@tonic-gate 			if ((ticks = SEC_TO_TICK((longlong_t)secs) +
8787c478bd9Sstevel@tonic-gate 			    NSEC_TO_TICK_ROUNDUP(nsecs)) > INT_MAX)
8797c478bd9Sstevel@tonic-gate 				return (ERANGE);
8807c478bd9Sstevel@tonic-gate 
8817c478bd9Sstevel@tonic-gate 			fxprmsp->fx_tqntm = (int)ticks;
8827c478bd9Sstevel@tonic-gate 		} else {
8837c478bd9Sstevel@tonic-gate 			if (nsecs != FX_TQINF && nsecs != FX_TQDEF)
8847c478bd9Sstevel@tonic-gate 				return (EINVAL);
8857c478bd9Sstevel@tonic-gate 			fxprmsp->fx_tqntm = nsecs;
8867c478bd9Sstevel@tonic-gate 		}
8877c478bd9Sstevel@tonic-gate 	}
8887c478bd9Sstevel@tonic-gate 
8897c478bd9Sstevel@tonic-gate 	return (0);
8907c478bd9Sstevel@tonic-gate }
8917c478bd9Sstevel@tonic-gate 
8927c478bd9Sstevel@tonic-gate 
8937c478bd9Sstevel@tonic-gate /*
8947c478bd9Sstevel@tonic-gate  * Nothing to do here but return success.
8957c478bd9Sstevel@tonic-gate  */
8967c478bd9Sstevel@tonic-gate /* ARGSUSED */
8977c478bd9Sstevel@tonic-gate static int
fx_parmsout(void * parmsp,pc_vaparms_t * vaparmsp)8987c478bd9Sstevel@tonic-gate fx_parmsout(void *parmsp, pc_vaparms_t *vaparmsp)
8997c478bd9Sstevel@tonic-gate {
9007c478bd9Sstevel@tonic-gate 	register fxkparms_t	*fxkprmsp = (fxkparms_t *)parmsp;
9017c478bd9Sstevel@tonic-gate 
9027c478bd9Sstevel@tonic-gate 	if (vaparmsp != NULL)
9037c478bd9Sstevel@tonic-gate 		return (0);
9047c478bd9Sstevel@tonic-gate 
9057c478bd9Sstevel@tonic-gate 	if (fxkprmsp->fx_tqntm < 0) {
9067c478bd9Sstevel@tonic-gate 		/*
9077c478bd9Sstevel@tonic-gate 		 * Quantum field set to special value (e.g. FX_TQINF)
9087c478bd9Sstevel@tonic-gate 		 */
9097c478bd9Sstevel@tonic-gate 		((fxparms_t *)fxkprmsp)->fx_tqnsecs = fxkprmsp->fx_tqntm;
9107c478bd9Sstevel@tonic-gate 		((fxparms_t *)fxkprmsp)->fx_tqsecs = 0;
9117c478bd9Sstevel@tonic-gate 
9127c478bd9Sstevel@tonic-gate 	} else {
9137c478bd9Sstevel@tonic-gate 		/* Convert quantum from ticks to seconds-nanoseconds */
9147c478bd9Sstevel@tonic-gate 
9157c478bd9Sstevel@tonic-gate 		timestruc_t ts;
9167c478bd9Sstevel@tonic-gate 		TICK_TO_TIMESTRUC(fxkprmsp->fx_tqntm, &ts);
9177c478bd9Sstevel@tonic-gate 		((fxparms_t *)fxkprmsp)->fx_tqsecs = ts.tv_sec;
9187c478bd9Sstevel@tonic-gate 		((fxparms_t *)fxkprmsp)->fx_tqnsecs = ts.tv_nsec;
9197c478bd9Sstevel@tonic-gate 	}
9207c478bd9Sstevel@tonic-gate 
9217c478bd9Sstevel@tonic-gate 	return (0);
9227c478bd9Sstevel@tonic-gate }
9237c478bd9Sstevel@tonic-gate 
9247c478bd9Sstevel@tonic-gate 
9257c478bd9Sstevel@tonic-gate /*
9267c478bd9Sstevel@tonic-gate  * Copy all selected fixed-priority class parameters to the user.
9277c478bd9Sstevel@tonic-gate  * The parameters are specified by a key.
9287c478bd9Sstevel@tonic-gate  */
9297c478bd9Sstevel@tonic-gate static int
fx_vaparmsout(void * prmsp,pc_vaparms_t * vaparmsp)9307c478bd9Sstevel@tonic-gate fx_vaparmsout(void *prmsp, pc_vaparms_t *vaparmsp)
9317c478bd9Sstevel@tonic-gate {
9327c478bd9Sstevel@tonic-gate 	fxkparms_t	*fxkprmsp = (fxkparms_t *)prmsp;
9337c478bd9Sstevel@tonic-gate 	timestruc_t	ts;
9347c478bd9Sstevel@tonic-gate 	uint_t		cnt;
9357c478bd9Sstevel@tonic-gate 	uint_t		secs;
9367c478bd9Sstevel@tonic-gate 	int		nsecs;
9377c478bd9Sstevel@tonic-gate 	int		priflag, secflag, nsecflag, limflag;
9387c478bd9Sstevel@tonic-gate 	pc_vaparm_t	*vpp = &vaparmsp->pc_parms[0];
9397c478bd9Sstevel@tonic-gate 
9407c478bd9Sstevel@tonic-gate 	ASSERT(MUTEX_NOT_HELD(&curproc->p_lock));
9417c478bd9Sstevel@tonic-gate 
9427c478bd9Sstevel@tonic-gate 	priflag = secflag = nsecflag = limflag = 0;
9437c478bd9Sstevel@tonic-gate 
9447c478bd9Sstevel@tonic-gate 	if (vaparmsp->pc_vaparmscnt > PC_VAPARMCNT)
9457c478bd9Sstevel@tonic-gate 		return (EINVAL);
9467c478bd9Sstevel@tonic-gate 
9477c478bd9Sstevel@tonic-gate 	if (fxkprmsp->fx_tqntm < 0) {
9487c478bd9Sstevel@tonic-gate 		/*
9497c478bd9Sstevel@tonic-gate 		 * Quantum field set to special value (e.g. FX_TQINF).
9507c478bd9Sstevel@tonic-gate 		 */
9517c478bd9Sstevel@tonic-gate 		secs = 0;
9527c478bd9Sstevel@tonic-gate 		nsecs = fxkprmsp->fx_tqntm;
9537c478bd9Sstevel@tonic-gate 	} else {
9547c478bd9Sstevel@tonic-gate 		/*
9557c478bd9Sstevel@tonic-gate 		 * Convert quantum from ticks to seconds-nanoseconds.
9567c478bd9Sstevel@tonic-gate 		 */
9577c478bd9Sstevel@tonic-gate 		TICK_TO_TIMESTRUC(fxkprmsp->fx_tqntm, &ts);
9587c478bd9Sstevel@tonic-gate 		secs = ts.tv_sec;
9597c478bd9Sstevel@tonic-gate 		nsecs = ts.tv_nsec;
9607c478bd9Sstevel@tonic-gate 	}
9617c478bd9Sstevel@tonic-gate 
9627c478bd9Sstevel@tonic-gate 
9637c478bd9Sstevel@tonic-gate 	for (cnt = 0; cnt < vaparmsp->pc_vaparmscnt; cnt++, vpp++) {
9647c478bd9Sstevel@tonic-gate 
9657c478bd9Sstevel@tonic-gate 		switch (vpp->pc_key) {
9667c478bd9Sstevel@tonic-gate 		case FX_KY_UPRILIM:
9677c478bd9Sstevel@tonic-gate 			if (limflag++)
9687c478bd9Sstevel@tonic-gate 				return (EINVAL);
9697c478bd9Sstevel@tonic-gate 			if (copyout(&fxkprmsp->fx_uprilim,
9707c478bd9Sstevel@tonic-gate 			    (void *)(uintptr_t)vpp->pc_parm, sizeof (pri_t)))
9717c478bd9Sstevel@tonic-gate 				return (EFAULT);
9727c478bd9Sstevel@tonic-gate 			break;
9737c478bd9Sstevel@tonic-gate 
9747c478bd9Sstevel@tonic-gate 		case FX_KY_UPRI:
9757c478bd9Sstevel@tonic-gate 			if (priflag++)
9767c478bd9Sstevel@tonic-gate 				return (EINVAL);
9777c478bd9Sstevel@tonic-gate 			if (copyout(&fxkprmsp->fx_upri,
9787c478bd9Sstevel@tonic-gate 			    (void *)(uintptr_t)vpp->pc_parm, sizeof (pri_t)))
9797c478bd9Sstevel@tonic-gate 				return (EFAULT);
9807c478bd9Sstevel@tonic-gate 			break;
9817c478bd9Sstevel@tonic-gate 
9827c478bd9Sstevel@tonic-gate 		case FX_KY_TQSECS:
9837c478bd9Sstevel@tonic-gate 			if (secflag++)
9847c478bd9Sstevel@tonic-gate 				return (EINVAL);
9857c478bd9Sstevel@tonic-gate 			if (copyout(&secs,
9867c478bd9Sstevel@tonic-gate 			    (void *)(uintptr_t)vpp->pc_parm, sizeof (uint_t)))
9877c478bd9Sstevel@tonic-gate 				return (EFAULT);
9887c478bd9Sstevel@tonic-gate 			break;
9897c478bd9Sstevel@tonic-gate 
9907c478bd9Sstevel@tonic-gate 		case FX_KY_TQNSECS:
9917c478bd9Sstevel@tonic-gate 			if (nsecflag++)
9927c478bd9Sstevel@tonic-gate 				return (EINVAL);
9937c478bd9Sstevel@tonic-gate 			if (copyout(&nsecs,
9947c478bd9Sstevel@tonic-gate 			    (void *)(uintptr_t)vpp->pc_parm, sizeof (int)))
9957c478bd9Sstevel@tonic-gate 				return (EFAULT);
9967c478bd9Sstevel@tonic-gate 			break;
9977c478bd9Sstevel@tonic-gate 
9987c478bd9Sstevel@tonic-gate 		default:
9997c478bd9Sstevel@tonic-gate 			return (EINVAL);
10007c478bd9Sstevel@tonic-gate 		}
10017c478bd9Sstevel@tonic-gate 	}
10027c478bd9Sstevel@tonic-gate 
10037c478bd9Sstevel@tonic-gate 	return (0);
10047c478bd9Sstevel@tonic-gate }
10057c478bd9Sstevel@tonic-gate 
10067c478bd9Sstevel@tonic-gate /*
10077c478bd9Sstevel@tonic-gate  * Set the scheduling parameters of the thread pointed to by fxprocp
10087c478bd9Sstevel@tonic-gate  * to those specified in the buffer pointed to by fxparmsp.
10097c478bd9Sstevel@tonic-gate  */
10107c478bd9Sstevel@tonic-gate /* ARGSUSED */
10117c478bd9Sstevel@tonic-gate static int
fx_parmsset(kthread_t * tx,void * parmsp,id_t reqpcid,cred_t * reqpcredp)10127c478bd9Sstevel@tonic-gate fx_parmsset(kthread_t *tx, void *parmsp, id_t reqpcid, cred_t *reqpcredp)
10137c478bd9Sstevel@tonic-gate {
10147c478bd9Sstevel@tonic-gate 	char		nice;
10157c478bd9Sstevel@tonic-gate 	pri_t		reqfxuprilim;
10167c478bd9Sstevel@tonic-gate 	pri_t		reqfxupri;
10177c478bd9Sstevel@tonic-gate 	fxkparms_t	*fxkparmsp = (fxkparms_t *)parmsp;
10187c478bd9Sstevel@tonic-gate 	fxproc_t	*fxpp;
10197c478bd9Sstevel@tonic-gate 
10207c478bd9Sstevel@tonic-gate 
10217c478bd9Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&(ttoproc(tx))->p_lock));
10227c478bd9Sstevel@tonic-gate 
10237c478bd9Sstevel@tonic-gate 	thread_lock(tx);
10247c478bd9Sstevel@tonic-gate 	fxpp = (fxproc_t *)tx->t_cldata;
10257c478bd9Sstevel@tonic-gate 
10267c478bd9Sstevel@tonic-gate 	if ((fxkparmsp->fx_cflags & FX_DOUPRILIM) == 0)
10277c478bd9Sstevel@tonic-gate 		reqfxuprilim = fxpp->fx_uprilim;
10287c478bd9Sstevel@tonic-gate 	else
10297c478bd9Sstevel@tonic-gate 		reqfxuprilim = fxkparmsp->fx_uprilim;
10307c478bd9Sstevel@tonic-gate 
10317c478bd9Sstevel@tonic-gate 	/*
10327c478bd9Sstevel@tonic-gate 	 * Basic permissions enforced by generic kernel code
10337c478bd9Sstevel@tonic-gate 	 * for all classes require that a thread attempting
10347c478bd9Sstevel@tonic-gate 	 * to change the scheduling parameters of a target
10357c478bd9Sstevel@tonic-gate 	 * thread be privileged or have a real or effective
10367c478bd9Sstevel@tonic-gate 	 * UID matching that of the target thread. We are not
10377c478bd9Sstevel@tonic-gate 	 * called unless these basic permission checks have
10387c478bd9Sstevel@tonic-gate 	 * already passed. The fixed priority class requires in
10397c478bd9Sstevel@tonic-gate 	 * addition that the calling thread be privileged if it
10407c478bd9Sstevel@tonic-gate 	 * is attempting to raise the pri above its current
10417c478bd9Sstevel@tonic-gate 	 * value This may have been checked previously but if our
10427c478bd9Sstevel@tonic-gate 	 * caller passed us a non-NULL credential pointer we assume
10437c478bd9Sstevel@tonic-gate 	 * it hasn't and we check it here.
10447c478bd9Sstevel@tonic-gate 	 */
10457c478bd9Sstevel@tonic-gate 
10467c478bd9Sstevel@tonic-gate 	if ((reqpcredp != NULL) &&
10477c478bd9Sstevel@tonic-gate 	    (reqfxuprilim > fxpp->fx_uprilim ||
10487c478bd9Sstevel@tonic-gate 	    ((fxkparmsp->fx_cflags & FX_DOTQ) != 0)) &&
104924d819e6SJerry Jelinek 	    secpolicy_raisepriority(reqpcredp) != 0) {
10507c478bd9Sstevel@tonic-gate 		thread_unlock(tx);
10517c478bd9Sstevel@tonic-gate 		return (EPERM);
10527c478bd9Sstevel@tonic-gate 	}
10537c478bd9Sstevel@tonic-gate 
10547c478bd9Sstevel@tonic-gate 	FX_ADJUST_PRI(reqfxuprilim);
10557c478bd9Sstevel@tonic-gate 
10567c478bd9Sstevel@tonic-gate 	if ((fxkparmsp->fx_cflags & FX_DOUPRI) == 0)
10577c478bd9Sstevel@tonic-gate 		reqfxupri = fxpp->fx_pri;
10587c478bd9Sstevel@tonic-gate 	else
10597c478bd9Sstevel@tonic-gate 		reqfxupri = fxkparmsp->fx_upri;
10607c478bd9Sstevel@tonic-gate 
10617c478bd9Sstevel@tonic-gate 
10627c478bd9Sstevel@tonic-gate 	/*
10637c478bd9Sstevel@tonic-gate 	 * Make sure the user priority doesn't exceed the upri limit.
10647c478bd9Sstevel@tonic-gate 	 */
10657c478bd9Sstevel@tonic-gate 	if (reqfxupri > reqfxuprilim)
10667c478bd9Sstevel@tonic-gate 		reqfxupri = reqfxuprilim;
10677c478bd9Sstevel@tonic-gate 
10687c478bd9Sstevel@tonic-gate 	/*
10697c478bd9Sstevel@tonic-gate 	 * Set fx_nice to the nice value corresponding to the user
10707c478bd9Sstevel@tonic-gate 	 * priority we are setting.  Note that setting the nice field
10717c478bd9Sstevel@tonic-gate 	 * of the parameter struct won't affect upri or nice.
10727c478bd9Sstevel@tonic-gate 	 */
10737c478bd9Sstevel@tonic-gate 
10747c478bd9Sstevel@tonic-gate 	nice = NZERO - (reqfxupri * NZERO) / fx_maxupri;
10757c478bd9Sstevel@tonic-gate 
10767c478bd9Sstevel@tonic-gate 	if (nice > NZERO)
10777c478bd9Sstevel@tonic-gate 		nice = NZERO;
10787c478bd9Sstevel@tonic-gate 
10797c478bd9Sstevel@tonic-gate 	fxpp->fx_uprilim = reqfxuprilim;
10807c478bd9Sstevel@tonic-gate 	fxpp->fx_pri = reqfxupri;
10817c478bd9Sstevel@tonic-gate 
10827c478bd9Sstevel@tonic-gate 	if (fxkparmsp->fx_tqntm == FX_TQINF)
10837c478bd9Sstevel@tonic-gate 		fxpp->fx_pquantum = FX_TQINF;
10847c478bd9Sstevel@tonic-gate 	else if (fxkparmsp->fx_tqntm == FX_TQDEF)
10857c478bd9Sstevel@tonic-gate 		fxpp->fx_pquantum = fx_dptbl[fxpp->fx_pri].fx_quantum;
10867c478bd9Sstevel@tonic-gate 	else if ((fxkparmsp->fx_cflags & FX_DOTQ) != 0)
10877c478bd9Sstevel@tonic-gate 		fxpp->fx_pquantum = fxkparmsp->fx_tqntm;
10887c478bd9Sstevel@tonic-gate 
10897c478bd9Sstevel@tonic-gate 	fxpp->fx_nice = nice;
10907c478bd9Sstevel@tonic-gate 
10917c478bd9Sstevel@tonic-gate 	fx_change_priority(tx, fxpp);
10927c478bd9Sstevel@tonic-gate 	thread_unlock(tx);
10937c478bd9Sstevel@tonic-gate 	return (0);
10947c478bd9Sstevel@tonic-gate }
10957c478bd9Sstevel@tonic-gate 
10967c478bd9Sstevel@tonic-gate 
10977c478bd9Sstevel@tonic-gate /*
10987c478bd9Sstevel@tonic-gate  * Return the global scheduling priority that would be assigned
10997c478bd9Sstevel@tonic-gate  * to a thread entering the fixed-priority class with the fx_upri.
11007c478bd9Sstevel@tonic-gate  */
11017c478bd9Sstevel@tonic-gate static pri_t
fx_globpri(kthread_t * t)11027c478bd9Sstevel@tonic-gate fx_globpri(kthread_t *t)
11037c478bd9Sstevel@tonic-gate {
11047c478bd9Sstevel@tonic-gate 	fxproc_t *fxpp;
11057c478bd9Sstevel@tonic-gate 
11067c478bd9Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&ttoproc(t)->p_lock));
11077c478bd9Sstevel@tonic-gate 
11087c478bd9Sstevel@tonic-gate 	fxpp = (fxproc_t *)t->t_cldata;
11097c478bd9Sstevel@tonic-gate 	return (fx_dptbl[fxpp->fx_pri].fx_globpri);
11107c478bd9Sstevel@tonic-gate 
11117c478bd9Sstevel@tonic-gate }
11127c478bd9Sstevel@tonic-gate 
11137c478bd9Sstevel@tonic-gate /*
11147c478bd9Sstevel@tonic-gate  * Arrange for thread to be placed in appropriate location
11157c478bd9Sstevel@tonic-gate  * on dispatcher queue.
11167c478bd9Sstevel@tonic-gate  *
11177c478bd9Sstevel@tonic-gate  * This is called with the current thread in TS_ONPROC and locked.
11187c478bd9Sstevel@tonic-gate  */
11197c478bd9Sstevel@tonic-gate static void
fx_preempt(kthread_t * t)11207c478bd9Sstevel@tonic-gate fx_preempt(kthread_t *t)
11217c478bd9Sstevel@tonic-gate {
11227c478bd9Sstevel@tonic-gate 	fxproc_t	*fxpp = (fxproc_t *)(t->t_cldata);
11237c478bd9Sstevel@tonic-gate 
11247c478bd9Sstevel@tonic-gate 	ASSERT(t == curthread);
11257c478bd9Sstevel@tonic-gate 	ASSERT(THREAD_LOCK_HELD(curthread));
11267c478bd9Sstevel@tonic-gate 
11278c34bbb7Sakolb 	(void) CPUCAPS_CHARGE(t, &fxpp->fx_caps, CPUCAPS_CHARGE_ENFORCE);
1128c97ad5cdSakolb 
11297c478bd9Sstevel@tonic-gate 	/*
11307c478bd9Sstevel@tonic-gate 	 * Check to see if we're doing "preemption control" here.  If
11317c478bd9Sstevel@tonic-gate 	 * we are, and if the user has requested that this thread not
11327c478bd9Sstevel@tonic-gate 	 * be preempted, and if preemptions haven't been put off for
11337c478bd9Sstevel@tonic-gate 	 * too long, let the preemption happen here but try to make
11347c478bd9Sstevel@tonic-gate 	 * sure the thread is rescheduled as soon as possible.  We do
11357c478bd9Sstevel@tonic-gate 	 * this by putting it on the front of the highest priority run
11367c478bd9Sstevel@tonic-gate 	 * queue in the FX class.  If the preemption has been put off
11377c478bd9Sstevel@tonic-gate 	 * for too long, clear the "nopreempt" bit and let the thread
11387c478bd9Sstevel@tonic-gate 	 * be preempted.
11397c478bd9Sstevel@tonic-gate 	 */
11407c478bd9Sstevel@tonic-gate 	if (t->t_schedctl && schedctl_get_nopreempt(t)) {
11417c478bd9Sstevel@tonic-gate 		if (fxpp->fx_pquantum == FX_TQINF ||
11427c478bd9Sstevel@tonic-gate 		    fxpp->fx_timeleft > -SC_MAX_TICKS) {
11437c478bd9Sstevel@tonic-gate 			DTRACE_SCHED1(schedctl__nopreempt, kthread_t *, t);
11447c478bd9Sstevel@tonic-gate 			schedctl_set_yield(t, 1);
11457c478bd9Sstevel@tonic-gate 			setfrontdq(t);
11467c478bd9Sstevel@tonic-gate 			return;
11477c478bd9Sstevel@tonic-gate 		} else {
11487c478bd9Sstevel@tonic-gate 			schedctl_set_nopreempt(t, 0);
11497c478bd9Sstevel@tonic-gate 			DTRACE_SCHED1(schedctl__preempt, kthread_t *, t);
11507c478bd9Sstevel@tonic-gate 			/*
11517c478bd9Sstevel@tonic-gate 			 * Fall through and be preempted below.
11527c478bd9Sstevel@tonic-gate 			 */
11537c478bd9Sstevel@tonic-gate 		}
11547c478bd9Sstevel@tonic-gate 	}
11557c478bd9Sstevel@tonic-gate 
11567c478bd9Sstevel@tonic-gate 	if (FX_HAS_CB(fxpp)) {
11577c478bd9Sstevel@tonic-gate 		clock_t new_quantum =  (clock_t)fxpp->fx_pquantum;
11587c478bd9Sstevel@tonic-gate 		pri_t	newpri = fxpp->fx_pri;
11597c478bd9Sstevel@tonic-gate 		FX_CB_PREEMPT(FX_CALLB(fxpp), fxpp->fx_cookie,
1160d4204c85Sraf 		    &new_quantum, &newpri);
11617c478bd9Sstevel@tonic-gate 		FX_ADJUST_QUANTUM(new_quantum);
11627c478bd9Sstevel@tonic-gate 		if ((int)new_quantum != fxpp->fx_pquantum) {
11637c478bd9Sstevel@tonic-gate 			fxpp->fx_pquantum = (int)new_quantum;
11647c478bd9Sstevel@tonic-gate 			fxpp->fx_timeleft = fxpp->fx_pquantum;
11657c478bd9Sstevel@tonic-gate 		}
11667c478bd9Sstevel@tonic-gate 		FX_ADJUST_PRI(newpri);
11677c478bd9Sstevel@tonic-gate 		fxpp->fx_pri = newpri;
11687c478bd9Sstevel@tonic-gate 		THREAD_CHANGE_PRI(t, fx_dptbl[fxpp->fx_pri].fx_globpri);
11697c478bd9Sstevel@tonic-gate 	}
11707c478bd9Sstevel@tonic-gate 
1171c97ad5cdSakolb 	/*
1172c97ad5cdSakolb 	 * This thread may be placed on wait queue by CPU Caps. In this case we
1173c97ad5cdSakolb 	 * do not need to do anything until it is removed from the wait queue.
1174c97ad5cdSakolb 	 */
1175c97ad5cdSakolb 	if (CPUCAPS_ENFORCE(t)) {
1176c97ad5cdSakolb 		return;
1177c97ad5cdSakolb 	}
1178c97ad5cdSakolb 
11797c478bd9Sstevel@tonic-gate 	if ((fxpp->fx_flags & (FXBACKQ)) == FXBACKQ) {
11807c478bd9Sstevel@tonic-gate 		fxpp->fx_timeleft = fxpp->fx_pquantum;
11817c478bd9Sstevel@tonic-gate 		fxpp->fx_flags &= ~FXBACKQ;
11827c478bd9Sstevel@tonic-gate 		setbackdq(t);
11837c478bd9Sstevel@tonic-gate 	} else {
1184c97ad5cdSakolb 		setfrontdq(t);
11857c478bd9Sstevel@tonic-gate 	}
11867c478bd9Sstevel@tonic-gate }
11877c478bd9Sstevel@tonic-gate 
11887c478bd9Sstevel@tonic-gate static void
fx_setrun(kthread_t * t)11897c478bd9Sstevel@tonic-gate fx_setrun(kthread_t *t)
11907c478bd9Sstevel@tonic-gate {
11917c478bd9Sstevel@tonic-gate 	fxproc_t *fxpp = (fxproc_t *)(t->t_cldata);
11927c478bd9Sstevel@tonic-gate 
11937c478bd9Sstevel@tonic-gate 	ASSERT(THREAD_LOCK_HELD(t));	/* t should be in transition */
11947c478bd9Sstevel@tonic-gate 	fxpp->fx_flags &= ~FXBACKQ;
11957c478bd9Sstevel@tonic-gate 
1196d3d50737SRafael Vanoni 	if (t->t_disp_time != ddi_get_lbolt())
11977c478bd9Sstevel@tonic-gate 		setbackdq(t);
11987c478bd9Sstevel@tonic-gate 	else
11997c478bd9Sstevel@tonic-gate 		setfrontdq(t);
12007c478bd9Sstevel@tonic-gate }
12017c478bd9Sstevel@tonic-gate 
12027c478bd9Sstevel@tonic-gate 
12037c478bd9Sstevel@tonic-gate /*
12047c478bd9Sstevel@tonic-gate  * Prepare thread for sleep. We reset the thread priority so it will
12057c478bd9Sstevel@tonic-gate  * run at the kernel priority level when it wakes up.
12067c478bd9Sstevel@tonic-gate  */
12077c478bd9Sstevel@tonic-gate static void
fx_sleep(kthread_t * t)12087c478bd9Sstevel@tonic-gate fx_sleep(kthread_t *t)
12097c478bd9Sstevel@tonic-gate {
12107c478bd9Sstevel@tonic-gate 	fxproc_t	*fxpp = (fxproc_t *)(t->t_cldata);
12117c478bd9Sstevel@tonic-gate 
12127c478bd9Sstevel@tonic-gate 	ASSERT(t == curthread);
12137c478bd9Sstevel@tonic-gate 	ASSERT(THREAD_LOCK_HELD(t));
12147c478bd9Sstevel@tonic-gate 
1215c97ad5cdSakolb 	/*
1216c97ad5cdSakolb 	 * Account for time spent on CPU before going to sleep.
1217c97ad5cdSakolb 	 */
12188c34bbb7Sakolb 	(void) CPUCAPS_CHARGE(t, &fxpp->fx_caps, CPUCAPS_CHARGE_ENFORCE);
1219c97ad5cdSakolb 
12207c478bd9Sstevel@tonic-gate 	if (FX_HAS_CB(fxpp)) {
12217c478bd9Sstevel@tonic-gate 		FX_CB_SLEEP(FX_CALLB(fxpp), fxpp->fx_cookie);
12227c478bd9Sstevel@tonic-gate 	}
1223d3d50737SRafael Vanoni 	t->t_stime = ddi_get_lbolt();		/* time stamp for the swapper */
12247c478bd9Sstevel@tonic-gate }
12257c478bd9Sstevel@tonic-gate 
12267c478bd9Sstevel@tonic-gate 
12277c478bd9Sstevel@tonic-gate /*
12287c478bd9Sstevel@tonic-gate  * Return Values:
12297c478bd9Sstevel@tonic-gate  *
12307c478bd9Sstevel@tonic-gate  *	-1 if the thread is loaded or is not eligible to be swapped in.
12317c478bd9Sstevel@tonic-gate  *
12327c478bd9Sstevel@tonic-gate  * FX and RT threads are designed so that they don't swapout; however,
12337c478bd9Sstevel@tonic-gate  * it is possible that while the thread is swapped out and in another class, it
12347c478bd9Sstevel@tonic-gate  * can be changed to FX or RT.  Since these threads should be swapped in
12357c478bd9Sstevel@tonic-gate  * as soon as they're runnable, rt_swapin returns SHRT_MAX, and fx_swapin
12367c478bd9Sstevel@tonic-gate  * returns SHRT_MAX - 1, so that it gives deference to any swapped out
12377c478bd9Sstevel@tonic-gate  * RT threads.
12387c478bd9Sstevel@tonic-gate  */
12397c478bd9Sstevel@tonic-gate /* ARGSUSED */
12407c478bd9Sstevel@tonic-gate static pri_t
fx_swapin(kthread_t * t,int flags)12417c478bd9Sstevel@tonic-gate fx_swapin(kthread_t *t, int flags)
12427c478bd9Sstevel@tonic-gate {
12437c478bd9Sstevel@tonic-gate 	pri_t	tpri = -1;
12447c478bd9Sstevel@tonic-gate 
12457c478bd9Sstevel@tonic-gate 	ASSERT(THREAD_LOCK_HELD(t));
12467c478bd9Sstevel@tonic-gate 
12477c478bd9Sstevel@tonic-gate 	if (t->t_state == TS_RUN && (t->t_schedflag & TS_LOAD) == 0) {
12487c478bd9Sstevel@tonic-gate 		tpri = (pri_t)SHRT_MAX - 1;
12497c478bd9Sstevel@tonic-gate 	}
12507c478bd9Sstevel@tonic-gate 
12517c478bd9Sstevel@tonic-gate 	return (tpri);
12527c478bd9Sstevel@tonic-gate }
12537c478bd9Sstevel@tonic-gate 
12547c478bd9Sstevel@tonic-gate /*
12557c478bd9Sstevel@tonic-gate  * Return Values
12567c478bd9Sstevel@tonic-gate  *	-1 if the thread isn't loaded or is not eligible to be swapped out.
12577c478bd9Sstevel@tonic-gate  */
12587c478bd9Sstevel@tonic-gate /* ARGSUSED */
12597c478bd9Sstevel@tonic-gate static pri_t
fx_swapout(kthread_t * t,int flags)12607c478bd9Sstevel@tonic-gate fx_swapout(kthread_t *t, int flags)
12617c478bd9Sstevel@tonic-gate {
12627c478bd9Sstevel@tonic-gate 	ASSERT(THREAD_LOCK_HELD(t));
12637c478bd9Sstevel@tonic-gate 
12647c478bd9Sstevel@tonic-gate 	return (-1);
12657c478bd9Sstevel@tonic-gate 
12667c478bd9Sstevel@tonic-gate }
12677c478bd9Sstevel@tonic-gate 
12687c478bd9Sstevel@tonic-gate /* ARGSUSED */
12697c478bd9Sstevel@tonic-gate static void
fx_stop(kthread_t * t,int why,int what)12707c478bd9Sstevel@tonic-gate fx_stop(kthread_t *t, int why, int what)
12717c478bd9Sstevel@tonic-gate {
12727c478bd9Sstevel@tonic-gate 	fxproc_t *fxpp = (fxproc_t *)(t->t_cldata);
12737c478bd9Sstevel@tonic-gate 
12747c478bd9Sstevel@tonic-gate 	ASSERT(THREAD_LOCK_HELD(t));
12757c478bd9Sstevel@tonic-gate 
12767c478bd9Sstevel@tonic-gate 	if (FX_HAS_CB(fxpp)) {
12777c478bd9Sstevel@tonic-gate 		FX_CB_STOP(FX_CALLB(fxpp), fxpp->fx_cookie);
12787c478bd9Sstevel@tonic-gate 	}
12797c478bd9Sstevel@tonic-gate }
12807c478bd9Sstevel@tonic-gate 
12817c478bd9Sstevel@tonic-gate /*
12827c478bd9Sstevel@tonic-gate  * Check for time slice expiration.  If time slice has expired
12837c478bd9Sstevel@tonic-gate  * set runrun to cause preemption.
12847c478bd9Sstevel@tonic-gate  */
12857c478bd9Sstevel@tonic-gate static void
fx_tick(kthread_t * t)12867c478bd9Sstevel@tonic-gate fx_tick(kthread_t *t)
12877c478bd9Sstevel@tonic-gate {
1288c97ad5cdSakolb 	boolean_t call_cpu_surrender = B_FALSE;
12897c478bd9Sstevel@tonic-gate 	fxproc_t *fxpp;
12907c478bd9Sstevel@tonic-gate 
12917c478bd9Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&(ttoproc(t))->p_lock));
12927c478bd9Sstevel@tonic-gate 
12937c478bd9Sstevel@tonic-gate 	thread_lock(t);
12947c478bd9Sstevel@tonic-gate 
12957c478bd9Sstevel@tonic-gate 	fxpp = (fxproc_t *)(t->t_cldata);
12967c478bd9Sstevel@tonic-gate 
12977c478bd9Sstevel@tonic-gate 	if (FX_HAS_CB(fxpp)) {
12987c478bd9Sstevel@tonic-gate 		clock_t new_quantum =  (clock_t)fxpp->fx_pquantum;
12997c478bd9Sstevel@tonic-gate 		pri_t	newpri = fxpp->fx_pri;
13007c478bd9Sstevel@tonic-gate 		FX_CB_TICK(FX_CALLB(fxpp), fxpp->fx_cookie,
1301d4204c85Sraf 		    &new_quantum, &newpri);
13027c478bd9Sstevel@tonic-gate 		FX_ADJUST_QUANTUM(new_quantum);
13037c478bd9Sstevel@tonic-gate 		if ((int)new_quantum != fxpp->fx_pquantum) {
13047c478bd9Sstevel@tonic-gate 			fxpp->fx_pquantum = (int)new_quantum;
13057c478bd9Sstevel@tonic-gate 			fxpp->fx_timeleft = fxpp->fx_pquantum;
13067c478bd9Sstevel@tonic-gate 		}
13077c478bd9Sstevel@tonic-gate 		FX_ADJUST_PRI(newpri);
13087c478bd9Sstevel@tonic-gate 		if (newpri != fxpp->fx_pri) {
13097c478bd9Sstevel@tonic-gate 			fxpp->fx_pri = newpri;
13107c478bd9Sstevel@tonic-gate 			fx_change_priority(t, fxpp);
13117c478bd9Sstevel@tonic-gate 		}
13127c478bd9Sstevel@tonic-gate 	}
1313c97ad5cdSakolb 
1314c97ad5cdSakolb 	/*
1315c97ad5cdSakolb 	 * Keep track of thread's project CPU usage.  Note that projects
1316c97ad5cdSakolb 	 * get charged even when threads are running in the kernel.
1317c97ad5cdSakolb 	 */
1318c97ad5cdSakolb 	call_cpu_surrender =  CPUCAPS_CHARGE(t, &fxpp->fx_caps,
1319c97ad5cdSakolb 	    CPUCAPS_CHARGE_ENFORCE);
1320c97ad5cdSakolb 
13217c478bd9Sstevel@tonic-gate 	if ((fxpp->fx_pquantum != FX_TQINF) &&
13227c478bd9Sstevel@tonic-gate 	    (--fxpp->fx_timeleft <= 0)) {
13237c478bd9Sstevel@tonic-gate 		pri_t	new_pri;
13247c478bd9Sstevel@tonic-gate 
13257c478bd9Sstevel@tonic-gate 		/*
13267c478bd9Sstevel@tonic-gate 		 * If we're doing preemption control and trying to
13277c478bd9Sstevel@tonic-gate 		 * avoid preempting this thread, just note that
13287c478bd9Sstevel@tonic-gate 		 * the thread should yield soon and let it keep
13297c478bd9Sstevel@tonic-gate 		 * running (unless it's been a while).
13307c478bd9Sstevel@tonic-gate 		 */
13317c478bd9Sstevel@tonic-gate 		if (t->t_schedctl && schedctl_get_nopreempt(t)) {
13327c478bd9Sstevel@tonic-gate 			if (fxpp->fx_timeleft > -SC_MAX_TICKS) {
13337c478bd9Sstevel@tonic-gate 				DTRACE_SCHED1(schedctl__nopreempt,
13347c478bd9Sstevel@tonic-gate 				    kthread_t *, t);
13357c478bd9Sstevel@tonic-gate 				schedctl_set_yield(t, 1);
13367c478bd9Sstevel@tonic-gate 				thread_unlock_nopreempt(t);
13377c478bd9Sstevel@tonic-gate 				return;
13387c478bd9Sstevel@tonic-gate 			}
1339*5405159cSGordon Ross 			DTRACE_SCHED1(schedctl__failsafe,
1340*5405159cSGordon Ross 			    kthread_t *, t);
13417c478bd9Sstevel@tonic-gate 		}
13427c478bd9Sstevel@tonic-gate 		new_pri = fx_dptbl[fxpp->fx_pri].fx_globpri;
13437c478bd9Sstevel@tonic-gate 		ASSERT(new_pri >= 0 && new_pri <= fx_maxglobpri);
13447c478bd9Sstevel@tonic-gate 		/*
13457c478bd9Sstevel@tonic-gate 		 * When the priority of a thread is changed,
13467c478bd9Sstevel@tonic-gate 		 * it may be necessary to adjust its position
13477c478bd9Sstevel@tonic-gate 		 * on a sleep queue or dispatch queue. Even
13487c478bd9Sstevel@tonic-gate 		 * when the priority is not changed, we need
13497c478bd9Sstevel@tonic-gate 		 * to preserve round robin on dispatch queue.
13507c478bd9Sstevel@tonic-gate 		 * The function thread_change_pri accomplishes
13517c478bd9Sstevel@tonic-gate 		 * this.
13527c478bd9Sstevel@tonic-gate 		 */
13537c478bd9Sstevel@tonic-gate 		if (thread_change_pri(t, new_pri, 0)) {
13547c478bd9Sstevel@tonic-gate 			fxpp->fx_timeleft = fxpp->fx_pquantum;
13557c478bd9Sstevel@tonic-gate 		} else {
1356c97ad5cdSakolb 			call_cpu_surrender = B_TRUE;
13577c478bd9Sstevel@tonic-gate 		}
1358b3383343Smishra 	} else if (t->t_state == TS_ONPROC &&
1359d4204c85Sraf 	    t->t_pri < t->t_disp_queue->disp_maxrunpri) {
1360c97ad5cdSakolb 		call_cpu_surrender = B_TRUE;
1361c97ad5cdSakolb 	}
1362c97ad5cdSakolb 
1363c97ad5cdSakolb 	if (call_cpu_surrender) {
13647c478bd9Sstevel@tonic-gate 		fxpp->fx_flags |= FXBACKQ;
13657c478bd9Sstevel@tonic-gate 		cpu_surrender(t);
13667c478bd9Sstevel@tonic-gate 	}
13677c478bd9Sstevel@tonic-gate 	thread_unlock_nopreempt(t);	/* clock thread can't be preempted */
13687c478bd9Sstevel@tonic-gate }
13697c478bd9Sstevel@tonic-gate 
13707c478bd9Sstevel@tonic-gate 
13717c478bd9Sstevel@tonic-gate static void
fx_trapret(kthread_t * t)13727c478bd9Sstevel@tonic-gate fx_trapret(kthread_t *t)
13737c478bd9Sstevel@tonic-gate {
13747c478bd9Sstevel@tonic-gate 	cpu_t		*cp = CPU;
13757c478bd9Sstevel@tonic-gate 
13767c478bd9Sstevel@tonic-gate 	ASSERT(THREAD_LOCK_HELD(t));
13777c478bd9Sstevel@tonic-gate 	ASSERT(t == curthread);
13787c478bd9Sstevel@tonic-gate 	ASSERT(cp->cpu_dispthread == t);
13797c478bd9Sstevel@tonic-gate 	ASSERT(t->t_state == TS_ONPROC);
13807c478bd9Sstevel@tonic-gate }
13817c478bd9Sstevel@tonic-gate 
13827c478bd9Sstevel@tonic-gate 
13837c478bd9Sstevel@tonic-gate /*
13847c478bd9Sstevel@tonic-gate  * Processes waking up go to the back of their queue.
13857c478bd9Sstevel@tonic-gate  */
13867c478bd9Sstevel@tonic-gate static void
fx_wakeup(kthread_t * t)13877c478bd9Sstevel@tonic-gate fx_wakeup(kthread_t *t)
13887c478bd9Sstevel@tonic-gate {
13897c478bd9Sstevel@tonic-gate 	fxproc_t	*fxpp = (fxproc_t *)(t->t_cldata);
13907c478bd9Sstevel@tonic-gate 
13917c478bd9Sstevel@tonic-gate 	ASSERT(THREAD_LOCK_HELD(t));
13927c478bd9Sstevel@tonic-gate 
1393d3d50737SRafael Vanoni 	t->t_stime = ddi_get_lbolt();		/* time stamp for the swapper */
13947c478bd9Sstevel@tonic-gate 	if (FX_HAS_CB(fxpp)) {
13957c478bd9Sstevel@tonic-gate 		clock_t new_quantum =  (clock_t)fxpp->fx_pquantum;
13967c478bd9Sstevel@tonic-gate 		pri_t	newpri = fxpp->fx_pri;
13977c478bd9Sstevel@tonic-gate 		FX_CB_WAKEUP(FX_CALLB(fxpp), fxpp->fx_cookie,
1398d4204c85Sraf 		    &new_quantum, &newpri);
13997c478bd9Sstevel@tonic-gate 		FX_ADJUST_QUANTUM(new_quantum);
14007c478bd9Sstevel@tonic-gate 		if ((int)new_quantum != fxpp->fx_pquantum) {
14017c478bd9Sstevel@tonic-gate 			fxpp->fx_pquantum = (int)new_quantum;
14027c478bd9Sstevel@tonic-gate 			fxpp->fx_timeleft = fxpp->fx_pquantum;
14037c478bd9Sstevel@tonic-gate 		}
14047c478bd9Sstevel@tonic-gate 
14057c478bd9Sstevel@tonic-gate 		FX_ADJUST_PRI(newpri);
14067c478bd9Sstevel@tonic-gate 		if (newpri != fxpp->fx_pri) {
14077c478bd9Sstevel@tonic-gate 			fxpp->fx_pri = newpri;
14087c478bd9Sstevel@tonic-gate 			THREAD_CHANGE_PRI(t, fx_dptbl[fxpp->fx_pri].fx_globpri);
14097c478bd9Sstevel@tonic-gate 		}
14107c478bd9Sstevel@tonic-gate 	}
14117c478bd9Sstevel@tonic-gate 
14127c478bd9Sstevel@tonic-gate 	fxpp->fx_flags &= ~FXBACKQ;
14137c478bd9Sstevel@tonic-gate 
1414d3d50737SRafael Vanoni 	if (t->t_disp_time != ddi_get_lbolt())
14157c478bd9Sstevel@tonic-gate 		setbackdq(t);
14167c478bd9Sstevel@tonic-gate 	else
14177c478bd9Sstevel@tonic-gate 		setfrontdq(t);
14187c478bd9Sstevel@tonic-gate }
14197c478bd9Sstevel@tonic-gate 
14207c478bd9Sstevel@tonic-gate 
14217c478bd9Sstevel@tonic-gate /*
14227c478bd9Sstevel@tonic-gate  * When a thread yields, put it on the back of the run queue.
14237c478bd9Sstevel@tonic-gate  */
14247c478bd9Sstevel@tonic-gate static void
fx_yield(kthread_t * t)14257c478bd9Sstevel@tonic-gate fx_yield(kthread_t *t)
14267c478bd9Sstevel@tonic-gate {
14277c478bd9Sstevel@tonic-gate 	fxproc_t	*fxpp = (fxproc_t *)(t->t_cldata);
14287c478bd9Sstevel@tonic-gate 
14297c478bd9Sstevel@tonic-gate 	ASSERT(t == curthread);
14307c478bd9Sstevel@tonic-gate 	ASSERT(THREAD_LOCK_HELD(t));
14317c478bd9Sstevel@tonic-gate 
1432c97ad5cdSakolb 	/*
1433c97ad5cdSakolb 	 * Collect CPU usage spent before yielding CPU.
1434c97ad5cdSakolb 	 */
14358c34bbb7Sakolb 	(void) CPUCAPS_CHARGE(t, &fxpp->fx_caps, CPUCAPS_CHARGE_ENFORCE);
1436c97ad5cdSakolb 
14377c478bd9Sstevel@tonic-gate 	if (FX_HAS_CB(fxpp))  {
14387c478bd9Sstevel@tonic-gate 		clock_t new_quantum =  (clock_t)fxpp->fx_pquantum;
14397c478bd9Sstevel@tonic-gate 		pri_t	newpri = fxpp->fx_pri;
14407c478bd9Sstevel@tonic-gate 		FX_CB_PREEMPT(FX_CALLB(fxpp), fxpp->fx_cookie,
1441d4204c85Sraf 		    &new_quantum, &newpri);
14427c478bd9Sstevel@tonic-gate 		FX_ADJUST_QUANTUM(new_quantum);
14437c478bd9Sstevel@tonic-gate 		if ((int)new_quantum != fxpp->fx_pquantum) {
14447c478bd9Sstevel@tonic-gate 			fxpp->fx_pquantum = (int)new_quantum;
14457c478bd9Sstevel@tonic-gate 			fxpp->fx_timeleft = fxpp->fx_pquantum;
14467c478bd9Sstevel@tonic-gate 		}
14477c478bd9Sstevel@tonic-gate 		FX_ADJUST_PRI(newpri);
14487c478bd9Sstevel@tonic-gate 		fxpp->fx_pri = newpri;
14497c478bd9Sstevel@tonic-gate 		THREAD_CHANGE_PRI(t, fx_dptbl[fxpp->fx_pri].fx_globpri);
14507c478bd9Sstevel@tonic-gate 	}
14517c478bd9Sstevel@tonic-gate 
14527c478bd9Sstevel@tonic-gate 	/*
14537c478bd9Sstevel@tonic-gate 	 * Clear the preemption control "yield" bit since the user is
14547c478bd9Sstevel@tonic-gate 	 * doing a yield.
14557c478bd9Sstevel@tonic-gate 	 */
14567c478bd9Sstevel@tonic-gate 	if (t->t_schedctl)
14577c478bd9Sstevel@tonic-gate 		schedctl_set_yield(t, 0);
14587c478bd9Sstevel@tonic-gate 
14597c478bd9Sstevel@tonic-gate 	if (fxpp->fx_timeleft <= 0) {
14607c478bd9Sstevel@tonic-gate 		/*
14617c478bd9Sstevel@tonic-gate 		 * Time slice was artificially extended to avoid
14627c478bd9Sstevel@tonic-gate 		 * preemption, so pretend we're preempting it now.
14637c478bd9Sstevel@tonic-gate 		 */
14647c478bd9Sstevel@tonic-gate 		DTRACE_SCHED1(schedctl__yield, int, -fxpp->fx_timeleft);
14657c478bd9Sstevel@tonic-gate 		fxpp->fx_timeleft = fxpp->fx_pquantum;
14667c478bd9Sstevel@tonic-gate 		THREAD_CHANGE_PRI(t, fx_dptbl[fxpp->fx_pri].fx_globpri);
14677c478bd9Sstevel@tonic-gate 		ASSERT(t->t_pri >= 0 && t->t_pri <= fx_maxglobpri);
14687c478bd9Sstevel@tonic-gate 	}
14697c478bd9Sstevel@tonic-gate 
14707c478bd9Sstevel@tonic-gate 	fxpp->fx_flags &= ~FXBACKQ;
14717c478bd9Sstevel@tonic-gate 	setbackdq(t);
14727c478bd9Sstevel@tonic-gate }
14737c478bd9Sstevel@tonic-gate 
14747c478bd9Sstevel@tonic-gate /*
14757c478bd9Sstevel@tonic-gate  * Increment the nice value of the specified thread by incr and
14767c478bd9Sstevel@tonic-gate  * return the new value in *retvalp.
14777c478bd9Sstevel@tonic-gate  */
14787c478bd9Sstevel@tonic-gate static int
fx_donice(kthread_t * t,cred_t * cr,int incr,int * retvalp)14797c478bd9Sstevel@tonic-gate fx_donice(kthread_t *t, cred_t *cr, int incr, int *retvalp)
14807c478bd9Sstevel@tonic-gate {
14817c478bd9Sstevel@tonic-gate 	int		newnice;
14827c478bd9Sstevel@tonic-gate 	fxproc_t	*fxpp = (fxproc_t *)(t->t_cldata);
14837c478bd9Sstevel@tonic-gate 	fxkparms_t	fxkparms;
14847c478bd9Sstevel@tonic-gate 
14857c478bd9Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&(ttoproc(t))->p_lock));
14867c478bd9Sstevel@tonic-gate 
14877c478bd9Sstevel@tonic-gate 	/* If there's no change to priority, just return current setting */
14887c478bd9Sstevel@tonic-gate 	if (incr == 0) {
14897c478bd9Sstevel@tonic-gate 		if (retvalp) {
14907c478bd9Sstevel@tonic-gate 			*retvalp = fxpp->fx_nice - NZERO;
14917c478bd9Sstevel@tonic-gate 		}
14927c478bd9Sstevel@tonic-gate 		return (0);
14937c478bd9Sstevel@tonic-gate 	}
14947c478bd9Sstevel@tonic-gate 
14957c478bd9Sstevel@tonic-gate 	if ((incr < 0 || incr > 2 * NZERO) &&
149624d819e6SJerry Jelinek 	    secpolicy_raisepriority(cr) != 0)
14977c478bd9Sstevel@tonic-gate 		return (EPERM);
14987c478bd9Sstevel@tonic-gate 
14997c478bd9Sstevel@tonic-gate 	/*
15007c478bd9Sstevel@tonic-gate 	 * Specifying a nice increment greater than the upper limit of
15017c478bd9Sstevel@tonic-gate 	 * 2 * NZERO - 1 will result in the thread's nice value being
15027c478bd9Sstevel@tonic-gate 	 * set to the upper limit.  We check for this before computing
15037c478bd9Sstevel@tonic-gate 	 * the new value because otherwise we could get overflow
15047c478bd9Sstevel@tonic-gate 	 * if a privileged user specified some ridiculous increment.
15057c478bd9Sstevel@tonic-gate 	 */
15067c478bd9Sstevel@tonic-gate 	if (incr > 2 * NZERO - 1)
15077c478bd9Sstevel@tonic-gate 		incr = 2 * NZERO - 1;
15087c478bd9Sstevel@tonic-gate 
15097c478bd9Sstevel@tonic-gate 	newnice = fxpp->fx_nice + incr;
15107c478bd9Sstevel@tonic-gate 	if (newnice > NZERO)
15117c478bd9Sstevel@tonic-gate 		newnice = NZERO;
15127c478bd9Sstevel@tonic-gate 	else if (newnice < 0)
15137c478bd9Sstevel@tonic-gate 		newnice = 0;
15147c478bd9Sstevel@tonic-gate 
15157c478bd9Sstevel@tonic-gate 	fxkparms.fx_uprilim = fxkparms.fx_upri =
1516d4204c85Sraf 	    -((newnice - NZERO) * fx_maxupri) / NZERO;
15177c478bd9Sstevel@tonic-gate 
15187c478bd9Sstevel@tonic-gate 	fxkparms.fx_cflags = FX_DOUPRILIM | FX_DOUPRI;
15197c478bd9Sstevel@tonic-gate 
15207c478bd9Sstevel@tonic-gate 	fxkparms.fx_tqntm = FX_TQDEF;
15217c478bd9Sstevel@tonic-gate 
15227c478bd9Sstevel@tonic-gate 	/*
15237c478bd9Sstevel@tonic-gate 	 * Reset the uprilim and upri values of the thread. Adjust
15247c478bd9Sstevel@tonic-gate 	 * time quantum accordingly.
15257c478bd9Sstevel@tonic-gate 	 */
15267c478bd9Sstevel@tonic-gate 
15277c478bd9Sstevel@tonic-gate 	(void) fx_parmsset(t, (void *)&fxkparms, (id_t)0, (cred_t *)NULL);
15287c478bd9Sstevel@tonic-gate 
15297c478bd9Sstevel@tonic-gate 	/*
15307c478bd9Sstevel@tonic-gate 	 * Although fx_parmsset already reset fx_nice it may
15317c478bd9Sstevel@tonic-gate 	 * not have been set to precisely the value calculated above
15327c478bd9Sstevel@tonic-gate 	 * because fx_parmsset determines the nice value from the
15337c478bd9Sstevel@tonic-gate 	 * user priority and we may have truncated during the integer
15347c478bd9Sstevel@tonic-gate 	 * conversion from nice value to user priority and back.
15357c478bd9Sstevel@tonic-gate 	 * We reset fx_nice to the value we calculated above.
15367c478bd9Sstevel@tonic-gate 	 */
15377c478bd9Sstevel@tonic-gate 	fxpp->fx_nice = (char)newnice;
15387c478bd9Sstevel@tonic-gate 
15397c478bd9Sstevel@tonic-gate 	if (retvalp)
15407c478bd9Sstevel@tonic-gate 		*retvalp = newnice - NZERO;
15417c478bd9Sstevel@tonic-gate 
15427c478bd9Sstevel@tonic-gate 	return (0);
15437c478bd9Sstevel@tonic-gate }
15447c478bd9Sstevel@tonic-gate 
1545d4204c85Sraf /*
1546d4204c85Sraf  * Increment the priority of the specified thread by incr and
1547d4204c85Sraf  * return the new value in *retvalp.
1548d4204c85Sraf  */
1549d4204c85Sraf static int
fx_doprio(kthread_t * t,cred_t * cr,int incr,int * retvalp)1550d4204c85Sraf fx_doprio(kthread_t *t, cred_t *cr, int incr, int *retvalp)
1551d4204c85Sraf {
1552d4204c85Sraf 	int		newpri;
1553d4204c85Sraf 	fxproc_t	*fxpp = (fxproc_t *)(t->t_cldata);
1554d4204c85Sraf 	fxkparms_t	fxkparms;
1555d4204c85Sraf 
1556d4204c85Sraf 	ASSERT(MUTEX_HELD(&(ttoproc(t))->p_lock));
1557d4204c85Sraf 
1558d4204c85Sraf 	/* If there's no change to priority, just return current setting */
1559d4204c85Sraf 	if (incr == 0) {
1560d4204c85Sraf 		*retvalp = fxpp->fx_pri;
1561d4204c85Sraf 		return (0);
1562d4204c85Sraf 	}
1563d4204c85Sraf 
1564d4204c85Sraf 	newpri = fxpp->fx_pri + incr;
1565d4204c85Sraf 	if (newpri > fx_maxupri || newpri < 0)
1566d4204c85Sraf 		return (EINVAL);
1567d4204c85Sraf 
1568d4204c85Sraf 	*retvalp = newpri;
1569d4204c85Sraf 	fxkparms.fx_uprilim = fxkparms.fx_upri = newpri;
1570d4204c85Sraf 	fxkparms.fx_tqntm = FX_NOCHANGE;
1571d4204c85Sraf 	fxkparms.fx_cflags = FX_DOUPRILIM | FX_DOUPRI;
1572d4204c85Sraf 
1573d4204c85Sraf 	/*
1574d4204c85Sraf 	 * Reset the uprilim and upri values of the thread.
1575d4204c85Sraf 	 */
1576d4204c85Sraf 	return (fx_parmsset(t, (void *)&fxkparms, (id_t)0, cr));
1577d4204c85Sraf }
1578d4204c85Sraf 
15797c478bd9Sstevel@tonic-gate static void
fx_change_priority(kthread_t * t,fxproc_t * fxpp)15807c478bd9Sstevel@tonic-gate fx_change_priority(kthread_t *t, fxproc_t *fxpp)
15817c478bd9Sstevel@tonic-gate {
15827c478bd9Sstevel@tonic-gate 	pri_t	new_pri;
15837c478bd9Sstevel@tonic-gate 
15847c478bd9Sstevel@tonic-gate 	ASSERT(THREAD_LOCK_HELD(t));
15857c478bd9Sstevel@tonic-gate 	new_pri = fx_dptbl[fxpp->fx_pri].fx_globpri;
15867c478bd9Sstevel@tonic-gate 	ASSERT(new_pri >= 0 && new_pri <= fx_maxglobpri);
1587d4204c85Sraf 	t->t_cpri = fxpp->fx_pri;
15887c478bd9Sstevel@tonic-gate 	if (t == curthread || t->t_state == TS_ONPROC) {
15897c478bd9Sstevel@tonic-gate 		/* curthread is always onproc */
15907c478bd9Sstevel@tonic-gate 		cpu_t	*cp = t->t_disp_queue->disp_cpu;
15917c478bd9Sstevel@tonic-gate 		THREAD_CHANGE_PRI(t, new_pri);
15927c478bd9Sstevel@tonic-gate 		if (t == cp->cpu_dispthread)
15937c478bd9Sstevel@tonic-gate 			cp->cpu_dispatch_pri = DISP_PRIO(t);
15947c478bd9Sstevel@tonic-gate 		if (DISP_MUST_SURRENDER(t)) {
15957c478bd9Sstevel@tonic-gate 			fxpp->fx_flags |= FXBACKQ;
15967c478bd9Sstevel@tonic-gate 			cpu_surrender(t);
15977c478bd9Sstevel@tonic-gate 		} else {
15987c478bd9Sstevel@tonic-gate 			fxpp->fx_timeleft = fxpp->fx_pquantum;
15997c478bd9Sstevel@tonic-gate 		}
16007c478bd9Sstevel@tonic-gate 	} else {
16017c478bd9Sstevel@tonic-gate 		/*
16027c478bd9Sstevel@tonic-gate 		 * When the priority of a thread is changed,
16037c478bd9Sstevel@tonic-gate 		 * it may be necessary to adjust its position
16047c478bd9Sstevel@tonic-gate 		 * on a sleep queue or dispatch queue.
16057c478bd9Sstevel@tonic-gate 		 * The function thread_change_pri accomplishes
16067c478bd9Sstevel@tonic-gate 		 * this.
16077c478bd9Sstevel@tonic-gate 		 */
16087c478bd9Sstevel@tonic-gate 		if (thread_change_pri(t, new_pri, 0)) {
16097c478bd9Sstevel@tonic-gate 			/*
16107c478bd9Sstevel@tonic-gate 			 * The thread was on a run queue. Reset
16117c478bd9Sstevel@tonic-gate 			 * its CPU timeleft from the quantum
16127c478bd9Sstevel@tonic-gate 			 * associated with the new priority.
16137c478bd9Sstevel@tonic-gate 			 */
16147c478bd9Sstevel@tonic-gate 			fxpp->fx_timeleft = fxpp->fx_pquantum;
16157c478bd9Sstevel@tonic-gate 		} else {
16167c478bd9Sstevel@tonic-gate 			fxpp->fx_flags |= FXBACKQ;
16177c478bd9Sstevel@tonic-gate 		}
16187c478bd9Sstevel@tonic-gate 	}
16197c478bd9Sstevel@tonic-gate }
16207c478bd9Sstevel@tonic-gate 
16217c478bd9Sstevel@tonic-gate static int
fx_alloc(void ** p,int flag)16227c478bd9Sstevel@tonic-gate fx_alloc(void **p, int flag)
16237c478bd9Sstevel@tonic-gate {
16247c478bd9Sstevel@tonic-gate 	void *bufp;
16257c478bd9Sstevel@tonic-gate 
16267c478bd9Sstevel@tonic-gate 	bufp = kmem_alloc(sizeof (fxproc_t), flag);
16277c478bd9Sstevel@tonic-gate 	if (bufp == NULL) {
16287c478bd9Sstevel@tonic-gate 		return (ENOMEM);
16297c478bd9Sstevel@tonic-gate 	} else {
16307c478bd9Sstevel@tonic-gate 		*p = bufp;
16317c478bd9Sstevel@tonic-gate 		return (0);
16327c478bd9Sstevel@tonic-gate 	}
16337c478bd9Sstevel@tonic-gate }
16347c478bd9Sstevel@tonic-gate 
16357c478bd9Sstevel@tonic-gate static void
fx_free(void * bufp)16367c478bd9Sstevel@tonic-gate fx_free(void *bufp)
16377c478bd9Sstevel@tonic-gate {
16387c478bd9Sstevel@tonic-gate 	if (bufp)
16397c478bd9Sstevel@tonic-gate 		kmem_free(bufp, sizeof (fxproc_t));
16407c478bd9Sstevel@tonic-gate }
16417c478bd9Sstevel@tonic-gate 
16427c478bd9Sstevel@tonic-gate /*
16437c478bd9Sstevel@tonic-gate  * Release the callback list mutex after successful lookup
16447c478bd9Sstevel@tonic-gate  */
16457c478bd9Sstevel@tonic-gate void
fx_list_release(fxproc_t * fxpp)16467c478bd9Sstevel@tonic-gate fx_list_release(fxproc_t *fxpp)
16477c478bd9Sstevel@tonic-gate {
16487c478bd9Sstevel@tonic-gate 	int index = FX_CB_LIST_HASH(fxpp->fx_ktid);
16497c478bd9Sstevel@tonic-gate 	kmutex_t *lockp = &fx_cb_list_lock[index];
16507c478bd9Sstevel@tonic-gate 	mutex_exit(lockp);
16517c478bd9Sstevel@tonic-gate }
16527c478bd9Sstevel@tonic-gate 
16537c478bd9Sstevel@tonic-gate fxproc_t *
fx_list_lookup(kt_did_t ktid)16547c478bd9Sstevel@tonic-gate fx_list_lookup(kt_did_t ktid)
16557c478bd9Sstevel@tonic-gate {
16567c478bd9Sstevel@tonic-gate 	int index = FX_CB_LIST_HASH(ktid);
16577c478bd9Sstevel@tonic-gate 	kmutex_t *lockp = &fx_cb_list_lock[index];
16587c478bd9Sstevel@tonic-gate 	fxproc_t *fxpp;
16597c478bd9Sstevel@tonic-gate 
16607c478bd9Sstevel@tonic-gate 	mutex_enter(lockp);
16617c478bd9Sstevel@tonic-gate 
16627c478bd9Sstevel@tonic-gate 	for (fxpp = fx_cb_plisthead[index].fx_cb_next;
16637c478bd9Sstevel@tonic-gate 	    fxpp != &fx_cb_plisthead[index]; fxpp = fxpp->fx_cb_next) {
16647c478bd9Sstevel@tonic-gate 		if (fxpp->fx_tp->t_cid == fx_cid && fxpp->fx_ktid == ktid &&
16657c478bd9Sstevel@tonic-gate 		    fxpp->fx_callback != NULL) {
16667c478bd9Sstevel@tonic-gate 			/*
16677c478bd9Sstevel@tonic-gate 			 * The caller is responsible for calling
16687c478bd9Sstevel@tonic-gate 			 * fx_list_release to drop the lock upon
16697c478bd9Sstevel@tonic-gate 			 * successful lookup
16707c478bd9Sstevel@tonic-gate 			 */
16717c478bd9Sstevel@tonic-gate 			return (fxpp);
16727c478bd9Sstevel@tonic-gate 		}
16737c478bd9Sstevel@tonic-gate 	}
16747c478bd9Sstevel@tonic-gate 	mutex_exit(lockp);
16757c478bd9Sstevel@tonic-gate 	return ((fxproc_t *)NULL);
16767c478bd9Sstevel@tonic-gate }
16777c478bd9Sstevel@tonic-gate 
16787c478bd9Sstevel@tonic-gate 
16797c478bd9Sstevel@tonic-gate /*
16807c478bd9Sstevel@tonic-gate  * register a callback set of routines for current thread
16817c478bd9Sstevel@tonic-gate  * thread should already be in FX class
16827c478bd9Sstevel@tonic-gate  */
16837c478bd9Sstevel@tonic-gate int
fx_register_callbacks(fx_callbacks_t * fx_callback,fx_cookie_t cookie,pri_t pri,clock_t quantum)16847c478bd9Sstevel@tonic-gate fx_register_callbacks(fx_callbacks_t *fx_callback, fx_cookie_t cookie,
168534b7c4d5SToomas Soome     pri_t pri, clock_t quantum)
16867c478bd9Sstevel@tonic-gate {
16877c478bd9Sstevel@tonic-gate 
16887c478bd9Sstevel@tonic-gate 	fxproc_t	*fxpp;
16897c478bd9Sstevel@tonic-gate 
16907c478bd9Sstevel@tonic-gate 	if (fx_callback == NULL)
16917c478bd9Sstevel@tonic-gate 		return (EINVAL);
16927c478bd9Sstevel@tonic-gate 
16937c478bd9Sstevel@tonic-gate 	if (secpolicy_dispadm(CRED()) != 0)
16947c478bd9Sstevel@tonic-gate 		return (EPERM);
16957c478bd9Sstevel@tonic-gate 
16967c478bd9Sstevel@tonic-gate 	if (FX_CB_VERSION(fx_callback) != FX_CALLB_REV)
16977c478bd9Sstevel@tonic-gate 		return (EINVAL);
16987c478bd9Sstevel@tonic-gate 
16997c478bd9Sstevel@tonic-gate 	if (!FX_ISVALID(pri, quantum))
17007c478bd9Sstevel@tonic-gate 		return (EINVAL);
17017c478bd9Sstevel@tonic-gate 
17027c478bd9Sstevel@tonic-gate 	thread_lock(curthread);		/* get dispatcher lock on thread */
17037c478bd9Sstevel@tonic-gate 
17047c478bd9Sstevel@tonic-gate 	if (curthread->t_cid != fx_cid) {
17057c478bd9Sstevel@tonic-gate 		thread_unlock(curthread);
17067c478bd9Sstevel@tonic-gate 		return (EINVAL);
17077c478bd9Sstevel@tonic-gate 	}
17087c478bd9Sstevel@tonic-gate 
17097c478bd9Sstevel@tonic-gate 	fxpp = (fxproc_t *)(curthread->t_cldata);
17107c478bd9Sstevel@tonic-gate 	ASSERT(fxpp != NULL);
17117c478bd9Sstevel@tonic-gate 	if (FX_HAS_CB(fxpp)) {
17127c478bd9Sstevel@tonic-gate 		thread_unlock(curthread);
17137c478bd9Sstevel@tonic-gate 		return (EINVAL);
17147c478bd9Sstevel@tonic-gate 	}
17157c478bd9Sstevel@tonic-gate 
17167c478bd9Sstevel@tonic-gate 	fxpp->fx_callback = fx_callback;
17177c478bd9Sstevel@tonic-gate 	fxpp->fx_cookie = cookie;
17187c478bd9Sstevel@tonic-gate 
17197c478bd9Sstevel@tonic-gate 	if (pri != FX_CB_NOCHANGE) {
17207c478bd9Sstevel@tonic-gate 		fxpp->fx_pri = pri;
17217c478bd9Sstevel@tonic-gate 		FX_ADJUST_PRI(fxpp->fx_pri);
17227c478bd9Sstevel@tonic-gate 		if (quantum == FX_TQDEF) {
17237c478bd9Sstevel@tonic-gate 			fxpp->fx_pquantum = fx_dptbl[fxpp->fx_pri].fx_quantum;
17247c478bd9Sstevel@tonic-gate 		} else if (quantum == FX_TQINF) {
17257c478bd9Sstevel@tonic-gate 			fxpp->fx_pquantum = FX_TQINF;
17267c478bd9Sstevel@tonic-gate 		} else if (quantum != FX_NOCHANGE) {
17277c478bd9Sstevel@tonic-gate 			FX_ADJUST_QUANTUM(quantum);
17287c478bd9Sstevel@tonic-gate 			fxpp->fx_pquantum = quantum;
17297c478bd9Sstevel@tonic-gate 		}
17307c478bd9Sstevel@tonic-gate 	} else if (quantum != FX_NOCHANGE && quantum != FX_TQDEF) {
17317c478bd9Sstevel@tonic-gate 		if (quantum == FX_TQINF)
17327c478bd9Sstevel@tonic-gate 			fxpp->fx_pquantum = FX_TQINF;
17337c478bd9Sstevel@tonic-gate 		else {
17347c478bd9Sstevel@tonic-gate 			FX_ADJUST_QUANTUM(quantum);
17357c478bd9Sstevel@tonic-gate 			fxpp->fx_pquantum = quantum;
17367c478bd9Sstevel@tonic-gate 		}
17377c478bd9Sstevel@tonic-gate 	}
17387c478bd9Sstevel@tonic-gate 
17397c478bd9Sstevel@tonic-gate 	fxpp->fx_ktid = ddi_get_kt_did();
17407c478bd9Sstevel@tonic-gate 
17417c478bd9Sstevel@tonic-gate 	fx_change_priority(curthread, fxpp);
17427c478bd9Sstevel@tonic-gate 
17437c478bd9Sstevel@tonic-gate 	thread_unlock(curthread);
17447c478bd9Sstevel@tonic-gate 
17457c478bd9Sstevel@tonic-gate 	/*
17467c478bd9Sstevel@tonic-gate 	 * Link new structure into fxproc list.
17477c478bd9Sstevel@tonic-gate 	 */
17487c478bd9Sstevel@tonic-gate 	FX_CB_LIST_INSERT(fxpp);
17497c478bd9Sstevel@tonic-gate 	return (0);
17507c478bd9Sstevel@tonic-gate }
17517c478bd9Sstevel@tonic-gate 
17527c478bd9Sstevel@tonic-gate /* unregister a callback set of routines for current thread */
17537c478bd9Sstevel@tonic-gate int
fx_unregister_callbacks()17547c478bd9Sstevel@tonic-gate fx_unregister_callbacks()
17557c478bd9Sstevel@tonic-gate {
17567c478bd9Sstevel@tonic-gate 	fxproc_t	*fxpp;
17577c478bd9Sstevel@tonic-gate 
17587c478bd9Sstevel@tonic-gate 	if ((fxpp = fx_list_lookup(ddi_get_kt_did())) == NULL) {
17597c478bd9Sstevel@tonic-gate 		/*
17607c478bd9Sstevel@tonic-gate 		 * did not have a registered callback;
17617c478bd9Sstevel@tonic-gate 		 */
17627c478bd9Sstevel@tonic-gate 		return (EINVAL);
17637c478bd9Sstevel@tonic-gate 	}
17647c478bd9Sstevel@tonic-gate 
17657c478bd9Sstevel@tonic-gate 	thread_lock(fxpp->fx_tp);
17667c478bd9Sstevel@tonic-gate 	fxpp->fx_callback = NULL;
176734b7c4d5SToomas Soome 	fxpp->fx_cookie = 0;
17687c478bd9Sstevel@tonic-gate 	thread_unlock(fxpp->fx_tp);
17697c478bd9Sstevel@tonic-gate 	fx_list_release(fxpp);
17707c478bd9Sstevel@tonic-gate 
17717c478bd9Sstevel@tonic-gate 	FX_CB_LIST_DELETE(fxpp);
17727c478bd9Sstevel@tonic-gate 	return (0);
17737c478bd9Sstevel@tonic-gate }
17747c478bd9Sstevel@tonic-gate 
17757c478bd9Sstevel@tonic-gate /*
17767c478bd9Sstevel@tonic-gate  * modify priority and/or quantum value of a thread with callback
17777c478bd9Sstevel@tonic-gate  */
17787c478bd9Sstevel@tonic-gate int
fx_modify_priority(kt_did_t ktid,clock_t quantum,pri_t pri)17797c478bd9Sstevel@tonic-gate fx_modify_priority(kt_did_t ktid, clock_t quantum, pri_t pri)
17807c478bd9Sstevel@tonic-gate {
17817c478bd9Sstevel@tonic-gate 	fxproc_t	*fxpp;
17827c478bd9Sstevel@tonic-gate 
17837c478bd9Sstevel@tonic-gate 	if (!FX_ISVALID(pri, quantum))
17847c478bd9Sstevel@tonic-gate 		return (EINVAL);
17857c478bd9Sstevel@tonic-gate 
17867c478bd9Sstevel@tonic-gate 	if ((fxpp = fx_list_lookup(ktid)) == NULL) {
17877c478bd9Sstevel@tonic-gate 		/*
17887c478bd9Sstevel@tonic-gate 		 * either thread had exited or did not have a registered
17897c478bd9Sstevel@tonic-gate 		 * callback;
17907c478bd9Sstevel@tonic-gate 		 */
17917c478bd9Sstevel@tonic-gate 		return (ESRCH);
17927c478bd9Sstevel@tonic-gate 	}
17937c478bd9Sstevel@tonic-gate 
17947c478bd9Sstevel@tonic-gate 	thread_lock(fxpp->fx_tp);
17957c478bd9Sstevel@tonic-gate 
17967c478bd9Sstevel@tonic-gate 	if (pri != FX_CB_NOCHANGE) {
17977c478bd9Sstevel@tonic-gate 		fxpp->fx_pri = pri;
17987c478bd9Sstevel@tonic-gate 		FX_ADJUST_PRI(fxpp->fx_pri);
17997c478bd9Sstevel@tonic-gate 		if (quantum == FX_TQDEF) {
18007c478bd9Sstevel@tonic-gate 			fxpp->fx_pquantum = fx_dptbl[fxpp->fx_pri].fx_quantum;
18017c478bd9Sstevel@tonic-gate 		} else if (quantum == FX_TQINF) {
18027c478bd9Sstevel@tonic-gate 			fxpp->fx_pquantum = FX_TQINF;
18037c478bd9Sstevel@tonic-gate 		} else if (quantum != FX_NOCHANGE) {
18047c478bd9Sstevel@tonic-gate 			FX_ADJUST_QUANTUM(quantum);
18057c478bd9Sstevel@tonic-gate 			fxpp->fx_pquantum = quantum;
18067c478bd9Sstevel@tonic-gate 		}
18077c478bd9Sstevel@tonic-gate 	} else if (quantum != FX_NOCHANGE && quantum != FX_TQDEF) {
18087c478bd9Sstevel@tonic-gate 		if (quantum == FX_TQINF) {
18097c478bd9Sstevel@tonic-gate 			fxpp->fx_pquantum = FX_TQINF;
18107c478bd9Sstevel@tonic-gate 		} else {
18117c478bd9Sstevel@tonic-gate 			FX_ADJUST_QUANTUM(quantum);
18127c478bd9Sstevel@tonic-gate 			fxpp->fx_pquantum = quantum;
18137c478bd9Sstevel@tonic-gate 		}
18147c478bd9Sstevel@tonic-gate 	}
18157c478bd9Sstevel@tonic-gate 
18167c478bd9Sstevel@tonic-gate 	fx_change_priority(fxpp->fx_tp, fxpp);
18177c478bd9Sstevel@tonic-gate 
18187c478bd9Sstevel@tonic-gate 	thread_unlock(fxpp->fx_tp);
18197c478bd9Sstevel@tonic-gate 	fx_list_release(fxpp);
18207c478bd9Sstevel@tonic-gate 	return (0);
18217c478bd9Sstevel@tonic-gate }
18227c478bd9Sstevel@tonic-gate 
18237c478bd9Sstevel@tonic-gate 
18247c478bd9Sstevel@tonic-gate /*
18257c478bd9Sstevel@tonic-gate  * return an iblock cookie for mutex initialization to be used in callbacks
18267c478bd9Sstevel@tonic-gate  */
18277c478bd9Sstevel@tonic-gate void *
fx_get_mutex_cookie()18287c478bd9Sstevel@tonic-gate fx_get_mutex_cookie()
18297c478bd9Sstevel@tonic-gate {
18307c478bd9Sstevel@tonic-gate 	return ((void *)(uintptr_t)__ipltospl(DISP_LEVEL));
18317c478bd9Sstevel@tonic-gate }
18327c478bd9Sstevel@tonic-gate 
18337c478bd9Sstevel@tonic-gate /*
18347c478bd9Sstevel@tonic-gate  * return maximum relative priority
18357c478bd9Sstevel@tonic-gate  */
18367c478bd9Sstevel@tonic-gate pri_t
fx_get_maxpri()18377c478bd9Sstevel@tonic-gate fx_get_maxpri()
18387c478bd9Sstevel@tonic-gate {
18397c478bd9Sstevel@tonic-gate 	return (fx_maxumdpri);
18407c478bd9Sstevel@tonic-gate }
1841