xref: /openbmc/dbus-sensors/src/nvidia-gpu/NvidiaGpuPowerPeakReading.hpp (revision d0125c9cdf0f0ae7f1943f773c99fc512db0a68e)
16b712322SHarshit Aghera /*
26b712322SHarshit Aghera  * SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION &
36b712322SHarshit Aghera  * AFFILIATES. All rights reserved.
46b712322SHarshit Aghera  * SPDX-License-Identifier: Apache-2.0
56b712322SHarshit Aghera  */
66b712322SHarshit Aghera 
76b712322SHarshit Aghera #pragma once
86b712322SHarshit Aghera 
96b712322SHarshit Aghera #include "MctpRequester.hpp"
106b712322SHarshit Aghera 
116b712322SHarshit Aghera #include <NvidiaGpuMctpVdm.hpp>
126b712322SHarshit Aghera #include <sdbusplus/asio/object_server.hpp>
136b712322SHarshit Aghera 
146b712322SHarshit Aghera #include <array>
156b712322SHarshit Aghera #include <cstdint>
166b712322SHarshit Aghera #include <memory>
176b712322SHarshit Aghera #include <string>
186b712322SHarshit Aghera #include <tuple>
196b712322SHarshit Aghera #include <vector>
206b712322SHarshit Aghera 
216b712322SHarshit Aghera constexpr uint8_t gpuPeakPowerSensorId{0};
226b712322SHarshit Aghera 
236b712322SHarshit Aghera // GPU Power Sensor Averaging Interval in seconds, 0 implies default
246b712322SHarshit Aghera constexpr uint8_t gpuPowerAveragingIntervalInSec{0};
256b712322SHarshit Aghera 
266b712322SHarshit Aghera struct NvidiaGpuPowerPeakReading
276b712322SHarshit Aghera {
286b712322SHarshit Aghera   public:
296b712322SHarshit Aghera     NvidiaGpuPowerPeakReading(mctp::MctpRequester& mctpRequester,
306b712322SHarshit Aghera                               const std::string& name, uint8_t eid,
316b712322SHarshit Aghera                               uint8_t sensorId,
326b712322SHarshit Aghera                               sdbusplus::asio::object_server& objectServer);
336b712322SHarshit Aghera 
346b712322SHarshit Aghera     ~NvidiaGpuPowerPeakReading();
356b712322SHarshit Aghera 
366b712322SHarshit Aghera     void update();
376b712322SHarshit Aghera 
386b712322SHarshit Aghera   private:
39*d0125c9cSMarc Olberding     void processResponse(const std::error_code& ec,
40*d0125c9cSMarc Olberding                          std::span<const uint8_t> buffer);
416b712322SHarshit Aghera 
426b712322SHarshit Aghera     uint8_t eid{};
436b712322SHarshit Aghera 
446b712322SHarshit Aghera     uint8_t sensorId;
456b712322SHarshit Aghera 
466b712322SHarshit Aghera     uint8_t averagingInterval{gpuPowerAveragingIntervalInSec};
476b712322SHarshit Aghera 
486b712322SHarshit Aghera     std::tuple<
496b712322SHarshit Aghera         uint64_t,
506b712322SHarshit Aghera         std::vector<std::tuple<std::string, std::string, double, uint64_t>>>
516b712322SHarshit Aghera         readings;
526b712322SHarshit Aghera 
536b712322SHarshit Aghera     mctp::MctpRequester& mctpRequester;
546b712322SHarshit Aghera 
556b712322SHarshit Aghera     sdbusplus::asio::object_server& objectServer;
566b712322SHarshit Aghera 
576b712322SHarshit Aghera     std::array<uint8_t, sizeof(gpu::GetPowerDrawRequest)> request{};
586b712322SHarshit Aghera 
596b712322SHarshit Aghera     std::shared_ptr<sdbusplus::asio::dbus_interface> telemetryReportInterface;
606b712322SHarshit Aghera };
61