Real-time pod services.
[Xenomai nucleus.]

Collaboration diagram for Real-time pod services.:

Detailed Description

Real-time pod services.


Files

file  pod.h
 Real-time pod interface header.
file  pod.c
 Real-time pod services.

Data Structures

struct  xnsched_t
 Scheduling information structure. More...
struct  xnpod
 Real-time pod descriptor. More...

Functions

void xnpod_schedule_runnable (xnthread_t *thread, int flags)
 Hidden rescheduling procedure.
int xnpod_init (void)
 Initialize the core pod.
int xnpod_enable_timesource (void)
 Activate the core time source.
void xnpod_disable_timesource (void)
 Stop the core time source.
void xnpod_shutdown (int xtype)
 Shutdown the current pod.
int xnpod_init_thread (xnthread_t *thread, xntbase_t *tbase, const char *name, int prio, xnflags_t flags, unsigned stacksize, xnthrops_t *ops)
 Initialize a new thread.
int xnpod_start_thread (xnthread_t *thread, xnflags_t mode, int imask, xnarch_cpumask_t affinity, void(*entry)(void *cookie), void *cookie)
 Initial start of a newly created thread.
void xnpod_restart_thread (xnthread_t *thread)
 Restart a thread.
void xnpod_delete_thread (xnthread_t *thread)
 Delete a thread.
void xnpod_abort_thread (xnthread_t *thread)
 Abort a thread.
xnflags_t xnpod_set_thread_mode (xnthread_t *thread, xnflags_t clrmask, xnflags_t setmask)
 Change a thread's control mode.
void xnpod_resume_thread (xnthread_t *thread, xnflags_t mask)
 Resume a thread.
int xnpod_unblock_thread (xnthread_t *thread)
 Unblock a thread.
void xnpod_renice_thread (xnthread_t *thread, int prio)
 Change the base priority of a thread.
int xnpod_migrate_thread (int cpu)
void xnpod_rotate_readyq (int prio)
 Rotate a priority level in the ready queue.
void xnpod_do_rr (void)
 Handle the round-robin scheduling policy.
void xnpod_schedule (void)
 Rescheduling procedure entry point.
void xnpod_dispatch_signals (void)
 Deliver pending asynchronous signals to the running thread.
void xnpod_activate_rr (xnticks_t quantum)
 Globally activate the round-robin scheduling.
void xnpod_deactivate_rr (void)
 Globally deactivate the round-robin scheduling.
int xnpod_set_thread_periodic (xnthread_t *thread, xnticks_t idate, xnticks_t period)
 Make a thread periodic.
int xnpod_wait_thread_period (unsigned long *overruns_r)
int xnpod_add_hook (int type, void(*routine)(xnthread_t *))
 Install a nucleus hook.
int xnpod_remove_hook (int type, void(*routine)(xnthread_t *))
 Remove a nucleus hook.
void xnpod_suspend_thread (xnthread_t *thread, xnflags_t mask, xnticks_t timeout, xntmode_t timeout_mode, xnsynch_t *wchan)
 Suspend a thread.
void xnpod_welcome_thread (xnthread_t *thread, int imask)
 Thread prologue.
static void xnpod_preempt_current_thread (xnsched_t *sched)
 Preempts the current thread.
int xnpod_trap_fault (xnarch_fltinfo_t *fltinfo)
 Default fault handler.


Function Documentation

void xnpod_abort_thread ( xnthread_t *  thread  ) 

Abort a thread.

Unconditionally terminates a thread and releases all the nucleus resources it currently holds, regardless of whether the target thread is currently active in kernel or user-space. xnpod_abort_thread() should be reserved for use by skin cleanup routines; xnpod_delete_thread() should be preferred as the common method for removing threads from a running system.

Parameters:
thread The descriptor address of the terminated thread.
This service forces a call to xnpod_delete_thread() for the target thread.

Environments:

This service can be called from:

Rescheduling: possible if the current thread self-deletes.

void xnpod_activate_rr ( xnticks_t  quantum  ) 

Globally activate the round-robin scheduling.

This service activates the round-robin scheduling for all threads which have the XNRRB flag set in their status mask (see xnpod_set_thread_mode()). Each of them will run for the given time quantum, then preempted and moved to the end of its priority group in the ready queue. This process is repeated until the round-robin scheduling is disabled for those threads.

Parameters:
quantum The time credit which will be given to each rr-enabled thread (in ticks).
Environments:

