Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 1 | #include "occ_status.hpp" |
| 2 | |
Chris Cain | b6535e8 | 2022-01-21 08:24:13 -0600 | [diff] [blame] | 3 | #include <fmt/core.h> |
| 4 | |
Andrew Geissler | 32016d1 | 2017-06-20 15:46:52 -0500 | [diff] [blame] | 5 | #include <phosphor-logging/log.hpp> |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 6 | #include <powercap.hpp> |
George Liu | b5ca101 | 2021-09-10 12:53:11 +0800 | [diff] [blame] | 7 | |
| 8 | #include <cassert> |
Chris Cain | e2d0a43 | 2022-03-28 11:08:49 -0500 | [diff] [blame] | 9 | #include <filesystem> |
Andrew Geissler | 32016d1 | 2017-06-20 15:46:52 -0500 | [diff] [blame] | 10 | |
| 11 | namespace open_power |
| 12 | { |
| 13 | namespace occ |
| 14 | { |
| 15 | namespace powercap |
| 16 | { |
| 17 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 18 | constexpr auto PCAP_PATH = "/xyz/openbmc_project/control/host0/power_cap"; |
Andrew Geissler | 52cf26a | 2017-07-06 12:56:32 -0500 | [diff] [blame] | 19 | constexpr auto PCAP_INTERFACE = "xyz.openbmc_project.Control.Power.Cap"; |
| 20 | |
Andrew Geissler | 52cf26a | 2017-07-06 12:56:32 -0500 | [diff] [blame] | 21 | constexpr auto POWER_CAP_PROP = "PowerCap"; |
| 22 | constexpr auto POWER_CAP_ENABLE_PROP = "PowerCapEnable"; |
Chris Cain | 613dc90 | 2022-04-08 09:56:22 -0500 | [diff] [blame] | 23 | constexpr auto POWER_CAP_SOFT_MIN = "MinSoftPowerCapValue"; |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 24 | constexpr auto POWER_CAP_HARD_MIN = "MinPowerCapValue"; |
| 25 | constexpr auto POWER_CAP_MAX = "MaxPowerCapValue"; |
Andrew Geissler | 52cf26a | 2017-07-06 12:56:32 -0500 | [diff] [blame] | 26 | |
Andrew Geissler | 32016d1 | 2017-06-20 15:46:52 -0500 | [diff] [blame] | 27 | using namespace phosphor::logging; |
George Liu | bcef3b4 | 2021-09-10 12:39:02 +0800 | [diff] [blame] | 28 | namespace fs = std::filesystem; |
Andrew Geissler | 32016d1 | 2017-06-20 15:46:52 -0500 | [diff] [blame] | 29 | |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 30 | void PowerCap::updatePcapBounds() |
| 31 | { |
| 32 | // Build the hwmon string to write the power cap bounds |
| 33 | fs::path minName = getPcapFilename(std::regex{"power\\d+_cap_min$"}); |
Chris Cain | 613dc90 | 2022-04-08 09:56:22 -0500 | [diff] [blame] | 34 | fs::path softMinName = |
| 35 | getPcapFilename(std::regex{"power\\d+_cap_min_soft$"}); |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 36 | fs::path maxName = getPcapFilename(std::regex{"power\\d+_cap_max$"}); |
| 37 | |
| 38 | // Read the power cap bounds from sysfs files |
| 39 | uint64_t cap; |
Chris Cain | 613dc90 | 2022-04-08 09:56:22 -0500 | [diff] [blame] | 40 | uint32_t capSoftMin = 0, capHardMin = 0, capMax = INT_MAX; |
| 41 | |
| 42 | std::ifstream softMinFile(softMinName, std::ios::in); |
| 43 | if (softMinFile) |
| 44 | { |
| 45 | softMinFile >> cap; |
| 46 | softMinFile.close(); |
| 47 | // Convert to Input Power in Watts (round up) |
| 48 | capSoftMin = ((cap / (PS_DERATING_FACTOR / 100.0) / 1000000) + 0.9); |
| 49 | } |
| 50 | else |
| 51 | { |
| 52 | log<level::ERR>( |
| 53 | fmt::format( |
| 54 | "updatePcapBounds: unable to find pcap_min_soft file: {} (errno={})", |
| 55 | pcapBasePathname.c_str(), errno) |
| 56 | .c_str()); |
| 57 | } |
| 58 | |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 59 | std::ifstream minFile(minName, std::ios::in); |
| 60 | if (minFile) |
| 61 | { |
| 62 | minFile >> cap; |
| 63 | minFile.close(); |
Chris Cain | 8676e03 | 2022-03-24 15:06:23 -0500 | [diff] [blame] | 64 | // Convert to Input Power in Watts (round up) |
| 65 | capHardMin = ((cap / (PS_DERATING_FACTOR / 100.0) / 1000000) + 0.9); |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 66 | } |
| 67 | else |
| 68 | { |
| 69 | log<level::ERR>( |
| 70 | fmt::format( |
| 71 | "updatePcapBounds: unable to find cap_min file: {} (errno={})", |
| 72 | pcapBasePathname.c_str(), errno) |
| 73 | .c_str()); |
| 74 | } |
Chris Cain | 613dc90 | 2022-04-08 09:56:22 -0500 | [diff] [blame] | 75 | |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 76 | std::ifstream maxFile(maxName, std::ios::in); |
| 77 | if (maxFile) |
| 78 | { |
| 79 | maxFile >> cap; |
| 80 | maxFile.close(); |
Chris Cain | 8676e03 | 2022-03-24 15:06:23 -0500 | [diff] [blame] | 81 | // Convert to Input Power in Watts (truncate remainder) |
| 82 | capMax = cap / (PS_DERATING_FACTOR / 100.0) / 1000000; |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 83 | } |
| 84 | else |
| 85 | { |
| 86 | log<level::ERR>( |
| 87 | fmt::format( |
| 88 | "updatePcapBounds: unable to find cap_max file: {} (errno={})", |
| 89 | pcapBasePathname.c_str(), errno) |
| 90 | .c_str()); |
| 91 | } |
| 92 | |
| 93 | // Save the bounds to dbus |
Chris Cain | 613dc90 | 2022-04-08 09:56:22 -0500 | [diff] [blame] | 94 | updateDbusPcap(capSoftMin, capHardMin, capMax); |
Chris Cain | 40501a2 | 2022-03-14 17:33:27 -0500 | [diff] [blame] | 95 | |
| 96 | // Validate dbus and hwmon user caps match |
| 97 | const uint32_t dbusUserCap = getPcap(); |
| 98 | const uint32_t hwmonUserCap = readUserCapHwmon(); |
| 99 | if ((hwmonUserCap != 0) && (dbusUserCap != hwmonUserCap)) |
| 100 | { |
| 101 | // User power cap is enabled, but does not match dbus |
| 102 | log<level::ERR>( |
| 103 | fmt::format( |
| 104 | "updatePcapBounds: user powercap mismatch (hwmon:{}W, bdus:{}W) - using dbus", |
| 105 | hwmonUserCap, dbusUserCap) |
| 106 | .c_str()); |
| 107 | writeOcc(dbusUserCap); |
| 108 | } |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 109 | } |
| 110 | |
Andrew Geissler | 4cea4d2 | 2017-07-10 15:13:33 -0500 | [diff] [blame] | 111 | uint32_t PowerCap::getOccInput(uint32_t pcap, bool pcapEnabled) |
| 112 | { |
| 113 | if (!pcapEnabled) |
| 114 | { |
| 115 | // Pcap disabled, return 0 to indicate disabled |
| 116 | return 0; |
| 117 | } |
| 118 | |
| 119 | // If pcap is not disabled then just return the pcap with the derating |
| 120 | // factor applied. |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 121 | return ((static_cast<uint64_t>(pcap) * PS_DERATING_FACTOR) / 100); |
Andrew Geissler | 4cea4d2 | 2017-07-10 15:13:33 -0500 | [diff] [blame] | 122 | } |
| 123 | |
Andrew Geissler | 52cf26a | 2017-07-06 12:56:32 -0500 | [diff] [blame] | 124 | uint32_t PowerCap::getPcap() |
| 125 | { |
George Liu | f3b7514 | 2021-06-10 11:22:50 +0800 | [diff] [blame] | 126 | utils::PropertyValue pcap{}; |
| 127 | try |
Andrew Geissler | 52cf26a | 2017-07-06 12:56:32 -0500 | [diff] [blame] | 128 | { |
George Liu | f3b7514 | 2021-06-10 11:22:50 +0800 | [diff] [blame] | 129 | pcap = utils::getProperty(PCAP_PATH, PCAP_INTERFACE, POWER_CAP_PROP); |
| 130 | |
| 131 | return std::get<uint32_t>(pcap); |
| 132 | } |
Patrick Williams | 2561362 | 2021-09-02 09:29:54 -0500 | [diff] [blame] | 133 | catch (const sdbusplus::exception::exception& e) |
George Liu | f3b7514 | 2021-06-10 11:22:50 +0800 | [diff] [blame] | 134 | { |
| 135 | log<level::ERR>("Failed to get PowerCap property", |
| 136 | entry("ERROR=%s", e.what()), |
| 137 | entry("PATH=%s", PCAP_PATH)); |
| 138 | |
Andrew Geissler | 52cf26a | 2017-07-06 12:56:32 -0500 | [diff] [blame] | 139 | return 0; |
| 140 | } |
Andrew Geissler | 52cf26a | 2017-07-06 12:56:32 -0500 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | bool PowerCap::getPcapEnabled() |
| 144 | { |
George Liu | f3b7514 | 2021-06-10 11:22:50 +0800 | [diff] [blame] | 145 | utils::PropertyValue pcapEnabled{}; |
| 146 | try |
Andrew Geissler | 52cf26a | 2017-07-06 12:56:32 -0500 | [diff] [blame] | 147 | { |
George Liu | f3b7514 | 2021-06-10 11:22:50 +0800 | [diff] [blame] | 148 | pcapEnabled = utils::getProperty(PCAP_PATH, PCAP_INTERFACE, |
| 149 | POWER_CAP_ENABLE_PROP); |
Andrew Geissler | 52cf26a | 2017-07-06 12:56:32 -0500 | [diff] [blame] | 150 | |
George Liu | f3b7514 | 2021-06-10 11:22:50 +0800 | [diff] [blame] | 151 | return std::get<bool>(pcapEnabled); |
| 152 | } |
Patrick Williams | 2561362 | 2021-09-02 09:29:54 -0500 | [diff] [blame] | 153 | catch (const sdbusplus::exception::exception& e) |
George Liu | f3b7514 | 2021-06-10 11:22:50 +0800 | [diff] [blame] | 154 | { |
| 155 | log<level::ERR>("Failed to get PowerCapEnable property", |
| 156 | entry("ERROR=%s", e.what()), |
| 157 | entry("PATH=%s", PCAP_PATH)); |
| 158 | |
| 159 | return false; |
| 160 | } |
Andrew Geissler | 52cf26a | 2017-07-06 12:56:32 -0500 | [diff] [blame] | 161 | } |
Andrew Geissler | 32016d1 | 2017-06-20 15:46:52 -0500 | [diff] [blame] | 162 | |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 163 | fs::path PowerCap::getPcapFilename(const std::regex& expr) |
Matt Spinler | eaaf3b2 | 2019-07-16 10:29:27 -0500 | [diff] [blame] | 164 | { |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 165 | if (pcapBasePathname.empty()) |
| 166 | { |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 167 | pcapBasePathname = occStatus.getHwmonPath(); |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 168 | } |
Chris Cain | e2d0a43 | 2022-03-28 11:08:49 -0500 | [diff] [blame] | 169 | |
| 170 | if (fs::exists(pcapBasePathname)) |
Matt Spinler | eaaf3b2 | 2019-07-16 10:29:27 -0500 | [diff] [blame] | 171 | { |
Chris Cain | e2d0a43 | 2022-03-28 11:08:49 -0500 | [diff] [blame] | 172 | // Search for pcap file based on the supplied expr |
| 173 | for (auto& file : fs::directory_iterator(pcapBasePathname)) |
Matt Spinler | eaaf3b2 | 2019-07-16 10:29:27 -0500 | [diff] [blame] | 174 | { |
Chris Cain | e2d0a43 | 2022-03-28 11:08:49 -0500 | [diff] [blame] | 175 | if (std::regex_search(file.path().string(), expr)) |
| 176 | { |
| 177 | // Found match |
| 178 | return file; |
| 179 | } |
Matt Spinler | eaaf3b2 | 2019-07-16 10:29:27 -0500 | [diff] [blame] | 180 | } |
| 181 | } |
Chris Cain | e2d0a43 | 2022-03-28 11:08:49 -0500 | [diff] [blame] | 182 | else |
| 183 | { |
| 184 | log<level::ERR>(fmt::format("Power Cap base filename not found: {}", |
| 185 | pcapBasePathname.c_str()) |
| 186 | .c_str()); |
| 187 | } |
| 188 | |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 189 | // return empty path |
| 190 | return fs::path{}; |
Matt Spinler | eaaf3b2 | 2019-07-16 10:29:27 -0500 | [diff] [blame] | 191 | } |
| 192 | |
Chris Cain | 40501a2 | 2022-03-14 17:33:27 -0500 | [diff] [blame] | 193 | // Write the user power cap to sysfs. |
| 194 | // This will trigger the driver to send the cap to the OCC |
Andrew Geissler | 6ac874e | 2017-07-10 15:54:58 -0500 | [diff] [blame] | 195 | void PowerCap::writeOcc(uint32_t pcapValue) |
| 196 | { |
Chris Cain | d4c19a0 | 2022-04-22 15:46:13 -0500 | [diff] [blame] | 197 | if (!occStatus.occActive()) |
| 198 | { |
| 199 | // OCC not running, skip update |
| 200 | return; |
| 201 | } |
| 202 | |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 203 | // Build the hwmon string to write the user power cap |
| 204 | fs::path fileName = getPcapFilename(std::regex{"power\\d+_cap_user$"}); |
| 205 | if (fileName.empty()) |
Matt Spinler | eaaf3b2 | 2019-07-16 10:29:27 -0500 | [diff] [blame] | 206 | { |
Chris Cain | b6535e8 | 2022-01-21 08:24:13 -0600 | [diff] [blame] | 207 | log<level::ERR>( |
| 208 | fmt::format("Could not find a power cap file to write to: {})", |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 209 | pcapBasePathname.c_str()) |
Chris Cain | b6535e8 | 2022-01-21 08:24:13 -0600 | [diff] [blame] | 210 | .c_str()); |
Matt Spinler | eaaf3b2 | 2019-07-16 10:29:27 -0500 | [diff] [blame] | 211 | return; |
| 212 | } |
Matt Spinler | eaaf3b2 | 2019-07-16 10:29:27 -0500 | [diff] [blame] | 213 | |
| 214 | uint64_t microWatts = pcapValue * 1000000ull; |
| 215 | |
| 216 | auto pcapString{std::to_string(microWatts)}; |
Andrew Geissler | 6ac874e | 2017-07-10 15:54:58 -0500 | [diff] [blame] | 217 | |
Andrew Geissler | 6ac874e | 2017-07-10 15:54:58 -0500 | [diff] [blame] | 218 | // Open the hwmon file and write the power cap |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 219 | std::ofstream file(fileName, std::ios::out); |
| 220 | if (file) |
| 221 | { |
| 222 | log<level::INFO>(fmt::format("Writing {}uW to {}", pcapString.c_str(), |
| 223 | fileName.c_str()) |
| 224 | .c_str()); |
| 225 | file << pcapString; |
| 226 | file.close(); |
| 227 | } |
| 228 | else |
| 229 | { |
| 230 | log<level::ERR>(fmt::format("Failed writing {}uW to {} (errno={})", |
| 231 | microWatts, fileName.c_str(), errno) |
| 232 | .c_str()); |
| 233 | } |
| 234 | |
Andrew Geissler | 6ac874e | 2017-07-10 15:54:58 -0500 | [diff] [blame] | 235 | return; |
| 236 | } |
| 237 | |
Chris Cain | 40501a2 | 2022-03-14 17:33:27 -0500 | [diff] [blame] | 238 | // Read the current user power cap from sysfs. |
| 239 | uint32_t PowerCap::readUserCapHwmon() |
| 240 | { |
| 241 | uint32_t userCap = 0; |
| 242 | |
| 243 | // Get the sysfs filename for the user power cap |
| 244 | fs::path userCapName = getPcapFilename(std::regex{"power\\d+_cap_user$"}); |
| 245 | if (userCapName.empty()) |
| 246 | { |
| 247 | log<level::ERR>( |
| 248 | fmt::format( |
| 249 | "readUserCapHwmon: Could not find a power cap file to read: {})", |
| 250 | pcapBasePathname.c_str()) |
| 251 | .c_str()); |
| 252 | return 0; |
| 253 | } |
| 254 | |
| 255 | // Open the sysfs file and read the power cap |
Chris Cain | 40501a2 | 2022-03-14 17:33:27 -0500 | [diff] [blame] | 256 | std::ifstream file(userCapName, std::ios::in); |
| 257 | if (file) |
| 258 | { |
Chris Cain | e2d0a43 | 2022-03-28 11:08:49 -0500 | [diff] [blame] | 259 | uint64_t cap; |
Chris Cain | 40501a2 | 2022-03-14 17:33:27 -0500 | [diff] [blame] | 260 | file >> cap; |
| 261 | file.close(); |
| 262 | // Convert to Watts |
| 263 | userCap = cap / 1000000; |
| 264 | } |
| 265 | else |
| 266 | { |
| 267 | log<level::ERR>( |
| 268 | fmt::format("readUserCapHwmon: Failed reading {} (errno={})", |
| 269 | userCapName.c_str(), errno) |
| 270 | .c_str()); |
| 271 | } |
| 272 | |
| 273 | return userCap; |
| 274 | } |
| 275 | |
Andrew Geissler | 32016d1 | 2017-06-20 15:46:52 -0500 | [diff] [blame] | 276 | void PowerCap::pcapChanged(sdbusplus::message::message& msg) |
| 277 | { |
Andrew Geissler | 32016d1 | 2017-06-20 15:46:52 -0500 | [diff] [blame] | 278 | if (!occStatus.occActive()) |
| 279 | { |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 280 | // Nothing to do |
Andrew Geissler | 32016d1 | 2017-06-20 15:46:52 -0500 | [diff] [blame] | 281 | return; |
| 282 | } |
Andrew Geissler | 52cf26a | 2017-07-06 12:56:32 -0500 | [diff] [blame] | 283 | |
| 284 | uint32_t pcap = 0; |
| 285 | bool pcapEnabled = false; |
| 286 | |
| 287 | std::string msgSensor; |
Patrick Williams | e096270 | 2020-05-13 17:50:22 -0500 | [diff] [blame] | 288 | std::map<std::string, std::variant<uint32_t, bool>> msgData; |
Andrew Geissler | 52cf26a | 2017-07-06 12:56:32 -0500 | [diff] [blame] | 289 | msg.read(msgSensor, msgData); |
| 290 | |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 291 | bool changeFound = false; |
| 292 | for (const auto& [prop, value] : msgData) |
Andrew Geissler | 52cf26a | 2017-07-06 12:56:32 -0500 | [diff] [blame] | 293 | { |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 294 | if (prop == POWER_CAP_PROP) |
Andrew Geissler | 52cf26a | 2017-07-06 12:56:32 -0500 | [diff] [blame] | 295 | { |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 296 | pcap = std::get<uint32_t>(value); |
| 297 | pcapEnabled = getPcapEnabled(); |
| 298 | changeFound = true; |
| 299 | } |
| 300 | else if (prop == POWER_CAP_ENABLE_PROP) |
| 301 | { |
| 302 | pcapEnabled = std::get<bool>(value); |
Andrew Geissler | 52cf26a | 2017-07-06 12:56:32 -0500 | [diff] [blame] | 303 | pcap = getPcap(); |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 304 | changeFound = true; |
Andrew Geissler | 52cf26a | 2017-07-06 12:56:32 -0500 | [diff] [blame] | 305 | } |
| 306 | else |
| 307 | { |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 308 | // Ignore other properties |
| 309 | log<level::DEBUG>( |
| 310 | fmt::format( |
| 311 | "pcapChanged: Unknown power cap property changed {} to {}", |
| 312 | prop.c_str(), std::get<uint32_t>(value)) |
| 313 | .c_str()); |
Andrew Geissler | 52cf26a | 2017-07-06 12:56:32 -0500 | [diff] [blame] | 314 | } |
| 315 | } |
| 316 | |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 317 | if (changeFound) |
| 318 | { |
| 319 | log<level::INFO>( |
| 320 | fmt::format( |
| 321 | "Power Cap Property Change (cap={}W (input), enabled={})", pcap, |
| 322 | pcapEnabled ? 'y' : 'n') |
| 323 | .c_str()); |
Andrew Geissler | 52cf26a | 2017-07-06 12:56:32 -0500 | [diff] [blame] | 324 | |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 325 | // Determine desired action to write to occ |
Andrew Geissler | 6ac874e | 2017-07-10 15:54:58 -0500 | [diff] [blame] | 326 | |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 327 | auto occInput = getOccInput(pcap, pcapEnabled); |
Andrew Geissler | 52cf26a | 2017-07-06 12:56:32 -0500 | [diff] [blame] | 328 | |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 329 | // Write action to occ |
| 330 | writeOcc(occInput); |
| 331 | } |
Andrew Geissler | 52cf26a | 2017-07-06 12:56:32 -0500 | [diff] [blame] | 332 | |
| 333 | return; |
Andrew Geissler | 32016d1 | 2017-06-20 15:46:52 -0500 | [diff] [blame] | 334 | } |
| 335 | |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 336 | // Update the Power Cap bounds on DBus |
Chris Cain | 613dc90 | 2022-04-08 09:56:22 -0500 | [diff] [blame] | 337 | bool PowerCap::updateDbusPcap(uint32_t softMin, uint32_t hardMin, uint32_t max) |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 338 | { |
| 339 | bool complete = true; |
| 340 | |
| 341 | try |
| 342 | { |
Chris Cain | 613dc90 | 2022-04-08 09:56:22 -0500 | [diff] [blame] | 343 | utils::setProperty(PCAP_PATH, PCAP_INTERFACE, POWER_CAP_SOFT_MIN, |
| 344 | softMin); |
| 345 | } |
| 346 | catch (const sdbusplus::exception::exception& e) |
| 347 | { |
| 348 | log<level::ERR>( |
| 349 | fmt::format( |
| 350 | "updateDbusPcap: Failed to set SOFT PCAP to {}W due to {}", |
| 351 | softMin, e.what()) |
| 352 | .c_str()); |
| 353 | complete = false; |
| 354 | } |
| 355 | |
| 356 | try |
| 357 | { |
Chris Cain | 5d66a0a | 2022-02-09 08:52:10 -0600 | [diff] [blame] | 358 | utils::setProperty(PCAP_PATH, PCAP_INTERFACE, POWER_CAP_HARD_MIN, |
| 359 | hardMin); |
| 360 | } |
| 361 | catch (const sdbusplus::exception::exception& e) |
| 362 | { |
| 363 | log<level::ERR>( |
| 364 | fmt::format( |
| 365 | "updateDbusPcap: Failed to set HARD PCAP to {}W due to {}", |
| 366 | hardMin, e.what()) |
| 367 | .c_str()); |
| 368 | complete = false; |
| 369 | } |
| 370 | |
| 371 | try |
| 372 | { |
| 373 | utils::setProperty(PCAP_PATH, PCAP_INTERFACE, POWER_CAP_MAX, max); |
| 374 | } |
| 375 | catch (const sdbusplus::exception::exception& e) |
| 376 | { |
| 377 | log<level::ERR>( |
| 378 | fmt::format( |
| 379 | "updateDbusPcap: Failed to set MAX PCAP to {}W due to {}", max, |
| 380 | e.what()) |
| 381 | .c_str()); |
| 382 | complete = false; |
| 383 | } |
| 384 | |
| 385 | return complete; |
| 386 | } |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 387 | } // namespace powercap |
Andrew Geissler | 32016d1 | 2017-06-20 15:46:52 -0500 | [diff] [blame] | 388 | |
| 389 | } // namespace occ |
| 390 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 391 | } // namespace open_power |