00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef _XENO_NUCLEUS_THREAD_H
00023 #define _XENO_NUCLEUS_THREAD_H
00024
00025 #include <nucleus/timer.h>
00026
00033
00034
00035 #define XNSUSP 0x00000001
00036 #define XNPEND 0x00000002
00037 #define XNDELAY 0x00000004
00038 #define XNREADY 0x00000008
00039 #define XNDORMANT 0x00000010
00040 #define XNZOMBIE 0x00000020
00041 #define XNRESTART 0x00000040
00042 #define XNSTARTED 0x00000080
00043 #define XNMAPPED 0x00000100
00044 #define XNRELAX 0x00000200
00045 #define XNHELD 0x00000400
00047 #define XNBOOST 0x00000800
00048 #define XNDEBUG 0x00001000
00049 #define XNLOCK 0x00002000
00050 #define XNRRB 0x00004000
00051 #define XNASDI 0x00008000
00053
00054
00055
00056
00057 #define XNSHIELD 0x00010000
00058 #define XNTRAPSW 0x00020000
00059 #define XNRPIOFF 0x00040000
00061 #define XNFPU 0x00100000
00062 #define XNSHADOW 0x00200000
00063 #define XNROOT 0x00400000
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086 #define XNTHREAD_STATE_LABELS { \
00087 'S', 'W', 'D', 'R', 'U', \
00088 '.', '.', '.', '.', 'X', \
00089 'H', 'b', 'T', 'l', 'r', \
00090 '.', 's', 't', 'o', '.', \
00091 'f', '.', '.', \
00092 }
00093
00094 #define XNTHREAD_BLOCK_BITS (XNSUSP|XNPEND|XNDELAY|XNDORMANT|XNRELAX|XNHELD)
00095 #define XNTHREAD_MODE_BITS (XNLOCK|XNRRB|XNASDI|XNSHIELD|XNTRAPSW|XNRPIOFF)
00096
00097
00098 #define XNTHREAD_STATE_SPARE0 0x10000000
00099 #define XNTHREAD_STATE_SPARE1 0x20000000
00100 #define XNTHREAD_STATE_SPARE2 0x40000000
00101 #define XNTHREAD_STATE_SPARE3 0x80000000
00102 #define XNTHREAD_STATE_SPARES 0xf0000000
00103
00110
00111
00112 #define XNTIMEO 0x00000001
00113 #define XNRMID 0x00000002
00114 #define XNBREAK 0x00000004
00115 #define XNKICKED 0x00000008
00116 #define XNWAKEN 0x00000010
00117 #define XNROBBED 0x00000020
00118 #define XNATOMIC 0x00000040
00119 #define XNAFFSET 0x00000080
00121
00122 #define XNTHREAD_INFO_SPARE0 0x10000000
00123 #define XNTHREAD_INFO_SPARE1 0x20000000
00124 #define XNTHREAD_INFO_SPARE2 0x40000000
00125 #define XNTHREAD_INFO_SPARE3 0x80000000
00126 #define XNTHREAD_INFO_SPARES 0xf0000000
00127
00129
00130 #if defined(__KERNEL__) || defined(__XENO_SIM__)
00131
00132 #include <nucleus/stat.h>
00133
00134 #ifdef __XENO_SIM__
00135
00136 #define XNRUNNING XNTHREAD_STATE_SPARE0
00137 #define XNDELETED XNTHREAD_STATE_SPARE1
00138 #endif
00139
00140 #define XNTHREAD_INVALID_ASR ((void (*)(xnsigmask_t))0)
00141
00142 struct xnthread;
00143 struct xnsched;
00144 struct xnsynch;
00145 struct xnrpi;
00146
00147 typedef struct xnthrops {
00148
00149 int (*get_denormalized_prio)(struct xnthread *);
00150 unsigned (*get_magic)(void);
00151
00152 } xnthrops_t;
00153
00154 typedef void (*xnasr_t)(xnsigmask_t sigs);
00155
00156 typedef struct xnthread {
00157
00158 xnarchtcb_t tcb;
00159
00160 xnflags_t state;
00161
00162 xnflags_t info;
00163
00164 struct xnsched *sched;
00165
00166 xnarch_cpumask_t affinity;
00167
00168 int bprio;
00169
00170 int cprio;
00171
00172 u_long schedlck;
00174 xnpholder_t rlink;
00175
00176 xnpholder_t plink;
00177
00178 #ifdef CONFIG_XENO_OPT_PRIOCPL
00179 xnpholder_t xlink;
00180
00181 struct xnrpi *rpi;
00182 #endif
00183
00184 xnholder_t glink;
00185
00186 #define link2thread(ln, fld) container_of(ln, xnthread_t, fld)
00187
00188 xnpqueue_t claimq;
00189
00190 struct xnsynch *wchan;
00191
00192 xntimer_t rtimer;
00193
00194 xntimer_t ptimer;
00195
00196 xnsigmask_t signals;
00197
00198 xnticks_t rrperiod;
00199
00200 xnticks_t rrcredit;
00201
00202 struct {
00203 xnstat_counter_t ssw;
00204 xnstat_counter_t csw;
00205 xnstat_counter_t pf;
00206 xnstat_exectime_t account;
00207 xnstat_exectime_t lastperiod;
00208 } stat;
00209
00210 int errcode;
00211
00212 xnasr_t asr;
00213
00214 xnflags_t asrmode;
00215
00216 int asrimask;
00217
00218 unsigned asrlevel;
00219
00220 int imask;
00221
00222 int imode;
00223
00224 int iprio;
00225
00226 #ifdef CONFIG_XENO_OPT_REGISTRY
00227 struct {
00228 xnhandle_t handle;
00229 const char *waitkey;
00230 } registry;
00231 #endif
00232
00233 xnthrops_t *ops;
00234
00235 char name[XNOBJECT_NAME_LEN];
00236
00237 void (*entry)(void *cookie);
00238
00239 void *cookie;
00240
00241 XNARCH_DECL_DISPLAY_CONTEXT();
00242
00243 } xnthread_t;
00244
00245 #define XNHOOK_THREAD_START 1
00246 #define XNHOOK_THREAD_SWITCH 2
00247 #define XNHOOK_THREAD_DELETE 3
00248
00249 typedef struct xnhook {
00250
00251 xnholder_t link;
00252 #define link2hook(ln) container_of(ln, xnhook_t, link)
00253
00254 void (*routine)(xnthread_t *thread);
00255
00256 } xnhook_t;
00257
00258 #define xnthread_name(thread) ((thread)->name)
00259 #define xnthread_clear_name(thread) do { *(thread)->name = 0; } while(0)
00260 #define xnthread_sched(thread) ((thread)->sched)
00261 #define xnthread_start_time(thread) ((thread)->stime)
00262 #define xnthread_state_flags(thread) ((thread)->state)
00263 #define xnthread_test_state(thread,flags) testbits((thread)->state,flags)
00264 #define xnthread_set_state(thread,flags) __setbits((thread)->state,flags)
00265 #define xnthread_clear_state(thread,flags) __clrbits((thread)->state,flags)
00266 #define xnthread_test_info(thread,flags) testbits((thread)->info,flags)
00267 #define xnthread_set_info(thread,flags) __setbits((thread)->info,flags)
00268 #define xnthread_clear_info(thread,flags) __clrbits((thread)->info,flags)
00269 #define xnthread_lock_count(thread) ((thread)->schedlck)
00270 #define xnthread_initial_priority(thread) ((thread)->iprio)
00271 #define xnthread_base_priority(thread) ((thread)->bprio)
00272 #define xnthread_current_priority(thread) ((thread)->cprio)
00273 #define xnthread_time_slice(thread) ((thread)->rrperiod)
00274 #define xnthread_time_credit(thread) ((thread)->rrcredit)
00275 #define xnthread_archtcb(thread) (&((thread)->tcb))
00276 #define xnthread_asr_level(thread) ((thread)->asrlevel)
00277 #define xnthread_pending_signals(thread) ((thread)->signals)
00278 #define xnthread_timeout(thread) xntimer_get_timeout(&(thread)->rtimer)
00279 #define xnthread_stack_size(thread) xnarch_stack_size(xnthread_archtcb(thread))
00280 #define xnthread_handle(thread) ((thread)->registry.handle)
00281 #ifdef CONFIG_XENO_OPT_TIMING_PERIODIC
00282 #define xnthread_time_base(thread) ((thread)->rtimer.base)
00283 #else
00284 #define xnthread_time_base(thread) (&nktbase)
00285 #endif
00286 #define xnthread_signaled_p(thread) ((thread)->signals != 0)
00287 #define xnthread_timed_p(thread) (!!testbits(xnthread_time_base(thread)->status, XNTBRUN))
00288 #define xnthread_user_task(thread) xnarch_user_task(xnthread_archtcb(thread))
00289 #define xnthread_user_pid(thread) \
00290 (xnthread_test_state((thread),XNROOT) || !xnthread_user_task(thread) ? \
00291 0 : xnarch_user_pid(xnthread_archtcb(thread)))
00292 #define xnthread_affinity(thread) ((thread)->affinity)
00293 #define xnthread_affine_p(thread, cpu) xnarch_cpu_isset(cpu, (thread)->affinity)
00294 #define xnthread_get_exectime(thread) xnstat_exectime_get_total(&(thread)->stat.account)
00295 #define xnthread_get_lastswitch(thread) xnstat_exectime_get_last_switch((thread)->sched)
00296
00297
00298 static inline int xnthread_get_denormalized_prio(xnthread_t *t)
00299 {
00300 return t->ops ? t->ops->get_denormalized_prio(t) : xnthread_current_priority(t);
00301 }
00302
00303 static inline unsigned xnthread_get_magic(xnthread_t *t)
00304 {
00305 return t->ops ? t->ops->get_magic() : 0;
00306 }
00307
00308 #ifdef __cplusplus
00309 extern "C" {
00310 #endif
00311
00312 int xnthread_init(xnthread_t *thread,
00313 xntbase_t *tbase,
00314 const char *name,
00315 int prio,
00316 xnflags_t flags,
00317 unsigned stacksize,
00318 xnthrops_t *ops);
00319
00320 void xnthread_cleanup_tcb(xnthread_t *thread);
00321
00322 char *xnthread_symbolic_status(xnflags_t status, char *buf, int size);
00323
00324 int *xnthread_get_errno_location(void);
00325
00326 static inline xnticks_t xnthread_get_timeout(xnthread_t *thread, xnticks_t tsc_ns)
00327 {
00328 xnticks_t timeout;
00329 xntimer_t *timer;
00330
00331 if (!xnthread_test_state(thread,XNDELAY))
00332 return 0LL;
00333
00334 if (xntimer_running_p(&thread->rtimer))
00335 timer = &thread->rtimer;
00336 else if (xntimer_running_p(&thread->ptimer))
00337 timer = &thread->ptimer;
00338 else
00339 return 0LL;
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353 if (xntbase_periodic_p(xnthread_time_base(thread)))
00354 return xntimer_get_timeout(timer);
00355
00356 timeout = xntimer_get_date(timer);
00357
00358 if (timeout <= tsc_ns)
00359 return 1;
00360
00361 return timeout - tsc_ns;
00362 }
00363
00364 static inline xnticks_t xnthread_get_period(xnthread_t *thread)
00365 {
00366 xnticks_t period = 0;
00367
00368
00369
00370
00371
00372
00373
00374
00375 if (xntimer_running_p(&thread->ptimer))
00376 period = xntimer_get_interval(&thread->ptimer);
00377 else if (xnthread_test_state(thread,XNRRB))
00378 period = xnthread_time_slice(thread);
00379
00380 return period;
00381 }
00382
00383 #ifdef __cplusplus
00384 }
00385 #endif
00386
00387 #endif
00388
00389 #endif