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