Ben Tyner | 7029e52 | 2021-08-09 19:18:24 -0500 | [diff] [blame] | 1 | #include <attn/attn_dbus.hpp> |
| 2 | #include <attn/attn_dump.hpp> |
| 3 | #include <attn/attn_logging.hpp> |
| 4 | #include <sdbusplus/bus.hpp> |
| 5 | #include <sdbusplus/exception.hpp> |
Deepa Karthikeyan | a92dc02 | 2024-04-16 03:45:57 -0500 | [diff] [blame^] | 6 | #include <util/dbus.hpp> |
austinfcui | bfa831a | 2022-01-26 15:37:07 -0600 | [diff] [blame] | 7 | #include <util/trace.hpp> |
Ben Tyner | 7029e52 | 2021-08-09 19:18:24 -0500 | [diff] [blame] | 8 | |
Ben Tyner | e38a90b | 2022-03-02 19:30:35 -0600 | [diff] [blame] | 9 | constexpr uint64_t dumpTimeout = 3600000000; // microseconds |
| 10 | |
| 11 | constexpr auto operationStatusInProgress = |
| 12 | "xyz.openbmc_project.Common.Progress.OperationStatus.InProgress"; |
| 13 | |
Ben Tyner | 7029e52 | 2021-08-09 19:18:24 -0500 | [diff] [blame] | 14 | namespace attn |
| 15 | { |
| 16 | |
| 17 | /** |
| 18 | * Callback for dump request properties change signal monitor |
| 19 | * |
| 20 | * @param[in] i_msg Dbus message from the dbus match infrastructure |
Ben Tyner | e38a90b | 2022-03-02 19:30:35 -0600 | [diff] [blame] | 21 | * @param[out] o_dumpStatus Dump status dbus response string |
| 22 | * @return Always non-zero indicating no error, no cascading callbacks |
Ben Tyner | 7029e52 | 2021-08-09 19:18:24 -0500 | [diff] [blame] | 23 | */ |
Patrick Williams | e212fb0 | 2022-07-22 19:26:57 -0500 | [diff] [blame] | 24 | uint dumpStatusChanged(sdbusplus::message_t& i_msg, std::string& o_dumpStatus) |
Ben Tyner | 7029e52 | 2021-08-09 19:18:24 -0500 | [diff] [blame] | 25 | { |
| 26 | // reply (msg) will be a property change message |
| 27 | std::string interface; |
| 28 | std::map<std::string, std::variant<std::string, uint8_t>> property; |
| 29 | i_msg.read(interface, property); |
| 30 | |
| 31 | // looking for property Status changes |
| 32 | std::string propertyType = "Status"; |
Patrick Williams | 27dd636 | 2023-05-10 07:51:20 -0500 | [diff] [blame] | 33 | auto dumpStatus = property.find(propertyType); |
Ben Tyner | 7029e52 | 2021-08-09 19:18:24 -0500 | [diff] [blame] | 34 | |
| 35 | if (dumpStatus != property.end()) |
| 36 | { |
| 37 | const std::string* status = |
| 38 | std::get_if<std::string>(&(dumpStatus->second)); |
| 39 | |
Ben Tyner | e38a90b | 2022-03-02 19:30:35 -0600 | [diff] [blame] | 40 | if (nullptr != status) |
Ben Tyner | 7029e52 | 2021-08-09 19:18:24 -0500 | [diff] [blame] | 41 | { |
Ben Tyner | e38a90b | 2022-03-02 19:30:35 -0600 | [diff] [blame] | 42 | o_dumpStatus = *status; |
Ben Tyner | 7029e52 | 2021-08-09 19:18:24 -0500 | [diff] [blame] | 43 | } |
| 44 | } |
| 45 | |
| 46 | return 1; // non-negative return code for successful callback |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Register a callback for dump progress status changes |
| 51 | * |
| 52 | * @param[in] i_path The object path of the dump to monitor |
| 53 | */ |
| 54 | void monitorDump(const std::string& i_path) |
| 55 | { |
Ben Tyner | 7029e52 | 2021-08-09 19:18:24 -0500 | [diff] [blame] | 56 | // setup the signal match rules and callback |
| 57 | std::string matchInterface = "xyz.openbmc_project.Common.Progress"; |
Patrick Williams | 27dd636 | 2023-05-10 07:51:20 -0500 | [diff] [blame] | 58 | auto bus = sdbusplus::bus::new_system(); |
Ben Tyner | 7029e52 | 2021-08-09 19:18:24 -0500 | [diff] [blame] | 59 | |
Ben Tyner | e38a90b | 2022-03-02 19:30:35 -0600 | [diff] [blame] | 60 | // monitor dump status change property, will update dumpStatus |
| 61 | std::string dumpStatus = "requested"; |
Ben Tyner | 7029e52 | 2021-08-09 19:18:24 -0500 | [diff] [blame] | 62 | std::unique_ptr<sdbusplus::bus::match_t> match = |
| 63 | std::make_unique<sdbusplus::bus::match_t>( |
| 64 | bus, |
| 65 | sdbusplus::bus::match::rules::propertiesChanged( |
| 66 | i_path.c_str(), matchInterface.c_str()), |
Ben Tyner | e38a90b | 2022-03-02 19:30:35 -0600 | [diff] [blame] | 67 | [&](auto& msg) { return dumpStatusChanged(msg, dumpStatus); }); |
Ben Tyner | 7029e52 | 2021-08-09 19:18:24 -0500 | [diff] [blame] | 68 | |
| 69 | // wait for dump status to be completed (complete == true) |
Ben Tyner | e38a90b | 2022-03-02 19:30:35 -0600 | [diff] [blame] | 70 | trace::inf("dump requested %s", i_path.c_str()); |
| 71 | |
| 72 | // wait for dump status not InProgress or timeout |
| 73 | uint64_t timeRemaining = dumpTimeout; |
| 74 | |
| 75 | std::chrono::steady_clock::time_point begin = |
| 76 | std::chrono::steady_clock::now(); |
| 77 | |
| 78 | while (("requested" == dumpStatus || |
| 79 | operationStatusInProgress == dumpStatus) && |
| 80 | 0 != timeRemaining) |
Ben Tyner | 7029e52 | 2021-08-09 19:18:24 -0500 | [diff] [blame] | 81 | { |
Ben Tyner | e38a90b | 2022-03-02 19:30:35 -0600 | [diff] [blame] | 82 | bus.wait(timeRemaining); |
| 83 | uint64_t timeElapsed = |
| 84 | std::chrono::duration_cast<std::chrono::microseconds>( |
| 85 | std::chrono::steady_clock::now() - begin) |
| 86 | .count(); |
| 87 | |
| 88 | timeRemaining = |
| 89 | timeElapsed > timeRemaining ? 0 : timeRemaining - timeElapsed; |
| 90 | |
Ben Tyner | 7029e52 | 2021-08-09 19:18:24 -0500 | [diff] [blame] | 91 | bus.process_discard(); |
| 92 | } |
Ben Tyner | e38a90b | 2022-03-02 19:30:35 -0600 | [diff] [blame] | 93 | |
| 94 | if (0 == timeRemaining) |
| 95 | { |
| 96 | trace::err("dump request timed out after %" PRIu64 " microseconds", |
| 97 | dumpTimeout); |
| 98 | } |
| 99 | |
| 100 | trace::inf("dump status: %s", dumpStatus.c_str()); |
Ben Tyner | 7029e52 | 2021-08-09 19:18:24 -0500 | [diff] [blame] | 101 | } |
| 102 | |
Deepa Karthikeyan | a92dc02 | 2024-04-16 03:45:57 -0500 | [diff] [blame^] | 103 | /** Api used to enable or disable watchdog dbus property */ |
| 104 | void enableWatchdog(bool enable) |
| 105 | { |
| 106 | constexpr auto service = "xyz.openbmc_project.Watchdog"; |
| 107 | constexpr auto object = "/xyz/openbmc_project/watchdog/host0"; |
| 108 | constexpr auto interface = "xyz.openbmc_project.State.Watchdog"; |
| 109 | constexpr auto property = "Enabled"; |
| 110 | util::dbus::setProperty<bool>(service, object, interface, property, enable); |
| 111 | } |
| 112 | |
Ben Tyner | 7029e52 | 2021-08-09 19:18:24 -0500 | [diff] [blame] | 113 | /** Request a dump from the dump manager */ |
Zane Shelley | 611b344 | 2021-11-19 16:02:01 -0600 | [diff] [blame] | 114 | void requestDump(uint32_t i_logId, const DumpParameters& i_dumpParameters) |
Ben Tyner | 7029e52 | 2021-08-09 19:18:24 -0500 | [diff] [blame] | 115 | { |
Patrick Williams | 27dd636 | 2023-05-10 07:51:20 -0500 | [diff] [blame] | 116 | constexpr auto path = "/org/openpower/dump"; |
Ben Tyner | 7029e52 | 2021-08-09 19:18:24 -0500 | [diff] [blame] | 117 | constexpr auto interface = "xyz.openbmc_project.Dump.Create"; |
Patrick Williams | 27dd636 | 2023-05-10 07:51:20 -0500 | [diff] [blame] | 118 | constexpr auto function = "CreateDump"; |
Ben Tyner | 7029e52 | 2021-08-09 19:18:24 -0500 | [diff] [blame] | 119 | |
Patrick Williams | e212fb0 | 2022-07-22 19:26:57 -0500 | [diff] [blame] | 120 | sdbusplus::message_t method; |
Deepa Karthikeyan | a92dc02 | 2024-04-16 03:45:57 -0500 | [diff] [blame^] | 121 | bool watchdogDisabled = false; |
Ben Tyner | 7029e52 | 2021-08-09 19:18:24 -0500 | [diff] [blame] | 122 | |
| 123 | if (0 == dbusMethod(path, interface, function, method)) |
| 124 | { |
| 125 | try |
| 126 | { |
Deepa Karthikeyan | a92dc02 | 2024-04-16 03:45:57 -0500 | [diff] [blame^] | 127 | // During a checkstop attention, the system is not functioning |
| 128 | // normally. So a hardware or hostboot dump is collected and it |
| 129 | // could take a while to get completed. So disable the watchdog when |
| 130 | // the dump collection is in progress. |
| 131 | if (DumpType::Hostboot == i_dumpParameters.dumpType || |
| 132 | DumpType::Hardware == i_dumpParameters.dumpType) |
| 133 | { |
| 134 | watchdogDisabled = true; |
| 135 | enableWatchdog(false); |
| 136 | } |
Ben Tyner | 7029e52 | 2021-08-09 19:18:24 -0500 | [diff] [blame] | 137 | // dbus call arguments |
| 138 | std::map<std::string, std::variant<std::string, uint64_t>> |
| 139 | createParams; |
| 140 | createParams["com.ibm.Dump.Create.CreateParameters.ErrorLogId"] = |
Zane Shelley | 611b344 | 2021-11-19 16:02:01 -0600 | [diff] [blame] | 141 | uint64_t(i_logId); |
Ben Tyner | 7029e52 | 2021-08-09 19:18:24 -0500 | [diff] [blame] | 142 | if (DumpType::Hostboot == i_dumpParameters.dumpType) |
| 143 | { |
| 144 | createParams["com.ibm.Dump.Create.CreateParameters.DumpType"] = |
| 145 | "com.ibm.Dump.Create.DumpType.Hostboot"; |
| 146 | } |
| 147 | else if (DumpType::Hardware == i_dumpParameters.dumpType) |
| 148 | { |
| 149 | createParams["com.ibm.Dump.Create.CreateParameters.DumpType"] = |
| 150 | "com.ibm.Dump.Create.DumpType.Hardware"; |
| 151 | createParams |
| 152 | ["com.ibm.Dump.Create.CreateParameters.FailingUnitId"] = |
| 153 | i_dumpParameters.unitId; |
| 154 | } |
Ben Tyner | 7f6ce6a | 2021-08-17 19:40:00 -0500 | [diff] [blame] | 155 | else if (DumpType::SBE == i_dumpParameters.dumpType) |
| 156 | { |
| 157 | createParams["com.ibm.Dump.Create.CreateParameters.DumpType"] = |
| 158 | "com.ibm.Dump.Create.DumpType.SBE"; |
| 159 | createParams |
| 160 | ["com.ibm.Dump.Create.CreateParameters.FailingUnitId"] = |
| 161 | i_dumpParameters.unitId; |
| 162 | } |
Ben Tyner | 7029e52 | 2021-08-09 19:18:24 -0500 | [diff] [blame] | 163 | method.append(createParams); |
| 164 | |
| 165 | // using system dbus |
Patrick Williams | 27dd636 | 2023-05-10 07:51:20 -0500 | [diff] [blame] | 166 | auto bus = sdbusplus::bus::new_system(); |
Ben Tyner | 7029e52 | 2021-08-09 19:18:24 -0500 | [diff] [blame] | 167 | auto response = bus.call(method); |
| 168 | |
| 169 | // reply will be type dbus::ObjectPath |
| 170 | sdbusplus::message::object_path reply; |
| 171 | response.read(reply); |
| 172 | |
| 173 | // monitor dump progress |
| 174 | monitorDump(reply); |
| 175 | } |
| 176 | catch (const sdbusplus::exception::SdBusError& e) |
| 177 | { |
austinfcui | bfa831a | 2022-01-26 15:37:07 -0600 | [diff] [blame] | 178 | trace::err("requestDump exception"); |
| 179 | trace::err(e.what()); |
Ben Tyner | 7029e52 | 2021-08-09 19:18:24 -0500 | [diff] [blame] | 180 | } |
Deepa Karthikeyan | a92dc02 | 2024-04-16 03:45:57 -0500 | [diff] [blame^] | 181 | |
| 182 | if (watchdogDisabled) |
| 183 | { |
| 184 | // Dump collection is over, enable the watchdog |
| 185 | enableWatchdog(true); |
| 186 | } |
Ben Tyner | 7029e52 | 2021-08-09 19:18:24 -0500 | [diff] [blame] | 187 | } |
| 188 | } |
| 189 | |
| 190 | } // namespace attn |