xref: /titanic_51/usr/src/uts/common/sys/fx.h (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright (c) 2001 by Sun Microsystems, Inc.
24*7c478bd9Sstevel@tonic-gate  * All rights reserved.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #ifndef _SYS_FX_H
28*7c478bd9Sstevel@tonic-gate #define	_SYS_FX_H
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*7c478bd9Sstevel@tonic-gate 
32*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
33*7c478bd9Sstevel@tonic-gate #include <sys/thread.h>
34*7c478bd9Sstevel@tonic-gate #include <sys/ddi.h>
35*7c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
36*7c478bd9Sstevel@tonic-gate 
37*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
38*7c478bd9Sstevel@tonic-gate extern "C" {
39*7c478bd9Sstevel@tonic-gate #endif
40*7c478bd9Sstevel@tonic-gate 
41*7c478bd9Sstevel@tonic-gate /*
42*7c478bd9Sstevel@tonic-gate  * Fixed-priority dispatcher parameter table entry
43*7c478bd9Sstevel@tonic-gate  */
44*7c478bd9Sstevel@tonic-gate typedef struct fxdpent {
45*7c478bd9Sstevel@tonic-gate 	pri_t	fx_globpri;	/* global (class independent) priority */
46*7c478bd9Sstevel@tonic-gate 	int	fx_quantum;	/* time quantum given to procs at this level */
47*7c478bd9Sstevel@tonic-gate } fxdpent_t;
48*7c478bd9Sstevel@tonic-gate 
49*7c478bd9Sstevel@tonic-gate #ifdef _KERNEL
50*7c478bd9Sstevel@tonic-gate 
51*7c478bd9Sstevel@tonic-gate typedef uintptr_t fx_cookie_t;	/* handle for callback supplied storage */
52*7c478bd9Sstevel@tonic-gate 
53*7c478bd9Sstevel@tonic-gate /*
54*7c478bd9Sstevel@tonic-gate  * callbacks supplied by custom scheduler. In general, a change to quantum
55*7c478bd9Sstevel@tonic-gate  * and/or priority when returning from a callback has immediate effect.
56*7c478bd9Sstevel@tonic-gate  *
57*7c478bd9Sstevel@tonic-gate  * fx_exit - called when a thread exits. This also needs to free any storage
58*7c478bd9Sstevel@tonic-gate  *	for the fx_cookie_t.
59*7c478bd9Sstevel@tonic-gate  *
60*7c478bd9Sstevel@tonic-gate  * fx_callb_tick - called at every clock tick attributed to this thread
61*7c478bd9Sstevel@tonic-gate  *
62*7c478bd9Sstevel@tonic-gate  * fx_callb_preempt - called when a thread is being preempted or yielding
63*7c478bd9Sstevel@tonic-gate  *
64*7c478bd9Sstevel@tonic-gate  * fx_callb_stop/fx_callb_sleep - called when a thread stops running
65*7c478bd9Sstevel@tonic-gate  *
66*7c478bd9Sstevel@tonic-gate  * fx_callb_wakeup - called when a thread is again runnable
67*7c478bd9Sstevel@tonic-gate  */
68*7c478bd9Sstevel@tonic-gate typedef struct fx_callbacks {
69*7c478bd9Sstevel@tonic-gate 	int fx_callb_version;
70*7c478bd9Sstevel@tonic-gate 	void (*fx_callb_exit)(fx_cookie_t);
71*7c478bd9Sstevel@tonic-gate 	void (*fx_callb_tick)(fx_cookie_t, clock_t *, pri_t *);
72*7c478bd9Sstevel@tonic-gate 	void (*fx_callb_preempt)(fx_cookie_t, clock_t *, pri_t *);
73*7c478bd9Sstevel@tonic-gate 	void (*fx_callb_stop)(fx_cookie_t);
74*7c478bd9Sstevel@tonic-gate 	void (*fx_callb_sleep)(fx_cookie_t);
75*7c478bd9Sstevel@tonic-gate 	void (*fx_callb_wakeup)(fx_cookie_t, clock_t *, pri_t *);
76*7c478bd9Sstevel@tonic-gate 
77*7c478bd9Sstevel@tonic-gate } fx_callbacks_t;
78*7c478bd9Sstevel@tonic-gate 
79*7c478bd9Sstevel@tonic-gate 
80*7c478bd9Sstevel@tonic-gate #define	FX_CALLB_VERSION_1	1
81*7c478bd9Sstevel@tonic-gate 
82*7c478bd9Sstevel@tonic-gate #define	FX_CALLB_REV	FX_CALLB_VERSION_1
83*7c478bd9Sstevel@tonic-gate 
84*7c478bd9Sstevel@tonic-gate #define	FX_CB_VERSION(cb)		cb->fx_callb_version
85*7c478bd9Sstevel@tonic-gate 
86*7c478bd9Sstevel@tonic-gate #define	FX_CB_EXIT(cb, c)		cb->fx_callb_exit(c)
87*7c478bd9Sstevel@tonic-gate 
88*7c478bd9Sstevel@tonic-gate #define	FX_CB_TICK(cb, c, q, p)		cb->fx_callb_tick(c, q, p)
89*7c478bd9Sstevel@tonic-gate 
90*7c478bd9Sstevel@tonic-gate #define	FX_CB_PREEMPT(cb, c, q, p)	cb->fx_callb_preempt(c, q, p)
91*7c478bd9Sstevel@tonic-gate 
92*7c478bd9Sstevel@tonic-gate #define	FX_CB_STOP(cb, c)		cb->fx_callb_stop(c)
93*7c478bd9Sstevel@tonic-gate 
94*7c478bd9Sstevel@tonic-gate #define	FX_CB_SLEEP(cb, c)		cb->fx_callb_sleep(c)
95*7c478bd9Sstevel@tonic-gate 
96*7c478bd9Sstevel@tonic-gate #define	FX_CB_WAKEUP(cb, c, q, p)	cb->fx_callb_wakeup(c, q, p)
97*7c478bd9Sstevel@tonic-gate 
98*7c478bd9Sstevel@tonic-gate /* priority setting */
99*7c478bd9Sstevel@tonic-gate #define	FX_CB_NOCHANGE	-32768
100*7c478bd9Sstevel@tonic-gate 
101*7c478bd9Sstevel@tonic-gate 
102*7c478bd9Sstevel@tonic-gate /*
103*7c478bd9Sstevel@tonic-gate  * Fixed-priority class specific thread structure
104*7c478bd9Sstevel@tonic-gate  */
105*7c478bd9Sstevel@tonic-gate typedef struct fxproc {
106*7c478bd9Sstevel@tonic-gate 	int		fx_pquantum;	/* time quantum given to this proc */
107*7c478bd9Sstevel@tonic-gate 	int		fx_timeleft;	/* time remaining in procs quantum */
108*7c478bd9Sstevel@tonic-gate 
109*7c478bd9Sstevel@tonic-gate 	pri_t		fx_pri;		/* relative priority within fx class */
110*7c478bd9Sstevel@tonic-gate 					/* same as user priority */
111*7c478bd9Sstevel@tonic-gate 
112*7c478bd9Sstevel@tonic-gate 	pri_t		fx_uprilim;	/* user priority limit */
113*7c478bd9Sstevel@tonic-gate 
114*7c478bd9Sstevel@tonic-gate 	char		fx_nice;	/* nice value for compatibility */
115*7c478bd9Sstevel@tonic-gate 	uchar_t 	fx_flags;	/* flags defined below */
116*7c478bd9Sstevel@tonic-gate 	kthread_t 	*fx_tp;		/* pointer to thread */
117*7c478bd9Sstevel@tonic-gate 	struct fxproc 	*fx_next;	/* pointer to next fxproc */
118*7c478bd9Sstevel@tonic-gate 
119*7c478bd9Sstevel@tonic-gate 	struct fxproc 	*fx_prev;	/* pointer to previous fxproc */
120*7c478bd9Sstevel@tonic-gate 
121*7c478bd9Sstevel@tonic-gate 	/* the following are used only when we have callbacks registered */
122*7c478bd9Sstevel@tonic-gate 	kt_did_t	fx_ktid;
123*7c478bd9Sstevel@tonic-gate 	struct fxproc 	*fx_cb_next;	/* pointer to next fxproc that */
124*7c478bd9Sstevel@tonic-gate 					/* has a callback */
125*7c478bd9Sstevel@tonic-gate 
126*7c478bd9Sstevel@tonic-gate 	struct fxproc 	*fx_cb_prev;	/* pointer to previous fxproc that */
127*7c478bd9Sstevel@tonic-gate 					/* has a callback */
128*7c478bd9Sstevel@tonic-gate 	fx_cookie_t	fx_cookie;	/* cookie with which callback */
129*7c478bd9Sstevel@tonic-gate 					/* was registered */
130*7c478bd9Sstevel@tonic-gate 	fx_callbacks_t 	*fx_callback;	/* pointer to callback structure */
131*7c478bd9Sstevel@tonic-gate } fxproc_t;
132*7c478bd9Sstevel@tonic-gate 
133*7c478bd9Sstevel@tonic-gate 
134*7c478bd9Sstevel@tonic-gate #define	FX_CALLB(fxpp)	fxpp->fx_callback
135*7c478bd9Sstevel@tonic-gate 
136*7c478bd9Sstevel@tonic-gate 
137*7c478bd9Sstevel@tonic-gate /* flags */
138*7c478bd9Sstevel@tonic-gate #define	FXBACKQ	0x02	/* thread goes to back of disp q when preempted */
139*7c478bd9Sstevel@tonic-gate 
140*7c478bd9Sstevel@tonic-gate /*
141*7c478bd9Sstevel@tonic-gate  * Kernel version of fixed-priority class specific parameter structure
142*7c478bd9Sstevel@tonic-gate  */
143*7c478bd9Sstevel@tonic-gate typedef struct	fxkparms {
144*7c478bd9Sstevel@tonic-gate 	pri_t	fx_upri;
145*7c478bd9Sstevel@tonic-gate 	pri_t	fx_uprilim;
146*7c478bd9Sstevel@tonic-gate 	int	fx_tqntm;
147*7c478bd9Sstevel@tonic-gate 	uint_t	fx_cflags;
148*7c478bd9Sstevel@tonic-gate } fxkparms_t;
149*7c478bd9Sstevel@tonic-gate 
150*7c478bd9Sstevel@tonic-gate 
151*7c478bd9Sstevel@tonic-gate 
152*7c478bd9Sstevel@tonic-gate /*
153*7c478bd9Sstevel@tonic-gate  * Interface for partner private code. This is not a public interface.
154*7c478bd9Sstevel@tonic-gate  */
155*7c478bd9Sstevel@tonic-gate extern int fx_register_callbacks(fx_callbacks_t *, fx_cookie_t, pri_t, clock_t);
156*7c478bd9Sstevel@tonic-gate extern int fx_unregister_callbacks();
157*7c478bd9Sstevel@tonic-gate extern int fx_modify_priority(kt_did_t, clock_t, pri_t);
158*7c478bd9Sstevel@tonic-gate extern void *fx_get_mutex_cookie();
159*7c478bd9Sstevel@tonic-gate extern pri_t fx_get_maxpri();
160*7c478bd9Sstevel@tonic-gate 
161*7c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
162*7c478bd9Sstevel@tonic-gate 
163*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
164*7c478bd9Sstevel@tonic-gate }
165*7c478bd9Sstevel@tonic-gate #endif
166*7c478bd9Sstevel@tonic-gate 
167*7c478bd9Sstevel@tonic-gate #endif	/* _SYS_FX_H */
168