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