Skip to content

Commit

Permalink
add power sensors patch to mangohud (#702)
Browse files Browse the repository at this point in the history
  • Loading branch information
BoukeHaarsma23 authored Jul 24, 2023
1 parent 72f1e2e commit dfa07a4
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
65 changes: 65 additions & 0 deletions pkgs/mangohud/0001-Use-k10-temp-power-sensors-if-exist.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
From 20033beb012ad2e6d342c1e412afc426f2b32bd1 Mon Sep 17 00:00:00 2001
From: Bouke Haarsma <[email protected]>
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
11 changes: 11 additions & 0 deletions pkgs/mangohud/PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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=(
Expand All @@ -33,6 +34,7 @@ sha256sums=(
'b94997df68856753b72f0d7a3703b7d484d4745c567f3584ef97c96c25a5798e'
'53361271cfe274df8782e1e47bdc9e61b7af432ba30acbfe31723f9df2c257f3'
'860358cf5e73f458cd1e88f8c38116d123ab421d5ce2e4129ec38eaedd820e17'
'1aa439a66b5b46505d6039fbca00fb8dd9d0ac454a9babcaadd732f94f84e534'
)

_build_args="-Dappend_libdir_mangohud=false -Dwith_xnvctrl=disabled -Dmangoapp_layer=true"
Expand All @@ -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
Expand Down

0 comments on commit dfa07a4

Please sign in to comment.