Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 3 | #include "conf.hpp" |
| 4 | #include "controller.hpp" |
James Feist | 22c257a | 2018-08-31 14:07:12 -0700 | [diff] [blame] | 5 | #include "pidcontroller.hpp" |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 6 | #include "sensors/manager.hpp" |
| 7 | #include "sensors/sensor.hpp" |
Patrick Venture | c32e3fc | 2019-02-28 10:01:11 -0800 | [diff] [blame] | 8 | #include "tuning.hpp" |
Patrick Venture | 1a15379 | 2020-08-11 08:41:47 -0700 | [diff] [blame^] | 9 | #include "zone_interface.hpp" |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 10 | |
Patrick Venture | a83a3ec | 2020-08-04 09:52:05 -0700 | [diff] [blame] | 11 | #include <sdbusplus/bus.hpp> |
| 12 | #include <sdbusplus/server.hpp> |
| 13 | #include <xyz/openbmc_project/Control/Mode/server.hpp> |
| 14 | |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 15 | #include <fstream> |
| 16 | #include <map> |
| 17 | #include <memory> |
| 18 | #include <set> |
| 19 | #include <string> |
| 20 | #include <vector> |
| 21 | |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 22 | template <typename... T> |
| 23 | using ServerObject = typename sdbusplus::server::object::object<T...>; |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 24 | using ModeInterface = sdbusplus::xyz::openbmc_project::Control::server::Mode; |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 25 | using ModeObject = ServerObject<ModeInterface>; |
| 26 | |
Patrick Venture | a076487 | 2020-08-08 07:48:43 -0700 | [diff] [blame] | 27 | namespace pid_control |
| 28 | { |
| 29 | |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 30 | /* |
| 31 | * The PIDZone inherits from the Mode object so that it can listen for control |
| 32 | * mode changes. It primarily holds all PID loops and holds the sensor value |
| 33 | * cache that's used per iteration of the PID loops. |
| 34 | */ |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 35 | class PIDZone : public ZoneInterface, public ModeObject |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 36 | { |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 37 | public: |
James Feist | 3484bed | 2019-02-25 13:28:18 -0800 | [diff] [blame] | 38 | PIDZone(int64_t zone, double minThermalOutput, double failSafePercent, |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 39 | const SensorManager& mgr, sdbusplus::bus::bus& bus, |
| 40 | const char* objPath, bool defer) : |
| 41 | ModeObject(bus, objPath, defer), |
Patrick Venture | f7a2dd5 | 2019-07-16 14:31:13 -0700 | [diff] [blame] | 42 | _zoneId(zone), _maximumSetPoint(), |
James Feist | 3484bed | 2019-02-25 13:28:18 -0800 | [diff] [blame] | 43 | _minThermalOutputSetPt(minThermalOutput), |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 44 | _failSafePercent(failSafePercent), _mgr(mgr) |
| 45 | { |
Patrick Venture | de79ee0 | 2019-05-08 14:50:00 -0700 | [diff] [blame] | 46 | if (loggingEnabled) |
Patrick Venture | c32e3fc | 2019-02-28 10:01:11 -0800 | [diff] [blame] | 47 | { |
Patrick Venture | 89002db | 2019-05-08 15:02:55 -0700 | [diff] [blame] | 48 | _log.open(loggingPath + "/zone_" + std::to_string(zone) + ".log"); |
Patrick Venture | c32e3fc | 2019-02-28 10:01:11 -0800 | [diff] [blame] | 49 | } |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 50 | } |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 51 | |
Patrick Venture | f7a2dd5 | 2019-07-16 14:31:13 -0700 | [diff] [blame] | 52 | double getMaxSetPointRequest(void) const override; |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 53 | bool getManualMode(void) const; |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 54 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 55 | /* Could put lock around this since it's accessed from two threads, but |
| 56 | * only one reader/one writer. |
| 57 | */ |
| 58 | void setManualMode(bool mode); |
| 59 | bool getFailSafeMode(void) const override; |
Patrick Venture | 0bbeaf8 | 2018-10-30 18:50:31 -0700 | [diff] [blame] | 60 | int64_t getZoneID(void) const; |
Patrick Venture | 9bbf333 | 2019-07-16 10:50:37 -0700 | [diff] [blame] | 61 | void addSetPoint(double setpoint) override; |
James Feist | 608304d | 2019-02-25 10:01:42 -0800 | [diff] [blame] | 62 | void addRPMCeiling(double ceiling) override; |
Patrick Venture | 9bbf333 | 2019-07-16 10:50:37 -0700 | [diff] [blame] | 63 | void clearSetPoints(void); |
James Feist | 608304d | 2019-02-25 10:01:42 -0800 | [diff] [blame] | 64 | void clearRPMCeilings(void); |
Patrick Venture | 5f59c0f | 2018-11-11 12:55:14 -0800 | [diff] [blame] | 65 | double getFailSafePercent(void) const override; |
Patrick Venture | f7a2dd5 | 2019-07-16 14:31:13 -0700 | [diff] [blame] | 66 | double getMinThermalSetpoint(void) const; |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 67 | |
Patrick Venture | 2d8e785 | 2018-10-30 19:14:07 -0700 | [diff] [blame] | 68 | Sensor* getSensor(const std::string& name) override; |
Patrick Venture | f7a2dd5 | 2019-07-16 14:31:13 -0700 | [diff] [blame] | 69 | void determineMaxSetPointRequest(void); |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 70 | void updateFanTelemetry(void); |
| 71 | void updateSensors(void); |
| 72 | void initializeCache(void); |
| 73 | void dumpCache(void); |
Patrick Venture | 563a356 | 2018-10-30 09:31:26 -0700 | [diff] [blame] | 74 | void processFans(void); |
| 75 | void processThermals(void); |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 76 | |
James Feist | 22c257a | 2018-08-31 14:07:12 -0700 | [diff] [blame] | 77 | void addFanPID(std::unique_ptr<Controller> pid); |
| 78 | void addThermalPID(std::unique_ptr<Controller> pid); |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 79 | double getCachedValue(const std::string& name) override; |
Patrick Venture | c399f6f | 2018-10-30 19:24:47 -0700 | [diff] [blame] | 80 | void addFanInput(const std::string& fan); |
| 81 | void addThermalInput(const std::string& therm); |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 82 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 83 | void initializeLog(void); |
| 84 | std::ofstream& getLogHandle(void); |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 85 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 86 | /* Method for setting the manual mode over dbus */ |
| 87 | bool manual(bool value) override; |
| 88 | /* Method for reading whether in fail-safe mode over dbus */ |
| 89 | bool failSafe() const override; |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 90 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 91 | private: |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 92 | std::ofstream _log; |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 93 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 94 | const int64_t _zoneId; |
Patrick Venture | f7a2dd5 | 2019-07-16 14:31:13 -0700 | [diff] [blame] | 95 | double _maximumSetPoint = 0; |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 96 | bool _manualMode = false; |
James Feist | 3484bed | 2019-02-25 13:28:18 -0800 | [diff] [blame] | 97 | const double _minThermalOutputSetPt; |
Patrick Venture | 5f59c0f | 2018-11-11 12:55:14 -0800 | [diff] [blame] | 98 | const double _failSafePercent; |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 99 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 100 | std::set<std::string> _failSafeSensors; |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 101 | |
Patrick Venture | 9bbf333 | 2019-07-16 10:50:37 -0700 | [diff] [blame] | 102 | std::vector<double> _SetPoints; |
James Feist | 608304d | 2019-02-25 10:01:42 -0800 | [diff] [blame] | 103 | std::vector<double> _RPMCeilings; |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 104 | std::vector<std::string> _fanInputs; |
| 105 | std::vector<std::string> _thermalInputs; |
| 106 | std::map<std::string, double> _cachedValuesByName; |
| 107 | const SensorManager& _mgr; |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 108 | |
James Feist | 22c257a | 2018-08-31 14:07:12 -0700 | [diff] [blame] | 109 | std::vector<std::unique_ptr<Controller>> _fans; |
| 110 | std::vector<std::unique_ptr<Controller>> _thermals; |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 111 | }; |
Patrick Venture | a076487 | 2020-08-08 07:48:43 -0700 | [diff] [blame] | 112 | |
| 113 | } // namespace pid_control |