1*4ecdfaaaSHarshit Aghera /* 2*4ecdfaaaSHarshit Aghera * SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & 3*4ecdfaaaSHarshit Aghera * AFFILIATES. All rights reserved. 4*4ecdfaaaSHarshit Aghera * SPDX-License-Identifier: Apache-2.0 5*4ecdfaaaSHarshit Aghera */ 6*4ecdfaaaSHarshit Aghera 7*4ecdfaaaSHarshit Aghera #include "NvidiaGpuDevice.hpp" 8*4ecdfaaaSHarshit Aghera 9*4ecdfaaaSHarshit Aghera #include "NvidiaDeviceDiscovery.hpp" 10*4ecdfaaaSHarshit Aghera #include "NvidiaGpuSensor.hpp" 11*4ecdfaaaSHarshit Aghera #include "Thresholds.hpp" 12*4ecdfaaaSHarshit Aghera #include "Utils.hpp" 13*4ecdfaaaSHarshit Aghera 14*4ecdfaaaSHarshit Aghera #include <bits/basic_string.h> 15*4ecdfaaaSHarshit Aghera 16*4ecdfaaaSHarshit Aghera #include <MctpRequester.hpp> 17*4ecdfaaaSHarshit Aghera #include <boost/asio/io_context.hpp> 18*4ecdfaaaSHarshit Aghera #include <phosphor-logging/lg2.hpp> 19*4ecdfaaaSHarshit Aghera #include <sdbusplus/asio/connection.hpp> 20*4ecdfaaaSHarshit Aghera #include <sdbusplus/asio/object_server.hpp> 21*4ecdfaaaSHarshit Aghera 22*4ecdfaaaSHarshit Aghera #include <chrono> 23*4ecdfaaaSHarshit Aghera #include <cstdint> 24*4ecdfaaaSHarshit Aghera #include <memory> 25*4ecdfaaaSHarshit Aghera #include <string> 26*4ecdfaaaSHarshit Aghera #include <vector> 27*4ecdfaaaSHarshit Aghera 28*4ecdfaaaSHarshit Aghera GpuDevice::GpuDevice(const SensorConfigs& configs, const std::string& name, 29*4ecdfaaaSHarshit Aghera const std::string& path, 30*4ecdfaaaSHarshit Aghera const std::shared_ptr<sdbusplus::asio::connection>& conn, 31*4ecdfaaaSHarshit Aghera uint8_t eid, boost::asio::io_context& io, 32*4ecdfaaaSHarshit Aghera mctp::MctpRequester& mctpRequester, 33*4ecdfaaaSHarshit Aghera sdbusplus::asio::object_server& objectServer) : 34*4ecdfaaaSHarshit Aghera eid(eid), sensorPollMs(std::chrono::milliseconds{configs.pollRate}), 35*4ecdfaaaSHarshit Aghera waitTimer(io, std::chrono::steady_clock::duration(0)), 36*4ecdfaaaSHarshit Aghera mctpRequester(mctpRequester), conn(conn), objectServer(objectServer), 37*4ecdfaaaSHarshit Aghera configs(configs), name(escapeName(name)), path(path) 38*4ecdfaaaSHarshit Aghera { 39*4ecdfaaaSHarshit Aghera makeSensors(); 40*4ecdfaaaSHarshit Aghera } 41*4ecdfaaaSHarshit Aghera 42*4ecdfaaaSHarshit Aghera void GpuDevice::makeSensors() 43*4ecdfaaaSHarshit Aghera { 44*4ecdfaaaSHarshit Aghera tempSensor = std::make_shared<NvidiaGpuTempSensor>( 45*4ecdfaaaSHarshit Aghera conn, mctpRequester, name + "_TEMP_0", path, eid, objectServer, 46*4ecdfaaaSHarshit Aghera std::vector<thresholds::Threshold>{}); 47*4ecdfaaaSHarshit Aghera 48*4ecdfaaaSHarshit Aghera lg2::info("Added GPU {NAME} Sensors with chassis path: {PATH}.", "NAME", 49*4ecdfaaaSHarshit Aghera name, "PATH", path); 50*4ecdfaaaSHarshit Aghera 51*4ecdfaaaSHarshit Aghera read(); 52*4ecdfaaaSHarshit Aghera } 53*4ecdfaaaSHarshit Aghera 54*4ecdfaaaSHarshit Aghera void GpuDevice::read() 55*4ecdfaaaSHarshit Aghera { 56*4ecdfaaaSHarshit Aghera tempSensor->update(); 57*4ecdfaaaSHarshit Aghera 58*4ecdfaaaSHarshit Aghera waitTimer.expires_after(std::chrono::milliseconds(sensorPollMs)); 59*4ecdfaaaSHarshit Aghera waitTimer.async_wait([this](const boost::system::error_code& ec) { 60*4ecdfaaaSHarshit Aghera if (ec) 61*4ecdfaaaSHarshit Aghera { 62*4ecdfaaaSHarshit Aghera return; 63*4ecdfaaaSHarshit Aghera } 64*4ecdfaaaSHarshit Aghera read(); 65*4ecdfaaaSHarshit Aghera }); 66*4ecdfaaaSHarshit Aghera } 67