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