From 0b4237805def7217c6fcd13d90b27f024c622561 Mon Sep 17 00:00:00 2001 From: Thomas Gebert Date: Thu, 19 Sep 2024 14:36:35 +0200 Subject: [PATCH] Control CPU frequency and idle settings This selection of script, config and systemd unit file shall give control over configuring the CPU behaviour with cpupower on startup. Since SuSE does not ship anything we have to write our own... --- cpupower/cpupower | 2 ++ cpupower/cpupower.examples | 25 +++++++++++++++++++++++++ cpupower/cpupower.service | 11 +++++++++++ cpupower/cpupower.sh | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 74 insertions(+) create mode 100644 cpupower/cpupower create mode 100644 cpupower/cpupower.examples create mode 100644 cpupower/cpupower.service create mode 100644 cpupower/cpupower.sh diff --git a/cpupower/cpupower b/cpupower/cpupower new file mode 100644 index 0000000..d17ec34 --- /dev/null +++ b/cpupower/cpupower @@ -0,0 +1,2 @@ +CPU_GOVERNOR="performance" +CPU_CSTATES_DISABLE_BY_LATENCY="3" diff --git a/cpupower/cpupower.examples b/cpupower/cpupower.examples new file mode 100644 index 0000000..fcccbab --- /dev/null +++ b/cpupower/cpupower.examples @@ -0,0 +1,25 @@ +ansible -b all -m copy -a "src=cpupower.sh dest=/usr/local/sbin/cpupower.sh" +ansible -b all -m copy -a "src=cpupower.service dest=/etc/systemd/system/cpupower.service" +ansible -b all -m copy -a "src=cpupower.sh dest=/usr/local/sbin/cpupower.sh mode=0755" + +ansible -b all -m shell -a "systemctl enable --now cpupower.service" + +ansible -b all -m shell -a "cpupower frequency-info | grep governor; cpupower idle-info | grep ^C" + +l3support@uxicasfs01:~/cpupower> ansible -b all -m shell -a "cpupower frequency-info | grep governor; cpupower idle-info | grep ^C" +uxicasfs02 | CHANGED | rc=0 >> + available cpufreq governors: performance powersave + The governor "performance" may decide which speed to use +CPUidle driver: intel_idle +CPUidle governor: menu +C1: +C1E (DISABLED) : +C6 (DISABLED) : +uxicasfs01 | CHANGED | rc=0 >> + available cpufreq governors: performance powersave + The governor "performance" may decide which speed to use +CPUidle driver: intel_idle +CPUidle governor: menu +C1: +C1E (DISABLED) : +C6 (DISABLED) : diff --git a/cpupower/cpupower.service b/cpupower/cpupower.service new file mode 100644 index 0000000..fe02cee --- /dev/null +++ b/cpupower/cpupower.service @@ -0,0 +1,11 @@ +[Unit] +Description=Configure cpupower related settings + +[Service] +EnvironmentFile=-/etc/default/cpupower +Type=oneshot +ExecStart=/usr/local/sbin/cpupower.sh +RemainAfterExit=yes + +[Install] +WantedBy=multi-user.target diff --git a/cpupower/cpupower.sh b/cpupower/cpupower.sh new file mode 100644 index 0000000..4323c8a --- /dev/null +++ b/cpupower/cpupower.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +CPUPOWER_CONFIG="/etc/default/cpupower" + +if [ -f "${CPUPOWER_CONFIG}" ]; then + source "${CPUPOWER_CONFIG}" +else + exit 0 +fi + +print_header() { +cat << HEADER + +############################################################################### +# ${@} +############################################################################### +HEADER +} + +# Set the CPU governor +if [ ! "${CPU_GOVERNOR}" == "" ]; then + print_header "Setting CPU governor to ${CPU_GOVERNOR}" + cpupower frequency-set --governor "${CPU_GOVERNOR}" &> /dev/null + cpupower frequency-info +else + echo "CPU governor is not set." +fi + +# Set the Cstate by latency +if [ ! "${CPU_CSTATES_DISABLE_BY_LATENCY}" == "" ]; then + print_header "Setting CPU CStates by latency to ${CPU_CSTATES_DISABLE_BY_LATENCY}" + cpupower idle-set --disable-by-latency "${CPU_CSTATES_DISABLE_BY_LATENCY}" &> /dev/null + cpupower idle-info +else + echo "No CPU Cstates by latency configured." +fi