- Info
1
21
22
28
29 #ifndef _INCLUDE__CPU_SESSION__CPU_SESSION_H_
30 #define _INCLUDE__CPU_SESSION__CPU_SESSION_H_
31
32 #include <base/stdint.h>
33 #include <base/exception.h>
34 #include <base/thread_state.h>
35 #include <thread/capability.h>
36 #include <pager/capability.h>
37
38 namespace Genode {
39
40 class Cpu_session
41 {
42 protected:
43
44 enum Opcode {
45 CREATE_THREAD, KILL_THREAD, FIRST, NEXT, SET_PAGER, START,
46 CANCEL_BLOCKING, NAME, STATE
47 };
48
49 public:
50
51
54
55 class Thread_creation_failed : public Exception { };
56
57
58 static const char *service_name() { return "CPU"; }
59
60 enum { THREAD_NAME_LEN = 32 };
61 enum { PRIORITY_LIMIT = 1 << 16 };
62 enum { DEFAULT_PRIORITY = 0 };
63
64 virtual ~Cpu_session() { }
65
66
73 virtual Thread_capability create_thread(const char *name) = 0;
74
75
80 virtual void kill_thread(Thread_capability thread) = 0;
81
82
89 virtual Thread_capability first() = 0;
90 virtual Thread_capability next(Thread_capability curr) = 0;
91
92
98 virtual int set_pager(Thread_capability thread,
99 Pager_capability pager) = 0;
100
101
111 virtual int start(Thread_capability thread, addr_t ip, addr_t sp) = 0;
112
113
118 virtual void cancel_blocking(Thread_capability thread) = 0;
119
120
129 virtual int name(Thread_capability thread,
130 char *name_dst, size_t name_len) = 0;
131
132
140 virtual int state(Thread_capability thread,
141 Thread_state *state_dst) = 0;
142
143
156 static unsigned scale_priority(unsigned pf_prio_limit, unsigned prio,
157 bool inverse = true)
158 {
159
160 if (prio == 0) return pf_prio_limit;
161
162
167 prio = inverse ? Cpu_session::PRIORITY_LIMIT - prio : prio;
168
169
170 return (prio*pf_prio_limit)/Cpu_session::PRIORITY_LIMIT;
171 }
172 };
173 }
174
175 #endif