打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Topic: How To determine Linux Kernel Timer Interrupt Frequency

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 <signal.h>
02#include <stdio.h>
03#include <stdlib.h>
04#include <string.h>
05#include <sys/time.h>
06 
07 
08#define USECREQ 250
09#define LOOPS   1000
10 
11void event_handler (int signum)
12{
13 static unsigned long cnt = 0;
14 static struct timeval tsFirst;
15 if (cnt == 0) {
16   gettimeofday (&tsFirst, 0);
17 }
18 cnt ++;
19 if (cnt >= LOOPS) {
20   struct timeval tsNow;
21   struct timeval diff;
22   setitimer (ITIMER_REAL, NULL, NULL);
23   gettimeofday (&tsNow, 0);
24   timersub(&tsNow, &tsFirst, &diff);
25   unsigned long long udiff = (diff.tv_sec * 1000000) + diff.tv_usec;
26   double delta = (double)(udiff/cnt)/1000000;
27   int hz = (unsigned)(1.0/delta);
28   printf ("kernel timer interrupt frequency is approx. %d Hz", hz);
29   if (hz >= (int) (1.0/((double)(USECREQ)/1000000))) {
30     printf (" or higher");
31   }      
32   printf ("\n");
33   exit (0);
34 }
35}
36 
37int main (int argc, char **argv)
38{
39 struct sigaction sa;
40 struct itimerval timer;
41 
42 memset (&sa, 0, sizeof (sa));
43 sa.sa_handler = &event_handler;
44 sigaction (SIGALRM, &sa, NULL);
45 timer.it_value.tv_sec = 0;
46 timer.it_value.tv_usec = USECREQ;
47 timer.it_interval.tv_sec = 0;
48 timer.it_interval.tv_usec = USECREQ;
49 setitimer (ITIMER_REAL, &timer, NULL);
50 while (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).

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Linux服务器CPU的一些主要指标说明
linux世界里的时间
Examining Load Average | Linux Journal
编译内核2.6.34
Request_irq和setup_irq的区别 - Linux Kernel&Drive...
The tick broadcast framework
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服