James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 1 | /* |
| 2 | // Copyright (c) 2018 Intel Corporation |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | */ |
| 16 | |
Andrew Jeffery | e73bd0a | 2023-01-25 10:39:57 +1030 | [diff] [blame] | 17 | #include "IntelCPUSensor.hpp" |
| 18 | |
| 19 | #include "Utils.hpp" |
| 20 | |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 21 | #include <unistd.h> |
| 22 | |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 23 | #include <boost/algorithm/string/replace.hpp> |
James Feist | 8086aba | 2020-08-25 16:00:59 -0700 | [diff] [blame] | 24 | #include <boost/asio/read_until.hpp> |
James Feist | 38fb598 | 2020-05-28 10:09:54 -0700 | [diff] [blame] | 25 | #include <sdbusplus/asio/connection.hpp> |
| 26 | #include <sdbusplus/asio/object_server.hpp> |
| 27 | |
Ed Tanous | 2049bd2 | 2022-07-09 07:20:26 -0700 | [diff] [blame] | 28 | #include <cstddef> |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 29 | #include <iostream> |
Patrick Venture | 96e97db | 2019-10-31 13:44:38 -0700 | [diff] [blame] | 30 | #include <istream> |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 31 | #include <limits> |
Patrick Venture | 96e97db | 2019-10-31 13:44:38 -0700 | [diff] [blame] | 32 | #include <memory> |
Patrick Venture | 96e97db | 2019-10-31 13:44:38 -0700 | [diff] [blame] | 33 | #include <stdexcept> |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 34 | #include <string> |
Patrick Venture | 96e97db | 2019-10-31 13:44:38 -0700 | [diff] [blame] | 35 | #include <vector> |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 36 | |
Thu Nguyen | 255da6b | 2022-07-29 10:05:52 +0700 | [diff] [blame] | 37 | IntelCPUSensor::IntelCPUSensor( |
| 38 | const std::string& path, const std::string& objectType, |
| 39 | sdbusplus::asio::object_server& objectServer, |
| 40 | std::shared_ptr<sdbusplus::asio::connection>& conn, |
Ed Tanous | 1f97863 | 2023-02-28 18:16:39 -0800 | [diff] [blame] | 41 | boost::asio::io_context& io, const std::string& sensorName, |
Thu Nguyen | 255da6b | 2022-07-29 10:05:52 +0700 | [diff] [blame] | 42 | std::vector<thresholds::Threshold>&& thresholdsIn, |
| 43 | const std::string& sensorConfiguration, int cpuId, bool show, |
| 44 | double dtsOffset) : |
Zhikui Ren | da98f09 | 2021-11-01 09:41:08 -0700 | [diff] [blame] | 45 | Sensor(escapeName(sensorName), std::move(thresholdsIn), sensorConfiguration, |
| 46 | objectType, false, false, 0, 0, conn, PowerState::on), |
Ed Tanous | 2049bd2 | 2022-07-09 07:20:26 -0700 | [diff] [blame] | 47 | objServer(objectServer), inputDev(io), waitTimer(io), |
Ed Tanous | a771f6a | 2022-01-14 09:36:51 -0800 | [diff] [blame] | 48 | nameTcontrol("Tcontrol CPU" + std::to_string(cpuId)), path(path), |
Brad Bishop | fbb44ad | 2019-11-08 09:42:37 -0500 | [diff] [blame] | 49 | privTcontrol(std::numeric_limits<double>::quiet_NaN()), |
Thu Nguyen | 255da6b | 2022-07-29 10:05:52 +0700 | [diff] [blame] | 50 | dtsOffset(dtsOffset), show(show), pollTime(IntelCPUSensor::sensorPollMs) |
Ed Tanous | b429f31 | 2022-06-27 16:09:53 -0700 | [diff] [blame] | 51 | |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 52 | { |
Jae Hyun Yoo | 73ca551 | 2019-02-28 21:20:17 -0800 | [diff] [blame] | 53 | if (show) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 54 | { |
Zbigniew Kurzynski | 63f3866 | 2020-06-09 13:02:11 +0200 | [diff] [blame] | 55 | if (auto fileParts = splitFileName(path)) |
Jae Hyun Yoo | 73ca551 | 2019-02-28 21:20:17 -0800 | [diff] [blame] | 56 | { |
Zbigniew Kurzynski | dbfd466 | 2020-09-28 18:06:00 +0200 | [diff] [blame] | 57 | auto& [type, nr, item] = *fileParts; |
Zbigniew Kurzynski | 0a4c480 | 2020-04-01 11:22:27 +0200 | [diff] [blame] | 58 | std::string interfacePath; |
Ed Tanous | a771f6a | 2022-01-14 09:36:51 -0800 | [diff] [blame] | 59 | const char* units = nullptr; |
Ed Tanous | 2049bd2 | 2022-07-09 07:20:26 -0700 | [diff] [blame] | 60 | if (type == "power") |
Zbigniew Kurzynski | 0a4c480 | 2020-04-01 11:22:27 +0200 | [diff] [blame] | 61 | { |
| 62 | interfacePath = "/xyz/openbmc_project/sensors/power/" + name; |
Zev Weiss | 6b6891c | 2021-04-22 02:46:21 -0500 | [diff] [blame] | 63 | units = sensor_paths::unitWatts; |
Andrei Kartashev | 6736d4b | 2020-12-18 18:59:21 +0300 | [diff] [blame] | 64 | minValue = 0; |
| 65 | maxValue = 511; |
Zbigniew Kurzynski | 0a4c480 | 2020-04-01 11:22:27 +0200 | [diff] [blame] | 66 | } |
| 67 | else |
| 68 | { |
Patrick Williams | 779c96a | 2023-05-10 07:50:42 -0500 | [diff] [blame] | 69 | interfacePath = "/xyz/openbmc_project/sensors/temperature/" + |
| 70 | name; |
Zev Weiss | 6b6891c | 2021-04-22 02:46:21 -0500 | [diff] [blame] | 71 | units = sensor_paths::unitDegreesC; |
Andrei Kartashev | 6736d4b | 2020-12-18 18:59:21 +0300 | [diff] [blame] | 72 | minValue = -128; |
| 73 | maxValue = 127; |
Zbigniew Kurzynski | 0a4c480 | 2020-04-01 11:22:27 +0200 | [diff] [blame] | 74 | } |
James Feist | 078f232 | 2019-03-08 11:09:05 -0800 | [diff] [blame] | 75 | |
Zbigniew Kurzynski | 0a4c480 | 2020-04-01 11:22:27 +0200 | [diff] [blame] | 76 | sensorInterface = objectServer.add_interface( |
| 77 | interfacePath, "xyz.openbmc_project.Sensor.Value"); |
Jayashree Dhanapal | 5667808 | 2022-01-04 17:27:20 +0530 | [diff] [blame] | 78 | for (const auto& threshold : thresholds) |
Zbigniew Kurzynski | 0a4c480 | 2020-04-01 11:22:27 +0200 | [diff] [blame] | 79 | { |
Jayashree Dhanapal | 5667808 | 2022-01-04 17:27:20 +0530 | [diff] [blame] | 80 | std::string interface = |
| 81 | thresholds::getInterface(threshold.level); |
| 82 | thresholdInterfaces[static_cast<size_t>(threshold.level)] = |
| 83 | objectServer.add_interface(interfacePath, interface); |
Zbigniew Kurzynski | 0a4c480 | 2020-04-01 11:22:27 +0200 | [diff] [blame] | 84 | } |
| 85 | association = objectServer.add_interface(interfacePath, |
| 86 | association::interface); |
| 87 | |
Andrei Kartashev | 3928741 | 2022-02-04 16:04:47 +0300 | [diff] [blame] | 88 | setInitialProperties(units); |
Zbigniew Kurzynski | 0a4c480 | 2020-04-01 11:22:27 +0200 | [diff] [blame] | 89 | } |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 90 | } |
James Feist | 961bf09 | 2020-07-01 16:38:12 -0700 | [diff] [blame] | 91 | |
| 92 | // call setup always as not all sensors call setInitialProperties |
James Feist | 71d31b2 | 2019-01-02 16:57:54 -0800 | [diff] [blame] | 93 | setupPowerMatch(conn); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 94 | } |
| 95 | |
Thu Nguyen | 255da6b | 2022-07-29 10:05:52 +0700 | [diff] [blame] | 96 | IntelCPUSensor::~IntelCPUSensor() |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 97 | { |
| 98 | // close the input dev to cancel async operations |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 99 | inputDev.close(); |
| 100 | waitTimer.cancel(); |
Jae Hyun Yoo | 73ca551 | 2019-02-28 21:20:17 -0800 | [diff] [blame] | 101 | if (show) |
| 102 | { |
Jayashree Dhanapal | 5667808 | 2022-01-04 17:27:20 +0530 | [diff] [blame] | 103 | for (const auto& iface : thresholdInterfaces) |
| 104 | { |
| 105 | objServer.remove_interface(iface); |
| 106 | } |
Jae Hyun Yoo | 73ca551 | 2019-02-28 21:20:17 -0800 | [diff] [blame] | 107 | objServer.remove_interface(sensorInterface); |
James Feist | 078f232 | 2019-03-08 11:09:05 -0800 | [diff] [blame] | 108 | objServer.remove_interface(association); |
Arun P. Mohanan | b782eec | 2021-10-18 16:22:09 +0530 | [diff] [blame] | 109 | objServer.remove_interface(availableInterface); |
| 110 | objServer.remove_interface(operationalInterface); |
Jae Hyun Yoo | 73ca551 | 2019-02-28 21:20:17 -0800 | [diff] [blame] | 111 | } |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 112 | } |
| 113 | |
Thu Nguyen | 255da6b | 2022-07-29 10:05:52 +0700 | [diff] [blame] | 114 | void IntelCPUSensor::restartRead(void) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 115 | { |
Thu Nguyen | 255da6b | 2022-07-29 10:05:52 +0700 | [diff] [blame] | 116 | std::weak_ptr<IntelCPUSensor> weakRef = weak_from_this(); |
Ed Tanous | 83db50c | 2023-03-01 10:20:24 -0800 | [diff] [blame] | 117 | waitTimer.expires_after(std::chrono::milliseconds(pollTime)); |
Arun Lal K M | 8454571 | 2021-12-31 13:29:56 +0000 | [diff] [blame] | 118 | waitTimer.async_wait([weakRef](const boost::system::error_code& ec) { |
| 119 | if (ec == boost::asio::error::operation_aborted) |
| 120 | { |
| 121 | std::cerr << "Failed to reschedule\n"; |
| 122 | return; |
| 123 | } |
Thu Nguyen | 255da6b | 2022-07-29 10:05:52 +0700 | [diff] [blame] | 124 | std::shared_ptr<IntelCPUSensor> self = weakRef.lock(); |
Arun P. Mohanan | 04d0506 | 2021-10-29 20:30:26 +0530 | [diff] [blame] | 125 | |
Arun Lal K M | 8454571 | 2021-12-31 13:29:56 +0000 | [diff] [blame] | 126 | if (self) |
| 127 | { |
| 128 | self->setupRead(); |
| 129 | } |
| 130 | }); |
| 131 | } |
| 132 | |
Thu Nguyen | 255da6b | 2022-07-29 10:05:52 +0700 | [diff] [blame] | 133 | void IntelCPUSensor::setupRead(void) |
Arun Lal K M | 8454571 | 2021-12-31 13:29:56 +0000 | [diff] [blame] | 134 | { |
James Feist | c22b842 | 2020-07-07 14:40:39 -0700 | [diff] [blame] | 135 | if (readingStateGood()) |
| 136 | { |
| 137 | inputDev.close(); |
Ed Tanous | 99c4409 | 2022-01-14 09:59:09 -0800 | [diff] [blame] | 138 | |
| 139 | // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) |
Arun Lal K M | 8454571 | 2021-12-31 13:29:56 +0000 | [diff] [blame] | 140 | fd = open(path.c_str(), O_RDONLY | O_NONBLOCK); |
| 141 | if (fd < 0) |
James Feist | c22b842 | 2020-07-07 14:40:39 -0700 | [diff] [blame] | 142 | { |
| 143 | std::cerr << name << " unable to open fd!\n"; |
Arun Lal K M | 8454571 | 2021-12-31 13:29:56 +0000 | [diff] [blame] | 144 | return; |
James Feist | c22b842 | 2020-07-07 14:40:39 -0700 | [diff] [blame] | 145 | } |
Arun Lal K M | 8454571 | 2021-12-31 13:29:56 +0000 | [diff] [blame] | 146 | |
| 147 | inputDev.assign(fd); |
James Feist | c22b842 | 2020-07-07 14:40:39 -0700 | [diff] [blame] | 148 | } |
| 149 | else |
| 150 | { |
James Feist | c22b842 | 2020-07-07 14:40:39 -0700 | [diff] [blame] | 151 | markAvailable(false); |
Arun Lal K M | 8454571 | 2021-12-31 13:29:56 +0000 | [diff] [blame] | 152 | updateValue(std::numeric_limits<double>::quiet_NaN()); |
| 153 | restartRead(); |
| 154 | return; |
James Feist | c22b842 | 2020-07-07 14:40:39 -0700 | [diff] [blame] | 155 | } |
Arun Lal K M | 8454571 | 2021-12-31 13:29:56 +0000 | [diff] [blame] | 156 | |
Thu Nguyen | 255da6b | 2022-07-29 10:05:52 +0700 | [diff] [blame] | 157 | std::weak_ptr<IntelCPUSensor> weakRef = weak_from_this(); |
Arun Lal K M | 8454571 | 2021-12-31 13:29:56 +0000 | [diff] [blame] | 158 | inputDev.async_wait(boost::asio::posix::descriptor_base::wait_read, |
| 159 | [weakRef](const boost::system::error_code& ec) { |
Thu Nguyen | 255da6b | 2022-07-29 10:05:52 +0700 | [diff] [blame] | 160 | std::shared_ptr<IntelCPUSensor> self = weakRef.lock(); |
Arun Lal K M | 8454571 | 2021-12-31 13:29:56 +0000 | [diff] [blame] | 161 | |
Ed Tanous | bb67932 | 2022-05-16 16:10:00 -0700 | [diff] [blame] | 162 | if (self) |
| 163 | { |
| 164 | self->handleResponse(ec); |
| 165 | } |
| 166 | }); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 167 | } |
| 168 | |
Thu Nguyen | 255da6b | 2022-07-29 10:05:52 +0700 | [diff] [blame] | 169 | void IntelCPUSensor::updateMinMaxValues(void) |
Zbigniew Kurzynski | 8d8d8d7 | 2020-05-29 19:21:24 +0200 | [diff] [blame] | 170 | { |
| 171 | const boost::container::flat_map< |
| 172 | std::string, |
| 173 | std::vector<std::tuple<const char*, std::reference_wrapper<double>, |
| 174 | const char*>>> |
| 175 | map = { |
| 176 | { |
| 177 | "cap", |
| 178 | { |
| 179 | std::make_tuple("cap_max", std::ref(maxValue), "MaxValue"), |
| 180 | std::make_tuple("cap_min", std::ref(minValue), "MinValue"), |
| 181 | }, |
| 182 | }, |
| 183 | }; |
| 184 | |
Zbigniew Kurzynski | 63f3866 | 2020-06-09 13:02:11 +0200 | [diff] [blame] | 185 | if (auto fileParts = splitFileName(path)) |
Zbigniew Kurzynski | 8d8d8d7 | 2020-05-29 19:21:24 +0200 | [diff] [blame] | 186 | { |
Zbigniew Kurzynski | dbfd466 | 2020-09-28 18:06:00 +0200 | [diff] [blame] | 187 | auto& [fileType, fileNr, fileItem] = *fileParts; |
Zbigniew Kurzynski | 8d8d8d7 | 2020-05-29 19:21:24 +0200 | [diff] [blame] | 188 | const auto mapIt = map.find(fileItem); |
| 189 | if (mapIt != map.cend()) |
| 190 | { |
| 191 | for (const auto& vectorItem : mapIt->second) |
| 192 | { |
Ed Tanous | 2049bd2 | 2022-07-09 07:20:26 -0700 | [diff] [blame] | 193 | const auto& [suffix, oldValue, dbusName] = vectorItem; |
Zbigniew Kurzynski | 8d8d8d7 | 2020-05-29 19:21:24 +0200 | [diff] [blame] | 194 | auto attrPath = boost::replace_all_copy(path, fileItem, suffix); |
Patrick Williams | 779c96a | 2023-05-10 07:50:42 -0500 | [diff] [blame] | 195 | if (auto newVal = readFile(attrPath, |
| 196 | IntelCPUSensor::sensorScaleFactor)) |
Zbigniew Kurzynski | 8d8d8d7 | 2020-05-29 19:21:24 +0200 | [diff] [blame] | 197 | { |
Zbigniew Kurzynski | 4f45e42 | 2020-06-09 12:42:15 +0200 | [diff] [blame] | 198 | updateProperty(sensorInterface, oldValue, *newVal, |
| 199 | dbusName); |
Zbigniew Kurzynski | 8d8d8d7 | 2020-05-29 19:21:24 +0200 | [diff] [blame] | 200 | } |
| 201 | else |
| 202 | { |
| 203 | if (isPowerOn()) |
| 204 | { |
Zbigniew Kurzynski | 4f45e42 | 2020-06-09 12:42:15 +0200 | [diff] [blame] | 205 | updateProperty(sensorInterface, oldValue, 0, dbusName); |
Zbigniew Kurzynski | 8d8d8d7 | 2020-05-29 19:21:24 +0200 | [diff] [blame] | 206 | } |
| 207 | else |
| 208 | { |
Zbigniew Kurzynski | 4f45e42 | 2020-06-09 12:42:15 +0200 | [diff] [blame] | 209 | updateProperty(sensorInterface, oldValue, |
| 210 | std::numeric_limits<double>::quiet_NaN(), |
| 211 | dbusName); |
Zbigniew Kurzynski | 8d8d8d7 | 2020-05-29 19:21:24 +0200 | [diff] [blame] | 212 | } |
| 213 | } |
| 214 | } |
| 215 | } |
| 216 | } |
| 217 | } |
| 218 | |
Thu Nguyen | 255da6b | 2022-07-29 10:05:52 +0700 | [diff] [blame] | 219 | void IntelCPUSensor::handleResponse(const boost::system::error_code& err) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 220 | { |
Arun Lal K M | 8454571 | 2021-12-31 13:29:56 +0000 | [diff] [blame] | 221 | if ((err == boost::system::errc::bad_file_descriptor) || |
| 222 | (err == boost::asio::error::misc_errors::not_found)) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 223 | { |
| 224 | return; // we're being destroyed |
| 225 | } |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 226 | if (err == boost::system::errc::operation_canceled) |
James Feist | 838529b | 2020-09-02 16:57:05 -0700 | [diff] [blame] | 227 | { |
| 228 | if (readingStateGood()) |
| 229 | { |
| 230 | if (!loggedInterfaceDown) |
| 231 | { |
| 232 | std::cerr << name << " interface down!\n"; |
| 233 | loggedInterfaceDown = true; |
| 234 | } |
Thu Nguyen | 255da6b | 2022-07-29 10:05:52 +0700 | [diff] [blame] | 235 | pollTime = static_cast<size_t>(IntelCPUSensor::sensorPollMs) * 10U; |
James Feist | 838529b | 2020-09-02 16:57:05 -0700 | [diff] [blame] | 236 | markFunctional(false); |
| 237 | } |
| 238 | return; |
| 239 | } |
| 240 | loggedInterfaceDown = false; |
Arun Lal K M | 8454571 | 2021-12-31 13:29:56 +0000 | [diff] [blame] | 241 | |
| 242 | if (err) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 243 | { |
Arun Lal K M | 8454571 | 2021-12-31 13:29:56 +0000 | [diff] [blame] | 244 | pollTime = sensorFailedPollTimeMs; |
| 245 | incrementError(); |
| 246 | return; |
| 247 | } |
| 248 | |
| 249 | static constexpr uint32_t bufLen = 128; |
| 250 | std::string response; |
| 251 | response.resize(bufLen); |
| 252 | int rdLen = 0; |
| 253 | |
| 254 | if (fd >= 0) |
| 255 | { |
| 256 | rdLen = pread(fd, response.data(), bufLen, 0); |
| 257 | } |
| 258 | |
| 259 | if (rdLen > 0) |
| 260 | { |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 261 | try |
| 262 | { |
Zhikui Ren | d3da128 | 2020-09-11 17:02:01 -0700 | [diff] [blame] | 263 | rawValue = std::stod(response); |
Thu Nguyen | 255da6b | 2022-07-29 10:05:52 +0700 | [diff] [blame] | 264 | double nvalue = rawValue / IntelCPUSensor::sensorScaleFactor; |
Josh Lehan | 833661a | 2020-03-04 17:35:41 -0800 | [diff] [blame] | 265 | |
| 266 | if (show) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 267 | { |
Josh Lehan | 833661a | 2020-03-04 17:35:41 -0800 | [diff] [blame] | 268 | updateValue(nvalue); |
Jae Hyun Yoo | 73ca551 | 2019-02-28 21:20:17 -0800 | [diff] [blame] | 269 | } |
Josh Lehan | 833661a | 2020-03-04 17:35:41 -0800 | [diff] [blame] | 270 | else |
| 271 | { |
| 272 | value = nvalue; |
| 273 | } |
Zbigniew Kurzynski | 98be984 | 2020-09-07 18:49:15 +0200 | [diff] [blame] | 274 | if (minMaxReadCounter++ % 8 == 0) |
| 275 | { |
| 276 | updateMinMaxValues(); |
| 277 | } |
Josh Lehan | 833661a | 2020-03-04 17:35:41 -0800 | [diff] [blame] | 278 | |
Jae Hyun Yoo | 73ca551 | 2019-02-28 21:20:17 -0800 | [diff] [blame] | 279 | double gTcontrol = gCpuSensors[nameTcontrol] |
| 280 | ? gCpuSensors[nameTcontrol]->value |
| 281 | : std::numeric_limits<double>::quiet_NaN(); |
| 282 | if (gTcontrol != privTcontrol) |
| 283 | { |
| 284 | privTcontrol = gTcontrol; |
| 285 | |
| 286 | if (!thresholds.empty()) |
| 287 | { |
| 288 | std::vector<thresholds::Threshold> newThresholds; |
Thu Nguyen | 255da6b | 2022-07-29 10:05:52 +0700 | [diff] [blame] | 289 | if (parseThresholdsFromAttr( |
| 290 | newThresholds, path, |
| 291 | IntelCPUSensor::sensorScaleFactor, dtsOffset)) |
Jae Hyun Yoo | 73ca551 | 2019-02-28 21:20:17 -0800 | [diff] [blame] | 292 | { |
| 293 | if (!std::equal(thresholds.begin(), thresholds.end(), |
| 294 | newThresholds.begin(), |
| 295 | newThresholds.end())) |
| 296 | { |
| 297 | thresholds = newThresholds; |
| 298 | if (show) |
| 299 | { |
| 300 | thresholds::updateThresholds(this); |
| 301 | } |
| 302 | } |
| 303 | } |
| 304 | else |
| 305 | { |
| 306 | std::cerr << "Failure to update thresholds for " << name |
| 307 | << "\n"; |
| 308 | } |
Jae Hyun Yoo | 95b8a2d | 2019-02-25 20:15:09 -0800 | [diff] [blame] | 309 | } |
| 310 | } |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 311 | } |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 312 | catch (const std::invalid_argument&) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 313 | { |
James Feist | 961bf09 | 2020-07-01 16:38:12 -0700 | [diff] [blame] | 314 | incrementError(); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 315 | } |
| 316 | } |
| 317 | else |
| 318 | { |
James Feist | 1169eb4 | 2018-10-31 10:08:47 -0700 | [diff] [blame] | 319 | pollTime = sensorFailedPollTimeMs; |
James Feist | 961bf09 | 2020-07-01 16:38:12 -0700 | [diff] [blame] | 320 | incrementError(); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 321 | } |
Arun Lal K M | 8454571 | 2021-12-31 13:29:56 +0000 | [diff] [blame] | 322 | restartRead(); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 323 | } |
| 324 | |
Thu Nguyen | 255da6b | 2022-07-29 10:05:52 +0700 | [diff] [blame] | 325 | void IntelCPUSensor::checkThresholds(void) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 326 | { |
Jae Hyun Yoo | 73ca551 | 2019-02-28 21:20:17 -0800 | [diff] [blame] | 327 | if (show) |
| 328 | { |
| 329 | thresholds::checkThresholds(this); |
| 330 | } |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 331 | } |