summaryrefslogtreecommitdiffstats
path: root/meta-rcs/meta-talos/recipes-phosphor/fans/phosphor-pid-control/continue-if-sensor-not-present.patch
blob: 7c384013a15acbfa8eed04d9365a490c34dfc1d4 (plain)
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
diff --git a/dbus/dbuspassive.cpp b/dbus/dbuspassive.cpp
index 806ef40..75b83f5 100644
--- a/dbus/dbuspassive.cpp
+++ b/dbus/dbuspassive.cpp
@@ -26,6 +26,10 @@
 #include <string>
 #include <variant>
 
+using Property = std::string;
+using Value = std::variant<int64_t, double, std::string, bool>;
+using PropertyMap = std::map<Property, Value>;
+
 std::unique_ptr<ReadInterface> DbusPassive::createDbusPassive(
     sdbusplus::bus::bus& bus, const std::string& type, const std::string& id,
     DbusHelperInterface* helper, const conf::SensorConfig* info,
@@ -61,6 +65,41 @@ std::unique_ptr<ReadInterface> DbusPassive::createDbusPassive(
         return nullptr;
     }
 
+    if (failed && (type == "fan"))
+    {
+        std::string path = getInventoryPath(id);
+
+        try
+        {
+            bool present = true;
+
+            auto pimMsg = tempBus.new_method_call("xyz.openbmc_project.Inventory.Manager", path.c_str(), "org.freedesktop.DBus.Properties", "GetAll");
+            pimMsg.append("xyz.openbmc_project.Inventory.Item");
+
+            PropertyMap propMap;
+
+            auto valueResponseMsg = bus.call(pimMsg);
+            valueResponseMsg.read(propMap);
+
+            // If no error was set, the data should all be there.
+            auto findPresent = propMap.find("Present");
+            if (findPresent != propMap.end())
+            {
+                present = std::get<bool>(findPresent->second);
+            }
+
+            // std::cerr << "DbusPassive::createDbusPassive() present: '" << present << "'\n";
+            if (!present)
+            {
+                failed = false;
+            }
+        }
+        catch (const std::exception& e)
+        {
+            // Ignore failure
+        }
+    }
+
     /* if these values are zero, they're ignored. */
     if (info->ignoreDbusMinMax)
     {
@@ -68,6 +107,7 @@ std::unique_ptr<ReadInterface> DbusPassive::createDbusPassive(
         settings.max = 0;
     }
 
+    // std::cerr << "DbusPassive::createDbusPassive() failed: " << failed << "\n";
     return std::make_unique<DbusPassive>(bus, type, id, helper, settings,
                                          failed, path, redundancy);
 }
@@ -78,8 +118,9 @@ DbusPassive::DbusPassive(
     bool failed, const std::string& path,
     const std::shared_ptr<DbusPassiveRedundancy>& redundancy) :
     ReadInterface(),
-    _bus(bus), _signal(bus, getMatch(type, id).c_str(), dbusHandleSignal, this),
-    _id(id), _helper(helper), _failed(failed), path(path),
+    _id(id), _type(type), _helper(helper), _bus(bus),
+    _signal(bus, getMatch(type, id).c_str(), dbusHandleSignal, this),
+    _failed(failed), path(path),
     redundancy(redundancy)
 
 {
@@ -109,19 +150,23 @@ void DbusPassive::setValue(double value)
 
 bool DbusPassive::getFailed(void) const
 {
+    // std::cerr << "DbusPassive::getFailed() redundancy: " << redundancy << "\n";
     if (redundancy)
     {
         const std::set<std::string>& failures = redundancy->getFailed();
         if (failures.find(path) != failures.end())
         {
+            // std::cerr << "DbusPassive::getFailed() redundancy has signalled failure!\n";
             return true;
         }
     }
+    // std::cerr << "DbusPassive::getFailed() _failed: " << _failed << "\n";
     return _failed;
 }
 
 void DbusPassive::setFailed(bool value)
 {
+    // std::cerr << "DbusPassive::setFailed(" << value << ")\n";
     _failed = value;
 }
 
@@ -189,6 +234,43 @@ int handleSensorValue(sdbusplus::message::message& msg, DbusPassive* owner)
         {
             asserted = std::get<bool>(criticalAlarmHigh->second);
         }
+
+        // std::cerr << "handleSensorValue() asserted: " << asserted << " type: '" << owner->_type << "'\n";
+        if (asserted && (owner->_type == "fan"))
+        {
+            std::string path = getInventoryPath(owner->_id);
+
+            try
+            {
+                bool present = true;
+
+                auto pimMsg = owner->_bus.new_method_call("xyz.openbmc_project.Inventory.Manager", path.c_str(), "org.freedesktop.DBus.Properties", "GetAll");
+                pimMsg.append("xyz.openbmc_project.Inventory.Item");
+
+                PropertyMap propMap;
+
+                auto valueResponseMsg = owner->_bus.call(pimMsg);
+                valueResponseMsg.read(propMap);
+
+                // If no error was set, the data should all be there.
+                auto findPresent = propMap.find("Present");
+                if (findPresent != propMap.end())
+                {
+                    present = std::get<bool>(findPresent->second);
+                }
+
+                // std::cerr << "handleSensorValue() present: '" << present << "'\n";
+                if (!present)
+                {
+                    asserted = false;
+                }
+            }
+            catch (const std::exception& e)
+            {
+                // Ignore failure
+            }
+        }
+
         owner->setFailed(asserted);
     }
 
diff --git a/dbus/dbuspassive.hpp b/dbus/dbuspassive.hpp
index f00a2ea..d025ed4 100644
--- a/dbus/dbuspassive.hpp
+++ b/dbus/dbuspassive.hpp
@@ -57,12 +57,14 @@ class DbusPassive : public ReadInterface
     double getMax(void);
     double getMin(void);
 
-  private:
+    std::string _id; // for debug identification
+    std::string _type; // for inventory match
+    DbusHelperInterface* _helper;
     sdbusplus::bus::bus& _bus;
+
+  private:
     sdbusplus::server::match::match _signal;
     int64_t _scale;
-    std::string _id; // for debug identification
-    DbusHelperInterface* _helper;
 
     std::mutex _lock;
     double _value = 0;
diff --git a/dbus/dbuswrite.cpp b/dbus/dbuswrite.cpp
index 502b988..28a04e4 100644
--- a/dbus/dbuswrite.cpp
+++ b/dbus/dbuswrite.cpp
@@ -65,6 +65,8 @@ void DbusWritePercent::write(double value)
                                  "org.freedesktop.DBus.Properties", "Set");
     mesg.append(pwmInterface, "Target", std::variant<uint64_t>(ovalue));
 
