| 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 | |
| Marc Olberding | fd4a377 | 2025-09-24 16:31:02 -0700 | [diff] [blame] | 25 | struct NvidiaGpuEnergySensor : |
| 26 | public Sensor, |
| 27 | public std::enable_shared_from_this<NvidiaGpuEnergySensor> |
| Harshit Aghera | 775199d | 2025-05-27 14:20:24 +0530 | [diff] [blame] | 28 | { |
| 29 | public: |
| 30 | NvidiaGpuEnergySensor( |
| 31 | std::shared_ptr<sdbusplus::asio::connection>& conn, |
| 32 | mctp::MctpRequester& mctpRequester, const std::string& name, |
| 33 | const std::string& sensorConfiguration, uint8_t eid, uint8_t sensorId, |
| 34 | sdbusplus::asio::object_server& objectServer, |
| 35 | std::vector<thresholds::Threshold>&& thresholdData); |
| 36 | |
| 37 | ~NvidiaGpuEnergySensor() override; |
| 38 | |
| 39 | void checkThresholds() override; |
| 40 | |
| 41 | void update(); |
| 42 | |
| 43 | private: |
| Marc Olberding | d0125c9 | 2025-10-08 14:37:19 -0700 | [diff] [blame] | 44 | void processResponse(const std::error_code& ec, |
| 45 | std::span<const uint8_t> buffer); |
| Harshit Aghera | 775199d | 2025-05-27 14:20:24 +0530 | [diff] [blame] | 46 | |
| 47 | uint8_t eid{}; |
| 48 | |
| 49 | uint8_t sensorId; |
| 50 | |
| 51 | std::shared_ptr<sdbusplus::asio::connection> conn; |
| 52 | |
| 53 | mctp::MctpRequester& mctpRequester; |
| 54 | |
| 55 | sdbusplus::asio::object_server& objectServer; |
| 56 | |
| 57 | std::array<uint8_t, sizeof(gpu::GetCurrentEnergyCounterRequest)> request{}; |
| Harshit Aghera | 775199d | 2025-05-27 14:20:24 +0530 | [diff] [blame] | 58 | }; |