I wrote a small C++ application for a Raspberry PI, which creates a pseudo IRQ handler for a GPIO input using a worker thread doing a poll() on GPIO edge change.
This is working fine so far, but with default priorities I have a too high latency from signal change on GPIO to return of the poll() in the worker thread.
So, I tried to set the worker-thread to SCHED_FIFO using pthread_setschedparam().
This works perfect when compiling/running my application on my x86 Arch Linux machine (without the actual GPIO of course, but apart from that the same worker thread code - especially all the thread creation stuff is exactly the same). It even works using my non-root user account.
Running it on the Raspberry I always get an error EPERM on pthread_setschedparam(), even if running it as root.
I also tried to use chrt on the Raspberry to set the whole application to SCHED_FIFO, but this also fails with "operation not permitted".
I think the problem is that on the Raspberry I get
$this->bbcode_second_pass_code('', '
[root@raspberry ~]# cat /sys/fs/cgroup/cpu/cpu.rt_runtime_us
950000
[root@raspberry ~]# cat /sys/fs/cgroup/cpu/user.slice/cpu.rt_runtime_us
0
')
As far as I understood the last value of zero prevents using SCHED_FIFO and gives this EPERM error (when I run my application from console it gets put somewhere below this user.slice hierarchy).
On my x86 machine I don't have this ".../user.slice/..." folder, but only the first ".../cpu/..." with the same values for "cpu.rt_runtime_us" like on the Raspberry. Maybe that's why it works there...
I compared kernel configs (with repsect to cgroups) and systemd version and they seem to be the same on both.
Maybe there are some subtle differences... I couldn't find them up to now.
I also found some suggestions here:
http://www.freedesktop.org/wiki/Software/systemd/MyServiceCantGetRealtime/
But, the mentioned "DefaultControllers" parameter doesn't seem to exist in recent versions of systemd. At least, adding it to system.conf (and/or user.conf) as proposed doesn't change anything for me.
Apart from that it states that:
$this->bbcode_second_pass_quote('', '
')Note that this all only applies to services. By default, user applications run in the root cgroup of the "cpu" hierarchy, which avoids these problems for normal user applications.