Xenomai
3.0.5
|
Services dealing with preemptive multi-tasking. More...
Data Structures | |
struct | RT_TASK_INFO |
Task status descriptor. More... | |
Macros | |
#define | T_LOPRIO 0 |
Task priorities. More... | |
#define | T_LOCK __THREAD_M_LOCK |
Task mode bits. More... | |
#define | T_WARNSW __THREAD_M_WARNSW |
Cobalt only, nop over Mercury. More... | |
Functions | |
int | rt_task_delete (RT_TASK *task) |
Delete a real-time task. More... | |
int | rt_task_set_affinity (RT_TASK *task, const cpu_set_t *cpus) |
Set CPU affinity of real-time task. More... | |
int | rt_task_start (RT_TASK *task, void(*entry)(void *arg), void *arg) |
Start a real-time task. More... | |
int | rt_task_shadow (RT_TASK *task, const char *name, int prio, int mode) |
Turn caller into a real-time task. More... | |
int | rt_task_join (RT_TASK *task) |
Wait on the termination of a real-time task. More... | |
int | rt_task_wait_period (unsigned long *overruns_r) |
Wait for the next periodic release point. More... | |
int | rt_task_sleep (RTIME delay) |
Delay the current real-time task (with relative delay). More... | |
int | rt_task_sleep_until (RTIME date) |
Delay the current real-time task (with absolute wakeup date). More... | |
int | rt_task_same (RT_TASK *task1, RT_TASK *task2) |
Compare real-time task descriptors. More... | |
int | rt_task_suspend (RT_TASK *task) |
Suspend a real-time task. More... | |
int | rt_task_resume (RT_TASK *task) |
Resume a real-time task. More... | |
RT_TASK * | rt_task_self (void) |
Retrieve the current task descriptor. More... | |
int | rt_task_set_priority (RT_TASK *task, int prio) |
Change the base priority of a real-time task. More... | |
int | rt_task_set_mode (int clrmask, int setmask, int *mode_r) |
Change the current task mode. More... | |
int | rt_task_yield (void) |
Manual round-robin. More... | |
int | rt_task_unblock (RT_TASK *task) |
Unblock a real-time task. More... | |
int | rt_task_slice (RT_TASK *task, RTIME quantum) |
Set a task's round-robin quantum. More... | |
int | rt_task_inquire (RT_TASK *task, RT_TASK_INFO *info) |
Retrieve information about a real-time task. More... | |
ssize_t | rt_task_send_timed (RT_TASK *task, RT_TASK_MCB *mcb_s, RT_TASK_MCB *mcb_r, const struct timespec *abs_timeout) |
Send a message to a real-time task. More... | |
static ssize_t | rt_task_send_until (RT_TASK *task, RT_TASK_MCB *mcb_s, RT_TASK_MCB *mcb_r, RTIME timeout) |
Send a message to a real-time task (with absolute scalar timeout). More... | |
static 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 real-time task (with relative scalar timeout). More... | |
int | rt_task_receive_timed (RT_TASK_MCB *mcb_r, const struct timespec *abs_timeout) |
Receive a message from a real-time task. More... | |
static int | rt_task_receive_until (RT_TASK_MCB *mcb_r, RTIME timeout) |
Receive a message from a real-time task (with absolute scalar timeout). More... | |
static int | rt_task_receive (RT_TASK_MCB *mcb_r, RTIME timeout) |
Receive a message from a real-time task (with relative scalar timeout). More... | |
int | rt_task_reply (int flowid, RT_TASK_MCB *mcb_s) |
Reply to a remote task message. More... | |
int | rt_task_bind (RT_TASK *task, const char *name, RTIME timeout) |
Bind to a task. More... | |
int | rt_task_unbind (RT_TASK *task) |
Unbind from a task. More... | |
int | rt_task_create (RT_TASK *task, const char *name, int stksize, int prio, int mode) |
Create a task with Alchemy personality. More... | |
int | rt_task_set_periodic (RT_TASK *task, RTIME idate, RTIME period) |
Make a real-time task periodic. More... | |
int | rt_task_spawn (RT_TASK *task, const char *name, int stksize, int prio, int mode, void(*entry)(void *arg), void *arg) |
Create and start a real-time task. More... | |
Services dealing with preemptive multi-tasking.
Each Alchemy task is an independent portion of the overall application code embodied in a C procedure, which executes on its own stack context.
#define T_LOCK __THREAD_M_LOCK |
Task mode bits.
Referenced by rt_task_set_mode().
#define T_LOPRIO 0 |
Task priorities.
#define T_WARNSW __THREAD_M_WARNSW |
Cobalt only, nop over Mercury.
Referenced by rt_task_set_mode().
int rt_task_bind | ( | RT_TASK * | task, |
const char * | name, | ||
RTIME | timeout | ||
) |
Bind to a task.
This routine creates a new descriptor to refer to an existing Alchemy task identified by its symbolic name. If the object does not exist on entry, the caller may block until a task of the given name is created.
task | The address of a task descriptor filled in by the operation. Contents of this memory is undefined upon failure. |
name | A valid NULL-terminated name which identifies the task to bind to. This string should match the object name argument passed to rt_task_create(), or rt_task_shadow(). |
timeout | The number of clock ticks to wait for the registration to occur (see note). Passing TM_INFINITE causes the caller to block indefinitely until the object is registered. Passing TM_NONBLOCK causes the service to return immediately without waiting if the object is not registered on entry. |
int rt_task_create | ( | RT_TASK * | task, |
const char * | name, | ||
int | stksize, | ||
int | prio, | ||
int | mode | ||
) |
Create a task with Alchemy personality.
This service creates a task with access to the full set of Alchemy services. If prio is non-zero, the new task belongs to Xenomai's real-time FIFO scheduling class, aka SCHED_FIFO. If prio is zero, the task belongs to the regular SCHED_OTHER class.
Creating tasks with zero priority is useful for running non real-time processes which may invoke blocking real-time services, such as pending on a semaphore, reading from a message queue or a buffer, and so on.
Once created, the task is left dormant until it is actually started by rt_task_start().
task | The address of a task descriptor which can be later used to identify uniquely the created object, upon success of this call. |
name | An ASCII string standing for the symbolic name of the task. When non-NULL and non-empty, a copy of this string is used for indexing the created task into the object registry. |
stksize | The size of the stack (in bytes) for the new task. If zero is passed, a system-dependent default size will be substituted. |
prio | The base priority of the new task. This value must be in the [0 .. 99] range, where 0 is the lowest effective priority. |
mode | The task creation mode. The following flags can be OR'ed into this bitmask: |
int rt_task_delete | ( | RT_TASK * | task | ) |
Delete a real-time task.
This call terminates a task previously created by rt_task_create().
Tasks created with the T_JOINABLE flag shall be joined by a subsequent call to rt_task_join() once successfully deleted, to reclaim all resources.
task | The task descriptor. |
int rt_task_inquire | ( | RT_TASK * | task, |
RT_TASK_INFO * | info | ||
) |
Retrieve information about a real-time task.
Return various information about an Alchemy task. This service may also be used to probe for task existence.
task | The task descriptor. If task is NULL, the information about the current task is returned. |
info | The address of a structure the task information will be written to. Passing NULL is valid, in which case the system is only probed for existence of the specified task. |
int rt_task_join | ( | RT_TASK * | task | ) |
Wait on the termination of a real-time task.
This service blocks the caller in non-real-time context until task has terminated. All resources are released after successful completion of this service.
The specified task must have been created by the same process that wants to join it, and the T_JOINABLE mode flag must have been set on creation to rt_task_create().
Tasks created with the T_JOINABLE flag shall be joined by a subsequent call to rt_task_join() once successfully deleted, to reclaim all resources.
task | The task descriptor. |
|
inlinestatic |
Receive a message from a real-time task (with relative scalar timeout).
This routine is a variant of rt_task_receive_timed() accepting a relative timeout specification expressed as a scalar value.
mcb_r | The address of a message control block referring to the receive message area. |
timeout | A delay expressed in clock ticks. |
References rt_task_receive_timed().
int rt_task_receive_timed | ( | RT_TASK_MCB * | mcb_r, |
const struct timespec * | abs_timeout | ||
) |
Receive a message from a real-time task.
This service is part of the synchronous message passing support available to Alchemy tasks. The caller receives a variable-sized message from another task. The sender is blocked until the caller invokes rt_task_reply() to finish the transaction.
A basic message control block is used to store the location and size of the data area to receive from the client, in addition to a user-defined operation code.
mcb_r | The address of a message control block referring to the receive message area. The fields from this control block should be set as follows: |
Upon return, mcb_r->opcode will contain the operation code sent from the remote task using rt_task_send().
abs_timeout | The number of clock ticks to wait for receiving a message (see note). Passing NULL causes the caller to block indefinitely until a remote task eventually sends a message. Passing { .tv_sec = 0, .tv_nsec = 0 } causes the service to return immediately without waiting if no remote task is currently waiting for sending a message. |
Referenced by rt_task_receive(), and rt_task_receive_until().
|
inlinestatic |
Receive a message from a real-time task (with absolute scalar timeout).
This routine is a variant of rt_task_receive_timed() accepting an absolute timeout specification expressed as a scalar value.
mcb_r | The address of a message control block referring to the receive message area. |
abs_timeout | An absolute date expressed in clock ticks. |
References rt_task_receive_timed().
int rt_task_reply | ( | int | flowid, |
RT_TASK_MCB * | mcb_s | ||
) |
Reply to a remote task message.
This service is part of the synchronous message passing support available to Alchemy tasks. The caller sends a variable-sized message back to a remote task, in response to this task's initial message received by a call to rt_task_receive(). As a consequence of calling rt_task_reply(), the remote task will be unblocked from the rt_task_send() service.
A basic message control block is used to store the location and size of the data area to send back, in addition to a user-defined status code.
flowid | The flow identifier returned by a previous call to rt_task_receive() which uniquely identifies the current transaction. |
mcb_s | The address of an optional message control block referring to the message to be sent back. If mcb_s is NULL, the remote will be unblocked without getting any reply data. When mcb_s is valid, the fields from this control block should be set as follows: |
int rt_task_resume | ( | RT_TASK * | task | ) |
Resume a real-time task.
Forcibly resume the execution of a task which was previously suspended by a call to rt_task_suspend(), if the suspend nesting count decrements to zero.
task | The task descriptor. |
int rt_task_same | ( | RT_TASK * | task1, |
RT_TASK * | task2 | ||
) |
Compare real-time task descriptors.
This predicate returns true if task1 and task2 refer to the same task.
task1 | First task descriptor to compare. |
task2 | Second task descriptor to compare. |
RT_TASK * rt_task_self | ( | void | ) |
Retrieve the current task descriptor.
Return the address of the current Alchemy task descriptor.
|
inlinestatic |
Send a message to a real-time task (with relative scalar timeout).
This routine is a variant of rt_task_send_timed() accepting a relative timeout specification expressed as a scalar value.
task | The task descriptor. |
mcb_s | The address of the message control block referring to the message to be sent. |
mcb_r | The address of an optional message control block referring to the reply message area. |
timeout | A delay expressed in clock ticks. |
References rt_task_send_timed().
ssize_t rt_task_send_timed | ( | RT_TASK * | task, |
RT_TASK_MCB * | mcb_s, | ||
RT_TASK_MCB * | mcb_r, | ||
const struct timespec * | abs_timeout | ||
) |
Send a message to a real-time task.
This service is part of the synchronous message passing support available to Alchemy tasks. The caller sends a variable-sized message to another task, waiting for the remote to receive the initial message by a call to rt_task_receive(), then reply to it using rt_task_reply().
A basic message control block is used to store the location and size of the data area to send or retrieve upon reply, in addition to a user-defined operation code.
task | The task descriptor. |
mcb_s | The address of the message control block referring to the message to be sent. The fields from this control block should be set as follows: |
mcb_r | The address of an optional message control block referring to the reply message area. If mcb_r is NULL and a reply is sent back by the remote task, the reply message will be discarded, and -ENOBUFS will be returned to the caller. When mcb_r is valid, the fields from this control block should be set as follows: |
Upon return, mcb_r->opcode will contain the status code sent back from the remote task using rt_task_reply(), or zero if unspecified.
abs_timeout | An absolute date expressed in clock ticks, specifying a time limit to wait for the recipient task to reply to the initial message (see note). Passing NULL causes the caller to block indefinitely until a reply is received. Passing { .tv_sec = 0, .tv_nsec = 0 } causes the service to return without blocking in case the recipient task is not waiting for messages at the time of the call. |
Referenced by rt_task_send(), and rt_task_send_until().
|
inlinestatic |
Send a message to a real-time task (with absolute scalar timeout).
This routine is a variant of rt_task_send_timed() accepting an absolute timeout specification expressed as a scalar value.
task | The task descriptor. |
mcb_s | The address of the message control block referring to the message to be sent. |
mcb_r | The address of an optional message control block referring to the reply message area. |
abs_timeout | An absolute date expressed in clock ticks. |
References rt_task_send_timed().
int rt_task_set_affinity | ( | RT_TASK * | task, |
const cpu_set_t * | cpus | ||
) |
Set CPU affinity of real-time task.
This calls makes task affine to the set of CPUs defined by cpus.
task | The task descriptor. If task is NULL, the CPU affinity of the current task is changed. |
cpus | The set of CPUs task should be affine to. |
int rt_task_set_mode | ( | int | clrmask, |
int | setmask, | ||
int * | mode_r | ||
) |
Change the current task mode.
Each Alchemy task has a set of internal flags determining several operating conditions. rt_task_set_mode() takes a bitmask of mode bits to clear for disabling the corresponding modes for the current task, and another one to set for enabling them. The mode bits which were previously in effect before the change can be returned upon request.
The following bits can be part of the bitmask:
These two last flags have no effect over the Mercury core, and are simply ignored.
clrmask | A bitmask of mode bits to clear for the current task, before setmask is applied. Zero is an acceptable value which leads to a no-op. |
setmask | A bitmask of mode bits to set for the current task. Zero is an acceptable value which leads to a no-op. |
mode_r | If non-NULL, mode_r must be a pointer to a memory location which will be written upon success with the previous set of active mode bits. If NULL, the previous set of active mode bits will not be returned. |
int rt_task_set_periodic | ( | RT_TASK * | task, |
RTIME | idate, | ||
RTIME | period | ||
) |
Make a real-time task periodic.
Make a task periodic by programing its first release point and its period in the processor time line. task should then call rt_task_wait_period() to sleep until the next periodic release point in the processor timeline is reached.
task | The task descriptor. If task is NULL, the current task is made periodic. task must belong the current process. |
idate | The initial (absolute) date of the first release point, expressed in clock ticks (see note). If idate is equal to TM_NOW, the current system date is used. |
period | The period of the task, expressed in clock ticks (see note). Passing TM_INFINITE stops the task's periodic timer if enabled, then returns successfully. |
int rt_task_set_priority | ( | RT_TASK * | task, |
int | prio | ||
) |
Change the base priority of a real-time task.
The base priority of a task defines the relative importance of the work being done by each task, which gains conrol of the CPU accordingly.
Changing the base priority of a task does not affect the priority boost the target task might have obtained as a consequence of a priority inheritance undergoing.
task | The task descriptor. If task is NULL, the priority of the current task is changed. |
prio | The new priority. This value must range from [T_LOPRIO .. T_HIPRIO] (inclusive) where T_LOPRIO is the lowest effective priority. |
int rt_task_shadow | ( | RT_TASK * | task, |
const char * | name, | ||
int | prio, | ||
int | mode | ||
) |
Turn caller into a real-time task.
Set the calling thread personality to the Alchemy API, enabling the full set of Alchemy services. Upon success, the caller is no more a regular POSIX thread, but a Xenomai-extended thread.
If prio is non-zero, the new task moves to Xenomai's real-time FIFO scheduling class, aka SCHED_FIFO. If prio is zero, the task moves to the regular SCHED_OTHER class.
Running Xenomai tasks with zero priority is useful for running non real-time processes which may invoke blocking real-time services, such as pending on a semaphore, reading from a message queue or a buffer, and so on.
task | If non-NULL, the address of a task descriptor which can be later used to identify uniquely the task, upon success of this call. If NULL, no descriptor is returned. |
name | An ASCII string standing for the symbolic name of the task. When non-NULL and non-empty, a copy of this string is used for indexing the task into the object registry. |
prio | The base priority of the task. This value must be in the [0 .. 99] range, where 0 is the lowest effective priority. |
mode | The task shadowing mode. The following flags can be OR'ed into this bitmask: |
int rt_task_sleep | ( | RTIME | delay | ) |
Delay the current real-time task (with relative delay).
This routine is a variant of rt_task_sleep_until() accepting a relative timeout specification.
delay | A relative delay expressed in clock ticks (see note). A zero delay causes this service to return immediately to the caller with a success status. |
int rt_task_sleep_until | ( | RTIME | date | ) |
Delay the current real-time task (with absolute wakeup date).
Delay the execution of the calling task until a given date is reached. The caller is put to sleep, and does not consume any CPU time in such a state.
date | An absolute date expressed in clock ticks, specifying a wakeup date (see note). As a special case, TM_INFINITE is an acceptable value that causes the caller to block indefinitely, until rt_task_unblock() is called against it. Otherwise, any wake up date in the past causes the task to return immediately. |
int rt_task_slice | ( | RT_TASK * | task, |
RTIME | quantum | ||
) |
Set a task's round-robin quantum.
Set the time credit allotted to a task undergoing the round-robin scheduling. If quantum is non-zero, rt_task_slice() also refills the current quantum for the target task, otherwise, time-slicing is stopped for that task.
In other words, rt_task_slice() should be used to toggle round-robin scheduling for an Alchemy task.
task | The task descriptor. If task is NULL, the time credit of the current task is changed. task must belong to the current process. |
quantum | The round-robin quantum for the task expressed in clock ticks (see note). |
int rt_task_spawn | ( | RT_TASK * | task, |
const char * | name, | ||
int | stksize, | ||
int | prio, | ||
int | mode, | ||
void(*)(void *arg) | entry, | ||
void * | arg | ||
) |
Create and start a real-time task.
This service spawns a task by combining calls to rt_task_create() and rt_task_start() for the new task.
task | The address of a task descriptor which can be later used to identify uniquely the created object, upon success of this call. |
name | An ASCII string standing for the symbolic name of the task. When non-NULL and non-empty, a copy of this string is used for indexing the created task into the object registry. |
stksize | The size of the stack (in bytes) for the new task. If zero is passed, a system-dependent default size will be substituted. |
prio | The base priority of the new task. This value must be in the [0 .. 99] range, where 0 is the lowest effective priority. |
mode | The task creation mode. See rt_task_create(). |
entry | The address of the task entry point. |
arg | A user-defined opaque argument entry will receive. |
int rt_task_start | ( | RT_TASK * | task, |
void(*)(void *arg) | entry, | ||
void * | arg | ||
) |
Start a real-time task.
This call starts execution of a task previously created by rt_task_create(). This service causes the started task to leave the initial dormant state.
task | The task descriptor. |
entry | The address of the task entry point. |
arg | A user-defined opaque argument entry will receive. |
int rt_task_suspend | ( | RT_TASK * | task | ) |
Suspend a real-time task.
Forcibly suspend the execution of a task. This task will not be eligible for scheduling until it is explicitly resumed by a call to rt_task_resume(). In other words, the suspended state caused by a call to rt_task_suspend() is cumulative with respect to the delayed and blocked states caused by other services, and is managed separately from them.
A nesting count is maintained so that rt_task_suspend() and rt_task_resume() must be used in pairs.
Receiving a Linux signal causes the suspended task to resume immediately.
task | The task descriptor. If task is NULL, the current task is suspended. |
int rt_task_unbind | ( | RT_TASK * | task | ) |
Unbind from a task.
task | The task descriptor. |
This routine releases a previous binding to an Alchemy task. After this call has returned, the descriptor is no more valid for referencing this object.
int rt_task_unblock | ( | RT_TASK * | task | ) |
Unblock a real-time task.
Break the task out of any wait it is currently in. This call clears all delay and/or resource wait condition for the target task.
However, rt_task_unblock() does not resume a task which has been forcibly suspended by a previous call to rt_task_suspend(). If all suspensive conditions are gone, the task becomes eligible anew for scheduling.
task | The task descriptor. |
int rt_task_wait_period | ( | unsigned long * | overruns_r | ) |
Wait for the next periodic release point.
Delay the current task until the next periodic release point is reached. The periodic timer should have been previously started for task by a call to rt_task_set_periodic().
overruns_r | If non-NULL, overruns_r shall be a pointer to a memory location which will be written with the count of pending overruns. This value is written to only when rt_task_wait_period() returns -ETIMEDOUT or success. The memory location remains unmodified otherwise. If NULL, this count will not be returned. |
int rt_task_yield | ( | void | ) |
Manual round-robin.
Move the current task to the end of its priority group, so that the next equal-priority task in ready state is switched in.