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