Initial commit

This commit is contained in:
Your Name
2026-04-23 17:07:55 +08:00
commit b7e39e063b
16725 changed files with 1625565 additions and 0 deletions
@@ -0,0 +1,12 @@
diff --git a/src/FanMain.cpp b/src/FanMain.cpp
index 9c8a738..8c6991e 100644
--- a/src/FanMain.cpp
+++ b/src/FanMain.cpp
@@ -66,6 +66,7 @@ std::optional<RedundancySensor> systemRedundancy;
static const std::map<std::string, FanTypes> compatibleFanTypes = {
{"aspeed,ast2400-pwm-tacho", FanTypes::aspeed},
{"aspeed,ast2500-pwm-tacho", FanTypes::aspeed},
+ {"aspeed,ast2600-pwm-tacho", FanTypes::aspeed},
{"nuvoton,npcm750-pwm-fan", FanTypes::nuvoton},
{"hpe,gxp-fan-ctrl", FanTypes::hpe}
// add compatible string here for new fan type
@@ -0,0 +1,164 @@
From 77803d9dde846804061bd7815f42768e4fe8e48e Mon Sep 17 00:00:00 2001
From: wangjue <jue.wang2@luxshare-ict.com>
Date: Tue, 24 Sep 2024 20:28:30 +0800
Subject: [PATCH] Add Intel CPU sensors
Signed-off-by: wangjue <jue.wang2@luxshare-ict.com>
---
src/IntelCPUSensor.hpp | 96 ++++++++++++++++++++++++++++++++++++++
src/IntelCPUSensorMain.cpp | 26 ++++++++---
2 files changed, 116 insertions(+), 6 deletions(-)
diff --git a/src/IntelCPUSensor.hpp b/src/IntelCPUSensor.hpp
index 0417c6e..ae90ab7 100644
--- a/src/IntelCPUSensor.hpp
+++ b/src/IntelCPUSensor.hpp
@@ -17,6 +17,12 @@
#include <variant>
#include <vector>
+extern "C"
+{
+#include <i2c/smbus.h>
+#include <linux/i2c-dev.h>
+}
+
class IntelCPUSensor :
public Sensor,
public std::enable_shared_from_this<IntelCPUSensor>
@@ -114,3 +120,93 @@ inline bool cpuIsPresent(const SensorBaseConfigMap& gpioConfig)
return resp;
}
+
+inline int i2cWriteRead(std::string& i2cDev, const uint8_t slaveAddr,
+ std::vector<uint8_t> writeData,
+ std::vector<uint8_t>& readBuf)
+{
+ int fd = open(i2cDev.c_str(), O_RDWR | O_CLOEXEC);
+ if (fd < 0)
+ {
+ std::cerr << "unable to open i2c device \n";
+ return -1;
+ }
+
+ const size_t writeCount = writeData.size();
+ const size_t readCount = readBuf.size();
+
+ int msgCount = 0;
+ struct i2c_msg i2cmsg[2];
+
+ memset(i2cmsg, 0, sizeof(i2cmsg));
+
+ if (writeCount)
+ {
+ // Data will be writtern to the slave address
+ i2cmsg[msgCount].addr = slaveAddr;
+ i2cmsg[msgCount].flags = 0x00;
+ i2cmsg[msgCount].len = writeCount;
+ i2cmsg[msgCount].buf = writeData.data();
+ msgCount++;
+ }
+
+ if (readCount)
+ {
+ // Data will be read into the buffer from the slave address
+ i2cmsg[msgCount].addr = slaveAddr;
+ i2cmsg[msgCount].flags = I2C_M_RD;
+ i2cmsg[msgCount].len = readCount;
+ i2cmsg[msgCount].buf = readBuf.data();
+ msgCount++;
+ }
+
+ struct i2c_rdwr_ioctl_data msgReadWrite;
+ memset((void*)&msgReadWrite, 0, sizeof(msgReadWrite));
+ msgReadWrite.msgs = i2cmsg;
+ msgReadWrite.nmsgs = msgCount;
+
+ int ret = ioctl(fd, I2C_RDWR, &msgReadWrite);
+ close(fd);
+ if (ret < 0)
+ {
+ std::cerr << "I2C Read Write Failed. \n";
+ return -1;
+ }
+
+ if (readCount)
+ {
+ readBuf.resize(msgReadWrite.msgs[msgCount - 1].len);
+ }
+
+ return 0;
+}
+
+inline bool cpuIsPresentCPLD(int cpuId)
+{
+ int ret = 0;
+ uint8_t index;
+ std::string i2cDev = "/dev/i2c-0";
+ // Perform the combined write/read
+
+ std::vector<uint8_t> readBuf(1);
+ std::vector<uint8_t> writeData = {0x91, 0x02};
+ const uint8_t slaveAddr = 0x0D;
+ uint8_t regVal;
+
+ ret = i2cWriteRead(i2cDev, slaveAddr, writeData, readBuf);
+ if (ret < 0)
+ {
+ std::cerr << "i2c failed to read regVal. \n";
+ return false;
+ }
+
+ regVal = readBuf[0];
+ if(cpuId == 1)
+ index = 1;
+ else if(cpuId == 2)
+ index = 0;
+ else
+ return false;
+
+ return (regVal & (1 << index)) == 0;
+}
diff --git a/src/IntelCPUSensorMain.cpp b/src/IntelCPUSensorMain.cpp
index 0e0083a..a955c6f 100644
--- a/src/IntelCPUSensorMain.cpp
+++ b/src/IntelCPUSensorMain.cpp
@@ -721,14 +721,28 @@ bool getCpuConfig(const std::shared_ptr<sdbusplus::asio::connection>& systemBus,
std::string name = std::regex_replace(nameRaw, illegalDbusRegex,
"_");
+ int cpuId = -1;
+ auto findCpuId = cfg.find("CpuID");
+ if (findCpuId != cfg.end())
+ {
+ cpuId = std::visit(VariantToUnsignedIntVisitor(),
+ findCpuId->second);
+ }
+
auto present = std::optional<bool>();
- // if we can't detect it via gpio, we set presence later
- for (const auto& [suppIntf, suppCfg] : cfgData)
+ auto findPresence = cfg.find("Presence");
+ if (findPresence != cfg.end())
{
- if (suppIntf.find("PresenceGpio") != std::string::npos)
- {
- present = cpuIsPresent(suppCfg);
- break;
+ std::string method = std::visit(VariantToStringVisitor(),
+ findPresence->second);
+ if(method == "GPIO") {
+ for (const auto& [suppIntf, suppCfg] : cfgData)
+ present = cpuIsPresent(suppCfg);
+ } else if(method == "CPLD") {
+ if(cpuId != -1)
+ present = cpuIsPresentCPLD(cpuId);
+ } else {
+ std::cerr << "Invalid Presence value \n";
}
}
--
2.34.1
@@ -0,0 +1,544 @@
From b89bbf4a2a349cfc9cb047fce70ee064a193f82e Mon Sep 17 00:00:00 2001
From: wangjue <jue.wang2@luxshare-ict.com>
Date: Wed, 25 Sep 2024 19:27:30 +0800
Subject: [PATCH] Add DIMM Temp sensors
Signed-off-by: wangjue <jue.wang2@luxshare-ict.com>
---
meson_options.txt | 1 +
service_files/meson.build | 1 +
...xyz.openbmc_project.dimmtempsensor.service | 13 ++
src/DIMMTempSensor.cpp | 194 +++++++++++++++++
src/DIMMTempSensor.hpp | 43 ++++
src/DIMMTempSensorMain.cpp | 201 ++++++++++++++++++
src/meson.build | 15 ++
7 files changed, 468 insertions(+)
create mode 100644 service_files/xyz.openbmc_project.dimmtempsensor.service
create mode 100644 src/DIMMTempSensor.cpp
create mode 100644 src/DIMMTempSensor.hpp
create mode 100644 src/DIMMTempSensorMain.cpp
diff --git a/meson_options.txt b/meson_options.txt
index d6a8b96..79bf6b2 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -12,3 +12,4 @@ option('external', type: 'feature', value: 'enabled', description: 'Enable Exter
option('tests', type: 'feature', value: 'enabled', description: 'Build tests.',)
option('validate-unsecure-feature', type : 'feature', value : 'disabled', description : 'Enables unsecure features required by validation. Note: mustbe turned off for production images.',)
option('insecure-sensor-override', type : 'feature', value : 'disabled', description : 'Enables Sensor override feature without any check.',)
+option('dimmtemp', type: 'feature', value: 'enabled', description: 'Enable DIMMtemp sensor.',)
diff --git a/service_files/meson.build b/service_files/meson.build
index 5f5b78c..c60f76c 100644
--- a/service_files/meson.build
+++ b/service_files/meson.build
@@ -10,6 +10,7 @@ unit_files = [
['nvme', 'xyz.openbmc_project.nvmesensor.service'],
['psu', 'xyz.openbmc_project.psusensor.service'],
['external', 'xyz.openbmc_project.externalsensor.service'],
+ ['dimmtemp', 'xyz.openbmc_project.dimmtempsensor.service'],
]
foreach tuple : unit_files
diff --git a/service_files/xyz.openbmc_project.dimmtempsensor.service b/service_files/xyz.openbmc_project.dimmtempsensor.service
new file mode 100644
index 0000000..bb31e3a
--- /dev/null
+++ b/service_files/xyz.openbmc_project.dimmtempsensor.service
@@ -0,0 +1,13 @@
+[Unit]
+Description=DIMM Temp Sensor
+StopWhenUnneeded=false
+Requires=xyz.openbmc_project.EntityManager.service
+After=xyz.openbmc_project.EntityManager.service
+
+[Service]
+Restart=always
+RestartSec=5
+ExecStart=/usr/bin/dimmtempsensor
+
+[Install]
+WantedBy=multi-user.target
\ No newline at end of file
diff --git a/src/DIMMTempSensor.cpp b/src/DIMMTempSensor.cpp
new file mode 100644
index 0000000..7b0a1cd
--- /dev/null
+++ b/src/DIMMTempSensor.cpp
@@ -0,0 +1,194 @@
+/*
+// Copyright (c) 2019 Intel Corporation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+*/
+#include "DIMMTempSensor.hpp"
+
+#include "Utils.hpp"
+#include "VariantVisitors.hpp"
+
+#include <boost/algorithm/string.hpp>
+#include <boost/algorithm/string/predicate.hpp>
+#include <boost/algorithm/string/replace.hpp>
+#include <boost/container/flat_map.hpp>
+#include <sdbusplus/asio/connection.hpp>
+#include <sdbusplus/asio/object_server.hpp>
+#include <sdbusplus/bus/match.hpp>
+
+#include <chrono>
+#include <cmath>
+#include <functional>
+#include <iostream>
+#include <limits>
+#include <memory>
+#include <numeric>
+#include <string>
+#include <vector>
+
+#include <peci.h>
+extern "C"
+{
+#include <i2c/smbus.h>
+#include <linux/i2c-dev.h>
+}
+
+constexpr const bool debug = false;
+
+#define PECI_MBX_INDEX_DDR_DIMM_TEMP 0x0E
+
+DIMMTempSensor::DIMMTempSensor(
+ std::shared_ptr<sdbusplus::asio::connection>& conn,
+ boost::asio::io_context& io, const std::string& sensorName,
+ const std::string& sensorConfiguration,
+ sdbusplus::asio::object_server& objectServer,
+ std::vector<thresholds::Threshold>&& thresholdData, const double maxReading,
+ const double minReading, const std::string& sensorType, const char* units,
+ const float pollRate, PowerState readState, uint8_t peciBus,
+ uint8_t peciAddr, uint8_t rank, double calibOffset) :
+ Sensor(boost::replace_all_copy(sensorName, " ", "_"),
+ std::move(thresholdData), sensorConfiguration, "", false, false,
+ maxReading, minReading, conn, readState),
+ sensorPollMs(static_cast<unsigned int>(pollRate * 1000)), peciBus(peciBus),
+ peciAddr(peciAddr), dimmRank(rank), calibOffset(calibOffset),
+ objectServer(objectServer), waitTimer(io)
+{
+ std::string interfacePath = "/xyz/openbmc_project/sensors/" + sensorType +
+ "/" + name;
+
+ sensorInterface = objectServer.add_interface(
+ interfacePath, "xyz.openbmc_project.Sensor.Value");
+
+ for (const auto& threshold : thresholds)
+ {
+ std::string interface = thresholds::getInterface(threshold.level);
+ thresholdInterfaces[static_cast<size_t>(threshold.level)] =
+ objectServer.add_interface(interfacePath, interface);
+ }
+
+ association = objectServer.add_interface(interfacePath,
+ association::interface);
+
+ setInitialProperties(units);
+}
+
+DIMMTempSensor::~DIMMTempSensor()
+{
+ waitTimer.cancel();
+
+ for (const auto& iface : thresholdInterfaces)
+ {
+ objectServer.remove_interface(iface);
+ }
+
+ objectServer.remove_interface(sensorInterface);
+ objectServer.remove_interface(association);
+}
+
+void DIMMTempSensor::init(void)
+{
+ read();
+}
+
+void DIMMTempSensor::checkThresholds(void)
+{
+ thresholds::checkThresholds(this);
+}
+
+int DIMMTempSensor::getDIMMRegsInfoWord(double* ps64data)
+{
+ int ret = -1;
+ ret = getDIMMRegsTemp(ps64data);
+ return ret;
+}
+
+int DIMMTempSensor::getDIMMRegsTemp(double* ps64data)
+{
+ int peciFd = -1;
+ std::string peciDevPath = "/dev/peci-" + std::to_string(peciBus);
+
+ peci_SetDevName(peciDevPath.data());
+
+ if ((peci_Lock(&peciFd, PECI_NO_WAIT) != PECI_CC_SUCCESS) ||
+ (peciFd < 0))
+ {
+ std::cerr << "unable to open " << peciDevPath << " "
+ << std::strerror(errno) << "\n";
+ return -1;
+ }
+
+ if (peci_Ping(peciAddr) == PECI_CC_SUCCESS)
+ {
+ std::array<uint8_t, 8> pkgConfig{};
+ uint8_t cc = 0;
+
+ if (peci_RdPkgConfig(peciAddr, PECI_MBX_INDEX_DDR_DIMM_TEMP,
+ dimmRank, 4, &pkgConfig[0],
+ &cc) != PECI_CC_SUCCESS)
+ {
+ std::cerr << "PECI RdPkgConfig returns failure" << "\n";
+ return -1;
+ }
+
+ *ps64data = (double)pkgConfig[0];
+
+ } else {
+ std::cerr << "PECI Ping returns failure" << "\n";
+ return -1;
+ }
+ peci_Unlock(peciFd);
+ return 0;
+}
+
+void DIMMTempSensor::read(void)
+{
+ waitTimer.expires_after(std::chrono::milliseconds(sensorPollMs));
+ waitTimer.async_wait([this](const boost::system::error_code& ec) {
+ if (ec == boost::asio::error::operation_aborted)
+ {
+ return; // we're being cancelled
+ }
+ // read timer error
+ if (ec)
+ {
+ std::cerr << "timer error\n";
+ return;
+ }
+ if (readingStateGood())
+ {
+ double temp = 0;
+ int ret = getDIMMRegsInfoWord(&temp);
+ if (ret == 0)
+ {
+ double v = temp;
+ if constexpr (debug)
+ {
+ std::cerr << "Value update to " << v << ", raw reading "
+ << temp << "\n";
+ }
+ v += calibOffset;
+ updateValue(v);
+ }
+ else
+ {
+ std::cerr << "Invalid read getDIMMRegsInfoWord.\n";
+ incrementError();
+ }
+ }
+ else
+ {
+ updateValue(std::numeric_limits<double>::quiet_NaN());
+ }
+ read();
+ });
+}
diff --git a/src/DIMMTempSensor.hpp b/src/DIMMTempSensor.hpp
new file mode 100644
index 0000000..dd52053
--- /dev/null
+++ b/src/DIMMTempSensor.hpp
@@ -0,0 +1,43 @@
+#pragma once
+#include "sensor.hpp"
+
+#include <boost/asio/steady_timer.hpp>
+#include <boost/container/flat_map.hpp>
+
+#include <chrono>
+#include <limits>
+#include <memory>
+#include <string>
+#include <vector>
+
+struct DIMMTempSensor : public Sensor
+{
+ DIMMTempSensor(std::shared_ptr<sdbusplus::asio::connection>& conn,
+ boost::asio::io_context& io, const std::string& name,
+ const std::string& sensorConfiguration,
+ sdbusplus::asio::object_server& objectServer,
+ std::vector<thresholds::Threshold>&& thresholds,
+ const double maxReading, const double minReading,
+ const std::string& sensorType, const char* units,
+ const float pollRate, PowerState readState, uint8_t peciBus,
+ uint8_t peciAddr, uint8_t rank, double calibOffset);
+ ~DIMMTempSensor() override;
+
+ void checkThresholds(void) override;
+ void read(void);
+ void init(void);
+
+ unsigned int sensorPollMs;
+
+ uint8_t peciBus;
+ uint8_t peciAddr;
+ uint8_t dimmRank;
+ double calibOffset;
+
+ private:
+ int getDIMMRegsInfoWord(double* ps64data);
+ int getDIMMRegsTemp(double* ps64data);
+ // int getDIMMRegsPower(double* ps64data);
+ sdbusplus::asio::object_server& objectServer;
+ boost::asio::steady_timer waitTimer;
+};
diff --git a/src/DIMMTempSensorMain.cpp b/src/DIMMTempSensorMain.cpp
new file mode 100644
index 0000000..042659f
--- /dev/null
+++ b/src/DIMMTempSensorMain.cpp
@@ -0,0 +1,201 @@
+/*
+// Copyright (c) 2019 Intel Corporation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+*/
+
+// #include <math.h>
+#include <DIMMTempSensor.hpp>
+#include <Utils.hpp>
+#include <VariantVisitors.hpp>
+#include <boost/algorithm/string.hpp>
+#include <boost/algorithm/string/predicate.hpp>
+#include <boost/algorithm/string/replace.hpp>
+#include <boost/container/flat_map.hpp>
+#include <sdbusplus/asio/connection.hpp>
+#include <sdbusplus/asio/object_server.hpp>
+#include <sdbusplus/bus/match.hpp>
+
+#include <chrono>
+#include <functional>
+#include <iostream>
+#include <limits>
+#include <memory>
+#include <numeric>
+#include <string>
+#include <vector>
+
+constexpr const bool debug = false;
+constexpr const char* configInterface =
+ "xyz.openbmc_project.Configuration.DIMMTemp";
+
+static constexpr double maxTempReading = 127;
+static constexpr double minTempReading = -128;
+static constexpr double maxPowerReading = 500;
+static constexpr double minPowerReading = 0;
+
+void createSensors(
+ boost::asio::io_context& io, sdbusplus::asio::object_server& objectServer,
+ boost::container::flat_map<std::string, std::unique_ptr<DIMMTempSensor>>&
+ sensors,
+ std::shared_ptr<sdbusplus::asio::connection>& dbusConnection)
+{
+ if (!dbusConnection)
+ {
+ std::cerr << "Connection not created\n";
+ return;
+ }
+
+ dbusConnection->async_method_call(
+ [&io, &objectServer, &dbusConnection, &sensors](
+ boost::system::error_code ec, const ManagedObjectType& resp) {
+ if (ec)
+ {
+ std::cerr << "Error contacting entity manager\n";
+ return;
+ }
+ for (const auto& pathPair : resp)
+ {
+ for (const auto& entry : pathPair.second)
+ {
+ if (entry.first != configInterface)
+ {
+ continue;
+ }
+ std::string name = loadVariant<std::string>(entry.second,
+ "Name");
+
+ std::vector<thresholds::Threshold> sensorThresholds;
+ if (!parseThresholdsFromConfig(pathPair.second,
+ sensorThresholds))
+ {
+ std::cerr << "error populating thresholds for " << name
+ << "\n";
+ }
+
+ float pollRate = loadVariant<double>(entry.second, "PollRate");
+ uint8_t peciBus = loadVariant<uint8_t>(entry.second, "Bus");
+ uint8_t peciAddr = loadVariant<uint8_t>(entry.second, "Address");
+ uint8_t dimmRank = loadVariant<uint8_t>(entry.second, "Rank");
+
+ /* calibration offset */
+ auto findCalibOffset = entry.second.find("Offset");
+ double calibOffset = 0;
+ if (findCalibOffset != entry.second.end())
+ {
+ calibOffset = std::visit(VariantToDoubleVisitor(),
+ findCalibOffset->second);
+ }
+
+ /* PowerState */
+ auto findPowerOn = entry.second.find("PowerState");
+ PowerState readState = PowerState::always;
+ if (findPowerOn != entry.second.end())
+ {
+ std::string powerState = std::visit(
+ VariantToStringVisitor(), findPowerOn->second);
+ setReadState(powerState, readState);
+ }
+
+ if constexpr (debug)
+ {
+ std::cerr << "Configuration parsed for \n\t" << entry.first
+ << "\n"
+ << "with\n"
+ << "\tName: " << name << "\n"
+ << "\tBus: " << static_cast<int>(peciBus) << "\n"
+ << "\tAddress: " << static_cast<int>(peciAddr)
+ << "\n"
+ << "\tDimmRank: " << static_cast<int>(dimmRank)
+ << "\tOffset: " << calibOffset << "\n";
+ }
+
+ auto& sensor = sensors[name];
+ sensor = nullptr;
+
+ if (name.ends_with("_Temp"))
+ {
+ sensor = std::make_unique<DIMMTempSensor>(
+ dbusConnection, io, name, pathPair.first, objectServer,
+ std::move(sensorThresholds), maxTempReading,
+ minTempReading, "temperature",
+ sensor_paths::unitDegreesC, pollRate, readState,
+ peciBus, peciAddr, dimmRank, 0);
+ }
+ else if (name.ends_with("_Power"))
+ {
+ sensor = std::make_unique<DIMMTempSensor>(
+ dbusConnection, io, name, pathPair.first, objectServer,
+ std::move(sensorThresholds), maxPowerReading,
+ minPowerReading, "power", sensor_paths::unitWatts,
+ pollRate, readState, peciBus, peciAddr, dimmRank, 0);
+ }
+
+ sensor->init();
+ }
+ }
+ },
+ entityManagerName, "/xyz/openbmc_project/inventory",
+ "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
+}
+
+int main()
+{
+ boost::asio::io_context io;
+ auto systemBus = std::make_shared<sdbusplus::asio::connection>(io);
+ sdbusplus::asio::object_server objectServer(systemBus, true);
+
+ objectServer.add_manager("/xyz/openbmc_project/sensors");
+ systemBus->request_name("xyz.openbmc_project.DIMMTempSensor");
+
+ boost::container::flat_map<std::string, std::unique_ptr<DIMMTempSensor>>
+ sensors;
+ boost::asio::post(
+ io, [&]() { createSensors(io, objectServer, sensors, systemBus); });
+
+ boost::asio::steady_timer configTimer(io);
+ std::function<void(sdbusplus::message::message&)> eventHandler =
+ [&](sdbusplus::message::message&) {
+ configTimer.expires_after(std::chrono::seconds(1));
+ // create a timer because normally multiple properties change
+ configTimer.async_wait([&](const boost::system::error_code& ec) {
+ if (ec == boost::asio::error::operation_aborted)
+ {
+ return; // we're being canceled
+ }
+ // config timer error
+ if (ec)
+ {
+ std::cerr << "timer error\n";
+ return;
+ }
+ createSensors(io, objectServer, sensors, systemBus);
+ if (sensors.empty())
+ {
+ std::cout << "Configuration not detected\n";
+ }
+ });
+ };
+
+ sdbusplus::bus::match::match configMatch(
+ static_cast<sdbusplus::bus::bus&>(*systemBus),
+ "type='signal',member='PropertiesChanged',"
+ "path_namespace='" +
+ std::string(inventoryPath) +
+ "',"
+ "arg0namespace='" +
+ configInterface + "'",
+ eventHandler);
+
+ io.run();
+}
diff --git a/src/meson.build b/src/meson.build
index 9f56c31..7c33e3a 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -234,3 +234,18 @@ if get_option('external').enabled()
install: true,
)
endif
+
+if get_option('dimmtemp').allowed()
+ executable(
+ 'dimmtempsensor',
+ 'DIMMTempSensor.cpp',
+ 'DIMMTempSensorMain.cpp',
+ dependencies: [
+ default_deps,
+ thresholds_dep,
+ utils_dep,
+ peci_dep,
+ ],
+ install: true,
+ )
+endif
\ No newline at end of file
--
2.34.1
@@ -0,0 +1,23 @@
diff --git a/src/sensor.hpp b/src/sensor.hpp
index 9f092c6..e48036a 100644
--- a/src/sensor.hpp
+++ b/src/sensor.hpp
@@ -265,10 +265,18 @@ struct Sensor
sensorInterface->register_property("Unit", unit);
sensorInterface->register_property("MaxValue", maxValue);
sensorInterface->register_property("MinValue", minValue);
+ //Allows external overwrite DIMM temperature
+ if(sensorInterface->get_object_path().find("DIMM_CPU") != std::string::npos ){
+ sensorInterface->register_property(
+ "Value", value, [this](const double& newValue, double& oldValue) {
+ oldValue=newValue;return true;
+ });
+ }else{
sensorInterface->register_property(
"Value", value, [this](const double& newValue, double& oldValue) {
return setSensorValue(newValue, oldValue);
});
+ }
fillMissingThresholds();
@@ -0,0 +1,188 @@
From c049cf37710acb91b0361267048f8a71600677c1 Mon Sep 17 00:00:00 2001
From: wangjue <jue.wang2@luxshare-ict.com>
Date: Thu, 24 Oct 2024 16:40:34 +0800
Subject: [PATCH] Add dimmLEDInterface and dimmLEDState property
Signed-off-by: wangjue <jue.wang2@luxshare-ict.com>
---
src/DIMMTempSensor.cpp | 51 ++++++++++++++++++++++++++++++++------
src/DIMMTempSensor.hpp | 7 ++++--
src/DIMMTempSensorMain.cpp | 1 +
src/sensor.hpp | 1 +
4 files changed, 51 insertions(+), 9 deletions(-)
diff --git a/src/DIMMTempSensor.cpp b/src/DIMMTempSensor.cpp
index 6fba752..94843d2 100644
--- a/src/DIMMTempSensor.cpp
+++ b/src/DIMMTempSensor.cpp
@@ -60,7 +60,7 @@ DIMMTempSensor::DIMMTempSensor(
std::move(thresholdData), sensorConfiguration, "", false, false,
maxReading, minReading, conn, readState),
sensorPollMs(static_cast<unsigned int>(pollRate * 1000)), peciBus(peciBus),
- peciAddr(peciAddr), dimmRank(rank), calibOffset(calibOffset),
+ peciAddr(peciAddr), dimmRank(rank), calibOffset(calibOffset), dimmLEDState("OFF"),
objectServer(objectServer), waitTimer(io)
{
std::string interfacePath = "/xyz/openbmc_project/sensors/" + sensorType +
@@ -69,6 +69,16 @@ DIMMTempSensor::DIMMTempSensor(
sensorInterface = objectServer.add_interface(
interfacePath, "xyz.openbmc_project.Sensor.Value");
+ dimmLEDInterface = objectServer.add_interface(
+ interfacePath, "xyz.openbmc_project.Sensor.dimmLED");
+
+ dimmLEDInterface->register_property(
+ "LEDState", dimmLEDState, [this](const std::string& newValue, std::string& oldValue) {
+ oldValue = newValue; return true;
+ });
+
+ dimmLEDInterface->initialize();
+
for (const auto& threshold : thresholds)
{
std::string interface = thresholds::getInterface(threshold.level);
@@ -95,7 +105,7 @@ DIMMTempSensor::~DIMMTempSensor()
objectServer.remove_interface(association);
}
-void DIMMTempSensor::init(void)
+void DIMMTempSensor::init()
{
read();
}
@@ -124,7 +134,7 @@ int DIMMTempSensor::getDIMMRegsTemp(double* ps64data)
{
std::cerr << "unable to open " << peciDevPath << " "
<< std::strerror(errno) << "\n";
- return -1;
+ goto err;
}
if (peci_Ping(peciAddr) == PECI_CC_SUCCESS)
@@ -137,20 +147,25 @@ int DIMMTempSensor::getDIMMRegsTemp(double* ps64data)
&cc) != PECI_CC_SUCCESS)
{
std::cerr << "PECI RdPkgConfig returns failure" << "\n";
- return -1;
+ goto err;
}
*ps64data = (double)pkgConfig[0];
} else {
std::cerr << "PECI Ping returns failure" << "\n";
- return -1;
+ goto err;
}
+
peci_Unlock(peciFd);
return 0;
+
+err:
+ peci_Unlock(peciFd);
+ return -1;
}
-void DIMMTempSensor::read(void)
+void DIMMTempSensor::read()
{
waitTimer.expires_after(std::chrono::milliseconds(sensorPollMs));
waitTimer.async_wait([this](const boost::system::error_code& ec) {
@@ -177,18 +192,40 @@ void DIMMTempSensor::read(void)
<< temp << "\n";
}
v += calibOffset;
+
+
+ updateDIMMLedState(dimmLEDInterface, dimmLEDState, "ON", "LEDState");
updateValue(v);
}
else
{
- std::cerr << "Invalid read getDIMMRegsInfoWord.\n";
+ std::cerr << "Fail to read DIMM tempture.\n";
+ updateDIMMLedState(dimmLEDInterface, dimmLEDState, "OFF", "LEDState");
incrementError();
}
}
else
{
updateValue(std::numeric_limits<double>::quiet_NaN());
+ updateDIMMLedState(dimmLEDInterface, dimmLEDState, "OFF", "LEDState");
}
read();
});
}
+
+void DIMMTempSensor::updateDIMMLedState(std::shared_ptr<sdbusplus::asio::dbus_interface>& interface,
+ std::string& oldState, const std::string& newState, const char* dbusPropertyName)
+{
+ if(oldState == newState)
+ return;
+ oldState = newState;
+
+ if (interface &&
+ !(interface->set_property(dbusPropertyName, newState)))
+ {
+ std::cerr << "error setting property " << dbusPropertyName
+ << " to " << newState << "\n";
+ }
+
+ return;
+}
diff --git a/src/DIMMTempSensor.hpp b/src/DIMMTempSensor.hpp
index dd52053..9aea017 100644
--- a/src/DIMMTempSensor.hpp
+++ b/src/DIMMTempSensor.hpp
@@ -24,8 +24,8 @@ struct DIMMTempSensor : public Sensor
~DIMMTempSensor() override;
void checkThresholds(void) override;
- void read(void);
- void init(void);
+ void read();
+ void init();
unsigned int sensorPollMs;
@@ -33,10 +33,13 @@ struct DIMMTempSensor : public Sensor
uint8_t peciAddr;
uint8_t dimmRank;
double calibOffset;
+ std::string dimmLEDState;
private:
int getDIMMRegsInfoWord(double* ps64data);
int getDIMMRegsTemp(double* ps64data);
+ void updateDIMMLedState(std::shared_ptr<sdbusplus::asio::dbus_interface>& interface,
+ std::string& oldState, const std::string& newState, const char* dbusPropertyName);
// int getDIMMRegsPower(double* ps64data);
sdbusplus::asio::object_server& objectServer;
boost::asio::steady_timer waitTimer;
diff --git a/src/DIMMTempSensorMain.cpp b/src/DIMMTempSensorMain.cpp
index 042659f..5c3573c 100644
--- a/src/DIMMTempSensorMain.cpp
+++ b/src/DIMMTempSensorMain.cpp
@@ -87,6 +87,7 @@ void createSensors(
uint8_t peciBus = loadVariant<uint8_t>(entry.second, "Bus");
uint8_t peciAddr = loadVariant<uint8_t>(entry.second, "Address");
uint8_t dimmRank = loadVariant<uint8_t>(entry.second, "Rank");
+ //std::string LEDState = loadVariant<std::string>(entry.second, "LEDState");
/* calibration offset */
auto findCalibOffset = entry.second.find("Offset");
diff --git a/src/sensor.hpp b/src/sensor.hpp
index e48036a..2c46771 100644
--- a/src/sensor.hpp
+++ b/src/sensor.hpp
@@ -97,6 +97,7 @@ struct Sensor
std::shared_ptr<sdbusplus::asio::dbus_interface> availableInterface;
std::shared_ptr<sdbusplus::asio::dbus_interface> operationalInterface;
std::shared_ptr<sdbusplus::asio::dbus_interface> valueMutabilityInterface;
+ std::shared_ptr<sdbusplus::asio::dbus_interface> dimmLEDInterface;
double value = std::numeric_limits<double>::quiet_NaN();
double rawValue = std::numeric_limits<double>::quiet_NaN();
bool overriddenState = false;
--
2.34.1
@@ -0,0 +1,87 @@
From 2a4ceaf845fd605e4f44740e08bd92ddb868c87a Mon Sep 17 00:00:00 2001
From: "Wang.Bin" <Bin-B.Wang@luxshare-ict.com>
Date: Mon, 11 Nov 2024 13:07:48 +0800
Subject: [PATCH 6/6] Add PWM sensors
---
src/FanMain.cpp | 6 ++----
src/PwmSensor.cpp | 15 +++++++++++++++
src/PwmSensor.hpp | 2 ++
3 files changed, 19 insertions(+), 4 deletions(-)
diff --git a/src/FanMain.cpp b/src/FanMain.cpp
index 8c6991e..fc81a93 100644
--- a/src/FanMain.cpp
+++ b/src/FanMain.cpp
@@ -161,7 +161,7 @@ bool findPwmPath(const fs::path& directory, unsigned int pwm, fs::path& pwmPath)
std::error_code ec;
/* Assuming PWM file is appeared in the same directory as fanX_input */
- auto path = directory / ("pwm" + std::to_string(pwm + 1));
+ auto path = directory / ("pwm" + std::to_string(pwm));
bool exists = fs::exists(path, ec);
if (ec || !exists)
@@ -484,12 +484,10 @@ void createSensors(
<< " no pwm channel found!\n";
continue;
}
-
- fs::path pwmEnableFile = "pwm" + std::to_string(pwm + 1) +
+ fs::path pwmEnableFile = "pwm" + std::to_string(pwm) +
"_enable";
fs::path enablePath = pwmPath.parent_path() / pwmEnableFile;
enablePwm(enablePath);
-
/* use pwm name override if found in configuration else
* use default */
auto findOverride = connector->second.find("PwmName");
diff --git a/src/PwmSensor.cpp b/src/PwmSensor.cpp
index ad54dfe..eadf1bc 100644
--- a/src/PwmSensor.cpp
+++ b/src/PwmSensor.cpp
@@ -43,6 +43,19 @@ PwmSensor::PwmSensor(const std::string& name, const std::string& sysPath,
sensorInterface = objectServer.add_interface(
"/xyz/openbmc_project/sensors/fan_pwm/" + name,
"xyz.openbmc_project.Sensor.Value");
+ aInterface = objectServer.add_interface(
+ "/xyz/openbmc_project/sensors/fan_pwm/" + name,
+ "xyz.openbmc_project.State.Decorator.Availability");
+ fInterface = objectServer.add_interface(
+ "/xyz/openbmc_project/sensors/fan_pwm/" + name,
+ "xyz.openbmc_project.State.Decorator.OperationalStatus");
+
+
+ aInterface->register_property("Available", true,[](const bool &req, bool &res)
+ {res = req;return true; });
+ fInterface->register_property("Functional", true,[](const bool &req, bool &res)
+ {res = req;return true; });
+
uint32_t pwmValue = getValue(false);
if (sensorType == "PSU")
{
@@ -150,6 +163,8 @@ PwmSensor::PwmSensor(const std::string& name, const std::string& sysPath,
});
sensorInterface->initialize();
+ aInterface->initialize();
+ fInterface->initialize();
controlInterface->initialize();
if (isValueMutable)
diff --git a/src/PwmSensor.hpp b/src/PwmSensor.hpp
index f70079b..a1f2277 100644
--- a/src/PwmSensor.hpp
+++ b/src/PwmSensor.hpp
@@ -22,6 +22,8 @@ class PwmSensor
sdbusplus::asio::object_server& objectServer;
std::string name;
std::shared_ptr<sdbusplus::asio::dbus_interface> sensorInterface;
+ std::shared_ptr<sdbusplus::asio::dbus_interface> aInterface;
+ std::shared_ptr<sdbusplus::asio::dbus_interface> fInterface;
std::shared_ptr<sdbusplus::asio::dbus_interface> controlInterface;
std::shared_ptr<sdbusplus::asio::dbus_interface> association;
std::shared_ptr<sdbusplus::asio::dbus_interface> valueMutabilityInterface;
--
2.25.1
@@ -0,0 +1,108 @@
From 8ee0eb0cdbb7c3570c4a5ae65a44b22edb3b70a6 Mon Sep 17 00:00:00 2001
From: wangjue <jue.wang2@luxshare-ict.com>
Date: Mon, 11 Nov 2024 15:25:16 +0800
Subject: [PATCH] Remove updateDIMMLedState function as dimm presence state
will be set by bios
Signed-off-by: wangjue <jue.wang2@luxshare-ict.com>
---
src/DIMMTempSensor.cpp | 25 ++-----------------------
src/DIMMTempSensor.hpp | 3 ---
src/DIMMTempSensorMain.cpp | 1 -
3 files changed, 2 insertions(+), 27 deletions(-)
diff --git a/src/DIMMTempSensor.cpp b/src/DIMMTempSensor.cpp
index 94843d2..1399995 100644
--- a/src/DIMMTempSensor.cpp
+++ b/src/DIMMTempSensor.cpp
@@ -60,7 +60,7 @@ DIMMTempSensor::DIMMTempSensor(
std::move(thresholdData), sensorConfiguration, "", false, false,
maxReading, minReading, conn, readState),
sensorPollMs(static_cast<unsigned int>(pollRate * 1000)), peciBus(peciBus),
- peciAddr(peciAddr), dimmRank(rank), calibOffset(calibOffset), dimmLEDState("OFF"),
+ peciAddr(peciAddr), dimmRank(rank), calibOffset(calibOffset),
objectServer(objectServer), waitTimer(io)
{
std::string interfacePath = "/xyz/openbmc_project/sensors/" + sensorType +
@@ -72,6 +72,7 @@ DIMMTempSensor::DIMMTempSensor(
dimmLEDInterface = objectServer.add_interface(
interfacePath, "xyz.openbmc_project.Sensor.dimmLED");
+ std::string dimmLEDState = "OFF";
dimmLEDInterface->register_property(
"LEDState", dimmLEDState, [this](const std::string& newValue, std::string& oldValue) {
oldValue = newValue; return true;
@@ -192,40 +193,18 @@ void DIMMTempSensor::read()
<< temp << "\n";
}
v += calibOffset;
-
-
- updateDIMMLedState(dimmLEDInterface, dimmLEDState, "ON", "LEDState");
updateValue(v);
}
else
{
std::cerr << "Fail to read DIMM tempture.\n";
- updateDIMMLedState(dimmLEDInterface, dimmLEDState, "OFF", "LEDState");
incrementError();
}
}
else
{
updateValue(std::numeric_limits<double>::quiet_NaN());
- updateDIMMLedState(dimmLEDInterface, dimmLEDState, "OFF", "LEDState");
}
read();
});
}
-
-void DIMMTempSensor::updateDIMMLedState(std::shared_ptr<sdbusplus::asio::dbus_interface>& interface,
- std::string& oldState, const std::string& newState, const char* dbusPropertyName)
-{
- if(oldState == newState)
- return;
- oldState = newState;
-
- if (interface &&
- !(interface->set_property(dbusPropertyName, newState)))
- {
- std::cerr << "error setting property " << dbusPropertyName
- << " to " << newState << "\n";
- }
-
- return;
-}
diff --git a/src/DIMMTempSensor.hpp b/src/DIMMTempSensor.hpp
index 9aea017..1f7d8d3 100644
--- a/src/DIMMTempSensor.hpp
+++ b/src/DIMMTempSensor.hpp
@@ -33,13 +33,10 @@ struct DIMMTempSensor : public Sensor
uint8_t peciAddr;
uint8_t dimmRank;
double calibOffset;
- std::string dimmLEDState;
private:
int getDIMMRegsInfoWord(double* ps64data);
int getDIMMRegsTemp(double* ps64data);
- void updateDIMMLedState(std::shared_ptr<sdbusplus::asio::dbus_interface>& interface,
- std::string& oldState, const std::string& newState, const char* dbusPropertyName);
// int getDIMMRegsPower(double* ps64data);
sdbusplus::asio::object_server& objectServer;
boost::asio::steady_timer waitTimer;
diff --git a/src/DIMMTempSensorMain.cpp b/src/DIMMTempSensorMain.cpp
index 5c3573c..042659f 100644
--- a/src/DIMMTempSensorMain.cpp
+++ b/src/DIMMTempSensorMain.cpp
@@ -87,7 +87,6 @@ void createSensors(
uint8_t peciBus = loadVariant<uint8_t>(entry.second, "Bus");
uint8_t peciAddr = loadVariant<uint8_t>(entry.second, "Address");
uint8_t dimmRank = loadVariant<uint8_t>(entry.second, "Rank");
- //std::string LEDState = loadVariant<std::string>(entry.second, "LEDState");
/* calibration offset */
auto findCalibOffset = entry.second.find("Offset");
--
2.34.1
@@ -0,0 +1,223 @@
From 8e64d466ebd5a92ec7f500ddaa0148404acb5435 Mon Sep 17 00:00:00 2001
From: wangjue <jue.wang2@luxshare-ict.com>
Date: Wed, 13 Nov 2024 20:25:01 +0800
Subject: [PATCH] Fix issue that the reading value of dimm temp sensor is zero
even dimm is not present
Signed-off-by: wangjue <jue.wang2@luxshare-ict.com>
---
src/DIMMTempSensor.cpp | 62 +++++++++++++++++++++++++++++++++-----
src/DIMMTempSensor.hpp | 19 +++++++-----
src/DIMMTempSensorMain.cpp | 18 ++++++-----
3 files changed, 75 insertions(+), 24 deletions(-)
diff --git a/src/DIMMTempSensor.cpp b/src/DIMMTempSensor.cpp
index 1399995..d290d63 100644
--- a/src/DIMMTempSensor.cpp
+++ b/src/DIMMTempSensor.cpp
@@ -44,9 +44,36 @@ extern "C"
}
constexpr const bool debug = false;
-
+constexpr auto dimmSensorInterface = "xyz.openbmc_project.Sensor.dimmLED";
+constexpr auto dimmSensorPath = "/xyz/openbmc_project/sensors/temperature/";
#define PECI_MBX_INDEX_DDR_DIMM_TEMP 0x0E
+static void setupDimmLEDMatch(
+ std::vector<sdbusplus::bus::match_t>& matches, sdbusplus::bus_t& connection,
+ const std::string& sensorName, std::function<void(const std::string&)>&& callback)
+{
+ std::function<void(sdbusplus::message_t & message)> eventHandler =
+ [callback{std::move(callback)}](sdbusplus::message_t& message) {
+ std::string objectName;
+ boost::container::flat_map<std::string, std::variant<std::string>>
+ values;
+ message.read(objectName, values);
+ auto findValue = values.find("LEDState");
+ if (findValue == values.end())
+ {
+ return;
+ }
+ std::string value = std::visit(VariantToStringVisitor(), findValue->second);
+
+ callback(value);
+ };
+ matches.emplace_back(connection,
+ "type='signal',member='PropertiesChanged',path_namespace='" +
+ std::string(dimmSensorPath) + std::string(sensorName) + "',arg0namespace='" +
+ std::string(dimmSensorInterface) + "'",
+ std::move(eventHandler));
+}
+
DIMMTempSensor::DIMMTempSensor(
std::shared_ptr<sdbusplus::asio::connection>& conn,
boost::asio::io_context& io, const std::string& sensorName,
@@ -54,14 +81,14 @@ DIMMTempSensor::DIMMTempSensor(
sdbusplus::asio::object_server& objectServer,
std::vector<thresholds::Threshold>&& thresholdData, const double maxReading,
const double minReading, const std::string& sensorType, const char* units,
- const float pollRate, PowerState readState, uint8_t peciBus,
- uint8_t peciAddr, uint8_t rank, double calibOffset) :
+ const float pollRate, PowerState readState, double calibOffset,
+ uint8_t peciBus, uint8_t peciAddr, uint8_t rank) :
Sensor(boost::replace_all_copy(sensorName, " ", "_"),
std::move(thresholdData), sensorConfiguration, "", false, false,
maxReading, minReading, conn, readState),
- sensorPollMs(static_cast<unsigned int>(pollRate * 1000)), peciBus(peciBus),
- peciAddr(peciAddr), dimmRank(rank), calibOffset(calibOffset),
- objectServer(objectServer), waitTimer(io)
+ sensorPollMs(static_cast<unsigned int>(pollRate * 1000)), calibOffset(calibOffset),
+ objectServer(objectServer), waitTimer(io), peciBus(peciBus), peciAddr(peciAddr),
+ dimmRank(rank), dimmSensorName(sensorName), dimmLEDState("OFF")
{
std::string interfacePath = "/xyz/openbmc_project/sensors/" + sensorType +
"/" + name;
@@ -72,7 +99,6 @@ DIMMTempSensor::DIMMTempSensor(
dimmLEDInterface = objectServer.add_interface(
interfacePath, "xyz.openbmc_project.Sensor.dimmLED");
- std::string dimmLEDState = "OFF";
dimmLEDInterface->register_property(
"LEDState", dimmLEDState, [this](const std::string& newValue, std::string& oldValue) {
oldValue = newValue; return true;
@@ -180,7 +206,7 @@ void DIMMTempSensor::read()
std::cerr << "timer error\n";
return;
}
- if (readingStateGood())
+ if (readingStateGood() && dimmLEDState == "ON")
{
double temp = 0;
int ret = getDIMMRegsInfoWord(&temp);
@@ -208,3 +234,23 @@ void DIMMTempSensor::read()
read();
});
}
+
+void DIMMTempSensor::setupMatches(const std::string& sensorName)
+{
+ std::weak_ptr<DIMMTempSensor> weakRef = weak_from_this();
+ setupDimmLEDMatch(matches, *dbusConnection, sensorName,
+ [weakRef, sensorName](const std::string& value) {
+ auto self = weakRef.lock();
+ if (!self)
+ {
+ return;
+ }
+ self->dimmLEDState = value;
+ if constexpr (debug)
+ {
+ std::cout << sensorName << " LED State" << " changed to "
+ << self->dimmLEDState << std::endl;
+ }
+ }
+ );
+}
diff --git a/src/DIMMTempSensor.hpp b/src/DIMMTempSensor.hpp
index 1f7d8d3..774ace2 100644
--- a/src/DIMMTempSensor.hpp
+++ b/src/DIMMTempSensor.hpp
@@ -10,7 +10,7 @@
#include <string>
#include <vector>
-struct DIMMTempSensor : public Sensor
+struct DIMMTempSensor : public Sensor, std::enable_shared_from_this<DIMMTempSensor>
{
DIMMTempSensor(std::shared_ptr<sdbusplus::asio::connection>& conn,
boost::asio::io_context& io, const std::string& name,
@@ -19,25 +19,28 @@ struct DIMMTempSensor : public Sensor
std::vector<thresholds::Threshold>&& thresholds,
const double maxReading, const double minReading,
const std::string& sensorType, const char* units,
- const float pollRate, PowerState readState, uint8_t peciBus,
- uint8_t peciAddr, uint8_t rank, double calibOffset);
+ const float pollRate, PowerState readState, double calibOffset,
+ uint8_t peciBus, uint8_t peciAddr, uint8_t rank);
~DIMMTempSensor() override;
void checkThresholds(void) override;
void read();
void init();
-
+ void setupMatches(const std::string& sensorName);
unsigned int sensorPollMs;
-
- uint8_t peciBus;
- uint8_t peciAddr;
- uint8_t dimmRank;
double calibOffset;
private:
int getDIMMRegsInfoWord(double* ps64data);
int getDIMMRegsTemp(double* ps64data);
// int getDIMMRegsPower(double* ps64data);
+
sdbusplus::asio::object_server& objectServer;
boost::asio::steady_timer waitTimer;
+ uint8_t peciBus;
+ uint8_t peciAddr;
+ uint8_t dimmRank;
+ std::string dimmSensorName;
+ std::string dimmLEDState;
+ std::vector<sdbusplus::bus::match_t> matches;
};
diff --git a/src/DIMMTempSensorMain.cpp b/src/DIMMTempSensorMain.cpp
index 042659f..a8fc05c 100644
--- a/src/DIMMTempSensorMain.cpp
+++ b/src/DIMMTempSensorMain.cpp
@@ -44,9 +44,11 @@ static constexpr double minTempReading = -128;
static constexpr double maxPowerReading = 500;
static constexpr double minPowerReading = 0;
+std::vector<std::unique_ptr<sdbusplus::bus::match::match>> matches;
+
void createSensors(
boost::asio::io_context& io, sdbusplus::asio::object_server& objectServer,
- boost::container::flat_map<std::string, std::unique_ptr<DIMMTempSensor>>&
+ boost::container::flat_map<std::string, std::shared_ptr<DIMMTempSensor>>&
sensors,
std::shared_ptr<sdbusplus::asio::connection>& dbusConnection)
{
@@ -125,22 +127,22 @@ void createSensors(
if (name.ends_with("_Temp"))
{
- sensor = std::make_unique<DIMMTempSensor>(
+ sensor = std::make_shared<DIMMTempSensor>(
dbusConnection, io, name, pathPair.first, objectServer,
std::move(sensorThresholds), maxTempReading,
- minTempReading, "temperature",
- sensor_paths::unitDegreesC, pollRate, readState,
- peciBus, peciAddr, dimmRank, 0);
+ minTempReading, "temperature", sensor_paths::unitDegreesC,
+ pollRate, readState, 0, peciBus, peciAddr, dimmRank);
}
else if (name.ends_with("_Power"))
{
- sensor = std::make_unique<DIMMTempSensor>(
+ sensor = std::make_shared<DIMMTempSensor>(
dbusConnection, io, name, pathPair.first, objectServer,
std::move(sensorThresholds), maxPowerReading,
minPowerReading, "power", sensor_paths::unitWatts,
- pollRate, readState, peciBus, peciAddr, dimmRank, 0);
+ pollRate, readState, 0, peciBus, peciAddr, dimmRank);
}
+ sensor->setupMatches(name);
sensor->init();
}
}
@@ -158,7 +160,7 @@ int main()
objectServer.add_manager("/xyz/openbmc_project/sensors");
systemBus->request_name("xyz.openbmc_project.DIMMTempSensor");
- boost::container::flat_map<std::string, std::unique_ptr<DIMMTempSensor>>
+ boost::container::flat_map<std::string, std::shared_ptr<DIMMTempSensor>>
sensors;
boost::asio::post(
io, [&]() { createSensors(io, objectServer, sensors, systemBus); });
--
2.34.1
@@ -0,0 +1,176 @@
From 47e8984b64fff089ed16bf390b5739e62a53d24e Mon Sep 17 00:00:00 2001
From: wangjue <jue.wang2@luxshare-ict.com>
Date: Tue, 26 Nov 2024 21:09:21 +0800
Subject: [PATCH] switch dimmtempsensor from peci to i3c
Signed-off-by: wangjue <jue.wang2@luxshare-ict.com>
---
src/DIMMTempSensor.cpp | 78 +++++++++++++++++++++++---------------
src/DIMMTempSensor.hpp | 7 ++--
src/DIMMTempSensorMain.cpp | 2 +-
3 files changed, 52 insertions(+), 35 deletions(-)
diff --git a/src/DIMMTempSensor.cpp b/src/DIMMTempSensor.cpp
index d290d63..7c4412f 100644
--- a/src/DIMMTempSensor.cpp
+++ b/src/DIMMTempSensor.cpp
@@ -46,6 +46,10 @@ extern "C"
constexpr const bool debug = false;
constexpr auto dimmSensorInterface = "xyz.openbmc_project.Sensor.dimmLED";
constexpr auto dimmSensorPath = "/xyz/openbmc_project/sensors/temperature/";
+constexpr auto dimmSpdReaderService = "xyz.openbmc_project.DimmSpdReader";
+constexpr auto dbusProperties = "org.freedesktop.DBus.Properties";
+constexpr auto tempInterface = "xyz.openbmc_project.Dimm.Temperature";
+
#define PECI_MBX_INDEX_DDR_DIMM_TEMP 0x0E
static void setupDimmLEDMatch(
@@ -132,9 +136,9 @@ DIMMTempSensor::~DIMMTempSensor()
objectServer.remove_interface(association);
}
-void DIMMTempSensor::init()
+void DIMMTempSensor::init(const std::string& sensorName)
{
- read();
+ read(sensorName);
}
void DIMMTempSensor::checkThresholds(void)
@@ -142,13 +146,7 @@ void DIMMTempSensor::checkThresholds(void)
thresholds::checkThresholds(this);
}
-int DIMMTempSensor::getDIMMRegsInfoWord(double* ps64data)
-{
- int ret = -1;
- ret = getDIMMRegsTemp(ps64data);
- return ret;
-}
-
+#if 0
int DIMMTempSensor::getDIMMRegsTemp(double* ps64data)
{
int peciFd = -1;
@@ -192,10 +190,47 @@ err:
return -1;
}
-void DIMMTempSensor::read()
+#endif
+
+void DIMMTempSensor::getDIMMRegsTemp(const std::string& sensorName)
+{
+ std::string path = "/xyz/openbmc_project/dimm/" + sensorName;
+ size_t tempPos = path.find("_Temp");
+ if (tempPos != std::string::npos) {
+ path = path.substr(0, tempPos);
+ }
+
+ std::weak_ptr<DIMMTempSensor> weakRef = weak_from_this();
+ dbusConnection->async_method_call(
+ [weakRef](const boost::system::error_code ec, const std::variant<double> value) {
+ if (ec)
+ {
+ std::cerr << "Error setting DIMM sensor Temp" << "\n";
+ return;
+ }
+ auto self = weakRef.lock();
+ if (!self)
+ {
+ return;
+ }
+ double v = std::get<double>(value);
+ if constexpr (debug)
+ {
+ std::cerr << "Dimm Temp raw reading " << v << "\n";
+ }
+ v += self->calibOffset;
+ self->updateValue(v);
+
+ },
+ dimmSpdReaderService, path, dbusProperties, "Get", tempInterface, "TS0");
+
+ return;
+}
+
+void DIMMTempSensor::read(const std::string& sensorName)
{
waitTimer.expires_after(std::chrono::milliseconds(sensorPollMs));
- waitTimer.async_wait([this](const boost::system::error_code& ec) {
+ waitTimer.async_wait([this, sensorName](const boost::system::error_code& ec) {
if (ec == boost::asio::error::operation_aborted)
{
return; // we're being cancelled
@@ -208,30 +243,13 @@ void DIMMTempSensor::read()
}
if (readingStateGood() && dimmLEDState == "ON")
{
- double temp = 0;
- int ret = getDIMMRegsInfoWord(&temp);
- if (ret == 0)
- {
- double v = temp;
- if constexpr (debug)
- {
- std::cerr << "Value update to " << v << ", raw reading "
- << temp << "\n";
- }
- v += calibOffset;
- updateValue(v);
- }
- else
- {
- std::cerr << "Fail to read DIMM tempture.\n";
- incrementError();
- }
+ getDIMMRegsTemp(sensorName);
}
else
{
updateValue(std::numeric_limits<double>::quiet_NaN());
}
- read();
+ read(sensorName);
});
}
diff --git a/src/DIMMTempSensor.hpp b/src/DIMMTempSensor.hpp
index 774ace2..5e629da 100644
--- a/src/DIMMTempSensor.hpp
+++ b/src/DIMMTempSensor.hpp
@@ -24,15 +24,14 @@ struct DIMMTempSensor : public Sensor, std::enable_shared_from_this<DIMMTempSens
~DIMMTempSensor() override;
void checkThresholds(void) override;
- void read();
- void init();
+ void read(const std::string& sensorName);
+ void init(const std::string& sensorName);
void setupMatches(const std::string& sensorName);
unsigned int sensorPollMs;
double calibOffset;
private:
- int getDIMMRegsInfoWord(double* ps64data);
- int getDIMMRegsTemp(double* ps64data);
+ void getDIMMRegsTemp(const std::string& sensorName);
// int getDIMMRegsPower(double* ps64data);
sdbusplus::asio::object_server& objectServer;
diff --git a/src/DIMMTempSensorMain.cpp b/src/DIMMTempSensorMain.cpp
index a8fc05c..b8f002b 100644
--- a/src/DIMMTempSensorMain.cpp
+++ b/src/DIMMTempSensorMain.cpp
@@ -143,7 +143,7 @@ void createSensors(
}
sensor->setupMatches(name);
- sensor->init();
+ sensor->init(name);
}
}
},
--
2.34.1
@@ -0,0 +1,161 @@
From acff0dcb9a23be3bdd5282b806e85ab1a8e7646c Mon Sep 17 00:00:00 2001
From: wangjue <jue.wang2@luxshare-ict.com>
Date: Mon, 9 Dec 2024 15:42:57 +0800
Subject: [PATCH] Add Sel log for CPU presence event
Signed-off-by: wangjue <jue.wang2@luxshare-ict.com>
---
src/IntelCPUSensor.cpp | 61 ++++++++++++++++++++++++++++++++++++++
src/IntelCPUSensor.hpp | 37 +++++------------------
src/IntelCPUSensorMain.cpp | 6 +++-
3 files changed, 73 insertions(+), 31 deletions(-)
diff --git a/src/IntelCPUSensor.cpp b/src/IntelCPUSensor.cpp
index 2bebcd8..abde76f 100644
--- a/src/IntelCPUSensor.cpp
+++ b/src/IntelCPUSensor.cpp
@@ -329,3 +329,64 @@ void IntelCPUSensor::checkThresholds(void)
thresholds::checkThresholds(this);
}
}
+
+void CPUPresentStateLog(const std::shared_ptr<sdbusplus::asio::connection>& conn, const std::string CPUStateSensorName)
+{
+ constexpr const char* selService = "xyz.openbmc_project.Logging.IPMI";
+ constexpr const char* selPath = "/xyz/openbmc_project/Logging/IPMI";
+ constexpr const char* selInterface = "xyz.openbmc_project.Logging.IPMI";
+ constexpr const char* selMethod = "IpmiSelAdd";
+ std::string sensorPath ="/xyz/openbmc_project/inventory/system/board/Lux_Baseboard/" + CPUStateSensorName;
+
+ auto method =
+ conn->new_method_call(selService, selPath, selInterface, selMethod);
+
+ method.append("SEL Entry");
+ method.append(sensorPath);
+ method.append(
+ std::array<uint8_t, 3>({0x07, 0xFF, 0xFF})); // presence Detected
+
+ method.append(true); // assert is true and deassert is false
+ method.append(uint16_t(0x0020)); // generator ID
+ try
+ {
+ conn->call_noreply(method);
+ }
+ catch (const sdbusplus::exception::SdBusError& ex)
+ {
+ lg2::error(
+ "Failed to call sel log {SELPATH}, {SELINTERFACE}, {SELMRTHOD}",
+ "SELPATH", selPath, "SELINTERFACE", selInterface, "SELMRTHOD",
+ selMethod);
+ }
+}
+
+bool cpuIsPresentCPLD(int cpuId)
+{
+ int ret = 0;
+ uint8_t index;
+ std::string i2cDev = "/dev/i2c-0";
+ // Perform the combined write/read
+
+ std::vector<uint8_t> readBuf(1);
+ std::vector<uint8_t> writeData = {0x91, 0x02};
+ const uint8_t slaveAddr = 0x0D;
+ uint8_t regVal;
+
+ ret = i2cWriteRead(i2cDev, slaveAddr, writeData, readBuf);
+ if (ret < 0)
+ {
+ std::cerr << "i2c failed to read regVal. \n";
+ return false;
+ }
+
+ regVal = readBuf[0];
+ if(cpuId == 0)
+ index = 1;
+ else if(cpuId == 1)
+ index = 0;
+ else
+ return false;
+
+ return (regVal & (1 << index)) == 0;
+}
diff --git a/src/IntelCPUSensor.hpp b/src/IntelCPUSensor.hpp
index ae90ab7..b928894 100644
--- a/src/IntelCPUSensor.hpp
+++ b/src/IntelCPUSensor.hpp
@@ -7,6 +7,8 @@
#include <boost/container/flat_map.hpp>
#include <gpiod.hpp>
#include <sdbusplus/asio/object_server.hpp>
+#include <phosphor-logging/lg2.hpp>
+#include <phosphor-logging/elog-errors.hpp>
#include <sensor.hpp>
#include <filesystem>
@@ -65,6 +67,11 @@ class IntelCPUSensor :
extern boost::container::flat_map<std::string, std::shared_ptr<IntelCPUSensor>>
gCpuSensors;
+extern void CPUPresentStateLog(const std::shared_ptr<sdbusplus::asio::connection>& conn,
+ const std::string CPUStateSensorName);
+
+extern bool cpuIsPresentCPLD(int cpuId);
+
// this is added to intelcpusensor.hpp to avoid having every sensor have to link
// against libgpiod, if another sensor needs it we may move it to utils
inline bool cpuIsPresent(const SensorBaseConfigMap& gpioConfig)
@@ -180,33 +187,3 @@ inline int i2cWriteRead(std::string& i2cDev, const uint8_t slaveAddr,
return 0;
}
-
-inline bool cpuIsPresentCPLD(int cpuId)
-{
- int ret = 0;
- uint8_t index;
- std::string i2cDev = "/dev/i2c-0";
- // Perform the combined write/read
-
- std::vector<uint8_t> readBuf(1);
- std::vector<uint8_t> writeData = {0x91, 0x02};
- const uint8_t slaveAddr = 0x0D;
- uint8_t regVal;
-
- ret = i2cWriteRead(i2cDev, slaveAddr, writeData, readBuf);
- if (ret < 0)
- {
- std::cerr << "i2c failed to read regVal. \n";
- return false;
- }
-
- regVal = readBuf[0];
- if(cpuId == 1)
- index = 1;
- else if(cpuId == 2)
- index = 0;
- else
- return false;
-
- return (regVal & (1 << index)) == 0;
-}
diff --git a/src/IntelCPUSensorMain.cpp b/src/IntelCPUSensorMain.cpp
index a955c6f..7bdd9f9 100644
--- a/src/IntelCPUSensorMain.cpp
+++ b/src/IntelCPUSensorMain.cpp
@@ -739,8 +739,12 @@ bool getCpuConfig(const std::shared_ptr<sdbusplus::asio::connection>& systemBus,
for (const auto& [suppIntf, suppCfg] : cfgData)
present = cpuIsPresent(suppCfg);
} else if(method == "CPLD") {
- if(cpuId != -1)
+ if(cpuId != -1) {
present = cpuIsPresentCPLD(cpuId);
+ std::string CPUPresentName = "CPU" + std::string(1, '0' + cpuId) + "_State";
+ if (present.has_value() && present.value() == true)
+ CPUPresentStateLog(systemBus, CPUPresentName);
+ }
} else {
std::cerr << "Invalid Presence value \n";
}
--
2.34.1
@@ -0,0 +1,55 @@
From 30aee385442d8ec0b691b16b5229692cbf0df0a5 Mon Sep 17 00:00:00 2001
From: wangjue <jue.wang2@luxshare-ict.com>
Date: Thu, 19 Dec 2024 19:31:08 +0800
Subject: [PATCH] Ensure CPU sensor names match those in the IPMI SDR list
Signed-off-by: wangjue <jue.wang2@luxshare-ict.com>
---
src/IntelCPUSensorMain.cpp | 29 +++++++++++++++++++++++++----
1 file changed, 25 insertions(+), 4 deletions(-)
diff --git a/src/IntelCPUSensorMain.cpp b/src/IntelCPUSensorMain.cpp
index 7bdd9f9..b6dc544 100644
--- a/src/IntelCPUSensorMain.cpp
+++ b/src/IntelCPUSensorMain.cpp
@@ -106,12 +106,33 @@ void detectCpuAsync(
std::string createSensorName(const std::string& label, const std::string& item,
const int& cpuId)
{
- std::string sensorName = label;
- if (item != "input")
+ std::string sensorName{};
+
+ if (label == "DTS")
+ {
+ sensorName = "CPU" + std::to_string(cpuId) + " Temp";
+ }
+ else if (item == "average" && label == "dimm power")
{
- sensorName += " " + item;
+ sensorName = label + " CPU" + std::to_string(cpuId);
+ }
+ else if (label == "cpu power")
+ {
+ if(item == "average")
+ sensorName = "CPU" + std::to_string(cpuId) + " power " + "avg";
+ else
+ sensorName = "CPU" + std::to_string(cpuId) + " power " + item;
}
- sensorName += " CPU" + std::to_string(cpuId);
+ else
+ {
+ sensorName = label;
+ if (item != "input")
+ {
+ sensorName += " " + item;
+ }
+ sensorName += " CPU" + std::to_string(cpuId);
+ }
+
// converting to Upper Camel case whole name
bool isWordEnd = true;
std::transform(sensorName.begin(), sensorName.end(), sensorName.begin(),
--
2.34.1
@@ -0,0 +1,25 @@
From d486099eb09eee64a0e1dc45785785f22c61a4a8 Mon Sep 17 00:00:00 2001
From: wangjue <jue.wang2@luxshare-ict.com>
Date: Tue, 24 Dec 2024 16:52:19 +0800
Subject: [PATCH] Set Available to false when dimm temp reading is not ready
Signed-off-by: wangjue <jue.wang2@luxshare-ict.com>
---
src/DIMMTempSensor.cpp | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/DIMMTempSensor.cpp b/src/DIMMTempSensor.cpp
index 7c4412f..a0c9d76 100644
--- a/src/DIMMTempSensor.cpp
+++ b/src/DIMMTempSensor.cpp
@@ -247,6 +247,7 @@ void DIMMTempSensor::read(const std::string& sensorName)
}
else
{
+ markAvailable(false);
updateValue(std::numeric_limits<double>::quiet_NaN());
}
read(sensorName);
--
2.34.1
@@ -0,0 +1,25 @@
From 37cc98c8b90ca056ac100b33cc04d26b64c8ce9a Mon Sep 17 00:00:00 2001
From: wangjue <jue.wang2@luxshare-ict.com>
Date: Tue, 31 Dec 2024 18:10:15 +0800
Subject: [PATCH] Add INA220 sensor
Signed-off-by: wangjue <jue.wang2@luxshare-ict.com>
---
src/PSUSensorMain.cpp | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/PSUSensorMain.cpp b/src/PSUSensorMain.cpp
index 2991ba0..7dd95dd 100644
--- a/src/PSUSensorMain.cpp
+++ b/src/PSUSensorMain.cpp
@@ -53,6 +53,7 @@ static const I2CDeviceTypeMap sensorTypes{
{"BMR490", I2CDeviceType{"bmr490", true}},
{"DPS800", I2CDeviceType{"dps800", true}},
{"INA219", I2CDeviceType{"ina219", true}},
+ {"INA226", I2CDeviceType{"ina226", true}},
{"INA230", I2CDeviceType{"ina230", true}},
{"IPSPS1", I2CDeviceType{"ipsps1", true}},
{"IR38060", I2CDeviceType{"ir38060", true}},
--
2.34.1
@@ -0,0 +1,195 @@
From 301fd47f7f21a780b06c4403a657d31e967934bf Mon Sep 17 00:00:00 2001
From: wangjue <jue.wang2@luxshare-ict.com>
Date: Fri, 3 Jan 2025 18:57:29 +0800
Subject: [PATCH] Trigger to read dimm temp by vwgpio1
Signed-off-by: wangjue <jue.wang2@luxshare-ict.com>
%% original patch: 0014-Trigger-to-read-dimm-temp-by-vwgpio1.patch
---
src/DIMMTempSensor.cpp | 107 +++++++++++++++++++++++++++++++++++++++--
src/DIMMTempSensor.hpp | 2 +
2 files changed, 106 insertions(+), 3 deletions(-)
diff --git a/src/DIMMTempSensor.cpp b/src/DIMMTempSensor.cpp
index a0c9d76..852810b 100644
--- a/src/DIMMTempSensor.cpp
+++ b/src/DIMMTempSensor.cpp
@@ -49,6 +49,9 @@ constexpr auto dimmSensorPath = "/xyz/openbmc_project/sensors/temperature/";
constexpr auto dimmSpdReaderService = "xyz.openbmc_project.DimmSpdReader";
constexpr auto dbusProperties = "org.freedesktop.DBus.Properties";
constexpr auto tempInterface = "xyz.openbmc_project.Dimm.Temperature";
+constexpr auto HostMiscDbusName = "xyz.openbmc_project.Host.Misc.Manager";
+constexpr auto platformStatePath = "/xyz/openbmc_project/misc/platform_state";
+constexpr auto platformStateInterface = "xyz.openbmc_project.State.Host.Misc";
#define PECI_MBX_INDEX_DDR_DIMM_TEMP 0x0E
@@ -78,6 +81,60 @@ static void setupDimmLEDMatch(
std::move(eventHandler));
}
+static bool getDbusMsgState(sdbusplus::message_t& msg, bool& value)
+{
+ std::string pltStateInterface;
+ std::string event;
+ boost::container::flat_map<std::string, std::variant<bool>>
+ propertiesChanged;
+ try
+ {
+ msg.read(pltStateInterface, propertiesChanged);
+ if (propertiesChanged.empty())
+ {
+ return false;
+ }
+
+ std::string property = propertiesChanged.begin()->first;
+
+ if (property.empty() || property != "dimmI3cSwitch")
+ {
+ return false;
+ }
+
+ value = std::get<bool>(propertiesChanged.begin()->second);
+ return true;
+ }
+ catch (const std::exception& e)
+ {
+ std::cerr << "exception while reading dbus property dimmI3cSwitch" << "\n";
+ return false;
+ }
+}
+
+static void dimmI3cSwitchMatcher(
+ std::vector<sdbusplus::bus::match_t>& matches, sdbusplus::bus_t& connection,
+ std::function<void(bool)>&& onMatch)
+{
+ auto pulseEventMatcherCallback =
+ [onMatch{std::move(onMatch)}](sdbusplus::message_t& msg) {
+ bool value = false;
+ if (!getDbusMsgState(msg, value))
+ {
+ return;
+ }
+ onMatch(value);
+ };
+
+ matches.emplace_back(
+ connection,
+ "type='signal',interface='org.freedesktop.DBus.Properties',member='"
+ "PropertiesChanged',arg0='" +
+ std::string(platformStateInterface) + "'",
+ std::move(pulseEventMatcherCallback));
+}
+
+
DIMMTempSensor::DIMMTempSensor(
std::shared_ptr<sdbusplus::asio::connection>& conn,
boost::asio::io_context& io, const std::string& sensorName,
@@ -121,6 +178,8 @@ DIMMTempSensor::DIMMTempSensor(
association::interface);
setInitialProperties(units);
+
+ dimmI3cSwitchState = getdimmI3cSwitchState(io);
}
DIMMTempSensor::~DIMMTempSensor()
@@ -202,10 +261,10 @@ void DIMMTempSensor::getDIMMRegsTemp(const std::string& sensorName)
std::weak_ptr<DIMMTempSensor> weakRef = weak_from_this();
dbusConnection->async_method_call(
- [weakRef](const boost::system::error_code ec, const std::variant<double> value) {
+ [weakRef, sensorName](const boost::system::error_code ec, const std::variant<double> value) {
if (ec)
{
- std::cerr << "Error setting DIMM sensor Temp" << "\n";
+ std::cerr << "Error getting DIMM sensor " << sensorName << " Temp" << "\n";
return;
}
auto self = weakRef.lock();
@@ -241,7 +300,7 @@ void DIMMTempSensor::read(const std::string& sensorName)
std::cerr << "timer error\n";
return;
}
- if (readingStateGood() && dimmLEDState == "ON")
+ if (readingStateGood() && dimmI3cSwitchState)
{
getDIMMRegsTemp(sensorName);
}
@@ -257,6 +316,7 @@ void DIMMTempSensor::read(const std::string& sensorName)
void DIMMTempSensor::setupMatches(const std::string& sensorName)
{
std::weak_ptr<DIMMTempSensor> weakRef = weak_from_this();
+ std::shared_ptr<DIMMTempSensor> sharedRef = weakRef.lock();
setupDimmLEDMatch(matches, *dbusConnection, sensorName,
[weakRef, sensorName](const std::string& value) {
auto self = weakRef.lock();
@@ -272,4 +332,45 @@ void DIMMTempSensor::setupMatches(const std::string& sensorName)
}
}
);
+
+ dimmI3cSwitchMatcher(matches, *dbusConnection, [sharedRef](bool state)
+ {
+ if (!sharedRef)
+ {
+ return;
+ }
+ if (!state)
+ {
+ sharedRef->dimmI3cSwitchState = false;
+ }
+ else
+ {
+ sharedRef->dimmI3cSwitchState = true;
+ }
+ std::cout << "dimmI3cSwitchState: " << (int)sharedRef->dimmI3cSwitchState << std::endl;
+ });
+}
+
+bool DIMMTempSensor::getdimmI3cSwitchState(boost::asio::io_context& io)
+{
+ auto conn = std::make_shared<sdbusplus::asio::connection>(io);
+ auto mesg = conn->new_method_call(HostMiscDbusName, platformStatePath,
+ "org.freedesktop.DBus.Properties", "Get");
+ mesg.append(platformStateInterface, "dimmI3cSwitch");
+
+ bool state = false;
+ try
+ {
+ auto resp = conn->call(mesg);
+ std::variant<bool> value;
+ resp.read(value);
+ state = std::get<bool>(value);
+ std::cout << " get dimmI3cSwitch State: " << (int)state << std::endl;
+ }
+ catch (std::exception& e)
+ {
+ std::cerr << "auto shutdown: failed to read node id";
+ }
+
+ return state;
}
diff --git a/src/DIMMTempSensor.hpp b/src/DIMMTempSensor.hpp
index 5e629da..fc51928 100644
--- a/src/DIMMTempSensor.hpp
+++ b/src/DIMMTempSensor.hpp
@@ -27,6 +27,7 @@ struct DIMMTempSensor : public Sensor, std::enable_shared_from_this<DIMMTempSens
void read(const std::string& sensorName);
void init(const std::string& sensorName);
void setupMatches(const std::string& sensorName);
+ bool getdimmI3cSwitchState(boost::asio::io_context& io);
unsigned int sensorPollMs;
double calibOffset;
@@ -41,5 +42,6 @@ struct DIMMTempSensor : public Sensor, std::enable_shared_from_this<DIMMTempSens
uint8_t dimmRank;
std::string dimmSensorName;
std::string dimmLEDState;
+ bool dimmI3cSwitchState;
std::vector<sdbusplus::bus::match_t> matches;
};
--
2.34.1
@@ -0,0 +1,63 @@
From e0fca894d30279a487d375a312dd956c195b046a Mon Sep 17 00:00:00 2001
From: wangjue <jue.wang2@luxshare-ict.com>
Date: Wed, 8 Jan 2025 20:23:11 +0800
Subject: [PATCH] Get the highest temperature of TS0, TS1, SPD_Temp
Signed-off-by: wangjue <jue.wang2@luxshare-ict.com>
---
src/DIMMTempSensor.cpp | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
diff --git a/src/DIMMTempSensor.cpp b/src/DIMMTempSensor.cpp
index 852810b..0fe9b83 100644
--- a/src/DIMMTempSensor.cpp
+++ b/src/DIMMTempSensor.cpp
@@ -43,6 +43,9 @@ extern "C"
#include <linux/i2c-dev.h>
}
+using PropertyMapType =
+ boost::container::flat_map<std::string, BasicVariantType>;
+
constexpr const bool debug = false;
constexpr auto dimmSensorInterface = "xyz.openbmc_project.Sensor.dimmLED";
constexpr auto dimmSensorPath = "/xyz/openbmc_project/sensors/temperature/";
@@ -261,7 +264,7 @@ void DIMMTempSensor::getDIMMRegsTemp(const std::string& sensorName)
std::weak_ptr<DIMMTempSensor> weakRef = weak_from_this();
dbusConnection->async_method_call(
- [weakRef, sensorName](const boost::system::error_code ec, const std::variant<double> value) {
+ [weakRef, sensorName](const boost::system::error_code ec, PropertyMapType& propMap) {
if (ec)
{
std::cerr << "Error getting DIMM sensor " << sensorName << " Temp" << "\n";
@@ -272,16 +275,23 @@ void DIMMTempSensor::getDIMMRegsTemp(const std::string& sensorName)
{
return;
}
- double v = std::get<double>(value);
+
+ auto ts0_temp = std::get_if<double>(&propMap["TS0"]);
+ auto ts1_temp = std::get_if<double>(&propMap["TS1"]);
+ auto spd_temp = std::get_if<double>(&propMap["SPD_TS"]);
+
+ double v = std::max(std::max(*ts0_temp, *ts1_temp), *spd_temp);
+
if constexpr (debug)
{
- std::cerr << "Dimm Temp raw reading " << v << "\n";
+ std::cout << "ts0_temp: " << *ts0_temp << " ts1_temp: " << *ts1_temp << " spd_temp: " << *spd_temp << std::endl;
+ std::cerr << "Dimm Temp max_value: " << v << std::endl;
}
v += self->calibOffset;
self->updateValue(v);
},
- dimmSpdReaderService, path, dbusProperties, "Get", tempInterface, "TS0");
+ dimmSpdReaderService, path, dbusProperties, "GetAll", tempInterface);
return;
}
--
2.34.1
@@ -0,0 +1,78 @@
From 1bb10963f47654a6fed6826bb3131401508d86cc Mon Sep 17 00:00:00 2001
From: wangjue <jue.wang2@luxshare-ict.com>
Date: Thu, 23 Jan 2025 19:07:55 +0800
Subject: [PATCH] Add retry in case unable to open intelcpu sensor file node
and initialize dimm LED to "Orange"
Signed-off-by: wangjue <jue.wang2@luxshare-ict.com>
---
src/DIMMTempSensor.cpp | 2 +-
src/IntelCPUSensor.cpp | 18 ++++++++++++++----
src/IntelCPUSensor.hpp | 1 +
3 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/src/DIMMTempSensor.cpp b/src/DIMMTempSensor.cpp
index 0fe9b83..d2c2f65 100644
--- a/src/DIMMTempSensor.cpp
+++ b/src/DIMMTempSensor.cpp
@@ -152,7 +152,7 @@ DIMMTempSensor::DIMMTempSensor(
maxReading, minReading, conn, readState),
sensorPollMs(static_cast<unsigned int>(pollRate * 1000)), calibOffset(calibOffset),
objectServer(objectServer), waitTimer(io), peciBus(peciBus), peciAddr(peciAddr),
- dimmRank(rank), dimmSensorName(sensorName), dimmLEDState("OFF")
+ dimmRank(rank), dimmSensorName(sensorName), dimmLEDState("NA")
{
std::string interfacePath = "/xyz/openbmc_project/sensors/" + sensorType +
"/" + name;
diff --git a/src/IntelCPUSensor.cpp b/src/IntelCPUSensor.cpp
index abde76f..260ea77 100644
--- a/src/IntelCPUSensor.cpp
+++ b/src/IntelCPUSensor.cpp
@@ -47,7 +47,7 @@ IntelCPUSensor::IntelCPUSensor(
objServer(objectServer), inputDev(io), waitTimer(io),
nameTcontrol("Tcontrol CPU" + std::to_string(cpuId)), path(path),
privTcontrol(std::numeric_limits<double>::quiet_NaN()),
- dtsOffset(dtsOffset), show(show), pollTime(IntelCPUSensor::sensorPollMs)
+ dtsOffset(dtsOffset), show(show), pollTime(IntelCPUSensor::sensorPollMs), retry(10)
{
if (show)
@@ -140,10 +140,20 @@ void IntelCPUSensor::setupRead(void)
fd = open(path.c_str(), O_RDONLY | O_NONBLOCK);
if (fd < 0)
{
- std::cerr << name << " unable to open fd!\n";
- return;
+ std::cerr << name << " unable to open fd! Error code: " << errno
+ << " (" << strerror(errno) << ")\n";
+ if(retry > 0)
+ {
+ std::cout << "Call restartRead to retry opening fd, retry " << (int)retry << std::endl;
+ retry--;
+ restartRead();
+ }
+ else
+ {
+ std::cout << "Still can't open fd after retry 10 times" << std::endl;
+ return;
+ }
}
-
inputDev.assign(fd);
}
else
diff --git a/src/IntelCPUSensor.hpp b/src/IntelCPUSensor.hpp
index b928894..37e5694 100644
--- a/src/IntelCPUSensor.hpp
+++ b/src/IntelCPUSensor.hpp
@@ -62,6 +62,7 @@ class IntelCPUSensor :
void checkThresholds(void) override;
void updateMinMaxValues(void);
void restartRead(void);
+ uint8_t retry;
};
extern boost::container::flat_map<std::string, std::shared_ptr<IntelCPUSensor>>
--
2.34.1
@@ -0,0 +1,92 @@
From 5efe2a34889b828a19c84818be3a551516513907 Mon Sep 17 00:00:00 2001
From: wangjue <jue.wang2@luxshare-ict.com>
Date: Fri, 24 Jan 2025 17:27:19 +0800
Subject: [PATCH] Set DIMM LED to NA when dc on and OFF when dc off
Signed-off-by: wangjue <jue.wang2@luxshare-ict.com>
---
src/DIMMTempSensor.cpp | 26 ++++++++++++++------------
1 file changed, 14 insertions(+), 12 deletions(-)
diff --git a/src/DIMMTempSensor.cpp b/src/DIMMTempSensor.cpp
index d2c2f65..dca398e 100644
--- a/src/DIMMTempSensor.cpp
+++ b/src/DIMMTempSensor.cpp
@@ -84,7 +84,7 @@ static void setupDimmLEDMatch(
std::move(eventHandler));
}
-static bool getDbusMsgState(sdbusplus::message_t& msg, bool& value)
+static bool getDbusMsgState(sdbusplus::message_t& msg, bool& value, std::string& propertyName)
{
std::string pltStateInterface;
std::string event;
@@ -99,13 +99,13 @@ static bool getDbusMsgState(sdbusplus::message_t& msg, bool& value)
}
std::string property = propertiesChanged.begin()->first;
-
- if (property.empty() || property != "dimmI3cSwitch")
+ if (property.empty() || (property != "dimmI3cSwitch" && property != "ESpiPlatformReset"))
{
return false;
}
value = std::get<bool>(propertiesChanged.begin()->second);
+ propertyName = property;
return true;
}
catch (const std::exception& e)
@@ -117,16 +117,17 @@ static bool getDbusMsgState(sdbusplus::message_t& msg, bool& value)
static void dimmI3cSwitchMatcher(
std::vector<sdbusplus::bus::match_t>& matches, sdbusplus::bus_t& connection,
- std::function<void(bool)>&& onMatch)
+ std::function<void(std::string, bool)>&& onMatch)
{
auto pulseEventMatcherCallback =
[onMatch{std::move(onMatch)}](sdbusplus::message_t& msg) {
bool value = false;
- if (!getDbusMsgState(msg, value))
+ std::string propertyName = "";
+ if (!getDbusMsgState(msg, value, propertyName))
{
return;
}
- onMatch(value);
+ onMatch(propertyName, value);
};
matches.emplace_back(
@@ -343,21 +344,22 @@ void DIMMTempSensor::setupMatches(const std::string& sensorName)
}
);
- dimmI3cSwitchMatcher(matches, *dbusConnection, [sharedRef](bool state)
+ dimmI3cSwitchMatcher(matches, *dbusConnection, [sharedRef](std::string propertyName, bool state)
{
if (!sharedRef)
{
return;
}
- if (!state)
+
+ if (propertyName == "dimmI3cSwitch")
{
- sharedRef->dimmI3cSwitchState = false;
+ sharedRef->dimmI3cSwitchState = state;
}
- else
+ else if (propertyName == "ESpiPlatformReset")
{
- sharedRef->dimmI3cSwitchState = true;
+ std::string dimmLEDState = state ? "NA" : "OFF";
+ sharedRef->dimmLEDInterface->set_property("LEDState", dimmLEDState);
}
- std::cout << "dimmI3cSwitchState: " << (int)sharedRef->dimmI3cSwitchState << std::endl;
});
}
--
2.34.1
@@ -0,0 +1,108 @@
From b7052285e077a632bd3cc123e1327fb58540c30c Mon Sep 17 00:00:00 2001
From: wangjue <jue.wang2@luxshare-ict.com>
Date: Wed, 5 Mar 2025 19:30:42 +0800
Subject: [PATCH] Fix incorrect config state for intel cpu sensors
Signed-off-by: wangjue <jue.wang2@luxshare-ict.com>
%% original patch: 0018-Fix-incorrect-config-state-for-intel-cpu-sensors.patch
---
src/IntelCPUSensorMain.cpp | 47 +++++++++++++++++++++++---------------
1 file changed, 28 insertions(+), 19 deletions(-)
diff --git a/src/IntelCPUSensorMain.cpp b/src/IntelCPUSensorMain.cpp
index b6dc544..bdb6d25 100644
--- a/src/IntelCPUSensorMain.cpp
+++ b/src/IntelCPUSensorMain.cpp
@@ -571,7 +571,6 @@ void detectCpu(boost::asio::steady_timer& pingTimer,
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
if (peci_Ping(config.addr) == PECI_CC_SUCCESS)
{
- bool dimmReady = false;
for (unsigned int rank = 0; rank < rankNumMax; rank++)
{
std::array<uint8_t, 8> pkgConfig{};
@@ -585,7 +584,7 @@ void detectCpu(boost::asio::steady_timer& pingTimer,
if ((pkgConfig[0] != 0U) || (pkgConfig[1] != 0U) ||
(pkgConfig[2] != 0U))
{
- dimmReady = true;
+ //pkgConfig for DIMM_TEMP will return 0 if i3c is switched on BMC side.
break;
}
}
@@ -595,14 +594,7 @@ void detectCpu(boost::asio::steady_timer& pingTimer,
}
}
- if (dimmReady)
- {
- newState = State::READY;
- }
- else
- {
- newState = State::ON;
- }
+ newState = State::ON;
}
if (config.state != newState)
@@ -634,29 +626,46 @@ void detectCpu(boost::asio::steady_timer& pingTimer,
{
rescanDelaySeconds = 3;
}
- else if (newState == State::READY)
- {
- rescanDelaySeconds = 5;
- std::cout << "DIMM(s) on " << config.name
- << " is/are detected\n";
- }
}
config.state = newState;
}
- if (config.state != State::READY)
+ std::vector<fs::path> peciDimmDevPaths;
+ std::ostringstream searchDimmPath;
+ searchDimmPath << std::hex << "peci-" << config.bus << "/" << config.bus
+ << "-" << config.addr;
+
+ std::string peciDevDir = "/sys/bus/peci/devices/";
+ findFiles(fs::path(peciDevDir + searchDimmPath.str()),
+ R"(peci-dimmpower.+/hwmon/hwmon\d+/name$)", peciDimmDevPaths,
+ 3);
+ if (!peciDimmDevPaths.empty())
{
- keepPinging = true;
+ config.state = State::READY;
}
if (debug)
{
- std::cout << config.name << ", state: " << config.state << "\n";
+ std::cout << config.name << ", state: " << config.state << std::endl;
}
+
peci_Unlock(peciFd);
}
+ for (CPUConfig& config : cpuConfigs)
+ {
+ if(config.state == State::READY)
+ {
+ keepPinging = false;
+ }
+ else
+ {
+ keepPinging = true;
+ break;
+ }
+ }
+
if (rescanDelaySeconds != 0U)
{
creationTimer.expires_after(std::chrono::seconds(rescanDelaySeconds));
--
2.34.1
@@ -0,0 +1,377 @@
From d9f16c1ee1b17aa3b7eb8d693a493ca7e04c9a6a Mon Sep 17 00:00:00 2001
From: wangjue <jue.wang2@luxshare-ict.com>
Date: Tue, 22 Apr 2025 16:46:48 +0800
Subject: [PATCH] Add retries to get inventory objects
Signed-off-by: wangjue <jue.wang2@luxshare-ict.com>
---
src/DIMMTempSensorMain.cpp | 228 +++++++++++++++++++++----------------
src/IntelCPUSensorMain.cpp | 54 ++++++---
2 files changed, 171 insertions(+), 111 deletions(-)
diff --git a/src/DIMMTempSensorMain.cpp b/src/DIMMTempSensorMain.cpp
index b8f002b..04e221b 100644
--- a/src/DIMMTempSensorMain.cpp
+++ b/src/DIMMTempSensorMain.cpp
@@ -35,7 +35,7 @@
#include <string>
#include <vector>
-constexpr const bool debug = false;
+constexpr const bool debug = true;
constexpr const char* configInterface =
"xyz.openbmc_project.Configuration.DIMMTemp";
@@ -46,109 +46,147 @@ static constexpr double minPowerReading = 0;
std::vector<std::unique_ptr<sdbusplus::bus::match::match>> matches;
-void createSensors(
+bool createSensors(
boost::asio::io_context& io, sdbusplus::asio::object_server& objectServer,
- boost::container::flat_map<std::string, std::shared_ptr<DIMMTempSensor>>&
- sensors,
+ boost::container::flat_map<std::string, std::shared_ptr<DIMMTempSensor>>& sensors,
std::shared_ptr<sdbusplus::asio::connection>& dbusConnection)
{
if (!dbusConnection)
{
std::cerr << "Connection not created\n";
- return;
+ return false;
}
- dbusConnection->async_method_call(
- [&io, &objectServer, &dbusConnection, &sensors](
- boost::system::error_code ec, const ManagedObjectType& resp) {
- if (ec)
+ ManagedObjectType resp;
+ resp.clear();
+ sdbusplus::message_t getManagedObjects =
+ dbusConnection->new_method_call(
+ entityManagerName, "/xyz/openbmc_project/inventory",
+ "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
+ try
+ {
+ sdbusplus::message_t reply =
+ dbusConnection->call(getManagedObjects);
+ reply.read(resp);
+ }
+ catch (const sdbusplus::exception_t& e)
+ {
+ std::cerr << "Error contacting entity manager\n";
+ return false;
+ }
+
+ for (const auto& pathPair : resp)
+ {
+ for (const auto& entry : pathPair.second)
+ {
+ if (entry.first != configInterface)
+ {
+ continue;
+ }
+ std::string name = loadVariant<std::string>(entry.second,
+ "Name");
+
+ std::vector<thresholds::Threshold> sensorThresholds;
+ if (!parseThresholdsFromConfig(pathPair.second,
+ sensorThresholds))
+ {
+ std::cerr << "error populating thresholds for " << name
+ << "\n";
+ }
+
+ float pollRate = loadVariant<double>(entry.second, "PollRate");
+ uint8_t peciBus = loadVariant<uint8_t>(entry.second, "Bus");
+ uint8_t peciAddr = loadVariant<uint8_t>(entry.second, "Address");
+ uint8_t dimmRank = loadVariant<uint8_t>(entry.second, "Rank");
+
+ /* calibration offset */
+ auto findCalibOffset = entry.second.find("Offset");
+ double calibOffset = 0;
+ if (findCalibOffset != entry.second.end())
+ {
+ calibOffset = std::visit(VariantToDoubleVisitor(),
+ findCalibOffset->second);
+ }
+
+ /* PowerState */
+ auto findPowerOn = entry.second.find("PowerState");
+ PowerState readState = PowerState::always;
+ if (findPowerOn != entry.second.end())
+ {
+ std::string powerState = std::visit(
+ VariantToStringVisitor(), findPowerOn->second);
+ setReadState(powerState, readState);
+ }
+
+ if constexpr (debug)
+ {
+ std::cerr << "Configuration parsed for \n\t" << entry.first
+ << "\n"
+ << "with\n"
+ << "\tName: " << name << "\n"
+ << "\tBus: " << static_cast<int>(peciBus) << "\n"
+ << "\tAddress: " << static_cast<int>(peciAddr)
+ << "\n"
+ << "\tDimmRank: " << static_cast<int>(dimmRank)
+ << "\tOffset: " << calibOffset << "\n";
+ }
+
+ auto& sensor = sensors[name];
+ sensor = nullptr;
+
+ if (name.ends_with("_Temp"))
+ {
+ sensor = std::make_shared<DIMMTempSensor>(
+ dbusConnection, io, name, pathPair.first, objectServer,
+ std::move(sensorThresholds), maxTempReading,
+ minTempReading, "temperature", sensor_paths::unitDegreesC,
+ pollRate, readState, 0, peciBus, peciAddr, dimmRank);
+ }
+ else if (name.ends_with("_Power"))
+ {
+ sensor = std::make_shared<DIMMTempSensor>(
+ dbusConnection, io, name, pathPair.first, objectServer,
+ std::move(sensorThresholds), maxPowerReading,
+ minPowerReading, "power", sensor_paths::unitWatts,
+ pollRate, readState, 0, peciBus, peciAddr, dimmRank);
+ }
+
+ sensor->setupMatches(name);
+ sensor->init(name);
+ }
+ }
+ return true;
+}
+
+void startCreateSensors(
+ boost::asio::io_context& io, sdbusplus::asio::object_server& objectServer,
+ boost::container::flat_map<std::string, std::shared_ptr<DIMMTempSensor>>& sensors,
+ std::shared_ptr<sdbusplus::asio::connection>& dbusConnection,
+ boost::asio::steady_timer& filterTimer, int& retries)
+{
+ filterTimer.expires_after(std::chrono::seconds(3));
+ filterTimer.async_wait([&](const boost::system::error_code& ec) {
+ if (ec == boost::asio::error::operation_aborted)
+ {
+ return; // we're being canceled
+ }
+
+ if (createSensors(io, objectServer, sensors, dbusConnection))
{
- std::cerr << "Error contacting entity manager\n";
- return;
+ retries = 0;
+ std::cout << "createSensors successed " << std::endl;
}
- for (const auto& pathPair : resp)
+ else
{
- for (const auto& entry : pathPair.second)
+ std::cout << "createSensors failed with retries " << retries << std::endl;
+ if (retries > 0)
{
- if (entry.first != configInterface)
- {
- continue;
- }
- std::string name = loadVariant<std::string>(entry.second,
- "Name");
-
- std::vector<thresholds::Threshold> sensorThresholds;
- if (!parseThresholdsFromConfig(pathPair.second,
- sensorThresholds))
- {
- std::cerr << "error populating thresholds for " << name
- << "\n";
- }
-
- float pollRate = loadVariant<double>(entry.second, "PollRate");
- uint8_t peciBus = loadVariant<uint8_t>(entry.second, "Bus");
- uint8_t peciAddr = loadVariant<uint8_t>(entry.second, "Address");
- uint8_t dimmRank = loadVariant<uint8_t>(entry.second, "Rank");
-
- /* calibration offset */
- auto findCalibOffset = entry.second.find("Offset");
- double calibOffset = 0;
- if (findCalibOffset != entry.second.end())
- {
- calibOffset = std::visit(VariantToDoubleVisitor(),
- findCalibOffset->second);
- }
-
- /* PowerState */
- auto findPowerOn = entry.second.find("PowerState");
- PowerState readState = PowerState::always;
- if (findPowerOn != entry.second.end())
- {
- std::string powerState = std::visit(
- VariantToStringVisitor(), findPowerOn->second);
- setReadState(powerState, readState);
- }
-
- if constexpr (debug)
- {
- std::cerr << "Configuration parsed for \n\t" << entry.first
- << "\n"
- << "with\n"
- << "\tName: " << name << "\n"
- << "\tBus: " << static_cast<int>(peciBus) << "\n"
- << "\tAddress: " << static_cast<int>(peciAddr)
- << "\n"
- << "\tDimmRank: " << static_cast<int>(dimmRank)
- << "\tOffset: " << calibOffset << "\n";
- }
-
- auto& sensor = sensors[name];
- sensor = nullptr;
-
- if (name.ends_with("_Temp"))
- {
- sensor = std::make_shared<DIMMTempSensor>(
- dbusConnection, io, name, pathPair.first, objectServer,
- std::move(sensorThresholds), maxTempReading,
- minTempReading, "temperature", sensor_paths::unitDegreesC,
- pollRate, readState, 0, peciBus, peciAddr, dimmRank);
- }
- else if (name.ends_with("_Power"))
- {
- sensor = std::make_shared<DIMMTempSensor>(
- dbusConnection, io, name, pathPair.first, objectServer,
- std::move(sensorThresholds), maxPowerReading,
- minPowerReading, "power", sensor_paths::unitWatts,
- pollRate, readState, 0, peciBus, peciAddr, dimmRank);
- }
-
- sensor->setupMatches(name);
- sensor->init(name);
+ retries--;
+ startCreateSensors(io, objectServer, sensors,
+ dbusConnection, filterTimer, retries);
}
}
- },
- entityManagerName, "/xyz/openbmc_project/inventory",
- "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
+ });
}
int main()
@@ -162,9 +200,11 @@ int main()
boost::container::flat_map<std::string, std::shared_ptr<DIMMTempSensor>>
sensors;
+
boost::asio::post(
io, [&]() { createSensors(io, objectServer, sensors, systemBus); });
+ boost::asio::steady_timer filterTimer(io);
boost::asio::steady_timer configTimer(io);
std::function<void(sdbusplus::message::message&)> eventHandler =
[&](sdbusplus::message::message&) {
@@ -181,11 +221,9 @@ int main()
std::cerr << "timer error\n";
return;
}
- createSensors(io, objectServer, sensors, systemBus);
- if (sensors.empty())
- {
- std::cout << "Configuration not detected\n";
- }
+
+ int retries = 20;
+ startCreateSensors(io, objectServer, sensors, systemBus, filterTimer, retries);
});
};
diff --git a/src/IntelCPUSensorMain.cpp b/src/IntelCPUSensorMain.cpp
index bdb6d25..bffba79 100644
--- a/src/IntelCPUSensorMain.cpp
+++ b/src/IntelCPUSensorMain.cpp
@@ -50,7 +50,7 @@
#endif
// clang-format on
-static constexpr bool debug = false;
+static constexpr bool debug = true;
boost::container::flat_map<std::string, std::shared_ptr<IntelCPUSensor>>
gCpuSensors;
@@ -718,6 +718,7 @@ bool getCpuConfig(const std::shared_ptr<sdbusplus::asio::connection>& systemBus,
{
bool useCache = false;
sensorConfigs.clear();
+ cpuConfigs.clear();
// use new data the first time, then refresh
for (const char* type : sensorTypes)
{
@@ -834,6 +835,39 @@ bool getCpuConfig(const std::shared_ptr<sdbusplus::asio::connection>& systemBus,
return false;
}
+void startGetCpuConfig(std::shared_ptr<sdbusplus::asio::connection>& systemBus,
+ boost::container::flat_set<CPUConfig>& cpuConfigs, ManagedObjectType& sensorConfigs,
+ sdbusplus::asio::object_server& objectServer, boost::asio::steady_timer& filterTimer,
+ boost::asio::steady_timer& pingTimer, boost::asio::steady_timer& creationTimer,
+ boost::asio::io_context& io, int& retries)
+{
+ filterTimer.expires_after(std::chrono::seconds(3));
+ filterTimer.async_wait([&](const boost::system::error_code& ec) {
+ if (ec == boost::asio::error::operation_aborted)
+ {
+ return; // we're being canceled
+ }
+
+ if (getCpuConfig(systemBus, cpuConfigs, sensorConfigs, objectServer))
+ {
+ std::cout << "getCpuConfig successed " << std::endl;
+ retries = 0;
+ detectCpuAsync(pingTimer, creationTimer, io, objectServer,
+ systemBus, cpuConfigs, sensorConfigs);
+ }
+ else
+ {
+ std::cout << "getCpuConfig failed with retries " << retries << std::endl;
+ if(retries > 0)
+ {
+ retries--;
+ startGetCpuConfig(systemBus, cpuConfigs, sensorConfigs, objectServer,
+ filterTimer, pingTimer, creationTimer, io, retries);
+ }
+ }
+ });
+}
+
int main()
{
boost::asio::io_context io;
@@ -874,21 +908,9 @@ int main()
std::cout << message.get_path() << " is changed\n";
}
- // this implicitly cancels the timer
- filterTimer.expires_after(std::chrono::seconds(1));
- filterTimer.async_wait([&](const boost::system::error_code& ec) {
- if (ec == boost::asio::error::operation_aborted)
- {
- return; // we're being canceled
- }
-
- if (getCpuConfig(systemBus, cpuConfigs, sensorConfigs,
- objectServer))
- {
- detectCpuAsync(pingTimer, creationTimer, io, objectServer,
- systemBus, cpuConfigs, sensorConfigs);
- }
- });
+ int retries = 20;
+ startGetCpuConfig(systemBus, cpuConfigs, sensorConfigs, objectServer,
+ filterTimer, pingTimer, creationTimer, io, retries);
};
std::vector<std::unique_ptr<sdbusplus::bus::match_t>> matches =
--
2.34.1