1 /*
2 * Mach Operating System
3 * Copyright (c) 1993,1992 Carnegie Mellon University
4 * All Rights Reserved.
5 *
6 * Permission to use, copy, modify and distribute this software and its
7 * documentation is hereby granted, provided that both the copyright
8 * notice and this permission notice appear in all copies of the
9 * software, derivative works or modified versions, and any portions
10 * thereof, and that both notices appear in supporting documentation.
11 *
12 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
13 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
14 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
15 *
16 * Carnegie Mellon requests users of this software to return to
17 *
18 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
19 * School of Computer Science
20 * Carnegie Mellon University
21 * Pittsburgh PA 15213-3890
22 *
23 * any improvements or extensions that they make and grant Carnegie Mellon
24 * the rights to redistribute these changes.
25 */
26 /*
27 * HISTORY
28 * $Log: sched_policy.h,v $
29 * Revision 2.2 93/11/17 17:21:35 dbg
30 * Moved common code to kern/run_queues.c.
31 * [93/04/10 dbg]
32 *
33 * Added more operations to support per-scheduling-policy run queue
34 * structure.
35 * [93/04/06 dbg]
36 *
37 * Added THREAD_SELECT_POLICY and THREAD_REQUEUE. Removed one
38 * level of indirection from macros.
39 * [93/03/31 dbg]
40 *
41 * Added microseconds argument to CLOCK_SCHED macro.
42 * [93/01/28 dbg]
43 *
44 * Moved user interface into mach/sched_policy.h.
45 *
46 * Created
47 * [92/02/22 savage]
48 *
49 */
50
51 /*
52 * Selectable scheduling policies - kernel data structures.
53 */
54 #ifndef _KERN_SCHED_POLICY_H_
55 #define _KERN_SCHED_POLICY_H_
56
57 #include <mach_kdb.h>
58
59 #include <mach/boolean.h>
60 #include <mach/kern_return.h>
61 #include <mach/policy.h>
62 #include <kern/lock.h>
63 #include <kern/queue.h>
64 #include <kern/run_queues.h>
65 #include <kern/kern_types.h>
66
67 /*
68 * Scheduling operations that vary by policy
69 */
70 struct sched_ops {
71 /* get the next thread to run */
72 thread_t (*thread_dequeue)(
73 run_queue_t runq); /* choose from this run q */
74
75 /* enqueue a thread to run */
76 boolean_t (*thread_enqueue)(
77 run_queue_t runq, /* put on this runq */
78 thread_t thread, /* thread */
79 boolean_t may_preempt); /* may preempt running thread */
80 /* returns whether to preempt */
81
82 /* remove thread from a run queue */
83 void (*thread_remqueue)(
84 run_queue_t runq, /* remove from this run q */
85 thread_t thread); /* remove this thread */
86
87 /* preemption check */
88 boolean_t (*csw_needed)(
89 run_queue_t runq,
90 thread_t thread);
91
92 /* scheduling decisions at periodic clock tick */
93 void (*clock_sched)(
94 thread_t thread,
95 boolean_t end_of_quantum);
96
97 /* priority update */
98 void (*update_priority)(
99 thread_t thread);
100
101 /* allocate a run queue structure for this policy */
102 run_queue_t (*runq_alloc)(void);
103
104 /* deallocate a run queue structure for this policy */
105 void (*runq_free)(
106 run_queue_t runq);
107
108 /* set the limit values for this policy */
109 kern_return_t (*runq_set_limit)(
110 run_queue_t runq,
111 policy_param_t limit,
112 natural_t count);
113
114 /* get the limit values for this policy */
115 kern_return_t (*runq_get_limit)(
116 run_queue_t runq,
117 policy_param_t limit,
118 natural_t *count);
119
120 /* set the limit values for this thread */
121 kern_return_t (*thread_set_limit)(
122 thread_t thread,
123 policy_param_t limit,
124 natural_t count);
125
126 /* set the current parameters for a thread */
127 kern_return_t (*thread_set_param)(
128 thread_t thread,
129 policy_param_t param,
130 natural_t param_count,
131 boolean_t new_policy,
132 boolean_t check_limits);
133
134 /* get the limit and current parameters for a thread */
135 kern_return_t (*thread_get_param)(
136 thread_t thread,
137 policy_param_t param,
138 natural_t *count);
139
140 /* set the default parameters for a task */
141 kern_return_t (*task_set_param)(
142 task_t task,
143 policy_param_t param,
144 natural_t param_count);
145
146 /* get the default parameters for a task */
147 kern_return_t (*task_get_param)(
148 task_t task,
149 policy_param_t param,
150 natural_t *count);
151
152 #if MACH_IO_BINDING
153 /* compare threads at the heads of two run queues */
154 boolean_t (*runq_head_preempt)(
155 run_queue_t runq_1,
156 run_queue_t runq_2);
157 #endif /* MACH_IO_BINDING */
158
159 #if MACH_KDB
160 /* print thread policy and priority for debugger */
161 /* format is "%3s %3d" */
162 void (*thread_db_print)(
163 thread_t thread);
164 #endif /* MACH_KDB */
165 };
166
167 /*
168 * Scheduling operations are in the processor set.
169 */
170 #define THREAD_DEQUEUE(runq) \
171 ((*(runq)->rq_policy->sched_ops.thread_dequeue)\
172 ((runq)) )
173
174 #define THREAD_ENQUEUE(runq, thread, may_preempt) \
175 ((*(runq)->rq_policy->sched_ops.thread_enqueue)\
176 ((runq), (thread), (may_preempt)) )
177
178 #define THREAD_REMQUEUE(runq, thread) \
179 ((*(runq)->rq_policy->sched_ops.thread_remqueue)\
180 ((runq), (thread)) )
181
182 #define CSW_NEEDED(runq, thread) \
183 ((*(runq)->rq_policy->sched_ops.csw_needed)\
184 ((runq), (thread)) )
185
186 #define CLOCK_SCHED(thread, end_of_quantum) \
187 ((*(thread)->cur_policy->sched_ops.clock_sched)\
188 ((thread), (end_of_quantum)) )
189
190 /*
191 * Update_priority is often null.
192 * Check for null routine instead of calling it.
193 */
194 #define UPDATE_PRIORITY(thread) \
195 MACRO_BEGIN \
196 void (*upd_pri)(thread_t); \
197 \
198 upd_pri = (thread)->cur_policy->sched_ops.update_priority; \
199 if (upd_pri) \
200 (*upd_pri) ((thread)); \
201 MACRO_END
202
203 #define RUNQ_ALLOC(sched_policy) \
204 ((*(sched_policy)->sched_ops.runq_alloc)())
205
206 #define RUNQ_FREE(runq) \
207 ((*(runq)->rq_policy->sched_ops.runq_free)\
208 ((runq)) )
209
210 #define RUNQ_SET_LIMIT(runq, limit, count) \
211 ((*(runq)->rq_policy->sched_ops.runq_set_limit) \
212 ((runq), (limit), (count)) )
213
214 #define RUNQ_GET_LIMIT(runq, limit, count) \
215 ((*(runq)->rq_policy->sched_ops.runq_get_limit) \
216 ((runq), (limit), (count)) )
217
218 #define THREAD_SET_LIMIT(thread, limit, count) \
219 ((*(thread)->sched_policy->sched_ops.thread_set_limit) \
220 ((thread), (limit), (count)) )
221
222 #define THREAD_SET_PARAM(thread, param, count, new_policy, check_limits) \
223 ((*(thread)->sched_policy->sched_ops.thread_set_param)\
224 ((thread), (param), (count), (new_policy), (check_limits)) )
225
226 #define THREAD_GET_PARAM(thread, param, count) \
227 ((*(thread)->sched_policy->sched_ops.thread_get_param)\
228 ((thread), (param), (count)) )
229
230 #define TASK_SET_PARAM(task, param, count) \
231 ((*(task)->sched_policy->sched_ops.task_set_param)\
232 ((task), (param), (count)) )
233
234 #define TASK_GET_PARAM(task, param, count) \
235 ((*(task)->sched_policy->sched_ops.task_get_param)\
236 ((task), (param), (count)) )
237
238 #if MACH_IO_BINDING
239 #define RUNQ_HEAD_PREEMPT(runq_1, runq_2) \
240 ((*(runq_1)->rq_policy->sched_ops.runq_head_preempt) \
241 ((runq_1), (runq_2)) )
242 #endif /* MACH_IO_BINDING */
243
244 #if MACH_KDB
245 #define THREAD_DB_PRINT(thread) \
246 ((*(thread)->sched_policy->sched_ops.thread_db_print)\
247 ((thread)) )
248 #endif /* MACH_KDB */
249
250 /*
251 * Scheduling Policy
252 */
253 struct sched_policy {
254 struct sched_ops sched_ops; /* operations */
255 int name; /* integer name */
256 char * string_name; /* string name */
257 int rank; /* relative ranking */
258 };
259
260 typedef struct sched_policy * sched_policy_t;
261 typedef struct sched_policy sched_policy_data_t;
262
263 #define SCHED_POLICY_NULL ((sched_policy_t) 0)
264
265 /*
266 * Scheduling policy ranking function.
267 */
268 #define sched_policy_leq(sched1, sched2) \
269 ((sched1)->rank <= (sched2)->rank)
270
271 extern void sched_policy_init(void);
272 extern sched_policy_t sched_policy_lookup(int policy);
273
274 /*
275 * Generic scheduling parameter data structure.
276 *
277 * This should be configurable from the scheduling
278 * parameters built into the system, but it isn`t now.
279 */
280
281 #define SCHED_PARAM_MAX 8
282
283 struct sched_param {
284 natural_t data[SCHED_PARAM_MAX];
285 };
286
287 typedef struct sched_param sched_param_data_t;
288
289 /*
290 * Routines to set and get scheduling policies and parameters.
291 */
292 extern void processor_set_default_policies(processor_set_t);
293
294 extern void task_inherit_default_policy(
295 task_t parent_task,
296 task_t new_task);
297
298 extern void thread_set_default_policy(thread_t);
299 extern void thread_enforce_policy_limits(thread_t, processor_set_t);
300 extern void thread_set_initial_policy(thread_t, task_t);
301
302 #endif /* _KERN_SCHED_POLICY_H_ */
303
Cache object: 784a57cec9bd9a9a97513efe6a8b76fe
|