I am using Ubuntu 20.10 with kernel source 5.8.0-59.66
I need to get the current time of day (from the epoch) within the kernel. Using either RHEL 7.9 or CENTOS 7 I have relied on the gettimeofday() function.
In a nutshell, the documentation seems to indicate the function exists in Ubuntu -
http://manpages.ubuntu.com/manpages/bionic/man2/gettimeofday.2.html
within which it says to include the following
#include <sys/time.h>
This file or actually the directory "sys" doesn't seem to exist in my kernel source tree. If I do a "find" on time.h I do find a few including ~/include/linux/time.h but it does not contain the function definition.
Am I missing something here? Or perhaps there's a better and/or updated method for getting the time in the manner of gettimeofday?
It works fine on my other non-Ubuntu kernel mods. But this is my first experience with Ubuntu.
I neglected to add the compile error.
error: implicit declaration of function ‘gettimeofday’
[-Werror=implicit-function-declaration]
1329 | gettimeofday(&time);
The code using this function is
struct tm time;
gettimeofday(&time);
local_time = (u32)(time.tm_sec );
Please be aware that this is not the exact code in RHEL and Centos versions. I made minor changes based on compiler errors such as time.tv_sec became time.tm_sec and thus it is not proven.
However I think the first issue is not having the definition for gettimeofday? Or I could be wrong...