Add configurable gpu thermal zone (#89)

There is a bug where the `tempFile` was the entire path (instead of
just the subpath) leading to some issues. This commit fixes that and also adds
an option to set the entire path.
This commit is contained in:
senyc 2024-04-24 11:31:40 -04:00 committed by GitHub
parent 3a7ff0d179
commit b3f037db5b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 21 additions and 7 deletions

View file

@ -32,6 +32,13 @@ WidgetsRight: [Tray, Packages, Audio, Bluetooth, Network, Disk, VRAM, GPU, RAM,
# The CPU sensor to use # The CPU sensor to use
CPUThermalZone: /sys/devices/pci0000:00/0000:00:18.3/hwmon/hwmon2/temp1_input CPUThermalZone: /sys/devices/pci0000:00/0000:00:18.3/hwmon/hwmon2/temp1_input
# 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
# Relative path to AMD gpu thermal sensor, appended after /sys/class/drm/<DrmAmdCard>
AmdGPUThermalZone: /device/hwmon/hwmon1/temp1_input
# The command to execute on suspend # The command to execute on suspend
SuspendCommand: ~/.config/scripts/sys.sh suspend SuspendCommand: ~/.config/scripts/sys.sh suspend
@ -160,10 +167,6 @@ NetworkAdapter: eno1
# Disables the network widget when set to false # Disables the network widget when set to false
NetworkWidget: true 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 # Use tooltips instead of sliders for the sensors
SensorTooltips: false SensorTooltips: false

View file

@ -38,6 +38,16 @@ in {
default = "/sys/devices/pci0000:00/0000:00:18.3/hwmon/hwmon2/temp1_input"; default = "/sys/devices/pci0000:00/0000:00:18.3/hwmon/hwmon2/temp1_input";
description = "path to the cpu thermal sensor, probably something in /sys/device"; description = "path to the cpu thermal sensor, probably something in /sys/device";
}; };
DrmAmdCard = mkOption {
type = types.nullOr types.str;
default = "card0";
description = "AMD card to be queried for various system usage and temperature metrics. This can be found in /sys/class/drm";
};
AmdGPUThermalZone = mkOption {
type = types.nullOr types.str;
default = "/device/hwmon/hwmon1/temp1_input";
description = "Relative path to AMD gpu thermal sensor, appended after /sys/class/drm/<DrmAmdCard>";
};
SuspendCommand = mkOption { SuspendCommand = mkOption {
type = types.str; type = types.str;
default = "systemctl suspend"; default = "systemctl suspend";

View file

@ -10,8 +10,6 @@ namespace AMDGPU
static const char* utilizationFile = "/device/gpu_busy_percent"; static const char* utilizationFile = "/device/gpu_busy_percent";
static const char* vramTotalFile = "/device/mem_info_vram_total"; static const char* vramTotalFile = "/device/mem_info_vram_total";
static const char* vramUsedFile = "/device/mem_info_vram_used"; 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() inline void Init()
{ {
@ -46,7 +44,8 @@ namespace AMDGPU
return {}; return {};
} }
std::ifstream file(drmCardPrefix + Config::Get().drmAmdCard + tempFile); std::ifstream file(drmCardPrefix + Config::Get().drmAmdCard + Config::Get().amdGpuThermalZone);
std::string line; std::string line;
std::getline(file, line); std::getline(file, line);
return atoi(line.c_str()) / 1000; return atoi(line.c_str()) / 1000;

View file

@ -252,6 +252,7 @@ void Config::Load(const std::string& overrideConfigLocation)
AddConfigVar("WidgetsRight", config.widgetsRight, lineView, foundProperty); AddConfigVar("WidgetsRight", config.widgetsRight, lineView, foundProperty);
AddConfigVar("CPUThermalZone", config.cpuThermalZone, lineView, foundProperty); AddConfigVar("CPUThermalZone", config.cpuThermalZone, lineView, foundProperty);
AddConfigVar("AmdGPUThermalZone", config.amdGpuThermalZone, lineView, foundProperty);
AddConfigVar("NetworkAdapter", config.networkAdapter, lineView, foundProperty); AddConfigVar("NetworkAdapter", config.networkAdapter, lineView, foundProperty);
AddConfigVar("DrmAmdCard", config.drmAmdCard, lineView, foundProperty); AddConfigVar("DrmAmdCard", config.drmAmdCard, lineView, foundProperty);
AddConfigVar("SuspendCommand", config.suspendCommand, lineView, foundProperty); AddConfigVar("SuspendCommand", config.suspendCommand, lineView, foundProperty);

View file

@ -14,6 +14,7 @@ public:
"VRAM", "GPU", "RAM", "CPU", "Battery", "Power"}; "VRAM", "GPU", "RAM", "CPU", "Battery", "Power"};
std::string cpuThermalZone = ""; // idk, no standard way of doing this. std::string cpuThermalZone = ""; // idk, no standard way of doing this.
std::string amdGpuThermalZone = "/device/hwmon/hwmon1/temp1_input";
std::string networkAdapter = "eno1"; // Is this standard? std::string networkAdapter = "eno1"; // Is this standard?
std::string drmAmdCard = "card0"; // The card to poll in AMDGPU. std::string drmAmdCard = "card0"; // The card to poll in AMDGPU.
std::string suspendCommand = "systemctl suspend"; std::string suspendCommand = "systemctl suspend";