From dfa07a4eb966ee90a76aa249fbbd32786e1041c4 Mon Sep 17 00:00:00 2001 From: bouhaa Date: Mon, 24 Jul 2023 09:53:07 +0200 Subject: [PATCH] add power sensors patch to mangohud (#702) --- ...-Use-k10-temp-power-sensors-if-exist.patch | 65 +++++++++++++++++++ pkgs/mangohud/PKGBUILD | 11 ++++ 2 files changed, 76 insertions(+) create mode 100644 pkgs/mangohud/0001-Use-k10-temp-power-sensors-if-exist.patch diff --git a/pkgs/mangohud/0001-Use-k10-temp-power-sensors-if-exist.patch b/pkgs/mangohud/0001-Use-k10-temp-power-sensors-if-exist.patch new file mode 100644 index 000000000..39c0c944c --- /dev/null +++ b/pkgs/mangohud/0001-Use-k10-temp-power-sensors-if-exist.patch @@ -0,0 +1,65 @@ +From 20033beb012ad2e6d342c1e412afc426f2b32bd1 Mon Sep 17 00:00:00 2001 +From: Bouke Haarsma +Date: Sun, 23 Jul 2023 21:54:26 +0200 +Subject: [PATCH] Use k10-temp power sensors if exist + +--- + src/cpu.cpp | 17 ++++++++++++++++- + src/cpu.h | 6 ++++++ + 2 files changed, 22 insertions(+), 1 deletion(-) + +diff --git a/src/cpu.cpp b/src/cpu.cpp +index a33873987c..ee92b7bb9e 100644 +--- a/src/cpu.cpp ++++ b/src/cpu.cpp +@@ -296,9 +296,24 @@ bool CPUStats::UpdateCpuTemp() { + static bool get_cpu_power_k10temp(CPUPowerData* cpuPowerData, float& power) { + CPUPowerData_k10temp* powerData_k10temp = (CPUPowerData_k10temp*)cpuPowerData; + +- if (!powerData_k10temp->coreVoltageFile || !powerData_k10temp->coreCurrentFile || !powerData_k10temp->socVoltageFile || !powerData_k10temp->socCurrentFile) ++ if (!powerData_k10temp->coreVoltageFile || !powerData_k10temp->coreCurrentFile || !powerData_k10temp->socVoltageFile || !powerData_k10temp->socCurrentFile || !powerData_k10temp->corePowerFile || !powerData_k10temp->socPowerFile) + return false; + ++ if(powerData_k10temp->corePowerFile || powerData_k10temp->socPowerFile) ++ { ++ rewind(powerData_k10temp->corePowerFile); ++ rewind(powerData_k10temp->socPowerFile); ++ fflush(powerData_k10temp->corePowerFile); ++ fflush(powerData_k10temp->socPowerFile); ++ int corePower, socPower; ++ if (fscanf(powerData_k10temp->corePowerFile, "%d", &corePower) != 1) ++ goto voltagebased; ++ if (fscanf(powerData_k10temp->socPowerFile, "%d", &socPower) != 1) ++ goto voltagebased; ++ power = (corePower + socPower) / 1000000; ++ return true; ++ } ++ voltagebased: + rewind(powerData_k10temp->coreVoltageFile); + rewind(powerData_k10temp->coreCurrentFile); + rewind(powerData_k10temp->socVoltageFile); +diff --git a/src/cpu.h b/src/cpu.h +index ed91d98f0d..ef31735e69 100644 +--- a/src/cpu.h ++++ b/src/cpu.h +@@ -72,12 +72,18 @@ struct CPUPowerData_k10temp : public CPUPowerData { + fclose(this->socVoltageFile); + if(this->socCurrentFile) + fclose(this->socCurrentFile); ++ if(this->corePowerFile) ++ fclose(this->corePowerFile); ++ if(this->socPowerFile) ++ fclose(this->socPowerFile); + }; + + FILE* coreVoltageFile {nullptr}; + FILE* coreCurrentFile {nullptr}; + FILE* socVoltageFile {nullptr}; + FILE* socCurrentFile {nullptr}; ++ FILE* corePowerFile {nullptr}; ++ FILE* socPowerFile {nullptr}; + }; + + struct CPUPowerData_zenpower : public CPUPowerData { +-- +2.41.0 diff --git a/pkgs/mangohud/PKGBUILD b/pkgs/mangohud/PKGBUILD index b377ae3f1..5fad0ea67 100644 --- a/pkgs/mangohud/PKGBUILD +++ b/pkgs/mangohud/PKGBUILD @@ -21,6 +21,7 @@ source=( "nlohmann_json-3.10.5.zip::https://github.com/nlohmann/json/releases/download/v3.10.5/include.zip" "vulkan-headers-1.2.158.tar.gz::https://github.com/KhronosGroup/Vulkan-Headers/archive/v1.2.158.tar.gz" "vulkan-headers-1.2.158-2-wrap.zip::https://wrapdb.mesonbuild.com/v2/vulkan-headers_1.2.158-2/get_patch" + "0001-Use-k10-temp-power-sensors-if-exist.patch" ) sha256sums=( @@ -33,6 +34,7 @@ sha256sums=( 'b94997df68856753b72f0d7a3703b7d484d4745c567f3584ef97c96c25a5798e' '53361271cfe274df8782e1e47bdc9e61b7af432ba30acbfe31723f9df2c257f3' '860358cf5e73f458cd1e88f8c38116d123ab421d5ce2e4129ec38eaedd820e17' + '1aa439a66b5b46505d6039fbca00fb8dd9d0ac454a9babcaadd732f94f84e534' ) _build_args="-Dappend_libdir_mangohud=false -Dwith_xnvctrl=disabled -Dmangoapp_layer=true" @@ -48,6 +50,15 @@ prepare() { git config submodule.modules/minhook.url "$srcdir/mangohud-minhook" git -c protocol.file.allow=always submodule update + local src + for src in "${source[@]}"; do + src="${src%%::*}" + src="${src##*/}" + [[ $src = *.patch ]] || continue + echo "Applying patch $src..." + patch -Np1 < "../$src" + done + # meson subprojects ln -sv "$srcdir/imgui-1.81" subprojects ln -sv "$srcdir/spdlog-1.8.5" subprojects