| Harshit Aghera | 4ecdfaa | 2025-05-22 11:35:39 +0530 | [diff] [blame] | 1 | /* |
| Ed Tanous | b5e823f | 2025-10-09 20:28:42 -0400 | [diff] [blame^] | 2 | * SPDX-FileCopyrightText: Copyright OpenBMC Authors |
| Harshit Aghera | 4ecdfaa | 2025-05-22 11:35:39 +0530 | [diff] [blame] | 3 | * SPDX-License-Identifier: Apache-2.0 |
| 4 | */ |
| 5 | |
| 6 | #pragma once |
| 7 | |
| Rohit PAI | 0a88826 | 2025-06-11 08:52:29 +0530 | [diff] [blame] | 8 | #include "Inventory.hpp" |
| Harshit Aghera | 4ecdfaa | 2025-05-22 11:35:39 +0530 | [diff] [blame] | 9 | #include "MctpRequester.hpp" |
| 10 | #include "NvidiaDeviceDiscovery.hpp" |
| Harshit Aghera | 902c649 | 2025-05-08 15:57:42 +0530 | [diff] [blame] | 11 | #include "NvidiaGpuPowerSensor.hpp" |
| Harshit Aghera | 4ecdfaa | 2025-05-22 11:35:39 +0530 | [diff] [blame] | 12 | #include "NvidiaGpuSensor.hpp" |
| 13 | |
| Harshit Aghera | 775199d | 2025-05-27 14:20:24 +0530 | [diff] [blame] | 14 | #include <NvidiaGpuEnergySensor.hpp> |
| Harshit Aghera | 6b71232 | 2025-07-31 19:25:12 +0530 | [diff] [blame] | 15 | #include <NvidiaGpuPowerPeakReading.hpp> |
| Harshit Aghera | bef4d41 | 2025-05-27 14:53:56 +0530 | [diff] [blame] | 16 | #include <NvidiaGpuVoltageSensor.hpp> |
| Harshit Aghera | 4ecdfaa | 2025-05-22 11:35:39 +0530 | [diff] [blame] | 17 | #include <boost/asio/io_context.hpp> |
| 18 | #include <boost/asio/steady_timer.hpp> |
| 19 | #include <sdbusplus/asio/connection.hpp> |
| 20 | #include <sdbusplus/asio/object_server.hpp> |
| 21 | |
| 22 | #include <chrono> |
| 23 | #include <cstdint> |
| 24 | #include <memory> |
| 25 | #include <string> |
| Harshit Aghera | 5e7decc | 2025-05-07 16:20:16 +0530 | [diff] [blame] | 26 | #include <vector> |
| Harshit Aghera | 4ecdfaa | 2025-05-22 11:35:39 +0530 | [diff] [blame] | 27 | |
| Marc Olberding | 6282a45 | 2025-09-28 22:00:09 -0700 | [diff] [blame] | 28 | class GpuDevice : public std::enable_shared_from_this<GpuDevice> |
| Harshit Aghera | 4ecdfaa | 2025-05-22 11:35:39 +0530 | [diff] [blame] | 29 | { |
| 30 | public: |
| 31 | GpuDevice(const SensorConfigs& configs, const std::string& name, |
| 32 | const std::string& path, |
| 33 | const std::shared_ptr<sdbusplus::asio::connection>& conn, |
| 34 | uint8_t eid, boost::asio::io_context& io, |
| 35 | mctp::MctpRequester& mctpRequester, |
| 36 | sdbusplus::asio::object_server& objectServer); |
| 37 | |
| 38 | const std::string& getPath() const |
| 39 | { |
| 40 | return path; |
| 41 | } |
| 42 | |
| Marc Olberding | ac92073 | 2025-09-28 21:56:54 -0700 | [diff] [blame] | 43 | void init(); |
| 44 | |
| Harshit Aghera | 4ecdfaa | 2025-05-22 11:35:39 +0530 | [diff] [blame] | 45 | private: |
| 46 | void makeSensors(); |
| 47 | |
| 48 | void read(); |
| 49 | |
| Marc Olberding | 6282a45 | 2025-09-28 22:00:09 -0700 | [diff] [blame] | 50 | void processTLimitThresholds(const std::error_code& ec); |
| 51 | |
| 52 | void getTLimitThresholds(); |
| Harshit Aghera | 5e7decc | 2025-05-07 16:20:16 +0530 | [diff] [blame] | 53 | |
| Harshit Aghera | 4ecdfaa | 2025-05-22 11:35:39 +0530 | [diff] [blame] | 54 | uint8_t eid{}; |
| 55 | |
| Marc Olberding | 6282a45 | 2025-09-28 22:00:09 -0700 | [diff] [blame] | 56 | void getNextThermalParameter(); |
| 57 | void readThermalParameterCallback(const std::error_code& ec, |
| 58 | std::span<const uint8_t> buffer); |
| 59 | |
| Harshit Aghera | 4ecdfaa | 2025-05-22 11:35:39 +0530 | [diff] [blame] | 60 | std::chrono::milliseconds sensorPollMs; |
| 61 | |
| 62 | boost::asio::steady_timer waitTimer; |
| 63 | |
| 64 | mctp::MctpRequester& mctpRequester; |
| 65 | |
| 66 | std::shared_ptr<sdbusplus::asio::connection> conn; |
| 67 | |
| 68 | sdbusplus::asio::object_server& objectServer; |
| 69 | |
| 70 | std::shared_ptr<NvidiaGpuTempSensor> tempSensor; |
| Harshit Aghera | ba138da | 2025-05-05 12:26:35 +0530 | [diff] [blame] | 71 | std::shared_ptr<NvidiaGpuTempSensor> tLimitSensor; |
| Harshit Aghera | b10a67b | 2025-05-27 12:19:29 +0530 | [diff] [blame] | 72 | std::shared_ptr<NvidiaGpuTempSensor> dramTempSensor; |
| Harshit Aghera | 902c649 | 2025-05-08 15:57:42 +0530 | [diff] [blame] | 73 | std::shared_ptr<NvidiaGpuPowerSensor> powerSensor; |
| Harshit Aghera | 6b71232 | 2025-07-31 19:25:12 +0530 | [diff] [blame] | 74 | std::shared_ptr<NvidiaGpuPowerPeakReading> peakPower; |
| Harshit Aghera | 775199d | 2025-05-27 14:20:24 +0530 | [diff] [blame] | 75 | std::shared_ptr<NvidiaGpuEnergySensor> energySensor; |
| Harshit Aghera | bef4d41 | 2025-05-27 14:53:56 +0530 | [diff] [blame] | 76 | std::shared_ptr<NvidiaGpuVoltageSensor> voltageSensor; |
| Harshit Aghera | 4ecdfaa | 2025-05-22 11:35:39 +0530 | [diff] [blame] | 77 | |
| Marc Olberding | 6282a45 | 2025-09-28 22:00:09 -0700 | [diff] [blame] | 78 | std::array<uint8_t, sizeof(gpu::ReadThermalParametersRequest)> |
| 79 | thermalParamReqMsg{}; |
| Marc Olberding | 1851f64 | 2025-09-29 10:44:46 -0700 | [diff] [blame] | 80 | std::array<int32_t, 3> thresholds{}; |
| Marc Olberding | 6282a45 | 2025-09-28 22:00:09 -0700 | [diff] [blame] | 81 | size_t current_threshold_index{}; |
| 82 | |
| Harshit Aghera | 4ecdfaa | 2025-05-22 11:35:39 +0530 | [diff] [blame] | 83 | SensorConfigs configs; |
| 84 | |
| 85 | std::string name; |
| 86 | |
| 87 | std::string path; |
| Rohit PAI | 0a88826 | 2025-06-11 08:52:29 +0530 | [diff] [blame] | 88 | |
| 89 | std::shared_ptr<Inventory> inventory; |
| Harshit Aghera | 4ecdfaa | 2025-05-22 11:35:39 +0530 | [diff] [blame] | 90 | }; |