Xenomai
3.0.5
|
Modules | |
Thread state flags | |
Bits reporting permanent or transient states of threads. | |
Thread information flags | |
Bits reporting events notified to threads. | |
Functions | |
static struct xnthread * | xnthread_current (void) |
Retrieve the current Cobalt core TCB. More... | |
static struct xnthread * | xnthread_from_task (struct task_struct *p) |
Retrieve the Cobalt core TCB attached to a Linux task. More... | |
static void | xnthread_test_cancel (void) |
Introduce a thread cancellation point. More... | |
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. More... | |
int | xnthread_start (struct xnthread *thread, const struct xnthread_start_attr *attr) |
Start a newly created thread. More... | |
int | xnthread_set_mode (int clrmask, int setmask) |
Change control mode of the current thread. More... | |
void | xnthread_suspend (struct xnthread *thread, int mask, xnticks_t timeout, xntmode_t timeout_mode, struct xnsynch *wchan) |
Suspend a thread. More... | |
void | xnthread_resume (struct xnthread *thread, int mask) |
Resume a thread. More... | |
int | xnthread_unblock (struct xnthread *thread) |
Unblock a thread. More... | |
int | xnthread_set_periodic (struct xnthread *thread, xnticks_t idate, xntmode_t timeout_mode, xnticks_t period) |
Make a thread periodic. More... | |
int | xnthread_wait_period (unsigned long *overruns_r) |
Wait for the next periodic release point. More... | |
int | xnthread_set_slice (struct xnthread *thread, xnticks_t quantum) |
Set thread time-slicing information. More... | |
void | xnthread_cancel (struct xnthread *thread) |
Cancel a thread. More... | |
int | xnthread_join (struct xnthread *thread, bool uninterruptible) |
Join with a terminated thread. More... | |
int | xnthread_harden (void) |
Migrate a Linux task to the Xenomai domain. More... | |
void | xnthread_relax (int notify, int reason) |
Switch a shadow thread back to the Linux domain. More... | |
int | xnthread_map (struct xnthread *thread, struct completion *done) |
Create a shadow thread context over a kernel task. More... | |
int | xnthread_migrate (int cpu) |
Migrate the current thread. More... | |
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. More... | |
void xnthread_cancel | ( | struct xnthread * | thread | ) |
Cancel a thread.
Request cancellation of a thread. This service forces thread to exit from any blocking call, then to switch to secondary mode. thread will terminate as soon as it reaches a cancellation point. Cancellation points are defined for the following situations:
thread | The descriptor address of the thread to terminate. |
|
static |
Retrieve the current Cobalt core TCB.
Returns the address of the current Cobalt core thread descriptor, or NULL if running over a regular Linux task. This call is not affected by the current runtime mode of the core thread.
Referenced by xnsynch_acquire(), xnsynch_sleep_on(), xnsynch_try_acquire(), xnthread_harden(), xnthread_join(), xnthread_relax(), xnthread_set_periodic(), xnthread_test_cancel(), and xnthread_wait_period().
|
static |
Retrieve the Cobalt core TCB attached to a Linux task.
Returns the address of the Cobalt core thread descriptor attached to the Linux task p, or NULL if p is a regular Linux task. This call is not affected by the current runtime mode of the core thread.
int xnthread_harden | ( | void | ) |
Migrate a Linux task to the Xenomai domain.
This service causes the transition of "current" from the Linux domain to Xenomai. The shadow will resume in the Xenomai domain as returning from schedule().
References xnthread_current().
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.
Initializes a new thread. The thread is left dormant until it is actually started by xnthread_start().
thread | The address of a thread descriptor Cobalt will use to store the thread-specific data. This descriptor must always be valid while the thread is active therefore it must be allocated in permanent memory. |
attr | A pointer to an attribute block describing the initial properties of the new thread. Members of this structure are defined as follows: |
sched_class | The initial scheduling class the new thread should be assigned to. |
sched_param | The initial scheduling parameters to set for the new thread; sched_param must be valid within the context of sched_class. |
int xnthread_join | ( | struct xnthread * | thread, |
bool | uninterruptible | ||
) |
Join with a terminated thread.
This service waits for thread to terminate after a call to xnthread_cancel(). If that thread has already terminated or is dormant at the time of the call, then xnthread_join() returns immediately.
xnthread_join() adapts to the calling context (primary or secondary), switching to secondary mode if needed for the duration of the wait. Upon return, the original runtime mode is restored, unless a Linux signal is pending.
thread | The descriptor address of the thread to join with. |
uninterruptible | Boolean telling whether the service should wait for completion uninterruptible. |
References xnthread_current().
Referenced by rtdm_task_join().
int xnthread_map | ( | struct xnthread * | thread, |
struct completion * | done | ||
) |
Create a shadow thread context over a kernel task.
This call maps a Cobalt core thread to the "current" Linux task running in kernel space. The priority and scheduling class of the underlying Linux task are not affected; it is assumed that the caller did set them appropriately before issuing the shadow mapping request.
This call immediately moves the calling kernel thread to the Xenomai domain.
thread | The descriptor address of the new shadow thread to be mapped to "current". This descriptor must have been previously initialized by a call to xnthread_init(). |
done | A completion object to be signaled when thread is fully mapped over the current Linux context, waiting for xnthread_start(). |
int xnthread_migrate | ( | int | cpu | ) |
Migrate the current thread.
This call makes the current thread migrate to another (real-time) CPU if its affinity allows it. This call is available from primary mode only.
cpu | The destination CPU. |
0 | if the thread could migrate ; |
-EPERM | if the calling context is invalid, or the scheduler is locked. |
-EINVAL | if the current thread affinity forbids this migration. |
void xnthread_relax | ( | int | notify, |
int | reason | ||
) |
Switch a shadow thread back to the Linux domain.
This service yields the control of the running shadow back to Linux. This is obtained by suspending the shadow and scheduling a wake up call for the mated user task inside the Linux domain. The Linux task will resume on return from xnthread_suspend() on behalf of the root thread.
notify | A boolean flag indicating whether threads monitored from secondary mode switches should be sent a SIGDEBUG signal. For instance, some internal operations like task exit should not trigger such signal. |
reason | The reason to report along with the SIGDEBUG signal. |
References splmax, and xnthread_current().
void xnthread_resume | ( | struct xnthread * | thread, |
int | mask | ||
) |
Resume a thread.
Resumes the execution of a thread previously suspended by one or more calls to xnthread_suspend(). This call removes a suspensive condition affecting the target thread. When all suspensive conditions are gone, the thread is left in a READY state at which point it becomes eligible anew for scheduling.
thread | The descriptor address of the resumed thread. |
mask | The suspension mask specifying the suspensive condition to remove from the thread's wait mask. Possible values usable by the caller are: |
When the thread is eventually resumed by one or more calls to xnthread_resume(), the caller of xnthread_suspend() in the awakened thread that suspended itself should check for the following bits in its own information mask to determine what caused its wake up:
int xnthread_set_mode | ( | int | clrmask, |
int | setmask | ||
) |
Change control mode of the current thread.
Change the control mode of the current thread. The control mode affects several behaviours of the Cobalt core regarding this thread.
clrmask | Clears the corresponding bits from the control mode before setmask is applied. The scheduler lock held by the current thread can be forcibly released by passing the XNLOCK bit in this mask. In this case, the lock nesting count is also reset to zero. |
setmask | The new thread mode. The following flags may be set in this bitmask: |
int xnthread_set_periodic | ( | struct xnthread * | thread, |
xnticks_t | idate, | ||
xntmode_t | timeout_mode, | ||
xnticks_t | period | ||
) |
Make a thread periodic.
Make a thread periodic by programming its first release point and its period in the processor time line. Subsequent calls to xnthread_wait_period() will delay the thread until the next periodic release point in the processor timeline is reached.
thread | The core thread to make periodic. If NULL, the current thread is assumed. |
idate | The initial (absolute) date of the first release point, expressed in nanoseconds. The affected thread will be delayed by the first call to xnthread_wait_period() until this point is reached. If idate is equal to XN_INFINITE, the first release point is set to period nanoseconds after the current date. In the latter case, timeout_mode is not considered and can have any valid value. |
timeout_mode | The mode of the idate parameter. It can either be set to XN_ABSOLUTE or XN_REALTIME with idate different from XN_INFINITE (see also xntimer_start()). |
period | The period of the thread, expressed in nanoseconds. As a side-effect, passing XN_INFINITE attempts to stop the thread's periodic timer; in the latter case, the routine always exits succesfully, regardless of the previous state of this timer. |
References xnsched::cpu, and xnthread_current().
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.
Changes the base scheduling policy and paramaters of a thread. If the thread is currently blocked, waiting in priority-pending mode (XNSYNCH_PRIO) for a synchronization object to be signaled, Cobalt will attempt to reorder the object's wait queue so that it reflects the new sleeper's priority, unless the XNSYNCH_DREORD flag has been set for the pended object.
thread | The descriptor address of the affected thread. See note. |
sched_class | The new scheduling class the thread should be assigned to. |
sched_param | The scheduling parameters to set for the thread; sched_param must be valid within the context of sched_class. |
It is absolutely required to use this service to change a thread priority, in order to have all the needed housekeeping chores correctly performed. i.e. Do not call xnsched_set_policy() directly or worse, change the thread.cprio field by hand in any case.
int xnthread_set_slice | ( | struct xnthread * | thread, |
xnticks_t | quantum | ||
) |
Set thread time-slicing information.
Update the time-slicing information for a given thread. This service enables or disables round-robin scheduling for the thread, depending on the value of quantum. By default, times-slicing is disabled for a new thread initialized by a call to xnthread_init().
thread | The descriptor address of the affected thread. |
quantum | The time quantum assigned to the thread expressed in nanoseconds. If quantum is different from XN_INFINITE, the time-slice for the thread is set to that value and its current time credit is refilled (i.e. the thread is given a full time-slice to run next). Otherwise, if quantum equals XN_INFINITE, time-slicing is stopped for that thread. |
int xnthread_start | ( | struct xnthread * | thread, |
const struct xnthread_start_attr * | attr | ||
) |
Start a newly created thread.
Starts a (newly) created thread, scheduling it for the first time. This call releases the target thread from the XNDORMANT state. This service also sets the initial mode for the new thread.
thread | The descriptor address of the started thread which must have been previously initialized by a call to xnthread_init(). |
attr | A pointer to an attribute block describing the execution properties of the new thread. Members of this structure are defined as follows: |
0 | if thread could be started ; |
-EBUSY | if thread was not dormant or stopped ; |
void xnthread_suspend | ( | struct xnthread * | thread, |
int | mask, | ||
xnticks_t | timeout, | ||
xntmode_t | timeout_mode, | ||
struct xnsynch * | wchan | ||
) |
Suspend a thread.
Suspends the execution of a thread according to a given suspensive condition. This thread will not be eligible for scheduling until it all the pending suspensive conditions set by this service are removed by one or more calls to xnthread_resume().
thread | The descriptor address of the suspended thread. |
mask | The suspension mask specifying the suspensive condition to add to the thread's wait mask. Possible values usable by the caller are: |
timeout | The timeout which may be used to limit the time the thread pends on a resource. This value is a wait time given in nanoseconds. It can either be relative, absolute monotonic, or absolute adjustable depending on timeout_mode. |
Passing XN_INFINITE and setting timeout_mode to XN_RELATIVE specifies an unbounded wait. All other values are used to initialize a watchdog timer. If the current operation mode of the system timer is oneshot and timeout elapses before xnthread_suspend() has completed, then the target thread will not be suspended, and this routine leads to a null effect.
timeout_mode | The mode of the timeout parameter. It can either be set to XN_RELATIVE, XN_ABSOLUTE, or XN_REALTIME (see also xntimer_start()). |
wchan | The address of a pended resource. This parameter is used internally by the synchronization object implementation code to specify on which object the suspended thread pends. NULL is a legitimate value when this parameter does not apply to the current suspending mode (e.g. XNSUSP). |
|
inlinestatic |
Introduce a thread cancellation point.
Terminates the current thread if a cancellation request is pending for it, i.e. if xnthread_cancel() was called.
References xnthread_current().
int xnthread_unblock | ( | struct xnthread * | thread | ) |
Unblock a thread.
Breaks the thread out of any wait it is currently in. This call removes the XNDELAY and XNPEND suspensive conditions previously put by xnthread_suspend() on the target thread. If all suspensive conditions are gone, the thread is left in a READY state at which point it becomes eligible anew for scheduling.
thread | The descriptor address of the unblocked thread. |
This call neither releases the thread from the XNSUSP, XNRELAX, XNDORMANT or XNHELD suspensive conditions.
When the thread resumes execution, the XNBREAK bit is set in the unblocked thread's information mask. Unblocking a non-blocked thread is perfectly harmless.
int xnthread_wait_period | ( | unsigned long * | overruns_r | ) |
Wait for the next periodic release point.
Make the current thread wait for the next periodic release point in the processor time line.
overruns_r | If non-NULL, overruns_r must be a pointer to a memory location which will be written with the count of pending overruns. This value is copied only when xnthread_wait_period() returns -ETIMEDOUT or success; the memory location remains unmodified otherwise. If NULL, this count will never be copied back. |
References xnthread_current().