Implementing the TempToMargin feature
Wrapping the input name std::string in a new structure SensorInput, so
that the TempToMargin information can be cleanly carried along with
it, all the way down to the PID input processing layer where it is
needed. This allows the conversion to be done just-in-time before the
temperature reading is interpreted, minimizing the blast radius of
this change. Nonetheless, because of the type change, there was a
somewhat large blast radius to implement this feature.
The design, and the documentation, is already here:
https://github.com/openbmc/phosphor-pid-control/issues/23
Tested: Added unit tests for JSON parsing and for proper execution
of the TempToMargin feature. They pass. Ran it locally, on our
appropriately-configured system, and it seems to work for me.
Change-Id: I598ba485195aaa70c26e91a1da3ab88fff8c3a4c
Signed-off-by: Josh Lehan <krellan@google.com>
diff --git a/dbus/dbusconfiguration.cpp b/dbus/dbusconfiguration.cpp
index d784b2c..2473252 100644
--- a/dbus/dbusconfiguration.cpp
+++ b/dbus/dbusconfiguration.cpp
@@ -338,7 +338,13 @@
{
interface = thresholds::criticalInterface;
}
- const std::string& path = sensorConfig.at(info.inputs.front()).readPath;
+
+ // Although this checks only the first vector element for the
+ // named threshold, it is OK, because the SetPointOffset parser
+ // splits up the input into individual vectors, each with only a
+ // single element, if it detects that SetPointOffset is in use.
+ const std::string& path =
+ sensorConfig.at(info.inputs.front().name).readPath;
DbusHelper helper(sdbusplus::bus::new_system());
std::string service = helper.getService(interface, path);
@@ -848,19 +854,32 @@
}
}
+ std::vector<double> inputTempToMargin;
+
+ auto findTempToMargin = base.find("TempToMargin");
+ if (findTempToMargin != base.end())
+ {
+ inputTempToMargin =
+ std::get<std::vector<double>>(findTempToMargin->second);
+ }
+
+ std::vector<pid_control::conf::SensorInput> sensorInputs =
+ spliceInputs(inputSensorNames, inputTempToMargin);
+
if (offsetType.empty())
{
conf::ControllerInfo& info = conf[pidName];
- info.inputs = std::move(inputSensorNames);
+ info.inputs = std::move(sensorInputs);
populatePidInfo(bus, base, info, nullptr, sensorConfig);
}
else
{
// we have to split up the inputs, as in practice t-control
// values will differ, making setpoints differ
- for (const std::string& input : inputSensorNames)
+ for (const pid_control::conf::SensorInput& input :
+ sensorInputs)
{
- conf::ControllerInfo& info = conf[input];
+ conf::ControllerInfo& info = conf[input.name];
info.inputs.emplace_back(input);
populatePidInfo(bus, base, info, &offsetType,
sensorConfig);
@@ -932,7 +951,17 @@
continue;
}
conf::ControllerInfo& info = conf[pidName];
- info.inputs = std::move(inputs);
+
+ std::vector<double> inputTempToMargin;
+
+ auto findTempToMargin = base.find("TempToMargin");
+ if (findTempToMargin != base.end())
+ {
+ inputTempToMargin =
+ std::get<std::vector<double>>(findTempToMargin->second);
+ }
+
+ info.inputs = spliceInputs(inputs, inputTempToMargin);
info.type = "stepwise";
info.stepwiseInfo.ts = 1.0; // currently unused