Skip to content

Commit ed63403

Browse files
committed
pldm: Enable polling sensors individually
Sensors are polling as part of the polling loop in sensor manager. There is no provision to read a sensor individually. Add the provision to read a sensor using D-Bus infrastructure. Signed-off-by: Shirish Pargaonkar <Shirish.Pargaonkar@amd.com>
1 parent c2f346a commit ed63403

8 files changed

Lines changed: 139 additions & 27 deletions

File tree

platform-mc/manager.hpp

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,14 @@ class Manager : public pldm::MctpDiscoveryHandlerIntf
3838
explicit Manager(sdeventplus::Event& event, RequesterHandler& handler,
3939
pldm::InstanceIdDb& instanceIdDb, const bool verbose) :
4040
terminusManager(event, handler, instanceIdDb, termini, this,
41-
pldm::BmcMctpEid),
41+
pldm::BmcMctpEid, nullptr),
4242
platformManager(terminusManager, termini, this),
4343
sensorManager(event, terminusManager, termini, this),
4444
eventManager(terminusManager, termini, verbose)
45-
{this->verbose = verbose;}
45+
{
46+
this->verbose = verbose;
47+
terminusManager.setSensorManager(&sensorManager);
48+
}
4649

4750
/** @brief Helper function to do the actions before discovering terminus
4851
*
@@ -106,7 +109,23 @@ class Manager : public pldm::MctpDiscoveryHandlerIntf
106109
*/
107110
void startSensorPolling(pldm_tid_t tid)
108111
{
109-
sensorManager.startPolling(tid);
112+
if (termini.contains(tid))
113+
{
114+
for (auto& sensor : termini[tid]->numericSensors)
115+
{
116+
if (sensor)
117+
{
118+
sensor->isReady = true;
119+
}
120+
}
121+
}
122+
123+
else
124+
{
125+
lg2::error("terminii does not contain TID: {TID}.", "TID", tid);
126+
}
127+
128+
sensorManager.startPolling(tid);
110129
}
111130

