19#ifndef _COBALT_KERNEL_THREAD_H
20#define _COBALT_KERNEL_THREAD_H
22#include <linux/irq_work.h>
23#include <linux/wait.h>
24#include <linux/sched.h>
25#include <linux/sched/rt.h>
26#include <pipeline/thread.h>
27#include <cobalt/kernel/list.h>
28#include <cobalt/kernel/stat.h>
29#include <cobalt/kernel/timer.h>
30#include <cobalt/kernel/registry.h>
31#include <cobalt/kernel/schedparam.h>
32#include <cobalt/kernel/trace.h>
33#include <cobalt/kernel/synch.h>
34#include <cobalt/uapi/kernel/thread.h>
35#include <cobalt/uapi/signal.h>
36#include <asm/xenomai/machine.h>
37#include <asm/xenomai/thread.h>
43#define XNTHREAD_BLOCK_BITS (XNSUSP|XNPEND|XNDELAY|XNDORMANT|XNRELAX|XNHELD|XNDBGSTOP)
44#define XNTHREAD_MODE_BITS (XNRRB|XNWARN|XNTRAPLB)
46#define XNTHREAD_SIGDEBUG 0
47#define XNTHREAD_SIGSHADOW_HARDEN 1
48#define XNTHREAD_SIGSHADOW_BACKTRACE 2
49#define XNTHREAD_SIGSHADOW_HOME 3
50#define XNTHREAD_SIGTERM 4
51#define XNTHREAD_MAX_SIGNALS 5
58struct xnthread_personality;
61struct lostage_signal {
62 struct irq_work inband_work;
63 struct task_struct *task;
67struct lostage_wakeup {
68 struct irq_work inband_work;
69 struct task_struct *task;
72struct xnthread_init_attr {
73 struct xnthread_personality *personality;
79struct xnthread_start_attr {
81 void (*entry)(
void *cookie);
85struct xnthread_wait_context {
89struct xnthread_personality {
95 void *(*attach_process)(void);
96 void (*detach_process)(
void *arg);
97 void (*map_thread)(
struct xnthread *thread);
98 struct xnthread_personality *(*relax_thread)(
struct xnthread *thread);
99 struct xnthread_personality *(*harden_thread)(
struct xnthread *thread);
100 struct xnthread_personality *(*move_thread)(
struct xnthread *thread,
102 struct xnthread_personality *(*exit_thread)(
struct xnthread *thread);
103 struct xnthread_personality *(*finalize_thread)(
struct xnthread *thread);
105 struct module *
module;
109 struct xnarchtcb tcb;
116 struct xnsched_class *sched_class;
117 struct xnsched_class *base_class;
119#ifdef CONFIG_XENO_OPT_SCHED_TP
120 struct xnsched_tpslot *tps;
121 struct list_head tp_link;
123#ifdef CONFIG_XENO_OPT_SCHED_SPORADIC
124 struct xnsched_sporadic_data *pss;
126#ifdef CONFIG_XENO_OPT_SCHED_QUOTA
127 struct xnsched_quota_group *quota;
128 struct list_head quota_expired;
129 struct list_head quota_next;
150 struct list_head rlink;
156 struct list_head plink;
159 struct list_head glink;
173 struct list_head boosters;
175 struct xnsynch *wchan;
177 struct xnsynch *wwake;
181 struct xntimer rtimer;
183 struct xntimer ptimer;
187 struct xnthread_wait_context *wcontext;
190 xnstat_counter_t ssw;
191 xnstat_counter_t csw;
192 xnstat_counter_t xsc;
194 xnstat_exectime_t account;
195 xnstat_exectime_t lastperiod;
198 struct xnselector *selector;
202 char name[XNOBJECT_NAME_LEN];
204 void (*entry)(
void *cookie);
213 struct xnthread_user_window *u_window;
215 struct xnthread_personality *personality;
217 struct completion exited;
219#ifdef CONFIG_XENO_OPT_DEBUG
220 const char *exe_path;
223 struct lostage_signal sigarray[XNTHREAD_MAX_SIGNALS];
224 struct lostage_wakeup relax_work;
227static inline int xnthread_get_state(
const struct xnthread *thread)
229 return thread->state;
232static inline int xnthread_test_state(
struct xnthread *thread,
int bits)
234 return thread->state & bits;
237static inline void xnthread_set_state(
struct xnthread *thread,
int bits)
239 thread->state |= bits;
242static inline void xnthread_clear_state(
struct xnthread *thread,
int bits)
244 thread->state &= ~bits;
247static inline int xnthread_test_info(
struct xnthread *thread,
int bits)
249 return thread->info & bits;
252static inline void xnthread_set_info(
struct xnthread *thread,
int bits)
254 thread->info |= bits;
257static inline void xnthread_clear_info(
struct xnthread *thread,
int bits)
259 thread->info &= ~bits;
262static inline int xnthread_test_localinfo(
struct xnthread *curr,
int bits)
264 return curr->local_info & bits;
267static inline void xnthread_set_localinfo(
struct xnthread *curr,
int bits)
269 curr->local_info |= bits;
272static inline void xnthread_clear_localinfo(
struct xnthread *curr,
int bits)
274 curr->local_info &= ~bits;
277static inline struct xnarchtcb *xnthread_archtcb(
struct xnthread *thread)
282static inline int xnthread_base_priority(
const struct xnthread *thread)
284 return thread->bprio;
287static inline int xnthread_current_priority(
const struct xnthread *thread)
289 return thread->cprio;
292static inline struct task_struct *xnthread_host_task(
struct xnthread *thread)
294 return xnarch_host_task(xnthread_archtcb(thread));
297#define xnthread_for_each_booster(__pos, __thread) \
298 list_for_each_entry(__pos, &(__thread)->boosters, next)
300#define xnthread_for_each_booster_safe(__pos, __tmp, __thread) \
301 list_for_each_entry_safe(__pos, __tmp, &(__thread)->boosters, next)
303#define xnthread_run_handler(__t, __h, __a...) \
305 struct xnthread_personality *__p__ = (__t)->personality; \
306 if ((__p__)->ops.__h) \
307 (__p__)->ops.__h(__t, ##__a); \
310#define xnthread_run_handler_stack(__t, __h, __a...) \
312 struct xnthread_personality *__p__ = (__t)->personality; \
314 if ((__p__)->ops.__h == NULL) \
316 __p__ = (__p__)->ops.__h(__t, ##__a); \
321struct xnthread_wait_context *xnthread_get_wait_context(
struct xnthread *thread)
323 return thread->wcontext;
327int xnthread_register(
struct xnthread *thread,
const char *name)
333struct xnthread *xnthread_lookup(xnhandle_t threadh)
336 return thread && thread->handle == xnhandle_get_index(threadh) ? thread : NULL;
339static inline void xnthread_sync_window(
struct xnthread *thread)
341 if (thread->u_window) {
342 thread->u_window->state = thread->state;
343 thread->u_window->info = thread->info;
348void xnthread_clear_sync_window(
struct xnthread *thread,
int state_bits)
350 if (thread->u_window) {
351 thread->u_window->state = thread->state & ~state_bits;
352 thread->u_window->info = thread->info;
357void xnthread_set_sync_window(
struct xnthread *thread,
int state_bits)
359 if (thread->u_window) {
360 thread->u_window->state = thread->state | state_bits;
361 thread->u_window->info = thread->info;
365static inline int normalize_priority(
int prio)
367 return prio < MAX_RT_PRIO ? prio : MAX_RT_PRIO - 1;
370int __xnthread_init(
struct xnthread *thread,
371 const struct xnthread_init_attr *attr,
373 struct xnsched_class *sched_class,
374 const union xnsched_policy_param *sched_param);
376void __xnthread_test_cancel(
struct xnthread *curr);
378void __xnthread_cleanup(
struct xnthread *curr);
380void __xnthread_discard(
struct xnthread *thread);
399 return pipeline_current()->thread;
415 return pipeline_thread_from_task(p);
431 if (curr && xnthread_test_info(curr,
XNCANCELD))
432 __xnthread_test_cancel(curr);
436void xnthread_complete_wait(
struct xnthread_wait_context *wc)
442int xnthread_wait_complete_p(
struct xnthread_wait_context *wc)
447#ifdef CONFIG_XENO_ARCH_FPU
448void xnthread_switch_fpu(
struct xnsched *sched);
450static inline void xnthread_switch_fpu(
struct xnsched *sched) { }
453void xnthread_deregister(
struct xnthread *thread);
455char *xnthread_format_status(
unsigned long status,
456 char *buf,
int size);
458static inline pid_t xnthread_host_pid(
struct xnthread *thread)
460 return thread->host_pid;
463int xnthread_set_clock(
struct xnthread *thread,
464 struct xnclock *newclock);
466xnticks_t xnthread_get_timeout(
struct xnthread *thread,
469xnticks_t xnthread_get_period(
struct xnthread *thread);
471void xnthread_prepare_wait(
struct xnthread_wait_context *wc);
474 const struct xnthread_init_attr *attr,
475 struct xnsched_class *sched_class,
476 const union xnsched_policy_param *sched_param);
479 const struct xnthread_start_attr *attr);
487 xntmode_t timeout_mode,
488 struct xnsynch *wchan);
497 xntmode_t timeout_mode,
507int xnthread_join(
struct xnthread *thread,
bool uninterruptible);
513void __xnthread_kick(
struct xnthread *thread);
515void xnthread_kick(
struct xnthread *thread);
517void __xnthread_demote(
struct xnthread *thread);
519void xnthread_demote(
struct xnthread *thread);
521void __xnthread_signal(
struct xnthread *thread,
int sig,
int arg);
523void xnthread_signal(
struct xnthread *thread,
int sig,
int arg);
525void xnthread_pin_initial(
struct xnthread *thread);
527void xnthread_call_mayday(
struct xnthread *thread,
int reason);
529static inline void xnthread_get_resource(
struct xnthread *curr)
535static inline int xnthread_put_resource(
struct xnthread *curr)
537 if (xnthread_test_state(curr,
XNWEAK) ||
538 IS_ENABLED(CONFIG_XENO_OPT_DEBUG_MUTEX_SLEEP)) {
539 if (unlikely(curr->res_count == 0)) {
540 if (xnthread_test_state(curr,
XNWARN))
541 xnthread_signal(curr, SIGDEBUG,
542 SIGDEBUG_RESCNT_IMBALANCE);
551static inline void xnthread_commit_ceiling(
struct xnthread *curr)
553 if (curr->u_window->pp_pending)
554 xnsynch_commit_ceiling(curr);
559void xnthread_migrate_passive(
struct xnthread *thread,
563static inline void xnthread_migrate_passive(
struct xnthread *thread,
569int __xnthread_set_schedparam(
struct xnthread *thread,
570 struct xnsched_class *sched_class,
571 const union xnsched_policy_param *sched_param);
574 struct xnsched_class *sched_class,
575 const union xnsched_policy_param *sched_param);
577int xnthread_killall(
int grace,
int mask);
579void __xnthread_propagate_schedparam(
struct xnthread *curr);
581static inline void xnthread_propagate_schedparam(
struct xnthread *curr)
583 if (xnthread_test_info(curr,
XNSCHEDP))
584 __xnthread_propagate_schedparam(curr);
587extern struct xnthread_personality xenomai_personality;
int xnregistry_enter(const char *key, void *objaddr, xnhandle_t *phandle, struct xnpnode *pnode)
Register a real-time object.
Definition registry.c:634
static void * xnregistry_lookup(xnhandle_t handle, unsigned long *cstamp_r)
Find a real-time object into the registry.
Definition registry.h:176
#define XNSCHEDP
schedparam propagation is pending
Definition thread.h:74
#define XNCANCELD
Cancellation request is pending.
Definition thread.h:72
#define XNWARN
Issue SIGDEBUG on error detection.
Definition thread.h:45
#define XNDEBUG
User-level debugging enabled.
Definition thread.h:52
#define XNWEAK
Non real-time shadow (from the WEAK class)
Definition thread.h:48
int xnthread_wait_period(unsigned long *overruns_r)
Wait for the next periodic release point.
Definition thread.c:1385
static struct xnthread * xnthread_current(void)
Retrieve the current Cobalt core TCB.
Definition thread.h:397
int xnthread_set_mode(int clrmask, int setmask)
Change control mode of the current thread.
Definition thread.c:774
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:610
int xnthread_unblock(struct xnthread *thread)
Unblock a thread.
Definition thread.c:1203
int xnthread_set_slice(struct xnthread *thread, xnticks_t quantum)
Set thread time-slicing information.
Definition thread.c:1461
void xnthread_resume(struct xnthread *thread, int mask)
Resume a thread.
Definition thread.c:1085
void xnthread_relax(int notify, int reason)
Switch a shadow thread back to the Linux domain.
Definition thread.c:2036
void xnthread_suspend(struct xnthread *thread, int mask, xnticks_t timeout, xntmode_t timeout_mode, struct xnsynch *wchan)
Suspend a thread.
Definition thread.c:868
static void xnthread_test_cancel(void)
Introduce a thread cancellation point.
Definition thread.h:427
void xnthread_cancel(struct xnthread *thread)
Cancel a thread.
Definition thread.c:1518
static struct xnthread * xnthread_from_task(struct task_struct *p)
Retrieve the Cobalt core TCB attached to a Linux task.
Definition thread.h:413
int xnthread_start(struct xnthread *thread, const struct xnthread_start_attr *attr)
Start a newly created thread.
Definition thread.c:683
int xnthread_join(struct xnthread *thread, bool uninterruptible)
Join with a terminated thread.
Definition thread.c:1647
int xnthread_set_periodic(struct xnthread *thread, xnticks_t idate, xntmode_t timeout_mode, xnticks_t period)
Make a thread periodic.
Definition thread.c:1295
int xnthread_harden(void)
Migrate a Linux task to the Xenomai domain.
Definition thread.c:1916
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:1821
Copyright © 2011 Gilles Chanteperdrix gilles.chanteperdrix@xenomai.org.
Definition atomic.h:24
Scheduling information structure.
Definition sched.h:64