+    // std::cerr << "DbusWritePercent::write(" << value << "), writing to connection '" << connectionName.c_str() << "', path '" << path.c_str() << "' xyz.openbmc_project.Control.FanPwm Target '" << ovalue << "'\n";
+
     try
     {
         // TODO: if we don't use the reply, call_noreply()
@@ -111,6 +113,8 @@ void DbusWrite::write(double value)
                                  "org.freedesktop.DBus.Properties", "Set");
     mesg.append(pwmInterface, "Target", std::variant<uint64_t>(value));
 
+    // std::cerr << "DbusWrite::write(" << value << "), writing to connection '" << connectionName.c_str() << "', path '" << path.c_str() << "' xyz.openbmc_project.Control.FanPwm Target '" << value << "'\n";
+
     try
     {
         // TODO: consider call_noreplly
diff --git a/dbus/util.cpp b/dbus/util.cpp
index 33e0985..8a639eb 100644
--- a/dbus/util.cpp
+++ b/dbus/util.cpp
@@ -148,6 +148,7 @@ bool DbusHelper::thresholdsAsserted(sdbusplus::bus::bus& bus,
     {
         asserted = std::get<bool>(findCriticalHigh->second);
     }
+    // std::cerr << "DbusHelper::thresholdsAsserted path: '" << path << "' asserted: " << asserted << "\n";
     return asserted;
 }
 
@@ -170,6 +171,11 @@ std::string getSensorPath(const std::string& type, const std::string& id)
     return std::string("/xyz/openbmc_project/sensors/" + layer + "/" + id);
 }
 
