L4Re Operating System Framework – Interface and Usage Documentation
Loading...
Searching...
No Matches
scheduler.h
Go to the documentation of this file.
1
5/*
6 * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
7 * Alexander Warg <warg@os.inf.tu-dresden.de>
8 * economic rights: Technische Universität Dresden (Germany)
9 *
10 * This file is part of TUD:OS and distributed under the terms of the
11 * GNU General Public License 2.
12 * Please see the COPYING-GPL-2 file for details.
13 *
14 * As a special exception, you may use this file as part of a free software
15 * library without restriction. Specifically, if other files instantiate
16 * templates or use macros or inline functions from this file, or you compile
17 * this file and link it with other files to produce an executable, this
18 * file does not by itself cause the resulting executable to be covered by
19 * the GNU General Public License. This exception does not however
20 * invalidate any other reasons why the executable file might be covered by
21 * the GNU General Public License.
22 */
23#pragma once
24
26#include <l4/sys/ipc.h>
27
64
69typedef struct l4_sched_cpu_set_t
70{
84
89
90#ifdef __cplusplus
92 unsigned char granularity() const { return gran_offset >> 24; }
94 unsigned offset() const { return gran_offset & 0x00ffffff; }
101 void set(unsigned char granularity, unsigned offset)
102 { gran_offset = ((l4_umword_t)granularity << 24) | (offset & 0x00ffffff); }
103#endif
105
117l4_sched_cpu_set(l4_umword_t offset, unsigned char granularity,
118 l4_umword_t map L4_DEFAULT_PARAM(1)) L4_NOTHROW;
119
137l4_scheduler_info(l4_cap_idx_t scheduler, l4_umword_t *cpu_max,
139
163 l4_sched_cpu_set_t *cpus,
164 l4_umword_t *sched_classes) L4_NOTHROW;
165
170l4_scheduler_info_u(l4_cap_idx_t scheduler, l4_umword_t *cpu_max,
171 l4_sched_cpu_set_t *cpus, l4_umword_t *sched_classes,
172 l4_utcb_t *utcb) L4_NOTHROW;
173
174
185
193l4_sched_param(unsigned prio,
194 l4_umword_t quantum L4_DEFAULT_PARAM(0)) L4_NOTHROW;
195
205 l4_cap_idx_t thread, l4_sched_param_t const *sp) L4_NOTHROW;
206
211l4_scheduler_run_thread_u(l4_cap_idx_t scheduler, l4_cap_idx_t thread,
212 l4_sched_param_t const *sp, l4_utcb_t *utcb) L4_NOTHROW;
213
224
229l4_scheduler_idle_time_u(l4_cap_idx_t scheduler, l4_sched_cpu_set_t const *cpus,
231
232
233
244L4_INLINE int
246
250L4_INLINE int
251l4_scheduler_is_online_u(l4_cap_idx_t scheduler, l4_umword_t cpu,
252 l4_utcb_t *utcb) L4_NOTHROW;
253
254
255
268
269/*************** Implementations *******************/
270
272l4_sched_cpu_set(l4_umword_t offset, unsigned char granularity,
274{
276 cs.gran_offset = ((l4_umword_t)granularity << 24) | (offset & 0x00ffffff);
277 cs.map = map;
278 return cs;
279}
280
282l4_sched_param(unsigned prio, l4_umword_t quantum) L4_NOTHROW
283{
285 sp.prio = prio;
286 sp.quantum = quantum;
287 sp.affinity = l4_sched_cpu_set(0, ~0, 1);
288 return sp;
289}
290
291
293l4_scheduler_info_u(l4_cap_idx_t scheduler, l4_umword_t *cpu_max,
294 l4_sched_cpu_set_t *cpus, l4_umword_t *sched_classes,
295 l4_utcb_t *utcb) L4_NOTHROW
296{
297 l4_msg_regs_t *m = l4_utcb_mr_u(utcb);
298 l4_msgtag_t res;
299
300 m->mr[0] = L4_SCHEDULER_INFO_OP;
301 m->mr[1] = cpus->gran_offset;
302
303 res = l4_ipc_call(scheduler, utcb, l4_msgtag(L4_PROTO_SCHEDULER, 2, 0, 0), L4_IPC_NEVER);
304
305 if (l4_msgtag_has_error(res))
306 return res;
307
308 cpus->map = m->mr[0];
309
310 if (cpu_max)
311 *cpu_max = m->mr[1];
312
313 if (sched_classes)
314 *sched_classes = m->mr[2];
315
316 return res;
317}
318
320l4_scheduler_run_thread_u(l4_cap_idx_t scheduler, l4_cap_idx_t thread,
321 l4_sched_param_t const *sp, l4_utcb_t *utcb) L4_NOTHROW
322{
323 l4_msg_regs_t *m = l4_utcb_mr_u(utcb);
325 m->mr[1] = sp->affinity.gran_offset;
326 m->mr[2] = sp->affinity.map;
327 m->mr[3] = sp->prio;
328 m->mr[4] = sp->quantum;
329 m->mr[5] = l4_map_obj_control(0, 0);
330 m->mr[6] = l4_obj_fpage(thread, 0, L4_CAP_FPAGE_RWS).raw;
331
332 return l4_ipc_call(scheduler, utcb, l4_msgtag(L4_PROTO_SCHEDULER, 5, 1, 0), L4_IPC_NEVER);
333}
334
336l4_scheduler_idle_time_u(l4_cap_idx_t scheduler, l4_sched_cpu_set_t const *cpus,
338{
339 l4_msg_regs_t *v = l4_utcb_mr_u(utcb);
340 l4_msgtag_t res;
341
343 v->mr[1] = cpus->gran_offset;
344 v->mr[2] = cpus->map;
345
346 res = l4_ipc_call(scheduler, utcb,
348
349 if (l4_msgtag_has_error(res))
350 return res;
351
352 *us = v->mr64[l4_utcb_mr64_idx(0)];
353
354 return res;
355}
356
357
358L4_INLINE int
359l4_scheduler_is_online_u(l4_cap_idx_t scheduler, l4_umword_t cpu,
360 l4_utcb_t *utcb) L4_NOTHROW
361{
363 l4_msgtag_t r;
364 s.gran_offset = cpu;
365 r = l4_scheduler_info_u(scheduler, NULL, &s, NULL, utcb);
366 if (l4_msgtag_has_error(r) || l4_msgtag_label(r) < 0)
367 return 0;
368
369 return s.map & 1;
370}
371
372
376{
377 return l4_scheduler_info_u(scheduler, cpu_max, cpus, NULL, l4_utcb());
378}
379
382 l4_sched_cpu_set_t *cpus,
383 l4_umword_t *sched_classes) L4_NOTHROW
384{
385 return l4_scheduler_info_u(scheduler, cpu_max, cpus, sched_classes, l4_utcb());
386}
387
390 l4_cap_idx_t thread, l4_sched_param_t const *sp) L4_NOTHROW
391{
392 return l4_scheduler_run_thread_u(scheduler, thread, sp, l4_utcb());
393}
394
398{
399 return l4_scheduler_idle_time_u(scheduler, cpus, us, l4_utcb());
400}
401
402L4_INLINE int
404{
405 return l4_scheduler_is_online_u(scheduler, cpu, l4_utcb());
406}
unsigned long l4_umword_t
Unsigned machine word.
Definition l4int.h:51
l4_uint64_t l4_kernel_clock_t
Kernel clock type.
Definition l4int.h:64
unsigned long l4_cap_idx_t
Capability selector type.
Definition types.h:358
l4_fpage_t l4_obj_fpage(l4_cap_idx_t obj, unsigned int order, unsigned char rights) L4_NOTHROW
Create a kernel-object flex page.
Definition __l4_fpage.h:680
@ L4_CAP_FPAGE_RWS
Read, interface specific 'W', and 'S' rights for capability flex-pages.
Definition __l4_fpage.h:209
l4_msgtag_t l4_ipc_call(l4_cap_idx_t object, l4_utcb_t *utcb, l4_msgtag_t tag, l4_timeout_t timeout) L4_NOTHROW
Object call (usual invocation).
Definition ipc.h:550
l4_umword_t l4_map_obj_control(l4_umword_t spot, unsigned grant) L4_NOTHROW
Create the first word for a map item for the object space.
Definition __l4_fpage.h:714
unsigned l4_msgtag_has_error(l4_msgtag_t t) L4_NOTHROW
Test for error indicator flag.
Definition types.h:456
l4_msgtag_t l4_msgtag(long label, unsigned words, unsigned items, unsigned flags) L4_NOTHROW
Create a message tag from the specified values.
Definition types.h:427
long l4_msgtag_label(l4_msgtag_t t) L4_NOTHROW
Get the protocol of tag.
Definition types.h:439
@ L4_PROTO_SCHEDULER
Protocol for messages to a scheduler object.
Definition types.h:66
int l4_scheduler_is_online(l4_cap_idx_t scheduler, l4_umword_t cpu) L4_NOTHROW
Query if a CPU is online.
Definition scheduler.h:403
L4_scheduler_ops
Operations on the Scheduler object.
Definition scheduler.h:263
l4_sched_cpu_set_t l4_sched_cpu_set(l4_umword_t offset, unsigned char granularity, l4_umword_t map=1) L4_NOTHROW
Definition scheduler.h:272
L4_scheduler_classes
Supported scheduler classes.
Definition scheduler.h:58
l4_msgtag_t l4_scheduler_info(l4_cap_idx_t scheduler, l4_umword_t *cpu_max, l4_sched_cpu_set_t *cpus) L4_NOTHROW
Get scheduler information.
Definition scheduler.h:374
l4_msgtag_t l4_scheduler_info_with_classes(l4_cap_idx_t scheduler, l4_umword_t *cpu_max, l4_sched_cpu_set_t *cpus, l4_umword_t *sched_classes) L4_NOTHROW
Get scheduler information.
Definition scheduler.h:381
l4_sched_param_t l4_sched_param(unsigned prio, l4_umword_t quantum=0) L4_NOTHROW
Construct scheduler parameter.
Definition scheduler.h:282
l4_msgtag_t l4_scheduler_run_thread(l4_cap_idx_t scheduler, l4_cap_idx_t thread, l4_sched_param_t const *sp) L4_NOTHROW
Run a thread on a Scheduler.
Definition scheduler.h:389
l4_msgtag_t l4_scheduler_idle_time(l4_cap_idx_t scheduler, l4_sched_cpu_set_t const *cpus, l4_kernel_clock_t *us) L4_NOTHROW
Query the idle time (in µs) of a CPU.
Definition scheduler.h:396
@ L4_SCHEDULER_RUN_THREAD_OP
Run a thread on this scheduler.
Definition scheduler.h:265
@ L4_SCHEDULER_IDLE_TIME_OP
Query idle time for the scheduler.
Definition scheduler.h:266
@ L4_SCHEDULER_INFO_OP
Query infos about the scheduler.
Definition scheduler.h:264
@ L4_SCHEDULER_CLASS_WFQ
Weighted fair queuing scheduler.
Definition scheduler.h:62
@ L4_SCHEDULER_CLASS_FIXED_PRIO
Fixed-priority scheduler.
Definition scheduler.h:60
unsigned l4_utcb_mr64_idx(unsigned idx) L4_NOTHROW
Get index into 64bit message registers alias from native-sized index.
Definition utcb.h:386
#define L4_IPC_NEVER
never timeout
Definition __timeout.h:82
struct l4_utcb_t l4_utcb_t
Opaque type for the UTCB.
Definition utcb.h:67
l4_utcb_t * l4_utcb(void) L4_NOTHROW L4_PURE
Get the UTCB address.
Definition utcb.h:340
#define L4_NOTHROW
Mark a function declaration and definition as never throwing an exception.
Definition compiler.h:188
#define L4_INLINE
L4 Inline function attribute.
Definition compiler.h:62
Kernel object system calls.
Message tag data structure.
Definition types.h:163
unsigned offset() const
Definition scheduler.h:94
void set(unsigned char granularity, unsigned offset)
Set offset and granularity.
Definition scheduler.h:101
l4_umword_t gran_offset
Combination of granularity and offset.
Definition scheduler.h:83
l4_umword_t map
Bitmap of CPUs.
Definition scheduler.h:88
unsigned char granularity() const
Definition scheduler.h:92
Scheduler parameter set.
Definition scheduler.h:180
l4_sched_cpu_set_t affinity
CPU affinity.
Definition scheduler.h:181
l4_umword_t prio
Priority for scheduling.
Definition scheduler.h:182
l4_umword_t quantum
Timeslice in micro seconds.
Definition scheduler.h:183
l4_umword_t raw
Raw value.
Definition __l4_fpage.h:87
Encapsulation of the message-register block in the UTCB.
Definition utcb.h:79
l4_umword_t mr[L4_UTCB_GENERIC_DATA_SIZE]
Message registers.
Definition utcb.h:80
l4_uint64_t mr64[L4_UTCB_GENERIC_DATA_SIZE/(sizeof(l4_uint64_t)/sizeof(l4_umword_t))]
Message registers 64bit alias.
Definition utcb.h:81