title: How to prevent gcc optimizing in kernel modules?
body: <p>I'm trying to understand how can one disable code optimization for kernel modules when compiling with gcc.
  I tried giving pragmas like this </p>
  
  <pre><code>#pragma optimize("",off)
  void rt_ct_use_cpu(unsigned long long n_cicle){
      unsigned long long i;
      for(i=0;i&lt;n_cicle;i++);
  }
  #pragma optimize("",on)
  </code></pre>
  
  <p>But the compiler gives a warning saying that it is going to ignore those pragmas. I also tried making something that avoid the compiler to roll the loop like </p>
  
  <pre><code>void rt_ct_use_cpu(unsigned long long n_cicle){
      unsigned long long i;
      unsigned long long time=0;
      unsigned long long timebase = rt_get_cpu_time_ns();
      for(i=0;i&lt;n_cicle;i++) {
          time += rt_get_cpu_time_ns();
          time -= timebase;
      }
  }
  </code></pre>
  
  <p>but in this case it doesn't matter how long is the cicle (how big is n_cicle) the program will run always the same amount of time (few milliseconds)</p>
  
  <p>Can you help me?</p>