This service can be called from:

Rescheduling: never.

int xnpod_add_hook ( int  type,
void(*)(xnthread_t *)  routine 
)

Install a nucleus hook.

The nucleus allows to register user-defined routines which get called whenever a specific scheduling event occurs. Multiple hooks can be chained for a single event type, and get called on a FIFO basis.

The scheduling is locked while a hook is executing.

Parameters:
type Defines the kind of hook to install:

Parameters:
routine The address of the user-supplied routine to call.
Returns:
0 is returned on success. Otherwise, one of the following error codes indicates the cause of the failure:

Environments:

This service can be called from:

Rescheduling: never.

void xnpod_deactivate_rr ( void   ) 

Globally deactivate the round-robin scheduling.

This service deactivates the round-robin scheduling for all threads which have the XNRRB flag set in their status mask (see xnpod_set_thread_mode()).

Environments:

This service can be called from:

Rescheduling: never.

void xnpod_delete_thread ( xnthread_t *  thread  ) 

Delete a thread.

Terminates a thread and releases all the nucleus resources it currently holds. A thread exists in the system since xnpod_init_thread() has been called to create it, so this service must be called in order to destroy it afterwards.

Parameters:
thread The descriptor address of the terminated thread.
The target thread's resources may not be immediately removed if this is an active shadow thread running in user-space. In such a case, the mated Linux task is sent a termination signal instead, and the actual deletion is deferred until the task exit event is called.

The DELETE hooks are called on behalf of the calling context (if any). The information stored in the thread control block remains valid until all hooks have been called.

Self-terminating a thread is allowed. In such a case, this service does not return to the caller.

Environments:

This service can be called from:

Rescheduling: possible if the current thread self-deletes.

void xnpod_disable_timesource ( void   ) 

Stop the core time source.

Releases the hardware timer, and deactivates the master time base.

Environments:

This service can be called from:

Rescheduling: never.

void xnpod_dispatch_signals ( void   ) 

Deliver pending asynchronous signals to the running thread.

For internal use only.

This internal routine checks for the presence of asynchronous signals directed to the running thread, and attempts to start the asynchronous service routine (ASR) if any. Called with nklock locked, interrupts off.

void xnpod_do_rr ( void   ) 

Handle the round-robin scheduling policy.

For internal use only.

This routine is called from the slave time base tick handler to enforce the round-robin scheduling policy.

This service can be called from:

Rescheduling: never.

int xnpod_enable_timesource ( void   ) 

Activate the core time source.

Xenomai implements the notion of time base, by which software timers that belong to different skins may be clocked separately according to distinct frequencies, or aperiodically. In the periodic case, delays and timeouts are given in counts of ticks; the duration of a tick is specified by the time base. In the aperiodic case, timings are directly specified in nanoseconds.

Only a single aperiodic (i.e. tick-less) time base may exist in the system, and the nucleus provides for it through the nktbase object. All skins depending on aperiodic timings should bind to the latter, also known as the master time base. Skins depending on periodic timings may create and bind to their own time base. Such a periodic time base is managed as a slave object of the master one. A cascading software timer, which is fired by the master time base according to the appropriate frequency, triggers in turn the update process of the associated slave time base, which eventually fires the elapsed software timers controlled by the latter.

Xenomai always controls the underlying hardware timer in a tick-less fashion, also known as the oneshot mode. The xnpod_enable_timesource() service configures the timer chip as needed, and activates the master time base.

Returns:
0 is returned on success. Otherwise:

Side-effect: A host timing service is started in order to relay the canonical periodical tick to the underlying architecture, regardless of the frequency used for Xenomai's system tick. This routine does not call the rescheduling procedure.

Environments:

This service can be called from:

Rescheduling: never.

Note:
Built-in support for periodic timing depends on CONFIG_XENO_OPT_TIMING_PERIODIC.

int xnpod_init ( void   ) 

Initialize the core pod.

Initializes the core interface pod which can subsequently be used to start real-time activities. Once the core pod is active, real-time skins can be stacked over. There can only be a single core pod active in the host environment. Such environment can be confined to a process (e.g. simulator), or expand machine-wide (e.g. I-pipe).

Returns:
0 is returned on success. Otherwise:

Environments:

This service can be called from:

int xnpod_init_thread ( xnthread_t *  thread,
xntbase_t *  tbase,
const char *  name,
int  prio,
xnflags_t  flags,
unsigned  stacksize,
xnthrops_t *  ops 
)

