Xenomai API  2.6.5
task.h
Go to the documentation of this file.
1 
22 #ifndef _XENO_TASK_H
23 #define _XENO_TASK_H
24 
25 #include <nucleus/sched.h>
26 #include <native/types.h>
27 
28 /* Creation flags. */
29 #define T_FPU XNFPU
30 #define T_SUSP XNSUSP
31 /* <!> High bits must not conflict with XNFPU|XNSHADOW|XNSUSP. */
32 #define T_CPU(cpu) (1 << (24 + (cpu & 7))) /* Up to 8 cpus [0-7] */
33 #define T_CPUMASK 0xff000000
34 
42 #define T_BLOCKED XNPEND
43 #define T_DELAYED XNDELAY
44 #define T_READY XNREADY
45 #define T_DORMANT XNDORMANT
46 #define T_STARTED XNSTARTED
47 #define T_BOOST XNBOOST
48 #define T_LOCK XNLOCK
49 #define T_NOSIG XNASDI
50 #define T_WARNSW XNTRAPSW
51 #define T_RPIOFF XNRPIOFF
53 /* Pseudo-status bits (no conflict with other T_* bits) */
54 #define T_CONFORMING 0x00000200
55 #define T_JOINABLE 0x00000400
56  /* Ends doxygen-group native_task_status */
57 
58 /* Task hook types. */
59 #define T_HOOK_START XNHOOK_THREAD_START
60 #define T_HOOK_SWITCH XNHOOK_THREAD_SWITCH
61 #define T_HOOK_DELETE XNHOOK_THREAD_DELETE
62 #define T_DESC(cookie) thread2rtask(cookie)
63 
64 /* Priority range (POSIXish, same bounds as Xenomai's). */
65 #define T_LOPRIO XNSCHED_LOW_PRIO
66 #define T_HIPRIO XNSCHED_HIGH_PRIO
67 
68 typedef struct rt_task_placeholder {
69  xnhandle_t opaque;
70  unsigned long opaque2;
71 } RT_TASK_PLACEHOLDER;
72 
73 struct rt_queue_msg;
74 struct rt_task;
75 
80 typedef struct rt_task_info {
81 
82  int bprio;
84  int cprio;
86  unsigned status;
88  RTIME relpoint;
90  char name[XNOBJECT_NAME_LEN];
92  RTIME exectime;
98  int pagefaults;
100 } RT_TASK_INFO;
101 
102 #define RT_MCB_FSTORE_LIMIT 64
103 
107 typedef struct rt_task_mcb {
108 
109  int flowid;
111  int opcode;
113  caddr_t data;
115  size_t size;
117 } RT_TASK_MCB;
118 
119 #if (defined(__KERNEL__) || defined(__XENO_SIM__)) && !defined(DOXYGEN_CPP)
120 
121 #include <nucleus/synch.h>
122 
123 #define XENO_TASK_MAGIC 0x55550101
124 
125 typedef struct rt_task {
126 
127  unsigned magic; /* !< Magic code - must be first */
128 
129  xnholder_t link;
130 
131 #define link2rtask(ln) container_of(ln, RT_TASK, link)
132 
133  xnthread_t thread_base;
134 
135  char rname[XNOBJECT_NAME_LEN]; /* !< Name in registry. Not the same as
136  thread name for anonymous threads. */
137  int suspend_depth;
138 
139  int overrun;
140 
141  xnsynch_t safesynch; /* !< Safe synchronization object. */
142 
143  u_long safelock; /* !< Safe lock count. */
144 
145  u_long cstamp; /* !< Creation stamp. */
146 
147  xnarch_cpumask_t affinity;
148 
149  union { /* Saved args for current synch. wait operation. */
150 
151  struct {
152  int mode;
153  unsigned long mask;
154  } event;
155 
156 #ifdef CONFIG_XENO_OPT_NATIVE_MPS
157  struct {
158  RT_TASK_MCB mcb_s; /* Send area. */
159  RT_TASK_MCB mcb_r; /* Reply area. */
160  } mps;
161 #endif /* CONFIG_XENO_OPT_NATIVE_MPS */
162 
163  } wait_args;
164 
165 #ifdef CONFIG_XENO_OPT_NATIVE_MPS
166  xnsynch_t mrecv,
167  msendq;
168 
169  int flowgen; /* !< Flow id. generator. */
170 #endif /* CONFIG_XENO_OPT_NATIVE_MPS */
171 
172 } RT_TASK;
173 
174 static inline RT_TASK *thread2rtask (xnthread_t *t)
175 {
176  return t ? container_of(t, RT_TASK, thread_base) : NULL;
177 }
178 
179 #define xeno_current_task() thread2rtask(xnpod_current_thread())
180 
181 #ifdef __cplusplus
182 extern "C" {
183 #endif
184 
185 void __native_task_safe(RT_TASK *task);
186 
187 void __native_task_unsafe(RT_TASK *task);
188 
189 int __native_task_safewait(RT_TASK *task);
190 
191 int __native_task_pkg_init(void);
192 
193 void __native_task_pkg_cleanup(void);
194 
195 /* Public kernel interface */
196 
197 int rt_task_add_hook(int type,
198  void (*routine)(void *cookie));
199 
200 int rt_task_remove_hook(int type,
201  void (*routine)(void *cookie));
202 
203 int rt_task_catch(void (*handler)(rt_sigset_t));
204 
205 static inline int rt_task_same(RT_TASK *task1, RT_TASK *task2)
206 {
207  return task1 == task2;
208 }
209 
210 #ifdef __cplusplus
211 }
212 #endif
213 
214 #else /* !(__KERNEL__ || __XENO_SIM__) */
215 
216 typedef RT_TASK_PLACEHOLDER RT_TASK;
217 
218 #ifdef __cplusplus
219 extern "C" {
220 #endif
221 
222 int rt_task_shadow(RT_TASK *task,
223  const char *name,
224  int prio,
225  int mode);
226 
227 int rt_task_bind(RT_TASK *task,
228  const char *name,
229  RTIME timeout);
230 
231 static inline int rt_task_unbind (RT_TASK *task)
232 
233 {
234  task->opaque = XN_NO_HANDLE;
235  return 0;
236 }
237 
238 int rt_task_join(RT_TASK *task);
239 
240 #ifdef __cplusplus
241 }
242 #endif
243 
244 #endif /* __KERNEL__ || __XENO_SIM__ */
245 
246 #ifdef __cplusplus
247 extern "C" {
248 #endif
249 
250 /* Public interface */
251 
252 int rt_task_create(RT_TASK *task,
253  const char *name,
254  int stksize,
255  int prio,
256  int mode) __deprecated_in_kernel__;
257 
258 int rt_task_start(RT_TASK *task,
259  void (*fun)(void *cookie),
260  void *cookie);
261 
262 int rt_task_suspend(RT_TASK *task);
263 
264 int rt_task_resume(RT_TASK *task);
265 
266 int rt_task_delete(RT_TASK *task);
267 
268 int rt_task_yield(void);
269 
270 int rt_task_set_periodic(RT_TASK *task,
271  RTIME idate,
272  RTIME period);
273 
274 int rt_task_wait_period(unsigned long *overruns_r);
275 
276 int rt_task_set_priority(RT_TASK *task,
277  int prio);
278 
279 int rt_task_sleep(RTIME delay);
280 
281 int rt_task_sleep_until(RTIME date);
282 
283 int rt_task_unblock(RT_TASK *task);
284 
285 int rt_task_inquire(RT_TASK *task,
286  RT_TASK_INFO *info);
287 
288 int rt_task_notify(RT_TASK *task,
289  rt_sigset_t sigs);
290 
291 int rt_task_set_mode(int clrmask,
292  int setmask,
293  int *mode_r);
294 
295 RT_TASK *rt_task_self(void);
296 
297 int rt_task_slice(RT_TASK *task,
298  RTIME quantum);
299 
300 ssize_t rt_task_send(RT_TASK *task,
301  RT_TASK_MCB *mcb_s,
302  RT_TASK_MCB *mcb_r,
303  RTIME timeout);
304 
305 int rt_task_receive(RT_TASK_MCB *mcb_r,
306  RTIME timeout);
307 
308 int rt_task_reply(int flowid,
309  RT_TASK_MCB *mcb_s);
310 
311 static inline int rt_task_spawn(RT_TASK *task,
312  const char *name,
313  int stksize,
314  int prio,
315  int mode,
316  void (*entry)(void *cookie),
317  void *cookie)
318 {
319  int err = rt_task_create(task,name,stksize,prio,mode);
320 
321  if (!err)
322  err = rt_task_start(task,entry,cookie);
323 
324  return err;
325 }
326 
327 int rt_task_same(RT_TASK *task1, RT_TASK *task2);
328 
329 #ifdef __cplusplus
330 }
331 #endif
332 
333 #endif /* !_XENO_TASK_H */
int rt_task_wait_period(unsigned long *overruns_r)
Wait for the next periodic release point.
Definition: task.c:295
int rt_task_slice(RT_TASK *task, RTIME quantum)
Set a task's round-robin quantum.
Definition: task.c:386
int rt_task_notify(RT_TASK *task, rt_sigset_t sigs)
Send signals to a task.
Definition: task.c:353
ssize_t rt_task_send(RT_TASK *task, RT_TASK_MCB *mcb_s, RT_TASK_MCB *mcb_r, RTIME timeout)
Send a message to a task.
Definition: task.c:400
int rt_task_catch(void(*handler)(rt_sigset_t))
Install a signal handler.
Definition: task.c:1335
unsigned status
Task's status.
Definition: task.h:86
struct rt_task_info RT_TASK_INFO
Structure containing task-information useful to users.
Scheduler interface header.
int rt_task_add_hook(int type, void(*routine)(void *cookie))
Install a task hook.
Definition: task.c:1260
int rt_task_reply(int flowid, RT_TASK_MCB *mcb_s)
Reply to a task.
Definition: task.c:423
char name[XNOBJECT_NAME_LEN]
Symbolic name assigned at creation.
Definition: task.h:90
int rt_task_set_mode(int clrmask, int setmask, int *mode_r)
Change task mode bits.
Definition: task.c:359
int rt_task_yield(void)
Manual round-robin.
Definition: task.c:283
int rt_task_inquire(RT_TASK *task, RT_TASK_INFO *info)
Inquire about a real-time task.
Definition: task.c:347
int rt_task_start(RT_TASK *task, void(*fun)(void *cookie), void *cookie)
Start a real-time task.
Definition: task.c:178
int pagefaults
Number of triggered page faults.
Definition: task.h:98
int ctxswitches
Number of context switches.
Definition: task.h:96
int rt_task_suspend(RT_TASK *task)
Suspend a real-time task.
Definition: task.c:248
caddr_t data
Message address.
Definition: task.h:113
int rt_task_resume(RT_TASK *task)
Resume a real-time task.
Definition: task.c:253
int rt_task_delete(RT_TASK *task)
Delete a real-time task.
Definition: task.c:258
int rt_task_bind(RT_TASK *task, const char *name, RTIME timeout)
Bind to a real-time task.
Definition: task.c:242
int rt_task_join(RT_TASK *task)
Wait on the termination of a real-time task.
Definition: task.c:392
RTIME relpoint
Time of next release.
Definition: task.h:88
static int rt_task_unbind(RT_TASK *task)
Unbind from a real-time task.
Definition: task.h:231
int cprio
Current priority.
Definition: task.h:84
Structure containing task-information useful to users.
Definition: task.h:80
RT_TASK * rt_task_self(void)
Retrieve the current task.
Definition: task.c:370
Structure used in passing messages between tasks.
Definition: task.h:107
int rt_task_remove_hook(int type, void(*routine)(void *cookie))
Remove a task hook.
Definition: task.c:1298
int rt_task_set_priority(RT_TASK *task, int prio)
Change the base priority of a real-time task.
Definition: task.c:309
int rt_task_create(RT_TASK *task, const char *name, int stksize, int prio, int mode) __deprecated_in_kernel__
Create a new real-time task.
Definition: task.c:123
int rt_task_unblock(RT_TASK *task)
Unblock a real-time task.
Definition: task.c:342
int rt_task_shadow(RT_TASK *task, const char *name, int prio, int mode)
Turns the current Linux task into a native Xenomai task.
Definition: task.c:184
size_t size
Message size (bytes).
Definition: task.h:115
int rt_task_sleep_until(RTIME date)
Delay the calling task (absolute).
Definition: task.c:328
int rt_task_set_periodic(RT_TASK *task, RTIME idate, RTIME period)
Make a real-time task periodic.
Definition: task.c:288
struct rt_task_mcb RT_TASK_MCB
Structure used in passing messages between tasks.
int rt_task_same(RT_TASK *task1, RT_TASK *task2)
Compare two task descriptors.
Definition: task.c:429
int opcode
Operation code.
Definition: task.h:111
int modeswitches
Number of primary->secondary mode switches.
Definition: task.h:94
int flowid
Flow identifier.
Definition: task.h:109
int rt_task_sleep(RTIME delay)
Delay the calling task (relative).
Definition: task.c:315
RTIME exectime
Execution time in primary mode in nanoseconds.
Definition: task.h:92
This file is part of the Xenomai project.
int rt_task_receive(RT_TASK_MCB *mcb_r, RTIME timeout)
Receive a message from a task.
Definition: task.c:417
int bprio
Base priority.
Definition: task.h:82
static int rt_task_spawn(RT_TASK *task, const char *name, int stksize, int prio, int mode, void(*entry)(void *cookie), void *cookie)
Spawn a new real-time task.
Definition: task.h:311