From 9b551fe848e71bbe77c63edabe9e472d6dce55da Mon Sep 17 00:00:00 2001 From: scorpion-26 Date: Thu, 2 Nov 2023 23:04:09 +0100 Subject: [PATCH] Add DrmAmdCard config option Some AMD cards are under card1, so make the hardcoded path at least a bit configurable. --- data/config | 4 ++++ src/AMDGPU.h | 21 +++++++++++---------- src/Config.cpp | 1 + src/Config.h | 1 + 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/data/config b/data/config index d0fc0c2..d1a513a 100644 --- a/data/config +++ b/data/config @@ -124,6 +124,10 @@ NetworkAdapter: eno1 # Disables the network widget when set to false NetworkWidget: true +# The card to poll when using AMDGPU. If you don't have an AMD card, you can skip this config. +# Possible values can be found by querying /sys/class/drm +DrmAmdCard: card0 + # Use tooltips instead of sliders for the sensors SensorTooltips: false diff --git a/src/AMDGPU.h b/src/AMDGPU.h index 6136160..a296e2b 100644 --- a/src/AMDGPU.h +++ b/src/AMDGPU.h @@ -6,16 +6,17 @@ #ifdef WITH_AMD namespace AMDGPU { - static const char* utilizationFile = "/sys/class/drm/card0/device/gpu_busy_percent"; - static const char* vramTotalFile = "/sys/class/drm/card0/device/mem_info_vram_total"; - static const char* vramUsedFile = "/sys/class/drm/card0/device/mem_info_vram_used"; + static const char* drmCardPrefix = "/sys/class/drm/"; + static const char* utilizationFile = "/device/gpu_busy_percent"; + static const char* vramTotalFile = "/device/mem_info_vram_total"; + static const char* vramUsedFile = "/device/mem_info_vram_used"; // TODO: Make this configurable static const char* tempFile = "/sys/class/drm/card0/device/hwmon/hwmon1/temp1_input"; inline void Init() { // Test for drm device files - std::ifstream test(utilizationFile); + std::ifstream test(drmCardPrefix + Config::Get().drmAmdCard + utilizationFile); if (!test.is_open()) { LOG("AMD GPU not found, disabling AMD GPU"); @@ -31,7 +32,7 @@ namespace AMDGPU return {}; } - std::ifstream file(utilizationFile); + std::ifstream file(drmCardPrefix + Config::Get().drmAmdCard + utilizationFile); std::string line; std::getline(file, line); return atoi(line.c_str()); @@ -45,13 +46,13 @@ namespace AMDGPU return {}; } - std::ifstream file(tempFile); + std::ifstream file(drmCardPrefix + Config::Get().drmAmdCard + tempFile); std::string line; std::getline(file, line); return atoi(line.c_str()) / 1000; } - struct VRAM + struct VRAM { uint32_t totalB; uint32_t usedB; @@ -66,12 +67,12 @@ namespace AMDGPU } VRAM mem{}; - std::ifstream file(vramTotalFile); + std::ifstream file(drmCardPrefix + Config::Get().drmAmdCard + vramTotalFile); std::string line; std::getline(file, line); mem.totalB = atoi(line.c_str()); - - file = std::ifstream(vramUsedFile); + + file = std::ifstream(drmCardPrefix + Config::Get().drmAmdCard + vramUsedFile); std::getline(file, line); mem.usedB = atoi(line.c_str()); diff --git a/src/Config.cpp b/src/Config.cpp index f57ff9c..b61c265 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -232,6 +232,7 @@ void Config::Load() AddConfigVar("CPUThermalZone", config.cpuThermalZone, lineView, foundProperty); AddConfigVar("NetworkAdapter", config.networkAdapter, lineView, foundProperty); + AddConfigVar("DrmAmdCard", config.drmAmdCard, lineView, foundProperty); AddConfigVar("SuspendCommand", config.suspendCommand, lineView, foundProperty); AddConfigVar("LockCommand", config.lockCommand, lineView, foundProperty); AddConfigVar("ExitCommand", config.exitCommand, lineView, foundProperty); diff --git a/src/Config.h b/src/Config.h index c78a46e..980075a 100644 --- a/src/Config.h +++ b/src/Config.h @@ -14,6 +14,7 @@ public: std::string cpuThermalZone = ""; // idk, no standard way of doing this. std::string networkAdapter = "eno1"; // Is this standard? + std::string drmAmdCard = "card0"; // The card to poll in AMDGPU. std::string suspendCommand = "systemctl suspend"; std::string lockCommand = ""; // idk, no standard way of doing this. std::string exitCommand = ""; // idk, no standard way of doing this.