Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use recommended clocksources #1328

Merged
merged 1 commit into from
Jun 29, 2023
Merged

Use recommended clocksources #1328

merged 1 commit into from
Jun 29, 2023

Conversation

cartermckinnon
Copy link
Member

@cartermckinnon cartermckinnon commented Jun 15, 2023

Issue #, if available:

Fixes #249

Description of changes:

The tsc clocksource is the recommended default for instances on the Xen hypervisor, as it's significantly more performant than the xen clocksource (there's an interesting case study from Netflix).

A previous attempt (in #272) to swap xen for tsc had no effect; only the current clocksource was changed, not the default. The setting was applied during the AMI build process and had no effect after a reboot.

EC2 recommends:

  • Xen-based instance types: tsc
    • In my tests, xen was used by default.
  • Nitro-based instance types: kvm-clock
    • In my tests, tsc was used by default.
  • Graviton instance types: arch_sys_counter
    • In my tests, this is the only clocksource available; any other clocksource set on the kernel command-line is ignored.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Testing Done

  1. I built a 1.27 AMI on this branch (make 1.27).
  2. I launched:
  • m6i.large (Nitro): kvm-clock used as expected.
  • r7g.medium (Graviton3): arch_sys_counter used as expected.
    • I built an arm64 variant for this (make 1.27 arch=arm64).
  • m4.large (Xen): tsc used as expected.

Comment on lines -93 to -96
cat << EOF | sudo tee -a /etc/chrony.conf
# This directive enables kernel synchronisation (every 11 minutes) of the
# real-time clock. Note that it can’t be used along with the 'rtcfile' directive.
rtcsync
EOF
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I verified that this is already present in /etc/chrony.conf in the latest AL2 minimal AMI. We should not configure chrony here to avoid diverging from the defaults provided by AL2.

Comment on lines -99 to -104
# If current clocksource is xen, switch to tsc
if grep --quiet xen /sys/devices/system/clocksource/clocksource0/current_clocksource \
&& grep --quiet tsc /sys/devices/system/clocksource/clocksource0/available_clocksource; then
echo "tsc" | sudo tee /sys/devices/system/clocksource/clocksource0/current_clocksource
else
echo "tsc as a clock source is not applicable, skipping."
fi
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only sets the current clocksource, which has no effect after a reboot.

Comment on lines +27 to +32
# use the tsc clocksource by default
# https://repost.aws/knowledge-center/manage-ec2-linux-clock-source
sudo grubby \
--update-kernel=ALL \
--args="clocksource=tsc tsc=reliable"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't strictly necessary with the configure-clocksource unit in place, but the tsc=reliable flag is still worth setting, and we might as well configure a default here too.

@cartermckinnon cartermckinnon changed the title [WIP] Use tsc clocksource by default [WIP] Use recommended clocksource Jun 16, 2023
@cartermckinnon cartermckinnon changed the title [WIP] Use recommended clocksource [WIP] Use recommended clocksources Jun 17, 2023
@cartermckinnon cartermckinnon changed the title [WIP] Use recommended clocksources Use recommended clocksources Jun 17, 2023
@cartermckinnon cartermckinnon marked this pull request as ready for review June 17, 2023 01:14
Copy link
Contributor

@bwagner5 bwagner5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@cartermckinnon cartermckinnon merged commit 056e31f into master Jun 29, 2023
2 checks passed
@cartermckinnon cartermckinnon deleted the tsc-clocksource branch June 29, 2023 16:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make TSC the default system clock source
2 participants