无法计算 Linux 内核执行用 C 语言编写的 hello world 程序所花费的时间
Unable to calculate time taken by Linux Kernel to execute hello world program written in C language
我正在尝试计算 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”);
}
你想完成什么?
printk 是错误的,因为它不包括日志级别并且内核中没有 'clock()',但无论如何不应在此处使用等效项。
如果你真的对性能感兴趣,你想研究像 perf 这样的东西。
除了看起来你现在不应该内核工作。
我正在尝试计算 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”);
}
你想完成什么?
printk 是错误的,因为它不包括日志级别并且内核中没有 'clock()',但无论如何不应在此处使用等效项。
如果你真的对性能感兴趣,你想研究像 perf 这样的东西。
除了看起来你现在不应该内核工作。