System Calls Related to Timing Measurements
Several system calls allow User Mode processes to read and modify the time and date and to create timers. Let’s briefly review these and discuss how the kernel handles them.
The time( ) and gettimeofday( ) System Calls
Processes in User Mode can get the current time and date by means of several system calls:
time( )
Returns the number of elapsed seconds since midnight at the start of January 1, 1970 (UTC).
gettimeofday( )
Returns, in a data structure named
timeval
, the number of elapsed seconds since midnight of January 1, 1970 (UTC) and the number of elapsed microseconds in the last second (a second data structure namedtimezone
is not currently used).
The time( )
system call is
superseded by gettimeofday( )
, but
it is still included in Linux for backward compatibility. Another
widely used function, ftime( )
,
which is no longer implemented as a system call, returns the number of
elapsed seconds since midnight of January 1, 1970 (UTC) and the number
of elapsed milliseconds in the last second.
The gettimeofday( )
system
call is implemented by the sys_gettimeofday(
)
function. To compute the current date and time of the day,
this function invokes do_gettimeofday(
)
, which executes the following actions:
Acquires the
xtime_lock
seqlock for reading.Determines the number of microseconds elapsed since the last timer interrupt by invoking the
get_offset
method of thecur_timer
timer object:usec = cur_timer->getoffset( );
As explained in the earlier ...
Get Understanding the Linux Kernel, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.