title: Changing thread real time scheduling policy fails: CONFIG_RT_GROUP_SCHED=y
body: <p>My apologies if I'm posting this here instead of super user.</p>
  
  <p>I was trying to run docker inside real-time group and I came across enabling cgroups - <code>CONFIG_RT_GROUP_SCHED</code> in the kernel to run real-time docker applications (here: <a href="https://docs.docker.com/config/containers/resource_constraints/#configure-the-default-cfs-scheduler" rel="nofollow noreferrer">https://docs.docker.com/config/containers/resource_constraints/#configure-the-default-cfs-scheduler</a>)</p>
  
  <p>I configured my kernel to enable the FIFO/RR flags and verified it (Available here: <a href="https://stackoverflow.com/questions/56189710/how-to-enable-config-rt-group-sched-in-ubuntu-to-make-it-rt">How to enable CONFIG_RT_GROUP_SCHED in Ubuntu to make it RT</a>)</p>
  
  <p>I believe my system is properly scheduled now because I'm able to run the resource limited docker on this system which accesses the cgroups with the following command:</p>
  
  <pre><code>$ docker run -it --cpu-rt-runtime=950000 \
                        --ulimit rtprio=99 \
                        --cap-add=sys_nice \
                        debian:jessie
  </code></pre>
  
  <p>I went ahead and tried to explore more features of RT system. I've this CPP code to assign RT priority scheduling to threads. This code basically tries to set the <code>SCHED_FIFO</code> priority to a thread and prints if the kernel allowed it to set the priority or not. </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;pthread.h&gt;
  #include &lt;sched.h&gt;
  
  using namespace std;
  
  void set_realtime_priority() {
       int ret;
       // We'll operate on the currently running thread.
       pthread_t this_thread = pthread_self();
       // struct sched_param is used to store the scheduling priority
       struct sched_param params;
  
       // We'll set the priority to the maximum.
       params.sched_priority = sched_get_priority_max(SCHED_FIFO);
       std::cout &lt;&lt; "Trying to set thread realtime prio = " &lt;&lt; params.sched_priority &lt;&lt; std::endl;
  
       // Attempt to set thread real-time priority to the SCHED_FIFO policy
       ret = pthread_setschedparam(this_thread, SCHED_FIFO, &amp;params);
       if (ret != 0) {
           // Print the error
           std::cout &lt;&lt; "Unsuccessful in setting thread realtime prio" &lt;&lt; std::endl;
           return;     
       }
       // Now verify the change in thread priority
       int policy = 0;
       ret = pthread_getschedparam(this_thread, &amp;policy, &amp;params);
       if (ret != 0) {
           std::cout &lt;&lt; "Couldn't retrieve real-time scheduling paramers" &lt;&lt; std::endl;
           return;
       }
  
       // Check the correct policy was applied
       if(policy != SCHED_FIFO) {
           std::cout &lt;&lt; "Scheduling is NOT SCHED_FIFO!" &lt;&lt; std::endl;
       } else {
           std::cout &lt;&lt; "SCHED_FIFO OK" &lt;&lt; std::endl;
       }
  
       // Print thread scheduling priority
       std::cout &lt;&lt; "Thread priority is " &lt;&lt; params.sched_priority &lt;&lt; std::endl; 
  }
  
  int main(){
  set_realtime_priority();
  return 0;
  }
  </code></pre>
  
  <p>I've verified this code on a generic ubuntu/fedora and RT patched CentOS system. All of these systems allow the code to set the priority. Surprisingly its the <code>CONFIG_RT_GROUP_SCHED=y</code> configured kernel which doesn't allow me to set the priority policy. Similarly it also doesn't allow <code>cyclictest</code> to run</p>
  
  <pre><code>//install cyclictest by following
  
  $ sudo apt-get install rt-tests
  $ sudo cyclictest
  </code></pre>
  
  <p>I didn't understand this anomalous behavior. Does enabling the CONFIG_RT_GROUP_SCHED somehow block me from changing scheduling policies? </p>