PSUSensor: Fix CPU presence detection
Currently the CPU presence, indicated by 'CPURequired' property, is
board specific and there are boards making use of 0 based and boards
making use of 1 based CPU indices. It really doesn't matter as long
as the inventory uses the same indices and the inventory is board
specific as well.
Within dbus-sensors the indices read from the inventory are assumed
to be 0 based in one place and 1 based in another place.
This patch addresses CPUs that define the CPURequired property. CPUs
that don't have it were and are still unaffected and behavior is still
the same.
For CPUs that define the value, it depends when the CPU presence was
updated on dbus and when psusensors service was started. It's actually
undefined behavior since dbus-sensors race with the CPU presence
detection service.
- Fix that by always using the actual index read from the inventory,
making dbus-sensors consistent within itself and support 0 and 1 based
entity-manager configurations.
- Fix parsing intelcpusensor provided presence since it has an
underscore between 'cpu' and the digit.
Fixes PSU sensors missing for CPU0 when psusensors was started after
the CPU presence was updated on dbus and the board had 0 based CPU
indices in entity-manager configuration.
This change might regress on platforms when both conditions are true:
- psusensors was started after CPU presence was updated on dbus
- that use mixed indices (0 and 1 based) in inventory and
entity-manager configuration
Change-Id: Ieeb5989ef819f2d0a4a2aa9b593cb25b30e0194e
Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com>
diff --git a/src/PSUSensorMain.cpp b/src/PSUSensorMain.cpp
index e0a38fc..94ef530 100644
--- a/src/PSUSensorMain.cpp
+++ b/src/PSUSensorMain.cpp
@@ -1004,6 +1004,8 @@
for (const auto& [path, objDict] : cpuSubTree)
{
auto obj = sdbusplus::message::object_path(path).filename();
+ boost::to_lower(obj);
+
if (!obj.starts_with("cpu") || objDict.empty())
{
continue;
@@ -1032,14 +1034,14 @@
int cpuIndex = 0;
try
{
- cpuIndex = std::stoi(obj.substr(obj.find_last_of("cpu") + 1));
+ cpuIndex = std::stoi(obj.substr(obj.size() - 1));
}
catch (const std::exception& e)
{
std::cerr << "Error converting CPU index, " << e.what() << '\n';
continue;
}
- cpuPresence[cpuIndex + 1] = *present;
+ cpuPresence[cpuIndex] = *present;
}
}
}