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 {
58 
63 
64 #ifdef __cplusplus
65  unsigned char granularity() const { return gran_offset >> 24; }
68  unsigned offset() const { return gran_offset & 0x00ffffff; }
70  void set(unsigned char granularity, unsigned offset)
71  { gran_offset = ((l4_umword_t)granularity << 24) | (offset & 0x00ffffff); }
72 #endif
74 
85 L4_INLINE l4_sched_cpu_set_t
87  l4_umword_t map L4_DEFAULT_PARAM(1)) L4_NOTHROW;
88 
103 L4_INLINE l4_msgtag_t
104 l4_scheduler_info(l4_cap_idx_t scheduler, l4_umword_t *cpu_max,
106 
110 L4_INLINE l4_msgtag_t
111 l4_scheduler_info_u(l4_cap_idx_t scheduler, l4_umword_t *cpu_max,
113 
114 
119 typedef struct l4_sched_param_t
120 {
125 
130 L4_INLINE l4_sched_param_t
131 l4_sched_param(unsigned prio,
132  l4_cpu_time_t quantum L4_DEFAULT_PARAM(0)) L4_NOTHROW;
133 
141 L4_INLINE l4_msgtag_t
143  l4_cap_idx_t thread, l4_sched_param_t const *sp) L4_NOTHROW;
144 
148 L4_INLINE l4_msgtag_t
149 l4_scheduler_run_thread_u(l4_cap_idx_t scheduler, l4_cap_idx_t thread,
150  l4_sched_param_t const *sp, l4_utcb_t *utcb) L4_NOTHROW;
151 
159 L4_INLINE l4_msgtag_t
161  l4_kernel_clock_t *us) L4_NOTHROW;
162 
166 L4_INLINE l4_msgtag_t
167 l4_scheduler_idle_time_u(l4_cap_idx_t scheduler, l4_sched_cpu_set_t const *cpus,
168  l4_kernel_clock_t *us, l4_utcb_t *utcb) L4_NOTHROW;
169 
170 
171 
182 L4_INLINE int
183 l4_scheduler_is_online(l4_cap_idx_t scheduler, l4_umword_t cpu) L4_NOTHROW;
184 
188 L4_INLINE int
189 l4_scheduler_is_online_u(l4_cap_idx_t scheduler, l4_umword_t cpu,
190  l4_utcb_t *utcb) L4_NOTHROW;
191 
192 
193 
201 {
205 };
206 
207 /*************** Implementations *******************/
208 
209 L4_INLINE l4_sched_cpu_set_t
212 {
214  cs.gran_offset = ((l4_umword_t)granularity << 24) | offset;
215  cs.map = map;
216  return cs;
217 }
218 
219 L4_INLINE l4_sched_param_t
220 l4_sched_param(unsigned prio, l4_cpu_time_t quantum) L4_NOTHROW
221 {
222  l4_sched_param_t sp;
223  sp.prio = prio;
224  sp.quantum = quantum;
225  sp.affinity = l4_sched_cpu_set(0, ~0, 1);
226  return sp;
227 }
228 
229 
230 L4_INLINE l4_msgtag_t
231 l4_scheduler_info_u(l4_cap_idx_t scheduler, l4_umword_t *cpu_max,
233 {
234  l4_msg_regs_t *m = l4_utcb_mr_u(utcb);
235  l4_msgtag_t res;
236 
237  m->mr[0] = L4_SCHEDULER_INFO_OP;
238  m->mr[1] = cpus->gran_offset;
239 
240  res = l4_ipc_call(scheduler, utcb, l4_msgtag(L4_PROTO_SCHEDULER, 2, 0, 0), L4_IPC_NEVER);
241 
242  if (l4_msgtag_has_error(res))
243  return res;
244 
245  cpus->map = m->mr[0];
246 
247  if (cpu_max)
248  *cpu_max = m->mr[1];
249 
250  return res;
251 }
252 
253 L4_INLINE l4_msgtag_t
254 l4_scheduler_run_thread_u(l4_cap_idx_t scheduler, l4_cap_idx_t thread,
255  l4_sched_param_t const *sp, l4_utcb_t *utcb) L4_NOTHROW
256 {
257  l4_msg_regs_t *m = l4_utcb_mr_u(utcb);
259  m->mr[1] = sp->affinity.gran_offset;
260  m->mr[2] = sp->affinity.map;
261  m->mr[3] = sp->prio;
262  m->mr[4] = sp->quantum;
263  m->mr[5] = l4_map_obj_control(0, 0);
264  m->mr[6] = l4_obj_fpage(thread, 0, L4_FPAGE_RWX).raw;
265 
266  return l4_ipc_call(scheduler, utcb, l4_msgtag(L4_PROTO_SCHEDULER, 5, 1, 0), L4_IPC_NEVER);
267 }
268 
269 L4_INLINE l4_msgtag_t
270 l4_scheduler_idle_time_u(l4_cap_idx_t scheduler, l4_sched_cpu_set_t const *cpus,
272 {
273  l4_msg_regs_t *v = l4_utcb_mr_u(utcb);
274  l4_msgtag_t res;
275 
277  v->mr[1] = cpus->gran_offset;
278  v->mr[2] = cpus->map;
279 
280  res = l4_ipc_call(scheduler, utcb,
282 
283  if (l4_msgtag_has_error(res))
284  return res;
285 
286  *us = v->mr64[l4_utcb_mr64_idx(0)];
287 
288  return res;
289 }
290 
291 
292 L4_INLINE int
293 l4_scheduler_is_online_u(l4_cap_idx_t scheduler, l4_umword_t cpu,
294  l4_utcb_t *utcb) L4_NOTHROW
295 {
297  l4_msgtag_t r;
298  s.gran_offset = cpu;
299  r = l4_scheduler_info_u(scheduler, NULL, &s, utcb);
300  if (l4_msgtag_has_error(r) || l4_msgtag_label(r) < 0)
301  return 0;
302 
303  return s.map & 1;
304 }
305 
306 
307 L4_INLINE l4_msgtag_t
310 {
311  return l4_scheduler_info_u(scheduler, cpu_max, cpus, l4_utcb());
312 }
313 
314 L4_INLINE l4_msgtag_t
316  l4_cap_idx_t thread, l4_sched_param_t const *sp) L4_NOTHROW
317 {
318  return l4_scheduler_run_thread_u(scheduler, thread, sp, l4_utcb());
319 }
320 
321 L4_INLINE l4_msgtag_t
324 {
325  return l4_scheduler_idle_time_u(scheduler, cpus, us, l4_utcb());
326 }
327 
328 L4_INLINE int
330 {
331  return l4_scheduler_is_online_u(scheduler, cpu, l4_utcb());
332 }
Encapsulation of the message-register block in the UTCB.
Definition: utcb.h:78
Run a thread on this scheduler.
Definition: scheduler.h:203
l4_umword_t gran_offset
Combination of granularity and offset.
Definition: scheduler.h:57
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:122
unsigned l4_msgtag_has_error(l4_msgtag_t t) L4_NOTHROW
Test for error indicator flag.
Definition: types.h:435
unsigned offset() const
Definition: scheduler.h:68
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:119
l4_umword_t map
Bitmap of CPUs.
Definition: scheduler.h:62
unsigned long l4_cap_idx_t
L4 Capability selector Type.
Definition: types.h:341
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:210
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:322
#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:418
unsigned char granularity() const
Definition: scheduler.h:66
Query idle time for the scheduler.
Definition: scheduler.h:204
l4_sched_param_t l4_sched_param(unsigned prio, l4_cpu_time_t quantum=0) L4_NOTHROW
Construct scheduler parameter.
Definition: scheduler.h:220
Query infos about the scheduler.
Definition: scheduler.h:202
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:329
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:407
struct l4_sched_cpu_set_t l4_sched_cpu_set_t
CPU sets.
l4_sched_cpu_set_t affinity
CPU affinity.
Definition: scheduler.h:121
l4_umword_t quantum
Timeslice in micro seconds.
Definition: scheduler.h:123
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:200
Message tag data structure.
Definition: types.h:158
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:315
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:308
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