blob: 14627fcd21dc305be6a88ed3346c6cadffbe6b8c [file] [log] [blame]
Harshit Agherad837b562025-04-21 19:50:10 +05301/*
2 * SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION &
3 * AFFILIATES. All rights reserved. SPDX-License-Identifier: Apache-2.0
4 */
5
6#pragma once
7
8#include "Thresholds.hpp"
9#include "Utils.hpp"
10#include "sensor.hpp"
11
12#include <boost/asio/io_context.hpp>
13#include <boost/asio/steady_timer.hpp>
14#include <boost/container/flat_map.hpp>
15#include <sdbusplus/asio/connection.hpp>
16#include <sdbusplus/asio/object_server.hpp>
17#include <sdbusplus/message.hpp>
18
19#include <memory>
20#include <string>
21#include <vector>
22
23constexpr const char* sensorPathPrefix = "/xyz/openbmc_project/sensors/";
24constexpr const char* sensorType = "NvidiaMctpVdm";
25
26struct GpuTempSensor :
27 public Sensor,
28 public std::enable_shared_from_this<GpuTempSensor>
29{
30 public:
31 /**
32 * @brief Constructor for GpuTempSensor
33 * @param conn D-Bus connection
34 * @param io Boost ASIO I/O context for asynchronous operations
35 * @param mctpRequester MCTP protocol requester for GPU communication
36 * @param name Name of the sensor
37 * @param sensorConfiguration Configuration string for the sensor
38 * @param objectServer D-Bus object server
39 * @param thresholdData Vector of threshold configurations
40 * @param pollRate How often to poll for new readings
41 * @param deviceInfo Information about the GPU device
42 * @param verbose Whether to enable verbose logging
43 */
44 GpuTempSensor(std::shared_ptr<sdbusplus::asio::connection>& conn,
45 boost::asio::io_context& io, const std::string& name,
46 const std::string& sensorConfiguration,
47 sdbusplus::asio::object_server& objectServer,
48 std::vector<thresholds::Threshold>&& thresholdData);
49
50 /**
51 * @brief Destructor
52 */
53 ~GpuTempSensor() override;
54
55 /**
56 * @brief Check if any thresholds have been crossed
57 * @details Overrides the base class method to implement GPU-specific
58 * threshold checking
59 */
60 void checkThresholds() override;
61
62 private:
63 /**
64 * @brief Discover available GPUs on the system
65 */
66 void discoverGpus();
67
68 /**
69 * @brief Process MCTP endpoints discovered on the system
70 *
71 * @param[in] ec Error code from the D-Bus method call
72 * @param[in] ret Object tree results containing MCTP endpoint information
73 */
74 void queryEndpoints(const boost::system::error_code& ec,
75 const GetSubTreeType& ret);
76
77 /**
78 * @brief Process configuration properties for MCTP endpoints
79 *
80 * @param[in] ec Error code from the D-Bus properties method call
81 * @param[in] configs Map of configuration properties for the endpoint
82 */
83 void processEndpoint(const boost::system::error_code& ec,
84 const SensorBaseConfigMap& endpoint);
85
86 /**
87 * @brief Timer for scheduling sensor reads
88 */
89 boost::asio::steady_timer waitTimer;
90
91 /**
92 * @brief D-Bus connection
93 */
94 std::shared_ptr<sdbusplus::asio::connection> conn;
95
96 /**
97 * @brief D-Bus object server
98 */
99 sdbusplus::asio::object_server& objectServer;
100};
101
102/**
103 * @brief Create GPU temperature sensors
104 * @param io Boost ASIO I/O context
105 * @param objectServer D-Bus object server
106 * @param sensors Map to store created sensors
107 * @param dbusConnection D-Bus connection
108 */
109void createSensors(
110 boost::asio::io_context& io, sdbusplus::asio::object_server& objectServer,
111 boost::container::flat_map<std::string, std::shared_ptr<GpuTempSensor>>&
112 sensors,
113 std::shared_ptr<sdbusplus::asio::connection>& dbusConnection);
114
115/**
116 * @brief Handle D-Bus interface removal events
117 * @param message D-Bus message containing interface removal information
118 * @param sensors Map of GPU temperature sensors to check for removal
119 */
120void interfaceRemoved(
121 sdbusplus::message_t& message,
122 boost::container::flat_map<std::string, std::shared_ptr<GpuTempSensor>>&
123 sensors);