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