Skip to content
Advertisement

How to change kernel timer frequency?

I wanted to change kernel option on kernel timer frequency.

So i found this, it is saying that i can change the configuration via /boot/config-'uname -r'

(And i also found the post saying unless it builds a tickless kernel – CONFIG_NO_HZ=y i couldn’t change timer frequency but mine is set to CONFIG_NO_HZ=y)

And it is also mentioning how to calculate the frequency with C code.

So first i check for current kernel timer frequency with the C code.

The result is 1000~1500 Hz.

And i check /boot/config-'uname -r', it represents like below.

# 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

But at there timer frequency was 250 Hz…?

And then in order to check more, i try to modify the file to

# CONFIG_HZ_100 is not set
# CONFIG_HZ_250=y
# CONFIG_HZ_300 is not set
CONFIG_HZ_1000=y
CONFIG_HZ=1000

And reboot, check again the config file if the change is applied, and run the C code which checks timer frequency approximately.

But result was same as before.

What is a problem ???

My environment is VMware, ubuntu12.04

The below is the C code.

#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>

#define USECREQ 250
#define LOOPS   1000

void event_handler (int signum)
{
 static unsigned long cnt = 0;
 static struct timeval tsFirst;
 if (cnt == 0) {
   gettimeofday (&tsFirst, 0);
 } 
 cnt ++;
 if (cnt >= LOOPS) {
   struct timeval tsNow;
   struct timeval diff;
   setitimer (ITIMER_REAL, NULL, NULL);
   gettimeofday (&tsNow, 0);
   timersub(&tsNow, &tsFirst, &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 >= (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 (&sa, 0, sizeof (sa));
 sa.sa_handler = &event_handler;
 sigaction (SIGALRM, &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, &timer, NULL);
 while (1);
}

Advertisement

Answer

Changes you make to /boot/config do not affect the running kernel. Please read more about the kernel config file here.

The config file you see in /boot/config (actually, it’s more like config-[kernel_version]) is the config file that was USED to build the kernel. This means that every change you make to this config file does not affect anything.

To really make these changes you need to construct a new config file, with the modifications you require and compile and install a new kernel based on that config file. You can use the config file from /boot and just make the clock adjustments to fit.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement