-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -o errexit | ||
set -o pipefail | ||
set -o nounset | ||
|
||
CLOCK_PATH="/sys/devices/system/clocksource/clocksource0" | ||
|
||
function log() { | ||
echo >&2 "$@" | ||
} | ||
|
||
function current-clocksource() { | ||
cat "${CLOCK_PATH}/current_clocksource" | ||
} | ||
|
||
function check-available-clocksource() { | ||
grep --quiet "${1}" "${CLOCK_PATH}/available_clocksource" | ||
} | ||
|
||
function try-set-clocksource() { | ||
if check-available-clocksource "${1}"; then | ||
echo "${1}" > "${CLOCK_PATH}/current_clocksource" | ||
log "configured clocksource: ${1}" | ||
else | ||
log "clocksource not available: ${1}" | ||
fi | ||
} | ||
|
||
case "$(imds /latest/meta-data/system)" in | ||
nitro) | ||
CLOCKSOURCE="kvm-clock" | ||
;; | ||
|
||
**) | ||
CLOCKSOURCE="tsc" | ||
;; | ||
esac | ||
|
||
log "desired clocksource: ${CLOCKSOURCE}" | ||
|
||
if [ ! "$(current-clocksource)" = "${CLOCKSOURCE}" ]; then | ||
try-set-clocksource "${CLOCKSOURCE}" | ||
fi | ||
|
||
log "final clocksource: $(current-clocksource)" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[Unit] | ||
Description=Configure kernel clocksource | ||
|
||
[Service] | ||
ExecStart=/usr/bin/configure-clocksource | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,27 +81,13 @@ sudo yum versionlock kernel-$(uname -r) | |
# Remove the ec2-net-utils package, if it's installed. This package interferes with the route setup on the instance. | ||
if yum list installed | grep ec2-net-utils; then sudo yum remove ec2-net-utils -y -q; fi | ||
|
||
sudo mkdir -p /etc/eks/ | ||
|
||
################################################################################ | ||
### Time ####################################################################### | ||
################################################################################ | ||
|
||
# Make sure Amazon Time Sync Service starts on boot. | ||
sudo chkconfig chronyd on | ||
|
||
# Make sure that chronyd syncs RTC clock to the kernel. | ||
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 | ||
|
||
# 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 | ||
Comment on lines
-98
to
-104
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
sudo mv $WORKING_DIR/configure-clocksource.service /etc/eks/configure-clocksource.service | ||
|
||
################################################################################ | ||
### SSH ######################################################################## | ||
|
@@ -114,7 +100,7 @@ sudo systemctl restart sshd.service | |
################################################################################ | ||
### iptables ################################################################### | ||
################################################################################ | ||
sudo mkdir -p /etc/eks | ||
|
||
sudo mv $WORKING_DIR/iptables-restore.service /etc/eks/iptables-restore.service | ||
|
||
################################################################################ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,4 +24,10 @@ sudo grubby \ | |
--update-kernel=ALL \ | ||
--args="psi=1" | ||
|
||
# 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" | ||
|
||
Comment on lines
+27
to
+32
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't strictly necessary with the |
||
sudo reboot |
There was a problem hiding this comment.
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 configurechrony
here to avoid diverging from the defaults provided by AL2.