1# phosphor-pid-control 2 3This is a daemon running within the OpenBMC environment. It uses a well-defined 4configuration file to control the temperature of the tray components to keep 5them within operating conditions. It may require coordination with host-side 6tooling and OpenBMC. 7 8## Overview 9 10The BMC will run a daemon that controls the fans by pre-defined zones. The 11application will use thermal control, such that each defined zone is kept within 12a range and adjusted based on thermal information provided from locally readable 13sensors as well as host-provided information over an IPMI OEM command. 14 15A system (or tray) will be broken out into one or more zones, specified via 16configuration files or dbus. Each zone will contain at least one fan and at 17least one temperature sensor and some device margins. The sensor data can be 18provided via sysfs, dbus, or through IPMI. In either case, default margins 19should be provided in case of failure or other unknown situation. 20 21The system will run a control loop for each zone with the attempt to maintain 22the temperature within that zone within the margin for the devices specified. 23 24## Detailed Design 25 26The software will run as a multi-threaded daemon that runs a control loop for 27each zone, and has a master thread which listens for dbus messages. Each zone 28will require at least one fan that it exclusively controls, however, zones can 29share temperature sensors. 30 31 32 33In this figure the communications channels between swampd and ipmid and 34phosphor-hwmon are laid out. 35 36### Zone Specification 37 38A configuration file will need to exist for each board. 39 40Each zone must have at least one fan that it exclusively controls. Each zone 41must have at least one temperature sensor, but they may be shared. 42 43The internal thermometers specified can be read via sysfs or dbus. 44 45### Chassis Delta 46 47Due to data center requirements, the delta between the outgoing air temperature 48and the environmental air temperature must be no greater than 15C. 49 50### IPMI Access to Phosphor-pid-control 51 52[OEM-IPMI Definitions](ipmid.md) 53 54#### Set Sensor Value 55 56Tools needs to update the thermal controller with information not necessarily 57available to the BMC. This will comprise of a list of temperature (or margin?) 58sensors that are updated by the set sensor command. Because they don't represent 59real sensors in the system, the set sensor handler can simply broadcast the 60update as a properties update on dbus when it receives the command over IPMI. 61 62#### Set Fan PWM 63 64A tool can override a specific fan's PWM when we implement the set sensor IPMI 65command pathway. 66 67#### Get Fan Tach 68 69A tool can read fan_tach through the normal IPMI interface presently exported 70for sensors. 71 72### Sensor Update Loop 73 74The plan is to listen for fan_tach updates for each fan in a background thread. 75This will receive an update from phosphor-hwmon each time it updates any sensor 76it cares about. 77 78By default phosphor-hwmon reads each sensor in turn and then sleeps for 1 79second. We'll be updating phosphor-hwmon to sleep for a shorter period -- how 80short though is still TBD. We'll also be updating phosphor-hwmon to support pwm 81as a target. 82 83### Thermal Control Loops 84 85Each zone will require a control loop that monitors the associated thermals and 86controls the fan(s). The EC PID loop is designed to hit the fans 10 times per 87second to drive them to the desired value and read the sensors once per second. 88We'll be receiving sensor updates with such regularly, however, at present it 89takes ~0.13s to read all 8 fans. Which can't be read constantly without bringing 90the system to its knees -- in that all CPU cycles would be spent reading the 91fans. TBD on how frequently we'll be reading the fan sensors and the impact this 92will have. 93 94### Main Thread 95 96The main thread will manage the other threads, and process the initial 97configuration files. It will also register a dbus handler for the OEM message. 98 99### Enabling Logging & Tuning 100 101By default, swampd won't log information. To enable logging pass "-l" on the 102command line with a parameter that is the folder into which to write the logs. 103 104The log files will be named `{folderpath}/zone_{zoneid}.log`. 105 106To enable tuning, pass "-t" on the command line. 107 108See [Logging & Tuning](tuning.md) for more information. 109 110## Code Layout 111 112The code is broken out into modules as follows: 113 114* `dbus` - Any read or write interface that uses dbus primarily. 115* `experiments` - Small execution paths that allow for fan examination 116 including how quickly fans respond to changes. 117* `ipmi` - Manual control for any zone is handled by receiving an IPMI 118 message. This holds the ipmid provider for receiving those messages and 119 sending them onto swampd. 120* `notimpl` - These are read-only and write-only interface implementations 121 that can be dropped into a pluggable sensor to make it complete. 122* `pid` - This contains all the PID associated code, including the zone 123 definition, controller definition, and the PID computational code. 124* `scripts` - This contains the scripts that convert YAML into C++. 125* `sensors` - This contains a couple of sensor types including the pluggable 126 sensor's definition. It also holds the sensor manager. 127* `sysfs` - This contains code that reads from or writes to sysfs. 128* `threads` - Most of swampd's threads run in this method where there's just a 129 dbus bus that we manage. 130 131## Example System Configurations 132 133### Two Margin Sensors Into Three Fans (Non-Step PID) 134 135``` 136A single zone system where multiple margin thermal sensors are fed into one PID 137that generates the output RPM for a set of fans controlled by one PID. 138 139margin sensors as input to thermal pid 140 141fleeting0+---->+-------+ +-------+ Thermal PID sampled 142 | min()+--->+ PID | slower rate. 143fleeting1+---->+-------+ +---+---+ 144 | 145 | 146 | RPM setpoint 147 Current RPM v 148 +--+-----+ 149 The Fan PID fan0+---> | New PWM +-->fan0 150 samples at a | | | 151 faster rate fan1+---> PID +---------->--->fan1 152 speeding up the | | | 153 fans. fan2+---> | +-->fan2 154 ^ +--------+ + 155 | | 156 +-------------------------------+ 157 RPM updated by PWM. 158``` 159