Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <fstream> |
| 4 | #include <map> |
| 5 | #include <memory> |
| 6 | #include <set> |
| 7 | #include <string> |
| 8 | #include <vector> |
| 9 | |
| 10 | #include "conf.hpp" |
| 11 | #include "controller.hpp" |
| 12 | #include "sensors/sensor.hpp" |
| 13 | #include "sensors/manager.hpp" |
| 14 | |
Patrick Venture | dc3b790 | 2018-03-24 10:41:19 -0700 | [diff] [blame] | 15 | #include "xyz/openbmc_project/Control/Mode/server.hpp" |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 16 | #include <sdbusplus/bus.hpp> |
| 17 | #include <sdbusplus/server.hpp> |
| 18 | |
| 19 | |
| 20 | template <typename... T> |
| 21 | using ServerObject = typename sdbusplus::server::object::object<T...>; |
| 22 | using ModeInterface = |
Patrick Venture | dc3b790 | 2018-03-24 10:41:19 -0700 | [diff] [blame] | 23 | 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 | { |
| 28 | public: |
| 29 | virtual ~ZoneInterface() = default; |
| 30 | |
| 31 | virtual double getCachedValue(const std::string& name) = 0; |
| 32 | virtual void addRPMSetPoint(float setpoint) = 0; |
| 33 | virtual float getMaxRPMRequest() const = 0; |
| 34 | virtual bool getFailSafeMode() const = 0; |
| 35 | virtual float getFailSafePercent() const = 0; |
| 36 | virtual Sensor* getSensor(std::string name) = 0; |
| 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 | { |
| 46 | public: |
| 47 | PIDZone(int64_t zone, |
| 48 | float minThermalRpm, |
| 49 | float failSafePercent, |
Patrick Venture | fe75b19 | 2018-06-08 11:19:43 -0700 | [diff] [blame] | 50 | const SensorManager& mgr, |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 51 | sdbusplus::bus::bus& bus, |
| 52 | const char* objPath, |
| 53 | bool defer) |
| 54 | : ModeObject(bus, objPath, defer), |
| 55 | _zoneId(zone), |
| 56 | _maximumRPMSetPt(), |
| 57 | _minThermalRpmSetPt(minThermalRpm), |
| 58 | _failSafePercent(failSafePercent), |
| 59 | _mgr(mgr) |
| 60 | { |
| 61 | #ifdef __TUNING_LOGGING__ |
| 62 | _log.open("/tmp/swampd.log"); |
| 63 | #endif |
| 64 | } |
| 65 | |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 66 | float getMaxRPMRequest(void) const override; |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 67 | bool getManualMode(void) const; |
| 68 | |
| 69 | /* Could put lock around this since it's accessed from two threads, but |
| 70 | * only one reader/one writer. |
| 71 | */ |
| 72 | void setManualMode(bool mode); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 73 | bool getFailSafeMode(void) const override; |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 74 | int64_t getZoneId(void) const; |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 75 | void addRPMSetPoint(float setpoint) override; |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 76 | void clearRPMSetPoints(void); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 77 | float getFailSafePercent(void) const override; |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 78 | float getMinThermalRpmSetPt(void) const; |
| 79 | |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 80 | Sensor* getSensor(std::string name) override; |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 81 | void determineMaxRPMRequest(void); |
| 82 | void updateFanTelemetry(void); |
| 83 | void updateSensors(void); |
| 84 | void initializeCache(void); |
| 85 | void dumpCache(void); |
| 86 | void process_fans(void); |
| 87 | void process_thermals(void); |
| 88 | |
| 89 | void addFanPID(std::unique_ptr<PIDController> pid); |
| 90 | void addThermalPID(std::unique_ptr<PIDController> pid); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 91 | double getCachedValue(const std::string& name) override; |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 92 | void addFanInput(std::string fan); |
| 93 | void addThermalInput(std::string therm); |
| 94 | |
| 95 | #ifdef __TUNING_LOGGING__ |
| 96 | void initializeLog(void); |
| 97 | std::ofstream& getLogHandle(void); |
| 98 | #endif |
| 99 | |
| 100 | /* Method for setting the manual mode over dbus */ |
| 101 | bool manual(bool value) override; |
| 102 | /* Method for reading whether in fail-safe mode over dbus */ |
| 103 | bool failSafe() const override; |
| 104 | |
| 105 | private: |
| 106 | #ifdef __TUNING_LOGGING__ |
| 107 | std::ofstream _log; |
| 108 | #endif |
| 109 | |
| 110 | const int64_t _zoneId; |
| 111 | float _maximumRPMSetPt = 0; |
| 112 | bool _manualMode = false; |
| 113 | const float _minThermalRpmSetPt; |
| 114 | const float _failSafePercent; |
| 115 | |
| 116 | std::set<std::string> _failSafeSensors; |
| 117 | |
| 118 | std::vector<float> _RPMSetPoints; |
| 119 | std::vector<std::string> _fanInputs; |
| 120 | std::vector<std::string> _thermalInputs; |
| 121 | std::map<std::string, double> _cachedValuesByName; |
Patrick Venture | fe75b19 | 2018-06-08 11:19:43 -0700 | [diff] [blame] | 122 | const SensorManager& _mgr; |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 123 | |
| 124 | std::vector<std::unique_ptr<PIDController>> _fans; |
| 125 | std::vector<std::unique_ptr<PIDController>> _thermals; |
| 126 | }; |