From c2233cdc98139d48da71a94eaecd4da4eebcfe15 Mon Sep 17 00:00:00 2001 From: AuxXxilium Date: Fri, 11 Oct 2024 23:30:35 +0200 Subject: [PATCH] cpufreqscaling: add back Signed-off-by: AuxXxilium --- cpufreqscaling/all/usr/sbin/scaling.sh | 49 ++++++++++++++++++++++++++ cpufreqscaling/install.sh | 47 ++++++++++++++++++++++++ cpufreqscaling/manifest.yml | 20 +++++++++++ 3 files changed, 116 insertions(+) create mode 100755 cpufreqscaling/all/usr/sbin/scaling.sh create mode 100755 cpufreqscaling/install.sh create mode 100644 cpufreqscaling/manifest.yml diff --git a/cpufreqscaling/all/usr/sbin/scaling.sh b/cpufreqscaling/all/usr/sbin/scaling.sh new file mode 100755 index 0000000..df747a6 --- /dev/null +++ b/cpufreqscaling/all/usr/sbin/scaling.sh @@ -0,0 +1,49 @@ +#!/usr/bin/env bash +# +# Copyright (C) 2023 AuxXxilium +# +# This is free software, licensed under the MIT License. +# See /LICENSE for more information. +# + +# Make things safer +set -euo pipefail + +# Get cpu cores count minus 1, to allow maping from 0 +cpucorecount=$(cat /proc/cpuinfo | grep processor | wc -l) +cpucorecount=$((cpucorecount - 1)) +error=0 + +# Load the correct cpufreq module +if [ "${1}" = "ondemand" ] || [ "${1}" = "conservative" ]; then + if [ -f "/usr/lib/modules/cpufreq_${1}.ko" ]; then + modprobe cpufreq_${1} + echo "CPUFreqScaling: cpufreq_${1} loaded" + else + echo "CPUFreqScaling: cpufreq_${1} not found" + error=1 + break + fi +fi +# Deamonize the main function... +for i in $(seq 0 ${cpucorecount}); do + governor=$(cat /sys/devices/system/cpu/cpu${i}/cpufreq/scaling_governor) + # Set correct cpufreq governor to allow frequency scaling + if [ "${governor}" != "${1}" ]; then + echo "${1}" >/sys/devices/system/cpu/cpu${i}/cpufreq/scaling_governor + fi +done +sleep 10 +# Check if the governor is set correctly +for i in $(seq 0 ${cpucorecount}); do + governor=$(cat /sys/devices/system/cpu/cpu${i}/cpufreq/scaling_governor) + if [ "${governor}" = "${1}" ]; then + echo "CPUFreqScaling: Governor set to ${1}" + else + echo "CPUFreqScaling: Failed to set governor to ${1}" + error=1 + break + fi +done +[ ${error} -eq 1 ] && exit 1 +exit 0 \ No newline at end of file diff --git a/cpufreqscaling/install.sh b/cpufreqscaling/install.sh new file mode 100755 index 0000000..81da22b --- /dev/null +++ b/cpufreqscaling/install.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env ash +# +# Copyright (C) 2023 AuxXxilium +# +# This is free software, licensed under the MIT License. +# See /LICENSE for more information. +# + +if [ "${1}" = "late" ]; then + echo "Installing cpufreqscalingscaling - ${1}" + mkdir -p "/tmpRoot/usr/arc/addons/" + cp -vf "${0}" "/tmpRoot/usr/arc/addons/" + + cp -vf /usr/sbin/scaling.sh /tmpRoot/usr/sbin/scaling.sh + [ ! -f "/tmpRoot/usr/bin/echo" ] && cp -vf /usr/bin/echo /tmpRoot/usr/bin/echo || true + cp -f /usr/lib/modules/acpi_cpufreq.ko /tmpRoot/usr/lib/modules/acpi_cpufreq.ko + [ "${2}" != "schedutil" ] && cp -vf /usr/lib/modules/cpufreq_${2}.ko /tmpRoot/usr/lib/modules/cpufreq_${2}.ko && modprobe cpufreq_${2} || true + mkdir -p "/tmpRoot/usr/lib/systemd/system" + DEST="/tmpRoot/usr/lib/systemd/system/cpufreqscaling.service" + cat <${DEST} +[Unit] +Description=Enable CPU Freq scaling +DefaultDependencies=no +IgnoreOnIsolate=true +After=multi-user.target +After=udevrules.service + +[Service] +User=root +Type=simple +Restart=on-failure +RestartSec=10 +ExecStart=/usr/sbin/scaling.sh ${2} + +[Install] +WantedBy=multi-user.target +EOF + mkdir -vp /tmpRoot/usr/lib/systemd/system/multi-user.target.wants + ln -vsf /usr/lib/systemd/system/cpufreqscaling.service /tmpRoot/usr/lib/systemd/system/multi-user.target.wants/cpufreqscaling.service +elif [ "${1}" = "uninstall" ]; then + echo "Installing cpufreqscalingscaling - ${1}" + + rm -f "/tmpRoot/usr/lib/systemd/system/multi-user.target.wants/cpufreqscaling.service" + rm -f "/tmpRoot/usr/lib/systemd/system/cpufreqscaling.service" + + rm -f /tmpRoot/usr/sbin/scaling.sh +fi \ No newline at end of file diff --git a/cpufreqscaling/manifest.yml b/cpufreqscaling/manifest.yml new file mode 100644 index 0000000..393eb81 --- /dev/null +++ b/cpufreqscaling/manifest.yml @@ -0,0 +1,20 @@ +version: 1 +name: cpufreqscaling +description: "Enable CPU Freqscaling for DSM - Modify in Arc DSM Options" +system: false +beta: false +target: system +all: + install-script: "install.sh" + copy: "all" +apollolake: true +broadwell: true +broadwellnk: true +broadwellnkv2: true +broadwellntbap: true +denverton: true +geminilake: true +purley: true +v1000: true +r1000: true +epyc7002: true \ No newline at end of file