bottlerocket-os / bottlerocket

An operating system designed for hosting containers
https://bottlerocket.dev
Other
8.82k stars 521 forks source link

consider defaulting the clock source for EC2 instances #3881

Open tzneal opened 7 months ago

tzneal commented 7 months ago

What I'd like:

I would like the clock source (/sys/devices/system/clocksource/clocksource0/current_clocksource) to be defaulted on boot per the guidance at https://repost.aws/knowledge-center/manage-ec2-linux-clock-source

Any alternatives you've considered:

bcressey commented 7 months ago

My initial implementation idea is to have a pair of systemd units.

# ec2-nitro-clocksource.service
[Unit]
Description=Set Preferred Clock Source (Nitro)
DefaultDependencies=no
ConditionVirtualization=amazon

[Service]
Type=oneshot
ExecStart=/usr/bin/echo kvm-clock
RemainAfterExit=true
StandardOutput=file:/sys/devices/system/clocksource/clocksource0/current_clocksource

[Install]
WantedBy=sysinit.target
# ec2-xen-clocksource.service
[Unit]
Description=Set Preferred Clock Source (Xen)
DefaultDependencies=no
ConditionVirtualization=xen
ConditionCPUFeature=constant_tsc

[Service]
Type=oneshot
ExecStart=/usr/bin/echo tsc
RemainAfterExit=true
StandardOutput=file:/sys/devices/system/clocksource/clocksource0/current_clocksource

[Install]
WantedBy=sysinit.target

I need to make sure that the Xen unit does the right thing for the older instance types with an emulated TSC timer. Also, I believe the feature we actually want to test for is "invariant_tsc" or "nonstop_tsc" instead of just "constant_tsc", which may require a systemd patch.