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> |
Patrick Williams | b228bc3 | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 23 | using ServerObject = typename sdbusplus::server::object_t<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 | /* |
Patrick Venture | 597ebd6 | 2020-08-11 08:48:19 -0700 | [diff] [blame] | 31 | * The DbusPidZone inherits from the Mode object so that it can listen for |
| 32 | * control mode changes. It primarily holds all PID loops and holds the sensor |
| 33 | * value cache that's used per iteration of the PID loops. |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 34 | */ |
Patrick Venture | 597ebd6 | 2020-08-11 08:48:19 -0700 | [diff] [blame] | 35 | class DbusPidZone : 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: |
Patrick Venture | 597ebd6 | 2020-08-11 08:48:19 -0700 | [diff] [blame] | 38 | DbusPidZone(int64_t zone, double minThermalOutput, double failSafePercent, |
Patrick Williams | b228bc3 | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 39 | const SensorManager& mgr, sdbusplus::bus_t& bus, |
Patrick Venture | 597ebd6 | 2020-08-11 08:48:19 -0700 | [diff] [blame] | 40 | const char* objPath, bool defer) : |
Patrick Williams | d8c5a45 | 2022-04-07 16:08:56 -0500 | [diff] [blame] | 41 | ModeObject(bus, objPath, |
| 42 | defer ? ModeObject::action::defer_emit |
| 43 | : ModeObject::action::emit_object_added), |
Patrick Venture | f7a2dd5 | 2019-07-16 14:31:13 -0700 | [diff] [blame] | 44 | _zoneId(zone), _maximumSetPoint(), |
James Feist | 3484bed | 2019-02-25 13:28:18 -0800 | [diff] [blame] | 45 | _minThermalOutputSetPt(minThermalOutput), |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 46 | _failSafePercent(failSafePercent), _mgr(mgr) |
| 47 | { |
Patrick Venture | de79ee0 | 2019-05-08 14:50:00 -0700 | [diff] [blame] | 48 | if (loggingEnabled) |
Patrick Venture | c32e3fc | 2019-02-28 10:01:11 -0800 | [diff] [blame] | 49 | { |
Patrick Venture | 89002db | 2019-05-08 15:02:55 -0700 | [diff] [blame] | 50 | _log.open(loggingPath + "/zone_" + std::to_string(zone) + ".log"); |
Patrick Venture | c32e3fc | 2019-02-28 10:01:11 -0800 | [diff] [blame] | 51 | } |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 52 | } |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 53 | |
Patrick Venture | 7a98c19 | 2020-08-12 08:35:16 -0700 | [diff] [blame] | 54 | bool getManualMode(void) const override; |
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 | */ |
Josh Lehan | a4146eb | 2020-10-01 11:49:09 -0700 | [diff] [blame] | 58 | |
| 59 | bool getRedundantWrite(void) const override; |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 60 | void setManualMode(bool mode); |
| 61 | bool getFailSafeMode(void) const override; |
Patrick Venture | 7a98c19 | 2020-08-12 08:35:16 -0700 | [diff] [blame] | 62 | |
Patrick Venture | 0bbeaf8 | 2018-10-30 18:50:31 -0700 | [diff] [blame] | 63 | int64_t getZoneID(void) const; |
Nirav Shah | ccc8bb6 | 2022-02-17 21:06:51 -0800 | [diff] [blame] | 64 | void addSetPoint(double setPoint, const std::string& name) override; |
Patrick Venture | 7a98c19 | 2020-08-12 08:35:16 -0700 | [diff] [blame] | 65 | double getMaxSetPointRequest(void) const override; |
James Feist | 608304d | 2019-02-25 10:01:42 -0800 | [diff] [blame] | 66 | void addRPMCeiling(double ceiling) override; |
Patrick Venture | 7a98c19 | 2020-08-12 08:35:16 -0700 | [diff] [blame] | 67 | void clearSetPoints(void) override; |
| 68 | void clearRPMCeilings(void) override; |
Patrick Venture | 5f59c0f | 2018-11-11 12:55:14 -0800 | [diff] [blame] | 69 | double getFailSafePercent(void) const override; |
Nirav Shah | ccc8bb6 | 2022-02-17 21:06:51 -0800 | [diff] [blame] | 70 | double getMinThermalSetPoint(void) const; |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 71 | |
Patrick Venture | 2d8e785 | 2018-10-30 19:14:07 -0700 | [diff] [blame] | 72 | Sensor* getSensor(const std::string& name) override; |
Patrick Venture | 7a98c19 | 2020-08-12 08:35:16 -0700 | [diff] [blame] | 73 | void determineMaxSetPointRequest(void) override; |
| 74 | void updateFanTelemetry(void) override; |
| 75 | void updateSensors(void) override; |
| 76 | void initializeCache(void) override; |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 77 | void dumpCache(void); |
Josh Lehan | a4146eb | 2020-10-01 11:49:09 -0700 | [diff] [blame] | 78 | |
Patrick Venture | 7a98c19 | 2020-08-12 08:35:16 -0700 | [diff] [blame] | 79 | void processFans(void) override; |
| 80 | void processThermals(void) override; |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 81 | |
James Feist | 22c257a | 2018-08-31 14:07:12 -0700 | [diff] [blame] | 82 | void addFanPID(std::unique_ptr<Controller> pid); |
| 83 | void addThermalPID(std::unique_ptr<Controller> pid); |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 84 | double getCachedValue(const std::string& name) override; |
Patrick Venture | c399f6f | 2018-10-30 19:24:47 -0700 | [diff] [blame] | 85 | void addFanInput(const std::string& fan); |
| 86 | void addThermalInput(const std::string& therm); |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 87 | |
Patrick Venture | 7a98c19 | 2020-08-12 08:35:16 -0700 | [diff] [blame] | 88 | void initializeLog(void) override; |
| 89 | void writeLog(const std::string& value) 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 | /* Method for setting the manual mode over dbus */ |
| 92 | bool manual(bool value) override; |
| 93 | /* Method for reading whether in fail-safe mode over dbus */ |
| 94 | bool failSafe() const override; |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 95 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 96 | private: |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 97 | std::ofstream _log; |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 98 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 99 | const int64_t _zoneId; |
Patrick Venture | f7a2dd5 | 2019-07-16 14:31:13 -0700 | [diff] [blame] | 100 | double _maximumSetPoint = 0; |
Nirav Shah | ccc8bb6 | 2022-02-17 21:06:51 -0800 | [diff] [blame] | 101 | std::string _maximumSetPointName; |
| 102 | std::string _maximumSetPointNamePrev; |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 103 | bool _manualMode = false; |
Josh Lehan | a4146eb | 2020-10-01 11:49:09 -0700 | [diff] [blame] | 104 | bool _redundantWrite = false; |
James Feist | 3484bed | 2019-02-25 13:28:18 -0800 | [diff] [blame] | 105 | const double _minThermalOutputSetPt; |
Patrick Venture | 5f59c0f | 2018-11-11 12:55:14 -0800 | [diff] [blame] | 106 | const double _failSafePercent; |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 107 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 108 | std::set<std::string> _failSafeSensors; |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 109 | |
Patrick Venture | 9bbf333 | 2019-07-16 10:50:37 -0700 | [diff] [blame] | 110 | std::vector<double> _SetPoints; |
James Feist | 608304d | 2019-02-25 10:01:42 -0800 | [diff] [blame] | 111 | std::vector<double> _RPMCeilings; |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 112 | std::vector<std::string> _fanInputs; |
| 113 | std::vector<std::string> _thermalInputs; |
| 114 | std::map<std::string, double> _cachedValuesByName; |
| 115 | const SensorManager& _mgr; |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 116 | |
James Feist | 22c257a | 2018-08-31 14:07:12 -0700 | [diff] [blame] | 117 | std::vector<std::unique_ptr<Controller>> _fans; |
| 118 | std::vector<std::unique_ptr<Controller>> _thermals; |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 119 | }; |
Patrick Venture | a076487 | 2020-08-08 07:48:43 -0700 | [diff] [blame] | 120 | |
| 121 | } // namespace pid_control |