Skip to content
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

Add configurable gpu thermal zone #89

Merged
merged 7 commits into from
Apr 24, 2024
Merged

Conversation

senyc
Copy link
Contributor

@senyc senyc commented Apr 22, 2024

I noticed a bug where the tempFile was the entire path (instead of just the subpath) leading to some issues. So I fixed that and also added an option to set the entire path via the config since I'm not sure if the path will be the same for everyone.

If the path: device/hwmon/hwmon0/temp1_input won't change across machines then the configuration addition probably isn't needed since you can configure the card.

Copy link
Owner

@scorpion-26 scorpion-26 left a comment

Choose a reason for hiding this comment

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

Thank you for the PR!

This review is a bit more pedantic, since I want the config variables to behave consistent. I hope you understand :)

Some general points:

  • Can you make the config variable relative to /sys/class/drm/<card>/? (Since there is already a selector for the specific card)
  • The config variable + documentation is missing from data/config

src/AMDGPU.h Outdated
@@ -40,13 +39,20 @@ namespace AMDGPU

inline uint32_t GetTemperature()
{
if (!RuntimeConfig::Get().hasAMD)
if (!RuntimeConfig::Get().hasAMD && Config::Get().gpuThermalZone.empty())
Copy link
Owner

Choose a reason for hiding this comment

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

The additional check shouldn't be here (The check is only intended to fail if AMDGPU is disabled and this method is still called, meaning a developer error)

src/Config.cpp Outdated
@@ -252,6 +252,7 @@ void Config::Load(const std::string& overrideConfigLocation)
AddConfigVar("WidgetsRight", config.widgetsRight, lineView, foundProperty);

AddConfigVar("CPUThermalZone", config.cpuThermalZone, lineView, foundProperty);
AddConfigVar("GPUThermalZone", config.gpuThermalZone, lineView, foundProperty);
Copy link
Owner

Choose a reason for hiding this comment

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

The name should incorporate that this is only for AMD GPUs, so there is no confusion whether you actually need to set it. I'd suggest "AmdGPUThermalZone"

module.nix Outdated
@@ -38,6 +38,11 @@ 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";
};
GPUThermalZone = mkOption {
type = types.nullOr types.str;
default = "";
Copy link
Owner

Choose a reason for hiding this comment

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

Missing default. Please use the old value("device/hwmon/hwmon1/temp1_input") for backwards compatibility.

module.nix Outdated
GPUThermalZone = mkOption {
type = types.nullOr types.str;
default = "";
description = "path to the gpu thermal sensor, probably something in /sys/device";
Copy link
Owner

Choose a reason for hiding this comment

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

Please also mention here that this is AMD specific and that the path is relative to /sys/class/drm/<card>/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah lol I totally forgot about nvidia

src/AMDGPU.h Outdated
@@ -10,8 +10,7 @@ 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";
static const char* tempFile = "/device/hwmon/hwmon0/temp1_input";
Copy link
Owner

Choose a reason for hiding this comment

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

Not needed when the config variable has a default.

src/AMDGPU.h Outdated
file.open(Config::Get().gpuThermalZone);
} else {
file.open(drmCardPrefix + Config::Get().drmAmdCard + tempFile);
}
Copy link
Owner

Choose a reason for hiding this comment

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

This fallback code is not needed, when the gpuThermalZone has a default.

src/Config.h Outdated
@@ -14,6 +14,7 @@ class Config
"VRAM", "GPU", "RAM", "CPU", "Battery", "Power"};

std::string cpuThermalZone = ""; // idk, no standard way of doing this.
std::string gpuThermalZone = "";
Copy link
Owner

Choose a reason for hiding this comment

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

Please put the default value (The old one, same as comment in module.nix) here (Also for backwards compatibility)

@senyc
Copy link
Contributor Author

senyc commented Apr 22, 2024

Thank you for the PR!

This review is a bit more pedantic, since I want the config variables to behave consistent. I hope you understand :)

Some general points:

  • Can you make the config variable relative to /sys/class/drm/<card>/? (Since there is already a selector for the specific card)
  • The config variable + documentation is missing from data/config

Yeah for sure. I wasn't sure if that was how you wanted it done since it would be a little different than setting a CPU thermal zone (since for that we set a full path instead of a partial). To remove this difference between gpu/cpu's It might be worth changing things to only use full paths instead of setting the drmAmdCard with extra configuration for the sub path.

For example we could have config options for

  • AmdGpuUtilizationPath
  • AmdGpuThermalPath
  • AmdGpuVramPath

Removing the need for setting an explicit DrmAmdCard which is a little more work for the user, but a lot less confusing then adding arbitrary partial paths.

This would make things more inline with how things are set for the CPU. Let me know what you think, otherwise I can move forward with the points above (:

@scorpion-26
Copy link
Owner

Hmm, good points. I've thought about it a little and I think I still prefer relative paths, though:

  • Absolute paths would require either breaking old configs by removing DrmAmdCard or basically duplicating functionality in case AmdGpu* are not set. I'm not particularly fond of either of these options.
  • The 4 file configs (utilization, total vram, current vram and thermal zone) would all need to be present and each manually configured when changing the card index. IMHO this is a bit too much, especially since probably most (if not all) users will never want to change 3 of the 4 files.

@senyc
Copy link
Contributor Author

senyc commented Apr 23, 2024

Yeah sounds good, using relative paths is good for now, I'll get this updated to use them. It might be worth at some point looking into using a dependency or library that handles these queries in the future, or looking at what other bars/widgets do to solve this, not that it is that big of a deal haha.

@scorpion-26
Copy link
Owner

Last thing missing now is an entry in data/config with documentation (Can be copy-pasted from module.nix). Other than that, LGTM.

@@ -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

@scorpion-26 scorpion-26 merged commit b3f037d into scorpion-26:master Apr 24, 2024
@scorpion-26
Copy link
Owner

LGTM, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants