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> |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 16 | #include <regex> |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 17 | |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 18 | namespace open_power |
| 19 | { |
| 20 | namespace occ |
| 21 | { |
| 22 | |
Matt Spinler | 8b8abee | 2021-08-25 15:18:21 -0500 | [diff] [blame] | 23 | constexpr uint32_t fruTypeNotAvailable = 0xFF; |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 24 | constexpr auto fruTypeSuffix = "fru_type"; |
| 25 | constexpr auto faultSuffix = "fault"; |
| 26 | constexpr auto inputSuffix = "input"; |
Matt Spinler | ace67d8 | 2021-10-18 13:41:57 -0500 | [diff] [blame] | 27 | constexpr auto maxSuffix = "max"; |
Matt Spinler | 8b8abee | 2021-08-25 15:18:21 -0500 | [diff] [blame] | 28 | |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 29 | using namespace phosphor::logging; |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 30 | using namespace std::literals::chrono_literals; |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 31 | |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 32 | template <typename T> |
| 33 | T readFile(const std::string& path) |
| 34 | { |
| 35 | std::ifstream ifs; |
| 36 | ifs.exceptions(std::ifstream::failbit | std::ifstream::badbit | |
| 37 | std::ifstream::eofbit); |
| 38 | T data; |
| 39 | |
| 40 | try |
| 41 | { |
| 42 | ifs.open(path); |
| 43 | ifs >> data; |
| 44 | ifs.close(); |
| 45 | } |
| 46 | catch (const std::exception& e) |
| 47 | { |
| 48 | auto err = errno; |
| 49 | throw std::system_error(err, std::generic_category()); |
| 50 | } |
| 51 | |
| 52 | return data; |
| 53 | } |
| 54 | |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 55 | void Manager::findAndCreateObjects() |
| 56 | { |
Matt Spinler | d267cec | 2021-09-01 14:49:19 -0500 | [diff] [blame] | 57 | #ifndef POWER10 |
Deepak Kodihalli | 370f06b | 2017-10-25 04:26:07 -0500 | [diff] [blame] | 58 | for (auto id = 0; id < MAX_CPUS; ++id) |
| 59 | { |
Deepak Kodihalli | 30417a1 | 2017-12-04 00:54:01 -0600 | [diff] [blame] | 60 | // Create one occ per cpu |
| 61 | auto occ = std::string(OCC_NAME) + std::to_string(id); |
| 62 | createObjects(occ); |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 63 | } |
Matt Spinler | d267cec | 2021-09-01 14:49:19 -0500 | [diff] [blame] | 64 | #else |
| 65 | // Create the OCCs based on on the /dev/occX devices |
| 66 | auto occs = findOCCsInDev(); |
| 67 | |
| 68 | if (occs.empty() || (prevOCCSearch.size() != occs.size())) |
| 69 | { |
| 70 | // Something changed or no OCCs yet, try again in 10s. |
| 71 | // Note on the first pass prevOCCSearch will be empty, |
| 72 | // so there will be at least one delay to give things |
| 73 | // a chance to settle. |
| 74 | prevOCCSearch = occs; |
| 75 | |
Matt Spinler | d267cec | 2021-09-01 14:49:19 -0500 | [diff] [blame] | 76 | discoverTimer->restartOnce(10s); |
| 77 | } |
| 78 | else |
| 79 | { |
| 80 | discoverTimer.reset(); |
| 81 | |
| 82 | // createObjects requires OCC0 first. |
| 83 | std::sort(occs.begin(), occs.end()); |
| 84 | |
| 85 | for (auto id : occs) |
| 86 | { |
| 87 | createObjects(std::string(OCC_NAME) + std::to_string(id)); |
| 88 | } |
| 89 | } |
| 90 | #endif |
| 91 | } |
| 92 | |
| 93 | std::vector<int> Manager::findOCCsInDev() |
| 94 | { |
| 95 | std::vector<int> occs; |
| 96 | std::regex expr{R"(occ(\d+)$)"}; |
| 97 | |
| 98 | for (auto& file : fs::directory_iterator("/dev")) |
| 99 | { |
| 100 | std::smatch match; |
| 101 | std::string path{file.path().string()}; |
| 102 | if (std::regex_search(path, match, expr)) |
| 103 | { |
| 104 | auto num = std::stoi(match[1].str()); |
| 105 | |
| 106 | // /dev numbering starts at 1, ours starts at 0. |
| 107 | occs.push_back(num - 1); |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | return occs; |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | int Manager::cpuCreated(sdbusplus::message::message& msg) |
| 115 | { |
George Liu | bcef3b4 | 2021-09-10 12:39:02 +0800 | [diff] [blame] | 116 | namespace fs = std::filesystem; |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 117 | |
| 118 | sdbusplus::message::object_path o; |
| 119 | msg.read(o); |
| 120 | fs::path cpuPath(std::string(std::move(o))); |
| 121 | |
| 122 | auto name = cpuPath.filename().string(); |
| 123 | auto index = name.find(CPU_NAME); |
| 124 | name.replace(index, std::strlen(CPU_NAME), OCC_NAME); |
| 125 | |
| 126 | createObjects(name); |
| 127 | |
| 128 | return 0; |
| 129 | } |
| 130 | |
| 131 | void Manager::createObjects(const std::string& occ) |
| 132 | { |
| 133 | auto path = fs::path(OCC_CONTROL_ROOT) / occ; |
| 134 | |
| 135 | passThroughObjects.emplace_back( |
George Liu | f3b7514 | 2021-06-10 11:22:50 +0800 | [diff] [blame] | 136 | std::make_unique<PassThrough>(path.c_str())); |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 137 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 138 | statusObjects.emplace_back(std::make_unique<Status>( |
George Liu | f3b7514 | 2021-06-10 11:22:50 +0800 | [diff] [blame] | 139 | event, path.c_str(), *this, |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 140 | std::bind(std::mem_fn(&Manager::statusCallBack), this, |
Tom Joseph | 0032523 | 2020-07-29 17:51:48 +0530 | [diff] [blame] | 141 | std::placeholders::_1) |
| 142 | #ifdef PLDM |
| 143 | , |
| 144 | std::bind(std::mem_fn(&pldm::Interface::resetOCC), pldmHandle.get(), |
| 145 | std::placeholders::_1) |
| 146 | #endif |
| 147 | )); |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 148 | |
| 149 | // Create the power cap monitor object for master occ (0) |
| 150 | if (!pcap) |
| 151 | { |
| 152 | pcap = std::make_unique<open_power::occ::powercap::PowerCap>( |
George Liu | f3b7514 | 2021-06-10 11:22:50 +0800 | [diff] [blame] | 153 | *statusObjects.front()); |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 154 | } |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 155 | |
| 156 | #ifdef POWER10 |
| 157 | // Create the power mode monitor object for master occ (0) |
| 158 | if (!pmode) |
| 159 | { |
| 160 | pmode = std::make_unique<open_power::occ::powermode::PowerMode>( |
| 161 | *statusObjects.front()); |
| 162 | } |
Chris Cain | 1d51da2 | 2021-09-21 14:13:41 -0500 | [diff] [blame] | 163 | // Create the idle power saver monitor object for master occ (0) |
| 164 | if (!pips) |
| 165 | { |
| 166 | pips = std::make_unique<open_power::occ::powermode::PowerIPS>( |
| 167 | *statusObjects.front()); |
| 168 | } |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 169 | #endif |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | void Manager::statusCallBack(bool status) |
| 173 | { |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 174 | using InternalFailure = |
| 175 | sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure; |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 176 | |
| 177 | // At this time, it won't happen but keeping it |
| 178 | // here just in case something changes in the future |
| 179 | if ((activeCount == 0) && (!status)) |
| 180 | { |
| 181 | log<level::ERR>("Invalid update on OCCActive"); |
| 182 | elog<InternalFailure>(); |
| 183 | } |
| 184 | |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 185 | if (status == true) |
Eddie James | dae2d94 | 2017-12-20 10:50:03 -0600 | [diff] [blame] | 186 | { |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 187 | // OCC went active |
| 188 | ++activeCount; |
| 189 | |
| 190 | #ifdef POWER10 |
| 191 | if (activeCount == 1) |
Eddie James | dae2d94 | 2017-12-20 10:50:03 -0600 | [diff] [blame] | 192 | { |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 193 | // First OCC went active (allow some time for all OCCs to go active) |
| 194 | waitForAllOccsTimer->restartOnce(30s); |
Matt Spinler | 53f6814 | 2021-08-25 15:47:31 -0500 | [diff] [blame] | 195 | } |
| 196 | #endif |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 197 | |
| 198 | if (activeCount == statusObjects.size()) |
| 199 | { |
| 200 | #ifdef POWER10 |
| 201 | // All OCCs are now running |
| 202 | if (waitForAllOccsTimer->isEnabled()) |
| 203 | { |
| 204 | // stop occ wait timer |
| 205 | waitForAllOccsTimer->setEnabled(false); |
| 206 | } |
| 207 | #endif |
| 208 | |
| 209 | // Verify master OCC and start presence monitor |
| 210 | validateOccMaster(); |
| 211 | } |
| 212 | |
| 213 | // Start poll timer if not already started |
| 214 | if (!_pollTimer->isEnabled()) |
| 215 | { |
| 216 | log<level::INFO>( |
| 217 | fmt::format( |
| 218 | "Manager::statusCallBack(): {} OCCs will be polled every {} seconds", |
| 219 | activeCount, pollInterval) |
| 220 | .c_str()); |
| 221 | |
| 222 | // Send poll and start OCC poll timer |
| 223 | pollerTimerExpired(); |
| 224 | } |
| 225 | } |
| 226 | else |
| 227 | { |
| 228 | // OCC went away |
| 229 | --activeCount; |
| 230 | |
| 231 | if (activeCount == 0) |
| 232 | { |
| 233 | // No OCCs are running |
| 234 | |
| 235 | // Stop OCC poll timer |
| 236 | if (_pollTimer->isEnabled()) |
| 237 | { |
| 238 | log<level::INFO>( |
| 239 | "Manager::statusCallBack(): OCCs are not running, stopping poll timer"); |
| 240 | _pollTimer->setEnabled(false); |
| 241 | } |
| 242 | |
| 243 | #ifdef POWER10 |
| 244 | // stop wait timer |
| 245 | if (waitForAllOccsTimer->isEnabled()) |
| 246 | { |
| 247 | waitForAllOccsTimer->setEnabled(false); |
| 248 | } |
| 249 | #endif |
| 250 | |
| 251 | #ifdef READ_OCC_SENSORS |
| 252 | // Clear OCC sensors |
| 253 | for (auto& obj : statusObjects) |
| 254 | { |
| 255 | setSensorValueToNaN(obj->getOccInstanceID()); |
| 256 | } |
| 257 | #endif |
| 258 | } |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 259 | } |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | #ifdef I2C_OCC |
| 263 | void Manager::initStatusObjects() |
| 264 | { |
| 265 | // Make sure we have a valid path string |
| 266 | static_assert(sizeof(DEV_PATH) != 0); |
| 267 | |
| 268 | auto deviceNames = i2c_occ::getOccHwmonDevices(DEV_PATH); |
Lei YU | 41470e5 | 2017-11-30 16:03:50 +0800 | [diff] [blame] | 269 | auto occMasterName = deviceNames.front(); |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 270 | for (auto& name : deviceNames) |
| 271 | { |
| 272 | i2c_occ::i2cToDbus(name); |
Lei YU | b5259a1 | 2017-09-01 16:22:40 +0800 | [diff] [blame] | 273 | name = std::string(OCC_NAME) + '_' + name; |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 274 | auto path = fs::path(OCC_CONTROL_ROOT) / name; |
| 275 | statusObjects.emplace_back( |
George Liu | f3b7514 | 2021-06-10 11:22:50 +0800 | [diff] [blame] | 276 | std::make_unique<Status>(event, path.c_str(), *this)); |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 277 | } |
Lei YU | 41470e5 | 2017-11-30 16:03:50 +0800 | [diff] [blame] | 278 | // The first device is master occ |
| 279 | pcap = std::make_unique<open_power::occ::powercap::PowerCap>( |
George Liu | f3b7514 | 2021-06-10 11:22:50 +0800 | [diff] [blame] | 280 | *statusObjects.front(), occMasterName); |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 281 | #ifdef POWER10 |
| 282 | pmode = std::make_unique<open_power::occ::powermode::PowerMode>( |
| 283 | *statusObjects.front()); |
Chris Cain | 1d51da2 | 2021-09-21 14:13:41 -0500 | [diff] [blame] | 284 | pips = std::make_unique<open_power::occ::powermode::PowerIPS>( |
| 285 | *statusObjects.front()); |
Chris Cain | 78e8601 | 2021-03-04 16:15:31 -0600 | [diff] [blame] | 286 | #endif |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 287 | } |
| 288 | #endif |
| 289 | |
Tom Joseph | 815f9f5 | 2020-07-27 12:12:13 +0530 | [diff] [blame] | 290 | #ifdef PLDM |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 291 | void Manager::sbeTimeout(unsigned int instance) |
| 292 | { |
| 293 | log<level::INFO>("SBE timeout, requesting HRESET", |
| 294 | entry("SBE=%d", instance)); |
| 295 | |
| 296 | setSBEState(instance, SBE_STATE_NOT_USABLE); |
| 297 | |
| 298 | pldmHandle->sendHRESET(instance); |
| 299 | } |
| 300 | |
Tom Joseph | 815f9f5 | 2020-07-27 12:12:13 +0530 | [diff] [blame] | 301 | bool Manager::updateOCCActive(instanceID instance, bool status) |
| 302 | { |
| 303 | return (statusObjects[instance])->occActive(status); |
| 304 | } |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 305 | |
| 306 | void Manager::sbeHRESETResult(instanceID instance, bool success) |
| 307 | { |
| 308 | if (success) |
| 309 | { |
| 310 | log<level::INFO>("HRESET succeeded", entry("SBE=%d", instance)); |
| 311 | |
| 312 | setSBEState(instance, SBE_STATE_BOOTED); |
| 313 | |
| 314 | return; |
| 315 | } |
| 316 | |
| 317 | setSBEState(instance, SBE_STATE_FAILED); |
| 318 | |
| 319 | if (sbeCanDump(instance)) |
| 320 | { |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 321 | log<level::INFO>("HRESET failed, triggering SBE dump", |
| 322 | entry("SBE=%d", instance)); |
| 323 | |
| 324 | auto& bus = utils::getBus(); |
| 325 | uint32_t src6 = instance << 16; |
| 326 | uint32_t logId = |
| 327 | FFDC::createPEL("org.open_power.Processor.Error.SbeChipOpTimeout", |
| 328 | src6, "SBE command timeout"); |
| 329 | |
| 330 | try |
| 331 | { |
George Liu | f3a4a69 | 2021-12-28 13:59:51 +0800 | [diff] [blame^] | 332 | constexpr auto path = "/org/openpower/dump"; |
| 333 | constexpr auto interface = "xyz.openbmc_project.Dump.Create"; |
| 334 | constexpr auto function = "CreateDump"; |
| 335 | |
Eddie James | cbad219 | 2021-10-07 09:39:39 -0500 | [diff] [blame] | 336 | std::string service = utils::getService(path, interface); |
| 337 | auto method = |
| 338 | bus.new_method_call(service.c_str(), path, interface, function); |
| 339 | |
| 340 | std::map<std::string, std::variant<std::string, uint64_t>> |
| 341 | createParams{ |
| 342 | {"com.ibm.Dump.Create.CreateParameters.ErrorLogId", |
| 343 | uint64_t(logId)}, |
| 344 | {"com.ibm.Dump.Create.CreateParameters.DumpType", |
| 345 | "com.ibm.Dump.Create.DumpType.SBE"}, |
| 346 | {"com.ibm.Dump.Create.CreateParameters.FailingUnitId", |
| 347 | uint64_t(instance)}, |
| 348 | }; |
| 349 | |
| 350 | method.append(createParams); |
| 351 | |
| 352 | auto response = bus.call(method); |
| 353 | } |
| 354 | catch (const sdbusplus::exception::exception& e) |
| 355 | { |
| 356 | constexpr auto ERROR_DUMP_DISABLED = |
| 357 | "xyz.openbmc_project.Dump.Create.Error.Disabled"; |
| 358 | if (e.name() == ERROR_DUMP_DISABLED) |
| 359 | { |
| 360 | log<level::INFO>("Dump is disabled, skipping"); |
| 361 | } |
| 362 | else |
| 363 | { |
| 364 | log<level::ERR>("Dump failed"); |
| 365 | } |
| 366 | } |
| 367 | } |
| 368 | } |
| 369 | |
| 370 | bool Manager::sbeCanDump(unsigned int instance) |
| 371 | { |
| 372 | struct pdbg_target* proc = getPdbgTarget(instance); |
| 373 | |
| 374 | if (!proc) |
| 375 | { |
| 376 | // allow the dump in the error case |
| 377 | return true; |
| 378 | } |
| 379 | |
| 380 | try |
| 381 | { |
| 382 | if (!openpower::phal::sbe::isDumpAllowed(proc)) |
| 383 | { |
| 384 | return false; |
| 385 | } |
| 386 | |
| 387 | if (openpower::phal::pdbg::isSbeVitalAttnActive(proc)) |
| 388 | { |
| 389 | return false; |
| 390 | } |
| 391 | } |
| 392 | catch (openpower::phal::exception::SbeError& e) |
| 393 | { |
| 394 | log<level::INFO>("Failed to query SBE state"); |
| 395 | } |
| 396 | |
| 397 | // allow the dump in the error case |
| 398 | return true; |
| 399 | } |
| 400 | |
| 401 | void Manager::setSBEState(unsigned int instance, enum sbe_state state) |
| 402 | { |
| 403 | struct pdbg_target* proc = getPdbgTarget(instance); |
| 404 | |
| 405 | if (!proc) |
| 406 | { |
| 407 | return; |
| 408 | } |
| 409 | |
| 410 | try |
| 411 | { |
| 412 | openpower::phal::sbe::setState(proc, state); |
| 413 | } |
| 414 | catch (const openpower::phal::exception::SbeError& e) |
| 415 | { |
| 416 | log<level::ERR>("Failed to set SBE state"); |
| 417 | } |
| 418 | } |
| 419 | |
| 420 | struct pdbg_target* Manager::getPdbgTarget(unsigned int instance) |
| 421 | { |
| 422 | if (!pdbgInitialized) |
| 423 | { |
| 424 | try |
| 425 | { |
| 426 | openpower::phal::pdbg::init(); |
| 427 | pdbgInitialized = true; |
| 428 | } |
| 429 | catch (const openpower::phal::exception::PdbgError& e) |
| 430 | { |
| 431 | log<level::ERR>("pdbg initialization failed"); |
| 432 | return nullptr; |
| 433 | } |
| 434 | } |
| 435 | |
| 436 | struct pdbg_target* proc = nullptr; |
| 437 | pdbg_for_each_class_target("proc", proc) |
| 438 | { |
| 439 | if (pdbg_target_index(proc) == instance) |
| 440 | { |
| 441 | return proc; |
| 442 | } |
| 443 | } |
| 444 | |
| 445 | log<level::ERR>("Failed to get pdbg target"); |
| 446 | return nullptr; |
| 447 | } |
Tom Joseph | 815f9f5 | 2020-07-27 12:12:13 +0530 | [diff] [blame] | 448 | #endif |
| 449 | |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 450 | void Manager::pollerTimerExpired() |
| 451 | { |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 452 | if (!_pollTimer) |
| 453 | { |
| 454 | log<level::ERR>( |
| 455 | "Manager::pollerTimerExpired() ERROR: Timer not defined"); |
| 456 | return; |
| 457 | } |
| 458 | |
| 459 | for (auto& obj : statusObjects) |
| 460 | { |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 461 | #ifdef READ_OCC_SENSORS |
| 462 | auto id = obj->getOccInstanceID(); |
| 463 | #endif |
| 464 | if (!obj->occActive()) |
| 465 | { |
| 466 | // OCC is not running yet |
| 467 | #ifdef READ_OCC_SENSORS |
| 468 | setSensorValueToNaN(id); |
| 469 | #endif |
| 470 | continue; |
| 471 | } |
| 472 | |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 473 | // Read sysfs to force kernel to poll OCC |
| 474 | obj->readOccState(); |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 475 | |
| 476 | #ifdef READ_OCC_SENSORS |
| 477 | // Read occ sensor values |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 478 | getSensorValues(id, obj->isMasterOcc()); |
| 479 | #endif |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 480 | } |
| 481 | |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 482 | if (activeCount > 0) |
| 483 | { |
| 484 | // Restart OCC poll timer |
| 485 | _pollTimer->restartOnce(std::chrono::seconds(pollInterval)); |
| 486 | } |
| 487 | else |
| 488 | { |
| 489 | // No OCCs running, so poll timer will not be restarted |
| 490 | log<level::INFO>( |
| 491 | fmt::format( |
| 492 | "Manager::pollerTimerExpired: poll timer will not be restarted") |
| 493 | .c_str()); |
| 494 | } |
Chris Cain | a8857c5 | 2021-01-27 11:53:05 -0600 | [diff] [blame] | 495 | } |
| 496 | |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 497 | #ifdef READ_OCC_SENSORS |
| 498 | void Manager::readTempSensors(const fs::path& path, uint32_t id) |
| 499 | { |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 500 | std::regex expr{"temp\\d+_label$"}; // Example: temp5_label |
| 501 | for (auto& file : fs::directory_iterator(path)) |
| 502 | { |
| 503 | if (!std::regex_search(file.path().string(), expr)) |
| 504 | { |
| 505 | continue; |
| 506 | } |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 507 | |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 508 | uint32_t labelValue{0}; |
| 509 | |
| 510 | try |
| 511 | { |
| 512 | labelValue = readFile<uint32_t>(file.path()); |
| 513 | } |
| 514 | catch (const std::system_error& e) |
| 515 | { |
| 516 | log<level::DEBUG>( |
| 517 | fmt::format("readTempSensors: Failed reading {}, errno = {}", |
| 518 | file.path().string(), e.code().value()) |
| 519 | .c_str()); |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 520 | continue; |
| 521 | } |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 522 | |
| 523 | const std::string& tempLabel = "label"; |
| 524 | const std::string filePathString = file.path().string().substr( |
| 525 | 0, file.path().string().length() - tempLabel.length()); |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 526 | |
| 527 | uint32_t fruTypeValue{0}; |
| 528 | try |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 529 | { |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 530 | fruTypeValue = readFile<uint32_t>(filePathString + fruTypeSuffix); |
| 531 | } |
| 532 | catch (const std::system_error& e) |
| 533 | { |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 534 | log<level::DEBUG>( |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 535 | fmt::format("readTempSensors: Failed reading {}, errno = {}", |
| 536 | filePathString + fruTypeSuffix, e.code().value()) |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 537 | .c_str()); |
| 538 | continue; |
| 539 | } |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 540 | |
| 541 | std::string sensorPath = |
| 542 | OCC_SENSORS_ROOT + std::string("/temperature/"); |
| 543 | |
Matt Spinler | ace67d8 | 2021-10-18 13:41:57 -0500 | [diff] [blame] | 544 | std::string dvfsTempPath; |
| 545 | |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 546 | if (fruTypeValue == VRMVdd) |
| 547 | { |
| 548 | sensorPath.append("vrm_vdd" + std::to_string(id) + "_temp"); |
| 549 | } |
Matt Spinler | ace67d8 | 2021-10-18 13:41:57 -0500 | [diff] [blame] | 550 | else if (fruTypeValue == processorIoRing) |
| 551 | { |
| 552 | sensorPath.append("proc" + std::to_string(id) + "_ioring_temp"); |
| 553 | dvfsTempPath = std::string{OCC_SENSORS_ROOT} + "/temperature/proc" + |
| 554 | std::to_string(id) + "_ioring_dvfs_temp"; |
| 555 | } |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 556 | else |
| 557 | { |
Matt Spinler | 14d1402 | 2021-08-25 15:38:29 -0500 | [diff] [blame] | 558 | uint16_t type = (labelValue & 0xFF000000) >> 24; |
| 559 | uint16_t instanceID = labelValue & 0x0000FFFF; |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 560 | |
| 561 | if (type == OCC_DIMM_TEMP_SENSOR_TYPE) |
| 562 | { |
Matt Spinler | 8b8abee | 2021-08-25 15:18:21 -0500 | [diff] [blame] | 563 | if (fruTypeValue == fruTypeNotAvailable) |
| 564 | { |
| 565 | // Not all DIMM related temps are available to read |
| 566 | // (no _input file in this case) |
| 567 | continue; |
| 568 | } |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 569 | auto iter = dimmTempSensorName.find(fruTypeValue); |
| 570 | if (iter == dimmTempSensorName.end()) |
| 571 | { |
George Liu | b5ca101 | 2021-09-10 12:53:11 +0800 | [diff] [blame] | 572 | log<level::ERR>( |
| 573 | fmt::format( |
| 574 | "readTempSensors: Fru type error! fruTypeValue = {}) ", |
| 575 | fruTypeValue) |
| 576 | .c_str()); |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 577 | continue; |
| 578 | } |
| 579 | |
| 580 | sensorPath.append("dimm" + std::to_string(instanceID) + |
| 581 | iter->second); |
| 582 | } |
| 583 | else if (type == OCC_CPU_TEMP_SENSOR_TYPE) |
| 584 | { |
Matt Spinler | ace67d8 | 2021-10-18 13:41:57 -0500 | [diff] [blame] | 585 | if (fruTypeValue == processorCore) |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 586 | { |
Matt Spinler | ace67d8 | 2021-10-18 13:41:57 -0500 | [diff] [blame] | 587 | // The OCC reports small core temps, of which there are |
| 588 | // two per big core. All current P10 systems are in big |
| 589 | // core mode, so use a big core name. |
| 590 | uint16_t coreNum = instanceID / 2; |
| 591 | uint16_t tempNum = instanceID % 2; |
| 592 | sensorPath.append("proc" + std::to_string(id) + "_core" + |
| 593 | std::to_string(coreNum) + "_" + |
| 594 | std::to_string(tempNum) + "_temp"); |
| 595 | |
| 596 | dvfsTempPath = std::string{OCC_SENSORS_ROOT} + |
| 597 | "/temperature/proc" + std::to_string(id) + |
| 598 | "_core_dvfs_temp"; |
| 599 | } |
| 600 | else |
| 601 | { |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 602 | continue; |
| 603 | } |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 604 | } |
| 605 | else |
| 606 | { |
| 607 | continue; |
| 608 | } |
| 609 | } |
| 610 | |
Matt Spinler | ace67d8 | 2021-10-18 13:41:57 -0500 | [diff] [blame] | 611 | // The dvfs temp file only needs to be read once per chip per type. |
| 612 | if (!dvfsTempPath.empty() && |
| 613 | !dbus::OccDBusSensors::getOccDBus().hasDvfsTemp(dvfsTempPath)) |
| 614 | { |
| 615 | try |
| 616 | { |
| 617 | auto dvfsValue = readFile<double>(filePathString + maxSuffix); |
| 618 | |
| 619 | dbus::OccDBusSensors::getOccDBus().setDvfsTemp( |
| 620 | dvfsTempPath, dvfsValue * std::pow(10, -3)); |
| 621 | } |
| 622 | catch (const std::system_error& e) |
| 623 | { |
| 624 | log<level::DEBUG>( |
| 625 | fmt::format( |
| 626 | "readTempSensors: Failed reading {}, errno = {}", |
| 627 | filePathString + maxSuffix, e.code().value()) |
| 628 | .c_str()); |
| 629 | } |
| 630 | } |
| 631 | |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 632 | uint32_t faultValue{0}; |
| 633 | try |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 634 | { |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 635 | faultValue = readFile<uint32_t>(filePathString + faultSuffix); |
| 636 | } |
| 637 | catch (const std::system_error& e) |
| 638 | { |
| 639 | log<level::DEBUG>( |
| 640 | fmt::format("readTempSensors: Failed reading {}, errno = {}", |
| 641 | filePathString + faultSuffix, e.code().value()) |
| 642 | .c_str()); |
| 643 | continue; |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 644 | } |
| 645 | |
Matt Spinler | 5901abd | 2021-09-23 13:50:03 -0500 | [diff] [blame] | 646 | // At this point, the sensor will be created for sure. |
| 647 | if (existingSensors.find(sensorPath) == existingSensors.end()) |
| 648 | { |
| 649 | open_power::occ::dbus::OccDBusSensors::getOccDBus() |
| 650 | .setChassisAssociation(sensorPath); |
| 651 | } |
| 652 | |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 653 | if (faultValue != 0) |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 654 | { |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 655 | open_power::occ::dbus::OccDBusSensors::getOccDBus().setValue( |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 656 | sensorPath, std::numeric_limits<double>::quiet_NaN()); |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 657 | |
| 658 | open_power::occ::dbus::OccDBusSensors::getOccDBus() |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 659 | .setOperationalStatus(sensorPath, false); |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 660 | |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 661 | continue; |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 662 | } |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 663 | |
| 664 | double tempValue{0}; |
| 665 | |
| 666 | try |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 667 | { |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 668 | tempValue = readFile<double>(filePathString + inputSuffix); |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 669 | } |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 670 | catch (const std::system_error& e) |
| 671 | { |
| 672 | log<level::DEBUG>( |
| 673 | fmt::format("readTempSensors: Failed reading {}, errno = {}", |
| 674 | filePathString + inputSuffix, e.code().value()) |
| 675 | .c_str()); |
| 676 | continue; |
| 677 | } |
| 678 | |
| 679 | open_power::occ::dbus::OccDBusSensors::getOccDBus().setValue( |
| 680 | sensorPath, tempValue * std::pow(10, -3)); |
| 681 | |
| 682 | open_power::occ::dbus::OccDBusSensors::getOccDBus() |
| 683 | .setOperationalStatus(sensorPath, true); |
| 684 | |
| 685 | existingSensors[sensorPath] = id; |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 686 | } |
| 687 | return; |
| 688 | } |
| 689 | |
| 690 | std::optional<std::string> |
| 691 | Manager::getPowerLabelFunctionID(const std::string& value) |
| 692 | { |
| 693 | // If the value is "system", then the FunctionID is "system". |
| 694 | if (value == "system") |
| 695 | { |
| 696 | return value; |
| 697 | } |
| 698 | |
| 699 | // If the value is not "system", then the label value have 3 numbers, of |
| 700 | // which we only care about the middle one: |
| 701 | // <sensor id>_<function id>_<apss channel> |
| 702 | // eg: The value is "0_10_5" , then the FunctionID is "10". |
| 703 | if (value.find("_") == std::string::npos) |
| 704 | { |
| 705 | return std::nullopt; |
| 706 | } |
| 707 | |
| 708 | auto powerLabelValue = value.substr((value.find("_") + 1)); |
| 709 | |
| 710 | if (powerLabelValue.find("_") == std::string::npos) |
| 711 | { |
| 712 | return std::nullopt; |
| 713 | } |
| 714 | |
| 715 | return powerLabelValue.substr(0, powerLabelValue.find("_")); |
| 716 | } |
| 717 | |
| 718 | void Manager::readPowerSensors(const fs::path& path, uint32_t id) |
| 719 | { |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 720 | std::regex expr{"power\\d+_label$"}; // Example: power5_label |
| 721 | for (auto& file : fs::directory_iterator(path)) |
| 722 | { |
| 723 | if (!std::regex_search(file.path().string(), expr)) |
| 724 | { |
| 725 | continue; |
| 726 | } |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 727 | |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 728 | std::string labelValue; |
| 729 | try |
| 730 | { |
| 731 | labelValue = readFile<std::string>(file.path()); |
| 732 | } |
| 733 | catch (const std::system_error& e) |
| 734 | { |
| 735 | log<level::DEBUG>( |
| 736 | fmt::format("readPowerSensors: Failed reading {}, errno = {}", |
| 737 | file.path().string(), e.code().value()) |
| 738 | .c_str()); |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 739 | continue; |
| 740 | } |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 741 | |
| 742 | auto functionID = getPowerLabelFunctionID(labelValue); |
| 743 | if (functionID == std::nullopt) |
| 744 | { |
| 745 | continue; |
| 746 | } |
| 747 | |
| 748 | const std::string& tempLabel = "label"; |
| 749 | const std::string filePathString = file.path().string().substr( |
| 750 | 0, file.path().string().length() - tempLabel.length()); |
| 751 | |
| 752 | std::string sensorPath = OCC_SENSORS_ROOT + std::string("/power/"); |
| 753 | |
| 754 | auto iter = powerSensorName.find(*functionID); |
| 755 | if (iter == powerSensorName.end()) |
| 756 | { |
| 757 | continue; |
| 758 | } |
| 759 | sensorPath.append(iter->second); |
| 760 | |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 761 | double tempValue{0}; |
| 762 | |
| 763 | try |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 764 | { |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 765 | tempValue = readFile<double>(filePathString + inputSuffix); |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 766 | } |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 767 | catch (const std::system_error& e) |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 768 | { |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 769 | log<level::DEBUG>( |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 770 | fmt::format("readTempSensors: Failed reading {}, errno = {}", |
| 771 | filePathString + inputSuffix, e.code().value()) |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 772 | .c_str()); |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 773 | continue; |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 774 | } |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 775 | |
| 776 | open_power::occ::dbus::OccDBusSensors::getOccDBus().setValue( |
| 777 | sensorPath, tempValue * std::pow(10, -3) * std::pow(10, -3)); |
| 778 | |
| 779 | open_power::occ::dbus::OccDBusSensors::getOccDBus() |
| 780 | .setOperationalStatus(sensorPath, true); |
| 781 | |
Matt Spinler | 5901abd | 2021-09-23 13:50:03 -0500 | [diff] [blame] | 782 | if (existingSensors.find(sensorPath) == existingSensors.end()) |
| 783 | { |
| 784 | open_power::occ::dbus::OccDBusSensors::getOccDBus() |
| 785 | .setChassisAssociation(sensorPath); |
| 786 | } |
| 787 | |
Matt Spinler | a26f152 | 2021-08-25 15:50:20 -0500 | [diff] [blame] | 788 | existingSensors[sensorPath] = id; |
Chicago Duan | bb895cb | 2021-06-18 19:37:16 +0800 | [diff] [blame] | 789 | } |
| 790 | return; |
| 791 | } |
| 792 | |
| 793 | void Manager::setSensorValueToNaN(uint32_t id) |
| 794 | { |
| 795 | for (const auto& [sensorPath, occId] : existingSensors) |
| 796 | { |
| 797 | if (occId == id) |
| 798 | { |
| 799 | open_power::occ::dbus::OccDBusSensors::getOccDBus().setValue( |
| 800 | sensorPath, std::numeric_limits<double>::quiet_NaN()); |
| 801 | } |
| 802 | } |
| 803 | return; |
| 804 | } |
| 805 | |
| 806 | void Manager::getSensorValues(uint32_t id, bool masterOcc) |
| 807 | { |
| 808 | const auto occ = std::string("occ-hwmon.") + std::to_string(id + 1); |
| 809 | |
| 810 | fs::path fileName{OCC_HWMON_PATH + occ + "/hwmon/"}; |
| 811 | |
| 812 | // Need to get the hwmonXX directory name, there better only be 1 dir |
| 813 | assert(std::distance(fs::directory_iterator(fileName), |
| 814 | fs::directory_iterator{}) == 1); |
| 815 | // Now set our path to this full path, including this hwmonXX directory |
| 816 | fileName = fs::path(*fs::directory_iterator(fileName)); |
| 817 | |
| 818 | // Read temperature sensors |
| 819 | readTempSensors(fileName, id); |
| 820 | |
| 821 | if (masterOcc) |
| 822 | { |
| 823 | // Read power sensors |
| 824 | readPowerSensors(fileName, id); |
| 825 | } |
| 826 | |
| 827 | return; |
| 828 | } |
| 829 | #endif |
Chris Cain | 1725767 | 2021-10-22 13:41:03 -0500 | [diff] [blame] | 830 | |
| 831 | // Read the altitude from DBus |
| 832 | void Manager::readAltitude() |
| 833 | { |
| 834 | static bool traceAltitudeErr = true; |
| 835 | |
| 836 | utils::PropertyValue altitudeProperty{}; |
| 837 | try |
| 838 | { |
| 839 | altitudeProperty = utils::getProperty(ALTITUDE_PATH, ALTITUDE_INTERFACE, |
| 840 | ALTITUDE_PROP); |
| 841 | auto sensorVal = std::get<double>(altitudeProperty); |
| 842 | if (sensorVal < 0xFFFF) |
| 843 | { |
| 844 | if (sensorVal < 0) |
| 845 | { |
| 846 | altitude = 0; |
| 847 | } |
| 848 | else |
| 849 | { |
| 850 | // Round to nearest meter |
| 851 | altitude = uint16_t(sensorVal + 0.5); |
| 852 | } |
| 853 | log<level::DEBUG>(fmt::format("readAltitude: sensor={} ({}m)", |
| 854 | sensorVal, altitude) |
| 855 | .c_str()); |
| 856 | traceAltitudeErr = true; |
| 857 | } |
| 858 | else |
| 859 | { |
| 860 | if (traceAltitudeErr) |
| 861 | { |
| 862 | traceAltitudeErr = false; |
| 863 | log<level::DEBUG>( |
| 864 | fmt::format("Invalid altitude value: {}", sensorVal) |
| 865 | .c_str()); |
| 866 | } |
| 867 | } |
| 868 | } |
| 869 | catch (const sdbusplus::exception::exception& e) |
| 870 | { |
| 871 | if (traceAltitudeErr) |
| 872 | { |
| 873 | traceAltitudeErr = false; |
| 874 | log<level::INFO>( |
| 875 | fmt::format("Unable to read Altitude: {}", e.what()).c_str()); |
| 876 | } |
| 877 | altitude = 0xFFFF; // not available |
| 878 | } |
| 879 | } |
| 880 | |
| 881 | // Callback function when ambient temperature changes |
| 882 | void Manager::ambientCallback(sdbusplus::message::message& msg) |
| 883 | { |
| 884 | double currentTemp = 0; |
| 885 | uint8_t truncatedTemp = 0xFF; |
| 886 | std::string msgSensor; |
| 887 | std::map<std::string, std::variant<double>> msgData; |
| 888 | msg.read(msgSensor, msgData); |
| 889 | |
| 890 | auto valPropMap = msgData.find(AMBIENT_PROP); |
| 891 | if (valPropMap == msgData.end()) |
| 892 | { |
| 893 | log<level::DEBUG>("ambientCallback: Unknown ambient property changed"); |
| 894 | return; |
| 895 | } |
| 896 | currentTemp = std::get<double>(valPropMap->second); |
| 897 | if (std::isnan(currentTemp)) |
| 898 | { |
| 899 | truncatedTemp = 0xFF; |
| 900 | } |
| 901 | else |
| 902 | { |
| 903 | if (currentTemp < 0) |
| 904 | { |
| 905 | truncatedTemp = 0; |
| 906 | } |
| 907 | else |
| 908 | { |
| 909 | // Round to nearest degree C |
| 910 | truncatedTemp = uint8_t(currentTemp + 0.5); |
| 911 | } |
| 912 | } |
| 913 | |
| 914 | // If ambient changes, notify OCCs |
| 915 | if (truncatedTemp != ambient) |
| 916 | { |
| 917 | log<level::DEBUG>( |
| 918 | fmt::format("ambientCallback: Ambient change from {} to {}C", |
| 919 | ambient, currentTemp) |
| 920 | .c_str()); |
| 921 | |
| 922 | ambient = truncatedTemp; |
| 923 | if (altitude == 0xFFFF) |
| 924 | { |
| 925 | // No altitude yet, try reading again |
| 926 | readAltitude(); |
| 927 | } |
| 928 | |
| 929 | log<level::DEBUG>( |
| 930 | fmt::format("ambientCallback: Ambient: {}C, altitude: {}m", ambient, |
| 931 | altitude) |
| 932 | .c_str()); |
| 933 | #ifdef POWER10 |
| 934 | // Send ambient and altitude to all OCCs |
| 935 | for (auto& obj : statusObjects) |
| 936 | { |
| 937 | if (obj->occActive()) |
| 938 | { |
| 939 | obj->sendAmbient(ambient, altitude); |
| 940 | } |
| 941 | } |
| 942 | #endif // POWER10 |
| 943 | } |
| 944 | } |
| 945 | |
| 946 | // return the current ambient and altitude readings |
| 947 | void Manager::getAmbientData(bool& ambientValid, uint8_t& ambientTemp, |
| 948 | uint16_t& altitudeValue) const |
| 949 | { |
| 950 | ambientValid = true; |
| 951 | ambientTemp = ambient; |
| 952 | altitudeValue = altitude; |
| 953 | |
| 954 | if (ambient == 0xFF) |
| 955 | { |
| 956 | ambientValid = false; |
| 957 | } |
| 958 | } |
| 959 | |
Chris Cain | a7b74dc | 2021-11-10 17:03:43 -0600 | [diff] [blame] | 960 | #ifdef POWER10 |
| 961 | void Manager::occsNotAllRunning() |
| 962 | { |
| 963 | // Function will also gets called when occ-control app gets restarted. |
| 964 | // (occ active sensors do not change, so the Status object does not |
| 965 | // call Manager back for all OCCs) |
| 966 | |
| 967 | if (activeCount != statusObjects.size()) |
| 968 | { |
| 969 | // Not all OCCs went active |
| 970 | log<level::WARNING>( |
| 971 | fmt::format( |
| 972 | "occsNotAllRunning: Active OCC count ({}) does not match expected count ({})", |
| 973 | activeCount, statusObjects.size()) |
| 974 | .c_str()); |
| 975 | // Procs may be garded, so may not need reset. |
| 976 | } |
| 977 | |
| 978 | validateOccMaster(); |
| 979 | } |
| 980 | #endif // POWER10 |
| 981 | |
| 982 | // Verify single master OCC and start presence monitor |
| 983 | void Manager::validateOccMaster() |
| 984 | { |
| 985 | int masterInstance = -1; |
| 986 | for (auto& obj : statusObjects) |
| 987 | { |
| 988 | obj->addPresenceWatchMaster(); |
| 989 | if (obj->isMasterOcc()) |
| 990 | { |
| 991 | if (masterInstance == -1) |
| 992 | { |
| 993 | masterInstance = obj->getOccInstanceID(); |
| 994 | } |
| 995 | else |
| 996 | { |
| 997 | log<level::ERR>( |
| 998 | fmt::format( |
| 999 | "validateOccMaster: Multiple OCC masters! ({} and {})", |
| 1000 | masterInstance, obj->getOccInstanceID()) |
| 1001 | .c_str()); |
| 1002 | // request reset |
| 1003 | obj->deviceError(); |
| 1004 | } |
| 1005 | } |
| 1006 | } |
| 1007 | if (masterInstance < 0) |
| 1008 | { |
| 1009 | log<level::ERR>("validateOccMaster: Master OCC not found!"); |
| 1010 | // request reset |
| 1011 | statusObjects.front()->deviceError(); |
| 1012 | } |
| 1013 | else |
| 1014 | { |
| 1015 | log<level::INFO>( |
| 1016 | fmt::format("validateOccMaster: OCC{} is master", masterInstance) |
| 1017 | .c_str()); |
| 1018 | } |
| 1019 | } |
| 1020 | |
Vishwanatha Subbanna | dfc7ec7 | 2017-09-07 18:18:01 +0530 | [diff] [blame] | 1021 | } // namespace occ |
| 1022 | } // namespace open_power |