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