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