Xenomai API  2.5.6.1
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.
int sched_get_priority_max (int policy)
 Get maximum priority of the specified scheduling policy.
int sched_rr_get_interval (int pid, struct timespec *interval)
 Get the round-robin scheduling time slice.
int pthread_getschedparam (pthread_t tid, int *pol, struct sched_param *par)
 Get the scheduling policy and parameters of the specified thread.
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.
int pthread_setschedparam (pthread_t tid, int pol, const struct sched_param *par)
 Set the scheduling policy and parameters of the specified thread.
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.
int sched_yield (void)
 Yield the processor.

Detailed Description

Thread scheduling services.

Xenomai POSIX skin supports the scheduling policies SCHED_FIFO, SCHED_RR, SCHED_SPORADIC 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 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 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 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.

Examples:
rtcan_rtt.c.

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 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, or SCHED_OTHER.
Return values:
0on 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, or SCHED_OTHER.
Return values:
0on 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_yield ( void  )

Yield the processor.

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

Return values:
0
See also:
Specification.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines