Reputation: 160
Assumptions:
In a system which is designed to be Real Time, at least Soft Real Time rather than Hard Real Time. I was curious if you could apply core affinity for the background linux tasks that can "disrupt" the real time tasks to a single core, core A, and leave the real time tasks to run on the other core, B.
This way the linux kernel can execute its low priority tasks whilst being able to perform real time task execution.
This is quite a simplistic explanation but I'm curious simply if it is possible to do so. Granted there is other factors at play which can reduce determinism within a system such as interrupts but assumption removes those from this current scenario.
Any guidance to material or corrections on this question are welcome
Upvotes: 0
Views: 405
Reputation: 96
A very easy approach to isolate cores inside Linux is to use CPUSETS. See the excellent documentation there for further information.
The following example script assumes a cpu consisting of four cpu-cores. It will use cores 0-2 for all available tasks and reserve core 3 for tasks that are specifically attached to that core.
This is done by creating two cpusets "rt0" and "system". Global load-balancing gets disabled and only reenabled on the "system" set, which makes the remaining core inaccessible to the load-balancer. To attach tasks to the reserved core you have to write its pid to the corresponding tasks file.
$ mkdir /dev/cpuset
$ mount -t cgroup -o cpuset cpuset /dev/cpuset
$ cd /dev/cpuset
$ /bin/echo 1 > cpuset.cpu_exclusive
$ /bin/echo 0 > cpuset.sched_load_balance
$ mkdir rt0
$ /bin/echo 3 > rt0/cpuset.cpus
$ /bin/echo 0 > rt0/cpuset.mems
$ /bin/echo 1 > rt0/cpuset.cpu_exclusive
$ /bin/echo 0 > rt0/cpuset.sched_load_balance
$ /bin/echo $RT_PROC_PID > rt0/tasks
$ mkdir system
$ /bin/echo 0-2 > system/cpuset.cpus
$ /bin/echo 0 > system/cpuset.mems
$ /bin/echo 1 > system/cpuset.cpu_exclusive
$ /bin/echo 1 > system/cpuset.sched_load_balance
$ for pid in $(cat tasks); do /bin/echo $pid > system/tasks; done
A newer approach to deal with resource partitioning is systemd-slices. As far as I know it only works with Control Group v2 and obviously systemd. Since I did never really work with it I cannot provide further information here, but I thought it is worth mentioning.
Upvotes: 1