How do I manage the clock source for EC2 instances running Linux?

Last updated: 2020-08-13

How can I determine the clock source used by an Amazon Elastic Compute Cloud (Amazon EC2) instance running Linux, and how can I change it?

Short description

By using an SSH client, you can find the current clock source, list the available clock sources, or change the clock source.

Note: There are a variety of clock sources available for Hardware Virtual Machine (HVM) instances, such as Xen, Time Stamp Counter (TSC), High Precision Event Time (HPET), or Advanced Configuration and Power Interface Specification (ACPI). For EC2 instances launched on the AWS Xen Hypervisor, it's a best practice to use the tsc clock source. Other EC2 instance types, such as C5 or M5, use the AWS Nitro Hypervisor. The recommended clock source for the AWS Nitro Hypervisor is kvm-clock.

Resolution

To find the clock source

Open an SSH client into your EC2 instance, and then run the following commands to find the current and available clock sources.

To find the current clock source, use the current_clocksource command to list the file content:

cat /sys/devices/system/clocksource/clocksource0/current_clocksource
xen

To list the clock source, use the available_clocksource command:

cat /sys/devices/system/clocksource/clocksource0/available_clocksource
xen tsc hpet acpi_pm

To set the current clock source to a different value

1.    Run bash as a superuser to override the current_clocksource:

sudo bash -c 'echo tsc > /sys/devices/system/clocksource/clocksource0/current_clocksource'

2.    Run the dmesg command to view the kernel messages:

dmesg | less

If the override was successful, this message appears:

clocksource: Switched to clocksource tsc

Note: Rebooting the system causes the Linux kernel to reset the clock source.

To set a clock source during the system boot loader

1.    Set clocksource in the kernel command line parameter.

For example, if you use grub2 and you want to set the clock source to "tsc", edit the /etc/default/grub file and add clocksource=tsc tsc=reliable for the GRUB_CMDLINE_LINUX option:

GRUB_CMDLINE_LINUX="console=tty0 crashkernel=auto console=ttyS0,115200 clocksource=tsc tsc=reliable"

2.    Generate the grub.cfg file:

grub2-mkconfig -o /boot/grub2/grub.cfg

Did this article help you?


Do you need billing or technical support?