diff --git a/cpupower-start.sh b/cpupower-start.sh new file mode 100644 index 0000000..c478bd6 --- /dev/null +++ b/cpupower-start.sh @@ -0,0 +1,47 @@ +#!/bin/bash + +# 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. + +AVAIL_FILE=/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors +USE_GOVERNOR="" + +if ! test -e "${AVAIL_FILE}"; then + printf "CPU frequency scaling is not supported.\n" + exit 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 +fi + +# Set the governor at last. +printf "Using \"${USE_GOVERNOR}\" governor.\n" +/usr/bin/cpupower frequency-set -g ${USE_GOVERNOR} ${CPUPOWER_OTHER_ARGS} diff --git a/cpupower.config b/cpupower.config index 6605320..91f2d54 100644 --- a/cpupower.config +++ b/cpupower.config @@ -1,3 +1,7 @@ -# See 'cpupower help' and cpupower(1) for more info -CPUPOWER_START_OPTS="frequency-set -g @GOVERNOR@" -CPUPOWER_STOP_OPTS="frequency-set -g @GOVERNOR@" +# If you would like to use a particular CPU frequency scaling governor +# rather than the default one, specify it here. +# CPUPOWER_GOVERNOR= + +# Other command-line arguments to cpupower. +# See 'cpupower help' and cpupower(1) for more info. +# CPUPOWER_OTHER_ARGS= diff --git a/cpupower.service b/cpupower.service index 5f10ab7..44a119b 100644 --- a/cpupower.service +++ b/cpupower.service @@ -1,13 +1,12 @@ [Unit] -Description=Configure CPU power related settings +Description=Configure CPU frequency settings After=syslog.target [Service] Type=oneshot RemainAfterExit=yes EnvironmentFile=/etc/sysconfig/cpupower -ExecStart=/usr/bin/cpupower $CPUPOWER_START_OPTS -ExecStop=/usr/bin/cpupower $CPUPOWER_STOP_OPTS +ExecStart=/usr/bin/cpupower-start.sh [Install] WantedBy=multi-user.target diff --git a/kernel.spec b/kernel.spec index 9526710..71573eb 100644 --- a/kernel.spec +++ b/kernel.spec @@ -29,7 +29,7 @@ %define rpmrel %mkrel 0.%{kpatch}.%{mibrel} %endif %else -%define rpmrel 1 +%define rpmrel 2 %endif # fakerel and fakever never change, they are used to fool @@ -342,9 +342,10 @@ Source2: disable-mrproper-prepare-scripts-configs-in-devel-rpms.patch Source4: README.kernel-sources Source5: kernel.rpmlintrc -# config and systemd service file from fedora +# Cpupower: the service, the config and the wrapper script Source50: cpupower.service Source51: cpupower.config +Source52: cpupower-start.sh # Our patch tarball, # see https://abf.rosalinux.ru/soft/kernel-patches-and-configs/ @@ -621,7 +622,7 @@ latest %{kname}-%{1}-devel installed... \ %define summary_desktop586 Linux kernel for desktop use with i586 & 4GB RAM %define info_desktop586 This kernel is compiled for desktop use, single or \ multiple i586 processor(s)/core(s) and less than 4GB RAM, using HZ_1000, \ -voluntary preempt, CFS cpu scheduler and BFQ i/o scheduler, ONDEMAND governor. +voluntary preempt, CFS cpu scheduler and BFQ i/o scheduler. %mkflavour desktop586 %endif %endif @@ -639,7 +640,7 @@ voluntary preempt, CFS cpu scheduler and BFQ i/o scheduler. %define summary_desktop Linux Kernel for desktop use with %{_arch} %define info_desktop This kernel is compiled for desktop use, single or \ multiple %{_arch} processor(s)/core(s), using HZ_1000, \ -voluntary preempt, CFS cpu scheduler and BFQ i/o scheduler, ONDEMAND governor. +voluntary preempt, CFS cpu scheduler and BFQ i/o scheduler. %endif %mkflavour desktop %endif @@ -657,7 +658,7 @@ voluntary preempt, CFS cpu scheduler and BFQ i/o scheduler. %define summary_netbook Linux Kernel for netbook use with %{_arch} %define info_netbook This kernel is compiled for netbook use, single or \ multiple %{_arch} processor(s)/core(s), using HZ_250, \ -voluntary preempt, CFS cpu scheduler and BFQ i/o scheduler, ONDEMAND governor. +voluntary preempt, CFS cpu scheduler and BFQ i/o scheduler. %endif %mkflavour netbook %endif @@ -670,12 +671,12 @@ voluntary preempt, CFS cpu scheduler and BFQ i/o scheduler, ONDEMAND governor. %define summary_server Linux Kernel for server use with i686 & 64GB RAM %define info_server This kernel is compiled for server use, single or \ multiple i686 processor(s)/core(s) and up to 64GB RAM using PAE, using \ -no preempt, HZ_100, CFS cpu scheduler and CFQ i/o scheduler, ONDEMAND governor. +no preempt, HZ_100, CFS cpu scheduler and CFQ i/o scheduler. %else %define summary_server Linux Kernel for server use with %{_arch} %define info_server This kernel is compiled for server use, single or \ multiple %{_arch} processor(s)/core(s), using no preempt, HZ_100, \ -CFS cpu scheduler and CFQ i/o scheduler, ONDEMAND governor. +CFS cpu scheduler and CFQ i/o scheduler. %endif %mkflavour server %endif @@ -688,7 +689,7 @@ CFS cpu scheduler and CFQ i/o scheduler, ONDEMAND governor. %define summary_desktop_pae Linux kernel for desktop use with i686 & upto 64GB RAM %define info_desktop_pae This kernel is compiled for desktop use, single or \ multiple i686 processor(s)/core(s) and up to 64GB RAM using PAE, using HZ_1000, \ -voluntary preempt, CFS cpu scheduler and BFQ i/o scheduler, ONDEMAND governor. +voluntary preempt, CFS cpu scheduler and BFQ i/o scheduler. %mkflavour desktop-pae %endif %endif @@ -701,7 +702,7 @@ voluntary preempt, CFS cpu scheduler and BFQ i/o scheduler, ONDEMAND governor. %define summary_netbook_pae Linux Kernel for for netbook use with i686 & upto 64GB RAM %define info_netbook_pae This kernel is compiled for netbook use, single or \ multiple i686 processor(s)/core(s) and up to 64GB RAM using PAE, using HZ_250, \ -voluntary preempt, CFS cpu scheduler and BFQ i/o scheduler, ONDEMAND governor. +voluntary preempt, CFS cpu scheduler and BFQ i/o scheduler. %mkflavour netbook-pae %endif %endif @@ -714,7 +715,7 @@ voluntary preempt, CFS cpu scheduler and BFQ i/o scheduler, ONDEMAND governor. %define summary_nrj_desktop586 Linux kernel for desktop use with i586 & 4GB RAM %define info_nrj_desktop586 This kernel is compiled for desktop use, single or \ multiple i586 processor(s)/core(s) and less than 4GB RAM, using HZ_1000, \ -full preempt, rcu boost, CFS cpu scheduler and BFQ i/o scheduler, ONDEMAND governor. +full preempt, rcu boost, CFS cpu scheduler and BFQ i/o scheduler. %mkflavour nrj-desktop586 %endif %endif @@ -727,12 +728,12 @@ full preempt, rcu boost, CFS cpu scheduler and BFQ i/o scheduler, ONDEMAND gover %define summary_nrj_desktop Linux Kernel for desktop use with i686 & 4GB RAM %define info_nrj_desktop This kernel is compiled for desktop use, single or \ multiple i686 processor(s)/core(s) and less than 4GB RAM, using HZ_1000, \ -full preempt, rcu boost, RIFS cpu scheduler and BFQ I/O scheduler, ONDEMAND governor. +full preempt, rcu boost, RIFS cpu scheduler and BFQ I/O scheduler. %else %define summary_nrj_desktop Linux Kernel for desktop use with %{_arch} %define info_nrj_desktop This kernel is compiled for desktop use, single or \ multiple %{_arch} processor(s)/core(s), using HZ_1000, \ -full preempt, rcu boost, RIFS cpu scheduler and BFQ I/O scheduler, ONDEMAND governor. +full preempt, rcu boost, RIFS cpu scheduler and BFQ I/O scheduler. %endif %mkflavour nrj-desktop %endif @@ -745,12 +746,12 @@ full preempt, rcu boost, RIFS cpu scheduler and BFQ I/O scheduler, ONDEMAND gove %define summary_nrj_realtime Linux Kernel for low latency use with i686 & 4GB RAM %define info_nrj_realtime This kernel is compiled for low latency use, single or \ multiple i686 processor(s)/core(s) and less than 4GB RAM, using HZ_1000, \ -full preempt, rcu boost, CFS cpu scheduler and new BFQ I/O scheduler, PERFORMANCE governor. +full preempt, rcu boost, CFS cpu scheduler and new BFQ I/O scheduler. %else %define summary_nrj_realtime Linux Kernel for low latency use with %{_arch} %define info_nrj_realtime This kernel is compiled for low latency use, single or \ multiple %{_arch} processor(s)/core(s), using HZ_1000, \ -full preempt, rcu boost, CFS cpu scheduler and new BFQ I/O scheduler, PERFORMANCE governor. +full preempt, rcu boost, CFS cpu scheduler and new BFQ I/O scheduler. %endif %mkflavour nrj-realtime %endif @@ -763,12 +764,12 @@ full preempt, rcu boost, CFS cpu scheduler and new BFQ I/O scheduler, PERFORMANC %define summary_nrj_server Linux Kernel for server use with i686 & 64GB RAM %define info_nrj_server This kernel is compiled for server use, single or \ multiple i686 processor(s)/core(s) and up to 64GB RAM using PAE, using \ -no preempt, HZ_100, CFS cpu scheduler and BFQ i/o scheduler, ONDEMAND governor. +no preempt, HZ_100, CFS cpu scheduler and BFQ i/o scheduler. %else %define summary_nrj_server Linux Kernel for server use with %{_arch} %define info_nrj_server This kernel is compiled for server use, single or \ multiple %{_arch} processor(s)/core(s), using no preempt, HZ_100, \ -CFS cpu scheduler and BFQ i/o scheduler, ONDEMAND governor. +CFS cpu scheduler and BFQ i/o scheduler. %endif %mkflavour nrj-server %endif @@ -781,12 +782,12 @@ CFS cpu scheduler and BFQ i/o scheduler, ONDEMAND governor. %define summary_nrj_laptop Linux Kernel for laptop use with i686 & 4GB RAM %define info_nrj_laptop This kernel is compiled for laptop use, single or \ multiple i686 processor(s)/core(s) and less than 4GB RAM, using HZ_300, \ -full preempt, rcu boost, CFS cpu scheduler and BFQ i/o scheduler, ONDEMAND governor. +full preempt, rcu boost, CFS cpu scheduler and BFQ i/o scheduler. %else %define summary_nrj_laptop Linux Kernel for laptop use with %{_arch} %define info_nrj_laptop This kernel is compiled for laptop use, single or \ multiple %{_arch} processor(s)/core(s), using HZ_300, \ -full preempt, rcu boost, CFS cpu scheduler and BFQ i/o scheduler, ONDEMAND governor. +full preempt, rcu boost, CFS cpu scheduler and BFQ i/o scheduler. %endif %mkflavour nrj-laptop %endif @@ -799,12 +800,12 @@ full preempt, rcu boost, CFS cpu scheduler and BFQ i/o scheduler, ONDEMAND gover %define summary_nrj_netbook Linux Kernel for netbook use with i686 & 4GB RAM %define info_nrj_netbook This kernel is compiled for netbook use, single or \ multiple i686 processor(s)/core(s) and less than 4GB RAM, using HZ_250, \ -full preempt, rcu boost, CFS cpu scheduler and BFQ i/o scheduler, ONDEMAND governor. +full preempt, rcu boost, CFS cpu scheduler and BFQ i/o scheduler. %else %define summary_nrj_netbook Linux Kernel for netbook use with %{_arch} %define info_nrj_netbook This kernel is compiled for netbook use, single or \ multiple %{_arch} processor(s)/core(s), using HZ_250, \ -full preempt, rcu boost, CFS cpu scheduler and BFQ i/o scheduler, ONDEMAND governor. +full preempt, rcu boost, CFS cpu scheduler and BFQ i/o scheduler. %endif %mkflavour nrj-netbook %endif @@ -818,7 +819,7 @@ full preempt, rcu boost, CFS cpu scheduler and BFQ i/o scheduler, ONDEMAND gover %define summary_nrj_desktop_pae Linux kernel for desktop use with i686 & upto 64GB RAM %define info_nrj_desktop_pae This kernel is compiled for desktop use, single or \ multiple i686 processor(s)/core(s) and up to 64GB RAM using PAE, using HZ_1000, \ -full preempt, rcu boost, CFS cpu scheduler and BFQ i/o scheduler, ONDEMAND governor. +full preempt, rcu boost, CFS cpu scheduler and BFQ i/o scheduler. %mkflavour nrj-desktop-pae %endif %endif @@ -832,7 +833,7 @@ full preempt, rcu boost, CFS cpu scheduler and BFQ i/o scheduler, ONDEMAND gover %define summary_nrj_realtime_pae Linux kernel for low latency use with i686 & upto 64GB RAM %define info_nrj_realtime_pae This kernel is compiled for low latency use, single or \ multiple i686 processor(s)/core(s) and up to 64GB RAM using PAE, using HZ_1000, \ -full preempt, rcu boost, CFS cpu scheduler and new BFQ I/O scheduler, PERFORMANCE governor. +full preempt, rcu boost, CFS cpu scheduler and new BFQ I/O scheduler. %mkflavour nrj-realtime-pae %endif %endif @@ -846,7 +847,7 @@ full preempt, rcu boost, CFS cpu scheduler and new BFQ I/O scheduler, PERFORMANC %define summary_nrj_laptop_pae Linux Kernel for for laptop use with i686 & upto 64GB RAM %define info_nrj_laptop_pae This kernel is compiled for laptop use, single or \ multiple i686 processor(s)/core(s) and up to 64GB RAM using PAE, using HZ_300, \ -full preempt, rcu boost, CFS cpu scheduler and BFQ i/o scheduler, ONDEMAND governor. +full preempt, rcu boost, CFS cpu scheduler and BFQ i/o scheduler. %mkflavour nrj-laptop-pae %endif %endif @@ -860,7 +861,7 @@ full preempt, rcu boost, CFS cpu scheduler and BFQ i/o scheduler, ONDEMAND gover %define summary_nrj_netbook_pae Linux Kernel for for netbook use with i686 & upto 64GB RAM %define info_nrj_netbook_pae This kernel is compiled for netbook use, single or \ multiple i686 processor(s)/core(s) and up to 64GB RAM using PAE, using HZ_250, \ -full preempt, rcu boost, CFS cpu scheduler and BFQ i/o scheduler, ONDEMAND governor. +full preempt, rcu boost, CFS cpu scheduler and BFQ i/o scheduler. %mkflavour nrj-netbook-pae %endif %endif @@ -874,7 +875,7 @@ full preempt, rcu boost, CFS cpu scheduler and BFQ i/o scheduler, ONDEMAND gover %define summary_nrj_netbook_atom Linux Kernel for netbook use with Intel Atom cpu, less than 4GB RAM %define info_nrj_netbook_atom This kernel is compiled for netbook use, single or \ multiple Intel Atom cpu processor(s)/core(s) and less than 4GB RAM, using HZ_250, \ -full preempt, rcu boost, CFS cpu scheduler and BFQ i/o scheduler, ONDEMAND governor. +full preempt, rcu boost, CFS cpu scheduler and BFQ i/o scheduler. %mkflavour nrj-netbook-atom %endif %endif @@ -888,7 +889,7 @@ full preempt, rcu boost, CFS cpu scheduler and BFQ i/o scheduler, ONDEMAND gover %define summary_nrj_netbook_atom_pae Linux Kernel for netbook use with Intel Atom cpu & upto 64GB RAM %define info_nrj_netbook_atom_pae This kernel is compiled for netbook use, single or \ multiple Intel Atom cpu processor(s)/core(s) and up to 64GB RAM using PAE, using HZ_250, \ -full preempt, rcu boost, CFS cpu scheduler and BFQ i/o scheduler, ONDEMAND governor. +full preempt, rcu boost, CFS cpu scheduler and BFQ i/o scheduler. %mkflavour nrj-netbook-atom-pae %endif %endif @@ -902,7 +903,7 @@ full preempt, rcu boost, CFS cpu scheduler and BFQ i/o scheduler, ONDEMAND gover %define summary_nrj_desktop_core2 Linux Kernel for desktop use with i686 & 4GB RAM %define info_nrj_desktop_core2 This kernel is compiled for desktop use, single or \ multiple Intel Core 2 and newer processor(s)/core(s) and less than 4GB RAM, using HZ_1000, \ -full preempt, rcu boost, CFS cpu scheduler and BFQ i/o scheduler, ONDEMAND governor. +full preempt, rcu boost, CFS cpu scheduler and BFQ i/o scheduler. %mkflavour nrj-desktop-core2 %endif %endif @@ -916,7 +917,7 @@ full preempt, rcu boost, CFS cpu scheduler and BFQ i/o scheduler, ONDEMAND gover %define summary_nrj_desktop_core2_pae Linux Kernel for desktop use with i686 & upto 64GB RAM %define info_nrj_desktop_core2_pae This kernel is compiled for desktop use, single or \ multiple Intel Core 2 and newer processor(s)/core(s) and up to 64GB RAM using PAE, using HZ_1000, \ -full preempt, rcu boost, CFS cpu scheduler and BFQ i/o scheduler, ONDEMAND governor. +full preempt, rcu boost, CFS cpu scheduler and BFQ i/o scheduler. %mkflavour nrj-desktop-core2-pae %endif %endif @@ -1029,33 +1030,6 @@ The cpupower tools. %post -n cpupower -AVAIL_FILE=/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors -CFG_FILE=%{_sysconfdir}/sysconfig/cpupower - -if ! [ -e "${AVAIL_FILE}" ]; then - echo "Warning: CPU frequency scaling is not supported." - echo "Setting 'performance' governor as the default, just in case." - sed -i 's/@GOVERNOR@/performance/g' "${CFG_FILE}" - exit 0 -fi - -# Set "ondemand" or "powersave" by default, if they are supported, -# "performance" otherwise. -# ? Perhaps it is better to do this in runtime rather than here? -if grep "ondemand" "${AVAIL_FILE}" >/dev/null 2>&1; then - echo "Info: setting 'ondemand' governor as the default." - sed -i 's/@GOVERNOR@/ondemand/g' "${CFG_FILE}" -elif grep "powersave" "${AVAIL_FILE}" >/dev/null 2>&1; then - echo "Info: setting 'powersave' governor as the default." - sed -i 's/@GOVERNOR@/powersave/g' "${CFG_FILE}" -else - echo -n "Info: setting 'performance' governor as the default." - cat "${AVAIL_FILE}" - echo - sed -i 's/@GOVERNOR@/performance/g' "${CFG_FILE}" - exit 0 -fi - if [ $1 -ge 0 ]; then /bin/systemctl enable cpupower >/dev/null 2>&1 || : /bin/systemctl start cpupower >/dev/null 2>&1 || : @@ -1856,6 +1830,7 @@ chmod 0755 %{buildroot}%{_libdir}/libcpupower.so* mkdir -p %{buildroot}%{_unitdir} %{buildroot}%{_sysconfdir}/sysconfig install -m644 %{SOURCE50} %{buildroot}%{_unitdir}/cpupower.service install -m644 %{SOURCE51} %{buildroot}%{_sysconfdir}/sysconfig/cpupower +install -m755 %{SOURCE52} %{buildroot}%{_bindir}/cpupower-start.sh %endif ############################################################ ### Linker start4 > Check point to build for omv or rosa ### @@ -1967,6 +1942,7 @@ rm -rf %{buildroot} %if %{build_cpupower} %files -n cpupower -f cpupower.lang %{_bindir}/cpupower +%{_bindir}/cpupower-start.sh %{_libdir}/libcpupower.so.0 %{_libdir}/libcpupower.so.0.0.0 %{_unitdir}/cpupower.service