Add DrmAmdCard config option

Some AMD cards are under card1, so make the hardcoded path at least a
bit configurable.
This commit is contained in:
scorpion-26 2023-11-02 23:04:09 +01:00
parent 48c0f4814d
commit 9b551fe848
4 changed files with 17 additions and 10 deletions

View file

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

View file

@ -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,7 +46,7 @@ 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;
@ -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());

View file

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

View file

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