blob: 99a8f148e3f3b7e3e9a10a569821619ce3fa8af4 [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"
5#include "sensors/manager.hpp"
6#include "sensors/sensor.hpp"
7#include "xyz/openbmc_project/Control/Mode/server.hpp"
8
Patrick Ventured8012182018-03-08 08:21:38 -08009#include <fstream>
10#include <map>
11#include <memory>
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070012#include <sdbusplus/bus.hpp>
13#include <sdbusplus/server.hpp>
Patrick Ventured8012182018-03-08 08:21:38 -080014#include <set>
15#include <string>
16#include <vector>
17
Patrick Ventured8012182018-03-08 08:21:38 -080018template <typename... T>
19using ServerObject = typename sdbusplus::server::object::object<T...>;
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070020using ModeInterface = sdbusplus::xyz::openbmc_project::Control::server::Mode;
Patrick Ventured8012182018-03-08 08:21:38 -080021using ModeObject = ServerObject<ModeInterface>;
22
Patrick Venturea58197c2018-06-11 15:29:45 -070023class ZoneInterface
24{
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070025 public:
26 virtual ~ZoneInterface() = default;
Patrick Venturea58197c2018-06-11 15:29:45 -070027
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070028 virtual double getCachedValue(const std::string& name) = 0;
29 virtual void addRPMSetPoint(float setpoint) = 0;
30 virtual float getMaxRPMRequest() const = 0;
31 virtual bool getFailSafeMode() const = 0;
32 virtual float getFailSafePercent() const = 0;
33 virtual Sensor* getSensor(std::string name) = 0;
Patrick Venturea58197c2018-06-11 15:29:45 -070034};
35
Patrick Ventured8012182018-03-08 08:21:38 -080036/*
37 * The PIDZone inherits from the Mode object so that it can listen for control
38 * mode changes. It primarily holds all PID loops and holds the sensor value
39 * cache that's used per iteration of the PID loops.
40 */
Patrick Venturea58197c2018-06-11 15:29:45 -070041class PIDZone : public ZoneInterface, public ModeObject
Patrick Ventured8012182018-03-08 08:21:38 -080042{
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070043 public:
44 PIDZone(int64_t zone, float minThermalRpm, float failSafePercent,
45 const SensorManager& mgr, sdbusplus::bus::bus& bus,
46 const char* objPath, bool defer) :
47 ModeObject(bus, objPath, defer),
48 _zoneId(zone), _maximumRPMSetPt(), _minThermalRpmSetPt(minThermalRpm),
49 _failSafePercent(failSafePercent), _mgr(mgr)
50 {
Patrick Ventured8012182018-03-08 08:21:38 -080051#ifdef __TUNING_LOGGING__
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070052 _log.open("/tmp/swampd.log");
Patrick Ventured8012182018-03-08 08:21:38 -080053#endif
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070054 }
Patrick Ventured8012182018-03-08 08:21:38 -080055
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070056 float getMaxRPMRequest(void) const override;
57 bool getManualMode(void) const;
Patrick Ventured8012182018-03-08 08:21:38 -080058
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070059 /* Could put lock around this since it's accessed from two threads, but
60 * only one reader/one writer.
61 */
62 void setManualMode(bool mode);
63 bool getFailSafeMode(void) const override;
64 int64_t getZoneId(void) const;
65 void addRPMSetPoint(float setpoint) override;
66 void clearRPMSetPoints(void);
67 float getFailSafePercent(void) const override;
68 float getMinThermalRpmSetPt(void) const;
Patrick Ventured8012182018-03-08 08:21:38 -080069
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070070 Sensor* getSensor(std::string name) override;
71 void determineMaxRPMRequest(void);
72 void updateFanTelemetry(void);
73 void updateSensors(void);
74 void initializeCache(void);
75 void dumpCache(void);
76 void process_fans(void);
77 void process_thermals(void);
Patrick Ventured8012182018-03-08 08:21:38 -080078
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070079 void addFanPID(std::unique_ptr<PIDController> pid);
80 void addThermalPID(std::unique_ptr<PIDController> pid);
81 double getCachedValue(const std::string& name) override;
82 void addFanInput(std::string fan);
83 void addThermalInput(std::string therm);
Patrick Ventured8012182018-03-08 08:21:38 -080084
85#ifdef __TUNING_LOGGING__
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070086 void initializeLog(void);
87 std::ofstream& getLogHandle(void);
Patrick Ventured8012182018-03-08 08:21:38 -080088#endif
89
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070090 /* Method for setting the manual mode over dbus */
91 bool manual(bool value) override;
92 /* Method for reading whether in fail-safe mode over dbus */
93 bool failSafe() const override;
Patrick Ventured8012182018-03-08 08:21:38 -080094
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070095 private:
Patrick Ventured8012182018-03-08 08:21:38 -080096#ifdef __TUNING_LOGGING__
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070097 std::ofstream _log;
Patrick Ventured8012182018-03-08 08:21:38 -080098#endif
99
Patrick Ventureda4a5dd2018-08-31 09:42:48 -0700100 const int64_t _zoneId;
101 float _maximumRPMSetPt = 0;
102 bool _manualMode = false;
103 const float _minThermalRpmSetPt;
104 const float _failSafePercent;
Patrick Ventured8012182018-03-08 08:21:38 -0800105
Patrick Ventureda4a5dd2018-08-31 09:42:48 -0700106 std::set<std::string> _failSafeSensors;
Patrick Ventured8012182018-03-08 08:21:38 -0800107
Patrick Ventureda4a5dd2018-08-31 09:42:48 -0700108 std::vector<float> _RPMSetPoints;
109 std::vector<std::string> _fanInputs;
110 std::vector<std::string> _thermalInputs;
111 std::map<std::string, double> _cachedValuesByName;
112 const SensorManager& _mgr;
Patrick Ventured8012182018-03-08 08:21:38 -0800113
Patrick Ventureda4a5dd2018-08-31 09:42:48 -0700114 std::vector<std::unique_ptr<PIDController>> _fans;
115 std::vector<std::unique_ptr<PIDController>> _thermals;
Patrick Ventured8012182018-03-08 08:21:38 -0800116};