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