L4Re - L4 Runtime Environment
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 
25 #include <l4/sys/kernel_object.h>
26 #include <l4/sys/ipc.h>
27 
44 typedef struct l4_sched_cpu_set_t
45 {
59 
64 
65 #ifdef __cplusplus
66  unsigned char granularity() const { return gran_offset >> 24; }
69  unsigned offset() const { return gran_offset & 0x00ffffff; }
71  void set(unsigned char granularity, unsigned offset)
72  { gran_offset = ((l4_umword_t)granularity << 24) | (offset & 0x00ffffff); }
73 #endif
75 
86 L4_INLINE l4_sched_cpu_set_t
88  l4_umword_t map L4_DEFAULT_PARAM(1)) L4_NOTHROW;
89 
104 L4_INLINE l4_msgtag_t
105 l4_scheduler_info(l4_cap_idx_t scheduler, l4_umword_t *cpu_max,
107 
111 L4_INLINE l4_msgtag_t
112 l4_scheduler_info_u(l4_cap_idx_t scheduler, l4_umword_t *cpu_max,
114 
115 
120 typedef struct l4_sched_param_t
121 {
126 
131 L4_INLINE l4_sched_param_t
132 l4_sched_param(unsigned prio,
133  l4_cpu_time_t quantum L4_DEFAULT_PARAM(0)) L4_NOTHROW;
134 
142 L4_INLINE l4_msgtag_t
144  l4_cap_idx_t thread, l4_sched_param_t const *sp) L4_NOTHROW;
145 
149 L4_INLINE l4_msgtag_t
150 l4_scheduler_run_thread_u(l4_cap_idx_t scheduler, l4_cap_idx_t thread,
151  l4_sched_param_t const *sp, l4_utcb_t *utcb) L4_NOTHROW;
152 
160 L4_INLINE l4_msgtag_t
162  l4_kernel_clock_t *us) L4_NOTHROW;
163 
167 L4_INLINE l4_msgtag_t
168 l4_scheduler_idle_time_u(l4_cap_idx_t scheduler, l4_sched_cpu_set_t const *cpus,
169  l4_kernel_clock_t *us, l4_utcb_t *utcb) L4_NOTHROW;
170 
171 
172 
183 L4_INLINE int
184 l4_scheduler_is_online(l4_cap_idx_t scheduler, l4_umword_t cpu) L4_NOTHROW;
185 
189 L4_INLINE int
190 l4_scheduler_is_online_u(l4_cap_idx_t scheduler, l4_umword_t cpu,
191  l4_utcb_t *utcb) L4_NOTHROW;
192 
193 
194 
202 {
206 };
207 
208 /*************** Implementations *******************/
209 
210 L4_INLINE l4_sched_cpu_set_t
213 {
215  cs.gran_offset = ((l4_umword_t)granularity << 24) | offset;
216  cs.map = map;
217  return cs;
218 }
219 
220 L4_INLINE l4_sched_param_t
221 l4_sched_param(unsigned prio, l4_cpu_time_t quantum) L4_NOTHROW
222 {
223  l4_sched_param_t sp;
224  sp.prio = prio;
225  sp.quantum = quantum;
226  sp.affinity = l4_sched_cpu_set(0, ~0, 1);
227  return sp;
228 }
229 
230 
231 L4_INLINE l4_msgtag_t
232 l4_scheduler_info_u(l4_cap_idx_t scheduler, l4_umword_t *cpu_max,
234 {
235  l4_msg_regs_t *m = l4_utcb_mr_u(utcb);
236  l4_msgtag_t res;
237 
238  m->mr[0] = L4_SCHEDULER_INFO_OP;
239  m->mr[1] = cpus->gran_offset;
240 
241  res = l4_ipc_call(scheduler, utcb, l4_msgtag(L4_PROTO_SCHEDULER, 2, 0, 0), L4_IPC_NEVER);
242 
243  if (l4_msgtag_has_error(res))
244  return res;
245 
246  cpus->map = m->mr[0];
247 
248  if (cpu_max)
249  *cpu_max = m->mr[1];
250 
251  return res;
252 }
253 
254 L4_INLINE l4_msgtag_t
255 l4_scheduler_run_thread_u(l4_cap_idx_t scheduler, l4_cap_idx_t thread,
256  l4_sched_param_t const *sp, l4_utcb_t *utcb) L4_NOTHROW
257 {
258  l4_msg_regs_t *m = l4_utcb_mr_u(utcb);
260  m->mr[1] = sp->affinity.gran_offset;
261  m->mr[2] = sp->affinity.map;
262  m->mr[3] = sp->prio;
263  m->mr[4] = sp->quantum;
264  m->mr[5] = l4_map_obj_control(0, 0);
265  m->mr[6] = l4_obj_fpage(thread, 0, L4_FPAGE_RWX).raw;
266 
267  return l4_ipc_call(scheduler, utcb, l4_msgtag(L4_PROTO_SCHEDULER, 5, 1, 0), L4_IPC_NEVER);
268 }
269 
270 L4_INLINE l4_msgtag_t
271 l4_scheduler_idle_time_u(l4_cap_idx_t scheduler, l4_sched_cpu_set_t const *cpus,
273 {
274  l4_msg_regs_t *v = l4_utcb_mr_u(utcb);
275  l4_msgtag_t res;
276 
278  v->mr[1] = cpus->gran_offset;
279  v->mr[2] = cpus->map;
280 
281  res = l4_ipc_call(scheduler, utcb,
283 
284  if (l4_msgtag_has_error(res))
285  return res;
286 
287  *us = v->mr64[l4_utcb_mr64_idx(0)];
288 
289  return res;
290 }
291 
292 
293 L4_INLINE int
294 l4_scheduler_is_online_u(l4_cap_idx_t scheduler, l4_umword_t cpu,
295  l4_utcb_t *utcb) L4_NOTHROW
296 {
298  l4_msgtag_t r;
299  s.gran_offset = cpu;
300  r = l4_scheduler_info_u(scheduler, NULL, &s, utcb);
301  if (l4_msgtag_has_error(r) || l4_msgtag_label(r) < 0)
302  return 0;
303 
304  return s.map & 1;
305 }
306 
307 
308 L4_INLINE l4_msgtag_t
311 {
312  return l4_scheduler_info_u(scheduler, cpu_max, cpus, l4_utcb());
313 }
314 
315 L4_INLINE l4_msgtag_t
317  l4_cap_idx_t thread, l4_sched_param_t const *sp) L4_NOTHROW
318 {
319  return l4_scheduler_run_thread_u(scheduler, thread, sp, l4_utcb());
320 }
321 
322 L4_INLINE l4_msgtag_t
325 {
326  return l4_scheduler_idle_time_u(scheduler, cpus, us, l4_utcb());
327 }
328 
329 L4_INLINE int
331 {
332  return l4_scheduler_is_online_u(scheduler, cpu, l4_utcb());
333 }
Encapsulation of the message-register block in the UTCB.
Definition: utcb.h:78
Run a thread on this scheduler.
Definition: scheduler.h:204
l4_umword_t gran_offset
Combination of granularity and offset.
Definition: scheduler.h:58
unsigned l4_utcb_mr64_idx(unsigned idx) L4_NOTHROW
Get index into 64bit message registers alias from native-sized index.
Definition: utcb.h:386
l4_umword_t prio
Priority for scheduling.
Definition: scheduler.h:123
unsigned l4_msgtag_has_error(l4_msgtag_t t) L4_NOTHROW
Test for error indicator flag.
Definition: types.h:437
unsigned offset() const
Definition: scheduler.h:69
l4_umword_t mr[L4_UTCB_GENERIC_DATA_SIZE]
Message registers.
Definition: utcb.h:80
Read-write-execute flex page.
Definition: __l4_fpage.h:114
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:445
Scheduler parameter set.
Definition: scheduler.h:120
l4_umword_t map
Bitmap of CPUs.
Definition: scheduler.h:63
unsigned long l4_cap_idx_t
L4 Capability selector Type.
Definition: types.h:342
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:211
struct l4_utcb_t l4_utcb_t
Opaque type for the UTCB.
Definition: utcb.h:67
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:323
#define L4_IPC_NEVER
never timeout
Definition: __timeout.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
long l4_msgtag_label(l4_msgtag_t t) L4_NOTHROW
Get the protocol of tag.
Definition: types.h:420
unsigned char granularity() const
Definition: scheduler.h:67
Query idle time for the scheduler.
Definition: scheduler.h:205
l4_sched_param_t l4_sched_param(unsigned prio, l4_cpu_time_t quantum=0) L4_NOTHROW
Construct scheduler parameter.
Definition: scheduler.h:221
Query infos about the scheduler.
Definition: scheduler.h:203
l4_uint64_t l4_cpu_time_t
CPU clock type.
Definition: l4int.h:59
unsigned long l4_umword_t
Unsigned machine word.
Definition: l4int.h:52
l4_uint64_t l4_kernel_clock_t
Kernel clock type.
Definition: l4int.h:65
l4_umword_t raw
Raw value.
Definition: __l4_fpage.h:83
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:330
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:679
l4_utcb_t * l4_utcb(void) L4_NOTHROW L4_PURE
Get the UTCB address.
Definition: utcb.h:340
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:408
struct l4_sched_cpu_set_t l4_sched_cpu_set_t
CPU sets.
l4_sched_cpu_set_t affinity
CPU affinity.
Definition: scheduler.h:122
l4_umword_t quantum
Timeslice in micro seconds.
Definition: scheduler.h:124
Kernel object system calls.
Protocol for messages to a scheduler object.
Definition: types.h:66
struct l4_sched_param_t l4_sched_param_t
Scheduler parameter set.
L4_scheduler_ops
Operations on the Scheduler object.
Definition: scheduler.h:201
Message tag data structure.
Definition: types.h:159
CPU sets.
Definition: scheduler.h:44
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:316
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:309
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:645
#define L4_NOTHROW
Mark a function declaration and definition as never throwing an exception.
Definition: compiler.h:185