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.
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:
CLOCK_REALTIME is a settable system wide clock for real-world-time.
CLOCK_MONOTONIC is a non-settable non-decreasing clock that measures time since system startup.
CLOCK_PROCESS_CPUTIME_ID tracks the CPU time used by a process.
CLOCK_THREAD_CPUTIME_ID tracks the CPU time used by a thread.
CLOCK_MONOTONIC_RAW is a non-settable non-decreasing clock that is not affected by network time protocol (NTP) adjustments (and may be used for clock synchronization).
CLOCK_REALTIME_COARSE and CLOCK_MONOTONIC_COARSE are lower resolution versions of the CLOCK_REALTIME and CLOCK_MONOTONIC clocks, respectively.
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.