nvidia-gpu: add power sensor
This patch adds support to fetch power sensor value from gpu
Tested: Build an image for gb200nvl-obmc machine with the following
patches cherry picked. This patches are needed to enable the mctp stack.
https://gerrit.openbmc.org/c/openbmc/openbmc/+/79422
```
$ curl -s -k -u 'root:0penBmc' https://10.137.203.137/redfish/v1/Chassis/NVIDIA_GB200_1/Sensors/power_NVIDIA_GB200_GPU_0_Power_0
{
"@odata.id": "/redfish/v1/Chassis/NVIDIA_GB200_1/Sensors/power_NVIDIA_GB200_GPU_0_Power_0",
"@odata.type": "#Sensor.v1_2_0.Sensor",
"Id": "power_NVIDIA_GB200_GPU_0_Power_0",
"Name": "NVIDIA GB200 GPU 0 Power 0",
"Reading": 27.181,
"ReadingRangeMax": 4294967.295,
"ReadingRangeMin": 0.0,
"ReadingType": "Power",
"ReadingUnits": "W",
"Status": {
"Health": "OK",
"State": "Enabled"
}
}%
```
Change-Id: Ic227a0056daa68ab2239a609ed20c7ed2f6bd2c5
Signed-off-by: Harshit Aghera <haghera@nvidia.com>
diff --git a/src/nvidia-gpu/NvidiaGpuPowerSensor.hpp b/src/nvidia-gpu/NvidiaGpuPowerSensor.hpp
new file mode 100644
index 0000000..89b0ab4
--- /dev/null
+++ b/src/nvidia-gpu/NvidiaGpuPowerSensor.hpp
@@ -0,0 +1,59 @@
+/*
+ * SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION &
+ * AFFILIATES. All rights reserved.
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+#pragma once
+
+#include "MctpRequester.hpp"
+#include "Thresholds.hpp"
+#include "sensor.hpp"
+
+#include <NvidiaGpuMctpVdm.hpp>
+#include <sdbusplus/asio/connection.hpp>
+#include <sdbusplus/asio/object_server.hpp>
+
+#include <array>
+#include <cstdint>
+#include <memory>
+#include <string>
+#include <vector>
+
+constexpr uint8_t gpuPowerSensorId{0};
+
+struct NvidiaGpuPowerSensor : public Sensor
+{
+ public:
+ NvidiaGpuPowerSensor(
+ std::shared_ptr<sdbusplus::asio::connection>& conn,
+ mctp::MctpRequester& mctpRequester, const std::string& name,
+ const std::string& sensorConfiguration, uint8_t eid, uint8_t sensorId,
+ sdbusplus::asio::object_server& objectServer,
+ std::vector<thresholds::Threshold>&& thresholdData);
+
+ ~NvidiaGpuPowerSensor() override;
+
+ void checkThresholds() override;
+
+ void update();
+
+ private:
+ void processResponse(int sendRecvMsgResult);
+
+ uint8_t eid{};
+
+ uint8_t sensorId;
+
+ uint8_t averagingInterval;
+
+ std::shared_ptr<sdbusplus::asio::connection> conn;
+
+ mctp::MctpRequester& mctpRequester;
+
+ sdbusplus::asio::object_server& objectServer;
+
+ std::array<uint8_t, sizeof(gpu::GetCurrentPowerDrawRequest)> request{};
+
+ std::array<uint8_t, sizeof(gpu::GetCurrentPowerDrawResponse)> response{};
+};