Merge pull request #1 from import/kernel-6.1:cpupower

cpupower теперь работает
This commit is contained in:
mikhailnov 2023-09-14 03:54:56 +00:00
commit adeb192a94
5 changed files with 58 additions and 64 deletions

View file

@ -1,47 +1,32 @@
#!/bin/bash
# Copyright © 2012, Sébastien Luttringer
# SPDX-License-Identifier: GPL-2.0-or-later
# A wrapper for cpupower to set the appropriate governor for frequency
# scaling. Sets 'ondemand', 'powersave' or 'performance' if available
# (checks availablility in this order).
# The user can override this behaviour by specifying the governor in
# CPUPOWER_GOVERNOR variable.
#
# CPUPOWER_OTHER_ARGS can be used to provide additional arguments to
# cpupower.
declare -i fail=0
AVAIL_FILE=/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors
USE_GOVERNOR=""
# parse frequency options
declare -a params=()
params+=(${governor:+-g $governor})
params+=(${min_freq:+-d $min_freq})
params+=(${max_freq:+-u $max_freq})
params+=(${freq:+-f $freq})
if ! test -e "${AVAIL_FILE}"; then
printf "CPU frequency scaling is not supported.\n"
exit 1
# apply frequency options
if ((${#params[@]} > 0)); then
cpupower frequency-set "${params[@]}" >/dev/null || fail=1
fi
if test -n "${CPUPOWER_GOVERNOR}"; then
if grep "${CPUPOWER_GOVERNOR}" "${AVAIL_FILE}" >/dev/null 2>&1; then
USE_GOVERNOR="${CPUPOWER_GOVERNOR}"
else
printf "Unknown governor: ${CPUPOWER_GOVERNOR}.\n"
printf "Available governors: "
cat "${AVAIL_FILE}"
printf "\n"
exit 1
fi
elif grep "ondemand" "${AVAIL_FILE}" >/dev/null 2>&1; then
USE_GOVERNOR=ondemand
elif grep "powersave" "${AVAIL_FILE}" >/dev/null 2>&1; then
USE_GOVERNOR=powersave
elif grep "performance" "${AVAIL_FILE}" >/dev/null 2>&1; then
USE_GOVERNOR=performance
else
printf "Failed to select the governor automatically, "
printf "please specify it explicitly in CPUPOWER_GOVERNOR variable.\n"
printf "Available governors: "
cat "${AVAIL_FILE}"
printf "\n"
exit 1
# parse cpu options
declare -a params=()
params+=(${mc_scheduler:+-m $mc_scheduler})
params+=(${smp_scheduler:+-s $smp_scheduler})
params+=(${perf_bias:+-b $perf_bias})
# apply cpu options
if ((${#params[@]} > 0)); then
cpupower set "${params[@]}" >/dev/null || fail=1
fi
# Set the governor at last.
printf "Using \"${USE_GOVERNOR}\" governor.\n"
/usr/bin/cpupower frequency-set -g ${USE_GOVERNOR} ${CPUPOWER_OTHER_ARGS}
exit $fail
# vim:set ts=2 sw=2 ft=sh et:

View file

@ -1,7 +1,30 @@
# If you would like to use a particular CPU frequency scaling governor
# rather than the default one, specify it here.
# CPUPOWER_GOVERNOR=
# Define CPUs governor
# valid governors: ondemand, performance, powersave, conservative, userspace.
# governor='powersave'
# Other command-line arguments to cpupower.
# See 'cpupower help' and cpupower(1) for more info.
# CPUPOWER_OTHER_ARGS=
# Limit frequency range
# Valid suffixes: Hz, kHz (default), MHz, GHz, THz
# do not set ondemand if you use this
# min_freq="2.25GHz"
# max_freq="3.25GHz"
# Specific frequency to be set.
# Requires userspace governor to be available.
# Do not set governor field if you use this one.
# freq=
# Utilizes cores in one processor package/socket first before processes are
# scheduled to other processor packages/sockets.
# See man (1) CPUPOWER-SET for additional details.
# mc_scheduler=
# Utilizes thread siblings of one processor core first before processes are
# scheduled to other cores. See man (1) CPUPOWER-SET for additional details.
# smp_scheduler=
# Sets a register on supported Intel processore which allows software to convey
# its policy for the relative importance of performance versus energy savings to
# the processor. See man (1) CPUPOWER-SET for additional details.
# perf_bias=
# vim:set ts=2 sw=2 ft=sh et:

View file

@ -1,9 +0,0 @@
[Unit]
Description=cpupower - wait for the list of frequency governors
After=syslog.target
[Path]
PathExists=/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors
[Install]
WantedBy=multi-user.target

View file

@ -2,6 +2,7 @@
Description=Configure CPU frequency settings
After=syslog.target
ConditionPathExists=/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors
ConditionVirtualization=!container
[Service]
Type=oneshot
@ -11,4 +12,3 @@ ExecStart=/usr/bin/cpupower-start.sh
[Install]
WantedBy=multi-user.target
Also=cpupower.path

View file

@ -298,7 +298,6 @@ Source114: kernel-riscv64.config
Source50: cpupower.service
Source51: cpupower.config
Source52: cpupower-start.sh
Source53: cpupower.path
Source80: kernel.rpmlintrc
@ -791,16 +790,14 @@ The cpupower tools.
%post -n cpupower
if [ $1 -ge 0 ]; then
# Do not enable/disable cpupower.service directly, because it should start
# when cpupower.path triggers it.
/bin/systemctl enable cpupower.path >/dev/null 2>&1 || :
/bin/systemctl start cpupower.path >/dev/null 2>&1 || :
/bin/systemctl enable cpupower.service >/dev/null 2>&1 || :
/bin/systemctl start cpupower.service >/dev/null 2>&1 || :
fi
%preun -n cpupower
if [ $1 -eq 0 ]; then
/bin/systemctl --no-reload disable cpupower.path > /dev/null 2>&1 || :
/bin/systemctl stop cpupower.path > /dev/null 2>&1 || :
/bin/systemctl --no-reload disable cpupower.service > /dev/null 2>&1 || :
/bin/systemctl stop cpupower.service > /dev/null 2>&1 || :
fi
%files -n cpupower -f cpupower.lang
@ -810,7 +807,6 @@ fi
%{_libdir}/libcpupower.so.0
%{_libdir}/libcpupower.so.0.0.1
%{_unitdir}/cpupower.service
%{_unitdir}/cpupower.path
%{_datadir}/bash-completion/completions/cpupower
%{_mandir}/man[1-8]/cpupower*
@ -1798,7 +1794,6 @@ mv cpupower.lang ../
chmod 0755 %{buildroot}%{_libdir}/libcpupower.so*
mkdir -p %{buildroot}%{_unitdir} %{buildroot}%{_sysconfdir}/sysconfig
install -m644 %{SOURCE50} %{buildroot}%{_unitdir}/cpupower.service
install -m644 %{SOURCE53} %{buildroot}%{_unitdir}/cpupower.path
install -m644 %{SOURCE51} %{buildroot}%{_sysconfdir}/sysconfig/cpupower
install -m755 %{SOURCE52} %{buildroot}%{_bindir}/cpupower-start.sh
%endif