1# How to Configure Phosphor-pid-control 2 3A system needs two groups of configurations: zones and sensors. 4 5## Json Configuration 6 7The json object should be a dictionary with two keys, `sensors` and `zones`. 8`sensors` is a list of the sensor dictionaries, whereas `zones` is a list of 9zones. 10 11### Sensors 12 13``` 14"sensors" : [ 15 { 16 "name": "fan1", 17 "type": "fan", 18 "readPath": "/xyz/openbmc_project/sensors/fan_tach/fan1", 19 "writePath": "/sys/devices/platform/ahb/ahb:apb/1e786000.pwm-tacho-controller/hwmon/**/pwm1", 20 "min": 0, 21 "max": 255 22 }, 23 { 24 "name": "fan2", 25 "type": "fan", 26 "readPath": "/xyz/openbmc_project/sensors/fan_tach/fan2", 27 "writePath": "/sys/devices/platform/ahb/ahb:apb/1e786000.pwm-tacho-controller/hwmon/**/pwm2", 28 "min": 0, 29 "max": 255, 30 "timeout": 4, 31 }, 32... 33``` 34 35A sensor has a `name`, a `type`, a `readPath`, a `writePath`, a `minimum` value, 36a `maximum` value, and a `timeout`. 37 38The `name` is used to reference the sensor in the zone portion of the 39configuration. 40 41The `type` is the type of sensor it is. This influences how its value is 42treated. Supports values are: `fan`, `temp`, and `margin`. 43 44**TODO: Add further details on what the types mean.** 45 46The `readPath` is the path that tells the daemon how to read the value from this 47sensor. It is optional, allowing for write-only sensors. If the value is absent 48or `None` it'll be treated as a write-only sensor. 49 50If the `readPath` value contains: `/xyz/openbmc_project/extsensors/` it'll be 51treated as a sensor hosted by the daemon itself whose value is provided 52externally. The daemon will own the sensor and publish it to dbus. This is 53currently only supported for `temp` and `margin` sensor types. 54 55If the `readPath` value contains: `/xyz/openbmc_project/` (this is checked after 56external), then it's treated as a passive dbus sensor. A passive dbus sensor is 57one that listens for property updates to receive its value instead of actively 58reading the `Value` property. 59 60If the `readPath` value contains: `/sys/` this is treated as a directly read 61sysfs path. There are two supported paths: 62 63* `/sys/class/hwmon/hwmon0/pwm1` 64* `/sys/devices/platform/ahb/1e786000.pwm-tacho-controller/hwmon/<asterisk 65 asterisk>/pwm1` 66 67The `writePath` is the path to set the value for the sensor. This is only valid 68for a sensor of type `fan`. The path is optional. If can be empty or `None`. It 69then only supports two options. 70 71If the `writePath` value contains: `/sys/` this is treated as a directory 72written sysfs path. There are two support paths: 73 74* `/sys/class/hwmon/hwmon0/pwm1` 75* `/sys/devices/platform/ahb/1e786000.pwm-tacho-controller/hwmon/<asterisk 76 asterisk>/pwm1` 77 78If the `writePath` value contains: `/xyz/openbmc_project/sensors/fan_tach/fan{N}` it 79sets of a sensor object that writes over dbus to the 80`xyz.openbmc_project.Control.FanPwm` interface. The `writePath` should be the 81full object path. 82 83``` 84busctl introspect xyz.openbmc_project.Hwmon-1644477290.Hwmon1 /xyz/openbmc_project/sensors/fan_tach/fan1 --no-pager 85NAME TYPE SIGNATURE RESULT/VALUE FLAGS 86org.freedesktop.DBus.Introspectable interface - - - 87.Introspect method - s - 88org.freedesktop.DBus.Peer interface - - - 89.GetMachineId method - s - 90.Ping method - - - 91org.freedesktop.DBus.Properties interface - - - 92.Get method ss v - 93.GetAll method s a{sv} - 94.Set method ssv - - 95.PropertiesChanged signal sa{sv}as - - 96xyz.openbmc_project.Control.FanPwm interface - - - 97.Target property t 255 emits-change writable 98xyz.openbmc_project.Sensor.Value interface - - - 99.MaxValue property x 0 emits-change writable 100.MinValue property x 0 emits-change writable 101.Scale property x 0 emits-change writable 102.Unit property s "xyz.openbmc_project.Sensor.Value.Uni... emits-change writable 103.Value property x 2823 emits-change writable 104``` 105 106The `minimum` and `maximum` values are optional. When `maximum` is non-zero it 107expects to write a percentage value converted to a value between the minimum and 108maximum. 109 110The `timeout` value is optional and controls the sensor failure behavior. If a 111sensor is a fan the default value is 2 seconds, otherwise it's 0. When a 112sensor's timeout is 0 it isn't checked against a read timeout failure case. If a 113sensor fails to be read within the timeout period, the zone goes into failsafe 114to handle the case where it doesn't know what to do -- as it doesn't have all 115its inputs. 116 117### Zones 118 119``` 120"zones" : [ 121 { 122 "id": 1, 123 "minThermalOutput": 3000.0, 124 "failsafePercent": 75.0, 125 "pids": [], 126... 127``` 128 129Each zone has its own fields, and a list of PIDs. 130 131| field | type | meaning | 132| ------------------ | --------- | ----------------------------------------- | 133| `id` | `int64_t` | This is a unique identifier for the zone. | 134| `minThermalOutput` | `double` | This is the minimum value that should be considered from the thermal outputs. Commonly used as the minimum fan RPM.| 135| `failsafePercent` | `double` | If there is a fan PID, it will use this value if the zone goes into fail-safe as the output value written to the fan's sensors.| 136 137The `id` field here is used in the d-bus path to talk to the 138`xyz.openbmc_project.Control.Mode` interface. 139 140***TODO:*** Examine how the fan controller always treating its output as a 141percentage works for future cases. 142 143### PIDs 144 145There are a few PID types: `fan`, `temp`, `margin`, and `stepwise`. 146 147The `fan` PID is meant to drive fans. It's expecting to get the maximum RPM 148setpoint value from the owning zone and then drive the fans to that value. 149 150A `temp` PID is meant to drive the RPM setpoint given an absolute temperature 151value (higher value indicates a warmer temperature). 152 153A `margin` PID is meant to drive the RPM setpoint given a margin value (lower 154value indicates a warmer temperature). 155 156The setpoint output from the thermal controllers is called `RPMSetpoint()` 157However, it doesn't need to be an RPM value. 158 159***TODO:*** Rename this method and others to not say necessarily RPM. 160 161Some PID configurations have fields in common, but may be interpreted 162differently. 163 164#### PID Field 165 166If the PID `type` is not `stepwise` then the PID field is defined as follows: 167 168| field | type | meaning | 169| -------------------- | -------- | ----------------------------------------- | 170| `samplePeriod` | `double` | How frequently the value is sampled. 0.1 for fans, 1.0 for temperatures.| 171| `proportionalCoeff` | `double` | The proportional coefficient. | 172| `integralCoeff` | `double` | The integral coefficient. | 173| `feedFwdOffsetCoeff` | `double` | The feed forward offset coefficient. | 174| `feedFwdGainCoeff` | `double` | The feed forward gain coefficient. | 175| `integralLimit_min` | `double` | The integral minimum clamp value. | 176| `integralLimit_max` | `double` | The integral maximum clamp value. | 177| `outLim_min` | `double` | The output minimum clamp value. | 178| `outLim_max` | `double` | The output maximum clamp value. | 179| `slewNeg` | `double` | Negative slew value to dampen output. | 180| `slewPos` | `double` | Positive slew value to accelerate output. | 181 182The units for the coefficients depend on the configuration of the PIDs. 183 184If the PID is a `margin` controller and its `setpoint` is in centigrade and 185output in RPM: proportionalCoeff is your p value in units: RPM/C and integral 186coefficient: RPM/C sec 187 188If the PID is a fan controller whose output is pwm: proportionalCoeff is %/RPM 189and integralCoeff is %/RPM sec. 190 191***NOTE:*** The sample periods are specified in the configuration as they are 192used in the PID computations, however, they are not truly configurable as they 193are used for the update periods for the fan and thermal sensors. 194 195#### type == "fan" 196 197``` 198"name": "fan1-5", 199"type": "fan", 200"inputs": ["fan1", "fan5"], 201"setpoint": 90.0, 202"pid": { 203... 204} 205``` 206 207The type `fan` builds a `FanController` PID. 208 209| field | type | meaning | 210| ---------- | ----------------- | ------------------------------------------- | 211| `name` | `string` | The name of the PID. This is just for humans and logging.| 212| `type` | `string` | `fan` | 213| `inputs` | `list of strings` | The names of the sensor(s) that are used as input and output for the PID loop.| 214| `setpoint` | `double` | Presently UNUSED | 215| `pid` | `dictionary` | A PID dictionary detailed above. | 216 217#### type == "temp" 218 219***TODO:*** Add notes for temperature configuration. 220 221#### type == "margin" 222 223``` 224"name": "fleetingpid0", 225"type": "margin", 226"inputs": ["fleeting0"], 227"setpoint": 10, 228"pid": { 229... 230} 231``` 232 233The type `margin` builds a `ThermalController` PID. 234 235| field | type | meaning | 236| ---------- | ----------------- | ------------------------------------------- | 237| `name` | `string` | The name of the PID. This is just for humans and logging.| 238| `type` | `string` | `margin` | 239| `inputs` | `list of strings` | The names of the sensor(s) that are used as input for the PID loop.| 240| `setpoint` | `double` | The setpoint value for the thermal PID. The setpoint for the margin sensors.| 241| `pid` | `dictionary` | A PID dictionary detailed above. | 242 243The output of a `margin` PID loop is that it sets the setpoint value for the 244zone. It does this by adding the value to a list of values. The value chosen by 245the fan PIDs (in this cascade configuration) is the maximum value. 246 247#### type == "stepwise" 248 249***TODO:*** Write up `stepwise` details. 250