blob: 12e47a6006299414c26aa3a8a46bdbb1e4696b34 [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>
Patrick Williamsb228bc32022-07-22 19:26:56 -050023using ServerObject = typename sdbusplus::server::object_t<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/*
Patrick Venture597ebd62020-08-11 08:48:19 -070031 * The DbusPidZone inherits from the Mode object so that it can listen for
32 * control mode changes. It primarily holds all PID loops and holds the sensor
33 * value cache that's used per iteration of the PID loops.
Patrick Ventured8012182018-03-08 08:21:38 -080034 */
Patrick Venture597ebd62020-08-11 08:48:19 -070035class DbusPidZone : public ZoneInterface, public ModeObject
Patrick Ventured8012182018-03-08 08:21:38 -080036{
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070037 public:
Patrick Venture597ebd62020-08-11 08:48:19 -070038 DbusPidZone(int64_t zone, double minThermalOutput, double failSafePercent,
Patrick Williamsb228bc32022-07-22 19:26:56 -050039 const SensorManager& mgr, sdbusplus::bus_t& bus,
Patrick Venture597ebd62020-08-11 08:48:19 -070040 const char* objPath, bool defer) :
Patrick Williamsd8c5a452022-04-07 16:08:56 -050041 ModeObject(bus, objPath,
42 defer ? ModeObject::action::defer_emit
43 : ModeObject::action::emit_object_added),
Patrick Venturef7a2dd52019-07-16 14:31:13 -070044 _zoneId(zone), _maximumSetPoint(),
James Feist3484bed2019-02-25 13:28:18 -080045 _minThermalOutputSetPt(minThermalOutput),
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070046 _failSafePercent(failSafePercent), _mgr(mgr)
47 {
Patrick Venturede79ee02019-05-08 14:50:00 -070048 if (loggingEnabled)
Patrick Venturec32e3fc2019-02-28 10:01:11 -080049 {
Patrick Venture89002db2019-05-08 15:02:55 -070050 _log.open(loggingPath + "/zone_" + std::to_string(zone) + ".log");
Patrick Venturec32e3fc2019-02-28 10:01:11 -080051 }
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070052 }
Patrick Ventured8012182018-03-08 08:21:38 -080053
Patrick Venture7a98c192020-08-12 08:35:16 -070054 bool getManualMode(void) const override;
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 */
Josh Lehana4146eb2020-10-01 11:49:09 -070058
59 bool getRedundantWrite(void) const override;
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070060 void setManualMode(bool mode);
61 bool getFailSafeMode(void) const override;
Patrick Venture7a98c192020-08-12 08:35:16 -070062
Patrick Venture0bbeaf82018-10-30 18:50:31 -070063 int64_t getZoneID(void) const;
Nirav Shahccc8bb62022-02-17 21:06:51 -080064 void addSetPoint(double setPoint, const std::string& name) override;
Patrick Venture7a98c192020-08-12 08:35:16 -070065 double getMaxSetPointRequest(void) const override;
James Feist608304d2019-02-25 10:01:42 -080066 void addRPMCeiling(double ceiling) override;
Patrick Venture7a98c192020-08-12 08:35:16 -070067 void clearSetPoints(void) override;
68 void clearRPMCeilings(void) override;
Patrick Venture5f59c0f2018-11-11 12:55:14 -080069 double getFailSafePercent(void) const override;
Nirav Shahccc8bb62022-02-17 21:06:51 -080070 double getMinThermalSetPoint(void) const;
Patrick Ventured8012182018-03-08 08:21:38 -080071
Patrick Venture2d8e7852018-10-30 19:14:07 -070072 Sensor* getSensor(const std::string& name) override;
Patrick Venture7a98c192020-08-12 08:35:16 -070073 void determineMaxSetPointRequest(void) override;
74 void updateFanTelemetry(void) override;
75 void updateSensors(void) override;
76 void initializeCache(void) override;
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070077 void dumpCache(void);
Josh Lehana4146eb2020-10-01 11:49:09 -070078
Patrick Venture7a98c192020-08-12 08:35:16 -070079 void processFans(void) override;
80 void processThermals(void) override;
Patrick Ventured8012182018-03-08 08:21:38 -080081
James Feist22c257a2018-08-31 14:07:12 -070082 void addFanPID(std::unique_ptr<Controller> pid);
83 void addThermalPID(std::unique_ptr<Controller> pid);
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070084 double getCachedValue(const std::string& name) override;
Patrick Venturec399f6f2018-10-30 19:24:47 -070085 void addFanInput(const std::string& fan);
86 void addThermalInput(const std::string& therm);
Patrick Ventured8012182018-03-08 08:21:38 -080087
Patrick Venture7a98c192020-08-12 08:35:16 -070088 void initializeLog(void) override;
89 void writeLog(const std::string& value) override;
Patrick Ventured8012182018-03-08 08:21:38 -080090
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070091 /* Method for setting the manual mode over dbus */
92 bool manual(bool value) override;
93 /* Method for reading whether in fail-safe mode over dbus */
94 bool failSafe() const override;
Patrick Ventured8012182018-03-08 08:21:38 -080095
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070096 private:
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070097 std::ofstream _log;
Patrick Ventured8012182018-03-08 08:21:38 -080098
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070099 const int64_t _zoneId;
Patrick Venturef7a2dd52019-07-16 14:31:13 -0700100 double _maximumSetPoint = 0;
Nirav Shahccc8bb62022-02-17 21:06:51 -0800101 std::string _maximumSetPointName;
102 std::string _maximumSetPointNamePrev;
Patrick Ventureda4a5dd2018-08-31 09:42:48 -0700103 bool _manualMode = false;
Josh Lehana4146eb2020-10-01 11:49:09 -0700104 bool _redundantWrite = false;
James Feist3484bed2019-02-25 13:28:18 -0800105 const double _minThermalOutputSetPt;
Patrick Venture5f59c0f2018-11-11 12:55:14 -0800106 const double _failSafePercent;
Patrick Ventured8012182018-03-08 08:21:38 -0800107
Patrick Ventureda4a5dd2018-08-31 09:42:48 -0700108 std::set<std::string> _failSafeSensors;
Patrick Ventured8012182018-03-08 08:21:38 -0800109
Patrick Venture9bbf3332019-07-16 10:50:37 -0700110 std::vector<double> _SetPoints;
James Feist608304d2019-02-25 10:01:42 -0800111 std::vector<double> _RPMCeilings;
Patrick Ventureda4a5dd2018-08-31 09:42:48 -0700112 std::vector<std::string> _fanInputs;
113 std::vector<std::string> _thermalInputs;
114 std::map<std::string, double> _cachedValuesByName;
115 const SensorManager& _mgr;
Patrick Ventured8012182018-03-08 08:21:38 -0800116
James Feist22c257a2018-08-31 14:07:12 -0700117 std::vector<std::unique_ptr<Controller>> _fans;
118 std::vector<std::unique_ptr<Controller>> _thermals;
Patrick Ventured8012182018-03-08 08:21:38 -0800119};
Patrick Venturea0764872020-08-08 07:48:43 -0700120
121} // namespace pid_control