clinux-kerneltimespec

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


I am trying to convert the start_time of the linux kernel task_struct into nanoseconds. I need to give it the argument of const struct timespec * but start_time is of type struct timespec.

How would I make it a constant and a pointer to the timespec struct? Example code:

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

Solution

  • I would recommend picking up a primer on C, since you'll need to be very familiar with C programming (especially since the Linux kernel uses all the C trickery in the book) in order to write kernel code (or modify existing kernel code). However, to answer your question, you'll want to pass a pointer to the value (which is done using the & operator in C). Also, please use the correct dereferencing syntax for pointers to structures (p->attr).

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