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