19 #ifndef _COBALT_KERNEL_THREAD_H 20 #define _COBALT_KERNEL_THREAD_H 22 #include <linux/wait.h> 23 #include <linux/sched.h> 24 #include <linux/sched/rt.h> 25 #include <cobalt/kernel/list.h> 26 #include <cobalt/kernel/stat.h> 27 #include <cobalt/kernel/timer.h> 28 #include <cobalt/kernel/registry.h> 29 #include <cobalt/kernel/schedparam.h> 30 #include <cobalt/kernel/trace.h> 31 #include <cobalt/kernel/synch.h> 32 #include <cobalt/uapi/kernel/thread.h> 33 #include <cobalt/uapi/signal.h> 34 #include <asm/xenomai/machine.h> 35 #include <asm/xenomai/thread.h> 41 #define XNTHREAD_BLOCK_BITS (XNSUSP|XNPEND|XNDELAY|XNDORMANT|XNRELAX|XNMIGRATE|XNHELD|XNDBGSTOP) 42 #define XNTHREAD_MODE_BITS (XNRRB|XNWARN|XNTRAPLB) 48 struct xnsched_tpslot;
49 struct xnthread_personality;
52 struct xnthread_init_attr {
53 struct xnthread_personality *personality;
59 struct xnthread_start_attr {
61 void (*entry)(
void *cookie);
65 struct xnthread_wait_context {
69 struct xnthread_personality {
75 void *(*attach_process)(void);
76 void (*detach_process)(
void *arg);
77 void (*map_thread)(
struct xnthread *thread);
78 struct xnthread_personality *(*relax_thread)(
struct xnthread *thread);
79 struct xnthread_personality *(*harden_thread)(
struct xnthread *thread);
80 struct xnthread_personality *(*move_thread)(
struct xnthread *thread,
82 struct xnthread_personality *(*exit_thread)(
struct xnthread *thread);
83 struct xnthread_personality *(*finalize_thread)(
struct xnthread *thread);
85 struct module *module;
96 struct xnsched_class *sched_class;
97 struct xnsched_class *base_class;
99 #ifdef CONFIG_XENO_OPT_SCHED_TP 100 struct xnsched_tpslot *tps;
101 struct list_head tp_link;
103 #ifdef CONFIG_XENO_OPT_SCHED_SPORADIC 104 struct xnsched_sporadic_data *pss;
106 #ifdef CONFIG_XENO_OPT_SCHED_QUOTA 107 struct xnsched_quota_group *quota;
108 struct list_head quota_expired;
109 struct list_head quota_next;
130 struct list_head rlink;
136 struct list_head plink;
139 struct list_head glink;
153 struct list_head boosters;
155 struct xnsynch *wchan;
157 struct xnsynch *wwake;
161 struct xntimer rtimer;
163 struct xntimer ptimer;
167 struct xnthread_wait_context *wcontext;
170 xnstat_counter_t ssw;
171 xnstat_counter_t csw;
172 xnstat_counter_t xsc;
174 xnstat_exectime_t account;
175 xnstat_exectime_t lastperiod;
178 struct xnselector *selector;
182 char name[XNOBJECT_NAME_LEN];
184 void (*entry)(
void *cookie);
191 struct xnthread_user_window *u_window;
193 struct xnthread_personality *personality;
195 struct completion exited;
197 #ifdef CONFIG_XENO_OPT_DEBUG 198 const char *exe_path;
203 static inline int xnthread_get_state(
const struct xnthread *thread)
205 return thread->state;
208 static inline int xnthread_test_state(
struct xnthread *thread,
int bits)
210 return thread->state & bits;
213 static inline void xnthread_set_state(
struct xnthread *thread,
int bits)
215 thread->state |= bits;
218 static inline void xnthread_clear_state(
struct xnthread *thread,
int bits)
220 thread->state &= ~bits;
223 static inline int xnthread_test_info(
struct xnthread *thread,
int bits)
225 return thread->info & bits;
228 static inline void xnthread_set_info(
struct xnthread *thread,
int bits)
230 thread->info |= bits;
233 static inline void xnthread_clear_info(
struct xnthread *thread,
int bits)
235 thread->info &= ~bits;
238 static inline int xnthread_test_localinfo(
struct xnthread *curr,
int bits)
240 return curr->local_info & bits;
243 static inline void xnthread_set_localinfo(
struct xnthread *curr,
int bits)
245 curr->local_info |= bits;
248 static inline void xnthread_clear_localinfo(
struct xnthread *curr,
int bits)
250 curr->local_info &= ~bits;
253 static inline struct xnarchtcb *xnthread_archtcb(
struct xnthread *thread)
258 static inline int xnthread_base_priority(
const struct xnthread *thread)
260 return thread->bprio;
263 static inline int xnthread_current_priority(
const struct xnthread *thread)
265 return thread->cprio;
268 static inline struct task_struct *xnthread_host_task(
struct xnthread *thread)
270 return xnthread_archtcb(thread)->core.host_task;
273 #define xnthread_for_each_booster(__pos, __thread) \ 274 list_for_each_entry(__pos, &(__thread)->boosters, next) 276 #define xnthread_for_each_booster_safe(__pos, __tmp, __thread) \ 277 list_for_each_entry_safe(__pos, __tmp, &(__thread)->boosters, next) 279 #define xnthread_run_handler(__t, __h, __a...) \ 281 struct xnthread_personality *__p__ = (__t)->personality; \ 282 if ((__p__)->ops.__h) \ 283 (__p__)->ops.__h(__t, ##__a); \ 286 #define xnthread_run_handler_stack(__t, __h, __a...) \ 288 struct xnthread_personality *__p__ = (__t)->personality; \ 290 if ((__p__)->ops.__h == NULL) \ 292 __p__ = (__p__)->ops.__h(__t, ##__a); \ 297 struct xnthread_wait_context *xnthread_get_wait_context(
struct xnthread *thread)
299 return thread->wcontext;
303 int xnthread_register(
struct xnthread *thread,
const char *name)
309 struct xnthread *xnthread_lookup(xnhandle_t threadh)
312 return thread && thread->handle == xnhandle_get_index(threadh) ? thread : NULL;
315 static inline void xnthread_sync_window(
struct xnthread *thread)
317 if (thread->u_window) {
318 thread->u_window->state = thread->state;
319 thread->u_window->info = thread->info;
324 void xnthread_clear_sync_window(
struct xnthread *thread,
int state_bits)
326 if (thread->u_window) {
327 thread->u_window->state = thread->state & ~state_bits;
328 thread->u_window->info = thread->info;
333 void xnthread_set_sync_window(
struct xnthread *thread,
int state_bits)
335 if (thread->u_window) {
336 thread->u_window->state = thread->state | state_bits;
337 thread->u_window->info = thread->info;
341 static inline int normalize_priority(
int prio)
343 return prio < MAX_RT_PRIO ? prio : MAX_RT_PRIO - 1;
346 int __xnthread_init(
struct xnthread *thread,
347 const struct xnthread_init_attr *attr,
349 struct xnsched_class *sched_class,
350 const union xnsched_policy_param *sched_param);
352 void __xnthread_test_cancel(
struct xnthread *curr);
354 void __xnthread_cleanup(
struct xnthread *curr);
356 void __xnthread_discard(
struct xnthread *thread);
375 return ipipe_current_threadinfo()->thread;
391 return ipipe_task_threadinfo(p)->thread;
407 if (curr && xnthread_test_info(curr,
XNCANCELD))
408 __xnthread_test_cancel(curr);
412 void xnthread_complete_wait(
struct xnthread_wait_context *wc)
418 int xnthread_wait_complete_p(
struct xnthread_wait_context *wc)
423 #ifdef CONFIG_XENO_ARCH_FPU 424 void xnthread_switch_fpu(
struct xnsched *sched);
426 static inline void xnthread_switch_fpu(
struct xnsched *sched) { }
429 void xnthread_init_shadow_tcb(
struct xnthread *thread);
431 void xnthread_init_root_tcb(
struct xnthread *thread);
433 void xnthread_deregister(
struct xnthread *thread);
435 char *xnthread_format_status(
unsigned long status,
436 char *buf,
int size);
438 pid_t xnthread_host_pid(
struct xnthread *thread);
440 int xnthread_set_clock(
struct xnthread *thread,
441 struct xnclock *newclock);
443 xnticks_t xnthread_get_timeout(
struct xnthread *thread,
446 xnticks_t xnthread_get_period(
struct xnthread *thread);
448 void xnthread_prepare_wait(
struct xnthread_wait_context *wc);
451 const struct xnthread_init_attr *attr,
452 struct xnsched_class *sched_class,
453 const union xnsched_policy_param *sched_param);
456 const struct xnthread_start_attr *attr);
464 xntmode_t timeout_mode,
465 struct xnsynch *wchan);
474 xntmode_t timeout_mode,
484 int xnthread_join(
struct xnthread *thread,
bool uninterruptible);
490 void __xnthread_kick(
struct xnthread *thread);
492 void xnthread_kick(
struct xnthread *thread);
494 void __xnthread_demote(
struct xnthread *thread);
496 void xnthread_demote(
struct xnthread *thread);
498 void xnthread_signal(
struct xnthread *thread,
501 void xnthread_pin_initial(
struct xnthread *thread);
504 struct completion *done);
506 void xnthread_call_mayday(
struct xnthread *thread,
int reason);
508 static inline void xnthread_get_resource(
struct xnthread *curr)
514 static inline int xnthread_put_resource(
struct xnthread *curr)
516 if (xnthread_test_state(curr,
XNWEAK) ||
517 IS_ENABLED(CONFIG_XENO_OPT_DEBUG_MUTEX_SLEEP)) {
518 if (unlikely(curr->res_count == 0)) {
519 if (xnthread_test_state(curr,
XNWARN))
520 xnthread_signal(curr, SIGDEBUG,
521 SIGDEBUG_RESCNT_IMBALANCE);
530 static inline void xnthread_commit_ceiling(
struct xnthread *curr)
532 if (curr->u_window->pp_pending)
533 xnsynch_commit_ceiling(curr);
538 void xnthread_migrate_passive(
struct xnthread *thread,
542 static inline void xnthread_migrate_passive(
struct xnthread *thread,
548 int __xnthread_set_schedparam(
struct xnthread *thread,
549 struct xnsched_class *sched_class,
550 const union xnsched_policy_param *sched_param);
553 struct xnsched_class *sched_class,
554 const union xnsched_policy_param *sched_param);
556 int xnthread_killall(
int grace,
int mask);
558 void __xnthread_propagate_schedparam(
struct xnthread *curr);
560 static inline void xnthread_propagate_schedparam(
struct xnthread *curr)
562 if (xnthread_test_info(curr,
XNSCHEDP))
563 __xnthread_propagate_schedparam(curr);
566 extern struct xnthread_personality xenomai_personality;
#define XNSCHEDP
schedparam propagation is pending
Definition: thread.h:75
void xnthread_relax(int notify, int reason)
Switch a shadow thread back to the Linux domain.
Definition: thread.c:2088
void xnthread_cancel(struct xnthread *thread)
Cancel a thread.
Definition: thread.c:1541
#define XNCANCELD
Cancellation request is pending.
Definition: thread.h:73
static void xnthread_test_cancel(void)
Introduce a thread cancellation point.
Definition: thread.h:406
#define XNWARN
Issue SIGDEBUG on error detection.
Definition: thread.h:46
#define XNDEBUG
User-level debugging enabled.
Definition: thread.h:53
int xnregistry_enter(const char *key, void *objaddr, xnhandle_t *phandle, struct xnpnode *pnode)
Register a real-time object.
Definition: registry.c:632
void xnthread_suspend(struct xnthread *thread, int mask, xnticks_t timeout, xntmode_t timeout_mode, struct xnsynch *wchan)
Suspend a thread.
Definition: thread.c:881
#define XNWEAK
Non real-time shadow (from the WEAK class)
Definition: thread.h:49
int xnthread_set_slice(struct xnthread *thread, xnticks_t quantum)
Set thread time-slicing information.
Definition: thread.c:1483
static struct xnthread * xnthread_current(void)
Retrieve the current Cobalt core TCB.
Definition: thread.h:374
int xnthread_wait_period(unsigned long *overruns_r)
Wait for the next periodic release point.
Definition: thread.c:1406
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:2540
int xnthread_set_mode(int clrmask, int setmask)
Change control mode of the current thread.
Definition: thread.c:786
static void * xnregistry_lookup(xnhandle_t handle, unsigned long *cstamp_r)
Find a real-time object into the registry.
Definition: registry.h:176
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:620
int xnthread_harden(void)
Migrate a Linux task to the Xenomai domain.
Definition: thread.c:1943
int xnthread_set_periodic(struct xnthread *thread, xnticks_t idate, xntmode_t timeout_mode, xnticks_t period)
Make a thread periodic.
Definition: thread.c:1320
int xnthread_start(struct xnthread *thread, const struct xnthread_start_attr *attr)
Start a newly created thread.
Definition: thread.c:694
Copyright © 2011 Gilles Chanteperdrix gilles.chanteperdrix@xenomai.org.
Definition: atomic.h:24
int xnthread_unblock(struct xnthread *thread)
Unblock a thread.
Definition: thread.c:1228
static struct xnthread * xnthread_from_task(struct task_struct *p)
Retrieve the Cobalt core TCB attached to a Linux task.
Definition: thread.h:391
int xnthread_join(struct xnthread *thread, bool uninterruptible)
Join with a terminated thread.
Definition: thread.c:1671
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:1847
void xnthread_resume(struct xnthread *thread, int mask)
Resume a thread.
Definition: thread.c:1109