From 7be571a94f93b9dfa8a4e4d467b0ca6609fcce2d Mon Sep 17 00:00:00 2001 From: Jussi Kuokkanen Date: Wed, 25 Oct 2023 14:59:39 +0300 Subject: [PATCH] add AMD clock readings --- src/plugins/AMD.cpp | 65 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/src/plugins/AMD.cpp b/src/plugins/AMD.cpp index 48a9bb6..bc59248 100644 --- a/src/plugins/AMD.cpp +++ b/src/plugins/AMD.cpp @@ -421,6 +421,65 @@ std::vector> getPowerUsage(AMDGPUData data) { return {}; } +std::vector> getCoreClockRead(AMDGPUData data) { + auto func = [=]() -> ReadResult { + uint clock; + if (amdgpu_query_sensor_info( + data.devHandle, AMDGPU_INFO_SENSOR_GFX_SCLK, sizeof(clock), &clock) == 0) + return clock; + return ReadError::UnknownError; + }; + + DynamicReadable dr{func, _("MHz")}; + + if (hasReadableValue(func())) { + return {DeviceNode{ + .name = _("Core Clock"), + .interface = dr, + .hash = md5(data.pciId + "Core Clock"), + }}; + } + return {}; +} + +std::vector> getMemoryClockRead(AMDGPUData data) { + auto func = [=]() -> ReadResult { + uint clock; + // TODO: is this actually the clock speed or memory controller clock? + if (amdgpu_query_sensor_info( + data.devHandle, AMDGPU_INFO_SENSOR_GFX_MCLK, sizeof(clock), &clock) == 0) + return clock; + return ReadError::UnknownError; + }; + + DynamicReadable dr{func, _("MHz")}; + + if (hasReadableValue(func())) { + return {DeviceNode{ + .name = _("Memory Clock"), + .interface = dr, + .hash = md5(data.pciId + "Memory Clock"), + }}; + } + return {}; +} + +std::vector> getClocksRoot(AMDGPUData data) { + return {DeviceNode{ + .name = _("Clocks"), + .interface = std::nullopt, + .hash = md5(data.pciId + "Clocks"), + }}; +} + +std::vector> getPerformanceRoot(AMDGPUData data) { + return {DeviceNode{ + .name = _("Performance"), + .interface = std::nullopt, + .hash = md5(data.pciId + "Performance"), + }}; +} + std::vector> getFanRoot(AMDGPUData data) { return {DeviceNode{ .name = _("Fans"), @@ -462,6 +521,12 @@ auto gpuTree = TreeConstructor{ {getPowerRoot, { {getPowerLimit, {}}, {getPowerUsage, {}} + }}, + {getPerformanceRoot, { + {getClocksRoot, { + {getMemoryClockRead, {}}, + {getCoreClockRead, {}} + }} }} } };