112131
/** @brief Helper function to set available state for pldm request (sensor

platform-mc/numeric_sensor.cpp

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "common/utils.hpp"
44
#include "requester/handler.hpp"
5+
#include "sensor_manager.hpp"
56

67
#include <libpldm/platform.h>
78

@@ -15,6 +16,27 @@ namespace pldm
1516
namespace platform_mc
1617
{
1718

19+
double SensorValue::value() const
20+
{
21+
if (this->nSensor.sensorManager && !nSensor.updateTime && nSensor.isReady && !nSensor.pollPending)
22+
{
23+
nSensor.pollPending = true;
24+
25+
lg2::info("Get reading for sensor Id: {ID}", "ID", nSensor.sensorId);
26+
nSensor.scope.spawn(
27+
[](SensorManager* manager, NumericSensor* sensor) -> exec::task<void> {
28+
auto sPtr = std::shared_ptr<NumericSensor>(sensor, [](auto) {});
29+
co_await manager->getSensorReading(sPtr);
30+
sensor->pollPending = false;
31+
co_return;
32+
}(nSensor.sensorManager, const_cast<NumericSensor*>(&nSensor))
33+
);
34+
}
35+
36+
auto value = ValueIntf::value();
37+
return value;
38+
}
39+
1840
inline bool NumericSensor::createInventoryPath(
1941
const std::string& associationPath, const std::string& sensorName,
2042
const uint16_t entityType, const uint16_t entityInstanceNum,
@@ -163,7 +185,9 @@ void NumericSensor::setSensorUnit(uint8_t baseUnit)
163185
NumericSensor::NumericSensor(
164186
const pldm_tid_t tid, const bool sensorDisabled,
165187
std::shared_ptr<pldm_numeric_sensor_value_pdr> pdr, std::string& sensorName,
166-
std::string& associationPath) : tid(tid), sensorName(sensorName)
188+
std::string& associationPath, SensorManager* sensorManager,
189+
exec::async_scope& scoperef) :
190+
tid(tid), sensorName(sensorName), sensorManager(sensorManager), scope(scoperef)
167191
{
168192
if (!pdr)
169193
{
@@ -289,7 +313,7 @@ NumericSensor::NumericSensor(
289313
{
290314
try
291315
{
292-
valueIntf = std::make_unique<ValueIntf>(bus, path.c_str());
316+
valueIntf = std::make_unique<SensorValue>(bus, path.c_str(), *this);
293317
}
294318
catch (const sdbusplus::exception_t& e)
295319
{
@@ -419,8 +443,9 @@ NumericSensor::NumericSensor(
419443
NumericSensor::NumericSensor(
420444
const pldm_tid_t tid, const bool sensorDisabled,
421445
std::shared_ptr<pldm_compact_numeric_sensor_pdr> pdr,
422-
std::string& sensorName, std::string& associationPath) :
423-
tid(tid), sensorName(sensorName)
446+
std::string& sensorName, std::string& associationPath, SensorManager* sensorManager,
447+
exec::async_scope& scoperef) :
448+
tid(tid), sensorName(sensorName), sensorManager(sensorManager), scope(scoperef)
424449
{
425450
if (!pdr)
426451
{
@@ -532,7 +557,7 @@ NumericSensor::NumericSensor(
532557
{
533558
try
534559
{
535-
valueIntf = std::make_unique<ValueIntf>(bus, path.c_str());
560+
valueIntf = std::make_unique<SensorValue>(bus, path.c_str(), *this);
536561
}
537562
catch (const sdbusplus::exception_t& e)
538563
{
@@ -698,7 +723,7 @@ void NumericSensor::updateReading(bool available, bool functional, double value)
698723
double curValue = 0;
699724
if (!useMetricInterface)
700725
{
701-
curValue = valueIntf->value();
726+
curValue = valueIntf->ValueIntf::value();
702727
}
703728
else
704729
{

platform-mc/numeric_sensor.hpp

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,39 @@ using AssociationDefinitionsInft = sdbusplus::server::object_t<
4949
using EntityIntf = sdbusplus::server::object_t<
5050
sdbusplus::xyz::openbmc_project::Inventory::Source::PLDM::server::Entity>;
5151

52+
class NumericSensor; // Forward declaration
53+
class SensorManager; // forward declaration
54+
55+
/** @brief Custom implementation of the Value interface for numeric sensors.
56+
*
57+
* This class overrides the standard sdbusplus Value interface to provide
58+
* specialized handling for property access, such as triggering hardware
59+
* polls when the value is requested via D-Bus.
60+
*/
61+
class SensorValue : public ValueIntf {
62+
public:
63+
SensorValue(sdbusplus::bus_t& bus, const char* path, pldm::platform_mc::NumericSensor& nS) :
64+
ValueIntf(bus, path, ValueIntf::action::emit_object_added),
65+
nSensor(nS)
66+
{}
67+
68+
/** @brief Get the sensor reading property.
69+
*
70+
* This override triggers an asynchronous hardware poll to update the
71+
* sensor reading when the D-Bus property is accessed (Read-on-Demand).
72+
*
73+
* @return The current sensor value stored in the D-Bus interface.
74+
*/
75+
double value() const override;
76+
77+
double value(double val) override {
78+
return ValueIntf::value(val);
79+
}
80+
81+
private:
82+
pldm::platform_mc::NumericSensor& nSensor;
83+
};
84+
5285
/**
5386
* @brief NumericSensor
5487
*
@@ -60,11 +93,13 @@ class NumericSensor
6093
public:
6194
NumericSensor(const pldm_tid_t tid, const bool sensorDisabled,
6295
std::shared_ptr<pldm_numeric_sensor_value_pdr> pdr,
63-
std::string& sensorName, std::string& associationPath);
96+
std::string& sensorName, std::string& associationPath,
97+
SensorManager* sensorManager, exec::__scope::async_scope& scope);
6498

6599
NumericSensor(const pldm_tid_t tid, const bool sensorDisabled,
66100
std::shared_ptr<pldm_compact_numeric_sensor_pdr> pdr,
67-
std::string& sensorName, std::string& associationPath);
101+
std::string& sensorName, std::string& associationPath,
102+
SensorManager* sensorManager, exec::__scope::async_scope& scope);
68103

69104
~NumericSensor() {};
70105

@@ -247,6 +282,18 @@ class NumericSensor
247282
/** @brief Sensor Unit */
248283
SensorUnit sensorUnit;
249284

