Harshit Aghera | 902c649 | 2025-05-08 15:57:42 +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 gpuPowerSensorId{0}; |
| 24 | |
| 25 | struct NvidiaGpuPowerSensor : public Sensor |
| 26 | { |
| 27 | public: |
| 28 | NvidiaGpuPowerSensor( |
| 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 | ~NvidiaGpuPowerSensor() 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 | uint8_t averagingInterval; |
| 49 | |
| 50 | std::shared_ptr<sdbusplus::asio::connection> conn; |
| 51 | |
| 52 | mctp::MctpRequester& mctpRequester; |
| 53 | |
| 54 | sdbusplus::asio::object_server& objectServer; |
| 55 | |
| 56 | std::array<uint8_t, sizeof(gpu::GetCurrentPowerDrawRequest)> request{}; |
| 57 | |
| 58 | std::array<uint8_t, sizeof(gpu::GetCurrentPowerDrawResponse)> response{}; |
| 59 | }; |