linux编译内核timer frequency,Topic: How To determine Linux Kernel Timer Interrupt Frequency

Linux timer interrupt frequency is an important parameter for near to real-time and multimedia applications running on Linux. The timer interrupt frequency directly impacts the capability of any near-to real time and multimedia application to process events at high frequencies. The term high in this context means usually greater than 100 Hz (10 ms).

In the old days the kernel configuration setting CONFIG_HZ was the most important setting for the kernel timer frequency. It was defined at compilation time of the kernel and settings varied between distributions and kernel versions.

Today, a number of other kernel settings - such as NO_HZ, HIGH_RES_TIMERS - impact the kernel timer interrupt frequency as well. Finally the availability of High Precision Event Timer (HPET) support is also an important feature.

All these settings may be retrieved easily from the current kernel configuration. For example:

01$cat /boot/config-`uname -r` |grep HZ

02# CONFIG_HZ_1000 is not set

03# CONFIG_HZ_300 is not set

04CONFIG_MACHZ_WDT=m

05CONFIG_NO_HZ=y

06CONFIG_HZ=100

07CONFIG_HZ_100=y

08# CONFIG_HZ_250 is not set

09

10$cat /boot/config-`uname -r` |grep HIGH_RES_TIMERS

11CONFIG_HIGH_RES_TIMERS=y

However, for a near to real-time or multimedia application the effective achievable timer interrupt frequency counts. This frequency can be estimated quite well with timer interrupts. The small example program below depicts an algorithm to determine the actual achievable timer interrupt frequency using by actually requesting timer interrupts at high frequencies.

01#include

02#include

03#include

04#include

05#include

06

07

08#define USECREQ 250

09#define LOOPS   1000

10

11void event_handler (int signum)

12{

13static unsigned long cnt = 0;

14static struct timeval tsFirst;

15if (cnt == 0) {

16gettimeofday (&tsFirst, 0);

17}

18cnt ++;

19if (cnt >= LOOPS) {

20struct timeval tsNow;

21struct timevaldiff;

22setitimer (ITIMER_REAL, NULL, NULL);

23gettimeofday (&tsNow, 0);

24timersub(&tsNow, &tsFirst, &diff);

25unsigned long long udiff = (diff.tv_sec * 1000000) +diff.tv_usec;

26double delta = (double)(udiff/cnt)/1000000;

27int hz = (unsigned)(1.0/delta);

28printf ("kernel timer interrupt frequency is approx. %d Hz", hz);

29if (hz >= (int) (1.0/((double)(USECREQ)/1000000))) {

30printf (" or higher");

31}

32printf ("\n");

33exit (0);

34}

35}

36

37int main (int argc, char **argv)

38{

39struct sigaction sa;

40struct itimerval timer;

41

42memset (&sa, 0, sizeof (sa));

43sa.sa_handler = &event_handler;

44sigaction (SIGALRM, &sa, NULL);

45timer.it_value.tv_sec = 0;

46timer.it_value.tv_usec = USECREQ;

47timer.it_interval.tv_sec = 0;

48timer.it_interval.tv_usec = USECREQ;

49setitimer (ITIMER_REAL, &timer, NULL);

50while (1);

51}

To check your particular system regarding time interrupt frequency capabilities please follow the instructions below create a local copy of this small program, as e.g. frequency-test.c. Issue is that this setting has an important impact on near to real-time applications.Create a local copy of this small program, as e.g. frequency-test.c

Compile it with gcc: "gcc frequency-test.c"

Run it: "./a.out"

On a Ubuntu 8.04 LTS server (Hardy) ge got:

1$ ./a.out

2kernel timer interrupt frequency is approx. 4016 Hz or higher

On a Ubuntu 10.04 LTS server (Lucid) ge got:

1$ ./a.out

2kernel timer interrupt frequency is approx. 4016 Hz or higher

On a little bit older OpenSUSE with kernel 2.6.22.5-31-bigsmp we achieved:

1$ ./a.out

2kernel timer interrupt frequency is approx. 249 Hz

Both systems are multicore server chassis.

If the timer interrupt frequency determined on your system is for example around 250Hz, it will be very difficult for any near to real-time or multimedia application to send out an isochronous data stream of 250 packets per second (pps).

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值