blob: 53139ec468dabd09bd1425ff894163c80e769a5a [file] [log] [blame]
Patrick Ventured8012182018-03-08 08:21:38 -08001#pragma once
2
Patrick Ventureda4a5dd2018-08-31 09:42:48 -07003#include "conf.hpp"
4#include "controller.hpp"
James Feist22c257a2018-08-31 14:07:12 -07005#include "pidcontroller.hpp"
Patrick Ventureda4a5dd2018-08-31 09:42:48 -07006#include "sensors/manager.hpp"
7#include "sensors/sensor.hpp"
Patrick Venturec32e3fc2019-02-28 10:01:11 -08008#include "tuning.hpp"
Patrick Ventureda4a5dd2018-08-31 09:42:48 -07009
Patrick Ventured8012182018-03-08 08:21:38 -080010#include <fstream>
11#include <map>
12#include <memory>
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070013#include <sdbusplus/bus.hpp>
14#include <sdbusplus/server.hpp>
Patrick Ventured8012182018-03-08 08:21:38 -080015#include <set>
16#include <string>
17#include <vector>
Patrick Venture1248b152018-10-30 19:09:54 -070018#include <xyz/openbmc_project/Control/Mode/server.hpp>
Patrick Ventured8012182018-03-08 08:21:38 -080019
Patrick Ventured8012182018-03-08 08:21:38 -080020template <typename... T>
21using ServerObject = typename sdbusplus::server::object::object<T...>;
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070022using ModeInterface = sdbusplus::xyz::openbmc_project::Control::server::Mode;
Patrick Ventured8012182018-03-08 08:21:38 -080023using ModeObject = ServerObject<ModeInterface>;
24
Patrick Venturea58197c2018-06-11 15:29:45 -070025class ZoneInterface
26{
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070027 public:
28 virtual ~ZoneInterface() = default;
Patrick Venturea58197c2018-06-11 15:29:45 -070029
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070030 virtual double getCachedValue(const std::string& name) = 0;
Patrick Venture5f59c0f2018-11-11 12:55:14 -080031 virtual void addRPMSetPoint(double setpoint) = 0;
James Feist608304d2019-02-25 10:01:42 -080032 virtual void addRPMCeiling(double ceiling) = 0;
Patrick Venture5f59c0f2018-11-11 12:55:14 -080033 virtual double getMaxRPMRequest() const = 0;
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070034 virtual bool getFailSafeMode() const = 0;
Patrick Venture5f59c0f2018-11-11 12:55:14 -080035 virtual double getFailSafePercent() const = 0;
Patrick Venture2d8e7852018-10-30 19:14:07 -070036 virtual Sensor* getSensor(const std::string& name) = 0;
Patrick Venturea58197c2018-06-11 15:29:45 -070037};
38
Patrick Ventured8012182018-03-08 08:21:38 -080039/*
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 Venturea58197c2018-06-11 15:29:45 -070044class PIDZone : public ZoneInterface, public ModeObject
Patrick Ventured8012182018-03-08 08:21:38 -080045{
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070046 public:
James Feist3484bed2019-02-25 13:28:18 -080047 PIDZone(int64_t zone, double minThermalOutput, double failSafePercent,
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070048 const SensorManager& mgr, sdbusplus::bus::bus& bus,
49 const char* objPath, bool defer) :
50 ModeObject(bus, objPath, defer),
James Feist3484bed2019-02-25 13:28:18 -080051 _zoneId(zone), _maximumRPMSetPt(),
52 _minThermalOutputSetPt(minThermalOutput),
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070053 _failSafePercent(failSafePercent), _mgr(mgr)
54 {
Patrick Venturede79ee02019-05-08 14:50:00 -070055 if (loggingEnabled)
Patrick Venturec32e3fc2019-02-28 10:01:11 -080056 {
Patrick Venture89002db2019-05-08 15:02:55 -070057 _log.open(loggingPath + "/zone_" + std::to_string(zone) + ".log");
Patrick Venturec32e3fc2019-02-28 10:01:11 -080058 }
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070059 }
Patrick Ventured8012182018-03-08 08:21:38 -080060
Patrick Venture5f59c0f2018-11-11 12:55:14 -080061 double getMaxRPMRequest(void) const override;
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070062 bool getManualMode(void) const;
Patrick Ventured8012182018-03-08 08:21:38 -080063
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070064 /* 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 Venture0bbeaf82018-10-30 18:50:31 -070069 int64_t getZoneID(void) const;
Patrick Venture5f59c0f2018-11-11 12:55:14 -080070 void addRPMSetPoint(double setpoint) override;
James Feist608304d2019-02-25 10:01:42 -080071 void addRPMCeiling(double ceiling) override;
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070072 void clearRPMSetPoints(void);
James Feist608304d2019-02-25 10:01:42 -080073 void clearRPMCeilings(void);
Patrick Venture5f59c0f2018-11-11 12:55:14 -080074 double getFailSafePercent(void) const override;
75 double getMinThermalRPMSetpoint(void) const;
Patrick Ventured8012182018-03-08 08:21:38 -080076
Patrick Venture2d8e7852018-10-30 19:14:07 -070077 Sensor* getSensor(const std::string& name) override;
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070078 void determineMaxRPMRequest(void);
79 void updateFanTelemetry(void);
80 void updateSensors(void);
81 void initializeCache(void);
82 void dumpCache(void);
Patrick Venture563a3562018-10-30 09:31:26 -070083 void processFans(void);
84 void processThermals(void);
Patrick Ventured8012182018-03-08 08:21:38 -080085
James Feist22c257a2018-08-31 14:07:12 -070086 void addFanPID(std::unique_ptr<Controller> pid);
87 void addThermalPID(std::unique_ptr<Controller> pid);
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070088 double getCachedValue(const std::string& name) override;
Patrick Venturec399f6f2018-10-30 19:24:47 -070089 void addFanInput(const std::string& fan);
90 void addThermalInput(const std::string& therm);
Patrick Ventured8012182018-03-08 08:21:38 -080091
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070092 void initializeLog(void);
93 std::ofstream& getLogHandle(void);
Patrick Ventured8012182018-03-08 08:21:38 -080094
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070095 /* 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 Ventured8012182018-03-08 08:21:38 -080099
Patrick Ventureda4a5dd2018-08-31 09:42:48 -0700100 private:
Patrick Ventureda4a5dd2018-08-31 09:42:48 -0700101 std::ofstream _log;
Patrick Ventured8012182018-03-08 08:21:38 -0800102
Patrick Ventureda4a5dd2018-08-31 09:42:48 -0700103 const int64_t _zoneId;
Patrick Venture5f59c0f2018-11-11 12:55:14 -0800104 double _maximumRPMSetPt = 0;
Patrick Ventureda4a5dd2018-08-31 09:42:48 -0700105 bool _manualMode = false;
James Feist3484bed2019-02-25 13:28:18 -0800106 const double _minThermalOutputSetPt;
Patrick Venture5f59c0f2018-11-11 12:55:14 -0800107 const double _failSafePercent;
Patrick Ventured8012182018-03-08 08:21:38 -0800108
Patrick Ventureda4a5dd2018-08-31 09:42:48 -0700109 std::set<std::string> _failSafeSensors;
Patrick Ventured8012182018-03-08 08:21:38 -0800110
Patrick Venture5f59c0f2018-11-11 12:55:14 -0800111 std::vector<double> _RPMSetPoints;
James Feist608304d2019-02-25 10:01:42 -0800112 std::vector<double> _RPMCeilings;
Patrick Ventureda4a5dd2018-08-31 09:42:48 -0700113 std::vector<std::string> _fanInputs;
114 std::vector<std::string> _thermalInputs;
115 std::map<std::string, double> _cachedValuesByName;
116 const SensorManager& _mgr;
Patrick Ventured8012182018-03-08 08:21:38 -0800117
James Feist22c257a2018-08-31 14:07:12 -0700118 std::vector<std::unique_ptr<Controller>> _fans;
119 std::vector<std::unique_ptr<Controller>> _thermals;
Patrick Ventured8012182018-03-08 08:21:38 -0800120};