22 #ifndef _XENO_NUCLEUS_THREAD_H
23 #define _XENO_NUCLEUS_THREAD_H
25 #include <nucleus/types.h>
35 #define XNSUSP 0x00000001
36 #define XNPEND 0x00000002
37 #define XNDELAY 0x00000004
38 #define XNREADY 0x00000008
39 #define XNDORMANT 0x00000010
40 #define XNZOMBIE 0x00000020
41 #define XNRESTART 0x00000040
42 #define XNSTARTED 0x00000080
43 #define XNMAPPED 0x00000100
44 #define XNRELAX 0x00000200
45 #define XNMIGRATE 0x00000400
46 #define XNHELD 0x00000800
48 #define XNBOOST 0x00001000
49 #define XNDEBUG 0x00002000
50 #define XNLOCK 0x00004000
51 #define XNRRB 0x00008000
52 #define XNASDI 0x00010000
53 #define XNDEFCAN 0x00020000
60 #define XNTRAPSW 0x00040000
61 #define XNRPIOFF 0x00080000
62 #define XNFPU 0x00100000
63 #define XNSHADOW 0x00200000
64 #define XNROOT 0x00400000
65 #define XNOTHER 0x00800000
88 #define XNTHREAD_STATE_LABELS "SWDRU....X.HbTlr..tof.."
90 #define XNTHREAD_BLOCK_BITS (XNSUSP|XNPEND|XNDELAY|XNDORMANT|XNRELAX|XNMIGRATE|XNHELD)
91 #define XNTHREAD_MODE_BITS (XNLOCK|XNRRB|XNASDI|XNTRAPSW|XNRPIOFF)
94 #define XNTHREAD_STATE_SPARE0 0x10000000
95 #define XNTHREAD_STATE_SPARE1 0x20000000
96 #define XNTHREAD_STATE_SPARE2 0x40000000
97 #define XNTHREAD_STATE_SPARE3 0x80000000
98 #define XNTHREAD_STATE_SPARES 0xf0000000
108 #define XNTIMEO 0x00000001
109 #define XNRMID 0x00000002
110 #define XNBREAK 0x00000004
111 #define XNKICKED 0x00000008
112 #define XNWAKEN 0x00000010
113 #define XNROBBED 0x00000020
114 #define XNATOMIC 0x00000040
115 #define XNAFFSET 0x00000080
116 #define XNPRIOSET 0x00000100
117 #define XNABORT 0x00000200
118 #define XNCANPND 0x00000400
119 #define XNAMOK 0x00000800
120 #define XNSWREP 0x00001000
123 #define XNTHREAD_INFO_SPARE0 0x10000000
124 #define XNTHREAD_INFO_SPARE1 0x20000000
125 #define XNTHREAD_INFO_SPARE2 0x40000000
126 #define XNTHREAD_INFO_SPARE3 0x80000000
127 #define XNTHREAD_INFO_SPARES 0xf0000000
156 #if defined(__KERNEL__) || defined(__XENO_SIM__)
158 #include <nucleus/stat.h>
161 #include <nucleus/schedparam.h>
165 #define XNRUNNING XNTHREAD_STATE_SPARE0
166 #define XNDELETED XNTHREAD_STATE_SPARE1
169 #define XNTHREAD_INVALID_ASR ((void (*)(xnsigmask_t))0)
175 struct xnsched_class;
176 struct xnsched_tpslot;
177 union xnsched_policy_param;
180 struct xnthread_operations {
181 int (*get_denormalized_prio)(
struct xnthread *,
int coreprio);
182 unsigned (*get_magic)(void);
185 struct xnthread_init_attr {
186 struct xntbase *tbase;
187 struct xnthread_operations *ops;
189 unsigned int stacksize;
193 struct xnthread_start_attr {
196 xnarch_cpumask_t affinity;
197 void (*entry)(
void *cookie);
201 struct xnthread_wait_context {
202 unsigned long oldstate;
205 typedef void (*xnasr_t)(xnsigmask_t sigs);
207 typedef struct xnthread {
217 struct xnsched_class *sched_class;
219 struct xnsched_class *base_class;
221 #ifdef CONFIG_XENO_OPT_SCHED_TP
222 struct xnsched_tpslot *tps;
223 struct xnholder tp_link;
225 #ifdef CONFIG_XENO_OPT_SCHED_SPORADIC
226 struct xnsched_sporadic_data *pss;
231 xnarch_cpumask_t affinity;
243 #ifdef CONFIG_XENO_OPT_PRIOCPL
251 #define link2thread(ln, fld) container_of(ln, struct xnthread, fld)
255 struct xnsynch *wchan;
257 struct xnsynch *wwake;
286 struct xnthread_wait_context *wcontext;
289 xnstat_counter_t ssw;
290 xnstat_counter_t csw;
292 xnstat_exectime_t account;
293 xnstat_exectime_t lastperiod;
296 #ifdef CONFIG_XENO_OPT_SELECT
297 struct xnselector *selector;
314 struct xnsched_class *init_class;
316 union xnsched_policy_param init_schedparam;
323 struct xnthread_operations *ops;
325 char name[XNOBJECT_NAME_LEN];
327 void (*entry)(
void *cookie);
331 #ifdef CONFIG_XENO_OPT_PERVASIVE
332 unsigned long *u_mode;
335 XNARCH_DECL_DISPLAY_CONTEXT();
339 #define XNHOOK_THREAD_START 1
340 #define XNHOOK_THREAD_SWITCH 2
341 #define XNHOOK_THREAD_DELETE 3
343 typedef struct xnhook {
345 #define link2hook(ln) container_of(ln, xnhook_t, link)
346 void (*routine)(
struct xnthread *thread);
349 #define xnthread_name(thread) ((thread)->name)
350 #define xnthread_clear_name(thread) do { *(thread)->name = 0; } while(0)
351 #define xnthread_sched(thread) ((thread)->sched)
352 #define xnthread_start_time(thread) ((thread)->stime)
353 #define xnthread_state_flags(thread) ((thread)->state)
354 #define xnthread_test_state(thread,flags) testbits((thread)->state,flags)
355 #define xnthread_set_state(thread,flags) __setbits((thread)->state,flags)
356 #define xnthread_clear_state(thread,flags) __clrbits((thread)->state,flags)
357 #define xnthread_test_info(thread,flags) testbits((thread)->info,flags)
358 #define xnthread_set_info(thread,flags) __setbits((thread)->info,flags)
359 #define xnthread_clear_info(thread,flags) __clrbits((thread)->info,flags)
360 #define xnthread_lock_count(thread) ((thread)->schedlck)
361 #define xnthread_init_schedparam(thread) ((thread)->init_schedparam)
362 #define xnthread_base_priority(thread) ((thread)->bprio)
363 #define xnthread_current_priority(thread) ((thread)->cprio)
364 #define xnthread_init_class(thread) ((thread)->init_class)
365 #define xnthread_base_class(thread) ((thread)->base_class)
366 #define xnthread_sched_class(thread) ((thread)->sched_class)
367 #define xnthread_time_slice(thread) ((thread)->rrperiod)
368 #define xnthread_time_credit(thread) ((thread)->rrcredit)
369 #define xnthread_archtcb(thread) (&((thread)->tcb))
370 #define xnthread_asr_level(thread) ((thread)->asrlevel)
371 #define xnthread_pending_signals(thread) ((thread)->signals)
372 #define xnthread_timeout(thread) xntimer_get_timeout(&(thread)->rtimer)
373 #define xnthread_stack_size(thread) xnarch_stack_size(xnthread_archtcb(thread))
374 #define xnthread_stack_base(thread) xnarch_stack_base(xnthread_archtcb(thread))
375 #define xnthread_stack_end(thread) xnarch_stack_end(xnthread_archtcb(thread))
376 #define xnthread_handle(thread) ((thread)->registry.handle)
377 #ifdef CONFIG_XENO_OPT_TIMING_PERIODIC
378 #define xnthread_time_base(thread) ((thread)->rtimer.base)
380 #define xnthread_time_base(thread) (&nktbase)
382 #define xnthread_signaled_p(thread) ((thread)->signals != 0)
383 #define xnthread_timed_p(thread) (!!testbits(xnthread_time_base(thread)->status, XNTBRUN))
384 #define xnthread_user_task(thread) xnarch_user_task(xnthread_archtcb(thread))
385 #define xnthread_user_pid(thread) \
386 (xnthread_test_state((thread),XNROOT) || !xnthread_user_task(thread) ? \
387 0 : xnarch_user_pid(xnthread_archtcb(thread)))
388 #define xnthread_current_user_task(curr) \
390 struct xnthread *__c = (curr); \
391 XENO_BUGON(NUCLEUS, __c != xnpod_current_thread()); \
392 xnthread_test_state(__c, XNROOT|XNSHADOW) ? current : NULL; \
394 #define xnthread_current_user_pid(curr) \
396 struct task_struct *p = xnthread_current_user_task(curr); \
399 #define xnthread_affinity(thread) ((thread)->affinity)
400 #define xnthread_affine_p(thread, cpu) xnarch_cpu_isset(cpu, (thread)->affinity)
401 #define xnthread_get_exectime(thread) xnstat_exectime_get_total(&(thread)->stat.account)
402 #define xnthread_get_lastswitch(thread) xnstat_exectime_get_last_switch((thread)->sched)
403 #ifdef CONFIG_XENO_OPT_PERVASIVE
404 #define xnthread_inc_rescnt(thread) ({ (thread)->hrescnt++; })
405 #define xnthread_dec_rescnt(thread) ({ --(thread)->hrescnt; })
406 #define xnthread_get_rescnt(thread) ((thread)->hrescnt)
408 #define xnthread_inc_rescnt(thread) do { } while (0)
409 #define xnthread_dec_rescnt(thread) do { } while (0)
411 #if defined(CONFIG_XENO_OPT_WATCHDOG) || defined(CONFIG_XENO_SKIN_POSIX)
412 #define xnthread_amok_p(thread) xnthread_test_info(thread, XNAMOK)
413 #define xnthread_clear_amok(thread) xnthread_clear_info(thread, XNAMOK)
415 #define xnthread_amok_p(thread) ({ (void)(thread); 0; })
416 #define xnthread_clear_amok(thread) do { (void)(thread); } while (0)
420 static inline int xnthread_get_denormalized_prio(
struct xnthread *t,
int coreprio)
422 return t->ops && t->ops->get_denormalized_prio
423 ? t->ops->get_denormalized_prio(t, coreprio) : coreprio;
426 static inline unsigned xnthread_get_magic(
struct xnthread *t)
428 return t->ops ? t->ops->get_magic() : 0;
432 struct xnthread_wait_context *xnthread_get_wait_context(
struct xnthread *thread)
434 return thread->wcontext;
438 int xnthread_register(
struct xnthread *thread,
const char *name)
444 struct xnthread *xnthread_lookup(xnhandle_t threadh)
446 struct xnthread *thread = (
struct xnthread *)xnregistry_lookup(threadh);
447 return (thread && xnthread_handle(thread) == threadh) ? thread : NULL;
450 static inline int xnthread_try_grab(
struct xnthread *curr,
451 struct xnsynch *synch)
453 XENO_BUGON(NUCLEUS, xnsynch_fastlock_p(synch));
455 if (xnsynch_owner(synch) != NULL)
458 xnsynch_set_owner(synch, curr);
460 if (xnthread_test_state(curr,
XNOTHER))
461 xnthread_inc_rescnt(curr);
470 int xnthread_init(
struct xnthread *thread,
471 const struct xnthread_init_attr *attr,
473 struct xnsched_class *sched_class,
474 const union xnsched_policy_param *sched_param);
476 void xnthread_cleanup_tcb(
struct xnthread *thread);
478 char *xnthread_format_status(xnflags_t status,
char *buf,
int size);
480 int *xnthread_get_errno_location(
struct xnthread *thread);
482 xnticks_t xnthread_get_timeout(
struct xnthread *thread, xnticks_t tsc_ns);
484 xnticks_t xnthread_get_period(
struct xnthread *thread);
486 void xnthread_prepare_wait(
struct xnthread_wait_context *wc);
488 void xnthread_finish_wait(
struct xnthread_wait_context *wc,
489 void (*cleanup)(
struct xnthread_wait_context *wc));
#define XNOTHER
Non real-time shadow (prio=0)
Definition: thread.h:65
This file is part of the Xenomai project.
int cprio
Current priority.
Definition: thread.h:139
unsigned long modeswitches
Number of primary->secondary mode switches.
Definition: thread.h:148
Structure containing thread information.
Definition: thread.h:134
Scheduling information structure.
Definition: sched.h:66
int cpu
CPU the thread currently runs on.
Definition: thread.h:141
int xnregistry_enter(const char *key, void *objaddr, xnhandle_t *phandle, struct xnpnode *pnode)
Register a real-time object.
Definition: registry.c:657
char name[XNOBJECT_NAME_LEN]
Symbolic name assigned at creation.
Definition: thread.h:152
unsigned long pagefaults
Number of triggered page faults.
Definition: thread.h:150
unsigned long affinity
Thread's CPU affinity.
Definition: thread.h:142
unsigned long state
Thread state,.
Definition: thread.h:136
int bprio
Base priority.
Definition: thread.h:138
unsigned long long exectime
Execution time in primary mode in nanoseconds.
Definition: thread.h:146
unsigned long ctxswitches
Number of context switches.
Definition: thread.h:149
unsigned long long relpoint
Time of next release.
Definition: thread.h:144