Skip to content

Add configurable gpu thermal zone #89

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions data/config
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ WidgetsRight: [Tray, Packages, Audio, Bluetooth, Network, Disk, VRAM, GPU, RAM,
# The CPU sensor to use
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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved this option above to make it easier for a new user to understand the AmdGpuThermalZone comment


# 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
SuspendCommand: ~/.config/scripts/sys.sh suspend

Expand Down Expand Up @@ -160,10 +167,6 @@ 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

Expand Down
10 changes: 10 additions & 0 deletions module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ in {
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";
};
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 {
type = types.str;
default = "systemctl suspend";
Expand Down
5 changes: 2 additions & 3 deletions src/AMDGPU.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ namespace AMDGPU
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()
{
Expand Down Expand Up @@ -46,7 +44,8 @@ namespace AMDGPU
return {};
}

std::ifstream file(drmCardPrefix + Config::Get().drmAmdCard + tempFile);
std::ifstream file(drmCardPrefix + Config::Get().drmAmdCard + Config::Get().amdGpuThermalZone);

std::string line;
std::getline(file, line);
return atoi(line.c_str()) / 1000;
Expand Down
1 change: 1 addition & 0 deletions src/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ void Config::Load(const std::string& overrideConfigLocation)
AddConfigVar("WidgetsRight", config.widgetsRight, lineView, foundProperty);

AddConfigVar("CPUThermalZone", config.cpuThermalZone, lineView, foundProperty);
AddConfigVar("AmdGPUThermalZone", config.amdGpuThermalZone, lineView, foundProperty);
AddConfigVar("NetworkAdapter", config.networkAdapter, lineView, foundProperty);
AddConfigVar("DrmAmdCard", config.drmAmdCard, lineView, foundProperty);
AddConfigVar("SuspendCommand", config.suspendCommand, lineView, foundProperty);
Expand Down
1 change: 1 addition & 0 deletions src/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Config
"VRAM", "GPU", "RAM", "CPU", "Battery", "Power"};

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 drmAmdCard = "card0"; // The card to poll in AMDGPU.
std::string suspendCommand = "systemctl suspend";
Expand Down