linux - 如果系统调用发生得更频繁,内核跟踪点挂钩将花费更少的时间来运行
问题描述
我编写了一个内核模块来使用 raw_tracepoint 挂钩系统调用。为了测量跟踪点处理程序的时间消耗,我编写了一个用户态程序来生成系统调用并printk()
在内核模块中使用来输出时间消耗:
// userland program
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
extern int errno;
int main()
{
while (1) {
int f = open("foo.txt", O_RDONLY | O_CREAT);
close(f);
//usleep(1000000);
//usleep(100000);
usleep(1);
//usleep(10);
//usleep(100);
//usleep(10000);
//usleep(1000);
}
}
原来,tracepoint handler的时间消耗与相应系统调用的调用频率有关。随着睡眠时间的增加,跟踪点处理程序需要更多时间来运行。
以下是tracepoint handler( tp90 )的休眠时间和对应的耗时:数据图。为什么会这样?
睡眠时间(我们) | 跟踪点处理程序耗时(我们) |
---|---|
0 | 0.254 |
0.1 | 0.559 |
1 | 0.573 |
10 | 0.593 |
50 | 0.717 |
100 | 0.751 |
300 | 0.994 |
500 | 1.185 |
1000 | 1.206 |
1500 | 1.211 |
2000 | 1.306 |
3000 | 1.52 |
4000 | 1.656 |
5000 | 2.142 |
6500 | 2.696 |
8000 | 2.546 |
10000 | 3.297 |
1000000 | 3.625 |