Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 1 | #include "config.h" |
| 2 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 3 | #include "occ_manager.hpp" |
| 4 | |
| 5 | #include "i2c_occ.hpp" |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 6 | #include "occ_dbus.hpp" |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 7 | #include "utils.hpp" |
| 8 | |
George Liu | b5ca101 | 2021-09-10 12:53:11 +0800 | [diff] [blame] | 9 | #include <phosphor-logging/elog-errors.hpp> |
| 10 | #include <phosphor-logging/log.hpp> |
| 11 | #include <xyz/openbmc_project/Common/error.hpp> |
| 12 | |
Matt Spinler | d267cec | 2021-09-01 14:49:19 -0500 | [diff] [blame] | 13 | #include <chrono> |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 14 | #include <cmath> |
George Liu | bcef3b4 | 2021-09-10 12:39:02 +0800 | [diff] [blame] | 15 | #include <filesystem> |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 16 | #include <fstream> |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 17 | #include <regex> |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 18 | |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 19 | namespace open_power |
| 20 | { |
| 21 | namespace occ |
| 22 | { |
| 23 | |
Matt Spinler | 8b8abee | 2021-08-25 15:18:21 -0500 | [diff] [blame] | 24 | constexpr uint32_t fruTypeNotAvailable = 0xFF; |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 25 | constexpr auto fruTypeSuffix = "fru_type"; |
| 26 | constexpr auto faultSuffix = "fault"; |
| 27 | constexpr auto inputSuffix = "input"; |
Matt Spinler | ace67d8 | 2021-10-18 13:41:57 -0500 | [diff] [blame] | 28 | constexpr auto maxSuffix = "max"; |
Matt Spinler | 8b8abee | 2021-08-25 15:18:21 -0500 | [diff] [blame] | 29 | |
Chris Cain | 1718fd8 | 2022-02-16 16:39:50 -0600 | [diff] [blame] | 30 | const auto HOST_ON_FILE = "/run/openbmc/host@0-on"; |
| 31 | |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 32 | using namespace phosphor::logging; |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 33 | using namespace std::literals::chrono_literals; |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 34 | |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 35 | template <typename T> |
| 36 | T readFile(const std::string& path) |
| 37 | { |
| 38 | std::ifstream ifs; |
| 39 | ifs.exceptions(std::ifstream::failbit | std::ifstream::badbit | |
| 40 | std::ifstream::eofbit); |
| 41 | T data; |
| 42 | |
| 43 | try |
| 44 | { |
| 45 | ifs.open(path); |
| 46 | ifs >> data; |
| 47 | ifs.close(); |
| 48 | } |
| 49 | catch (const std::exception& e) |
| 50 | { |
| 51 | auto err = errno; |
| 52 | throw std::system_error(err, std::generic_category()); |
| 53 | } |
| 54 | |
| 55 | return data; |
| 56 | } |
| 57 | |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 58 | void Manager::findAndCreateObjects() |
| 59 | { |
Matt Spinler | d267cec | 2021-09-01 14:49:19 -0500 | [diff] [blame] | 60 | #ifndef POWER10 |
Deepak Kodihalli | 370f06b | 2017-10-25 04:26:07 -0500 | [diff] [blame] | 61 | for (auto id = 0; id < MAX_CPUS; ++id) |
| 62 | { |
Deepak Kodihalli | 30417a1 | 2017-12-04 00:54:01 -0600 | [diff] [blame] | 63 | // Create one occ per cpu |
| 64 | auto occ = std::string(OCC_NAME) + std::to_string(id); |
| 65 | createObjects(occ); |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 66 | } |
Matt Spinler | d267cec | 2021-09-01 14:49:19 -0500 | [diff] [blame] | 67 | #else |
Chris Cain | 613dc90 | 2022-04-08 09:56:22 -0500 | [diff] [blame] | 68 | if (!pmode) |
| 69 | { |
| 70 | // Create the power mode object |
| 71 | pmode = std::make_unique<powermode::PowerMode>( |
| 72 | *this, powermode::PMODE_PATH, powermode::PIPS_PATH, event); |
| 73 | } |
| 74 | |
Chris Cain | 1718fd8 | 2022-02-16 16:39:50 -0600 | [diff] [blame] | 75 | if (!fs::exists(HOST_ON_FILE)) |
Matt Spinler | d267cec | 2021-09-01 14:49:19 -0500 | [diff] [blame] | 76 | { |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 77 | static bool statusObjCreated = false; |
| 78 | if (!statusObjCreated) |
Chris Cain | 1718fd8 | 2022-02-16 16:39:50 -0600 | [diff] [blame] | 79 | { |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 80 | // Create the OCCs based on on the /dev/occX devices |
| 81 | auto occs = findOCCsInDev(); |
Chris Cain | 1718fd8 | 2022-02-16 16:39:50 -0600 | [diff] [blame] | 82 | |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 83 | if (occs.empty() || (prevOCCSearch.size() != occs.size())) |
Chris Cain | 1718fd8 | 2022-02-16 16:39:50 -0600 | [diff] [blame] | 84 | { |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 85 | // Something changed or no OCCs yet, try again in 10s. |
| 86 | // Note on the first pass prevOCCSearch will be empty, |
| 87 | // so there will be at least one delay to give things |
| 88 | // a chance to settle. |
| 89 | prevOCCSearch = occs; |
| 90 | |
| 91 | log<level::INFO>( |
| 92 | fmt::format( |
| 93 | "Manager::findAndCreateObjects(): Waiting for OCCs (currently {})", |
| 94 | occs.size()) |
| 95 | .c_str()); |
| 96 | |
| 97 | discoverTimer->restartOnce(10s); |
| 98 | } |
| 99 | else |
| 100 | { |
| 101 | // All OCCs appear to be available, create status objects |
| 102 | |
| 103 | // createObjects requires OCC0 first. |
| 104 | std::sort(occs.begin(), occs.end()); |
| 105 | |
| 106 | log<level::INFO>( |
| 107 | fmt::format( |
| 108 | "Manager::findAndCreateObjects(): Creating {} OCC Status Objects", |
| 109 | occs.size()) |
| 110 | .c_str()); |
| 111 | for (auto id : occs) |
| 112 | { |
| 113 | createObjects(std::string(OCC_NAME) + std::to_string(id)); |
| 114 | } |
| 115 | statusObjCreated = true; |
Chris Cain | 6d8f37a | 2022-04-29 13:46:01 -0500 | [diff] [blame] | 116 | waitingForAllOccActiveSensors = true; |
Chris Cain | c86d80f | 2023-05-04 15:49:18 -0500 | [diff] [blame] | 117 | |
| 118 | // Find/update the processor path associated with each OCC |
| 119 | for (auto& obj : statusObjects) |
| 120 | { |
| 121 | obj->updateProcAssociation(); |
| 122 | } |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 123 | } |
| 124 | } |
| 125 | |
Chris Cain | 6d8f37a | 2022-04-29 13:46:01 -0500 | [diff] [blame] | 126 | if (statusObjCreated && waitingForAllOccActiveSensors) |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 127 | { |
| 128 | static bool tracedHostWait = false; |
| 129 | if (utils::isHostRunning()) |
| 130 | { |
| 131 | if (tracedHostWait) |
| 132 | { |
| 133 | log<level::INFO>( |
| 134 | "Manager::findAndCreateObjects(): Host is running"); |
| 135 | tracedHostWait = false; |
| 136 | } |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 137 | checkAllActiveSensors(); |
| 138 | } |
| 139 | else |
| 140 | { |
| 141 | if (!tracedHostWait) |
| 142 | { |
| 143 | log<level::INFO>( |
| 144 | "Manager::findAndCreateObjects(): Waiting for host to start"); |
| 145 | tracedHostWait = true; |
| 146 | } |
| 147 | discoverTimer->restartOnce(30s); |
Chris Cain | 1718fd8 | 2022-02-16 16:39:50 -0600 | [diff] [blame] | 148 | } |
| 149 | } |
Matt Spinler | d267cec | 2021-09-01 14:49:19 -0500 | [diff] [blame] | 150 | } |
| 151 | else |
| 152 | { |
Chris Cain | 1718fd8 | 2022-02-16 16:39:50 -0600 | [diff] [blame] | 153 | log<level::INFO>( |
| 154 | fmt::format( |
| 155 | "Manager::findAndCreateObjects(): Waiting for {} to complete...", |
| 156 | HOST_ON_FILE) |
| 157 | .c_str()); |
| 158 | discoverTimer->restartOnce(10s); |
Matt Spinler | d267cec | 2021-09-01 14:49:19 -0500 | [diff] [blame] | 159 | } |
| 160 | #endif |
| 161 | } |
| 162 | |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 163 | #ifdef POWER10 |
| 164 | // Check if all occActive sensors are available |
| 165 | void Manager::checkAllActiveSensors() |
| 166 | { |
| 167 | static bool allActiveSensorAvailable = false; |
| 168 | static bool tracedSensorWait = false; |
Chris Cain | 082a6ca | 2023-03-21 10:27:26 -0500 | [diff] [blame] | 169 | static bool waitingForHost = false; |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 170 | |
Chris Cain | 082a6ca | 2023-03-21 10:27:26 -0500 | [diff] [blame] | 171 | if (open_power::occ::utils::isHostRunning()) |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 172 | { |
Chris Cain | 082a6ca | 2023-03-21 10:27:26 -0500 | [diff] [blame] | 173 | if (waitingForHost) |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 174 | { |
Chris Cain | 082a6ca | 2023-03-21 10:27:26 -0500 | [diff] [blame] | 175 | waitingForHost = false; |
| 176 | log<level::INFO>("checkAllActiveSensors(): Host is now running"); |
| 177 | } |
| 178 | |
| 179 | // Start with the assumption that all are available |
| 180 | allActiveSensorAvailable = true; |
| 181 | for (auto& obj : statusObjects) |
| 182 | { |
| 183 | if ((!obj->occActive()) && (!obj->getPldmSensorReceived())) |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 184 | { |
Chris Cain | 7f89e4d | 2022-05-09 13:27:45 -0500 | [diff] [blame] | 185 | auto instance = obj->getOccInstanceID(); |
| 186 | // Check if sensor was queued while waiting for discovery |
| 187 | auto match = queuedActiveState.find(instance); |
| 188 | if (match != queuedActiveState.end()) |
Chris Cain | bd551de | 2022-04-26 13:41:16 -0500 | [diff] [blame] | 189 | { |
Chris Cain | 7f89e4d | 2022-05-09 13:27:45 -0500 | [diff] [blame] | 190 | queuedActiveState.erase(match); |
Chris Cain | bd551de | 2022-04-26 13:41:16 -0500 | [diff] [blame] | 191 | log<level::INFO>( |
| 192 | fmt::format( |
Chris Cain | 7f89e4d | 2022-05-09 13:27:45 -0500 | [diff] [blame] | 193 | "checkAllActiveSensors(): OCC{} is ACTIVE (queued)", |
Chris Cain | bd551de | 2022-04-26 13:41:16 -0500 | [diff] [blame] | 194 | instance) |
| 195 | .c_str()); |
Chris Cain | 7f89e4d | 2022-05-09 13:27:45 -0500 | [diff] [blame] | 196 | obj->occActive(true); |
Chris Cain | bd551de | 2022-04-26 13:41:16 -0500 | [diff] [blame] | 197 | } |
Chris Cain | 7f89e4d | 2022-05-09 13:27:45 -0500 | [diff] [blame] | 198 | else |
| 199 | { |
| 200 | allActiveSensorAvailable = false; |
| 201 | if (!tracedSensorWait) |
| 202 | { |
| 203 | log<level::INFO>( |
| 204 | fmt::format( |
| 205 | "checkAllActiveSensors(): Waiting on OCC{} Active sensor", |
| 206 | instance) |
| 207 | .c_str()); |
| 208 | tracedSensorWait = true; |
| 209 | } |
| 210 | pldmHandle->checkActiveSensor(obj->getOccInstanceID()); |
| 211 | break; |
| 212 | } |
Chris Cain | bd551de | 2022-04-26 13:41:16 -0500 | [diff] [blame] | 213 | } |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 214 | } |
| 215 | } |
Chris Cain | 082a6ca | 2023-03-21 10:27:26 -0500 | [diff] [blame] | 216 | else |
| 217 | { |
| 218 | if (!waitingForHost) |
| 219 | { |
| 220 | waitingForHost = true; |
| 221 | log<level::INFO>( |
| 222 | "checkAllActiveSensors(): Waiting for host to start"); |
| 223 | } |
| 224 | } |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 225 | |
| 226 | if (allActiveSensorAvailable) |
| 227 | { |
| 228 | // All sensors were found, disable the discovery timer |
Chris Cain | 7f89e4d | 2022-05-09 13:27:45 -0500 | [diff] [blame] | 229 | if (discoverTimer->isEnabled()) |
| 230 | { |
Chris Cain | f55f91a | 2022-05-27 13:40:15 -0500 | [diff] [blame] | 231 | discoverTimer->setEnabled(false); |
Chris Cain | 7f89e4d | 2022-05-09 13:27:45 -0500 | [diff] [blame] | 232 | } |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 233 | |
Chris Cain | 7f89e4d | 2022-05-09 13:27:45 -0500 | [diff] [blame] | 234 | if (waitingForAllOccActiveSensors) |
| 235 | { |
| 236 | log<level::INFO>( |
| 237 | "checkAllActiveSensors(): OCC Active sensors are available"); |
| 238 | waitingForAllOccActiveSensors = false; |
| 239 | } |
| 240 | queuedActiveState.clear(); |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 241 | tracedSensorWait = false; |
| 242 | } |
| 243 | else |
| 244 | { |
| 245 | // Not all sensors were available, so keep waiting |
| 246 | if (!tracedSensorWait) |
| 247 | { |
| 248 | log<level::INFO>( |
Chris Cain | bd551de | 2022-04-26 13:41:16 -0500 | [diff] [blame] | 249 | "checkAllActiveSensors(): Waiting for OCC Active sensors to become available"); |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 250 | tracedSensorWait = true; |
| 251 | } |
Chris Cain | f55f91a | 2022-05-27 13:40:15 -0500 | [diff] [blame] | 252 | discoverTimer->restartOnce(10s); |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 253 | } |
| 254 | } |
| 255 | #endif |
| 256 | |
Matt Spinler | d267cec | 2021-09-01 14:49:19 -0500 | [diff] [blame] | 257 | std::vector<int> Manager::findOCCsInDev() |
| 258 | { |
| 259 | std::vector<int> occs; |
| 260 | std::regex expr{R"(occ(\d+)$)"}; |
| 261 | |
| 262 | for (auto& file : fs::directory_iterator("/dev")) |
| 263 | { |
| 264 | std::smatch match; |
| 265 | std::string path{file.path().string()}; |
| 266 | if (std::regex_search(path, match, expr)) |
| 267 | { |
| 268 | auto num = std::stoi(match[1].str()); |
| 269 | |
| 270 | // /dev numbering starts at 1, ours starts at 0. |
| 271 | occs.push_back(num - 1); |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | return occs; |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 276 | } |
| 277 | |
Patrick Williams | af40808 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 278 | int Manager::cpuCreated(sdbusplus::message_t& msg) |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 279 | { |
George Liu | bcef3b4 | 2021-09-10 12:39:02 +0800 | [diff] [blame] | 280 | namespace fs = std::filesystem; |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 281 | |
| 282 | sdbusplus::message::object_path o; |
| 283 | msg.read(o); |
| 284 | fs::path cpuPath(std::string(std::move(o))); |
| 285 | |
| 286 | auto name = cpuPath.filename().string(); |
| 287 | auto index = name.find(CPU_NAME); |
| 288 | name.replace(index, std::strlen(CPU_NAME), OCC_NAME); |
| 289 | |
| 290 | createObjects(name); |
| 291 | |
| 292 | return 0; |
| 293 | } |
| 294 | |
| 295 | void Manager::createObjects(const std::string& occ) |
| 296 | { |
| 297 | auto path = fs::path(OCC_CONTROL_ROOT) / occ; |
| 298 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 299 | statusObjects.emplace_back(std::make_unique<Status>( |
George Liu | f3b7514 | 2021-06-10 11:22:50 +0800 | [diff] [blame] | 300 | event, path.c_str(), *this, |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 301 | #ifdef POWER10 |
| 302 | pmode, |
| 303 | #endif |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 304 | std::bind(std::mem_fn(&Manager::statusCallBack), this, |
Sheldon Bailey | 373af75 | 2022-02-21 15:14:00 -0600 | [diff] [blame] | 305 | std::placeholders::_1, std::placeholders::_2) |
Tom Joseph | 0032523 | 2020-07-29 17:51:48 +0530 | [diff] [blame] | 306 | #ifdef PLDM |
| 307 | , |
| 308 | std::bind(std::mem_fn(&pldm::Interface::resetOCC), pldmHandle.get(), |
| 309 | std::placeholders::_1) |
| 310 | #endif |
| 311 | )); |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 312 | |
Chris Cain | 40501a2 | 2022-03-14 17:33:27 -0500 | [diff] [blame] | 313 | // Create the power cap monitor object |
| 314 | if (!pcap) |
| 315 | { |
| 316 | pcap = std::make_unique<open_power::occ::powercap::PowerCap>( |
| 317 | *statusObjects.back()); |
| 318 | } |
| 319 | |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 320 | if (statusObjects.back()->isMasterOcc()) |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 321 | { |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 322 | log<level::INFO>( |
| 323 | fmt::format("Manager::createObjects(): OCC{} is the master", |
| 324 | statusObjects.back()->getOccInstanceID()) |
| 325 | .c_str()); |
| 326 | _pollTimer->setEnabled(false); |
| 327 | |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 328 | #ifdef POWER10 |
Chris Cain | 6fa848a | 2022-01-24 14:54:38 -0600 | [diff] [blame] | 329 | // Set the master OCC on the PowerMode object |
| 330 | pmode->setMasterOcc(path); |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 331 | #endif |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | passThroughObjects.emplace_back(std::make_unique<PassThrough>(path.c_str() |
| 335 | #ifdef POWER10 |
| 336 | , |
| 337 | pmode |
| 338 | #endif |
| 339 | )); |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 340 | } |
| 341 | |
Sheldon Bailey | 373af75 | 2022-02-21 15:14:00 -0600 | [diff] [blame] | 342 | void Manager::statusCallBack(instanceID instance, bool status) |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 343 | { |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 344 | if (status == true) |
Eddie James | dae2d94 | 2017-12-20 10:50:03 -0600 | [diff] [blame] | 345 | { |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 346 | // OCC went active |
| 347 | ++activeCount; |
| 348 | |
| 349 | #ifdef POWER10 |
| 350 | if (activeCount == 1) |
Eddie James | dae2d94 | 2017-12-20 10:50:03 -0600 | [diff] [blame] | 351 | { |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 352 | // First OCC went active (allow some time for all OCCs to go active) |
Chris Cain | bd551de | 2022-04-26 13:41:16 -0500 | [diff] [blame] | 353 | waitForAllOccsTimer->restartOnce(60s); |
Matt Spinler | 53f6814 | 2021-08-25 15:47:31 -0500 | [diff] [blame] | 354 | } |
| 355 | #endif |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 356 | |
| 357 | if (activeCount == statusObjects.size()) |
| 358 | { |
| 359 | #ifdef POWER10 |
| 360 | // All OCCs are now running |
| 361 | if (waitForAllOccsTimer->isEnabled()) |
| 362 | { |
| 363 | // stop occ wait timer |
| 364 | waitForAllOccsTimer->setEnabled(false); |
| 365 | } |
| 366 | #endif |
| 367 | |
| 368 | // Verify master OCC and start presence monitor |
| 369 | validateOccMaster(); |
| 370 | } |
| 371 | |
| 372 | // Start poll timer if not already started |
| 373 | if (!_pollTimer->isEnabled()) |
| 374 | { |
| 375 | log<level::INFO>( |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 376 | fmt::format("Manager: OCCs will be polled every {} seconds", |
| 377 | pollInterval) |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 378 | .c_str()); |
| 379 | |
| 380 | // Send poll and start OCC poll timer |
| 381 | pollerTimerExpired(); |
| 382 | } |
| 383 | } |
| 384 | else |
| 385 | { |
| 386 | // OCC went away |
Chris Cain | 082a6ca | 2023-03-21 10:27:26 -0500 | [diff] [blame] | 387 | if (activeCount > 0) |
| 388 | { |
| 389 | --activeCount; |
| 390 | } |
| 391 | else |
| 392 | { |
| 393 | log<level::ERR>( |
| 394 | fmt::format("OCC{} disabled, but currently no active OCCs", |
| 395 | instance) |
| 396 | .c_str()); |
| 397 | } |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 398 | |
| 399 | if (activeCount == 0) |
| 400 | { |
| 401 | // No OCCs are running |
| 402 | |
| 403 | // Stop OCC poll timer |
| 404 | if (_pollTimer->isEnabled()) |
| 405 | { |
| 406 | log<level::INFO>( |
| 407 | "Manager::statusCallBack(): OCCs are not running, stopping poll timer"); |
| 408 | _pollTimer->setEnabled(false); |
| 409 | } |
| 410 | |
| 411 | #ifdef POWER10 |
| 412 | // stop wait timer |
| 413 | if (waitForAllOccsTimer->isEnabled()) |
| 414 | { |
| 415 | waitForAllOccsTimer->setEnabled(false); |
| 416 | } |
| 417 | #endif |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 418 | } |
Sheldon Bailey | 373af75 | 2022-02-21 15:14:00 -0600 | [diff] [blame] | 419 | #ifdef READ_OCC_SENSORS |
| 420 | // Clear OCC sensors |
Sheldon Bailey | c8dd459 | 2022-05-12 10:15:14 -0500 | [diff] [blame] | 421 | setSensorValueToNaN(instance); |
Sheldon Bailey | 373af75 | 2022-02-21 15:14:00 -0600 | [diff] [blame] | 422 | #endif |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 423 | } |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 424 | |
| 425 | #ifdef POWER10 |
| 426 | if (waitingForAllOccActiveSensors) |
| 427 | { |
Chris Cain | 6d8f37a | 2022-04-29 13:46:01 -0500 | [diff] [blame] | 428 | if (utils::isHostRunning()) |
| 429 | { |
| 430 | checkAllActiveSensors(); |
| 431 | } |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 432 | } |
| 433 | #endif |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | #ifdef I2C_OCC |
| 437 | void Manager::initStatusObjects() |
| 438 | { |
| 439 | // Make sure we have a valid path string |
| 440 | static_assert(sizeof(DEV_PATH) != 0); |
| 441 | |
| 442 | auto deviceNames = i2c_occ::getOccHwmonDevices(DEV_PATH); |
| 443 | for (auto& name : deviceNames) |
| 444 | { |
| 445 | i2c_occ::i2cToDbus(name); |
Lei YU | b5259a1 | 2017-09-01 16:22:40 +0800 | [diff] [blame] | 446 | name = std::string(OCC_NAME) + '_' + name; |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 447 | auto path = fs::path(OCC_CONTROL_ROOT) / name; |
| 448 | statusObjects.emplace_back( |
George Liu | f3b7514 | 2021-06-10 11:22:50 +0800 | [diff] [blame] | 449 | std::make_unique<Status>(event, path.c_str(), *this)); |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 450 | } |
Chris Cain | 40501a2 | 2022-03-14 17:33:27 -0500 | [diff] [blame] | 451 | // The first device is master occ |
| 452 | pcap = std::make_unique<open_power::occ::powercap::PowerCap>( |
| 453 | *statusObjects.front()); |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 454 | #ifdef POWER10 |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 455 | pmode = std::make_unique<powermode::PowerMode>(*this, powermode::PMODE_PATH, |
| 456 | powermode::PIPS_PATH); |
Chris Cain | 6fa848a | 2022-01-24 14:54:38 -0600 | [diff] [blame] | 457 | // Set the master OCC on the PowerMode object |
| 458 | pmode->setMasterOcc(path); |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 459 | #endif |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 460 | } |
| 461 | #endif |
| 462 | |
Tom Joseph | 815f9f5 | 2020-07-27 12:12:13 +0530 | [diff] [blame] | 463 | #ifdef PLDM |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 464 | void Manager::sbeTimeout(unsigned int instance) |
| 465 | { |
Eddie James | 2a751d7 | 2022-03-04 09:16:12 -0600 | [diff] [blame] | 466 | auto obj = std::find_if(statusObjects.begin(), statusObjects.end(), |
| 467 | [instance](const auto& obj) { |
Patrick Williams | a49c987 | 2023-05-10 07:50:35 -0500 | [diff] [blame] | 468 | return instance == obj->getOccInstanceID(); |
| 469 | }); |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 470 | |
Eddie James | cb018da | 2022-03-05 11:49:37 -0600 | [diff] [blame] | 471 | if (obj != statusObjects.end() && (*obj)->occActive()) |
Eddie James | 2a751d7 | 2022-03-04 09:16:12 -0600 | [diff] [blame] | 472 | { |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 473 | log<level::INFO>( |
| 474 | fmt::format("SBE timeout, requesting HRESET (OCC{})", instance) |
| 475 | .c_str()); |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 476 | |
Eddie James | 2a751d7 | 2022-03-04 09:16:12 -0600 | [diff] [blame] | 477 | setSBEState(instance, SBE_STATE_NOT_USABLE); |
| 478 | |
| 479 | pldmHandle->sendHRESET(instance); |
| 480 | } |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 481 | } |
| 482 | |
Tom Joseph | 815f9f5 | 2020-07-27 12:12:13 +0530 | [diff] [blame] | 483 | bool Manager::updateOCCActive(instanceID instance, bool status) |
| 484 | { |
Chris Cain | 7e374fb | 2022-04-07 09:47:23 -0500 | [diff] [blame] | 485 | auto obj = std::find_if(statusObjects.begin(), statusObjects.end(), |
| 486 | [instance](const auto& obj) { |
Patrick Williams | a49c987 | 2023-05-10 07:50:35 -0500 | [diff] [blame] | 487 | return instance == obj->getOccInstanceID(); |
| 488 | }); |
Chris Cain | 7e374fb | 2022-04-07 09:47:23 -0500 | [diff] [blame] | 489 | |
Chris Cain | 082a6ca | 2023-03-21 10:27:26 -0500 | [diff] [blame] | 490 | const bool hostRunning = open_power::occ::utils::isHostRunning(); |
Chris Cain | 7e374fb | 2022-04-07 09:47:23 -0500 | [diff] [blame] | 491 | if (obj != statusObjects.end()) |
| 492 | { |
Chris Cain | 082a6ca | 2023-03-21 10:27:26 -0500 | [diff] [blame] | 493 | if (!hostRunning && (status == true)) |
| 494 | { |
| 495 | log<level::WARNING>( |
| 496 | fmt::format( |
| 497 | "updateOCCActive: Host is not running yet (OCC{} active={}), clearing sensor received", |
| 498 | instance, status) |
| 499 | .c_str()); |
| 500 | (*obj)->setPldmSensorReceived(false); |
| 501 | if (!waitingForAllOccActiveSensors) |
| 502 | { |
| 503 | log<level::INFO>( |
| 504 | "updateOCCActive: Waiting for Host and all OCC Active Sensors"); |
| 505 | waitingForAllOccActiveSensors = true; |
| 506 | } |
| 507 | discoverTimer->restartOnce(30s); |
| 508 | return false; |
| 509 | } |
| 510 | else |
| 511 | { |
| 512 | log<level::INFO>(fmt::format("updateOCCActive: OCC{} active={}", |
| 513 | instance, status) |
| 514 | .c_str()); |
| 515 | (*obj)->setPldmSensorReceived(true); |
| 516 | return (*obj)->occActive(status); |
| 517 | } |
Chris Cain | 7e374fb | 2022-04-07 09:47:23 -0500 | [diff] [blame] | 518 | } |
| 519 | else |
| 520 | { |
Chris Cain | 082a6ca | 2023-03-21 10:27:26 -0500 | [diff] [blame] | 521 | if (hostRunning) |
| 522 | { |
| 523 | log<level::WARNING>( |
| 524 | fmt::format( |
| 525 | "updateOCCActive: No status object to update for OCC{} (active={})", |
| 526 | instance, status) |
| 527 | .c_str()); |
| 528 | } |
| 529 | else |
| 530 | { |
| 531 | if (status == true) |
| 532 | { |
| 533 | log<level::WARNING>( |
| 534 | fmt::format( |
| 535 | "updateOCCActive: No status objects and Host is not running yet (OCC{} active={})", |
| 536 | instance, status) |
| 537 | .c_str()); |
| 538 | } |
| 539 | } |
Chris Cain | bd551de | 2022-04-26 13:41:16 -0500 | [diff] [blame] | 540 | if (status == true) |
| 541 | { |
| 542 | // OCC went active |
| 543 | queuedActiveState.insert(instance); |
| 544 | } |
| 545 | else |
| 546 | { |
| 547 | auto match = queuedActiveState.find(instance); |
| 548 | if (match != queuedActiveState.end()) |
| 549 | { |
| 550 | // OCC was disabled |
| 551 | queuedActiveState.erase(match); |
| 552 | } |
| 553 | } |
Chris Cain | 7e374fb | 2022-04-07 09:47:23 -0500 | [diff] [blame] | 554 | return false; |
| 555 | } |
Tom Joseph | 815f9f5 | 2020-07-27 12:12:13 +0530 | [diff] [blame] | 556 | } |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 557 | |
Sheldon Bailey | 31a2f13 | 2022-05-20 11:31:52 -0500 | [diff] [blame] | 558 | // Called upon pldm event To set powermode Safe Mode State for system. |
| 559 | void Manager::updateOccSafeMode(bool safeMode) |
| 560 | { |
| 561 | #ifdef POWER10 |
| 562 | pmode->updateDbusSafeMode(safeMode); |
| 563 | #endif |
Chris Cain | c86d80f | 2023-05-04 15:49:18 -0500 | [diff] [blame] | 564 | // Update the processor throttle status on dbus |
| 565 | for (auto& obj : statusObjects) |
| 566 | { |
| 567 | obj->updateThrottle(safeMode, THROTTLED_SAFE); |
| 568 | } |
Sheldon Bailey | 31a2f13 | 2022-05-20 11:31:52 -0500 | [diff] [blame] | 569 | } |
| 570 | |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 571 | void Manager::sbeHRESETResult(instanceID instance, bool success) |
| 572 | { |
| 573 | if (success) |
| 574 | { |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 575 | log<level::INFO>( |
| 576 | fmt::format("HRESET succeeded (OCC{})", instance).c_str()); |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 577 | |
| 578 | setSBEState(instance, SBE_STATE_BOOTED); |
| 579 | |
| 580 | return; |
| 581 | } |
| 582 | |
| 583 | setSBEState(instance, SBE_STATE_FAILED); |
| 584 | |
| 585 | if (sbeCanDump(instance)) |
| 586 | { |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 587 | log<level::INFO>( |
| 588 | fmt::format("HRESET failed (OCC{}), triggering SBE dump", instance) |
| 589 | .c_str()); |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 590 | |
| 591 | auto& bus = utils::getBus(); |
| 592 | uint32_t src6 = instance << 16; |
| 593 | uint32_t logId = |
| 594 | FFDC::createPEL("org.open_power.Processor.Error.SbeChipOpTimeout", |
| 595 | src6, "SBE command timeout"); |
| 596 | |
| 597 | try |
| 598 | { |
George Liu | f3a4a69 | 2021-12-28 13:59:51 +0800 | [diff] [blame] | 599 | constexpr auto path = "/org/openpower/dump"; |
| 600 | constexpr auto interface = "xyz.openbmc_project.Dump.Create"; |
| 601 | constexpr auto function = "CreateDump"; |
| 602 | |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 603 | std::string service = utils::getService(path, interface); |
Patrick Williams | a49c987 | 2023-05-10 07:50:35 -0500 | [diff] [blame] | 604 | auto method = bus.new_method_call(service.c_str(), path, interface, |
| 605 | function); |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 606 | |
| 607 | std::map<std::string, std::variant<std::string, uint64_t>> |
| 608 | createParams{ |
| 609 | {"com.ibm.Dump.Create.CreateParameters.ErrorLogId", |
| 610 | uint64_t(logId)}, |
| 611 | {"com.ibm.Dump.Create.CreateParameters.DumpType", |
| 612 | "com.ibm.Dump.Create.DumpType.SBE"}, |
| 613 | {"com.ibm.Dump.Create.CreateParameters.FailingUnitId", |
| 614 | uint64_t(instance)}, |
| 615 | }; |
| 616 | |
| 617 | method.append(createParams); |
| 618 | |
| 619 | auto response = bus.call(method); |
| 620 | } |
Patrick Williams | af40808 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 621 | catch (const sdbusplus::exception_t& e) |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 622 | { |
| 623 | constexpr auto ERROR_DUMP_DISABLED = |
| 624 | "xyz.openbmc_project.Dump.Create.Error.Disabled"; |
| 625 | if (e.name() == ERROR_DUMP_DISABLED) |
| 626 | { |
| 627 | log<level::INFO>("Dump is disabled, skipping"); |
| 628 | } |
| 629 | else |
| 630 | { |
| 631 | log<level::ERR>("Dump failed"); |
| 632 | } |
| 633 | } |
| 634 | } |
| 635 | } |
| 636 | |
| 637 | bool Manager::sbeCanDump(unsigned int instance) |
| 638 | { |
| 639 | struct pdbg_target* proc = getPdbgTarget(instance); |
| 640 | |
| 641 | if (!proc) |
| 642 | { |
| 643 | // allow the dump in the error case |
| 644 | return true; |
| 645 | } |
| 646 | |
| 647 | try |
| 648 | { |
| 649 | if (!openpower::phal::sbe::isDumpAllowed(proc)) |
| 650 | { |
| 651 | return false; |
| 652 | } |
| 653 | |
| 654 | if (openpower::phal::pdbg::isSbeVitalAttnActive(proc)) |
| 655 | { |
| 656 | return false; |
| 657 | } |
| 658 | } |
| 659 | catch (openpower::phal::exception::SbeError& e) |
| 660 | { |
| 661 | log<level::INFO>("Failed to query SBE state"); |
| 662 | } |
| 663 | |
| 664 | // allow the dump in the error case |
| 665 | return true; |
| 666 | } |
| 667 | |
| 668 | void Manager::setSBEState(unsigned int instance, enum sbe_state state) |
| 669 | { |
| 670 | struct pdbg_target* proc = getPdbgTarget(instance); |
| 671 | |
| 672 | if (!proc) |
| 673 | { |
| 674 | return; |
| 675 | } |
| 676 | |
| 677 | try |
| 678 | { |
| 679 | openpower::phal::sbe::setState(proc, state); |
| 680 | } |
| 681 | catch (const openpower::phal::exception::SbeError& e) |
| 682 | { |
| 683 | log<level::ERR>("Failed to set SBE state"); |
| 684 | } |
| 685 | } |
| 686 | |
| 687 | struct pdbg_target* Manager::getPdbgTarget(unsigned int instance) |
| 688 | { |
| 689 | if (!pdbgInitialized) |
| 690 | { |
| 691 | try |
| 692 | { |
| 693 | openpower::phal::pdbg::init(); |
| 694 | pdbgInitialized = true; |
| 695 | } |
| 696 | catch (const openpower::phal::exception::PdbgError& e) |
| 697 | { |
| 698 | log<level::ERR>("pdbg initialization failed"); |
| 699 | return nullptr; |
| 700 | } |
| 701 | } |
| 702 | |
| 703 | struct pdbg_target* proc = nullptr; |
| 704 | pdbg_for_each_class_target("proc", proc) |
| 705 | { |
| 706 | if (pdbg_target_index(proc) == instance) |
| 707 | { |
| 708 | return proc; |
| 709 | } |
| 710 | } |
| 711 | |
| 712 | log<level::ERR>("Failed to get pdbg target"); |
| 713 | return nullptr; |
| 714 | } |
Tom Joseph | 815f9f5 | 2020-07-27 12:12:13 +0530 | [diff] [blame] | 715 | #endif |
| 716 | |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 717 | void Manager::pollerTimerExpired() |
| 718 | { |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 719 | if (!_pollTimer) |
| 720 | { |
| 721 | log<level::ERR>( |
| 722 | "Manager::pollerTimerExpired() ERROR: Timer not defined"); |
| 723 | return; |
| 724 | } |
| 725 | |
| 726 | for (auto& obj : statusObjects) |
| 727 | { |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 728 | if (!obj->occActive()) |
| 729 | { |
| 730 | // OCC is not running yet |
| 731 | #ifdef READ_OCC_SENSORS |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 732 | auto id = obj->getOccInstanceID(); |
Sheldon Bailey | c8dd459 | 2022-05-12 10:15:14 -0500 | [diff] [blame] | 733 | setSensorValueToNaN(id); |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 734 | #endif |
| 735 | continue; |
| 736 | } |
| 737 | |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 738 | // Read sysfs to force kernel to poll OCC |
| 739 | obj->readOccState(); |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 740 | |
| 741 | #ifdef READ_OCC_SENSORS |
| 742 | // Read occ sensor values |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 743 | getSensorValues(obj); |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 744 | #endif |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 745 | } |
| 746 | |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 747 | if (activeCount > 0) |
| 748 | { |
| 749 | // Restart OCC poll timer |
| 750 | _pollTimer->restartOnce(std::chrono::seconds(pollInterval)); |
| 751 | } |
| 752 | else |
| 753 | { |
| 754 | // No OCCs running, so poll timer will not be restarted |
| 755 | log<level::INFO>( |
| 756 | fmt::format( |
| 757 | "Manager::pollerTimerExpired: poll timer will not be restarted") |
| 758 | .c_str()); |
| 759 | } |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 760 | } |
| 761 | |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 762 | #ifdef READ_OCC_SENSORS |
Chris Cain | ae157b6 | 2024-01-23 16:05:12 -0600 | [diff] [blame^] | 763 | void Manager::readTempSensors(const fs::path& path, uint32_t occInstance) |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 764 | { |
Matt Spinler | 818cc8d | 2023-10-23 11:43:39 -0500 | [diff] [blame] | 765 | // There may be more than one sensor with the same FRU type |
| 766 | // and label so make two passes: the first to read the temps |
| 767 | // from sysfs, and the second to put them on D-Bus after |
| 768 | // resolving any conflicts. |
| 769 | std::map<std::string, double> sensorData; |
| 770 | |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 771 | std::regex expr{"temp\\d+_label$"}; // Example: temp5_label |
| 772 | for (auto& file : fs::directory_iterator(path)) |
| 773 | { |
| 774 | if (!std::regex_search(file.path().string(), expr)) |
| 775 | { |
| 776 | continue; |
| 777 | } |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 778 | |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 779 | uint32_t labelValue{0}; |
| 780 | |
| 781 | try |
| 782 | { |
| 783 | labelValue = readFile<uint32_t>(file.path()); |
| 784 | } |
| 785 | catch (const std::system_error& e) |
| 786 | { |
| 787 | log<level::DEBUG>( |
| 788 | fmt::format("readTempSensors: Failed reading {}, errno = {}", |
| 789 | file.path().string(), e.code().value()) |
| 790 | .c_str()); |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 791 | continue; |
| 792 | } |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 793 | |
| 794 | const std::string& tempLabel = "label"; |
| 795 | const std::string filePathString = file.path().string().substr( |
| 796 | 0, file.path().string().length() - tempLabel.length()); |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 797 | |
| 798 | uint32_t fruTypeValue{0}; |
| 799 | try |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 800 | { |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 801 | fruTypeValue = readFile<uint32_t>(filePathString + fruTypeSuffix); |
| 802 | } |
| 803 | catch (const std::system_error& e) |
| 804 | { |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 805 | log<level::DEBUG>( |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 806 | fmt::format("readTempSensors: Failed reading {}, errno = {}", |
| 807 | filePathString + fruTypeSuffix, e.code().value()) |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 808 | .c_str()); |
| 809 | continue; |
| 810 | } |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 811 | |
Patrick Williams | a49c987 | 2023-05-10 07:50:35 -0500 | [diff] [blame] | 812 | std::string sensorPath = OCC_SENSORS_ROOT + |
| 813 | std::string("/temperature/"); |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 814 | |
Matt Spinler | ace67d8 | 2021-10-18 13:41:57 -0500 | [diff] [blame] | 815 | std::string dvfsTempPath; |
| 816 | |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 817 | if (fruTypeValue == VRMVdd) |
| 818 | { |
Chris Cain | ae157b6 | 2024-01-23 16:05:12 -0600 | [diff] [blame^] | 819 | sensorPath.append("vrm_vdd" + std::to_string(occInstance) + |
| 820 | "_temp"); |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 821 | } |
Matt Spinler | ace67d8 | 2021-10-18 13:41:57 -0500 | [diff] [blame] | 822 | else if (fruTypeValue == processorIoRing) |
| 823 | { |
Chris Cain | ae157b6 | 2024-01-23 16:05:12 -0600 | [diff] [blame^] | 824 | sensorPath.append("proc" + std::to_string(occInstance) + |
| 825 | "_ioring_temp"); |
Matt Spinler | ace67d8 | 2021-10-18 13:41:57 -0500 | [diff] [blame] | 826 | dvfsTempPath = std::string{OCC_SENSORS_ROOT} + "/temperature/proc" + |
Chris Cain | ae157b6 | 2024-01-23 16:05:12 -0600 | [diff] [blame^] | 827 | std::to_string(occInstance) + "_ioring_dvfs_temp"; |
Matt Spinler | ace67d8 | 2021-10-18 13:41:57 -0500 | [diff] [blame] | 828 | } |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 829 | else |
| 830 | { |
Matt Spinler | 14d1402 | 2021-08-25 15:38:29 -0500 | [diff] [blame] | 831 | uint16_t type = (labelValue & 0xFF000000) >> 24; |
| 832 | uint16_t instanceID = labelValue & 0x0000FFFF; |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 833 | |
| 834 | if (type == OCC_DIMM_TEMP_SENSOR_TYPE) |
| 835 | { |
Matt Spinler | 8b8abee | 2021-08-25 15:18:21 -0500 | [diff] [blame] | 836 | if (fruTypeValue == fruTypeNotAvailable) |
| 837 | { |
| 838 | // Not all DIMM related temps are available to read |
| 839 | // (no _input file in this case) |
| 840 | continue; |
| 841 | } |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 842 | auto iter = dimmTempSensorName.find(fruTypeValue); |
| 843 | if (iter == dimmTempSensorName.end()) |
| 844 | { |
George Liu | b5ca101 | 2021-09-10 12:53:11 +0800 | [diff] [blame] | 845 | log<level::ERR>( |
| 846 | fmt::format( |
| 847 | "readTempSensors: Fru type error! fruTypeValue = {}) ", |
| 848 | fruTypeValue) |
| 849 | .c_str()); |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 850 | continue; |
| 851 | } |
| 852 | |
| 853 | sensorPath.append("dimm" + std::to_string(instanceID) + |
| 854 | iter->second); |
Matt Spinler | ad8f452 | 2023-10-25 11:14:46 -0500 | [diff] [blame] | 855 | |
| 856 | dvfsTempPath = std::string{OCC_SENSORS_ROOT} + "/temperature/" + |
| 857 | dimmDVFSSensorName.at(fruTypeValue); |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 858 | } |
| 859 | else if (type == OCC_CPU_TEMP_SENSOR_TYPE) |
| 860 | { |
Matt Spinler | ace67d8 | 2021-10-18 13:41:57 -0500 | [diff] [blame] | 861 | if (fruTypeValue == processorCore) |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 862 | { |
Matt Spinler | ace67d8 | 2021-10-18 13:41:57 -0500 | [diff] [blame] | 863 | // The OCC reports small core temps, of which there are |
| 864 | // two per big core. All current P10 systems are in big |
| 865 | // core mode, so use a big core name. |
| 866 | uint16_t coreNum = instanceID / 2; |
| 867 | uint16_t tempNum = instanceID % 2; |
Chris Cain | ae157b6 | 2024-01-23 16:05:12 -0600 | [diff] [blame^] | 868 | sensorPath.append("proc" + std::to_string(occInstance) + |
| 869 | "_core" + std::to_string(coreNum) + "_" + |
Matt Spinler | ace67d8 | 2021-10-18 13:41:57 -0500 | [diff] [blame] | 870 | std::to_string(tempNum) + "_temp"); |
| 871 | |
Chris Cain | ae157b6 | 2024-01-23 16:05:12 -0600 | [diff] [blame^] | 872 | dvfsTempPath = |
| 873 | std::string{OCC_SENSORS_ROOT} + "/temperature/proc" + |
| 874 | std::to_string(occInstance) + "_core_dvfs_temp"; |
Matt Spinler | ace67d8 | 2021-10-18 13:41:57 -0500 | [diff] [blame] | 875 | } |
| 876 | else |
| 877 | { |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 878 | continue; |
| 879 | } |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 880 | } |
| 881 | else |
| 882 | { |
| 883 | continue; |
| 884 | } |
| 885 | } |
| 886 | |
Matt Spinler | ace67d8 | 2021-10-18 13:41:57 -0500 | [diff] [blame] | 887 | // The dvfs temp file only needs to be read once per chip per type. |
| 888 | if (!dvfsTempPath.empty() && |
| 889 | !dbus::OccDBusSensors::getOccDBus().hasDvfsTemp(dvfsTempPath)) |
| 890 | { |
| 891 | try |
| 892 | { |
| 893 | auto dvfsValue = readFile<double>(filePathString + maxSuffix); |
| 894 | |
| 895 | dbus::OccDBusSensors::getOccDBus().setDvfsTemp( |
| 896 | dvfsTempPath, dvfsValue * std::pow(10, -3)); |
| 897 | } |
| 898 | catch (const std::system_error& e) |
| 899 | { |
| 900 | log<level::DEBUG>( |
| 901 | fmt::format( |
| 902 | "readTempSensors: Failed reading {}, errno = {}", |
| 903 | filePathString + maxSuffix, e.code().value()) |
| 904 | .c_str()); |
| 905 | } |
| 906 | } |
| 907 | |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 908 | uint32_t faultValue{0}; |
| 909 | try |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 910 | { |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 911 | faultValue = readFile<uint32_t>(filePathString + faultSuffix); |
| 912 | } |
| 913 | catch (const std::system_error& e) |
| 914 | { |
| 915 | log<level::DEBUG>( |
| 916 | fmt::format("readTempSensors: Failed reading {}, errno = {}", |
| 917 | filePathString + faultSuffix, e.code().value()) |
| 918 | .c_str()); |
| 919 | continue; |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 920 | } |
| 921 | |
Chris Cain | ae157b6 | 2024-01-23 16:05:12 -0600 | [diff] [blame^] | 922 | double tempValue{0}; |
| 923 | // NOTE: if OCC sends back 0xFF, kernal sets this fault value to 1. |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 924 | if (faultValue != 0) |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 925 | { |
Chris Cain | ae157b6 | 2024-01-23 16:05:12 -0600 | [diff] [blame^] | 926 | tempValue = std::numeric_limits<double>::quiet_NaN(); |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 927 | } |
Chris Cain | ae157b6 | 2024-01-23 16:05:12 -0600 | [diff] [blame^] | 928 | else |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 929 | { |
Chris Cain | ae157b6 | 2024-01-23 16:05:12 -0600 | [diff] [blame^] | 930 | // Read the temperature |
| 931 | try |
Sheldon Bailey | cd0940b | 2022-04-26 14:24:05 -0500 | [diff] [blame] | 932 | { |
Chris Cain | ae157b6 | 2024-01-23 16:05:12 -0600 | [diff] [blame^] | 933 | tempValue = readFile<double>(filePathString + inputSuffix); |
Sheldon Bailey | cd0940b | 2022-04-26 14:24:05 -0500 | [diff] [blame] | 934 | } |
Chris Cain | ae157b6 | 2024-01-23 16:05:12 -0600 | [diff] [blame^] | 935 | catch (const std::system_error& e) |
Sheldon Bailey | cd0940b | 2022-04-26 14:24:05 -0500 | [diff] [blame] | 936 | { |
Chris Cain | ae157b6 | 2024-01-23 16:05:12 -0600 | [diff] [blame^] | 937 | log<level::DEBUG>( |
| 938 | fmt::format( |
| 939 | "readTempSensors: Failed reading {}, errno = {}", |
| 940 | filePathString + inputSuffix, e.code().value()) |
| 941 | .c_str()); |
| 942 | |
| 943 | // if errno == EAGAIN(Resource temporarily unavailable) then set |
| 944 | // temp to 0, to avoid using old temp, and affecting FAN |
| 945 | // Control. |
| 946 | if (e.code().value() == EAGAIN) |
| 947 | { |
| 948 | tempValue = 0; |
| 949 | } |
| 950 | // else the errno would be something like |
| 951 | // EBADF(Bad file descriptor) |
| 952 | // or ENOENT(No such file or directory) |
| 953 | else |
| 954 | { |
| 955 | continue; |
| 956 | } |
Sheldon Bailey | cd0940b | 2022-04-26 14:24:05 -0500 | [diff] [blame] | 957 | } |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 958 | } |
| 959 | |
Matt Spinler | 818cc8d | 2023-10-23 11:43:39 -0500 | [diff] [blame] | 960 | // If this object path already has a value, only overwite |
| 961 | // it if the previous one was an NaN or a smaller value. |
| 962 | auto existing = sensorData.find(sensorPath); |
| 963 | if (existing != sensorData.end()) |
| 964 | { |
Chris Cain | ae157b6 | 2024-01-23 16:05:12 -0600 | [diff] [blame^] | 965 | // Multiple sensors found for this FRU type |
| 966 | if ((std::isnan(existing->second) && (tempValue == 0)) || |
| 967 | ((existing->second == 0) && std::isnan(tempValue))) |
| 968 | { |
| 969 | // One of the redundant sensors has failed (0xFF/nan), and the |
| 970 | // other sensor has no reading (0), so set the FRU to NaN to |
| 971 | // force fan increase |
| 972 | tempValue = std::numeric_limits<double>::quiet_NaN(); |
| 973 | existing->second = tempValue; |
| 974 | } |
Matt Spinler | 818cc8d | 2023-10-23 11:43:39 -0500 | [diff] [blame] | 975 | if (std::isnan(existing->second) || (tempValue > existing->second)) |
| 976 | { |
| 977 | existing->second = tempValue; |
| 978 | } |
| 979 | } |
| 980 | else |
| 981 | { |
Chris Cain | ae157b6 | 2024-01-23 16:05:12 -0600 | [diff] [blame^] | 982 | // First sensor for this FRU type |
Matt Spinler | 818cc8d | 2023-10-23 11:43:39 -0500 | [diff] [blame] | 983 | sensorData[sensorPath] = tempValue; |
| 984 | } |
| 985 | } |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 986 | |
Matt Spinler | 818cc8d | 2023-10-23 11:43:39 -0500 | [diff] [blame] | 987 | // Now publish the values on D-Bus. |
| 988 | for (const auto& [objectPath, value] : sensorData) |
| 989 | { |
| 990 | dbus::OccDBusSensors::getOccDBus().setValue(objectPath, |
| 991 | value * std::pow(10, -3)); |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 992 | |
Matt Spinler | 818cc8d | 2023-10-23 11:43:39 -0500 | [diff] [blame] | 993 | dbus::OccDBusSensors::getOccDBus().setOperationalStatus( |
| 994 | objectPath, !std::isnan(value)); |
| 995 | |
| 996 | if (existingSensors.find(objectPath) == existingSensors.end()) |
Chris Cain | 6fa848a | 2022-01-24 14:54:38 -0600 | [diff] [blame] | 997 | { |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 998 | dbus::OccDBusSensors::getOccDBus().setChassisAssociation( |
Matt Spinler | 818cc8d | 2023-10-23 11:43:39 -0500 | [diff] [blame] | 999 | objectPath); |
Chris Cain | 6fa848a | 2022-01-24 14:54:38 -0600 | [diff] [blame] | 1000 | } |
| 1001 | |
Chris Cain | ae157b6 | 2024-01-23 16:05:12 -0600 | [diff] [blame^] | 1002 | existingSensors[objectPath] = occInstance; |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 1003 | } |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 1004 | } |
| 1005 | |
| 1006 | std::optional<std::string> |
| 1007 | Manager::getPowerLabelFunctionID(const std::string& value) |
| 1008 | { |
| 1009 | // If the value is "system", then the FunctionID is "system". |
| 1010 | if (value == "system") |
| 1011 | { |
| 1012 | return value; |
| 1013 | } |
| 1014 | |
| 1015 | // If the value is not "system", then the label value have 3 numbers, of |
| 1016 | // which we only care about the middle one: |
| 1017 | // <sensor id>_<function id>_<apss channel> |
| 1018 | // eg: The value is "0_10_5" , then the FunctionID is "10". |
| 1019 | if (value.find("_") == std::string::npos) |
| 1020 | { |
| 1021 | return std::nullopt; |
| 1022 | } |
| 1023 | |
| 1024 | auto powerLabelValue = value.substr((value.find("_") + 1)); |
| 1025 | |
| 1026 | if (powerLabelValue.find("_") == std::string::npos) |
| 1027 | { |
| 1028 | return std::nullopt; |
| 1029 | } |
| 1030 | |
| 1031 | return powerLabelValue.substr(0, powerLabelValue.find("_")); |
| 1032 | } |
| 1033 | |
| 1034 | void Manager::readPowerSensors(const fs::path& path, uint32_t id) |
| 1035 | { |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 1036 | std::regex expr{"power\\d+_label$"}; // Example: power5_label |
| 1037 | for (auto& file : fs::directory_iterator(path)) |
| 1038 | { |
| 1039 | if (!std::regex_search(file.path().string(), expr)) |
| 1040 | { |
| 1041 | continue; |
| 1042 | } |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 1043 | |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 1044 | std::string labelValue; |
| 1045 | try |
| 1046 | { |
| 1047 | labelValue = readFile<std::string>(file.path()); |
| 1048 | } |
| 1049 | catch (const std::system_error& e) |
| 1050 | { |
| 1051 | log<level::DEBUG>( |
| 1052 | fmt::format("readPowerSensors: Failed reading {}, errno = {}", |
| 1053 | file.path().string(), e.code().value()) |
| 1054 | .c_str()); |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 1055 | continue; |
| 1056 | } |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 1057 | |
| 1058 | auto functionID = getPowerLabelFunctionID(labelValue); |
| 1059 | if (functionID == std::nullopt) |
| 1060 | { |
| 1061 | continue; |
| 1062 | } |
| 1063 | |
| 1064 | const std::string& tempLabel = "label"; |
| 1065 | const std::string filePathString = file.path().string().substr( |
| 1066 | 0, file.path().string().length() - tempLabel.length()); |
| 1067 | |
| 1068 | std::string sensorPath = OCC_SENSORS_ROOT + std::string("/power/"); |
| 1069 | |
| 1070 | auto iter = powerSensorName.find(*functionID); |
| 1071 | if (iter == powerSensorName.end()) |
| 1072 | { |
| 1073 | continue; |
| 1074 | } |
| 1075 | sensorPath.append(iter->second); |
| 1076 | |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 1077 | double tempValue{0}; |
| 1078 | |
| 1079 | try |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 1080 | { |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 1081 | tempValue = readFile<double>(filePathString + inputSuffix); |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 1082 | } |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 1083 | catch (const std::system_error& e) |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 1084 | { |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 1085 | log<level::DEBUG>( |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 1086 | fmt::format("readPowerSensors: Failed reading {}, errno = {}", |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 1087 | filePathString + inputSuffix, e.code().value()) |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 1088 | .c_str()); |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 1089 | continue; |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 1090 | } |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 1091 | |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 1092 | dbus::OccDBusSensors::getOccDBus().setUnit( |
Chris Cain | d84a833 | 2022-01-13 08:58:45 -0600 | [diff] [blame] | 1093 | sensorPath, "xyz.openbmc_project.Sensor.Value.Unit.Watts"); |
| 1094 | |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 1095 | dbus::OccDBusSensors::getOccDBus().setValue( |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 1096 | sensorPath, tempValue * std::pow(10, -3) * std::pow(10, -3)); |
| 1097 | |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 1098 | dbus::OccDBusSensors::getOccDBus().setOperationalStatus(sensorPath, |
| 1099 | true); |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 1100 | |
Matt Spinler | 5901abd | 2021-09-23 13:50:03 -0500 | [diff] [blame] | 1101 | if (existingSensors.find(sensorPath) == existingSensors.end()) |
| 1102 | { |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 1103 | dbus::OccDBusSensors::getOccDBus().setChassisAssociation( |
| 1104 | sensorPath); |
Matt Spinler | 5901abd | 2021-09-23 13:50:03 -0500 | [diff] [blame] | 1105 | } |
| 1106 | |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 1107 | existingSensors[sensorPath] = id; |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 1108 | } |
| 1109 | return; |
| 1110 | } |
| 1111 | |
Sheldon Bailey | c8dd459 | 2022-05-12 10:15:14 -0500 | [diff] [blame] | 1112 | void Manager::setSensorValueToNaN(uint32_t id) const |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 1113 | { |
| 1114 | for (const auto& [sensorPath, occId] : existingSensors) |
| 1115 | { |
| 1116 | if (occId == id) |
| 1117 | { |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 1118 | dbus::OccDBusSensors::getOccDBus().setValue( |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 1119 | sensorPath, std::numeric_limits<double>::quiet_NaN()); |
Sheldon Bailey | c8dd459 | 2022-05-12 10:15:14 -0500 | [diff] [blame] | 1120 | |
| 1121 | dbus::OccDBusSensors::getOccDBus().setOperationalStatus(sensorPath, |
| 1122 | true); |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 1123 | } |
| 1124 | } |
| 1125 | return; |
| 1126 | } |
| 1127 | |
Sheldon Bailey | 373af75 | 2022-02-21 15:14:00 -0600 | [diff] [blame] | 1128 | void Manager::setSensorValueToNonFunctional(uint32_t id) const |
| 1129 | { |
| 1130 | for (const auto& [sensorPath, occId] : existingSensors) |
| 1131 | { |
| 1132 | if (occId == id) |
| 1133 | { |
| 1134 | dbus::OccDBusSensors::getOccDBus().setValue( |
| 1135 | sensorPath, std::numeric_limits<double>::quiet_NaN()); |
| 1136 | |
| 1137 | dbus::OccDBusSensors::getOccDBus().setOperationalStatus(sensorPath, |
| 1138 | false); |
| 1139 | } |
| 1140 | } |
| 1141 | return; |
| 1142 | } |
| 1143 | |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 1144 | void Manager::getSensorValues(std::unique_ptr<Status>& occ) |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 1145 | { |
Chris Cain | e2d0a43 | 2022-03-28 11:08:49 -0500 | [diff] [blame] | 1146 | static bool tracedError[8] = {0}; |
| 1147 | const fs::path sensorPath = occ->getHwmonPath(); |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 1148 | const uint32_t id = occ->getOccInstanceID(); |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 1149 | |
Chris Cain | e2d0a43 | 2022-03-28 11:08:49 -0500 | [diff] [blame] | 1150 | if (fs::exists(sensorPath)) |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 1151 | { |
Chris Cain | e2d0a43 | 2022-03-28 11:08:49 -0500 | [diff] [blame] | 1152 | // Read temperature sensors |
| 1153 | readTempSensors(sensorPath, id); |
| 1154 | |
| 1155 | if (occ->isMasterOcc()) |
| 1156 | { |
| 1157 | // Read power sensors |
| 1158 | readPowerSensors(sensorPath, id); |
| 1159 | } |
| 1160 | tracedError[id] = false; |
| 1161 | } |
| 1162 | else |
| 1163 | { |
| 1164 | if (!tracedError[id]) |
| 1165 | { |
| 1166 | log<level::ERR>( |
| 1167 | fmt::format( |
| 1168 | "Manager::getSensorValues: OCC{} sensor path missing: {}", |
| 1169 | id, sensorPath.c_str()) |
| 1170 | .c_str()); |
| 1171 | tracedError[id] = true; |
| 1172 | } |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 1173 | } |
| 1174 | |
| 1175 | return; |
| 1176 | } |
| 1177 | #endif |
Chris Cain | 1725767 | 2021-10-22 13:41:03 -0500 | [diff] [blame] | 1178 | |
| 1179 | // Read the altitude from DBus |
| 1180 | void Manager::readAltitude() |
| 1181 | { |
| 1182 | static bool traceAltitudeErr = true; |
| 1183 | |
| 1184 | utils::PropertyValue altitudeProperty{}; |
| 1185 | try |
| 1186 | { |
| 1187 | altitudeProperty = utils::getProperty(ALTITUDE_PATH, ALTITUDE_INTERFACE, |
| 1188 | ALTITUDE_PROP); |
| 1189 | auto sensorVal = std::get<double>(altitudeProperty); |
| 1190 | if (sensorVal < 0xFFFF) |
| 1191 | { |
| 1192 | if (sensorVal < 0) |
| 1193 | { |
| 1194 | altitude = 0; |
| 1195 | } |
| 1196 | else |
| 1197 | { |
| 1198 | // Round to nearest meter |
| 1199 | altitude = uint16_t(sensorVal + 0.5); |
| 1200 | } |
| 1201 | log<level::DEBUG>(fmt::format("readAltitude: sensor={} ({}m)", |
| 1202 | sensorVal, altitude) |
| 1203 | .c_str()); |
| 1204 | traceAltitudeErr = true; |
| 1205 | } |
| 1206 | else |
| 1207 | { |
| 1208 | if (traceAltitudeErr) |
| 1209 | { |
| 1210 | traceAltitudeErr = false; |
| 1211 | log<level::DEBUG>( |
| 1212 | fmt::format("Invalid altitude value: {}", sensorVal) |
| 1213 | .c_str()); |
| 1214 | } |
| 1215 | } |
| 1216 | } |
Patrick Williams | af40808 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 1217 | catch (const sdbusplus::exception_t& e) |
Chris Cain | 1725767 | 2021-10-22 13:41:03 -0500 | [diff] [blame] | 1218 | { |
| 1219 | if (traceAltitudeErr) |
| 1220 | { |
| 1221 | traceAltitudeErr = false; |
| 1222 | log<level::INFO>( |
| 1223 | fmt::format("Unable to read Altitude: {}", e.what()).c_str()); |
| 1224 | } |
| 1225 | altitude = 0xFFFF; // not available |
| 1226 | } |
| 1227 | } |
| 1228 | |
| 1229 | // Callback function when ambient temperature changes |
Patrick Williams | af40808 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 1230 | void Manager::ambientCallback(sdbusplus::message_t& msg) |
Chris Cain | 1725767 | 2021-10-22 13:41:03 -0500 | [diff] [blame] | 1231 | { |
| 1232 | double currentTemp = 0; |
| 1233 | uint8_t truncatedTemp = 0xFF; |
| 1234 | std::string msgSensor; |
| 1235 | std::map<std::string, std::variant<double>> msgData; |
| 1236 | msg.read(msgSensor, msgData); |
| 1237 | |
| 1238 | auto valPropMap = msgData.find(AMBIENT_PROP); |
| 1239 | if (valPropMap == msgData.end()) |
| 1240 | { |
| 1241 | log<level::DEBUG>("ambientCallback: Unknown ambient property changed"); |
| 1242 | return; |
| 1243 | } |
| 1244 | currentTemp = std::get<double>(valPropMap->second); |
| 1245 | if (std::isnan(currentTemp)) |
| 1246 | { |
| 1247 | truncatedTemp = 0xFF; |
| 1248 | } |
| 1249 | else |
| 1250 | { |
| 1251 | if (currentTemp < 0) |
| 1252 | { |
| 1253 | truncatedTemp = 0; |
| 1254 | } |
| 1255 | else |
| 1256 | { |
| 1257 | // Round to nearest degree C |
| 1258 | truncatedTemp = uint8_t(currentTemp + 0.5); |
| 1259 | } |
| 1260 | } |
| 1261 | |
| 1262 | // If ambient changes, notify OCCs |
| 1263 | if (truncatedTemp != ambient) |
| 1264 | { |
| 1265 | log<level::DEBUG>( |
| 1266 | fmt::format("ambientCallback: Ambient change from {} to {}C", |
| 1267 | ambient, currentTemp) |
| 1268 | .c_str()); |
| 1269 | |
| 1270 | ambient = truncatedTemp; |
| 1271 | if (altitude == 0xFFFF) |
| 1272 | { |
| 1273 | // No altitude yet, try reading again |
| 1274 | readAltitude(); |
| 1275 | } |
| 1276 | |
| 1277 | log<level::DEBUG>( |
| 1278 | fmt::format("ambientCallback: Ambient: {}C, altitude: {}m", ambient, |
| 1279 | altitude) |
| 1280 | .c_str()); |
| 1281 | #ifdef POWER10 |
| 1282 | // Send ambient and altitude to all OCCs |
| 1283 | for (auto& obj : statusObjects) |
| 1284 | { |
| 1285 | if (obj->occActive()) |
| 1286 | { |
| 1287 | obj->sendAmbient(ambient, altitude); |
| 1288 | } |
| 1289 | } |
| 1290 | #endif // POWER10 |
| 1291 | } |
| 1292 | } |
| 1293 | |
| 1294 | // return the current ambient and altitude readings |
| 1295 | void Manager::getAmbientData(bool& ambientValid, uint8_t& ambientTemp, |
| 1296 | uint16_t& altitudeValue) const |
| 1297 | { |
| 1298 | ambientValid = true; |
| 1299 | ambientTemp = ambient; |
| 1300 | altitudeValue = altitude; |
| 1301 | |
| 1302 | if (ambient == 0xFF) |
| 1303 | { |
| 1304 | ambientValid = false; |
| 1305 | } |
| 1306 | } |
| 1307 | |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 1308 | #ifdef POWER10 |
Chris Cain | 7f89e4d | 2022-05-09 13:27:45 -0500 | [diff] [blame] | 1309 | // Called when waitForAllOccsTimer expires |
| 1310 | // After the first OCC goes active, this timer will be started (60 seconds) |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 1311 | void Manager::occsNotAllRunning() |
| 1312 | { |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 1313 | if (activeCount != statusObjects.size()) |
| 1314 | { |
| 1315 | // Not all OCCs went active |
| 1316 | log<level::WARNING>( |
| 1317 | fmt::format( |
| 1318 | "occsNotAllRunning: Active OCC count ({}) does not match expected count ({})", |
| 1319 | activeCount, statusObjects.size()) |
| 1320 | .c_str()); |
Chris Cain | 7f89e4d | 2022-05-09 13:27:45 -0500 | [diff] [blame] | 1321 | // Procs may be garded, so may be expected |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 1322 | } |
| 1323 | |
| 1324 | validateOccMaster(); |
| 1325 | } |
| 1326 | #endif // POWER10 |
| 1327 | |
| 1328 | // Verify single master OCC and start presence monitor |
| 1329 | void Manager::validateOccMaster() |
| 1330 | { |
| 1331 | int masterInstance = -1; |
| 1332 | for (auto& obj : statusObjects) |
| 1333 | { |
Chris Cain | bd551de | 2022-04-26 13:41:16 -0500 | [diff] [blame] | 1334 | auto instance = obj->getOccInstanceID(); |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 1335 | #ifdef POWER10 |
| 1336 | if (!obj->occActive()) |
| 1337 | { |
| 1338 | if (utils::isHostRunning()) |
| 1339 | { |
Chris Cain | bd551de | 2022-04-26 13:41:16 -0500 | [diff] [blame] | 1340 | // Check if sensor was queued while waiting for discovery |
| 1341 | auto match = queuedActiveState.find(instance); |
| 1342 | if (match != queuedActiveState.end()) |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 1343 | { |
Chris Cain | 7f89e4d | 2022-05-09 13:27:45 -0500 | [diff] [blame] | 1344 | queuedActiveState.erase(match); |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 1345 | log<level::INFO>( |
| 1346 | fmt::format( |
Chris Cain | bd551de | 2022-04-26 13:41:16 -0500 | [diff] [blame] | 1347 | "validateOccMaster: OCC{} is ACTIVE (queued)", |
| 1348 | instance) |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 1349 | .c_str()); |
Chris Cain | bd551de | 2022-04-26 13:41:16 -0500 | [diff] [blame] | 1350 | obj->occActive(true); |
| 1351 | } |
| 1352 | else |
| 1353 | { |
| 1354 | // OCC does not appear to be active yet, check active sensor |
| 1355 | pldmHandle->checkActiveSensor(instance); |
| 1356 | if (obj->occActive()) |
| 1357 | { |
| 1358 | log<level::INFO>( |
| 1359 | fmt::format( |
| 1360 | "validateOccMaster: OCC{} is ACTIVE after reading sensor", |
| 1361 | instance) |
| 1362 | .c_str()); |
| 1363 | } |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 1364 | } |
| 1365 | } |
| 1366 | else |
| 1367 | { |
| 1368 | log<level::WARNING>( |
| 1369 | fmt::format( |
| 1370 | "validateOccMaster: HOST is not running (OCC{})", |
Chris Cain | bd551de | 2022-04-26 13:41:16 -0500 | [diff] [blame] | 1371 | instance) |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 1372 | .c_str()); |
| 1373 | return; |
| 1374 | } |
| 1375 | } |
| 1376 | #endif // POWER10 |
| 1377 | |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 1378 | if (obj->isMasterOcc()) |
| 1379 | { |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 1380 | obj->addPresenceWatchMaster(); |
| 1381 | |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 1382 | if (masterInstance == -1) |
| 1383 | { |
Chris Cain | bd551de | 2022-04-26 13:41:16 -0500 | [diff] [blame] | 1384 | masterInstance = instance; |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 1385 | } |
| 1386 | else |
| 1387 | { |
| 1388 | log<level::ERR>( |
| 1389 | fmt::format( |
| 1390 | "validateOccMaster: Multiple OCC masters! ({} and {})", |
Chris Cain | bd551de | 2022-04-26 13:41:16 -0500 | [diff] [blame] | 1391 | masterInstance, instance) |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 1392 | .c_str()); |
| 1393 | // request reset |
Eddie James | 9789e71 | 2022-05-25 15:43:40 -0500 | [diff] [blame] | 1394 | obj->deviceError(Error::Descriptor(PRESENCE_ERROR_PATH)); |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 1395 | } |
| 1396 | } |
| 1397 | } |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 1398 | |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 1399 | if (masterInstance < 0) |
| 1400 | { |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 1401 | log<level::ERR>( |
| 1402 | fmt::format("validateOccMaster: Master OCC not found! (of {} OCCs)", |
| 1403 | statusObjects.size()) |
| 1404 | .c_str()); |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 1405 | // request reset |
Eddie James | 9789e71 | 2022-05-25 15:43:40 -0500 | [diff] [blame] | 1406 | statusObjects.front()->deviceError( |
| 1407 | Error::Descriptor(PRESENCE_ERROR_PATH)); |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 1408 | } |
| 1409 | else |
| 1410 | { |
| 1411 | log<level::INFO>( |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 1412 | fmt::format("validateOccMaster: OCC{} is master of {} OCCs", |
| 1413 | masterInstance, activeCount) |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 1414 | .c_str()); |
Sheldon Bailey | 31a2f13 | 2022-05-20 11:31:52 -0500 | [diff] [blame] | 1415 | #ifdef POWER10 |
| 1416 | pmode->updateDbusSafeMode(false); |
| 1417 | #endif |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 1418 | } |
| 1419 | } |
| 1420 | |
Chris Cain | 40501a2 | 2022-03-14 17:33:27 -0500 | [diff] [blame] | 1421 | void Manager::updatePcapBounds() const |
| 1422 | { |
| 1423 | if (pcap) |
| 1424 | { |
| 1425 | pcap->updatePcapBounds(); |
| 1426 | } |
| 1427 | } |
| 1428 | |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 1429 | } // namespace occ |
| 1430 | } // namespace open_power |