openbmc / phosphor-pid-control

OpenBMC PID-based Thermal Control Daemon
Apache License 2.0
16 stars 21 forks source link

Add temp-to-margin conversion in margin PID loops #23

Closed Krellan closed 9 months ago

Krellan commented 1 year ago

This is not an issue, but rather, it's a proposal for enhancement. It takes more than a few sentences to describe, so I'm writing it up here, instead of just mentioning it on the OpenBMC Discord.

The read-margin-temp program is very useful, as a preprocessor for phosphor-pid-control, however, it's part of Quanta's BMC fork. It's not part of OpenBMC.

In the list of input sensors, for a margin PID loop, there are 2 key features that using read-margin-temp provides, that aren't currently matched by phosphor-pid-control alone:

I propose adding a new field to the PID loop configuration for PID loops of type margin.

The name of the field will be TempToMargin (unless I can think of a better name). The content of the field will be a JSON dictionary.

The phosphor-pid-control program will then preprocess the sensors accordingly, converting the named temperature sensors into margin sensors, in the usual way (Margin = Tjmax - Temperature). The rest of the PID loop processing will continue normally.

Example:

{
  ...
  "Type": "margin",
  "Inputs": ["temp1", "temp2", "margin1", "margin2"],
  "TempToMargin": {
    "temp1": 85,
    "temp2": 95
  },
  ...
}

How's this sound?

drakedog2008 commented 1 year ago

How could it deal with the case that the "temp1" is dynamically populated by EntityManager?

harveyquta commented 1 year ago

According to your example and my understanding, this is only for pid-control static json(config.json), not for entity-manager json setting, right?

Krellan commented 1 year ago

The TempToMargin field will be optional: if not present, it will be treated as if it were an empty JSON dictionary. In other words, it will have no effect.

It should work with entity-manager JSON and static JSON. They both boil down to populating the same data structure internally. I see no reason for a difference in behavior.

Ugh, I got the syntax wrong. Now I see what you mean. Here's a revised example:

{
  ...
  "Type": "Pid",
  "Class": "margin",
  "Inputs": [
    "temp1",
    "temp2",
    "margin1",
    "margin2"
  ],
  "TempToMargin": {
    "temp1": 85,
    "temp2": 95
  },
  ...
}

If it's to be dynamically populated by EntityManager, then this JSON stanza should be placed within the Exposes array of your EntityManager JSON files. This is only the addition of a new optional field TempToMargin to the existing JSON dictionary that holds the PID loop configuration (all the coefficients and so forth). It doesn't change or affect any other syntax.

harveyquta commented 1 year ago

So...it means that pid-control will preprocess to calculate the margin value of temp1(become 85 - temp1) and temp2(become 95 - temp2) and use the same setpoint as margin1 and margin2, for example, 10, to calculate pid?

Another question, does "TempToMargin" value need to support string value? Like "SetPointOffset" in pid-control.

Krellan commented 1 year ago

Yes, you got it. The intent of the example above: temp1 and temp2 are in units of raw temperature, and will be converted to margin, as you described. As margin1 and margin2 are already natively in units of margin, all four inputs will now be in units of margin. The PID can then take the input with the worst margin (the leader), using this margin value as the PID input, in the usual way.

As for string values, I haven't used this usage before. Looking through the code, I see it's a way to dynamically take a specified threshold field, by name, for the sensor, and get the necessary value from the threshold, instead of having to specify the value directly in the field. Interesting, it could be useful for some users. I don't really use thresholds, so haven't had the need for this. It could be added, as an optional syntax extension, if desired. Give the name of a particular threshold, such as CriticalHigh, and that value will be looked up and used as the margin-zero temperature point.

Krellan commented 1 year ago

Slight change of format needed.

I'm working on an initial implementation of this. Unfortunately, entity-manager has some limitations:

These are bugs in entity-manager that are beyond the scope of this feature request to fix. So, working around them seems to be the best approach for now.

I define a new format:

"TempToMargin": [
  85.0,
  95.0
]

These are the changes:

Hope this is all right with everyone.

Krellan commented 1 year ago

Oh, two more things this brings up:

Krellan commented 1 year ago

OK, the implementation is now up for review: https://gerrit.openbmc.org/c/openbmc/phosphor-pid-control/+/60303

Krellan commented 9 months ago

This feature has been merged! This FR can now be closed.