Xenomai API  2.6.5
Threads scheduling services.

Thread scheduling services. More...

Collaboration diagram for Threads scheduling services.:

Functions

int sched_get_priority_min (int policy)
 Get minimum priority of the specified scheduling policy. More...
 
int sched_get_priority_max (int policy)
 Get maximum priority of the specified scheduling policy. More...
 
int sched_rr_get_interval (int pid, struct timespec *interval)
 Get the round-robin scheduling time slice. More...
 
int pthread_getschedparam (pthread_t tid, int *pol, struct sched_param *par)
 Get the scheduling policy and parameters of the specified thread. More...
 
int pthread_getschedparam_ex (pthread_t tid, int *pol, struct sched_param_ex *par)
 Get the extended scheduling policy and parameters of the specified thread. More...
 
int pthread_setschedparam (pthread_t tid, int pol, const struct sched_param *par)
 Set the scheduling policy and parameters of the specified thread. More...
 
int pthread_setschedparam_ex (pthread_t tid, int pol, const struct sched_param_ex *par)
 Set the extended scheduling policy and parameters of the specified thread. More...
 
int sched_yield (void)
 Yield the processor. More...
 
int sched_setconfig_np (int cpu, int policy, union sched_config *config, size_t len)
 Load CPU-specific scheduler settings for a given policy. More...
 

Detailed Description

Thread scheduling services.

Xenomai POSIX skin supports the scheduling policies SCHED_FIFO, SCHED_RR, SCHED_SPORADIC, SCHED_TP and SCHED_OTHER.

The SCHED_OTHER policy is mainly useful for user-space non-realtime activities that need to synchronize with real-time activities.

The SCHED_RR policy is only effective if the time base is periodic (i.e. if configured with the compilation constant CONFIG_XENO_OPT_POSIX_PERIOD or the xeno_nucleus module parameter tick_arg set to a non null value). The SCHED_RR round-robin time slice is configured with the xeno_posix module parameter time_slice, as a count of system timer clock ticks.

The SCHED_SPORADIC policy provides a mean to schedule aperiodic or sporadic threads in periodic-based systems.

The SCHED_TP policy divides the scheduling time into a recurring global frame, which is itself divided into an arbitrary number of time partitions. Only threads assigned to the current partition are deemed runnable, and scheduled according to a FIFO-based rule within this partition. When completed, the current partition is advanced automatically to the next one by the scheduler, and the global time frame recurs from the first partition defined, when the last partition has ended.

The scheduling policy and priority of a thread is set when creating a thread, by using thread creation attributes (see pthread_attr_setinheritsched(), pthread_attr_setschedpolicy() and pthread_attr_setschedparam()), or when the thread is already running by using the service pthread_setschedparam().

See also
Specification.

Function Documentation

int pthread_getschedparam ( pthread_t  tid,
int *  pol,
struct sched_param *  par 
)

Get the scheduling policy and parameters of the specified thread.

This service returns, at the addresses pol and par, the current scheduling policy and scheduling parameters (i.e. priority) of the Xenomai POSIX skin thread tid. If this service is called from user-space and tid is not the identifier of a Xenomai POSIX skin thread, this service fallback to Linux regular pthread_getschedparam service.

Parameters
tidtarget thread;
poladdress where the scheduling policy of tid is stored on success;
paraddress where the scheduling parameters of tid is stored on success.
Returns
0 on success;
an error number if:
  • ESRCH, tid is invalid.
See also
Specification.

References XNRRB.

int pthread_getschedparam_ex ( pthread_t  tid,
int *  pol,
struct sched_param_ex *  par 
)

Get the extended scheduling policy and parameters of the specified thread.

This service is an extended version of pthread_getschedparam(), that also supports Xenomai-specific or additional POSIX scheduling policies, which are not available with the host Linux environment.

Typically, SCHED_SPORADIC or SCHED_TP parameters can be retrieved from this call.

Parameters
tidtarget thread;
poladdress where the scheduling policy of tid is stored on success;
paraddress where the scheduling parameters of tid is stored on success.
Returns
0 on success;
an error number if:
  • ESRCH, tid is invalid.
See also
Specification.

References XNRRB.

Referenced by pthread_create().

int pthread_setschedparam ( pthread_t  tid,
int  pol,
const struct sched_param *  par 
)

Set the scheduling policy and parameters of the specified thread.

This service set the scheduling policy of the Xenomai POSIX skin thread tid to the value pol, and its scheduling parameters (i.e. its priority) to the value pointed to by par.

When used in user-space, passing the current thread ID as tid argument, this service turns the current thread into a Xenomai POSIX skin thread. If tid is neither the identifier of the current thread nor the identifier of a Xenomai POSIX skin thread this service falls back to the regular pthread_setschedparam() service, hereby causing the current thread to switch to secondary mode if it is Xenomai thread.

Parameters
tidtarget thread;
polscheduling policy, one of SCHED_FIFO, SCHED_RR, SCHED_SPORADIC, SCHED_TP or SCHED_OTHER;
parscheduling parameters address.
Returns
0 on success;
an error number if:
  • ESRCH, tid is invalid;
  • EINVAL, pol or par->sched_priority is invalid;
  • EAGAIN, in user-space, insufficient memory exists in the system heap, increase CONFIG_XENO_OPT_SYS_HEAPSZ;
  • EFAULT, in user-space, par is an invalid address;
  • EPERM, in user-space, the calling process does not have superuser permissions.
