C - Linux 内核 - 如何使用 timespec_to_ns()?

C - Linux Kernel - How to use timespec_to_ns()?

我正在尝试将 linux 内核 task_structstart_time 转换为纳秒。我需要给它 const struct timespec * 的参数,但是 start_time 的类型是 struct timespec.

如何使它成为常量和指向 timespec 结构的指针?示例代码:

(*kinfo).start_time = timespec_to_ns((*current).start_time);

我建议您学习 C 入门,因为您需要非常熟悉 C 编程(特别是因为 Linux 内核使用了书中所有的 C 技巧)才能编写内核代码(或修改现有内核代码)。但是,要回答您的问题,您需要传递一个指向该值的指针(这是使用 C 中的 & 运算符完成的)。另外,请对指向结构的指针使用正确的取消引用语法 (p->attr)。

kinfo->start_time = timespec_to_ns(&current->start_time);