Anwser
Solved!! Thanks to @IanAbbott
the header should be:
#include <linux/ktime.h>
#include <linux/timekeeping.h>
rather than <linux/time.h>
.
More detail see discussion.
Original Question
I am writing a system call names sys_my_time.c
, which will use getnstimeofday()
. I have imported <linux/time.h>
. The code like this:
#include <linux/kernel.h>
#include <linux/linkage.h>
#include <linux/time.h>
asmlinkage int sys_my_time() {
struct timespec t;
getnstimeofday(&t);
// ...
return 0;
}
But while compiling, the error shows:
CC kernel/sys_my_time.o
kernel/sys_my_time.c: In function ‘sys_my_time’:
kernel/sys_my_time.c:8:3: error: implicit declaration of function ‘getnstimeofday’ [-Werror=implicit-function-declaration]
getnstimeofday(&t);
^
cc1: some warnings being treated as errors
scripts/Makefile.build:320: recipe for target 'kernel/sys_my_time.o' failed
make[1]: *** [kernel/sys_my_time.o] Error 1
Makefile:1029: recipe for target 'kernel' failed
make: *** [kernel] Error 2
I have no idea why the error happens.
P.S. compiling kernel V4.14.25 in Ubuntu 16.04