blob: dd90fc5c1e6de55e4e716c80f86df01a10bb83a5 [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 Venture1a153792020-08-11 08:41:47 -07009#include "zone_interface.hpp"
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070010
Patrick Venturea83a3ec2020-08-04 09:52:05 -070011#include <sdbusplus/bus.hpp>
12#include <sdbusplus/server.hpp>
13#include <xyz/openbmc_project/Control/Mode/server.hpp>
14
Patrick Ventured8012182018-03-08 08:21:38 -080015#include <fstream>
16#include <map>
17#include <memory>
18#include <set>
19#include <string>
20#include <vector>
21
Patrick Ventured8012182018-03-08 08:21:38 -080022template <typename... T>
23using ServerObject = typename sdbusplus::server::object::object<T...>;
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070024using ModeInterface = sdbusplus::xyz::openbmc_project::Control::server::Mode;
Patrick Ventured8012182018-03-08 08:21:38 -080025using ModeObject = ServerObject<ModeInterface>;
26
Patrick Venturea0764872020-08-08 07:48:43 -070027namespace pid_control
28{
29
Patrick Ventured8012182018-03-08 08:21:38 -080030/*
31 * The PIDZone inherits from the Mode object so that it can listen for control
32 * mode changes. It primarily holds all PID loops and holds the sensor value
33 * cache that's used per iteration of the PID loops.
34 */
Patrick Venturea58197c2018-06-11 15:29:45 -070035class PIDZone : public ZoneInterface, public ModeObject
Patrick Ventured8012182018-03-08 08:21:38 -080036{
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070037 public:
James Feist3484bed2019-02-25 13:28:18 -080038 PIDZone(int64_t zone, double minThermalOutput, double failSafePercent,
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070039 const SensorManager& mgr, sdbusplus::bus::bus& bus,
40 const char* objPath, bool defer) :
41 ModeObject(bus, objPath, defer),
Patrick Venturef7a2dd52019-07-16 14:31:13 -070042 _zoneId(zone), _maximumSetPoint(),
James Feist3484bed2019-02-25 13:28:18 -080043 _minThermalOutputSetPt(minThermalOutput),
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070044 _failSafePercent(failSafePercent), _mgr(mgr)
45 {
Patrick Venturede79ee02019-05-08 14:50:00 -070046 if (loggingEnabled)
Patrick Venturec32e3fc2019-02-28 10:01:11 -080047 {
Patrick Venture89002db2019-05-08 15:02:55 -070048 _log.open(loggingPath + "/zone_" + std::to_string(zone) + ".log");
Patrick Venturec32e3fc2019-02-28 10:01:11 -080049 }
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070050 }
Patrick Ventured8012182018-03-08 08:21:38 -080051
Patrick Venturef7a2dd52019-07-16 14:31:13 -070052 double getMaxSetPointRequest(void) const override;
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070053 bool getManualMode(void) const;
Patrick Ventured8012182018-03-08 08:21:38 -080054
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070055 /* Could put lock around this since it's accessed from two threads, but
56 * only one reader/one writer.
57 */
58 void setManualMode(bool mode);
59 bool getFailSafeMode(void) const override;
Patrick Venture0bbeaf82018-10-30 18:50:31 -070060 int64_t getZoneID(void) const;
Patrick Venture9bbf3332019-07-16 10:50:37 -070061 void addSetPoint(double setpoint) override;
James Feist608304d2019-02-25 10:01:42 -080062 void addRPMCeiling(double ceiling) override;
Patrick Venture9bbf3332019-07-16 10:50:37 -070063 void clearSetPoints(void);
James Feist608304d2019-02-25 10:01:42 -080064 void clearRPMCeilings(void);
Patrick Venture5f59c0f2018-11-11 12:55:14 -080065 double getFailSafePercent(void) const override;
Patrick Venturef7a2dd52019-07-16 14:31:13 -070066 double getMinThermalSetpoint(void) const;
Patrick Ventured8012182018-03-08 08:21:38 -080067
Patrick Venture2d8e7852018-10-30 19:14:07 -070068 Sensor* getSensor(const std::string& name) override;
Patrick Venturef7a2dd52019-07-16 14:31:13 -070069 void determineMaxSetPointRequest(void);
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070070 void updateFanTelemetry(void);
71 void updateSensors(void);
72 void initializeCache(void);
73 void dumpCache(void);
Patrick Venture563a3562018-10-30 09:31:26 -070074 void processFans(void);
75 void processThermals(void);
Patrick Ventured8012182018-03-08 08:21:38 -080076
James Feist22c257a2018-08-31 14:07:12 -070077 void addFanPID(std::unique_ptr<Controller> pid);
78 void addThermalPID(std::unique_ptr<Controller> pid);
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070079 double getCachedValue(const std::string& name) override;
Patrick Venturec399f6f2018-10-30 19:24:47 -070080 void addFanInput(const std::string& fan);
81 void addThermalInput(const std::string& therm);
Patrick Ventured8012182018-03-08 08:21:38 -080082
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070083 void initializeLog(void);
84 std::ofstream& getLogHandle(void);
Patrick Ventured8012182018-03-08 08:21:38 -080085
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070086 /* Method for setting the manual mode over dbus */
87 bool manual(bool value) override;
88 /* Method for reading whether in fail-safe mode over dbus */
89 bool failSafe() const override;
Patrick Ventured8012182018-03-08 08:21:38 -080090
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070091 private:
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070092 std::ofstream _log;
Patrick Ventured8012182018-03-08 08:21:38 -080093
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070094 const int64_t _zoneId;
Patrick Venturef7a2dd52019-07-16 14:31:13 -070095 double _maximumSetPoint = 0;
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070096 bool _manualMode = false;
James Feist3484bed2019-02-25 13:28:18 -080097 const double _minThermalOutputSetPt;
Patrick Venture5f59c0f2018-11-11 12:55:14 -080098 const double _failSafePercent;
Patrick Ventured8012182018-03-08 08:21:38 -080099
Patrick Ventureda4a5dd2018-08-31 09:42:48 -0700100 std::set<std::string> _failSafeSensors;
Patrick Ventured8012182018-03-08 08:21:38 -0800101
Patrick Venture9bbf3332019-07-16 10:50:37 -0700102 std::vector<double> _SetPoints;
James Feist608304d2019-02-25 10:01:42 -0800103 std::vector<double> _RPMCeilings;
Patrick Ventureda4a5dd2018-08-31 09:42:48 -0700104 std::vector<std::string> _fanInputs;
105 std::vector<std::string> _thermalInputs;
106 std::map<std::string, double> _cachedValuesByName;
107 const SensorManager& _mgr;
Patrick Ventured8012182018-03-08 08:21:38 -0800108
James Feist22c257a2018-08-31 14:07:12 -0700109 std::vector<std::unique_ptr<Controller>> _fans;
110 std::vector<std::unique_ptr<Controller>> _thermals;
Patrick Ventured8012182018-03-08 08:21:38 -0800111};
Patrick Venturea0764872020-08-08 07:48:43 -0700112
113} // namespace pid_control