| 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> |
| Marc Olberding | d0125c9 | 2025-10-08 14:37:19 -0700 | [diff] [blame] | 20 | #include <span> |
| Harshit Aghera | 902c649 | 2025-05-08 15:57:42 +0530 | [diff] [blame] | 21 | #include <string> |
| Marc Olberding | d0125c9 | 2025-10-08 14:37:19 -0700 | [diff] [blame] | 22 | #include <system_error> |
| Harshit Aghera | 902c649 | 2025-05-08 15:57:42 +0530 | [diff] [blame] | 23 | #include <vector> |
| 24 | |
| 25 | constexpr uint8_t gpuPowerSensorId{0}; |
| 26 | |
| Marc Olberding | fd4a377 | 2025-09-24 16:31:02 -0700 | [diff] [blame] | 27 | struct NvidiaGpuPowerSensor : |
| 28 | public Sensor, |
| 29 | public std::enable_shared_from_this<NvidiaGpuPowerSensor> |
| Harshit Aghera | 902c649 | 2025-05-08 15:57:42 +0530 | [diff] [blame] | 30 | { |
| 31 | public: |
| 32 | NvidiaGpuPowerSensor( |
| 33 | std::shared_ptr<sdbusplus::asio::connection>& conn, |
| 34 | mctp::MctpRequester& mctpRequester, const std::string& name, |
| 35 | const std::string& sensorConfiguration, uint8_t eid, uint8_t sensorId, |
| 36 | sdbusplus::asio::object_server& objectServer, |
| 37 | std::vector<thresholds::Threshold>&& thresholdData); |
| 38 | |
| 39 | ~NvidiaGpuPowerSensor() override; |
| 40 | |
| 41 | void checkThresholds() override; |
| 42 | |
| 43 | void update(); |
| 44 | |
| 45 | private: |
| Marc Olberding | d0125c9 | 2025-10-08 14:37:19 -0700 | [diff] [blame] | 46 | void processResponse(const std::error_code& ec, |
| 47 | std::span<const uint8_t> buffer); |
| Harshit Aghera | 902c649 | 2025-05-08 15:57:42 +0530 | [diff] [blame] | 48 | |
| 49 | uint8_t eid{}; |
| 50 | |
| 51 | uint8_t sensorId; |
| 52 | |
| Ed Tanous | aba6fca | 2025-09-29 13:53:20 -0700 | [diff] [blame] | 53 | uint8_t averagingInterval = 0; |
| Harshit Aghera | 902c649 | 2025-05-08 15:57:42 +0530 | [diff] [blame] | 54 | |
| 55 | std::shared_ptr<sdbusplus::asio::connection> conn; |
| 56 | |
| 57 | mctp::MctpRequester& mctpRequester; |
| 58 | |
| 59 | sdbusplus::asio::object_server& objectServer; |
| 60 | |
| Harshit Aghera | 6b71232 | 2025-07-31 19:25:12 +0530 | [diff] [blame] | 61 | std::array<uint8_t, sizeof(gpu::GetPowerDrawRequest)> request{}; |
| Harshit Aghera | 902c649 | 2025-05-08 15:57:42 +0530 | [diff] [blame] | 62 | }; |