From 15ca3091e41b10c2e43a1a74c255710bd4ecd6f6 Mon Sep 17 00:00:00 2001 From: Stepan Blyshchak <38952541+stepanblyschak@users.noreply.github.com> Date: Mon, 4 Nov 2024 19:53:29 +0200 Subject: [PATCH] [finalize-warmboot.sh] reset cpufreq governor to default (#19634) #### Why I did it Set cpufreq.default_governor to *performance* for faster boot time. We observe consistent 1 sec improvement across several devices. The change in finalize-warmboot.sh restores the default governor after fast or warm boot is finished. **NOTE**: This will apply to upgrades starting from 202405 since this is set in shutdown path to avoid any extra scripts running at boot time. Upgrade from older versions/branches will require a runtime patch to fast-reboot and warm-reboot script. #### How I did it After fast or warm boot is finished restore to default governor. #### How to verify it Run fast-reboot or warm-reboot. Check: ``` admin@sonic:~$ cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor performance ``` After boot is finalized check that it is reset back to default: ``` admin@sonic:~$ cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor schedutil ``` Tested with https://github.com/sonic-net/sonic-utilities/pull/3435 --- .../warmboot-finalizer/finalize-warmboot.sh | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/files/image_config/warmboot-finalizer/finalize-warmboot.sh b/files/image_config/warmboot-finalizer/finalize-warmboot.sh index b01832a6c7b8..492ad4792e86 100755 --- a/files/image_config/warmboot-finalizer/finalize-warmboot.sh +++ b/files/image_config/warmboot-finalizer/finalize-warmboot.sh @@ -2,6 +2,9 @@ VERBOSE=no +# read SONiC immutable variables +[ -f /etc/sonic/sonic-environment ] && . /etc/sonic/sonic-environment + # Define components that needs to reconcile during warm # boot: # The key is the name of the service that the components belong to. @@ -101,16 +104,34 @@ function check_list() echo ${RET_LIST} } +function set_cpufreq_governor() { + local -r governor="$1" + echo "$governor" | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor 1> /dev/null \ + && debug "Set CPUFreq scaling governor to $governor" \ + || debug "Failed to set CPUFreq scaling governor to $governor" +} + +function finalize_common() { + local -r asic_type=${ASIC_TYPE:-`sonic-cfggen -y /etc/sonic/sonic_version.yml -v asic_type`} + + if [[ "$asic_type" == "mellanox" ]]; then + # Read default governor from kernel config + local -r default_governor=$(cat "/boot/config-$(uname -r)" | grep -E 'CONFIG_CPU_FREQ_DEFAULT_GOV_.*=y' | sed -E 's/CONFIG_CPU_FREQ_DEFAULT_GOV_(.*)=y/\1/') + set_cpufreq_governor "$default_governor" + fi +} function finalize_warm_boot() { debug "Finalizing warmboot..." + finalize_common sudo config warm_restart disable } function finalize_fast_reboot() { debug "Finalizing fast-reboot..." + finalize_common sonic-db-cli STATE_DB hset "FAST_RESTART_ENABLE_TABLE|system" "enable" "false" &>/dev/null sonic-db-cli CONFIG_DB DEL "WARM_RESTART|teamd" &>/dev/null }