Unable to set real-time thread priority inside Docker container using pthread_setschedparam(...) on AGX Orin

I need to give one of my threads real-time thread priority using …

    int policy = SCHED_FIFO;
    struct sched_param param;    
    param.sched_priority = 80;
    ret = pthread_setschedparam(pthread_self(), policy, &param);

However, this returns with Operation not permitted.

I have looked around and tried modifying /proc/sys/kernel/sched_rt_runtime_us and /etc/security/limits.conf in addition to modifying rtpriority with ulimit and what was outlined in this post but no beans.

Also looked here.

The Orin has JetPack 5.1.2 (R35.4.1, Ubuntu 20.04, OpenCV4.5.4, Cuda 11.4.19, TensorRT 8.5.2 cuDNN v8.6.0) Kernel 5.10-tegra. The process is running inside a docker container with the same base image as the host (Ubuntu 20.04)

I have also noticed this during similar projects on previous boards (Xavier) natively on the host so I can’t say that running this from within a docker container is the issue.

Any pointers is appreciated.

How does docker negotiate with the host regarding thread prioritization?
Should modifying rtpriority be done inside or outside the container?

Hi,

Which WAR do you apply?
Is /proc/sys/kernel/sched_rt_runtime_us = -1?

Suppose this command should be applied outside of the container.
If it still does not work, could you share a compiled source that we can test?

Thanks.

/proc/sys/kernel/sched_rt_runtime_us is indeed -1, both inside and outside the container.
What do you mean by ‘WAR’ being applied? Is this a system level Nvidia configuration?

Unfortunately I cannot share any source just yet. I will see if I can get a simpler test running that I can share with you.

thread_test_main.txt (852 Bytes)
I had a minute to make this quick test. .cpp files are not allowed to be uploaded so I renamed it to a text file. We are using ROS2 for a project so I built this using colcon.

#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <pthread.h>	
#include <cstring>    
#include <stdexcept>

void SetThreadRealtime (int inRtPri = 80) {
#if defined(__linux__)    
    int policy = SCHED_FIFO;
    int ret = 0;
    struct sched_param param;    
    param.sched_priority = inRtPri;
    std::cout << "setting realtime priority" << std::endl;	
    ret = pthread_setschedparam(pthread_self(), policy, &param);
    if (ret) {
        throw std::runtime_error(std::strerror(ret));  
    }
#else
    throw std::runtime_error("OS RT not supported");  
#endif
}

int main(int argc, char *argv[])
{
    std::cout << "start" << std::endl;

    try {
    	SetThreadRealtime();
    	std::cout << "success!" << std::endl;
    }
    catch (std::runtime_error& err) {
    	std::cout << "failed : " << err.what() << std::endl;
    }
 
}

With this script, I am able to set realtime thread priority outside the container. Within the container, I can also set realtime thread priority only if I prefix running the command with sudo.

What permissions are required to set realtime thread priority?

Hi,

When you run the app outside of the container, do you need to run it with sudo?
Or sudo is only needed when running the app within the container.

Thanks.

The latter, sudo is only needed inside the container. It can be run outside without sudo