【问题标题】:How to change kernel timer frequency?如何更改内核定时器频率?
【发布时间】:2015-03-30 19:25:30
【问题描述】:

我想更改内核定时器频率的内核选项。

所以我找到了this,据说我可以通过/boot/config-'uname -r'更改配置

(我还发现帖子说除非它构建一个无滴答内核 - CONFIG_NO_HZ=y 我无法更改计时器频率,但我的设置为 CONFIG_NO_HZ=y

还提到了如何用C代码计算频率。

所以首先我用 C 代码检查当前内核定时器频率。

结果为 1000~1500 Hz。

我检查了/boot/config-'uname -r',它代表如下。

# 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

但是那里的定时器频率是 250 Hz...?

然后为了检查更多,我尝试将文件修改为

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

然后重新启动,如果应用了更改,再次检查配置文件,然后运行大致检查定时器频率的 C 代码。

但结果和以前一样。

有什么问题???

我的环境是VMware,ubuntu12.04

下面是C代码。

#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);
}

【问题讨论】:

    标签: linux timer linux-kernel


    【解决方案1】:

    您对 /boot/config 所做的更改不会影响正在运行的内核。请阅读更多关于内核配置文件here

    您在/boot/config 中看到的配置文件(实际上,它更像是config-[kernel_version])是用于构建内核的配置文件。这意味着您对该配置文件所做的每项更改都不会影响任何内容。

    要真正进行这些更改,您需要构建一个新的配置文件,并根据该配置文件进行所需的修改并编译和安装新内核。您可以使用 /boot 中的配置文件,并根据需要调整时钟。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-02-02
      • 1970-01-01
      • 2015-12-09
      • 2011-05-13
      • 1970-01-01
      • 1970-01-01
      • 2014-10-09
      相关资源
      最近更新 更多