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 | |
Sheldon Bailey | 31a2f13 | 2022-05-20 11:31:52 -0500 | [diff] [blame^] | 505 | // Called upon pldm event To set powermode Safe Mode State for system. |
| 506 | void Manager::updateOccSafeMode(bool safeMode) |
| 507 | { |
| 508 | #ifdef POWER10 |
| 509 | pmode->updateDbusSafeMode(safeMode); |
| 510 | #endif |
| 511 | } |
| 512 | |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 513 | void Manager::sbeHRESETResult(instanceID instance, bool success) |
| 514 | { |
| 515 | if (success) |
| 516 | { |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 517 | log<level::INFO>( |
| 518 | fmt::format("HRESET succeeded (OCC{})", instance).c_str()); |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 519 | |
| 520 | setSBEState(instance, SBE_STATE_BOOTED); |
| 521 | |
| 522 | return; |
| 523 | } |
| 524 | |
| 525 | setSBEState(instance, SBE_STATE_FAILED); |
| 526 | |
| 527 | if (sbeCanDump(instance)) |
| 528 | { |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 529 | log<level::INFO>( |
| 530 | fmt::format("HRESET failed (OCC{}), triggering SBE dump", instance) |
| 531 | .c_str()); |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 532 | |
| 533 | auto& bus = utils::getBus(); |
| 534 | uint32_t src6 = instance << 16; |
| 535 | uint32_t logId = |
| 536 | FFDC::createPEL("org.open_power.Processor.Error.SbeChipOpTimeout", |
| 537 | src6, "SBE command timeout"); |
| 538 | |
| 539 | try |
| 540 | { |
George Liu | f3a4a69 | 2021-12-28 13:59:51 +0800 | [diff] [blame] | 541 | constexpr auto path = "/org/openpower/dump"; |
| 542 | constexpr auto interface = "xyz.openbmc_project.Dump.Create"; |
| 543 | constexpr auto function = "CreateDump"; |
| 544 | |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 545 | std::string service = utils::getService(path, interface); |
| 546 | auto method = |
| 547 | bus.new_method_call(service.c_str(), path, interface, function); |
| 548 | |
| 549 | std::map<std::string, std::variant<std::string, uint64_t>> |
| 550 | createParams{ |
| 551 | {"com.ibm.Dump.Create.CreateParameters.ErrorLogId", |
| 552 | uint64_t(logId)}, |
| 553 | {"com.ibm.Dump.Create.CreateParameters.DumpType", |
| 554 | "com.ibm.Dump.Create.DumpType.SBE"}, |
| 555 | {"com.ibm.Dump.Create.CreateParameters.FailingUnitId", |
| 556 | uint64_t(instance)}, |
| 557 | }; |
| 558 | |
| 559 | method.append(createParams); |
| 560 | |
| 561 | auto response = bus.call(method); |
| 562 | } |
| 563 | catch (const sdbusplus::exception::exception& e) |
| 564 | { |
| 565 | constexpr auto ERROR_DUMP_DISABLED = |
| 566 | "xyz.openbmc_project.Dump.Create.Error.Disabled"; |
| 567 | if (e.name() == ERROR_DUMP_DISABLED) |
| 568 | { |
| 569 | log<level::INFO>("Dump is disabled, skipping"); |
| 570 | } |
| 571 | else |
| 572 | { |
| 573 | log<level::ERR>("Dump failed"); |
| 574 | } |
| 575 | } |
| 576 | } |
| 577 | } |
| 578 | |
| 579 | bool Manager::sbeCanDump(unsigned int instance) |
| 580 | { |
| 581 | struct pdbg_target* proc = getPdbgTarget(instance); |
| 582 | |
| 583 | if (!proc) |
| 584 | { |
| 585 | // allow the dump in the error case |
| 586 | return true; |
| 587 | } |
| 588 | |
| 589 | try |
| 590 | { |
| 591 | if (!openpower::phal::sbe::isDumpAllowed(proc)) |
| 592 | { |
| 593 | return false; |
| 594 | } |
| 595 | |
| 596 | if (openpower::phal::pdbg::isSbeVitalAttnActive(proc)) |
| 597 | { |
| 598 | return false; |
| 599 | } |
| 600 | } |
| 601 | catch (openpower::phal::exception::SbeError& e) |
| 602 | { |
| 603 | log<level::INFO>("Failed to query SBE state"); |
| 604 | } |
| 605 | |
| 606 | // allow the dump in the error case |
| 607 | return true; |
| 608 | } |
| 609 | |
| 610 | void Manager::setSBEState(unsigned int instance, enum sbe_state state) |
| 611 | { |
| 612 | struct pdbg_target* proc = getPdbgTarget(instance); |
| 613 | |
| 614 | if (!proc) |
| 615 | { |
| 616 | return; |
| 617 | } |
| 618 | |
| 619 | try |
| 620 | { |
| 621 | openpower::phal::sbe::setState(proc, state); |
| 622 | } |
| 623 | catch (const openpower::phal::exception::SbeError& e) |
| 624 | { |
| 625 | log<level::ERR>("Failed to set SBE state"); |
| 626 | } |
| 627 | } |
| 628 | |
| 629 | struct pdbg_target* Manager::getPdbgTarget(unsigned int instance) |
| 630 | { |
| 631 | if (!pdbgInitialized) |
| 632 | { |
| 633 | try |
| 634 | { |
| 635 | openpower::phal::pdbg::init(); |
| 636 | pdbgInitialized = true; |
| 637 | } |
| 638 | catch (const openpower::phal::exception::PdbgError& e) |
| 639 | { |
| 640 | log<level::ERR>("pdbg initialization failed"); |
| 641 | return nullptr; |
| 642 | } |
| 643 | } |
| 644 | |
| 645 | struct pdbg_target* proc = nullptr; |
| 646 | pdbg_for_each_class_target("proc", proc) |
| 647 | { |
| 648 | if (pdbg_target_index(proc) == instance) |
| 649 | { |
| 650 | return proc; |
| 651 | } |
| 652 | } |
| 653 | |
| 654 | log<level::ERR>("Failed to get pdbg target"); |
| 655 | return nullptr; |
| 656 | } |
Tom Joseph | 815f9f5 | 2020-07-27 12:12:13 +0530 | [diff] [blame] | 657 | #endif |
| 658 | |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 659 | void Manager::pollerTimerExpired() |
| 660 | { |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 661 | if (!_pollTimer) |
| 662 | { |
| 663 | log<level::ERR>( |
| 664 | "Manager::pollerTimerExpired() ERROR: Timer not defined"); |
| 665 | return; |
| 666 | } |
| 667 | |
| 668 | for (auto& obj : statusObjects) |
| 669 | { |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 670 | if (!obj->occActive()) |
| 671 | { |
| 672 | // OCC is not running yet |
| 673 | #ifdef READ_OCC_SENSORS |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 674 | auto id = obj->getOccInstanceID(); |
Sheldon Bailey | c8dd459 | 2022-05-12 10:15:14 -0500 | [diff] [blame] | 675 | setSensorValueToNaN(id); |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 676 | #endif |
| 677 | continue; |
| 678 | } |
| 679 | |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 680 | // Read sysfs to force kernel to poll OCC |
| 681 | obj->readOccState(); |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 682 | |
| 683 | #ifdef READ_OCC_SENSORS |
| 684 | // Read occ sensor values |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 685 | getSensorValues(obj); |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 686 | #endif |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 687 | } |
| 688 | |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 689 | if (activeCount > 0) |
| 690 | { |
| 691 | // Restart OCC poll timer |
| 692 | _pollTimer->restartOnce(std::chrono::seconds(pollInterval)); |
| 693 | } |
| 694 | else |
| 695 | { |
| 696 | // No OCCs running, so poll timer will not be restarted |
| 697 | log<level::INFO>( |
| 698 | fmt::format( |
| 699 | "Manager::pollerTimerExpired: poll timer will not be restarted") |
| 700 | .c_str()); |
| 701 | } |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 702 | } |
| 703 | |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 704 | #ifdef READ_OCC_SENSORS |
| 705 | void Manager::readTempSensors(const fs::path& path, uint32_t id) |
| 706 | { |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 707 | std::regex expr{"temp\\d+_label$"}; // Example: temp5_label |
| 708 | for (auto& file : fs::directory_iterator(path)) |
| 709 | { |
| 710 | if (!std::regex_search(file.path().string(), expr)) |
| 711 | { |
| 712 | continue; |
| 713 | } |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 714 | |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 715 | uint32_t labelValue{0}; |
| 716 | |
| 717 | try |
| 718 | { |
| 719 | labelValue = readFile<uint32_t>(file.path()); |
| 720 | } |
| 721 | catch (const std::system_error& e) |
| 722 | { |
| 723 | log<level::DEBUG>( |
| 724 | fmt::format("readTempSensors: Failed reading {}, errno = {}", |
| 725 | file.path().string(), e.code().value()) |
| 726 | .c_str()); |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 727 | continue; |
| 728 | } |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 729 | |
| 730 | const std::string& tempLabel = "label"; |
| 731 | const std::string filePathString = file.path().string().substr( |
| 732 | 0, file.path().string().length() - tempLabel.length()); |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 733 | |
| 734 | uint32_t fruTypeValue{0}; |
| 735 | try |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 736 | { |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 737 | fruTypeValue = readFile<uint32_t>(filePathString + fruTypeSuffix); |
| 738 | } |
| 739 | catch (const std::system_error& e) |
| 740 | { |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 741 | log<level::DEBUG>( |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 742 | fmt::format("readTempSensors: Failed reading {}, errno = {}", |
| 743 | filePathString + fruTypeSuffix, e.code().value()) |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 744 | .c_str()); |
| 745 | continue; |
| 746 | } |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 747 | |
| 748 | std::string sensorPath = |
| 749 | OCC_SENSORS_ROOT + std::string("/temperature/"); |
| 750 | |
Matt Spinler | ace67d8 | 2021-10-18 13:41:57 -0500 | [diff] [blame] | 751 | std::string dvfsTempPath; |
| 752 | |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 753 | if (fruTypeValue == VRMVdd) |
| 754 | { |
| 755 | sensorPath.append("vrm_vdd" + std::to_string(id) + "_temp"); |
| 756 | } |
Matt Spinler | ace67d8 | 2021-10-18 13:41:57 -0500 | [diff] [blame] | 757 | else if (fruTypeValue == processorIoRing) |
| 758 | { |
| 759 | sensorPath.append("proc" + std::to_string(id) + "_ioring_temp"); |
| 760 | dvfsTempPath = std::string{OCC_SENSORS_ROOT} + "/temperature/proc" + |
| 761 | std::to_string(id) + "_ioring_dvfs_temp"; |
| 762 | } |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 763 | else |
| 764 | { |
Matt Spinler | 14d1402 | 2021-08-25 15:38:29 -0500 | [diff] [blame] | 765 | uint16_t type = (labelValue & 0xFF000000) >> 24; |
| 766 | uint16_t instanceID = labelValue & 0x0000FFFF; |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 767 | |
| 768 | if (type == OCC_DIMM_TEMP_SENSOR_TYPE) |
| 769 | { |
Matt Spinler | 8b8abee | 2021-08-25 15:18:21 -0500 | [diff] [blame] | 770 | if (fruTypeValue == fruTypeNotAvailable) |
| 771 | { |
| 772 | // Not all DIMM related temps are available to read |
| 773 | // (no _input file in this case) |
| 774 | continue; |
| 775 | } |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 776 | auto iter = dimmTempSensorName.find(fruTypeValue); |
| 777 | if (iter == dimmTempSensorName.end()) |
| 778 | { |
George Liu | b5ca101 | 2021-09-10 12:53:11 +0800 | [diff] [blame] | 779 | log<level::ERR>( |
| 780 | fmt::format( |
| 781 | "readTempSensors: Fru type error! fruTypeValue = {}) ", |
| 782 | fruTypeValue) |
| 783 | .c_str()); |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 784 | continue; |
| 785 | } |
| 786 | |
| 787 | sensorPath.append("dimm" + std::to_string(instanceID) + |
| 788 | iter->second); |
| 789 | } |
| 790 | else if (type == OCC_CPU_TEMP_SENSOR_TYPE) |
| 791 | { |
Matt Spinler | ace67d8 | 2021-10-18 13:41:57 -0500 | [diff] [blame] | 792 | if (fruTypeValue == processorCore) |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 793 | { |
Matt Spinler | ace67d8 | 2021-10-18 13:41:57 -0500 | [diff] [blame] | 794 | // The OCC reports small core temps, of which there are |
| 795 | // two per big core. All current P10 systems are in big |
| 796 | // core mode, so use a big core name. |
| 797 | uint16_t coreNum = instanceID / 2; |
| 798 | uint16_t tempNum = instanceID % 2; |
| 799 | sensorPath.append("proc" + std::to_string(id) + "_core" + |
| 800 | std::to_string(coreNum) + "_" + |
| 801 | std::to_string(tempNum) + "_temp"); |
| 802 | |
| 803 | dvfsTempPath = std::string{OCC_SENSORS_ROOT} + |
| 804 | "/temperature/proc" + std::to_string(id) + |
| 805 | "_core_dvfs_temp"; |
| 806 | } |
| 807 | else |
| 808 | { |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 809 | continue; |
| 810 | } |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 811 | } |
| 812 | else |
| 813 | { |
| 814 | continue; |
| 815 | } |
| 816 | } |
| 817 | |
Matt Spinler | ace67d8 | 2021-10-18 13:41:57 -0500 | [diff] [blame] | 818 | // The dvfs temp file only needs to be read once per chip per type. |
| 819 | if (!dvfsTempPath.empty() && |
| 820 | !dbus::OccDBusSensors::getOccDBus().hasDvfsTemp(dvfsTempPath)) |
| 821 | { |
| 822 | try |
| 823 | { |
| 824 | auto dvfsValue = readFile<double>(filePathString + maxSuffix); |
| 825 | |
| 826 | dbus::OccDBusSensors::getOccDBus().setDvfsTemp( |
| 827 | dvfsTempPath, dvfsValue * std::pow(10, -3)); |
| 828 | } |
| 829 | catch (const std::system_error& e) |
| 830 | { |
| 831 | log<level::DEBUG>( |
| 832 | fmt::format( |
| 833 | "readTempSensors: Failed reading {}, errno = {}", |
| 834 | filePathString + maxSuffix, e.code().value()) |
| 835 | .c_str()); |
| 836 | } |
| 837 | } |
| 838 | |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 839 | uint32_t faultValue{0}; |
| 840 | try |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 841 | { |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 842 | faultValue = readFile<uint32_t>(filePathString + faultSuffix); |
| 843 | } |
| 844 | catch (const std::system_error& e) |
| 845 | { |
| 846 | log<level::DEBUG>( |
| 847 | fmt::format("readTempSensors: Failed reading {}, errno = {}", |
| 848 | filePathString + faultSuffix, e.code().value()) |
| 849 | .c_str()); |
| 850 | continue; |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 851 | } |
| 852 | |
Sheldon Bailey | c8dd459 | 2022-05-12 10:15:14 -0500 | [diff] [blame] | 853 | // 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] | 854 | if (faultValue != 0) |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 855 | { |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 856 | dbus::OccDBusSensors::getOccDBus().setValue( |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 857 | sensorPath, std::numeric_limits<double>::quiet_NaN()); |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 858 | |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 859 | dbus::OccDBusSensors::getOccDBus().setOperationalStatus(sensorPath, |
| 860 | false); |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 861 | |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 862 | continue; |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 863 | } |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 864 | |
| 865 | double tempValue{0}; |
| 866 | |
| 867 | try |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 868 | { |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 869 | tempValue = readFile<double>(filePathString + inputSuffix); |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 870 | } |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 871 | catch (const std::system_error& e) |
| 872 | { |
| 873 | log<level::DEBUG>( |
| 874 | fmt::format("readTempSensors: Failed reading {}, errno = {}", |
| 875 | filePathString + inputSuffix, e.code().value()) |
| 876 | .c_str()); |
Sheldon Bailey | cd0940b | 2022-04-26 14:24:05 -0500 | [diff] [blame] | 877 | |
| 878 | // if errno == EAGAIN(Resource temporarily unavailable) then set |
| 879 | // temp to 0, to avoid using old temp, and affecting FAN Control. |
| 880 | if (e.code().value() == EAGAIN) |
| 881 | { |
| 882 | tempValue = 0; |
| 883 | } |
| 884 | // else the errno would be something like |
| 885 | // EBADF(Bad file descriptor) |
| 886 | // or ENOENT(No such file or directory) |
| 887 | else |
| 888 | { |
| 889 | continue; |
| 890 | } |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 891 | } |
| 892 | |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 893 | dbus::OccDBusSensors::getOccDBus().setValue( |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 894 | sensorPath, tempValue * std::pow(10, -3)); |
| 895 | |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 896 | dbus::OccDBusSensors::getOccDBus().setOperationalStatus(sensorPath, |
| 897 | true); |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 898 | |
Chris Cain | 6fa848a | 2022-01-24 14:54:38 -0600 | [diff] [blame] | 899 | // At this point, the sensor will be created for sure. |
| 900 | if (existingSensors.find(sensorPath) == existingSensors.end()) |
| 901 | { |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 902 | dbus::OccDBusSensors::getOccDBus().setChassisAssociation( |
| 903 | sensorPath); |
Chris Cain | 6fa848a | 2022-01-24 14:54:38 -0600 | [diff] [blame] | 904 | } |
| 905 | |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 906 | existingSensors[sensorPath] = id; |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 907 | } |
| 908 | return; |
| 909 | } |
| 910 | |
| 911 | std::optional<std::string> |
| 912 | Manager::getPowerLabelFunctionID(const std::string& value) |
| 913 | { |
| 914 | // If the value is "system", then the FunctionID is "system". |
| 915 | if (value == "system") |
| 916 | { |
| 917 | return value; |
| 918 | } |
| 919 | |
| 920 | // If the value is not "system", then the label value have 3 numbers, of |
| 921 | // which we only care about the middle one: |
| 922 | // <sensor id>_<function id>_<apss channel> |
| 923 | // eg: The value is "0_10_5" , then the FunctionID is "10". |
| 924 | if (value.find("_") == std::string::npos) |
| 925 | { |
| 926 | return std::nullopt; |
| 927 | } |
| 928 | |
| 929 | auto powerLabelValue = value.substr((value.find("_") + 1)); |
| 930 | |
| 931 | if (powerLabelValue.find("_") == std::string::npos) |
| 932 | { |
| 933 | return std::nullopt; |
| 934 | } |
| 935 | |
| 936 | return powerLabelValue.substr(0, powerLabelValue.find("_")); |
| 937 | } |
| 938 | |
| 939 | void Manager::readPowerSensors(const fs::path& path, uint32_t id) |
| 940 | { |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 941 | std::regex expr{"power\\d+_label$"}; // Example: power5_label |
| 942 | for (auto& file : fs::directory_iterator(path)) |
| 943 | { |
| 944 | if (!std::regex_search(file.path().string(), expr)) |
| 945 | { |
| 946 | continue; |
| 947 | } |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 948 | |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 949 | std::string labelValue; |
| 950 | try |
| 951 | { |
| 952 | labelValue = readFile<std::string>(file.path()); |
| 953 | } |
| 954 | catch (const std::system_error& e) |
| 955 | { |
| 956 | log<level::DEBUG>( |
| 957 | fmt::format("readPowerSensors: Failed reading {}, errno = {}", |
| 958 | file.path().string(), e.code().value()) |
| 959 | .c_str()); |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 960 | continue; |
| 961 | } |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 962 | |
| 963 | auto functionID = getPowerLabelFunctionID(labelValue); |
| 964 | if (functionID == std::nullopt) |
| 965 | { |
| 966 | continue; |
| 967 | } |
| 968 | |
| 969 | const std::string& tempLabel = "label"; |
| 970 | const std::string filePathString = file.path().string().substr( |
| 971 | 0, file.path().string().length() - tempLabel.length()); |
| 972 | |
| 973 | std::string sensorPath = OCC_SENSORS_ROOT + std::string("/power/"); |
| 974 | |
| 975 | auto iter = powerSensorName.find(*functionID); |
| 976 | if (iter == powerSensorName.end()) |
| 977 | { |
| 978 | continue; |
| 979 | } |
| 980 | sensorPath.append(iter->second); |
| 981 | |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 982 | double tempValue{0}; |
| 983 | |
| 984 | try |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 985 | { |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 986 | tempValue = readFile<double>(filePathString + inputSuffix); |
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 | catch (const std::system_error& e) |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 989 | { |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 990 | log<level::DEBUG>( |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 991 | fmt::format("readPowerSensors: Failed reading {}, errno = {}", |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 992 | filePathString + inputSuffix, e.code().value()) |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 993 | .c_str()); |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 994 | continue; |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 995 | } |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 996 | |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 997 | dbus::OccDBusSensors::getOccDBus().setUnit( |
Chris Cain | d84a833 | 2022-01-13 08:58:45 -0600 | [diff] [blame] | 998 | sensorPath, "xyz.openbmc_project.Sensor.Value.Unit.Watts"); |
| 999 | |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 1000 | dbus::OccDBusSensors::getOccDBus().setValue( |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 1001 | sensorPath, tempValue * std::pow(10, -3) * std::pow(10, -3)); |
| 1002 | |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 1003 | dbus::OccDBusSensors::getOccDBus().setOperationalStatus(sensorPath, |
| 1004 | true); |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 1005 | |
Matt Spinler | 5901abd | 2021-09-23 13:50:03 -0500 | [diff] [blame] | 1006 | if (existingSensors.find(sensorPath) == existingSensors.end()) |
| 1007 | { |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 1008 | dbus::OccDBusSensors::getOccDBus().setChassisAssociation( |
| 1009 | sensorPath); |
Matt Spinler | 5901abd | 2021-09-23 13:50:03 -0500 | [diff] [blame] | 1010 | } |
| 1011 | |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 1012 | existingSensors[sensorPath] = id; |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 1013 | } |
| 1014 | return; |
| 1015 | } |
| 1016 | |
Sheldon Bailey | c8dd459 | 2022-05-12 10:15:14 -0500 | [diff] [blame] | 1017 | void Manager::setSensorValueToNaN(uint32_t id) const |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 1018 | { |
| 1019 | for (const auto& [sensorPath, occId] : existingSensors) |
| 1020 | { |
| 1021 | if (occId == id) |
| 1022 | { |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 1023 | dbus::OccDBusSensors::getOccDBus().setValue( |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 1024 | sensorPath, std::numeric_limits<double>::quiet_NaN()); |
Sheldon Bailey | c8dd459 | 2022-05-12 10:15:14 -0500 | [diff] [blame] | 1025 | |
| 1026 | dbus::OccDBusSensors::getOccDBus().setOperationalStatus(sensorPath, |
| 1027 | true); |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 1028 | } |
| 1029 | } |
| 1030 | return; |
| 1031 | } |
| 1032 | |
Sheldon Bailey | 373af75 | 2022-02-21 15:14:00 -0600 | [diff] [blame] | 1033 | void Manager::setSensorValueToNonFunctional(uint32_t id) const |
| 1034 | { |
| 1035 | for (const auto& [sensorPath, occId] : existingSensors) |
| 1036 | { |
| 1037 | if (occId == id) |
| 1038 | { |
| 1039 | dbus::OccDBusSensors::getOccDBus().setValue( |
| 1040 | sensorPath, std::numeric_limits<double>::quiet_NaN()); |
| 1041 | |
| 1042 | dbus::OccDBusSensors::getOccDBus().setOperationalStatus(sensorPath, |
| 1043 | false); |
| 1044 | } |
| 1045 | } |
| 1046 | return; |
| 1047 | } |
| 1048 | |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 1049 | void Manager::getSensorValues(std::unique_ptr<Status>& occ) |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 1050 | { |
Chris Cain | e2d0a43 | 2022-03-28 11:08:49 -0500 | [diff] [blame] | 1051 | static bool tracedError[8] = {0}; |
| 1052 | const fs::path sensorPath = occ->getHwmonPath(); |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 1053 | const uint32_t id = occ->getOccInstanceID(); |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 1054 | |
Chris Cain | e2d0a43 | 2022-03-28 11:08:49 -0500 | [diff] [blame] | 1055 | if (fs::exists(sensorPath)) |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 1056 | { |
Chris Cain | e2d0a43 | 2022-03-28 11:08:49 -0500 | [diff] [blame] | 1057 | // Read temperature sensors |
| 1058 | readTempSensors(sensorPath, id); |
| 1059 | |
| 1060 | if (occ->isMasterOcc()) |
| 1061 | { |
| 1062 | // Read power sensors |
| 1063 | readPowerSensors(sensorPath, id); |
| 1064 | } |
| 1065 | tracedError[id] = false; |
| 1066 | } |
| 1067 | else |
| 1068 | { |
| 1069 | if (!tracedError[id]) |
| 1070 | { |
| 1071 | log<level::ERR>( |
| 1072 | fmt::format( |
| 1073 | "Manager::getSensorValues: OCC{} sensor path missing: {}", |
| 1074 | id, sensorPath.c_str()) |
| 1075 | .c_str()); |
| 1076 | tracedError[id] = true; |
| 1077 | } |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 1078 | } |
| 1079 | |
| 1080 | return; |
| 1081 | } |
| 1082 | #endif |
Chris Cain | 1725767 | 2021-10-22 13:41:03 -0500 | [diff] [blame] | 1083 | |
| 1084 | // Read the altitude from DBus |
| 1085 | void Manager::readAltitude() |
| 1086 | { |
| 1087 | static bool traceAltitudeErr = true; |
| 1088 | |
| 1089 | utils::PropertyValue altitudeProperty{}; |
| 1090 | try |
| 1091 | { |
| 1092 | altitudeProperty = utils::getProperty(ALTITUDE_PATH, ALTITUDE_INTERFACE, |
| 1093 | ALTITUDE_PROP); |
| 1094 | auto sensorVal = std::get<double>(altitudeProperty); |
| 1095 | if (sensorVal < 0xFFFF) |
| 1096 | { |
| 1097 | if (sensorVal < 0) |
| 1098 | { |
| 1099 | altitude = 0; |
| 1100 | } |
| 1101 | else |
| 1102 | { |
| 1103 | // Round to nearest meter |
| 1104 | altitude = uint16_t(sensorVal + 0.5); |
| 1105 | } |
| 1106 | log<level::DEBUG>(fmt::format("readAltitude: sensor={} ({}m)", |
| 1107 | sensorVal, altitude) |
| 1108 | .c_str()); |
| 1109 | traceAltitudeErr = true; |
| 1110 | } |
| 1111 | else |
| 1112 | { |
| 1113 | if (traceAltitudeErr) |
| 1114 | { |
| 1115 | traceAltitudeErr = false; |
| 1116 | log<level::DEBUG>( |
| 1117 | fmt::format("Invalid altitude value: {}", sensorVal) |
| 1118 | .c_str()); |
| 1119 | } |
| 1120 | } |
| 1121 | } |
| 1122 | catch (const sdbusplus::exception::exception& e) |
| 1123 | { |
| 1124 | if (traceAltitudeErr) |
| 1125 | { |
| 1126 | traceAltitudeErr = false; |
| 1127 | log<level::INFO>( |
| 1128 | fmt::format("Unable to read Altitude: {}", e.what()).c_str()); |
| 1129 | } |
| 1130 | altitude = 0xFFFF; // not available |
| 1131 | } |
| 1132 | } |
| 1133 | |
| 1134 | // Callback function when ambient temperature changes |
| 1135 | void Manager::ambientCallback(sdbusplus::message::message& msg) |
| 1136 | { |
| 1137 | double currentTemp = 0; |
| 1138 | uint8_t truncatedTemp = 0xFF; |
| 1139 | std::string msgSensor; |
| 1140 | std::map<std::string, std::variant<double>> msgData; |
| 1141 | msg.read(msgSensor, msgData); |
| 1142 | |
| 1143 | auto valPropMap = msgData.find(AMBIENT_PROP); |
| 1144 | if (valPropMap == msgData.end()) |
| 1145 | { |
| 1146 | log<level::DEBUG>("ambientCallback: Unknown ambient property changed"); |
| 1147 | return; |
| 1148 | } |
| 1149 | currentTemp = std::get<double>(valPropMap->second); |
| 1150 | if (std::isnan(currentTemp)) |
| 1151 | { |
| 1152 | truncatedTemp = 0xFF; |
| 1153 | } |
| 1154 | else |
| 1155 | { |
| 1156 | if (currentTemp < 0) |
| 1157 | { |
| 1158 | truncatedTemp = 0; |
| 1159 | } |
| 1160 | else |
| 1161 | { |
| 1162 | // Round to nearest degree C |
| 1163 | truncatedTemp = uint8_t(currentTemp + 0.5); |
| 1164 | } |
| 1165 | } |
| 1166 | |
| 1167 | // If ambient changes, notify OCCs |
| 1168 | if (truncatedTemp != ambient) |
| 1169 | { |
| 1170 | log<level::DEBUG>( |
| 1171 | fmt::format("ambientCallback: Ambient change from {} to {}C", |
| 1172 | ambient, currentTemp) |
| 1173 | .c_str()); |
| 1174 | |
| 1175 | ambient = truncatedTemp; |
| 1176 | if (altitude == 0xFFFF) |
| 1177 | { |
| 1178 | // No altitude yet, try reading again |
| 1179 | readAltitude(); |
| 1180 | } |
| 1181 | |
| 1182 | log<level::DEBUG>( |
| 1183 | fmt::format("ambientCallback: Ambient: {}C, altitude: {}m", ambient, |
| 1184 | altitude) |
| 1185 | .c_str()); |
| 1186 | #ifdef POWER10 |
| 1187 | // Send ambient and altitude to all OCCs |
| 1188 | for (auto& obj : statusObjects) |
| 1189 | { |
| 1190 | if (obj->occActive()) |
| 1191 | { |
| 1192 | obj->sendAmbient(ambient, altitude); |
| 1193 | } |
| 1194 | } |
| 1195 | #endif // POWER10 |
| 1196 | } |
| 1197 | } |
| 1198 | |
| 1199 | // return the current ambient and altitude readings |
| 1200 | void Manager::getAmbientData(bool& ambientValid, uint8_t& ambientTemp, |
| 1201 | uint16_t& altitudeValue) const |
| 1202 | { |
| 1203 | ambientValid = true; |
| 1204 | ambientTemp = ambient; |
| 1205 | altitudeValue = altitude; |
| 1206 | |
| 1207 | if (ambient == 0xFF) |
| 1208 | { |
| 1209 | ambientValid = false; |
| 1210 | } |
| 1211 | } |
| 1212 | |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 1213 | #ifdef POWER10 |
Chris Cain | 7f89e4d | 2022-05-09 13:27:45 -0500 | [diff] [blame] | 1214 | // Called when waitForAllOccsTimer expires |
| 1215 | // 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] | 1216 | void Manager::occsNotAllRunning() |
| 1217 | { |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 1218 | if (activeCount != statusObjects.size()) |
| 1219 | { |
| 1220 | // Not all OCCs went active |
| 1221 | log<level::WARNING>( |
| 1222 | fmt::format( |
| 1223 | "occsNotAllRunning: Active OCC count ({}) does not match expected count ({})", |
| 1224 | activeCount, statusObjects.size()) |
| 1225 | .c_str()); |
Chris Cain | 7f89e4d | 2022-05-09 13:27:45 -0500 | [diff] [blame] | 1226 | // Procs may be garded, so may be expected |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 1227 | } |
| 1228 | |
| 1229 | validateOccMaster(); |
| 1230 | } |
| 1231 | #endif // POWER10 |
| 1232 | |
| 1233 | // Verify single master OCC and start presence monitor |
| 1234 | void Manager::validateOccMaster() |
| 1235 | { |
| 1236 | int masterInstance = -1; |
| 1237 | for (auto& obj : statusObjects) |
| 1238 | { |
Chris Cain | bd551de | 2022-04-26 13:41:16 -0500 | [diff] [blame] | 1239 | auto instance = obj->getOccInstanceID(); |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 1240 | #ifdef POWER10 |
| 1241 | if (!obj->occActive()) |
| 1242 | { |
| 1243 | if (utils::isHostRunning()) |
| 1244 | { |
Chris Cain | bd551de | 2022-04-26 13:41:16 -0500 | [diff] [blame] | 1245 | // Check if sensor was queued while waiting for discovery |
| 1246 | auto match = queuedActiveState.find(instance); |
| 1247 | if (match != queuedActiveState.end()) |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 1248 | { |
Chris Cain | 7f89e4d | 2022-05-09 13:27:45 -0500 | [diff] [blame] | 1249 | queuedActiveState.erase(match); |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 1250 | log<level::INFO>( |
| 1251 | fmt::format( |
Chris Cain | bd551de | 2022-04-26 13:41:16 -0500 | [diff] [blame] | 1252 | "validateOccMaster: OCC{} is ACTIVE (queued)", |
| 1253 | instance) |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 1254 | .c_str()); |
Chris Cain | bd551de | 2022-04-26 13:41:16 -0500 | [diff] [blame] | 1255 | obj->occActive(true); |
| 1256 | } |
| 1257 | else |
| 1258 | { |
| 1259 | // OCC does not appear to be active yet, check active sensor |
| 1260 | pldmHandle->checkActiveSensor(instance); |
| 1261 | if (obj->occActive()) |
| 1262 | { |
| 1263 | log<level::INFO>( |
| 1264 | fmt::format( |
| 1265 | "validateOccMaster: OCC{} is ACTIVE after reading sensor", |
| 1266 | instance) |
| 1267 | .c_str()); |
| 1268 | } |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 1269 | } |
| 1270 | } |
| 1271 | else |
| 1272 | { |
| 1273 | log<level::WARNING>( |
| 1274 | fmt::format( |
| 1275 | "validateOccMaster: HOST is not running (OCC{})", |
Chris Cain | bd551de | 2022-04-26 13:41:16 -0500 | [diff] [blame] | 1276 | instance) |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 1277 | .c_str()); |
| 1278 | return; |
| 1279 | } |
| 1280 | } |
| 1281 | #endif // POWER10 |
| 1282 | |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 1283 | if (obj->isMasterOcc()) |
| 1284 | { |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 1285 | obj->addPresenceWatchMaster(); |
| 1286 | |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 1287 | if (masterInstance == -1) |
| 1288 | { |
Chris Cain | bd551de | 2022-04-26 13:41:16 -0500 | [diff] [blame] | 1289 | masterInstance = instance; |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 1290 | } |
| 1291 | else |
| 1292 | { |
| 1293 | log<level::ERR>( |
| 1294 | fmt::format( |
| 1295 | "validateOccMaster: Multiple OCC masters! ({} and {})", |
Chris Cain | bd551de | 2022-04-26 13:41:16 -0500 | [diff] [blame] | 1296 | masterInstance, instance) |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 1297 | .c_str()); |
| 1298 | // request reset |
Eddie James | 9789e71 | 2022-05-25 15:43:40 -0500 | [diff] [blame] | 1299 | obj->deviceError(Error::Descriptor(PRESENCE_ERROR_PATH)); |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 1300 | } |
| 1301 | } |
| 1302 | } |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 1303 | |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 1304 | if (masterInstance < 0) |
| 1305 | { |
Chris Cain | bae4d07 | 2022-02-28 09:46:50 -0600 | [diff] [blame] | 1306 | log<level::ERR>( |
| 1307 | fmt::format("validateOccMaster: Master OCC not found! (of {} OCCs)", |
| 1308 | statusObjects.size()) |
| 1309 | .c_str()); |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 1310 | // request reset |
Eddie James | 9789e71 | 2022-05-25 15:43:40 -0500 | [diff] [blame] | 1311 | statusObjects.front()->deviceError( |
| 1312 | Error::Descriptor(PRESENCE_ERROR_PATH)); |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 1313 | } |
| 1314 | else |
| 1315 | { |
| 1316 | log<level::INFO>( |
Chris Cain | 36f9cde | 2021-11-22 11:18:21 -0600 | [diff] [blame] | 1317 | fmt::format("validateOccMaster: OCC{} is master of {} OCCs", |
| 1318 | masterInstance, activeCount) |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 1319 | .c_str()); |
Sheldon Bailey | 31a2f13 | 2022-05-20 11:31:52 -0500 | [diff] [blame^] | 1320 | #ifdef POWER10 |
| 1321 | pmode->updateDbusSafeMode(false); |
| 1322 | #endif |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 1323 | } |
| 1324 | } |
| 1325 | |
Chris Cain | 40501a2 | 2022-03-14 17:33:27 -0500 | [diff] [blame] | 1326 | void Manager::updatePcapBounds() const |
| 1327 | { |
| 1328 | if (pcap) |
| 1329 | { |
| 1330 | pcap->updatePcapBounds(); |
| 1331 | } |
| 1332 | } |
| 1333 | |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 1334 | } // namespace occ |
| 1335 | } // namespace open_power |