原理比较简单,如何查看自己的Linux的CONFIG_HZ的值呢?
- root@manu:~/code/c/self/ticks# grep ^CONFIG_HZ /boot/config-3.2.0-29-generic-pae
- CONFIG_HZ_250=y
- CONFIG_HZ=250
- global count_jiffies, count_ms
- probe timer.jiffies(100) { count_jiffies ++ }
- probe timer.ms(100) { count_ms ++ }
- probe timer.ms(543210)
- {
- hz=(1000*count_jiffies) / count_ms
- printf ("jiffies:ms ratio %d:%d => CONFIG_HZ=%d\n",
- count_jiffies, count_ms, hz)
- exit ()
- }
- jiffies:ms ratio 1358:5420 => CONFIG_HZ=250
除此外,还有一个值是USER_HZ,不了解这个的,可能会了解times系统调用,这个系统调用是统计进程时间消耗的,
- #include <sys/times.h>
- clock_t times(struct tms *buf);
- #include<stdio.h>
- #include<stdlib.h>
- #include<unistd.h>
- #include<sys/times.h>
- #include<time.h>
- int main()
- {
- int user_ticks_per_second ;
- user_ticks_per_second = (int)sysconf(_SC_CLK_TCK);
- if(user_ticks_per_second == -1)
- {
- fprintf(stderr,"failed to get ticks per second by sysconf\n");
- return -1;
- }
- printf("The Number of USER ticks per second is %d\n",user_ticks_per_second);
- return 0;
- }
- The Number of USER ticks per second is 100
- root@manu:~/code/c/self/ticks# getconf CLK_TCK
- 100
参考文献:
1 man 7 time
2 systemtap tutorial