285+
/** @brief Sensor Manager to read sensor reading */
286+
SensorManager* sensorManager;
287+
288+
/** @brief Scope to manage the lifetime of asynchronous sensor reading tasks */
289+
exec::__scope::async_scope& scope;
290+
291+
/** @brief Flag to enable Read-on-Demand only after initialization is complete */
292+
bool isReady{false};
293+
294+
/** @brief Flag to prevent multiple concurrent hardware polls for the same sensor */
295+
std::atomic<bool> pollPending{false};
296+
250297
private:
251298
/**
252299
* @brief Check sensor reading if any threshold has been crossed and update
@@ -275,7 +322,7 @@ class NumericSensor
275322
const uint16_t containerId);
276323

277324
std::unique_ptr<MetricIntf> metricIntf = nullptr;
278-
std::unique_ptr<ValueIntf> valueIntf = nullptr;
325+
std::unique_ptr<SensorValue> valueIntf = nullptr;
279326
std::unique_ptr<ThresholdWarningIntf> thresholdWarningIntf = nullptr;
280327
std::unique_ptr<ThresholdCriticalIntf> thresholdCriticalIntf = nullptr;
281328
std::unique_ptr<ThresholdHardShutdownIntf> thresholdHardShutdownIntf =

platform-mc/sensor_manager.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ class SensorManager
7777
return availableState[tid];
7878
};
7979

80+
/** @brief Sending getSensorReading command for the sensor
81+
*
82+
* @param[in] sensor - the sensor to be updated
83+
* @return coroutine return_value - PLDM completion code
84+
*/
85+
exec::task<int> getSensorReading(std::shared_ptr<NumericSensor> sensor);
86+
8087
protected:
8188
/** @brief start a coroutine for polling all sensors.
8289
*/
@@ -89,13 +96,6 @@ class SensorManager
8996
*/
9097
exec::task<int> doSensorPollingTask(pldm_tid_t tid);
9198

92-
/** @brief Sending getSensorReading command for the sensor
93-
*
94-
* @param[in] sensor - the sensor to be updated
95-
* @return coroutine return_value - PLDM completion code
96-
*/
97-
exec::task<int> getSensorReading(std::shared_ptr<NumericSensor> sensor);
98-
9999
/** @brief Reference to to PLDM daemon's main event loop.
100100
*/
101101
sdeventplus::Event& event;

platform-mc/terminus.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "dbus_impl_fru.hpp"
44
#include "terminus_manager.hpp"
5+
#include "sensor_manager.hpp"
56

67
#include <libpldm/platform.h>
78

@@ -16,11 +17,12 @@ namespace platform_mc
1617

1718
Terminus::Terminus(pldm_tid_t tid, uint64_t supportedTypes,
1819
sdeventplus::Event& event,
19-
TerminusManager& terminusManager) :
20+
TerminusManager& terminusManager,
21+
SensorManager* sensorManager) :
2022
initialized(false), maxBufferSize(PLDM_PLATFORM_EVENT_MSG_MAX_BUFFER_SIZE),
2123
synchronyConfigurationSupported(0), pollEvent(false), tid(tid),
2224
supportedTypes(supportedTypes), event(event),
23-
terminusManager(terminusManager)
25+
terminusManager(terminusManager), sensorManager(sensorManager)
2426
{}
2527

