0

In my embedded device I absorb strange behaviour with the protocol we use, sometimes it takes a while to send the data via serial device using FIFO.

My suspicion is Linux is not real-time OS and why do they have such real-time emulated function such as pthread_setschedparam? and having such priority in queue causing another process to starve due to that it takes a lot of time in detecting slave device.

I just want to know is it advisable to use param.sched_priority = 40; in Linux? I tried to tweak this parameter but the issue is quite hard to reproduce this happens in the field.

This is code

if (1)
{
    int policy;
    int r;
    struct sched_param param;

    policy = SCHED_FIFO;
    param.sched_priority = 40;
    r = pthread_setschedparam(cc_state->ser_thread, policy, &param);
    printf("%s: pthread_setschedparam %d", __func__, r);
}
1

Linux real time is not an emulation, there are system calls affecting scheduling. See man sched(7). It's not clear from your question what you are trying to do and what your exact problem is. The value of sched_priority is only relevant relative to the priorities of other threads. For example, if there's just one thread with priority > 0, it doesn't matter if the priority is 1 or 40; a higher value will not give extra "boost" to the thread. You will have to determine the relative priority required by your threads and assign them priority values accordingly.

Note that there is no time quantum associated with SCHED_FIFO threads. A SCHED_FIFO thread runs until one of the following happens: the thread is blocked because it is waiting for I/O, a higher priority thread is ready to run, or the thread voluntarily yields the processor. You will have to take this into consideration if you have several threads with equal priority, otherwise one thread might hog the CPU from the other threads. On a multiprocessor machine several threads can of course be running concurrently each on their own CPU.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.