A Brief Guide to Time in Linux


The ktime_t type defined in the include/linux/ktime.h file provides a nanosecond-resolution representation of kernel time values, though time keeping may be done at coarser time-scales (e.g., at the granularity with which the jiffy is configured).

The kernel/time/hrtimer.c file implements a high resolution timers subsystem that is the basis for high resolution kernel timers as well as most current userspace timer iterfaces: itimers, nanosleep, and POSIX timers.

The kernel/time/tick-common.c file defines functions for generating and handling tick events, including the tick_periodic function for periodic tick systems.

The kernel/time/tick-oneshot.c file defines functions for oneshot ticks.

The kernel/time/tick-broadcast.c file defines functions for handling the broadcast of tick events for SMP systems, including functions for handling ticks in oneshot mode.

The kernel/time/timekeeping.c file several functions for accessing, measuring, and setting time in the Linux kernel, including several functions which return or take as parameters variables of the ktime_t type.


The kernel/time/time.c file defines basic time related system calls: gettimeofday and time, which measure calendar time (a.k.a. real world time); settimeofday, which updates the system clock; etc.


The include/uapi/linux/time.h file defines IDs for the different system clocks according to the POSIX clocks API, which is intended to improve portability across different Unix variants. As is noted on pages 491-492 of the LPI text book:

The kernel/time/posix-timers.c file defines key system calls for the POSIX clocks API: clock_gettime and clock_getres for obtaining the time and resolution of a given clock; and clock_settime that a privileged process can use to set the CLOCK_REALTIME clock.


The kernel/time/timer.c file implements a legacy timer subsystem based on timer wheels, which is provided for backward compatibility with older versions of Linux.