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