L4Re Operating System Framework
Interface and Usage Documentation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 * License: see LICENSE.spdx (in this directory or the directories above)
11 */
12#pragma once
13
15#include <l4/sys/ipc.h>
16
53
58typedef struct l4_sched_cpu_set_t
59{
73
78
79#ifdef __cplusplus
81 unsigned char granularity() const { return gran_offset >> 24; }
83 unsigned offset() const { return gran_offset & 0x00ffffff; }
90 void set(unsigned char granularity, unsigned offset)
91 {
92 gran_offset = (static_cast<l4_umword_t>(granularity) << 24)
93 | (offset & 0x00ffffff);
94 }
95#endif
97
109l4_sched_cpu_set(l4_umword_t offset, unsigned char granularity,
110 l4_umword_t map L4_DEFAULT_PARAM(1)) L4_NOTHROW;
111
129l4_scheduler_info(l4_cap_idx_t scheduler, l4_umword_t *cpu_max,
130 l4_sched_cpu_set_t *cpus)
131 L4_NOTHROW __attribute__((nonnull (3)));
132
156 l4_sched_cpu_set_t *cpus,
157 l4_umword_t *sched_classes)
158 L4_NOTHROW __attribute__((nonnull (3)));
159
164l4_scheduler_info_u(l4_cap_idx_t scheduler, l4_umword_t *cpu_max,
165 l4_sched_cpu_set_t *cpus, l4_umword_t *sched_classes,
166 l4_utcb_t *utcb) L4_NOTHROW __attribute__((nonnull (3, 5)));
167
168
186
196l4_sched_param(unsigned prio,
197 l4_umword_t quantum L4_DEFAULT_PARAM(0)) L4_NOTHROW;
198
208 l4_cap_idx_t thread, l4_sched_param_t const *sp)
209 L4_NOTHROW __attribute__((nonnull));
210
215l4_scheduler_run_thread_u(l4_cap_idx_t scheduler, l4_cap_idx_t thread,
216 l4_sched_param_t const *sp, l4_utcb_t *utcb)
217 L4_NOTHROW __attribute__((nonnull));
218
229 L4_NOTHROW __attribute__((nonnull));
230
235l4_scheduler_idle_time_u(l4_cap_idx_t scheduler, l4_sched_cpu_set_t const *cpus,
236 l4_kernel_clock_t *us, l4_utcb_t *utcb)
237 L4_NOTHROW __attribute__((nonnull));
238
239
240
251L4_INLINE int
253
257L4_INLINE int
258l4_scheduler_is_online_u(l4_cap_idx_t scheduler, l4_umword_t cpu,
259 l4_utcb_t *utcb) L4_NOTHROW __attribute__((nonnull));
260
261
262
275
276/*************** Implementations *******************/
277
279l4_sched_cpu_set(l4_umword_t offset, unsigned char granularity,
281{
283 cs.gran_offset = ((l4_umword_t)granularity << 24) | (offset & 0x00ffffff);
284 cs.map = map;
285 return cs;
286}
287
289l4_sched_param(unsigned prio, l4_umword_t quantum) L4_NOTHROW
290{
292 sp.prio = prio;
293 sp.quantum = quantum;
294 sp.affinity = l4_sched_cpu_set(0, ~0, 1);
295 return sp;
296}
297
298
300l4_scheduler_info_u(l4_cap_idx_t scheduler, l4_umword_t *cpu_max,
301 l4_sched_cpu_set_t *cpus, l4_umword_t *sched_classes,
302 l4_utcb_t *utcb) L4_NOTHROW
303{
304 l4_msg_regs_t *m = l4_utcb_mr_u(utcb);
305 l4_msgtag_t res;
306
307 m->mr[0] = L4_SCHEDULER_INFO_OP;
308 m->mr[1] = cpus->gran_offset;
309
310 res = l4_ipc_call(scheduler, utcb, l4_msgtag(L4_PROTO_SCHEDULER, 2, 0, 0), L4_IPC_NEVER);
311
312 if (l4_msgtag_has_error(res))
313 return res;
314
315 cpus->map = m->mr[0];
316
317 if (cpu_max)
318 *cpu_max = m->mr[1];
319
320 if (sched_classes)
321 *sched_classes = m->mr[2];
322
323 return res;
324}
325
327l4_scheduler_run_thread_u(l4_cap_idx_t scheduler, l4_cap_idx_t thread,
328 l4_sched_param_t const *sp, l4_utcb_t *utcb) L4_NOTHROW
329{
330 l4_msg_regs_t *m = l4_utcb_mr_u(utcb);
332 m->mr[1] = sp->affinity.gran_offset;
333 m->mr[2] = sp->affinity.map;
334 m->mr[3] = sp->prio;
335 m->mr[4] = sp->quantum;
336 m->mr[5] = l4_map_obj_control(0, 0);
337 m->mr[6] = l4_obj_fpage(thread, 0, L4_CAP_FPAGE_RWS).raw;
338
339 return l4_ipc_call(scheduler, utcb, l4_msgtag(L4_PROTO_SCHEDULER, 5, 1, 0), L4_IPC_NEVER);
340}
341
343l4_scheduler_idle_time_u(l4_cap_idx_t scheduler, l4_sched_cpu_set_t const *cpus,
345{
346 l4_msg_regs_t *v = l4_utcb_mr_u(utcb);
347 l4_msgtag_t res;
348
350 v->mr[1] = cpus->gran_offset;
351 v->mr[2] = cpus->map;
352
353 res = l4_ipc_call(scheduler, utcb,
355
356 if (l4_msgtag_has_error(res))
357 return res;
358
359 *us = v->mr64[l4_utcb_mr64_idx(0)];
360
361 return res;
362}
363
364
365L4_INLINE int
366l4_scheduler_is_online_u(l4_cap_idx_t scheduler, l4_umword_t cpu,
367 l4_utcb_t *utcb) L4_NOTHROW
368{
370 l4_msgtag_t r;
371 s.gran_offset = cpu;
372 r = l4_scheduler_info_u(scheduler, NULL, &s, NULL, utcb);
373 if (l4_msgtag_has_error(r) || l4_msgtag_label(r) < 0)
374 return 0;
375
376 return s.map & 1;
377}
378
379
383{
384 return l4_scheduler_info_u(scheduler, cpu_max, cpus, NULL, l4_utcb());
385}
386
389 l4_sched_cpu_set_t *cpus,
390 l4_umword_t *sched_classes) L4_NOTHROW
391{
392 return l4_scheduler_info_u(scheduler, cpu_max, cpus, sched_classes, l4_utcb());
393}
394
397 l4_cap_idx_t thread, l4_sched_param_t const *sp) L4_NOTHROW
398{
399 return l4_scheduler_run_thread_u(scheduler, thread, sp, l4_utcb());
400}
401
405{
406 return l4_scheduler_idle_time_u(scheduler, cpus, us, l4_utcb());
407}
408
409L4_INLINE int
411{
412 return l4_scheduler_is_online_u(scheduler, cpu, l4_utcb());
413}
unsigned long l4_umword_t
Unsigned machine word.
Definition l4int.h:40
l4_uint64_t l4_kernel_clock_t
Kernel clock type.
Definition l4int.h:53
unsigned long l4_cap_idx_t
Capability selector type.
Definition types.h:335
l4_fpage_t l4_obj_fpage(l4_cap_idx_t obj, unsigned int order, unsigned char rights) L4_NOTHROW
Create a kernel-object flexpage.
Definition __l4_fpage.h:696
@ L4_CAP_FPAGE_RWS
Read, interface specific 'W', and 'S' rights for capability flexpages.
Definition __l4_fpage.h:206
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:565
l4_umword_t l4_map_obj_control(l4_umword_t spot, unsigned grant) L4_NOTHROW
Create the first word for a map item that is a send item for the object space.
Definition __l4_fpage.h:730
unsigned l4_msgtag_has_error(l4_msgtag_t t) L4_NOTHROW
Test for error indicator flag.
Definition types.h:439
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:404
long l4_msgtag_label(l4_msgtag_t t) L4_NOTHROW
Get the protocol of tag.
Definition types.h:416
@ L4_PROTO_SCHEDULER
Protocol for messages to a scheduler object.
Definition types.h:55
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:410
L4_scheduler_ops
Operations on the Scheduler object.
Definition scheduler.h:270
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:279
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:396
L4_scheduler_classes
Supported scheduler classes.
Definition scheduler.h:47
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:381
l4_sched_param_t l4_sched_param(unsigned prio, l4_umword_t quantum=0) L4_NOTHROW
Construct scheduler parameter.
Definition scheduler.h:289
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:388
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:403
@ L4_SCHEDULER_RUN_THREAD_OP
Run a thread on this scheduler.
Definition scheduler.h:272
@ L4_SCHEDULER_IDLE_TIME_OP
Query idle time for the scheduler.
Definition scheduler.h:273
@ L4_SCHEDULER_INFO_OP
Query infos about the scheduler.
Definition scheduler.h:271
@ L4_SCHEDULER_CLASS_WFQ
Weighted fair queuing scheduler.
Definition scheduler.h:51
@ L4_SCHEDULER_CLASS_FIXED_PRIO
Fixed-priority scheduler.
Definition scheduler.h:49
unsigned l4_utcb_mr64_idx(unsigned idx) L4_NOTHROW
Get index into 64bit message registers alias from native-sized index.
Definition utcb.h:392
#define L4_IPC_NEVER
never timeout
Definition __timeout.h:76
struct l4_utcb_t l4_utcb_t
Opaque type for the UTCB.
Definition utcb.h:56
l4_utcb_t * l4_utcb(void) L4_NOTHROW L4_PURE
Get the UTCB address.
Definition utcb.h:346
#define L4_NOTHROW
Mark a function declaration and definition as never throwing an exception.
Definition compiler.h:159
#define L4_INLINE
L4 Inline function attribute.
Definition compiler.h:51
Kernel object system calls.
Message tag data structure.
Definition types.h:153
unsigned offset() const
Definition scheduler.h:83
void set(unsigned char granularity, unsigned offset)
Set offset and granularity.
Definition scheduler.h:90
l4_umword_t gran_offset
Combination of granularity and offset.
Definition scheduler.h:72
l4_umword_t map
Bitmap of CPUs.
Definition scheduler.h:77
unsigned char granularity() const
Definition scheduler.h:81
Scheduler parameter set.
Definition scheduler.h:174
l4_sched_cpu_set_t affinity
CPU affinity.
Definition scheduler.h:176
l4_umword_t prio
Priority for scheduling.
Definition scheduler.h:182
l4_umword_t quantum
Timeslice in micro seconds.
Definition scheduler.h:184
l4_umword_t raw
Raw value.
Definition __l4_fpage.h:78
Encapsulation of the message-register block in the UTCB.
Definition utcb.h:68
l4_umword_t mr[L4_UTCB_GENERIC_DATA_SIZE]
Message registers.
Definition utcb.h:69
l4_uint64_t mr64[L4_UTCB_GENERIC_DATA_SIZE/(sizeof(l4_uint64_t)/sizeof(l4_umword_t))]
Message registers 64bit alias.
Definition utcb.h:70