gpt4 book ai didi

c - 无法计算Linux内核执行C语言编写的hello world程序所花费的时间

转载 作者:行者123 更新时间:2023-11-30 20:23:33 25 4
gpt4 key购买 nike

我正在尝试计算 Linux 内核执行简单的 hello world 程序所花费的时间。我做不到。我附上错误消息。我没有附上 Makefile,但据我所知,它是正确的。有什么帮助可以完美计算吗?

代码:

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/time.h>

int init_module(void)
{
clock_t t;
t = clock();
printk(“hello world\n”);
t = clock() - t;
double time_taken = ((double)t)/CLOCKS_PER_SEC;
printk(“%f\n”, time_taken);
return 0;
}

void cleanup_module(void)
{
printk(KERN_ALERT “Goodbye world\n”);
}
<小时/>

This is the error message

最佳答案

你想实现什么目标?

printk 是错误的,因为它不包括日志级别,并且内核中没有“clock()”,但无论如何不应在此处使用等效项。

如果您真的对性能感兴趣,您可能会想研究诸如性能之类的东西。

不过看起来您还不应该进行内核工作。

关于c - 无法计算Linux内核执行C语言编写的hello world程序所花费的时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35915738/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com