1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
#pragma once
#include "conf.hpp"
#include "controller.hpp"
#include "pidcontroller.hpp"
#include "sensors/manager.hpp"
#include "sensors/sensor.hpp"
#include "tuning.hpp"
#include <fstream>
#include <map>
#include <memory>
#include <sdbusplus/bus.hpp>
#include <sdbusplus/server.hpp>
#include <set>
#include <string>
#include <vector>
#include <xyz/openbmc_project/Control/Mode/server.hpp>
template <typename... T>
using ServerObject = typename sdbusplus::server::object::object<T...>;
using ModeInterface = sdbusplus::xyz::openbmc_project::Control::server::Mode;
using ModeObject = ServerObject<ModeInterface>;
class ZoneInterface
{
public:
virtual ~ZoneInterface() = default;
virtual double getCachedValue(const std::string& name) = 0;
virtual void addRPMSetPoint(double setpoint) = 0;
virtual void addRPMCeiling(double ceiling) = 0;
virtual double getMaxRPMRequest() const = 0;
virtual bool getFailSafeMode() const = 0;
virtual double getFailSafePercent() const = 0;
virtual Sensor* getSensor(const std::string& name) = 0;
};
/*
* The PIDZone inherits from the Mode object so that it can listen for control
* mode changes. It primarily holds all PID loops and holds the sensor value
* cache that's used per iteration of the PID loops.
*/
class PIDZone : public ZoneInterface, public ModeObject
{
public:
PIDZone(int64_t zone, double minThermalOutput, double failSafePercent,
const SensorManager& mgr, sdbusplus::bus::bus& bus,
const char* objPath, bool defer) :
ModeObject(bus, objPath, defer),
_zoneId(zone), _maximumRPMSetPt(),
_minThermalOutputSetPt(minThermalOutput),
_failSafePercent(failSafePercent), _mgr(mgr)
{
if (tuningLoggingEnabled && !tuningLoggingPath.empty())
{
_log.open(tuningLoggingPath);
}
}
double getMaxRPMRequest(void) const override;
bool getManualMode(void) const;
/* Could put lock around this since it's accessed from two threads, but
* only one reader/one writer.
*/
void setManualMode(bool mode);
bool getFailSafeMode(void) const override;
int64_t getZoneID(void) const;
void addRPMSetPoint(double setpoint) override;
void addRPMCeiling(double ceiling) override;
void clearRPMSetPoints(void);
void clearRPMCeilings(void);
double getFailSafePercent(void) const override;
double getMinThermalRPMSetpoint(void) const;
Sensor* getSensor(const std::string& name) override;
void determineMaxRPMRequest(void);
void updateFanTelemetry(void);
void updateSensors(void);
void initializeCache(void);
void dumpCache(void);
void processFans(void);
void processThermals(void);
void addFanPID(std::unique_ptr<Controller> pid);
void addThermalPID(std::unique_ptr<Controller> pid);
double getCachedValue(const std::string& name) override;
void addFanInput(const std::string& fan);
void addThermalInput(const std::string& therm);
void initializeLog(void);
std::ofstream& getLogHandle(void);
/* Method for setting the manual mode over dbus */
bool manual(bool value) override;
/* Method for reading whether in fail-safe mode over dbus */
bool failSafe() const override;
private:
std::ofstream _log;
const int64_t _zoneId;
double _maximumRPMSetPt = 0;
bool _manualMode = false;
const double _minThermalOutputSetPt;
const double _failSafePercent;
std::set<std::string> _failSafeSensors;
std::vector<double> _RPMSetPoints;
std::vector<double> _RPMCeilings;
std::vector<std::string> _fanInputs;
std::vector<std::string> _thermalInputs;
std::map<std::string, double> _cachedValuesByName;
const SensorManager& _mgr;
std::vector<std::unique_ptr<Controller>> _fans;
std::vector<std::unique_ptr<Controller>> _thermals;
};
|