Xenomai API
2.6.5
|
Thread scheduling services. More...
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... | |
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().
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.
tid | target thread; |
pol | address where the scheduling policy of tid is stored on success; |
par | address where the scheduling parameters of tid is stored on success. |
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.
tid | target thread; |
pol | address where the scheduling policy of tid is stored on success; |
par | address where the scheduling parameters of tid is stored on success. |
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.
tid | target thread; |
pol | scheduling policy, one of SCHED_FIFO, SCHED_RR, SCHED_SPORADIC, SCHED_TP or SCHED_OTHER; |
par | scheduling parameters address. |
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.
tid | target thread; |
pol | address where the scheduling policy of tid is stored on success; |
par | address where the scheduling parameters of tid is stored on success. |
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.
policy | scheduling policy, one of SCHED_FIFO, SCHED_RR, SCHED_SPORADIC, SCHED_TP or SCHED_OTHER. |
The | maximum priority of policy on success; |
-1 | with errno set if:
|
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.
policy | scheduling policy, one of SCHED_FIFO, SCHED_RR, SCHED_SPORADIC, SCHED_TP or SCHED_OTHER. |
The | minimum priority of policy on success; |
-1 | with errno set if:
|
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.
pid | must be zero; |
interval | address where the round-robin scheduling time quantum will be returned on success. |
0 | on success; |
-1 | with errno set if:
|
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.
cpu | processor to load the configuration of. |
policy | scheduling policy to which the configuration data applies. Currently, only SCHED_TP is valid. |
p | a 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.
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.
len | size of the configuration data (in bytes). |
int sched_yield | ( | void | ) |
Yield the processor.
This function move the current thread at the end of its priority group.
0 |