Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 8026

Advanced users • Re: "Realtime" GPIO with bcm2835 (AirSpayce)library, how to turn scheduling back on

$
0
0

Code:

#include <sched.h>struct sched_param sp;memset(&sp, 0, sizeof(sp));sp.sched_priority = sched_get_priority_max(SCHED_FIFO);sched_setscheduler(0, SCHED_FIFO, &sp);
That block of code tells the Linux process scheduler to schedule the current process as FIFO (First In First Out). First In, First Out basically means once it is scheduled to run (First In), no other process can stop it from running until it, itself, yields with something like a call to `sleep`or finishes its task (First Out).

That is important for realtime behavior because, if the process is interrupted or otherwise taken out of a running state by another process, any deterministic timing will be lost.

Another way to help keep the process running uninterrupted is to isolate a CPU core, and ensure only your realtime process can run on that core. That can be done with cpusets and/or `isolcpus` and `taskset`. See http://www.comfilewiki.co.kr/en/doku.ph ... ance:index for more on that.

See also `cset shield` at https://manpages.debian.org/bookworm/cp ... .1.en.html if you prefer to use cpusets.

I'm not sure about `mlockall(MCL_CURRENT | MCL_FUTURE);` and whether that is important for this use case.

Statistics: Posted by JinShil — Wed Jan 24, 2024 12:45 am



Viewing all articles
Browse latest Browse all 8026

Trending Articles