1 #pragma once 2 3 #include "conf.hpp" 4 #include "controller.hpp" 5 #include "pidcontroller.hpp" 6 #include "sensors/manager.hpp" 7 #include "sensors/sensor.hpp" 8 9 #include <fstream> 10 #include <map> 11 #include <memory> 12 #include <sdbusplus/bus.hpp> 13 #include <sdbusplus/server.hpp> 14 #include <set> 15 #include <string> 16 #include <vector> 17 #include <xyz/openbmc_project/Control/Mode/server.hpp> 18 19 template <typename... T> 20 using ServerObject = typename sdbusplus::server::object::object<T...>; 21 using ModeInterface = sdbusplus::xyz::openbmc_project::Control::server::Mode; 22 using ModeObject = ServerObject<ModeInterface>; 23 24 class ZoneInterface 25 { 26 public: 27 virtual ~ZoneInterface() = default; 28 29 virtual double getCachedValue(const std::string& name) = 0; 30 virtual void addRPMSetPoint(double setpoint) = 0; 31 virtual void addRPMCeiling(double ceiling) = 0; 32 virtual double getMaxRPMRequest() const = 0; 33 virtual bool getFailSafeMode() const = 0; 34 virtual double getFailSafePercent() const = 0; 35 virtual Sensor* getSensor(const std::string& name) = 0; 36 }; 37 38 /* 39 * The PIDZone inherits from the Mode object so that it can listen for control 40 * mode changes. It primarily holds all PID loops and holds the sensor value 41 * cache that's used per iteration of the PID loops. 42 */ 43 class PIDZone : public ZoneInterface, public ModeObject 44 { 45 public: 46 PIDZone(int64_t zone, double minThermalRpm, double failSafePercent, 47 const SensorManager& mgr, sdbusplus::bus::bus& bus, 48 const char* objPath, bool defer) : 49 ModeObject(bus, objPath, defer), 50 _zoneId(zone), _maximumRPMSetPt(), _minThermalRpmSetPt(minThermalRpm), 51 _failSafePercent(failSafePercent), _mgr(mgr) 52 { 53 #ifdef __TUNING_LOGGING__ 54 _log.open("/tmp/swampd.log"); 55 #endif 56 } 57 58 double getMaxRPMRequest(void) const override; 59 bool getManualMode(void) const; 60 61 /* Could put lock around this since it's accessed from two threads, but 62 * only one reader/one writer. 63 */ 64 void setManualMode(bool mode); 65 bool getFailSafeMode(void) const override; 66 int64_t getZoneID(void) const; 67 void addRPMSetPoint(double setpoint) override; 68 void addRPMCeiling(double ceiling) override; 69 void clearRPMSetPoints(void); 70 void clearRPMCeilings(void); 71 double getFailSafePercent(void) const override; 72 double getMinThermalRPMSetpoint(void) const; 73 74 Sensor* getSensor(const std::string& name) override; 75 void determineMaxRPMRequest(void); 76 void updateFanTelemetry(void); 77 void updateSensors(void); 78 void initializeCache(void); 79 void dumpCache(void); 80 void processFans(void); 81 void processThermals(void); 82 83 void addFanPID(std::unique_ptr<Controller> pid); 84 void addThermalPID(std::unique_ptr<Controller> pid); 85 double getCachedValue(const std::string& name) override; 86 void addFanInput(const std::string& fan); 87 void addThermalInput(const std::string& therm); 88 89 #ifdef __TUNING_LOGGING__ 90 void initializeLog(void); 91 std::ofstream& getLogHandle(void); 92 #endif 93 94 /* Method for setting the manual mode over dbus */ 95 bool manual(bool value) override; 96 /* Method for reading whether in fail-safe mode over dbus */ 97 bool failSafe() const override; 98 99 private: 100 #ifdef __TUNING_LOGGING__ 101 std::ofstream _log; 102 #endif 103 104 const int64_t _zoneId; 105 double _maximumRPMSetPt = 0; 106 bool _manualMode = false; 107 const double _minThermalRpmSetPt; 108 const double _failSafePercent; 109 110 std::set<std::string> _failSafeSensors; 111 112 std::vector<double> _RPMSetPoints; 113 std::vector<double> _RPMCeilings; 114 std::vector<std::string> _fanInputs; 115 std::vector<std::string> _thermalInputs; 116 std::map<std::string, double> _cachedValuesByName; 117 const SensorManager& _mgr; 118 119 std::vector<std::unique_ptr<Controller>> _fans; 120 std::vector<std::unique_ptr<Controller>> _thermals; 121 }; 122