
#CDOCK SOURCE CODE#
The example above uses the following categories:Īs specified in the code above, the function reads the clock five times, with 200 microseconds between each reading:
#CDOCK SOURCE HOW TO#
The time(1) manual page provides detailed information on how to use the command and interpret its output. # echo acpi_pm > /sys/devices/system/clocksource/clocksource0/current_clocksource The steps are repeated with the ACPI_PM clock source: The clock source is changed to HPET to compare the duration required to generate 10 million timestamps: The time command is used to view the duration required to read the clock source 10 million times: In this example, the clock source currently in use is TSC. # echo hpet > /sys/devices/system/clocksource/clocksource0/current_clocksource For example, the following command sets HPET as the clock source in use: To do so, write the name of the clock source into the /sys/devices/system/clocksource/clocksource0/current_clocksource file. It is possible to select a different clock source, from the list presented in the /sys/devices/system/clocksource/clocksource0/available_clocksource file. # cat /sys/devices/system/clocksource/clocksource0/current_clocksource The clock source currently in use can be inspected by reading the /sys/devices/system/clocksource/clocksource0/current_clocksource file: In the sample output above, the TSC, HPET and ACPI_PM clock sources are available. # cat /sys/devices/system/clocksource/clocksource0/available_clocksource The last two options are either costly to read or have a low resolution (time granularity), therefore they are sub-optimal for the realtime kernel.įor the list of the available clock sources in your system, view the /sys/devices/system/clocksource/clocksource0/available_clocksource file: In the absence of TSC and HPET, other options include the ACPI Power Management Timer (ACPI_PM), the Programmable Interval Timer (PIT) and the Real Time Clock (RTC). However, not all systems have HPET clocks and some HPET clocks can be unreliable. The preferred clock source is the Time Stamp Counter (TSC), but if it is not available the High Precision Event Timer (HPET) is the second best option. The way clocks interact among themselves and the way they react to system events, such as CPU frequency scaling or entering energy economy modes, determine whether they are suitable clock sources for the realtime kernel.ĭuring boot time the kernel discovers the available clock sources and selects one to use. Multiprocessor systems such as NUMA or SMP have multiple instances of clock sources. Using the time command to compare cost of reading clocks Using C code to compare clock resolutionġ5.2.4. Using clock_getres() to compare clock resolutionġ5.2.3. CLOCK_MONOTONIC_COARSE and CLOCK_REALTIME_COARSEġ5.2.2. Using sched-yield() for SCHED_DEADLINE tasksġ5.2.1. sched_get_priority_min and sched_get_priority_maxġ4.3. Using library calls to set priority"ġ1.3.3. Using library calls to set priority"Ĭollapse section "11.3. Using library calls to set priorityĮxpand section "11.3. Setting the scheduler"Ĭollapse section "11. Thread synchronization"Įxpand section "11. Thread synchronization"Ĭollapse section "7. Isolating a single CPU to run high utilization tasksĮxpand section "7. SCHED_DEADLINE and cpusets"Ĭollapse section "6.3. Using the sched_setaffinity() system call to set processor affinityĮxpand section "6.3. Using the taskset command to set processor affinityĦ.2. Application architecture"Ĭollapse section "II. Advanced programmable interrupt controllerĮxpand section "II.