2628
bool Terminus::doesSupportType(uint8_t type)
@@ -703,7 +705,8 @@ void Terminus::addNumericSensor(
703705
try
704706
{
705707
auto sensor = std::make_shared<NumericSensor>(
706-
tid, true, pdr, sensorName, inventoryPath);
708+
tid, true, pdr, sensorName, inventoryPath, sensorManager,
709+
terminusScope);
707710
lg2::info("Created NumericSensor {NAME}", "NAME", sensorName);
708711
numericSensors.emplace_back(sensor);
709712
}
@@ -876,7 +879,8 @@ void Terminus::addCompactNumericSensor(
876879
try
877880
{
878881
auto sensor = std::make_shared<NumericSensor>(
879-
tid, true, pdr, sensorName, inventoryPath);
882+
tid, true, pdr, sensorName, inventoryPath, sensorManager,
883+
terminusScope);
880884
lg2::info("Created Compact NumericSensor {NAME}", "NAME", sensorName);
881885
numericSensors.emplace_back(sensor);
882886
}

platform-mc/terminus.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ namespace pldm
8989
namespace platform_mc
9090
{
9191

92+
class SensorManager; //forward declaration
93+
9294
using ContainerID = uint16_t;
9395
using EntityInstanceNumber = uint16_t;
9496
using EntityName = std::string;
@@ -142,7 +144,8 @@ class Terminus
142144
{
143145
public:
144146
Terminus(pldm_tid_t tid, uint64_t supportedPLDMTypes,
145-
sdeventplus::Event& event, TerminusManager& terminusManager);
147+
sdeventplus::Event& event, TerminusManager& terminusManager,
148+
SensorManager* sensorManager);
146149

147150
/** @brief Check if the terminus supports the PLDM type message
148151
*
@@ -519,6 +522,9 @@ class Terminus
519522
/** @brief Reference to TerminusManager */
520523
TerminusManager& terminusManager;
521524

525+
/** @brief Reference to SensorManager */
526+
SensorManager* sensorManager;
527+
522528
/** @brief Numeric Sensor PDR list */
523529
std::vector<std::shared_ptr<pldm_numeric_sensor_value_pdr>>
524530
numericSensorPdrs{};

platform-mc/terminus_manager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ exec::task<int> TerminusManager::initMctpTerminus(const MctpInfo& mctpInfo)
360360
try
361361
{
362362
termini[tid] =
363-
std::make_shared<Terminus>(tid, supportedTypes, event, *this);
363+
std::make_shared<Terminus>(tid, supportedTypes, event, *this, sensorManager);
364364
}
365365
catch (const sdbusplus::exception_t& e)
366366
{

platform-mc/terminus_manager.hpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,24 @@ class TerminusManager
5454
explicit TerminusManager(
5555
sdeventplus::Event& event, RequesterHandler& handler,
5656
pldm::InstanceIdDb& instanceIdDb, TerminiMapper& termini,
57-
Manager* manager, mctp_eid_t localEid) :
57+
Manager* manager, mctp_eid_t localEid, SensorManager* sensorManager) :
5858
handler(handler), instanceIdDb(instanceIdDb), termini(termini),
5959
tidPool(tidPoolSize, false), manager(manager), localEid(localEid),
60-
event(event)
60+
event(event), sensorManager(sensorManager)
6161
{
6262
// DSP0240 v1.1.0 table-8, special value: 0,0xFF = reserved
6363
tidPool[0] = true;
6464
tidPool[PLDM_TID_RESERVED] = true;
6565
}
6666

67+
/** @brief Set the Sensor Manager pointer
68+
*
69+
* @param[in] manager - Pointer to the Sensor Manager
70+
*/
71+
void setSensorManager(SensorManager* manager) {
72+
sensorManager = manager;
73+
}
74+
6775
/** @brief start a coroutine to discover terminus
6876
*
6977
* @param[in] mctpInfos - list information of the MCTP endpoints
@@ -321,6 +329,9 @@ class TerminusManager
321329
* work
322330
*/
323331
sdeventplus::Event& event;
332+
333+
/** @brief A Sensor Manager instance **/
334+
SensorManager* sensorManager;
324335
};
325336
} // namespace platform_mc
326337
} // namespace pldm

0 commit comments

Comments
 (0)