| Harshit Aghera | 775199d | 2025-05-27 14:20:24 +0530 | [diff] [blame] | 1 | /* | 
|  | 2 | * SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & | 
|  | 3 | * AFFILIATES. All rights reserved. | 
|  | 4 | * SPDX-License-Identifier: Apache-2.0 | 
|  | 5 | */ | 
|  | 6 |  | 
|  | 7 | #pragma once | 
|  | 8 |  | 
|  | 9 | #include "MctpRequester.hpp" | 
|  | 10 | #include "Thresholds.hpp" | 
|  | 11 | #include "sensor.hpp" | 
|  | 12 |  | 
|  | 13 | #include <NvidiaGpuMctpVdm.hpp> | 
|  | 14 | #include <sdbusplus/asio/connection.hpp> | 
|  | 15 | #include <sdbusplus/asio/object_server.hpp> | 
|  | 16 |  | 
|  | 17 | #include <array> | 
|  | 18 | #include <cstdint> | 
|  | 19 | #include <memory> | 
|  | 20 | #include <string> | 
|  | 21 | #include <vector> | 
|  | 22 |  | 
|  | 23 | constexpr uint8_t gpuEnergySensorId{0}; | 
|  | 24 |  | 
|  | 25 | struct NvidiaGpuEnergySensor : public Sensor | 
|  | 26 | { | 
|  | 27 | public: | 
|  | 28 | NvidiaGpuEnergySensor( | 
|  | 29 | std::shared_ptr<sdbusplus::asio::connection>& conn, | 
|  | 30 | mctp::MctpRequester& mctpRequester, const std::string& name, | 
|  | 31 | const std::string& sensorConfiguration, uint8_t eid, uint8_t sensorId, | 
|  | 32 | sdbusplus::asio::object_server& objectServer, | 
|  | 33 | std::vector<thresholds::Threshold>&& thresholdData); | 
|  | 34 |  | 
|  | 35 | ~NvidiaGpuEnergySensor() override; | 
|  | 36 |  | 
|  | 37 | void checkThresholds() override; | 
|  | 38 |  | 
|  | 39 | void update(); | 
|  | 40 |  | 
|  | 41 | private: | 
|  | 42 | void processResponse(int sendRecvMsgResult); | 
|  | 43 |  | 
|  | 44 | uint8_t eid{}; | 
|  | 45 |  | 
|  | 46 | uint8_t sensorId; | 
|  | 47 |  | 
|  | 48 | std::shared_ptr<sdbusplus::asio::connection> conn; | 
|  | 49 |  | 
|  | 50 | mctp::MctpRequester& mctpRequester; | 
|  | 51 |  | 
|  | 52 | sdbusplus::asio::object_server& objectServer; | 
|  | 53 |  | 
|  | 54 | std::array<uint8_t, sizeof(gpu::GetCurrentEnergyCounterRequest)> request{}; | 
|  | 55 |  | 
|  | 56 | std::array<uint8_t, sizeof(gpu::GetCurrentEnergyCounterResponse)> | 
|  | 57 | response{}; | 
|  | 58 | }; |