Initialize a new thread.

Initializes a new thread attached to the active pod. The thread is left in an innocuous state until it is actually started by xnpod_start_thread().

Parameters:
thread The address of a thread descriptor the nucleus 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.
Warning:
Some architectures may require the descriptor to be properly aligned in memory; this is an additional reason for descriptors not to be laid in the program stack where alignement constraints might not always be satisfied.
Parameters:
name An ASCII string standing for the symbolic name of the thread. This name is copied to a safe place into the thread descriptor. This name might be used in various situations by the nucleus for issuing human-readable diagnostic messages, so it is usually a good idea to provide a sensible value here. The simulator even uses this name intensively to identify threads in the debugging GUI it provides. However, passing NULL here is always legal and means "anonymous".
tbase The time base descriptor to refer to for all timed operations issued by the new thread. See xntbase_alloc() for detailed explanations about time bases.
prio The base priority of the new thread. This value must range from [loprio .. hiprio] (inclusive) as specified when calling the xnpod_init() service.
flags A set of creation flags affecting the operation. The following flags can be part of this bitmask, each of them affecting the nucleus behaviour regarding the created thread:

Parameters:
stacksize The size of the stack (in bytes) for the new thread. If zero is passed, the nucleus will use a reasonable pre-defined size depending on the underlying real-time control layer.
ops A pointer to a structure defining the class-level operations available for this thread. Fields from this structure must have been set appropriately by the caller.
Returns:
0 is returned on success. Otherwise, one of the following error codes indicates the cause of the failure:

Side-effect: This routine does not call the rescheduling procedure.

Environments:

This service can be called from:

Rescheduling: never.

int xnpod_migrate_thread ( int  cpu  ) 

Migrate the current thread.

This call makes the current thread migrate to another CPU if its affinity allows it.

Parameters:
cpu The destination CPU.
Return values:
0 if the thread could migrate ;
-EPERM if the calling context is asynchronous, or the current thread affinity forbids this migration ;
-EBUSY if the scheduler is locked.

void xnpod_preempt_current_thread ( xnsched_t sched  )  [inline, static]

Preempts the current thread.

For internal use only.

Preempts the running thread (because a higher priority thread has just been readied). The thread is re-inserted to the front of its priority group in the ready thread queue. Must be called with nklock locked, interrupts off.

int xnpod_remove_hook ( int  type,
void(*)(xnthread_t *)  routine 
)

Remove a nucleus hook.

This service removes a nucleus hook previously registered using xnpod_add_hook().

Parameters:
type Defines the kind of hook to remove among XNHOOK_THREAD_START, XNHOOK_THREAD_DELETE and XNHOOK_THREAD_SWITCH.
routine The address of the user-supplied routine to remove.
Returns:
0 is returned on success. Otherwise, -EINVAL is returned if type is incorrect or if the routine has never been registered before.
Environments:

This service can be called from:

Rescheduling: never.

void xnpod_renice_thread ( xnthread_t *  thread,
int  prio 
)

Change the base priority of a thread.

Changes the base priority of a thread. If the reniced thread is currently blocked, waiting in priority-pending mode (XNSYNCH_PRIO) for a synchronization object to be signaled, the nucleus 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.

Parameters:
thread The descriptor address of the affected thread.
prio The new thread priority.
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* change the thread.cprio field by hand, unless the thread is known to be in an innocuous state (e.g. dormant).

Side-effects:

Environments:

This service can be called from:

Rescheduling: never.

void xnpod_restart_thread ( xnthread_t *  thread  ) 

Restart a thread.

Restarts a previously started thread. The thread is first terminated then respawned using the same information that prevailed when it was first started, including the mode bits and interrupt mask initially passed to the xnpod_start_thread() service. As a consequence of this call, the thread entry point is rerun.

Parameters:
thread The descriptor address of the affected thread which must have been previously started by the xnpod_start_thread() service.
Self-restarting a thread is allowed. However, restarting the root thread is not.

Environments:

This service can be called from:

Rescheduling: possible.

void xnpod_resume_thread ( xnthread_t *  thread,
xnflags_t  mask 
)

Resume a thread.

Resumes the execution of a thread previously suspended by one or more calls to xnpod_suspend_thread(). 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.

Parameters:
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 xnpod_resume_thread(), the caller of xnpod_suspend_thread() 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:

