Harshit Aghera | 4ecdfaa | 2025-05-22 11:35:39 +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 | #include "NvidiaGpuDevice.hpp" |
| 8 | |
| 9 | #include "NvidiaDeviceDiscovery.hpp" |
| 10 | #include "NvidiaGpuSensor.hpp" |
| 11 | #include "Thresholds.hpp" |
| 12 | #include "Utils.hpp" |
| 13 | |
| 14 | #include <bits/basic_string.h> |
| 15 | |
| 16 | #include <MctpRequester.hpp> |
| 17 | #include <boost/asio/io_context.hpp> |
| 18 | #include <phosphor-logging/lg2.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> |
| 26 | #include <vector> |
| 27 | |
| 28 | GpuDevice::GpuDevice(const SensorConfigs& configs, const std::string& name, |
| 29 | const std::string& path, |
| 30 | const std::shared_ptr<sdbusplus::asio::connection>& conn, |
| 31 | uint8_t eid, boost::asio::io_context& io, |
| 32 | mctp::MctpRequester& mctpRequester, |
| 33 | sdbusplus::asio::object_server& objectServer) : |
| 34 | eid(eid), sensorPollMs(std::chrono::milliseconds{configs.pollRate}), |
| 35 | waitTimer(io, std::chrono::steady_clock::duration(0)), |
| 36 | mctpRequester(mctpRequester), conn(conn), objectServer(objectServer), |
| 37 | configs(configs), name(escapeName(name)), path(path) |
| 38 | { |
| 39 | makeSensors(); |
| 40 | } |
| 41 | |
| 42 | void GpuDevice::makeSensors() |
| 43 | { |
| 44 | tempSensor = std::make_shared<NvidiaGpuTempSensor>( |
| 45 | conn, mctpRequester, name + "_TEMP_0", path, eid, objectServer, |
| 46 | std::vector<thresholds::Threshold>{}); |
| 47 | |
| 48 | lg2::info("Added GPU {NAME} Sensors with chassis path: {PATH}.", "NAME", |
| 49 | name, "PATH", path); |
| 50 | |
| 51 | read(); |
| 52 | } |
| 53 | |
| 54 | void GpuDevice::read() |
| 55 | { |
| 56 | tempSensor->update(); |
| 57 | |
| 58 | waitTimer.expires_after(std::chrono::milliseconds(sensorPollMs)); |
| 59 | waitTimer.async_wait([this](const boost::system::error_code& ec) { |
| 60 | if (ec) |
| 61 | { |
| 62 | return; |
| 63 | } |
| 64 | read(); |
| 65 | }); |
| 66 | } |