Matthew Barth | 29e9e38 | 2020-01-23 13:40:49 -0600 | [diff] [blame] | 1 | /** |
| 2 | * Copyright © 2020 IBM Corporation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "manager.hpp" |
| 18 | |
Shawn McCarney | e0c6a2d | 2020-05-01 11:37:08 -0500 | [diff] [blame] | 19 | #include "chassis.hpp" |
| 20 | #include "config_file_parser.hpp" |
| 21 | #include "exception_utils.hpp" |
Shawn McCarney | cee2e20 | 2024-08-02 16:38:33 -0500 | [diff] [blame^] | 22 | #include "format_utils.hpp" |
Shawn McCarney | e0c6a2d | 2020-05-01 11:37:08 -0500 | [diff] [blame] | 23 | #include "rule.hpp" |
Matthew Barth | bbc7c58 | 2020-02-03 15:55:15 -0600 | [diff] [blame] | 24 | #include "utility.hpp" |
| 25 | |
Shawn McCarney | 415094c | 2021-02-15 11:08:19 -0600 | [diff] [blame] | 26 | #include <xyz/openbmc_project/Common/error.hpp> |
Shawn McCarney | d9c8be5 | 2021-05-18 10:07:53 -0500 | [diff] [blame] | 27 | #include <xyz/openbmc_project/State/Chassis/server.hpp> |
Shawn McCarney | 415094c | 2021-02-15 11:08:19 -0600 | [diff] [blame] | 28 | |
Matthew Barth | f2bcf1f | 2020-01-29 14:42:47 -0600 | [diff] [blame] | 29 | #include <chrono> |
Shawn McCarney | e0c6a2d | 2020-05-01 11:37:08 -0500 | [diff] [blame] | 30 | #include <exception> |
Shawn McCarney | 589c181 | 2021-01-14 12:13:26 -0600 | [diff] [blame] | 31 | #include <functional> |
Shawn McCarney | cee2e20 | 2024-08-02 16:38:33 -0500 | [diff] [blame^] | 32 | #include <span> |
Shawn McCarney | 8acaf54 | 2021-03-30 10:38:37 -0500 | [diff] [blame] | 33 | #include <thread> |
Shawn McCarney | e0c6a2d | 2020-05-01 11:37:08 -0500 | [diff] [blame] | 34 | #include <tuple> |
| 35 | #include <utility> |
Matthew Barth | f2bcf1f | 2020-01-29 14:42:47 -0600 | [diff] [blame] | 36 | |
Shawn McCarney | 84807b9 | 2020-04-30 18:40:03 -0500 | [diff] [blame] | 37 | namespace phosphor::power::regulators |
Matthew Barth | 29e9e38 | 2020-01-23 13:40:49 -0600 | [diff] [blame] | 38 | { |
| 39 | |
Shawn McCarney | e0c6a2d | 2020-05-01 11:37:08 -0500 | [diff] [blame] | 40 | namespace fs = std::filesystem; |
| 41 | |
Shawn McCarney | 589c181 | 2021-01-14 12:13:26 -0600 | [diff] [blame] | 42 | constexpr auto busName = "xyz.openbmc_project.Power.Regulators"; |
| 43 | constexpr auto managerObjPath = "/xyz/openbmc_project/power/regulators/manager"; |
Shawn McCarney | d9c8be5 | 2021-05-18 10:07:53 -0500 | [diff] [blame] | 44 | constexpr auto chassisStatePath = "/xyz/openbmc_project/state/chassis0"; |
| 45 | constexpr auto chassisStateIntf = "xyz.openbmc_project.State.Chassis"; |
| 46 | constexpr auto chassisStateProp = "CurrentPowerState"; |
Shawn McCarney | 8acaf54 | 2021-03-30 10:38:37 -0500 | [diff] [blame] | 47 | constexpr std::chrono::minutes maxTimeToWaitForCompatTypes{5}; |
Shawn McCarney | 589c181 | 2021-01-14 12:13:26 -0600 | [diff] [blame] | 48 | |
Shawn McCarney | d9c8be5 | 2021-05-18 10:07:53 -0500 | [diff] [blame] | 49 | using PowerState = |
| 50 | sdbusplus::xyz::openbmc_project::State::server::Chassis::PowerState; |
| 51 | |
Shawn McCarney | 589c181 | 2021-01-14 12:13:26 -0600 | [diff] [blame] | 52 | /** |
| 53 | * Default configuration file name. This is used when the system does not |
| 54 | * implement the D-Bus compatible interface. |
| 55 | */ |
| 56 | constexpr auto defaultConfigFileName = "config.json"; |
| 57 | |
Shawn McCarney | e0c6a2d | 2020-05-01 11:37:08 -0500 | [diff] [blame] | 58 | /** |
| 59 | * Standard configuration file directory. This directory is part of the |
| 60 | * firmware install image. It contains the standard version of the config file. |
| 61 | */ |
| 62 | const fs::path standardConfigFileDir{"/usr/share/phosphor-regulators"}; |
| 63 | |
| 64 | /** |
| 65 | * Test configuration file directory. This directory can contain a test version |
| 66 | * of the config file. The test version will override the standard version. |
| 67 | */ |
| 68 | const fs::path testConfigFileDir{"/etc/phosphor-regulators"}; |
| 69 | |
Patrick Williams | 7354ce6 | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 70 | Manager::Manager(sdbusplus::bus_t& bus, const sdeventplus::Event& event) : |
Zev Weiss | d130729 | 2022-04-19 17:13:28 -0700 | [diff] [blame] | 71 | ManagerObject{bus, managerObjPath}, bus{bus}, eventLoop{event}, |
Patrick Williams | 48781ae | 2023-05-10 07:50:50 -0500 | [diff] [blame] | 72 | services{bus}, |
| 73 | phaseFaultTimer{event, std::bind(&Manager::phaseFaultTimerExpired, this)}, |
Shawn McCarney | c8cbeac | 2021-09-10 15:42:56 -0500 | [diff] [blame] | 74 | sensorTimer{event, std::bind(&Manager::sensorTimerExpired, this)} |
Matthew Barth | 29e9e38 | 2020-01-23 13:40:49 -0600 | [diff] [blame] | 75 | { |
Shawn McCarney | cee2e20 | 2024-08-02 16:38:33 -0500 | [diff] [blame^] | 76 | // Create object to find compatible system types for current system. |
| 77 | // Note that some systems do not provide this information. |
| 78 | compatSysTypesFinder = std::make_unique<util::CompatibleSystemTypesFinder>( |
| 79 | bus, std::bind_front(&Manager::compatibleSystemTypesFound, this)); |
Matthew Barth | 250d0a9 | 2020-02-28 13:04:24 -0600 | [diff] [blame] | 80 | |
Shawn McCarney | cee2e20 | 2024-08-02 16:38:33 -0500 | [diff] [blame^] | 81 | // If no system types found so far, try to load default config file |
| 82 | if (compatibleSystemTypes.empty()) |
| 83 | { |
| 84 | loadConfigFile(); |
| 85 | } |
Matthew Barth | 29e9e38 | 2020-01-23 13:40:49 -0600 | [diff] [blame] | 86 | |
Shawn McCarney | d9c8be5 | 2021-05-18 10:07:53 -0500 | [diff] [blame] | 87 | // Obtain D-Bus service name |
Matthew Barth | 29e9e38 | 2020-01-23 13:40:49 -0600 | [diff] [blame] | 88 | bus.request_name(busName); |
Shawn McCarney | d9c8be5 | 2021-05-18 10:07:53 -0500 | [diff] [blame] | 89 | |
| 90 | // If system is already powered on, enable monitoring |
| 91 | if (isSystemPoweredOn()) |
| 92 | { |
| 93 | monitor(true); |
| 94 | } |
Matthew Barth | 29e9e38 | 2020-01-23 13:40:49 -0600 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | void Manager::configure() |
| 98 | { |
Shawn McCarney | 9bd94d3 | 2021-01-25 19:40:42 -0600 | [diff] [blame] | 99 | // Clear any cached data or error history related to hardware devices |
| 100 | clearHardwareData(); |
| 101 | |
Shawn McCarney | 8acaf54 | 2021-03-30 10:38:37 -0500 | [diff] [blame] | 102 | // Wait until the config file has been loaded or hit max wait time |
| 103 | waitUntilConfigFileLoaded(); |
| 104 | |
| 105 | // Verify config file has been loaded and System object is valid |
| 106 | if (isConfigFileLoaded()) |
Shawn McCarney | 6345c6c | 2020-05-04 10:35:05 -0500 | [diff] [blame] | 107 | { |
| 108 | // Configure the regulator devices in the system |
Bob King | 23243f8 | 2020-07-29 10:38:57 +0800 | [diff] [blame] | 109 | system->configure(services); |
Shawn McCarney | 6345c6c | 2020-05-04 10:35:05 -0500 | [diff] [blame] | 110 | } |
| 111 | else |
| 112 | { |
Shawn McCarney | 415094c | 2021-02-15 11:08:19 -0600 | [diff] [blame] | 113 | // Write error message to journal |
Shawn McCarney | b464c8b | 2020-07-16 17:51:38 -0500 | [diff] [blame] | 114 | services.getJournal().logError("Unable to configure regulator devices: " |
| 115 | "Configuration file not loaded"); |
Shawn McCarney | 6345c6c | 2020-05-04 10:35:05 -0500 | [diff] [blame] | 116 | |
Shawn McCarney | 415094c | 2021-02-15 11:08:19 -0600 | [diff] [blame] | 117 | // Log critical error since regulators could not be configured. Could |
| 118 | // cause hardware damage if default regulator settings are very wrong. |
| 119 | services.getErrorLogging().logConfigFileError(Entry::Level::Critical, |
| 120 | services.getJournal()); |
| 121 | |
| 122 | // Throw InternalFailure to propogate error status to D-Bus client |
| 123 | throw sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure{}; |
| 124 | } |
Matthew Barth | 29e9e38 | 2020-01-23 13:40:49 -0600 | [diff] [blame] | 125 | } |
| 126 | |
Shawn McCarney | 5b19ea5 | 2020-06-02 18:52:56 -0500 | [diff] [blame] | 127 | void Manager::monitor(bool enable) |
Matthew Barth | 29e9e38 | 2020-01-23 13:40:49 -0600 | [diff] [blame] | 128 | { |
Shawn McCarney | d9c8be5 | 2021-05-18 10:07:53 -0500 | [diff] [blame] | 129 | // Check whether already in the requested monitoring state |
| 130 | if (enable == isMonitoringEnabled) |
Matthew Barth | 29e9e38 | 2020-01-23 13:40:49 -0600 | [diff] [blame] | 131 | { |
Shawn McCarney | d9c8be5 | 2021-05-18 10:07:53 -0500 | [diff] [blame] | 132 | return; |
| 133 | } |
| 134 | |
| 135 | isMonitoringEnabled = enable; |
| 136 | if (isMonitoringEnabled) |
| 137 | { |
| 138 | services.getJournal().logDebug("Monitoring enabled"); |
| 139 | |
Shawn McCarney | c8cbeac | 2021-09-10 15:42:56 -0500 | [diff] [blame] | 140 | // Restart phase fault detection timer with repeating 15 second interval |
| 141 | phaseFaultTimer.restart(std::chrono::seconds(15)); |
| 142 | |
| 143 | // Restart sensor monitoring timer with repeating 1 second interval |
| 144 | sensorTimer.restart(std::chrono::seconds(1)); |
Shawn McCarney | d9c8be5 | 2021-05-18 10:07:53 -0500 | [diff] [blame] | 145 | |
| 146 | // Enable sensors service; put all sensors in an active state |
| 147 | services.getSensors().enable(); |
Matthew Barth | 29e9e38 | 2020-01-23 13:40:49 -0600 | [diff] [blame] | 148 | } |
| 149 | else |
| 150 | { |
Shawn McCarney | d9c8be5 | 2021-05-18 10:07:53 -0500 | [diff] [blame] | 151 | services.getJournal().logDebug("Monitoring disabled"); |
| 152 | |
Shawn McCarney | c8cbeac | 2021-09-10 15:42:56 -0500 | [diff] [blame] | 153 | // Disable timers |
| 154 | phaseFaultTimer.setEnabled(false); |
| 155 | sensorTimer.setEnabled(false); |
Shawn McCarney | d9c8be5 | 2021-05-18 10:07:53 -0500 | [diff] [blame] | 156 | |
| 157 | // Disable sensors service; put all sensors in an inactive state |
| 158 | services.getSensors().disable(); |
Shawn McCarney | 5b19ea5 | 2020-06-02 18:52:56 -0500 | [diff] [blame] | 159 | |
Shawn McCarney | 8acaf54 | 2021-03-30 10:38:37 -0500 | [diff] [blame] | 160 | // Verify config file has been loaded and System object is valid |
| 161 | if (isConfigFileLoaded()) |
Shawn McCarney | 5b19ea5 | 2020-06-02 18:52:56 -0500 | [diff] [blame] | 162 | { |
| 163 | // Close the regulator devices in the system. Monitoring is |
| 164 | // normally disabled because the system is being powered off. The |
| 165 | // devices should be closed in case hardware is removed or replaced |
Shawn McCarney | 9bd94d3 | 2021-01-25 19:40:42 -0600 | [diff] [blame] | 166 | // while the system is powered off. |
Bob King | d692d6d | 2020-09-14 13:42:57 +0800 | [diff] [blame] | 167 | system->closeDevices(services); |
Shawn McCarney | 5b19ea5 | 2020-06-02 18:52:56 -0500 | [diff] [blame] | 168 | } |
Matthew Barth | 29e9e38 | 2020-01-23 13:40:49 -0600 | [diff] [blame] | 169 | } |
| 170 | } |
| 171 | |
Shawn McCarney | cee2e20 | 2024-08-02 16:38:33 -0500 | [diff] [blame^] | 172 | void Manager::compatibleSystemTypesFound(const std::vector<std::string>& types) |
| 173 | { |
| 174 | // If we don't already have compatible system types |
| 175 | if (compatibleSystemTypes.empty()) |
| 176 | { |
| 177 | std::string typesStr = format_utils::toString(std::span{types}); |
| 178 | services.getJournal().logInfo( |
| 179 | std::format("Compatible system types found: {}", typesStr)); |
| 180 | |
| 181 | // Store compatible system types |
| 182 | compatibleSystemTypes = types; |
| 183 | |
| 184 | // Find and load JSON config file based on system types |
| 185 | loadConfigFile(); |
| 186 | } |
| 187 | } |
| 188 | |
Shawn McCarney | c8cbeac | 2021-09-10 15:42:56 -0500 | [diff] [blame] | 189 | void Manager::phaseFaultTimerExpired() |
Shawn McCarney | 589c181 | 2021-01-14 12:13:26 -0600 | [diff] [blame] | 190 | { |
Shawn McCarney | c8cbeac | 2021-09-10 15:42:56 -0500 | [diff] [blame] | 191 | // Verify config file has been loaded and System object is valid |
| 192 | if (isConfigFileLoaded()) |
| 193 | { |
| 194 | // Detect redundant phase faults in regulator devices in the system |
| 195 | system->detectPhaseFaults(services); |
| 196 | } |
Shawn McCarney | 589c181 | 2021-01-14 12:13:26 -0600 | [diff] [blame] | 197 | } |
| 198 | |
Shawn McCarney | c8cbeac | 2021-09-10 15:42:56 -0500 | [diff] [blame] | 199 | void Manager::sensorTimerExpired() |
Matthew Barth | f2bcf1f | 2020-01-29 14:42:47 -0600 | [diff] [blame] | 200 | { |
Shawn McCarney | d9c8be5 | 2021-05-18 10:07:53 -0500 | [diff] [blame] | 201 | // Notify sensors service that a sensor monitoring cycle is starting |
| 202 | services.getSensors().startCycle(); |
| 203 | |
| 204 | // Verify config file has been loaded and System object is valid |
| 205 | if (isConfigFileLoaded()) |
| 206 | { |
| 207 | // Monitor sensors for the voltage rails in the system |
| 208 | system->monitorSensors(services); |
| 209 | } |
| 210 | |
| 211 | // Notify sensors service that current sensor monitoring cycle has ended |
| 212 | services.getSensors().endCycle(); |
Matthew Barth | f2bcf1f | 2020-01-29 14:42:47 -0600 | [diff] [blame] | 213 | } |
| 214 | |
Shawn McCarney | c8cbeac | 2021-09-10 15:42:56 -0500 | [diff] [blame] | 215 | void Manager::sighupHandler(sdeventplus::source::Signal& /*sigSrc*/, |
| 216 | const struct signalfd_siginfo* /*sigInfo*/) |
| 217 | { |
| 218 | // Reload the JSON configuration file |
| 219 | loadConfigFile(); |
| 220 | } |
| 221 | |
Shawn McCarney | 9bd94d3 | 2021-01-25 19:40:42 -0600 | [diff] [blame] | 222 | void Manager::clearHardwareData() |
| 223 | { |
Shawn McCarney | 4e0402c | 2021-02-05 00:08:33 -0600 | [diff] [blame] | 224 | // Clear any cached hardware presence data and VPD values |
Shawn McCarney | 9bd94d3 | 2021-01-25 19:40:42 -0600 | [diff] [blame] | 225 | services.getPresenceService().clearCache(); |
Shawn McCarney | 4e0402c | 2021-02-05 00:08:33 -0600 | [diff] [blame] | 226 | services.getVPD().clearCache(); |
Shawn McCarney | 9bd94d3 | 2021-01-25 19:40:42 -0600 | [diff] [blame] | 227 | |
Shawn McCarney | 8acaf54 | 2021-03-30 10:38:37 -0500 | [diff] [blame] | 228 | // Verify config file has been loaded and System object is valid |
| 229 | if (isConfigFileLoaded()) |
Shawn McCarney | 9bd94d3 | 2021-01-25 19:40:42 -0600 | [diff] [blame] | 230 | { |
| 231 | // Clear any cached hardware data in the System object |
| 232 | system->clearCache(); |
Shawn McCarney | 9bd94d3 | 2021-01-25 19:40:42 -0600 | [diff] [blame] | 233 | |
Shawn McCarney | ce540f3 | 2021-05-14 17:08:41 -0500 | [diff] [blame] | 234 | // Clear error history related to hardware devices in the System object |
| 235 | system->clearErrorHistory(); |
| 236 | } |
Shawn McCarney | 9bd94d3 | 2021-01-25 19:40:42 -0600 | [diff] [blame] | 237 | } |
| 238 | |
Shawn McCarney | e0c6a2d | 2020-05-01 11:37:08 -0500 | [diff] [blame] | 239 | fs::path Manager::findConfigFile() |
| 240 | { |
Shawn McCarney | 589c181 | 2021-01-14 12:13:26 -0600 | [diff] [blame] | 241 | // Build list of possible base file names |
| 242 | std::vector<std::string> fileNames{}; |
| 243 | |
| 244 | // Add possible file names based on compatible system types (if any) |
| 245 | for (const std::string& systemType : compatibleSystemTypes) |
Shawn McCarney | e0c6a2d | 2020-05-01 11:37:08 -0500 | [diff] [blame] | 246 | { |
Shawn McCarney | cee2e20 | 2024-08-02 16:38:33 -0500 | [diff] [blame^] | 247 | // Look for file name that is entire system type + ".json" |
| 248 | // Example: com.acme.Hardware.Chassis.Model.MegaServer.json |
| 249 | fileNames.emplace_back(systemType + ".json"); |
Shawn McCarney | 589c181 | 2021-01-14 12:13:26 -0600 | [diff] [blame] | 250 | |
Shawn McCarney | cee2e20 | 2024-08-02 16:38:33 -0500 | [diff] [blame^] | 251 | // Look for file name that is last node of system type + ".json" |
| 252 | // Example: MegaServer.json |
| 253 | std::string::size_type pos = systemType.rfind('.'); |
| 254 | if ((pos != std::string::npos) && ((systemType.size() - pos) > 1)) |
| 255 | { |
| 256 | fileNames.emplace_back(systemType.substr(pos + 1) + ".json"); |
| 257 | } |
Shawn McCarney | 589c181 | 2021-01-14 12:13:26 -0600 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | // Add default file name for systems that don't use compatible interface |
| 261 | fileNames.emplace_back(defaultConfigFileName); |
| 262 | |
| 263 | // Look for a config file with one of the possible base names |
| 264 | for (const std::string& fileName : fileNames) |
| 265 | { |
| 266 | // Check if file exists in test directory |
| 267 | fs::path pathName{testConfigFileDir / fileName}; |
| 268 | if (fs::exists(pathName)) |
Shawn McCarney | e0c6a2d | 2020-05-01 11:37:08 -0500 | [diff] [blame] | 269 | { |
Shawn McCarney | 589c181 | 2021-01-14 12:13:26 -0600 | [diff] [blame] | 270 | return pathName; |
| 271 | } |
| 272 | |
| 273 | // Check if file exists in standard directory |
| 274 | pathName = standardConfigFileDir / fileName; |
| 275 | if (fs::exists(pathName)) |
| 276 | { |
| 277 | return pathName; |
Shawn McCarney | e0c6a2d | 2020-05-01 11:37:08 -0500 | [diff] [blame] | 278 | } |
| 279 | } |
| 280 | |
Shawn McCarney | 589c181 | 2021-01-14 12:13:26 -0600 | [diff] [blame] | 281 | // No config file found; return empty path |
| 282 | return fs::path{}; |
Shawn McCarney | e0c6a2d | 2020-05-01 11:37:08 -0500 | [diff] [blame] | 283 | } |
| 284 | |
Shawn McCarney | d9c8be5 | 2021-05-18 10:07:53 -0500 | [diff] [blame] | 285 | bool Manager::isSystemPoweredOn() |
| 286 | { |
| 287 | bool isOn{false}; |
| 288 | |
| 289 | try |
| 290 | { |
| 291 | // Get D-Bus property that contains the current power state for |
| 292 | // chassis0, which represents the entire system (all chassis) |
| 293 | using namespace phosphor::power::util; |
| 294 | auto service = getService(chassisStatePath, chassisStateIntf, bus); |
| 295 | if (!service.empty()) |
| 296 | { |
| 297 | PowerState currentPowerState; |
| 298 | getProperty(chassisStateIntf, chassisStateProp, chassisStatePath, |
| 299 | service, bus, currentPowerState); |
| 300 | if (currentPowerState == PowerState::On) |
| 301 | { |
| 302 | isOn = true; |
| 303 | } |
| 304 | } |
| 305 | } |
| 306 | catch (const std::exception& e) |
| 307 | { |
| 308 | // Current power state might not be available yet. The regulators |
| 309 | // application can start before the power state is published on D-Bus. |
| 310 | } |
| 311 | |
| 312 | return isOn; |
| 313 | } |
| 314 | |
Shawn McCarney | e0c6a2d | 2020-05-01 11:37:08 -0500 | [diff] [blame] | 315 | void Manager::loadConfigFile() |
| 316 | { |
| 317 | try |
| 318 | { |
| 319 | // Find the absolute path to the config file |
| 320 | fs::path pathName = findConfigFile(); |
Shawn McCarney | 589c181 | 2021-01-14 12:13:26 -0600 | [diff] [blame] | 321 | if (!pathName.empty()) |
| 322 | { |
| 323 | // Log info message in journal; config file path is important |
| 324 | services.getJournal().logInfo("Loading configuration file " + |
| 325 | pathName.string()); |
Shawn McCarney | e0c6a2d | 2020-05-01 11:37:08 -0500 | [diff] [blame] | 326 | |
Shawn McCarney | 589c181 | 2021-01-14 12:13:26 -0600 | [diff] [blame] | 327 | // Parse the config file |
| 328 | std::vector<std::unique_ptr<Rule>> rules{}; |
| 329 | std::vector<std::unique_ptr<Chassis>> chassis{}; |
| 330 | std::tie(rules, chassis) = config_file_parser::parse(pathName); |
Shawn McCarney | e0c6a2d | 2020-05-01 11:37:08 -0500 | [diff] [blame] | 331 | |
Shawn McCarney | 589c181 | 2021-01-14 12:13:26 -0600 | [diff] [blame] | 332 | // Store config file information in a new System object. The old |
| 333 | // System object, if any, is automatically deleted. |
Patrick Williams | 48781ae | 2023-05-10 07:50:50 -0500 | [diff] [blame] | 334 | system = std::make_unique<System>(std::move(rules), |
| 335 | std::move(chassis)); |
Shawn McCarney | 589c181 | 2021-01-14 12:13:26 -0600 | [diff] [blame] | 336 | } |
Shawn McCarney | e0c6a2d | 2020-05-01 11:37:08 -0500 | [diff] [blame] | 337 | } |
| 338 | catch (const std::exception& e) |
| 339 | { |
| 340 | // Log error messages in journal |
Shawn McCarney | b464c8b | 2020-07-16 17:51:38 -0500 | [diff] [blame] | 341 | services.getJournal().logError(exception_utils::getMessages(e)); |
| 342 | services.getJournal().logError("Unable to load configuration file"); |
Shawn McCarney | e0c6a2d | 2020-05-01 11:37:08 -0500 | [diff] [blame] | 343 | |
Shawn McCarney | 415094c | 2021-02-15 11:08:19 -0600 | [diff] [blame] | 344 | // Log error |
| 345 | services.getErrorLogging().logConfigFileError(Entry::Level::Error, |
| 346 | services.getJournal()); |
Shawn McCarney | e0c6a2d | 2020-05-01 11:37:08 -0500 | [diff] [blame] | 347 | } |
| 348 | } |
| 349 | |
Shawn McCarney | 8acaf54 | 2021-03-30 10:38:37 -0500 | [diff] [blame] | 350 | void Manager::waitUntilConfigFileLoaded() |
| 351 | { |
| 352 | // If config file not loaded and list of compatible system types is empty |
| 353 | if (!isConfigFileLoaded() && compatibleSystemTypes.empty()) |
| 354 | { |
| 355 | // Loop until compatible system types found or waited max amount of time |
| 356 | auto start = std::chrono::system_clock::now(); |
| 357 | std::chrono::system_clock::duration timeWaited{0}; |
| 358 | while (compatibleSystemTypes.empty() && |
| 359 | (timeWaited <= maxTimeToWaitForCompatTypes)) |
| 360 | { |
Shawn McCarney | cee2e20 | 2024-08-02 16:38:33 -0500 | [diff] [blame^] | 361 | // Try to find list of compatible system types. Force finder object |
| 362 | // to re-find system types on D-Bus because we are not receiving |
| 363 | // InterfacesAdded signals within this while loop. |
| 364 | compatSysTypesFinder->refind(); |
| 365 | if (compatibleSystemTypes.empty()) |
Shawn McCarney | 8acaf54 | 2021-03-30 10:38:37 -0500 | [diff] [blame] | 366 | { |
Shawn McCarney | cee2e20 | 2024-08-02 16:38:33 -0500 | [diff] [blame^] | 367 | // Not found; sleep 5 seconds |
Shawn McCarney | 8acaf54 | 2021-03-30 10:38:37 -0500 | [diff] [blame] | 368 | using namespace std::chrono_literals; |
| 369 | std::this_thread::sleep_for(5s); |
| 370 | } |
| 371 | timeWaited = std::chrono::system_clock::now() - start; |
| 372 | } |
| 373 | } |
| 374 | } |
| 375 | |
Shawn McCarney | 84807b9 | 2020-04-30 18:40:03 -0500 | [diff] [blame] | 376 | } // namespace phosphor::power::regulators |