Several system calls allow User Mode processes to read and modify the time and date and to create timers. Let us briefly review them and discuss how the kernel handles them.
Processes in User Mode can get the current time and date by means of several system calls:
Returns the number of elapsed seconds since midnight at the start of January 1, 1970
Returns, in a data structure of type timeb, the number of elapsed seconds since midnight of January 1, 1970; the number of elapsed milliseconds in the last second; the time zone; and the current status of daylight saving time
Returns the same information as ftime( ) in two data structures named timeval and timezone
The former system calls are superseded by gettimeofday( ), but they are still included in Linux for backward compatibility. We don't discuss them further.
The gettimeofday( ) system call is implemented by the sys_gettimeofday( ) function. In order to compute the current date and time of the day, this function invokes do_ gettimeofday( ), which executes the following actions:
Copies the contents of xtime into the user-space buffer specified by the system call parameter tv:
*tv = xtime;
Updates the number of microseconds by invoking the function addressed by the do_ gettimeoffset variable:
tv->tv_usec += do_gettimeoffset( );
If the CPU has a Time Stamp Counter, the do_fast_gettimeoffset( ...