By using AWS re:Post, you agree to the AWS re:Post Terms of Use

How do I manage the clock source for an EC2 instance that runs Linux?

3 minute read
0

I want to check and change the clock source that my Amazon Elastic Compute Cloud (Amazon EC2) instance uses when I run Linux.

Short description

Use an SSH (Secure Shell) client to find the current clock source, list the available clock sources, or change the clock source.

The following are some of the clock sources that you can use for Hardware Virtual Machine (HVM) instances:

  • Xen
  • Time Stamp Counter (TSC)
  • High Precision Event Time (HPET)
  • Advanced Configuration
  • Power Interface Specification (ACPI)

For all Amazon EC2 Intel and AMD instances, it's best practice to use tsc as the clock source. If your instance uses the AWS Xen Hypervisor or the AWS Nitro Hypervisor, then use tsc as the clock source.

Note: All AWS Graviton processors use arch_sys_counter as the clock source.

Resolution

Find the clock source

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

To find the current clock source, list the contents of the current_clocksource file:

cat /sys/devices/system/clocksource/clocksource0/current_clocksourc
exen

To list the available clock sources, list the contents of the available_clocksource file:

cat /sys/devices/system/clocksource/clocksource0/available_clocksourc
exen tsc hpet acpi_pm

Set the current clock source to a different value

Complete the following steps:

  1. To override the current clock source, run the following bash as a superuser:

    sudo bash -c 'echo tsc > /sys/devices/system/clocksource/clocksource0/current_clocksource'
  2. To view the kernel messages, run the following dmesg command:

    dmesg | less

If the override is successful, then the clocksource: Switched to clocksource tsc message appears.

Note: If you reboot the system, then the Linux kernel resets the clock source.

Permanently set the clock source

To permanently set the clock source, set the source in the system boot loader. For example, if you use grub2 and you want to set the clock source to tsc, then open /etc/default/grub in an editor. Then, add clocksource=tsc tsc=reliable for the GRUB_CMDLINE_LINUX option.

Complete the following steps:

  1. To set clocksource in the kernel command line parameter, run the following command:

    GRUB_CMDLINE_LINUX="console=tty0 crashkernel=auto console=ttyS0,115200 clocksource=tsc tsc=reliable"
  2. To generate the grub.cfg file, run the following command:

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

Related information

Precision clock and time synchronization on your EC2 instance

AWS OFFICIAL
AWS OFFICIALUpdated 3 months ago