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