Changing clock source in Linux

Ask questions about dedicated servers here and we and other users will do our best to answer them. Please also refer to the self-help section for tutorials and answers to the most commonly asked questions.
Post Reply
User avatar
Edge100x
Founder
Founder
Posts: 13127
https://www.youtube.com/channel/UC40BgXanDqOYoVCYFDSTfHA
Joined: Thu Apr 18, 2002 11:04 pm
Location: Seattle
Contact:

Changing clock source in Linux

Post by Edge100x »

A customer asked us in our support system how to change the clock source in Linux, and I'm posting about it here, because this seems like something that will come up again.

The clock source is used for kernel timers, and it is important to use a high-quality one because game servers use kernel timers constantly. Using a poor clock source can lead to problems with the game skipping or with the FPS being unstable/dipping.

Normally the kernel picks the best clocksource automatically. To see its current choice, use this command:

Code: Select all

cat /sys/devices/system/clocksource/clocksource0/current_clocksource
This will usually print out "tsc", on a Gentoo Linux VDS, and TSC (the CPU time stamp counter) is usually the right choice, because it is fast and stable on Nehalem CPUs. On CentOS, you should see "xen", which is good as well, since it mirrors Xen's clocksource (Xen usually picks TSC, but can change things up to be better at times).

You can see what other clock sources are available with this command:

Code: Select all

cat /sys/devices/system/clocksource/clocksource0/available_clocksource
Which will print out a number of possible sources that is a subset of these:

Code: Select all

xen acpi_pm hpet tsc
If you are using Gentoo (or a different kernel without PV-on-HVM drivers), you won't see then "xen" option, and if you have HPET turned off in the "Advanced" section of the Server control page, you won't see the "hpet" option.

Usually "tsc" is the best choice, but you can try any of the others out, as well, by changing the setting on the fly. To do this, just echo the one you want into the current_clocksource. For example:

Code: Select all

echo hpet > /sys/devices/system/clocksource/clocksource0/available_clocksource
If it seems to work better for you, just set your startup script (/etc/conf.d/local.start on Gentoo, /etc/rc.local on CentOS) to do this on boot.
Post Reply