c++pthreadsrhelthread-priority

Cannot set thread priority to real time despite using cap_sys_nice


I have an application that checks on POSIX environment whether thread priorities can be set to real time by calling

struct sched_param param;
param.sched_priority = 1;
int canSetRealTimeThreadPriority = (pthread_setschedparam(pthread_self(), SCHED_FIFO, &param) == 0);

On one system system A this works, but on another system B the check fails and I would like to find out why.

On both systems:

RESOURCE   DESCRIPTION                             SOFT      HARD UNITS
NICE       max nice prio allowed to raise             0         0
RTPRIO     max real-time priority                    20        20
RTTIME     timeout for real-time tasks        unlimited unlimited microsecs

On system B where it doesn't allow real time thread priorities:

[non root user]    -    rtprio    20

On system A where realtime thread priorities can be set:

When I test on system A and remove cap_sys_nice+eip from the binary via setcap '' [binary] I also cannot set real time thread priorities. I assume some setting on system B overrides the cap_sys_nice setting because it has a higher priority, so I wonder what that can be.


Solution

  • It turned out the reason why realtime thread priorities could not be set system wide was another service running, which had following settings in service script defined:

    CPUShares=20
    CPUQuota=500%
    

    After removing these settings from the script and restarting the service, thread priorities could be set system wide again.