title: How to change kernel timer frequency?
body: <p>I wanted to change kernel option on kernel timer frequency.</p>
  
  <p>So i found <a href="http://www.advenage.com/topics/linux-timer-interrupt-frequency.php" rel="nofollow">this</a>, it is saying that i can change the configuration via <code>/boot/config-'uname -r'</code></p>
  
  <p>(And i also found the post saying unless it builds a tickless kernel - <code>CONFIG_NO_HZ=y</code> i couldn't change timer frequency but mine is set to <code>CONFIG_NO_HZ=y</code>)</p>
  
  <p>And it is also mentioning how to calculate the frequency with C code.</p>
  
  <p>So first i check for current kernel timer frequency with the C code.</p>
  
  <p>The result is 1000~1500 Hz.</p>
  
  <p>And i check <code>/boot/config-'uname -r'</code>, it represents like below.</p>
  
  <pre><code># CONFIG_HZ_100 is not set
  CONFIG_HZ_250=y
  # CONFIG_HZ_300 is not set
  # CONFIG_HZ_1000 is not set
  CONFIG_HZ=250
  </code></pre>
  
  <p>But at there timer frequency was 250 Hz...?</p>
  
  <p>And then in order to check more, i try to modify the file to </p>
  
  <pre><code># CONFIG_HZ_100 is not set
  # CONFIG_HZ_250=y
  # CONFIG_HZ_300 is not set
  CONFIG_HZ_1000=y
  CONFIG_HZ=1000
  </code></pre>
  
  <p>And reboot, check again the config file if the change is applied, and run the C code which checks timer frequency approximately.</p>
  
  <p>But result was same as before.</p>
  
  <p>What is a problem ??? </p>
  
  <p>My environment is VMware, ubuntu12.04</p>
  
  <p>The below is the C code.</p>
  
  <pre><code>#include &lt;signal.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  #include &lt;sys/time.h&gt;
  
  #define USECREQ 250
  #define LOOPS   1000
  
  void event_handler (int signum)
  {
   static unsigned long cnt = 0;
   static struct timeval tsFirst;
   if (cnt == 0) {
     gettimeofday (&amp;tsFirst, 0);
   } 
   cnt ++;
   if (cnt &gt;= LOOPS) {
     struct timeval tsNow;
     struct timeval diff;
     setitimer (ITIMER_REAL, NULL, NULL);
     gettimeofday (&amp;tsNow, 0);
     timersub(&amp;tsNow, &amp;tsFirst, &amp;diff);
     unsigned long long udiff = (diff.tv_sec * 1000000) + diff.tv_usec;
     double delta = (double)(udiff/cnt)/1000000;
     int hz = (unsigned)(1.0/delta);
     printf ("kernel timer interrupt frequency is approx. %d Hz", hz);
     if (hz &gt;= (int) (1.0/((double)(USECREQ)/1000000))) {
       printf (" or higher");
     }       
     printf ("\n");
     exit (0);
   }
  }
  
  int main (int argc, char **argv)
  {
   struct sigaction sa;
   struct itimerval timer;
  
   memset (&amp;sa, 0, sizeof (sa));
   sa.sa_handler = &amp;event_handler;
   sigaction (SIGALRM, &amp;sa, NULL);
   timer.it_value.tv_sec = 0;
   timer.it_value.tv_usec = USECREQ;
   timer.it_interval.tv_sec = 0;
   timer.it_interval.tv_usec = USECREQ;
   setitimer (ITIMER_REAL, &amp;timer, NULL);
   while (1);
  }
  </code></pre>