+std::string getInventoryPath(const std::string& id)
+{
+    return std::string("/xyz/openbmc_project/inventory/system/chassis/motherboard/" + id);
+}
+
 std::string getMatch(const std::string& type, const std::string& id)
 {
     return std::string("type='signal',"
diff --git a/pid/ec/pid.cpp b/pid/ec/pid.cpp
index 7d8b403..7a8b91d 100644
--- a/pid/ec/pid.cpp
+++ b/pid/ec/pid.cpp
@@ -16,6 +16,8 @@
 
 #include "pid.hpp"
 
+#include <iostream>
+
 namespace ec
 {
 
@@ -72,6 +74,8 @@ double pid(pid_info_t* pidinfoptr, double input, double setpoint)
     output = proportionalTerm + integralTerm + feedFwdTerm;
     output = clamp(output, pidinfoptr->outLim.min, pidinfoptr->outLim.max);
 
+    // std::cerr << "pid() input: " << input << " error: " << error << " proportionalTerm: " << proportionalTerm << " integralTerm: " << integralTerm << " feedFwdTerm: " << feedFwdTerm << " output: " << output << "\n";
+
     // slew rate
     // TODO(aarena) - Simplify logic as Andy suggested by creating dynamic
     // outLim_min/max that are affected by slew rate control and just clamping
diff --git a/pid/fancontroller.cpp b/pid/fancontroller.cpp
index dd26d16..3a2c743 100644
--- a/pid/fancontroller.cpp
+++ b/pid/fancontroller.cpp
@@ -106,6 +106,7 @@ double FanController::setptProc(void)
         setFanDirection(FanSpeedDirection::NEUTRAL);
     }
 
+    // std::cerr << "FanController::setptProc() prev: " << prev << " going to return: " << maxRPM << "\n";
     setSetpoint(maxRPM);
 
     return (maxRPM);
@@ -128,12 +129,15 @@ void FanController::outputProc(double value)
         }
     }
 
+    // std::cerr << "FanController::outputProc(" << value << ") _owner->getFailSafeMode(): " << _owner->getFailSafeMode() << " percent: " << percent << "\n";
+
     // value and kFanFailSafeDutyCycle are 10 for 10% so let's fix that.
     percent /= 100;
 
     // PidSensorMap for writing.
     for (const auto& it : _inputs)
     {
+        // std::cerr << "FanController::outputProc(" << value << ") for '" << it << "', writing value '" << percent << "'\n";
         auto sensor = _owner->getSensor(it);
         sensor->write(percent);
     }
diff --git a/pid/pidcontroller.cpp b/pid/pidcontroller.cpp
index e3eaaff..e23149e 100644
--- a/pid/pidcontroller.cpp
+++ b/pid/pidcontroller.cpp
@@ -73,6 +73,8 @@ void PIDController::process(void)
         output = ec::pid(info, lastInput, setpt);
     }
 
+    // std::cerr << "PIDController::process() setpt: " << setpt << " input: " << input << " output: " << output << "\n";
+
     // Output new value
     outputProc(output);
 