Environments:

This service can be called from:

Rescheduling: never.

void xnpod_rotate_readyq ( int  prio  ) 

Rotate a priority level in the ready queue.

The thread at the head of the ready queue is moved to the end of its priority group. Round-robin scheduling policies may be implemented by periodically issuing this call. It should be noted that the nucleus already provides a built-in round-robin mode (see xnpod_activate_rr()).

Parameters:
prio The priority level to rotate. if XNPOD_RUNPRIO is given, the priority of the currently running thread is used to rotate the queue.
The priority level which is considered is always the base priority of a thread, not the possibly PIP-boosted current priority value. Specifying a priority level with no thread on it is harmless, and will simply lead to a null-effect.

Environments:

This service can be called from:

Rescheduling: never.

void xnpod_schedule ( void   ) 

Rescheduling procedure entry point.

This is the central rescheduling routine which should be called to validate and apply changes which have previously been made to the nucleus scheduling state, such as suspending, resuming or changing the priority of threads. This call first determines if a thread switch should take place, and performs it as needed. xnpod_schedule() actually switches threads if:

The nucleus implements a lazy rescheduling scheme so that most of the services affecting the threads state MUST be followed by a call to the rescheduling procedure for the new scheduling state to be applied. In other words, multiple changes on the scheduler state can be done in a row, waking threads up, blocking others, without being immediately translated into the corresponding context switches, like it would be necessary would it appear that a higher priority thread than the current one became runnable for instance. When all changes have been applied, the rescheduling procedure is then called to consider those changes, and possibly replace the current thread by another one.

As a notable exception to the previous principle however, every action which ends up suspending or deleting the current thread begets an immediate call to the rescheduling procedure on behalf of the service causing the state transition. For instance, self-suspension, self-destruction, or sleeping on a synchronization object automatically leads to a call to the rescheduling procedure, therefore the caller does not need to explicitly issue xnpod_schedule() after such operations.

The rescheduling procedure always leads to a null-effect if it is called on behalf of an ISR or callout. Any outstanding scheduler lock held by the outgoing thread will be restored when the thread is scheduled back in.

Calling this procedure with no applicable context switch pending is harmless and simply leads to a null-effect.

Side-effects:

Environments:

This service can be called from:

Note:
The switch hooks are called on behalf of the resuming thread.

void xnpod_schedule_runnable ( xnthread_t *  thread,
int  flags 
)

Hidden rescheduling procedure.

For internal use only.

xnpod_schedule_runnable() reinserts the given thread into the ready queue then switches to the highest priority runnable thread. It must be called with nklock locked, interrupts off.

This internal routine should NEVER be used directly by the client interfaces; xnpod_schedule() is the service to invoke normally for starting the rescheduling procedure.

Parameters:
thread The descriptor address of the thread to reinsert into the ready queue.
flags A bitmask composed as follows:

xnflags_t xnpod_set_thread_mode ( xnthread_t *  thread,
xnflags_t  clrmask,
xnflags_t  setmask 
)

Change a thread's control mode.

Change the control mode of a given thread. The control mode affects the behaviour of the nucleus regarding the specified thread.

Parameters:
thread The descriptor address of the affected thread.
clrmask Clears the corresponding bits from the control field 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 can be part of this bitmask, each of them affecting the nucleus behaviour regarding the thread:

Environments:

This service can be called from:

Rescheduling: never, therefore, the caller should reschedule if XNLOCK has been passed into clrmask.

