blob: dc2ceb82305c97211fa07e88ab6e944c3af190d9 [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 Venturea83a3ec2020-08-04 09:52:05 -070010#include <sdbusplus/bus.hpp>
11#include <sdbusplus/server.hpp>
12#include <xyz/openbmc_project/Control/Mode/server.hpp>
13
Patrick Ventured8012182018-03-08 08:21:38 -080014#include <fstream>
15#include <map>
16#include <memory>
17#include <set>
18#include <string>
19#include <vector>
20
Patrick Ventured8012182018-03-08 08:21:38 -080021template <typename... T>
22using ServerObject = typename sdbusplus::server::object::object<T...>;
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070023using ModeInterface = sdbusplus::xyz::openbmc_project::Control::server::Mode;
Patrick Ventured8012182018-03-08 08:21:38 -080024using ModeObject = ServerObject<ModeInterface>;
25
Patrick Venturea58197c2018-06-11 15:29:45 -070026class ZoneInterface
27{
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070028 public:
29 virtual ~ZoneInterface() = default;
Patrick Venturea58197c2018-06-11 15:29:45 -070030
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070031 virtual double getCachedValue(const std::string& name) = 0;
Patrick Venture9bbf3332019-07-16 10:50:37 -070032 virtual void addSetPoint(double setpoint) = 0;
James Feist608304d2019-02-25 10:01:42 -080033 virtual void addRPMCeiling(double ceiling) = 0;
Patrick Venturef7a2dd52019-07-16 14:31:13 -070034 virtual double getMaxSetPointRequest() const = 0;
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070035 virtual bool getFailSafeMode() const = 0;
Patrick Venture5f59c0f2018-11-11 12:55:14 -080036 virtual double getFailSafePercent() const = 0;
Patrick Venture2d8e7852018-10-30 19:14:07 -070037 virtual Sensor* getSensor(const std::string& name) = 0;
Patrick Venturea58197c2018-06-11 15:29:45 -070038};
39
Patrick Ventured8012182018-03-08 08:21:38 -080040/*
41 * The PIDZone inherits from the Mode object so that it can listen for control
42 * mode changes. It primarily holds all PID loops and holds the sensor value
43 * cache that's used per iteration of the PID loops.
44 */
Patrick Venturea58197c2018-06-11 15:29:45 -070045class PIDZone : public ZoneInterface, public ModeObject
Patrick Ventured8012182018-03-08 08:21:38 -080046{
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070047 public:
James Feist3484bed2019-02-25 13:28:18 -080048 PIDZone(int64_t zone, double minThermalOutput, double failSafePercent,
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070049 const SensorManager& mgr, sdbusplus::bus::bus& bus,
50 const char* objPath, bool defer) :
51 ModeObject(bus, objPath, defer),
Patrick Venturef7a2dd52019-07-16 14:31:13 -070052 _zoneId(zone), _maximumSetPoint(),
James Feist3484bed2019-02-25 13:28:18 -080053 _minThermalOutputSetPt(minThermalOutput),
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070054 _failSafePercent(failSafePercent), _mgr(mgr)
55 {
Patrick Venturede79ee02019-05-08 14:50:00 -070056 if (loggingEnabled)
Patrick Venturec32e3fc2019-02-28 10:01:11 -080057 {
Patrick Venture89002db2019-05-08 15:02:55 -070058 _log.open(loggingPath + "/zone_" + std::to_string(zone) + ".log");
Patrick Venturec32e3fc2019-02-28 10:01:11 -080059 }
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070060 }
Patrick Ventured8012182018-03-08 08:21:38 -080061
Patrick Venturef7a2dd52019-07-16 14:31:13 -070062 double getMaxSetPointRequest(void) const override;
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070063 bool getManualMode(void) const;
Patrick Ventured8012182018-03-08 08:21:38 -080064
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070065 /* Could put lock around this since it's accessed from two threads, but
66 * only one reader/one writer.
67 */
68 void setManualMode(bool mode);
69 bool getFailSafeMode(void) const override;
Patrick Venture0bbeaf82018-10-30 18:50:31 -070070 int64_t getZoneID(void) const;
Patrick Venture9bbf3332019-07-16 10:50:37 -070071 void addSetPoint(double setpoint) override;
James Feist608304d2019-02-25 10:01:42 -080072 void addRPMCeiling(double ceiling) override;
Patrick Venture9bbf3332019-07-16 10:50:37 -070073 void clearSetPoints(void);
James Feist608304d2019-02-25 10:01:42 -080074 void clearRPMCeilings(void);
Patrick Venture5f59c0f2018-11-11 12:55:14 -080075 double getFailSafePercent(void) const override;
Patrick Venturef7a2dd52019-07-16 14:31:13 -070076 double getMinThermalSetpoint(void) const;
Patrick Ventured8012182018-03-08 08:21:38 -080077
Patrick Venture2d8e7852018-10-30 19:14:07 -070078 Sensor* getSensor(const std::string& name) override;
Patrick Venturef7a2dd52019-07-16 14:31:13 -070079 void determineMaxSetPointRequest(void);
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070080 void updateFanTelemetry(void);
81 void updateSensors(void);
82 void initializeCache(void);
83 void dumpCache(void);
Patrick Venture563a3562018-10-30 09:31:26 -070084 void processFans(void);
85 void processThermals(void);
Patrick Ventured8012182018-03-08 08:21:38 -080086
James Feist22c257a2018-08-31 14:07:12 -070087 void addFanPID(std::unique_ptr<Controller> pid);
88 void addThermalPID(std::unique_ptr<Controller> pid);
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070089 double getCachedValue(const std::string& name) override;
Patrick Venturec399f6f2018-10-30 19:24:47 -070090 void addFanInput(const std::string& fan);
91 void addThermalInput(const std::string& therm);
Patrick Ventured8012182018-03-08 08:21:38 -080092
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070093 void initializeLog(void);
94 std::ofstream& getLogHandle(void);
Patrick Ventured8012182018-03-08 08:21:38 -080095
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070096 /* Method for setting the manual mode over dbus */
97 bool manual(bool value) override;
98 /* Method for reading whether in fail-safe mode over dbus */
99 bool failSafe() const override;
Patrick Ventured8012182018-03-08 08:21:38 -0800100
Patrick Ventureda4a5dd2018-08-31 09:42:48 -0700101 private:
Patrick Ventureda4a5dd2018-08-31 09:42:48 -0700102 std::ofstream _log;
Patrick Ventured8012182018-03-08 08:21:38 -0800103
Patrick Ventureda4a5dd2018-08-31 09:42:48 -0700104 const int64_t _zoneId;
Patrick Venturef7a2dd52019-07-16 14:31:13 -0700105 double _maximumSetPoint = 0;
Patrick Ventureda4a5dd2018-08-31 09:42:48 -0700106 bool _manualMode = false;
James Feist3484bed2019-02-25 13:28:18 -0800107 const double _minThermalOutputSetPt;
Patrick Venture5f59c0f2018-11-11 12:55:14 -0800108 const double _failSafePercent;
Patrick Ventured8012182018-03-08 08:21:38 -0800109
Patrick Ventureda4a5dd2018-08-31 09:42:48 -0700110 std::set<std::string> _failSafeSensors;
Patrick Ventured8012182018-03-08 08:21:38 -0800111
Patrick Venture9bbf3332019-07-16 10:50:37 -0700112 std::vector<double> _SetPoints;
James Feist608304d2019-02-25 10:01:42 -0800113 std::vector<double> _RPMCeilings;
Patrick Ventureda4a5dd2018-08-31 09:42:48 -0700114 std::vector<std::string> _fanInputs;
115 std::vector<std::string> _thermalInputs;
116 std::map<std::string, double> _cachedValuesByName;
117 const SensorManager& _mgr;
Patrick Ventured8012182018-03-08 08:21:38 -0800118
James Feist22c257a2018-08-31 14:07:12 -0700119 std::vector<std::unique_ptr<Controller>> _fans;
120 std::vector<std::unique_ptr<Controller>> _thermals;
Patrick Ventured8012182018-03-08 08:21:38 -0800121};