====== RT setup ======
you need a kernel with low-latency patch.
To allow thread to change priority to rt, you need (choose one):
- to be root (buuuuuuuuurk)
- to use libpam
- to use realtime-lsm (linux security module) (DEPRECATED)
====== PThread ======
* set thread in rt:
pthread_attr_init(&attr);
result = pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
result = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
result = pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
* set priority on a thread: (sample from jack)
struct sched_param rtparam;
int x;
memset (&rtparam, 0, sizeof (rtparam));
rtparam.sched_priority = priority;
if ((x = pthread_setschedparam (thread, SCHED_FIFO, &rtparam)) != 0)
{
return -1;
}
* usefull function to configure thread:
//autostart the thread
pthread_attr_setdetachstate
//inherit attr for the thread from parent
pthread_attr_setinheritsched
//set the thread type and it's priority
//priority only for FIFO or RR
pthread_attr_setschedparam
//set the thread type (round robin, fifo, sporadic, etc...)
//SCHED_FIFO (only blocking function or preemption from higher priority thread can stop the current thread)
//SCHED_RR (same as fifo, but the thread only run for one time quantum)
//SCHED_OTHER (tout pourri algorithme inside)
//SCHED_SPORADIC (there is a minimal time between to activation of the task (periodic task are sporadic with inter-arrival)
pthread_attr_setschedpolicy
//set the scope (system or process)
pthread_attr_setscope
//configure the stack
pthread_attr_setstack