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
|
From 021b17af775b58a61661f75af595b71625509241 Mon Sep 17 00:00:00 2001
From: Wojciech Dembinski <wojciech.dembinski@intel.com>
Date: Mon, 7 Dec 2020 19:23:10 +0100
Subject: [PATCH] Add check for min/max received from hwmon files
When hwmon reports incorrect min/max values or CPU Sensor cannot access
readings, it shall keep the last known good readings and not update
DBus with incorrect values.
This patch adds min < max verification check for the values received
from hwmon and removes check for power on/off in the case of a read
failure.
Tested manually on a physical platform, test cases cover incorrect
max/min values and failing access to hwmon files.
SDR over IPMI can be fully received in the case of error.
Signed-off-by: Wojciech Dembinski <wojciech.dembinski@intel.com>
Change-Id: Ia061f849b0f434812f822ed1902c8964d4c64b45
---
src/CPUSensor.cpp | 50 ++++++++++++++++++++++++-----------------------
1 file changed, 26 insertions(+), 24 deletions(-)
diff --git a/src/CPUSensor.cpp b/src/CPUSensor.cpp
index cd1038f..16c3686 100644
--- a/src/CPUSensor.cpp
+++ b/src/CPUSensor.cpp
@@ -1,5 +1,5 @@
/*
-// Copyright (c) 2018 Intel Corporation
+// Copyright (c) 2018-2021 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -166,19 +166,22 @@ void CPUSensor::setupRead(void)
void CPUSensor::updateMinMaxValues(void)
{
+ double newMin = std::numeric_limits<double>::quiet_NaN();
+ double newMax = std::numeric_limits<double>::quiet_NaN();
+
const boost::container::flat_map<
std::string,
std::vector<std::tuple<const char*, std::reference_wrapper<double>,
- const char*>>>
- map = {
+ const char*, std::reference_wrapper<double>>>>
+ map = {
+ {
+ "cap",
{
- "cap",
- {
- std::make_tuple("cap_max", std::ref(maxValue), "MaxValue"),
- std::make_tuple("cap_min", std::ref(minValue), "MinValue"),
- },
+ std::make_tuple("cap_max", std::ref(maxValue), "MaxValue", std::ref(newMax)),
+ std::make_tuple("cap_min", std::ref(minValue), "MinValue", std::ref(newMin)),
},
- };
+ },
+ };
if (auto fileParts = splitFileName(path))
{
@@ -188,26 +191,25 @@ void CPUSensor::updateMinMaxValues(void)
{
for (const auto& vectorItem : mapIt->second)
{
- auto& [suffix, oldValue, dbusName] = vectorItem;
+ auto& [suffix, oldValue, dbusName, newValue] = vectorItem;
auto attrPath = boost::replace_all_copy(path, fileItem, suffix);
- if (auto newVal =
- readFile(attrPath, CPUSensor::sensorScaleFactor))
+
+ if(auto tmp = readFile(attrPath, CPUSensor::sensorScaleFactor))
{
- updateProperty(sensorInterface, oldValue, *newVal,
- dbusName);
+ newValue.get() = *tmp;
}
else
{
- if (isPowerOn())
- {
- updateProperty(sensorInterface, oldValue, 0, dbusName);
- }
- else
- {
- updateProperty(sensorInterface, oldValue,
- std::numeric_limits<double>::quiet_NaN(),
- dbusName);
- }
+ newValue.get() = std::numeric_limits<double>::quiet_NaN();
+ }
+ }
+
+ if(std::isfinite(newMin) && std::isfinite(newMax) && (newMin < newMax))
+ {
+ for (const auto& vectorItem : mapIt->second)
+ {
+ auto& [suffix, oldValue, dbusName, newValue] = vectorItem;
+ updateProperty(sensorInterface, oldValue, newValue, dbusName);
}
}
}
--
2.17.1
|