19 #ifndef _COBALT_KERNEL_THREAD_H
20 #define _COBALT_KERNEL_THREAD_H
22 #include <linux/sched.h>
23 #include <linux/sched/rt.h>
24 #include <cobalt/kernel/list.h>
25 #include <cobalt/kernel/stat.h>
26 #include <cobalt/kernel/timer.h>
27 #include <cobalt/kernel/registry.h>
28 #include <cobalt/kernel/schedparam.h>
29 #include <cobalt/kernel/trace.h>
30 #include <cobalt/kernel/synch.h>
31 #include <cobalt/uapi/kernel/thread.h>
32 #include <asm/xenomai/machine.h>
33 #include <asm/xenomai/thread.h>
39 #define XNTHREAD_BLOCK_BITS (XNSUSP|XNPEND|XNDELAY|XNDORMANT|XNRELAX|XNMIGRATE|XNHELD)
40 #define XNTHREAD_MODE_BITS (XNLOCK|XNRRB|XNWARN|XNTRAPLB)
46 struct xnsched_tpslot;
47 struct xnthread_personality;
50 struct xnthread_init_attr {
51 struct xnthread_personality *personality;
57 struct xnthread_start_attr {
59 void (*entry)(
void *cookie);
63 struct xnthread_wait_context {
67 struct xnthread_personality {
73 void *(*attach_process)(void);
74 void (*detach_process)(
void *arg);
75 void (*map_thread)(
struct xnthread *thread);
76 struct xnthread_personality *(*relax_thread)(
struct xnthread *thread);
77 struct xnthread_personality *(*harden_thread)(
struct xnthread *thread);
78 struct xnthread_personality *(*move_thread)(
struct xnthread *thread,
80 struct xnthread_personality *(*exit_thread)(
struct xnthread *thread);
81 struct xnthread_personality *(*finalize_thread)(
struct xnthread *thread);
83 struct module *module;
93 struct xnsched_class *sched_class;
94 struct xnsched_class *base_class;
96 #ifdef CONFIG_XENO_OPT_SCHED_TP
97 struct xnsched_tpslot *tps;
98 struct list_head tp_link;
100 #ifdef CONFIG_XENO_OPT_SCHED_SPORADIC
101 struct xnsched_sporadic_data *pss;
103 #ifdef CONFIG_XENO_OPT_SCHED_QUOTA
104 struct xnsched_quota_group *quota;
105 struct list_head quota_expired;
106 struct list_head quota_next;
128 struct list_head rlink;
134 struct list_head plink;
137 struct list_head glink;
143 struct list_head claimq;
145 struct xnsynch *wchan;
147 struct xnsynch *wwake;
151 struct xntimer rtimer;
153 struct xntimer ptimer;
157 struct xnthread_wait_context *wcontext;
160 xnstat_counter_t ssw;
161 xnstat_counter_t csw;
162 xnstat_counter_t xsc;
164 xnstat_exectime_t account;
165 xnstat_exectime_t lastperiod;
168 struct xnselector *selector;
172 char name[XNOBJECT_NAME_LEN];
174 void (*entry)(
void *cookie);
177 struct xnthread_user_window *u_window;
179 struct xnthread_personality *personality;
181 #ifdef CONFIG_XENO_OPT_DEBUG
182 const char *exe_path;
186 struct xnsynch join_synch;
189 static inline int xnthread_get_state(
const struct xnthread *thread)
191 return thread->state;
194 static inline int xnthread_test_state(
struct xnthread *thread,
int bits)
196 return thread->state & bits;
199 static inline void xnthread_set_state(
struct xnthread *thread,
int bits)
201 thread->state |= bits;
204 static inline void xnthread_clear_state(
struct xnthread *thread,
int bits)
206 thread->state &= ~bits;
209 static inline int xnthread_test_info(
struct xnthread *thread,
int bits)
211 return thread->info & bits;
214 static inline void xnthread_set_info(
struct xnthread *thread,
int bits)
216 thread->info |= bits;
219 static inline void xnthread_clear_info(
struct xnthread *thread,
int bits)
221 thread->info &= ~bits;
224 static inline struct xnarchtcb *xnthread_archtcb(
struct xnthread *thread)
229 static inline int xnthread_base_priority(
const struct xnthread *thread)
231 return thread->bprio;
234 static inline int xnthread_current_priority(
const struct xnthread *thread)
236 return thread->cprio;
239 static inline struct task_struct *xnthread_host_task(
struct xnthread *thread)
241 return xnthread_archtcb(thread)->core.host_task;
244 static inline pid_t xnthread_host_pid(
struct xnthread *thread)
246 if (xnthread_test_state(thread,
XNROOT))
249 return xnthread_host_task(thread)->pid;
252 #define xnthread_for_each_claimed(__pos, __thread) \
253 list_for_each_entry(__pos, &(__thread)->claimq, link)
255 #define xnthread_for_each_claimed_safe(__pos, __tmp, __thread) \
256 list_for_each_entry_safe(__pos, __tmp, &(__thread)->claimq, link)
258 #define xnthread_run_handler(__t, __h, __a...) \
260 struct xnthread_personality *__p__ = (__t)->personality; \
261 if ((__p__)->ops.__h) \
262 (__p__)->ops.__h(__t, ##__a); \
265 #define xnthread_run_handler_stack(__t, __h, __a...) \
267 struct xnthread_personality *__p__ = (__t)->personality; \
269 if ((__p__)->ops.__h == NULL) \
271 __p__ = (__p__)->ops.__h(__t, ##__a); \
276 struct xnthread_wait_context *xnthread_get_wait_context(
struct xnthread *thread)
278 return thread->wcontext;
282 int xnthread_register(
struct xnthread *thread,
const char *name)
288 struct xnthread *xnthread_lookup(xnhandle_t threadh)
291 return thread && thread->handle == xnhandle_get_index(threadh) ? thread : NULL;
294 static inline void xnthread_sync_window(
struct xnthread *thread)
296 if (thread->u_window) {
297 thread->u_window->state = thread->state;
298 thread->u_window->info = thread->info;
303 void xnthread_clear_sync_window(
struct xnthread *thread,
int state_bits)
305 if (thread->u_window) {
306 thread->u_window->state = thread->state & ~state_bits;
307 thread->u_window->info = thread->info;
312 void xnthread_set_sync_window(
struct xnthread *thread,
int state_bits)
314 if (thread->u_window) {
315 thread->u_window->state = thread->state | state_bits;
316 thread->u_window->info = thread->info;
320 static inline int normalize_priority(
int prio)
322 return prio < MAX_RT_PRIO ? prio : MAX_RT_PRIO - 1;
325 int __xnthread_init(
struct xnthread *thread,
326 const struct xnthread_init_attr *attr,
328 struct xnsched_class *sched_class,
329 const union xnsched_policy_param *sched_param);
331 void __xnthread_test_cancel(
struct xnthread *curr);
333 void __xnthread_cleanup(
struct xnthread *curr);
335 void __xnthread_discard(
struct xnthread *thread);
354 return ipipe_current_threadinfo()->thread;
370 return ipipe_task_threadinfo(p)->thread;
386 if (curr && xnthread_test_info(curr,
XNCANCELD))
387 __xnthread_test_cancel(curr);
391 void xnthread_complete_wait(
struct xnthread_wait_context *wc)
397 int xnthread_wait_complete_p(
struct xnthread_wait_context *wc)
402 #ifdef CONFIG_XENO_ARCH_FPU
403 void xnthread_switch_fpu(
struct xnsched *sched);
405 static inline void xnthread_switch_fpu(
struct xnsched *sched) { }
408 void xnthread_init_shadow_tcb(
struct xnthread *thread);
410 void xnthread_init_root_tcb(
struct xnthread *thread);
412 void xnthread_deregister(
struct xnthread *thread);
414 char *xnthread_format_status(
unsigned long status,
char *buf,
int size);
416 xnticks_t xnthread_get_timeout(
struct xnthread *thread, xnticks_t ns);
418 xnticks_t xnthread_get_period(
struct xnthread *thread);
420 void xnthread_prepare_wait(
struct xnthread_wait_context *wc);
423 const struct xnthread_init_attr *attr,
424 struct xnsched_class *sched_class,
425 const union xnsched_policy_param *sched_param);
428 const struct xnthread_start_attr *attr);
437 xntmode_t timeout_mode,
438 struct xnsynch *wchan);
447 xntmode_t timeout_mode,
457 int xnthread_join(
struct xnthread *thread,
bool uninterruptible);
463 void __xnthread_kick(
struct xnthread *thread);
465 void xnthread_kick(
struct xnthread *thread);
467 void __xnthread_demote(
struct xnthread *thread);
469 void xnthread_demote(
struct xnthread *thread);
471 void xnthread_signal(
struct xnthread *thread,
474 void xnthread_pin_initial(
struct xnthread *thread);
477 struct completion *done);
479 void xnthread_call_mayday(
struct xnthread *thread,
int reason);
484 void xnthread_migrate_passive(
struct xnthread *thread,
490 return cpu ? -EINVAL : 0;
493 static inline void xnthread_migrate_passive(
struct xnthread *thread,
499 int __xnthread_set_schedparam(
struct xnthread *thread,
500 struct xnsched_class *sched_class,
501 const union xnsched_policy_param *sched_param);
504 struct xnsched_class *sched_class,
505 const union xnsched_policy_param *sched_param);
507 int xnthread_killall(
int grace,
int mask);
509 extern struct xnthread_personality xenomai_personality;
void xnthread_relax(int notify, int reason)
Switch a shadow thread back to the Linux domain.
Definition: thread.c:1974
void xnthread_cancel(struct xnthread *thread)
Cancel a thread.
Definition: thread.c:1468
#define XNCANCELD
Cancellation request is pending.
Definition: thread.h:72
static void xnthread_test_cancel(void)
Introduce a thread cancellation point.
Definition: thread.h:382
int xnregistry_enter(const char *key, void *objaddr, xnhandle_t *phandle, struct xnpnode *pnode)
Register a real-time object.
Definition: registry.c:627
void xnthread_suspend(struct xnthread *thread, int mask, xnticks_t timeout, xntmode_t timeout_mode, struct xnsynch *wchan)
Suspend a thread.
Definition: thread.c:833
int xnthread_set_slice(struct xnthread *thread, xnticks_t quantum)
Set thread time-slicing information.
Definition: thread.c:1409
#define XNROOT
Root thread (that is, Linux/IDLE)
Definition: thread.h:49
static struct xnthread * xnthread_current(void)
Retrieve the current Cobalt core TCB.
Definition: thread.h:352
int xnthread_wait_period(unsigned long *overruns_r)
Wait for the next periodic release point.
Definition: thread.c:1335
Scheduling information structure.
Definition: sched.h:58
int xnthread_map(struct xnthread *thread, struct completion *done)
Create a shadow thread context over a kernel task.
Definition: thread.c:2385
static void * xnregistry_lookup(xnhandle_t handle, unsigned long *cstamp_r)
Find a real-time object into the registry.
Definition: registry.h:175
int xnthread_init(struct xnthread *thread, const struct xnthread_init_attr *attr, struct xnsched_class *sched_class, const union xnsched_policy_param *sched_param)
Initialize a new thread.
Definition: thread.c:579
int xnthread_harden(void)
Migrate a Linux task to the Xenomai domain.
Definition: thread.c:1865
int xnthread_set_periodic(struct xnthread *thread, xnticks_t idate, xntmode_t timeout_mode, xnticks_t period)
Make a thread periodic.
Definition: thread.c:1254
int xnthread_start(struct xnthread *thread, const struct xnthread_start_attr *attr)
Start a newly created thread.
Definition: thread.c:660
Copyright © 2011 Gilles Chanteperdrix gilles.chanteperdrix@xenomai.org.
Definition: atomic.h:24
int xnthread_unblock(struct xnthread *thread)
Unblock a thread.
Definition: thread.c:1167
static struct xnthread * xnthread_from_task(struct task_struct *p)
Retrieve the Cobalt core TCB attached to a Linux task.
Definition: thread.h:368
int xnthread_join(struct xnthread *thread, bool uninterruptible)
Join with a terminated thread.
Definition: thread.c:1554
int xnthread_set_mode(struct xnthread *thread, int clrmask, int setmask)
Change thread control mode.
Definition: thread.c:737
int xnthread_set_schedparam(struct xnthread *thread, struct xnsched_class *sched_class, const union xnsched_policy_param *sched_param)
Change the base scheduling parameters of a thread.
Definition: thread.c:1764
void xnthread_resume(struct xnthread *thread, int mask)
Resume a thread.
Definition: thread.c:1049
int xnthread_migrate(int cpu)
Migrate the current thread.
Definition: thread.c:1639