diff --git a/pid/zone.cpp b/pid/zone.cpp
index 6a63671..8cdb9f7 100644
--- a/pid/zone.cpp
+++ b/pid/zone.cpp
@@ -53,6 +53,11 @@ void PIDZone::setManualMode(bool mode)
 bool PIDZone::getFailSafeMode(void) const
 {
     // If any keys are present at least one sensor is in fail safe mode.
+    // if (!_failSafeSensors.empty())
+    // {
+    //     std::set<std::string>::iterator it = _failSafeSensors.begin();
+    //     std::cerr << "PIDZone::getFailSafeMode sensor '" << *it << "' failed!\n";
+    // }
     return !_failSafeSensors.empty();
 }
 
@@ -139,6 +144,7 @@ void PIDZone::determineMaxSetPointRequest(void)
      */
     max = std::max(getMinThermalSetpoint(), max);
 
+    // std::cerr << "PIDZone::determineMaxSetPointRequest _SetPoints.size(): " << _SetPoints.size() << " tuningEnabled: " << tuningEnabled << " max: " << max << "\n";
     if (tuningEnabled)
     {
         /*
@@ -251,6 +257,7 @@ void PIDZone::updateFanTelemetry(void)
         // check if fan fail.
         if (sensor->getFailed())
         {
+            std::cerr << "Fan '" << f << "' has failed!.\n";
             _failSafeSensors.insert(f);
         }
         else if (timeout != 0 && duration >= period)
@@ -288,6 +295,17 @@ void PIDZone::updateSensors(void)
     for (const auto& t : _thermalInputs)
     {
         auto sensor = _mgr.getSensor(t);
+        if (!sensor)
+        {
+            // std::cerr << "Skipping missing sensor '" << t << "'.\n";
+            // Check if it's in there: remove it.
+            auto kt = _failSafeSensors.find(t);
+            if (kt != _failSafeSensors.end())
+            {
+                _failSafeSensors.erase(kt);
+            }
+            continue;
+        }
         ReadReturn r = sensor->read();
         int64_t timeout = sensor->getTimeout();
 
@@ -303,7 +321,7 @@ void PIDZone::updateSensors(void)
         }
         else if (timeout != 0 && duration >= period)
         {
-            // std::cerr << "Entering fail safe mode.\n";
+            std::cerr << "Entering fail safe mode.\n";
             _failSafeSensors.insert(t);
         }
         else
@@ -315,6 +333,8 @@ void PIDZone::updateSensors(void)
                 _failSafeSensors.erase(kt);
             }
         }
+
+        // std::cerr << "PIDZone::updateSensors for '" << t << "', got value '" << _cachedValuesByName[t] << "'\n";
     }
 
     return;
diff --git a/sensors/builder.cpp b/sensors/builder.cpp
index 4da1cf2..464ec9c 100644
--- a/sensors/builder.cpp
+++ b/sensors/builder.cpp
@@ -87,9 +87,7 @@ SensorManager
                 }
                 if (ri == nullptr)
                 {
-                    throw SensorBuildException(
-                        "Failed to create dbus passive sensor: " + name +
-                        " of type: " + info->type);
+                    continue;
                 }
                 break;
             case IOInterfaceType::EXTERNAL:
diff --git a/sensors/manager.hpp b/sensors/manager.hpp
index 411b302..bd1dd48 100644
--- a/sensors/manager.hpp
+++ b/sensors/manager.hpp
@@ -38,6 +38,8 @@ class SensorManager
     // TODO(venture): Should implement read/write by name.
     Sensor* getSensor(const std::string& name) const
     {
+        if (_sensorMap.count(name) <= 0)
+            return nullptr;
         return _sensorMap.at(name).get();
     }
 
diff --git a/util.hpp b/util.hpp
index e40b61f..5e2feae 100644
--- a/util.hpp
+++ b/util.hpp
@@ -149,6 +149,7 @@ class DbusHelper : public DbusHelperInterface
 };
 
 std::string getSensorPath(const std::string& type, const std::string& id);
+std::string getInventoryPath(const std::string& id);
 std::string getMatch(const std::string& type, const std::string& id);
 void scaleSensorReading(const double min, const double max, double& value);
 bool validType(const std::string& type);
OpenPOWER on IntegriCloud