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