Chapter 15. Timestamping
15.1. Hardware Clocks
cat /sys/devices/system/clocksource/clocksource0/available_clocksourcetsc hpet acpi_pm
/sys/devices/system/clocksource/clocksource0/available_clocksourcefile. To do so, write the name of the clock source into the
/sys/devices/system/clocksource/clocksource0/current_clocksourcefile. For example, the following command sets HPET as the clock source in use:
echo hpet > /sys/devices/system/clocksource/clocksource0/current_clocksource
idle=pollparameter forces the clock to avoid entering the idle state, and the
processor.max_cstate=1parameter prevents the clock from entering deeper C-states. Note however that in both cases there would be an increase on energy consumption, as the system would always run at top speed.
15.1.1. Reading Hardware Clock Sources
Example 15.1. Comparing the Cost of Reading Hardware Clock Sources
timecommand is used to view the duration required to read the clock source 10 million times:
cat /sys/devices/system/clocksource/clocksource0/current_clocksourcetsc ~]#
time ./clock_timingreal 0m0.601s user 0m0.592s sys 0m0.002s
echo hpet > /sys/devices/system/clocksource/clocksource0/current_clocksource~]#
cat /sys/devices/system/clocksource/clocksource0/current_clocksourcehpet ~]#
time ./clock_timingreal 0m12.263s user 0m12.197s sys 0m0.001s
echo acpi_pm > /sys/devices/system/clocksource/clocksource0/current_clocksource~]#
cat /sys/devices/system/clocksource/clocksource0/current_clocksourceacpi_pm ~]#
time ./clock_timingreal 0m24.461s user 0m0.504s sys 0m23.776s
time(1)man page provides detailed information on how to use the command and interpret its output. The example above uses the following categories:
real: The total time spent beginning from program invocation until the process ends.
systimes, and will usually be larger than the sum of the latter two. If this process is interrupted by an application with higher priority, or by a system event such as a hardware interrupt (IRQ), this time spent waiting is also computed under
user: The time the process spent in user space, performing tasks that did not require kernel intervention.
sys: The time spent by the kernel while performing tasks required by the user process. These tasks include opening files, reading and writing to files or I/O ports, memory allocation, thread creation and network related activities.