See also
Specification.
Note

When creating or shadowing a Xenomai thread for the first time in user-space, Xenomai installs a handler for the SIGWINCH signal. If you had installed a handler before that, it will be automatically called by Xenomai for SIGWINCH signals that it has not sent.

If, however, you install a signal handler for SIGWINCH after creating or shadowing the first Xenomai thread, you have to explicitly call the function xeno_sigwinch_handler at the beginning of your signal handler, using its return to know if the signal was in fact an internal signal of Xenomai (in which case it returns 1), or if you should handle the signal (in which case it returns 0). xeno_sigwinch_handler prototype is:

int xeno_sigwinch_handler(int sig, siginfo_t *si, void *ctxt);

Which means that you should register your handler with sigaction, using the SA_SIGINFO flag, and pass all the arguments you received to xeno_sigwinch_handler.

References xnpod_schedule(), xnpod_set_thread_schedparam(), and xnpod_set_thread_tslice().

Referenced by pthread_setschedparam_ex().

int pthread_setschedparam_ex ( pthread_t  tid,
int  pol,
const struct sched_param_ex *  par 
)

Set the extended scheduling policy and parameters of the specified thread.

This service is an extended version of pthread_setschedparam(), that supports Xenomai-specific or additional POSIX scheduling policies, which are not available with the host Linux environment.

Typically, a Xenomai thread policy can be set to SCHED_SPORADIC or SCHED_TP using this call.

Parameters
tidtarget thread;
poladdress where the scheduling policy of tid is stored on success;
paraddress where the scheduling parameters of tid is stored on success.
Returns
0 on success;
an error number if:
  • ESRCH, tid is invalid.
  • EINVAL, par contains invalid parameters.
  • ENOMEM, lack of memory to perform the operation.
See also
Specification.

References pthread_setschedparam(), xnpod_schedule(), xnpod_set_thread_schedparam(), and xnpod_set_thread_tslice().

int sched_get_priority_max ( int  policy)

Get maximum priority of the specified scheduling policy.

This service returns the maximum priority of the scheduling policy policy.

Parameters
policyscheduling policy, one of SCHED_FIFO, SCHED_RR, SCHED_SPORADIC, SCHED_TP or SCHED_OTHER.
Return values
Themaximum priority of policy on success;
-1with errno set if:
  • EINVAL, policy is invalid.
See also
Specification.
int sched_get_priority_min ( int  policy)

Get minimum priority of the specified scheduling policy.

This service returns the minimum priority of the scheduling policy policy.

Parameters
policyscheduling policy, one of SCHED_FIFO, SCHED_RR, SCHED_SPORADIC, SCHED_TP or SCHED_OTHER.
Return values
Theminimum priority of policy on success;
-1with errno set if:
  • EINVAL, policy is invalid.
See also
Specification.
int sched_rr_get_interval ( int  pid,
struct timespec *  interval 
)

Get the round-robin scheduling time slice.

This service returns the time quantum used by Xenomai POSIX skin SCHED_RR scheduling policy.

In kernel-space, this service only works if pid is zero, in user-space, round-robin scheduling policy is not supported, and this service not implemented.

Parameters
pidmust be zero;
intervaladdress where the round-robin scheduling time quantum will be returned on success.
Return values
0on success;
-1with errno set if:
  • ESRCH, pid is invalid (not 0).
See also
Specification.
int sched_setconfig_np ( int  cpu,
int  policy,
union sched_config *  config,
size_t  len 
)

Load CPU-specific scheduler settings for a given policy.

Currently, this call only supports the SCHED_TP policy, for loading the temporal partitions. A configuration is strictly local to the target cpu, and may differ from other processors.

Parameters
cpuprocessor to load the configuration of.
policyscheduling policy to which the configuration data applies. Currently, only SCHED_TP is valid.
pa pointer to the configuration data to load for cpu, applicable to policy.

Settings applicable to SCHED_TP:

This call installs the temporal partitions for cpu.

  • config.tp.windows should be a non-null set of time windows, defining the scheduling time slots for cpu. Each window defines its offset from the start of the global time frame (windows[].offset), a duration (windows[].duration), and the partition id it applies to (windows[].ptid).

Time windows must be strictly contiguous, i.e. windows[n].offset + windows[n].duration shall equal windows[n + 1].offset. If windows[].ptid is in the range [0..CONFIG_XENO_OPT_SCHED_TP_NRPART-1], SCHED_TP threads which belong to the partition being referred to may run for the duration of the time window.

Time holes may be defined using windows assigned to the pseudo partition #-1, during which no SCHED_TP threads may be scheduled.

  • config.tp.nr_windows should define the number of elements present in the config.tp.windows[] array.
Parameters
lensize of the configuration data (in bytes).
Returns
0 on success;
an error number if:
  • EINVAL, cpu is invalid, policy is different from SCHED_TP, SCHED_TP support is not compiled in (see CONFIG_XENO_OPT_SCHED_TP), len is zero, or p contains invalid parameters.
  • ENOMEM, lack of memory to perform the operation.
int sched_yield ( void  )

Yield the processor.

This function move the current thread at the end of its priority group.

Return values
0
See also
Specification.