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 {
103 gran_offset = (static_cast<l4_umword_t>(granularity) << 24)
104 | (offset & 0x00ffffff);
105 }
106#endif
108
120l4_sched_cpu_set(l4_umword_t offset, unsigned char granularity,
121 l4_umword_t map L4_DEFAULT_PARAM(1)) L4_NOTHROW;
122
140l4_scheduler_info(l4_cap_idx_t scheduler, l4_umword_t *cpu_max,
141 l4_sched_cpu_set_t *cpus)
142 L4_NOTHROW __attribute__((nonnull (3)));
143
167 l4_sched_cpu_set_t *cpus,
168 l4_umword_t *sched_classes)
169 L4_NOTHROW __attribute__((nonnull (3)));
170
175l4_scheduler_info_u(l4_cap_idx_t scheduler, l4_umword_t *cpu_max,
176 l4_sched_cpu_set_t *cpus, l4_umword_t *sched_classes,
177 l4_utcb_t *utcb) L4_NOTHROW __attribute__((nonnull (3, 5)));
178
179
190
198l4_sched_param(unsigned prio,
199 l4_umword_t quantum L4_DEFAULT_PARAM(0)) L4_NOTHROW;
200
210 l4_cap_idx_t thread, l4_sched_param_t const *sp)
211 L4_NOTHROW __attribute__((nonnull));
212
217l4_scheduler_run_thread_u(l4_cap_idx_t scheduler, l4_cap_idx_t thread,
218 l4_sched_param_t const *sp, l4_utcb_t *utcb)
219 L4_NOTHROW __attribute__((nonnull));
220
231 L4_NOTHROW __attribute__((nonnull));
232
237l4_scheduler_idle_time_u(l4_cap_idx_t scheduler, l4_sched_cpu_set_t const *cpus,
238 l4_kernel_clock_t *us, l4_utcb_t *utcb)
239 L4_NOTHROW __attribute__((nonnull));
240
241
242
253L4_INLINE int
255
259L4_INLINE int
260l4_scheduler_is_online_u(l4_cap_idx_t scheduler, l4_umword_t cpu,
261 l4_utcb_t *utcb) L4_NOTHROW __attribute__((nonnull));
262
263
264
277
278/*************** Implementations *******************/
279
281l4_sched_cpu_set(l4_umword_t offset, unsigned char granularity,
283{
285 cs.gran_offset = ((l4_umword_t)granularity << 24) | (offset & 0x00ffffff);
286 cs.map = map;
287 return cs;
288}
289
291l4_sched_param(unsigned prio, l4_umword_t quantum) L4_NOTHROW
292{
294 sp.prio = prio;
295 sp.quantum = quantum;
296 sp.affinity = l4_sched_cpu_set(0, ~0, 1);
297 return sp;
298}
299
300
302l4_scheduler_info_u(l4_cap_idx_t scheduler, l4_umword_t *cpu_max,
303 l4_sched_cpu_set_t *cpus, l4_umword_t *sched_classes,
304 l4_utcb_t *utcb) L4_NOTHROW
305{
306 l4_msg_regs_t *m = l4_utcb_mr_u(utcb);
307 l4_msgtag_t res;
308
309 m->mr[0] = L4_SCHEDULER_INFO_OP;
310 m->mr[1] = cpus->gran_offset;
311
312 res = l4_ipc_call(scheduler, utcb, l4_msgtag(L4_PROTO_SCHEDULER, 2, 0, 0), L4_IPC_NEVER);
313
314 if (l4_msgtag_has_error(res))
315 return res;
316
317 cpus->map = m->mr[0];
318
319 if (cpu_max)
320 *cpu_max = m->mr[1];
321
322 if (sched_classes)
323 *sched_classes = m->mr[2];
324
325 return res;
326}
327
329l4_scheduler_run_thread_u(l4_cap_idx_t scheduler, l4_cap_idx_t thread,
330 l4_sched_param_t const *sp, l4_utcb_t *utcb) L4_NOTHROW
331{
332 l4_msg_regs_t *m = l4_utcb_mr_u(utcb);
334 m->mr[1] = sp->affinity.gran_offset;
335 m->mr[2] = sp->affinity.map;
336 m->mr[3] = sp->prio;
337 m->mr[4] = sp->quantum;
338 m->mr[5] = l4_map_obj_control(0, 0);
339 m->mr[6] = l4_obj_fpage(thread, 0, L4_CAP_FPAGE_RWS).raw;
340
341 return l4_ipc_call(scheduler, utcb, l4_msgtag(L4_PROTO_SCHEDULER, 5, 1, 0), L4_IPC_NEVER);
342}
343
345l4_scheduler_idle_time_u(l4_cap_idx_t scheduler, l4_sched_cpu_set_t const *cpus,
347{
348 l4_msg_regs_t *v = l4_utcb_mr_u(utcb);
349 l4_msgtag_t res;
350
352 v->mr[1] = cpus->gran_offset;
353 v->mr[2] = cpus->map;
354
355 res = l4_ipc_call(scheduler, utcb,
357
358 if (l4_msgtag_has_error(res))
359 return res;
360
361 *us = v->mr64[l4_utcb_mr64_idx(0)];
362
363 return res;
364}
365
366
367L4_INLINE int
368l4_scheduler_is_online_u(l4_cap_idx_t scheduler, l4_umword_t cpu,
369 l4_utcb_t *utcb) L4_NOTHROW
370{
372 l4_msgtag_t r;
373 s.gran_offset = cpu;
374 r = l4_scheduler_info_u(scheduler, NULL, &s, NULL, utcb);
375 if (l4_msgtag_has_error(r) || l4_msgtag_label(r) < 0)
376 return 0;
377
378 return s.map & 1;
379}
380
381
385{
386 return l4_scheduler_info_u(scheduler, cpu_max, cpus, NULL, l4_utcb());
387}
388
391 l4_sched_cpu_set_t *cpus,
392 l4_umword_t *sched_classes) L4_NOTHROW
393{
394 return l4_scheduler_info_u(scheduler, cpu_max, cpus, sched_classes, l4_utcb());
395}
396
399 l4_cap_idx_t thread, l4_sched_param_t const *sp) L4_NOTHROW
400{
401 return l4_scheduler_run_thread_u(scheduler, thread, sp, l4_utcb());
402}
403
407{
408 return l4_scheduler_idle_time_u(scheduler, cpus, us, l4_utcb());
409}
410
411L4_INLINE int
413{
414 return l4_scheduler_is_online_u(scheduler, cpu, l4_utcb());
415}
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:359
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:576
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:457
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:428
long l4_msgtag_label(l4_msgtag_t t) L4_NOTHROW
Get the protocol of tag.
Definition types.h:440
@ 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:412
L4_scheduler_ops
Operations on the Scheduler object.
Definition scheduler.h:272
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:281
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:398
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:383
l4_sched_param_t l4_sched_param(unsigned prio, l4_umword_t quantum=0) L4_NOTHROW
Construct scheduler parameter.
Definition scheduler.h:291
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:390
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:405
@ L4_SCHEDULER_RUN_THREAD_OP
Run a thread on this scheduler.
Definition scheduler.h:274
@ L4_SCHEDULER_IDLE_TIME_OP
Query idle time for the scheduler.
Definition scheduler.h:275
@ L4_SCHEDULER_INFO_OP
Query infos about the scheduler.
Definition scheduler.h:273
@ 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:84
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:164
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:185
l4_sched_cpu_set_t affinity
CPU affinity.
Definition scheduler.h:186
l4_umword_t prio
Priority for scheduling.
Definition scheduler.h:187
l4_umword_t quantum
Timeslice in micro seconds.
Definition scheduler.h:188
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