int xnpod_set_thread_periodic ( xnthread_t *  thread,
xnticks_t  idate,
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 xnpod_wait_thread_period() will delay the thread until the next periodic release point in the processor timeline is reached.

Parameters:
thread The descriptor address of the affected thread. This thread is immediately delayed until the first periodic release point is reached.
idate The initial (absolute) date of the first release point, expressed in clock ticks (see note). The affected thread will be delayed until this point is reached. If idate is equal to XN_INFINITE, the current system date is used, and no initial delay takes place.
period The period of the thread, expressed in clock ticks (see note). 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.
Returns:
0 is returned upon success. Otherwise:

Environments:

This service can be called from:

Rescheduling: possible if the operation affects the current thread and idate has not elapsed yet.

Note:
The idate and period values will be interpreted as jiffies if thread is bound to a periodic time base (see xnpod_init_thread), or nanoseconds otherwise.

void xnpod_shutdown ( int  xtype  ) 

Shutdown the current pod.

Forcibly shutdowns the active pod. All existing nucleus threads (but the root one) are terminated, and the system heap is freed.

Parameters:
xtype An exit code passed to the host environment who started the nucleus. Zero is always interpreted as a successful return.
The nucleus never calls this routine directly. Skins should provide their own shutdown handlers which end up calling xnpod_shutdown() after their own housekeeping chores have been carried out.

Environments:

This service can be called from:

Rescheduling: never.

int xnpod_start_thread ( xnthread_t *  thread,
xnflags_t  mode,
int  imask,
xnarch_cpumask_t  affinity,
void(*)(void *cookie)  entry,
void *  cookie 
)

Initial start of 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 and interrupt mask for the new thread.

Parameters:
thread The descriptor address of the affected thread which must have been previously initialized by the xnpod_init_thread() service.
mode The initial thread mode. The following flags can be part of this bitmask, each of them affecting the nucleus behaviour regarding the started thread:

Parameters:
imask The interrupt mask that should be asserted when the thread starts. The processor interrupt state will be set to the given value when the thread starts running. The interpretation of this value might be different across real-time layers, but a non-zero value should always mark an interrupt masking in effect (e.g. local_irq_disable()). Conversely, a zero value should always mark a fully preemptible state regarding interrupts (e.g. local_irq_enable()).
affinity The processor affinity of this thread. Passing XNPOD_ALL_CPUS or an empty affinity set means "any cpu".
entry The address of the thread's body routine. In other words, it is the thread entry point.
cookie A user-defined opaque cookie the nucleus will pass to the emerging thread as the sole argument of its entry point.
The START hooks are called on behalf of the calling context (if any).

Return values:
0 if thread could be started ;
-EBUSY if thread was already started ;
-EINVAL if the value of affinity is invalid.
Environments:

This service can be called from:

Rescheduling: possible.

void xnpod_suspend_thread ( xnthread_t *  thread,
xnflags_t  mask,
xnticks_t  timeout,
xntmode_t  timeout_mode,
xnsynch_t *  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 xnpod_resume_thread().

Parameters:
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:

Parameters:
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 ticks (see note). 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 xnpod_suspend_thread() 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).
Note:
If the target thread is a shadow which has received a Linux-originated signal, then this service immediately exits without suspending the thread, but raises the XNBREAK condition in its information mask.
Environments:

This service can be called from:

Rescheduling: possible if the current thread suspends itself.

Note:
The timeout value will be interpreted as jiffies if thread is bound to a periodic time base (see xnpod_init_thread), or nanoseconds otherwise.

void xnpod_trap_fault ( xnarch_fltinfo_t *  fltinfo  ) 

Default fault handler.

This is the default handler which is called whenever an uncontrolled exception or fault is caught. If the fault is caught on behalf of a real-time thread, the fault is not propagated to the host system. Otherwise, the fault is unhandled by the nucleus and simply propagated.

Parameters:
fltinfo An opaque pointer to the arch-specific buffer describing the fault. The actual layout is defined by the xnarch_fltinfo_t type in each arch-dependent layer file.

int xnpod_unblock_thread ( xnthread_t *  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 xnpod_suspend_thread() 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.

Parameters:
thread The descriptor address of the unblocked thread.
This call neither releases the thread from the XNSUSP, XNRELAX nor the XNDORMANT 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.

Returns:
non-zero is returned if the thread was actually unblocked from a pending wait state, 0 otherwise.
Environments:

This service can be called from:

Rescheduling: never.

int xnpod_wait_thread_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.

Parameters:
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 xnpod_wait_thread_period() returns -ETIMEDOUT or success; the memory location remains unmodified otherwise. If NULL, this count will never be copied back.
Returns:
0 is returned upon success; if overruns_r is valid, zero is copied to the pointed memory location. Otherwise:

Environments:

This service can be called from:

Rescheduling: always, unless the current release point has already been reached. In the latter case, the current thread immediately returns from this service without being delayed.

void xnpod_welcome_thread ( xnthread_t *  thread,
int  imask 
)

Thread prologue.

For internal use only.

This internal routine is called on behalf of a (re)starting thread's prologue before the user entry point is invoked. This call is reserved for internal housekeeping chores and cannot be inlined.

Entered with nklock locked, irqs off.


Generated on Mon Mar 24 18:02:41 2008 for Xenomai API by  doxygen 1.5.3