Fix an issue in the partially installed CPU case
When there are multiple CPU configurations in entity manager and
actually just one CPU is installed, cpusensor service will keep
pinging the missing CPU with making reset on the creationTimer
callback so the Dbus tree creation never be called. To fix this
issue, this commit refines the timer handling code.
Tested: Installed just one CPU while entity manager has multiple
CPU configs. The cpusensor service created Dbus sensors for the
installed CPU properly.
Change-Id: I13f280bba8d9225e74c4d541314b54ce2ea803d8
Reported-by: John Wang <wangzqbj@inspur.com>
Signed-off-by: Jae Hyun Yoo <jae.hyun.yoo@linux.intel.com>
diff --git a/src/CPUSensorMain.cpp b/src/CPUSensorMain.cpp
index f5ce369..dcb8e24 100644
--- a/src/CPUSensorMain.cpp
+++ b/src/CPUSensorMain.cpp
@@ -379,7 +379,7 @@
ManagedObjectType& sensorConfigs)
{
size_t rescanDelaySeconds = 0;
- bool keepPinging = false;
+ static bool keepPinging = false;
for (CPUConfig& config : cpuConfigs)
{
@@ -391,7 +391,7 @@
std::exit(EXIT_FAILURE);
}
- State state;
+ State newState;
struct peci_ping_msg msg;
msg.addr = config.addr;
if (!ioctl(file, PECI_IOC_PING, &msg))
@@ -421,45 +421,43 @@
if (dimmReady)
{
- state = State::READY;
+ newState = State::READY;
}
else
{
- state = State::ON;
+ newState = State::ON;
}
}
else
{
- state = State::OFF;
+ newState = State::OFF;
}
close(file);
- if (config.state != state)
+ if (config.state != newState)
{
- if (config.state == State::OFF)
+ if (newState != State::OFF)
{
- std::cout << config.name << " is detected\n";
- exportDevice(config);
- }
- if (state == State::READY)
- {
- std::cout << "DIMM(s) on " << config.name
- << " is/are detected\n";
- }
- config.state = state;
- }
+ if (config.state == State::OFF)
+ {
+ std::cout << config.name << " is detected\n";
+ exportDevice(config);
+ }
- if (config.state != State::OFF)
- {
- if (config.state == State::ON)
- {
- rescanDelaySeconds = 3;
+ if (newState == State::ON)
+ {
+ rescanDelaySeconds = 3;
+ }
+ else if (newState == State::READY)
+ {
+ rescanDelaySeconds = 5;
+ std::cout << "DIMM(s) on " << config.name
+ << " is/are detected\n";
+ }
}
- else
- {
- rescanDelaySeconds = 5;
- }
+
+ config.state = newState;
}
if (config.state != State::READY)
@@ -484,15 +482,15 @@
}
if (!createSensors(io, objectServer, dbusConnection, cpuConfigs,
- sensorConfigs))
+ sensorConfigs) ||
+ keepPinging)
{
detectCpuAsync(pingTimer, creationTimer, io, objectServer,
dbusConnection, cpuConfigs, sensorConfigs);
}
});
}
-
- if (keepPinging)
+ else if (keepPinging)
{
detectCpuAsync(pingTimer, creationTimer, io, objectServer,
dbusConnection, cpuConfigs, sensorConfigs);