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