blob: 6d5f6cca78655baa5aa75b12ec0c63c45fea2f2e [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"
8#include "xyz/openbmc_project/Control/Mode/server.hpp"
9
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>
18
Patrick Ventured8012182018-03-08 08:21:38 -080019template <typename... T>
20using ServerObject = typename sdbusplus::server::object::object<T...>;
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070021using ModeInterface = sdbusplus::xyz::openbmc_project::Control::server::Mode;
Patrick Ventured8012182018-03-08 08:21:38 -080022using ModeObject = ServerObject<ModeInterface>;
23
Patrick Venturea58197c2018-06-11 15:29:45 -070024class ZoneInterface
25{
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070026 public:
27 virtual ~ZoneInterface() = default;
Patrick Venturea58197c2018-06-11 15:29:45 -070028
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070029 virtual double getCachedValue(const std::string& name) = 0;
30 virtual void addRPMSetPoint(float setpoint) = 0;
31 virtual float getMaxRPMRequest() const = 0;
32 virtual bool getFailSafeMode() const = 0;
33 virtual float getFailSafePercent() const = 0;
34 virtual Sensor* getSensor(std::string name) = 0;
Patrick Venturea58197c2018-06-11 15:29:45 -070035};
36
Patrick Ventured8012182018-03-08 08:21:38 -080037/*
38 * The PIDZone inherits from the Mode object so that it can listen for control
39 * mode changes. It primarily holds all PID loops and holds the sensor value
40 * cache that's used per iteration of the PID loops.
41 */
Patrick Venturea58197c2018-06-11 15:29:45 -070042class PIDZone : public ZoneInterface, public ModeObject
Patrick Ventured8012182018-03-08 08:21:38 -080043{
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070044 public:
45 PIDZone(int64_t zone, float minThermalRpm, float failSafePercent,
46 const SensorManager& mgr, sdbusplus::bus::bus& bus,
47 const char* objPath, bool defer) :
48 ModeObject(bus, objPath, defer),
49 _zoneId(zone), _maximumRPMSetPt(), _minThermalRpmSetPt(minThermalRpm),
50 _failSafePercent(failSafePercent), _mgr(mgr)
51 {
Patrick Ventured8012182018-03-08 08:21:38 -080052#ifdef __TUNING_LOGGING__
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070053 _log.open("/tmp/swampd.log");
Patrick Ventured8012182018-03-08 08:21:38 -080054#endif
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070055 }
Patrick Ventured8012182018-03-08 08:21:38 -080056
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070057 float getMaxRPMRequest(void) const override;
58 bool getManualMode(void) const;
Patrick Ventured8012182018-03-08 08:21:38 -080059
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070060 /* Could put lock around this since it's accessed from two threads, but
61 * only one reader/one writer.
62 */
63 void setManualMode(bool mode);
64 bool getFailSafeMode(void) const override;
65 int64_t getZoneId(void) const;
66 void addRPMSetPoint(float setpoint) override;
67 void clearRPMSetPoints(void);
68 float getFailSafePercent(void) const override;
69 float getMinThermalRpmSetPt(void) const;
Patrick Ventured8012182018-03-08 08:21:38 -080070
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070071 Sensor* getSensor(std::string name) override;
72 void determineMaxRPMRequest(void);
73 void updateFanTelemetry(void);
74 void updateSensors(void);
75 void initializeCache(void);
76 void dumpCache(void);
77 void process_fans(void);
78 void process_thermals(void);
Patrick Ventured8012182018-03-08 08:21:38 -080079
James Feist22c257a2018-08-31 14:07:12 -070080 void addFanPID(std::unique_ptr<Controller> pid);
81 void addThermalPID(std::unique_ptr<Controller> pid);
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070082 double getCachedValue(const std::string& name) override;
83 void addFanInput(std::string fan);
84 void addThermalInput(std::string therm);
Patrick Ventured8012182018-03-08 08:21:38 -080085
86#ifdef __TUNING_LOGGING__
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070087 void initializeLog(void);
88 std::ofstream& getLogHandle(void);
Patrick Ventured8012182018-03-08 08:21:38 -080089#endif
90
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 Ventured8012182018-03-08 08:21:38 -080097#ifdef __TUNING_LOGGING__
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070098 std::ofstream _log;
Patrick Ventured8012182018-03-08 08:21:38 -080099#endif
100
Patrick Ventureda4a5dd2018-08-31 09:42:48 -0700101 const int64_t _zoneId;
102 float _maximumRPMSetPt = 0;
103 bool _manualMode = false;
104 const float _minThermalRpmSetPt;
105 const float _failSafePercent;
Patrick Ventured8012182018-03-08 08:21:38 -0800106
Patrick Ventureda4a5dd2018-08-31 09:42:48 -0700107 std::set<std::string> _failSafeSensors;
Patrick Ventured8012182018-03-08 08:21:38 -0800108
Patrick Ventureda4a5dd2018-08-31 09:42:48 -0700109 std::vector<float> _RPMSetPoints;
110 std::vector<std::string> _fanInputs;
111 std::vector<std::string> _thermalInputs;
112 std::map<std::string, double> _cachedValuesByName;
113 const SensorManager& _mgr;
Patrick Ventured8012182018-03-08 08:21:38 -0800114
James Feist22c257a2018-08-31 14:07:12 -0700115 std::vector<std::unique_ptr<Controller>> _fans;
116 std::vector<std::unique_ptr<Controller>> _thermals;
Patrick Ventured8012182018-03-08 08:21:38 -0800117};