Skip to content

Commit

Permalink
[finalize-warmboot.sh] reset cpufreq governor to default (sonic-net#1…
Browse files Browse the repository at this point in the history
…9634)

#### 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 sonic-net/sonic-utilities#3435
  • Loading branch information
stepanblyschak authored and mssonicbld committed Dec 4, 2024
1 parent 8107455 commit 111d65f
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions files/image_config/warmboot-finalizer/finalize-warmboot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 111d65f

Please sign in to comment.