blob: 8fa967a316e45c32db65c4c9d1d065a407415c47 [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
27struct NvidiaGpuPowerSensor : public Sensor
28{
29 public:
30 NvidiaGpuPowerSensor(
31 std::shared_ptr<sdbusplus::asio::connection>& conn,
32 mctp::MctpRequester& mctpRequester, const std::string& name,
33 const std::string& sensorConfiguration, uint8_t eid, uint8_t sensorId,
34 sdbusplus::asio::object_server& objectServer,
35 std::vector<thresholds::Threshold>&& thresholdData);
36
37 ~NvidiaGpuPowerSensor() override;
38
39 void checkThresholds() override;
40
41 void update();
42
43 private:
Marc Olberdingd0125c92025-10-08 14:37:19 -070044 void processResponse(const std::error_code& ec,
45 std::span<const uint8_t> buffer);
Harshit Aghera902c6492025-05-08 15:57:42 +053046
47 uint8_t eid{};
48
49 uint8_t sensorId;
50
Ed Tanousaba6fca2025-09-29 13:53:20 -070051 uint8_t averagingInterval = 0;
Harshit Aghera902c6492025-05-08 15:57:42 +053052
53 std::shared_ptr<sdbusplus::asio::connection> conn;
54
55 mctp::MctpRequester& mctpRequester;
56
57 sdbusplus::asio::object_server& objectServer;
58
Harshit Aghera6b712322025-07-31 19:25:12 +053059 std::array<uint8_t, sizeof(gpu::GetPowerDrawRequest)> request{};
Harshit Aghera902c6492025-05-08 15:57:42 +053060};