Loading...
Searching...
No Matches
scheduler.h
Go to the documentation of this file.
/*
* (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
* Alexander Warg <warg@os.inf.tu-dresden.de>
* economic rights: Technische Universität Dresden (Germany)
*
* License: see LICENSE.spdx (in this directory or the directories above)
*/
#pragma once
#include <l4/sys/kernel_object.h>
#include <l4/sys/ipc.h>
enum L4_scheduler_classes
{
L4_SCHEDULER_CLASS_FIXED_PRIO = 1UL << 1,
L4_SCHEDULER_CLASS_WFQ = 1UL << 2,
};
typedef struct l4_sched_cpu_set_t
{
l4_umword_t gran_offset;
l4_umword_t map;
#ifdef __cplusplus
unsigned char granularity() const { return gran_offset >> 24; }
unsigned offset() const { return gran_offset & 0x00ffffff; }
void set(unsigned char granularity, unsigned offset)
{
gran_offset = (static_cast< l4_umword_t >(granularity) << 24)
| (offset & 0x00ffffff);
}
#endif
} l4_sched_cpu_set_t;
L4_INLINE l4_sched_cpu_set_t
l4_sched_cpu_set(l4_umword_t offset, unsigned char granularity,
l4_umword_t map L4_DEFAULT_PARAM(1)) L4_NOTHROW;
L4_INLINE l4_msgtag_t
l4_scheduler_info(l4_cap_idx_t scheduler, l4_umword_t *cpu_max,
l4_sched_cpu_set_t *cpus)
L4_NOTHROW __attribute__((nonnull (3)));
L4_INLINE 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 __attribute__((nonnull (3)));
L4_INLINE l4_msgtag_t
l4_scheduler_info_u(l4_cap_idx_t scheduler, l4_umword_t *cpu_max,
l4_sched_cpu_set_t *cpus, l4_umword_t *sched_classes,
l4_utcb_t *utcb) L4_NOTHROW __attribute__((nonnull (3, 5)));
typedef struct l4_sched_param_t
{
l4_sched_cpu_set_t affinity;
l4_umword_t prio;
l4_umword_t quantum;
} l4_sched_param_t;
L4_INLINE l4_sched_param_t
l4_sched_param(unsigned prio,
l4_umword_t quantum L4_DEFAULT_PARAM(0)) L4_NOTHROW;
L4_INLINE 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 __attribute__((nonnull));
L4_INLINE l4_msgtag_t
l4_scheduler_run_thread_u(l4_cap_idx_t scheduler, l4_cap_idx_t thread,
l4_sched_param_t const *sp, l4_utcb_t *utcb)
L4_NOTHROW __attribute__((nonnull));
L4_INLINE 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 __attribute__((nonnull));
L4_INLINE l4_msgtag_t
l4_scheduler_idle_time_u(l4_cap_idx_t scheduler, l4_sched_cpu_set_t const *cpus,
l4_kernel_clock_t *us, l4_utcb_t *utcb)
L4_NOTHROW __attribute__((nonnull));
L4_INLINE int
l4_scheduler_is_online(l4_cap_idx_t scheduler, l4_umword_t cpu) L4_NOTHROW;
L4_INLINE int
l4_scheduler_is_online_u(l4_cap_idx_t scheduler, l4_umword_t cpu,
l4_utcb_t *utcb) L4_NOTHROW __attribute__((nonnull));
enum L4_scheduler_ops
{
L4_SCHEDULER_INFO_OP = 0UL,
L4_SCHEDULER_RUN_THREAD_OP = 1UL,
L4_SCHEDULER_IDLE_TIME_OP = 2UL,
};
/*************** Implementations *******************/
L4_INLINE l4_sched_cpu_set_t
l4_sched_cpu_set(l4_umword_t offset, unsigned char granularity,
l4_umword_t map) L4_NOTHROW
{
l4_sched_cpu_set_t cs;
cs.gran_offset = ((l4_umword_t)granularity << 24) | (offset & 0x00ffffff);
cs.map = map;
return cs;
}
L4_INLINE l4_sched_param_t
l4_sched_param(unsigned prio, l4_umword_t quantum) L4_NOTHROW
{
l4_sched_param_t sp;
sp.prio = prio;
sp.quantum = quantum;
sp.affinity = l4_sched_cpu_set(0, ~0, 1);
return sp;
}
L4_INLINE l4_msgtag_t
l4_scheduler_info_u(l4_cap_idx_t scheduler, l4_umword_t *cpu_max,
l4_sched_cpu_set_t *cpus, l4_umword_t *sched_classes,
l4_utcb_t *utcb) L4_NOTHROW
{
l4_msg_regs_t *m = l4_utcb_mr_u(utcb);
l4_msgtag_t res;
m->mr[0] = L4_SCHEDULER_INFO_OP;
m->mr[1] = cpus->gran_offset;
res = l4_ipc_call(scheduler, utcb, l4_msgtag(L4_PROTO_SCHEDULER, 2, 0, 0), L4_IPC_NEVER);
if (l4_msgtag_has_error(res))
return res;
cpus->map = m->mr[0];
if (cpu_max)
*cpu_max = m->mr[1];
if (sched_classes)
*sched_classes = m->mr[2];
return res;
}
L4_INLINE l4_msgtag_t
l4_scheduler_run_thread_u(l4_cap_idx_t scheduler, l4_cap_idx_t thread,
l4_sched_param_t const *sp, l4_utcb_t *utcb) L4_NOTHROW
{
l4_msg_regs_t *m = l4_utcb_mr_u(utcb);
m->mr[0] = L4_SCHEDULER_RUN_THREAD_OP;
m->mr[1] = sp->affinity.gran_offset;
m->mr[2] = sp->affinity.map;
m->mr[3] = sp->prio;
m->mr[4] = sp->quantum;
m->mr[5] = l4_map_obj_control(0, 0);
m->mr[6] = l4_obj_fpage(thread, 0, L4_CAP_FPAGE_RWS).raw;
return l4_ipc_call(scheduler, utcb, l4_msgtag(L4_PROTO_SCHEDULER, 5, 1, 0), L4_IPC_NEVER);
}
L4_INLINE l4_msgtag_t
l4_scheduler_idle_time_u(l4_cap_idx_t scheduler, l4_sched_cpu_set_t const *cpus,
l4_kernel_clock_t *us, l4_utcb_t *utcb) L4_NOTHROW
{
l4_msg_regs_t *v = l4_utcb_mr_u(utcb);
l4_msgtag_t res;
v->mr[0] = L4_SCHEDULER_IDLE_TIME_OP;
v->mr[1] = cpus->gran_offset;
v->mr[2] = cpus->map;
res = l4_ipc_call(scheduler, utcb,
l4_msgtag(L4_PROTO_SCHEDULER, 3, 0, 0), L4_IPC_NEVER);
if (l4_msgtag_has_error(res))
return res;
*us = v->mr64[l4_utcb_mr64_idx(0)];
return res;
}
L4_INLINE int
l4_scheduler_is_online_u(l4_cap_idx_t scheduler, l4_umword_t cpu,
l4_utcb_t *utcb) L4_NOTHROW
{
l4_sched_cpu_set_t s;
l4_msgtag_t r;
s.gran_offset = cpu;
r = l4_scheduler_info_u(scheduler, NULL, &s, NULL, utcb);
if (l4_msgtag_has_error(r) || l4_msgtag_label(r) < 0)
return 0;
return s.map & 1;
}
L4_INLINE l4_msgtag_t
l4_scheduler_info(l4_cap_idx_t scheduler, l4_umword_t *cpu_max,
l4_sched_cpu_set_t *cpus) L4_NOTHROW
{
return l4_scheduler_info_u(scheduler, cpu_max, cpus, NULL, l4_utcb());
}
L4_INLINE 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
{
return l4_scheduler_info_u(scheduler, cpu_max, cpus, sched_classes, l4_utcb());
}
L4_INLINE 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
{
return l4_scheduler_run_thread_u(scheduler, thread, sp, l4_utcb());
}
L4_INLINE 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
{
return l4_scheduler_idle_time_u(scheduler, cpus, us, l4_utcb());
}
L4_INLINE int
l4_scheduler_is_online(l4_cap_idx_t scheduler, l4_umword_t cpu) L4_NOTHROW
{
return l4_scheduler_is_online_u(scheduler, cpu, l4_utcb());
}
l4_umword_t
unsigned long l4_umword_t
Unsigned machine word.
Definition l4int.h:40
l4_kernel_clock_t
l4_uint64_t l4_kernel_clock_t
Kernel clock type.
Definition l4int.h:53
l4_cap_idx_t
unsigned long l4_cap_idx_t
Capability selector type.
Definition types.h:336
l4_obj_fpage
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:715
L4_CAP_FPAGE_RWS
@ L4_CAP_FPAGE_RWS
Read, interface specific 'W', and 'S' rights for capability flexpages.
Definition __l4_fpage.h:206
l4_ipc_call
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_map_obj_control
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:749
l4_msgtag_has_error
unsigned l4_msgtag_has_error(l4_msgtag_t t) L4_NOTHROW
Test for error indicator flag.
Definition types.h:440
l4_msgtag
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:405
l4_msgtag_label
long l4_msgtag_label(l4_msgtag_t t) L4_NOTHROW
Get the protocol of tag.
Definition types.h:417
L4_PROTO_SCHEDULER
@ L4_PROTO_SCHEDULER
Protocol for messages to a scheduler object.
Definition types.h:56
l4_scheduler_is_online
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
L4_scheduler_ops
Operations on the Scheduler object.
Definition scheduler.h:270
l4_sched_cpu_set
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_scheduler_run_thread
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
L4_scheduler_classes
Supported scheduler classes.
Definition scheduler.h:47
l4_scheduler_info
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
l4_sched_param_t l4_sched_param(unsigned prio, l4_umword_t quantum=0) L4_NOTHROW
Construct scheduler parameter.
Definition scheduler.h:289
l4_scheduler_info_with_classes
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_scheduler_idle_time
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
@ L4_SCHEDULER_RUN_THREAD_OP
Run a thread on this scheduler.
Definition scheduler.h:272
L4_SCHEDULER_IDLE_TIME_OP
@ L4_SCHEDULER_IDLE_TIME_OP
Query idle time for the scheduler.
Definition scheduler.h:273
L4_SCHEDULER_INFO_OP
@ L4_SCHEDULER_INFO_OP
Query infos about the scheduler.
Definition scheduler.h:271
L4_SCHEDULER_CLASS_WFQ
@ L4_SCHEDULER_CLASS_WFQ
Weighted fair queuing scheduler.
Definition scheduler.h:51
L4_SCHEDULER_CLASS_FIXED_PRIO
@ L4_SCHEDULER_CLASS_FIXED_PRIO
Fixed-priority scheduler.
Definition scheduler.h:49
l4_utcb_mr64_idx
unsigned l4_utcb_mr64_idx(unsigned idx) L4_NOTHROW
Get index into 64bit message registers alias from native-sized index.
Definition utcb.h:392
L4_IPC_NEVER
#define L4_IPC_NEVER
never timeout
Definition __timeout.h:76
l4_utcb_t
struct l4_utcb_t l4_utcb_t
Opaque type for the UTCB.
Definition utcb.h:56
l4_utcb
l4_utcb_t * l4_utcb(void) L4_NOTHROW L4_PURE
Get the UTCB address.
Definition utcb.h:346
L4_NOTHROW
#define L4_NOTHROW
Mark a function declaration and definition as never throwing an exception.
Definition compiler.h:161
L4_INLINE
#define L4_INLINE
L4 Inline function attribute.
Definition compiler.h:51
kernel_object.h
Kernel object system calls.
ipc.h
Common IPC interface.
l4_msgtag_t
Message tag data structure.
Definition types.h:154
l4_sched_cpu_set_t
CPU sets.
Definition scheduler.h:59
l4_sched_cpu_set_t::offset
unsigned offset() const
Definition scheduler.h:83
l4_sched_cpu_set_t::set
void set(unsigned char granularity, unsigned offset)
Set offset and granularity.
Definition scheduler.h:90
l4_sched_cpu_set_t::gran_offset
l4_umword_t gran_offset
Combination of granularity and offset.
Definition scheduler.h:72
l4_sched_cpu_set_t::map
l4_umword_t map
Bitmap of CPUs.
Definition scheduler.h:77
l4_sched_cpu_set_t::granularity
unsigned char granularity() const
Definition scheduler.h:81
l4_sched_param_t
Scheduler parameter set.
Definition scheduler.h:174
l4_sched_param_t::affinity
l4_sched_cpu_set_t affinity
CPU affinity.
Definition scheduler.h:176
l4_sched_param_t::prio
l4_umword_t prio
Priority for scheduling.
Definition scheduler.h:182
l4_sched_param_t::quantum
l4_umword_t quantum
Timeslice in micro seconds.
Definition scheduler.h:184
l4_fpage_t::raw
l4_umword_t raw
Raw value.
Definition __l4_fpage.h:78
l4_msg_regs_t
Encapsulation of the message-register block in the UTCB.
Definition utcb.h:68
l4_msg_regs_t::mr
l4_umword_t mr[L4_UTCB_GENERIC_DATA_SIZE]
Message registers.
Definition utcb.h:69
l4_msg_regs_t::mr64
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