blob: 555418f821f0875ddacd90ca906d21e3c87a149d [file] [log] [blame]
Harshit Aghera902c6492025-05-08 15:57:42 +05301/*
2 * SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION &
3 * AFFILIATES. All rights reserved.
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#pragma once
8
9#include "MctpRequester.hpp"
10#include "Thresholds.hpp"
11#include "sensor.hpp"
12
13#include <NvidiaGpuMctpVdm.hpp>
14#include <sdbusplus/asio/connection.hpp>
15#include <sdbusplus/asio/object_server.hpp>
16
17#include <array>
18#include <cstdint>
19#include <memory>
Marc Olberdingd0125c92025-10-08 14:37:19 -070020#include <span>
Harshit Aghera902c6492025-05-08 15:57:42 +053021#include <string>
Marc Olberdingd0125c92025-10-08 14:37:19 -070022#include <system_error>
Harshit Aghera902c6492025-05-08 15:57:42 +053023#include <vector>
24
25constexpr uint8_t gpuPowerSensorId{0};
26
Marc Olberdingfd4a3772025-09-24 16:31:02 -070027struct NvidiaGpuPowerSensor :
28 public Sensor,
29 public std::enable_shared_from_this<NvidiaGpuPowerSensor>
Harshit Aghera902c6492025-05-08 15:57:42 +053030{
31 public:
32 NvidiaGpuPowerSensor(
33 std::shared_ptr<sdbusplus::asio::connection>& conn,
34 mctp::MctpRequester& mctpRequester, const std::string& name,
35 const std::string& sensorConfiguration, uint8_t eid, uint8_t sensorId,
36 sdbusplus::asio::object_server& objectServer,
37 std::vector<thresholds::Threshold>&& thresholdData);
38
39 ~NvidiaGpuPowerSensor() override;
40
41 void checkThresholds() override;
42
43 void update();
44
45 private:
Marc Olberdingd0125c92025-10-08 14:37:19 -070046 void processResponse(const std::error_code& ec,
47 std::span<const uint8_t> buffer);
Harshit Aghera902c6492025-05-08 15:57:42 +053048
49 uint8_t eid{};
50
51 uint8_t sensorId;
52
Ed Tanousaba6fca2025-09-29 13:53:20 -070053 uint8_t averagingInterval = 0;
Harshit Aghera902c6492025-05-08 15:57:42 +053054
55 std::shared_ptr<sdbusplus::asio::connection> conn;
56
57 mctp::MctpRequester& mctpRequester;
58
59 sdbusplus::asio::object_server& objectServer;
60
Harshit Aghera6b712322025-07-31 19:25:12 +053061 std::array<uint8_t, sizeof(gpu::GetPowerDrawRequest)> request{};
Harshit Aghera902c6492025-05-08 15:57:42 +053062};