Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 1 | /** |
| 2 | * Copyright 2017 Google Inc. |
| 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 | |
James Feist | 7136a5a | 2018-07-19 09:52:05 -0700 | [diff] [blame] | 17 | #include "config.h" |
Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 18 | |
Harvey Wu | 3dcfd54 | 2022-10-31 17:11:02 +0800 | [diff] [blame] | 19 | #include "buildjson/buildjson.hpp" |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 20 | #include "conf.hpp" |
Patrick Venture | 7f9d690 | 2020-09-10 12:09:57 -0700 | [diff] [blame] | 21 | #include "dbus/dbusconfiguration.hpp" |
Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 22 | #include "interfaces.hpp" |
Patrick Venture | 5c7cc54 | 2018-06-11 14:29:38 -0700 | [diff] [blame] | 23 | #include "pid/builder.hpp" |
Patrick Venture | ba8ffa7 | 2019-02-11 12:03:56 -0800 | [diff] [blame] | 24 | #include "pid/buildjson.hpp" |
James Feist | ce6a3f3 | 2019-03-12 11:20:16 -0700 | [diff] [blame] | 25 | #include "pid/pidloop.hpp" |
Patrick Venture | c32e3fc | 2019-02-28 10:01:11 -0800 | [diff] [blame] | 26 | #include "pid/tuning.hpp" |
Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 27 | #include "pid/zone.hpp" |
Patrick Venture | 5e92909 | 2018-06-08 10:55:23 -0700 | [diff] [blame] | 28 | #include "sensors/builder.hpp" |
Patrick Venture | ba8ffa7 | 2019-02-11 12:03:56 -0800 | [diff] [blame] | 29 | #include "sensors/buildjson.hpp" |
Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 30 | #include "sensors/manager.hpp" |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 31 | #include "util.hpp" |
Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 32 | |
Patrick Venture | b5cc37c | 2019-03-11 09:11:55 -0700 | [diff] [blame] | 33 | #include <CLI/CLI.hpp> |
James Feist | ce6a3f3 | 2019-03-12 11:20:16 -0700 | [diff] [blame] | 34 | #include <boost/asio/io_context.hpp> |
Potin Lai | e2ec69a | 2022-09-30 17:09:34 +0800 | [diff] [blame] | 35 | #include <boost/asio/signal_set.hpp> |
James Feist | ce6a3f3 | 2019-03-12 11:20:16 -0700 | [diff] [blame] | 36 | #include <boost/asio/steady_timer.hpp> |
Patrick Venture | a83a3ec | 2020-08-04 09:52:05 -0700 | [diff] [blame] | 37 | #include <sdbusplus/asio/connection.hpp> |
| 38 | #include <sdbusplus/bus.hpp> |
Bruce Lee | cb4c1a2 | 2021-04-20 16:06:38 +0800 | [diff] [blame] | 39 | #include <sdbusplus/server/manager.hpp> |
Patrick Venture | a83a3ec | 2020-08-04 09:52:05 -0700 | [diff] [blame] | 40 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 41 | #include <chrono> |
Patrick Venture | 7f9d690 | 2020-09-10 12:09:57 -0700 | [diff] [blame] | 42 | #include <filesystem> |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 43 | #include <iostream> |
James Feist | ce6a3f3 | 2019-03-12 11:20:16 -0700 | [diff] [blame] | 44 | #include <list> |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 45 | #include <map> |
| 46 | #include <memory> |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 47 | #include <thread> |
| 48 | #include <unordered_map> |
Patrick Venture | ba8ffa7 | 2019-02-11 12:03:56 -0800 | [diff] [blame] | 49 | #include <utility> |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 50 | #include <vector> |
Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 51 | |
Patrick Venture | a076487 | 2020-08-08 07:48:43 -0700 | [diff] [blame] | 52 | namespace pid_control |
| 53 | { |
| 54 | |
James Feist | 1fe0895 | 2019-05-07 09:17:16 -0700 | [diff] [blame] | 55 | /* The configuration converted sensor list. */ |
Patrick Venture | 1df9e87 | 2020-10-08 15:35:01 -0700 | [diff] [blame] | 56 | std::map<std::string, conf::SensorConfig> sensorConfig = {}; |
James Feist | 1fe0895 | 2019-05-07 09:17:16 -0700 | [diff] [blame] | 57 | /* The configuration converted PID list. */ |
James Feist | f81f288 | 2019-02-26 11:26:36 -0800 | [diff] [blame] | 58 | std::map<int64_t, conf::PIDConf> zoneConfig = {}; |
James Feist | 1fe0895 | 2019-05-07 09:17:16 -0700 | [diff] [blame] | 59 | /* The configuration converted Zone configuration. */ |
Patrick Venture | 1df9e87 | 2020-10-08 15:35:01 -0700 | [diff] [blame] | 60 | std::map<int64_t, conf::ZoneConfig> zoneDetailsConfig = {}; |
Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 61 | |
Patrick Venture | a076487 | 2020-08-08 07:48:43 -0700 | [diff] [blame] | 62 | } // namespace pid_control |
| 63 | |
Potin Lai | 79cde00 | 2023-02-16 13:53:10 +0800 | [diff] [blame] | 64 | std::filesystem::path configPath = ""; |
Patrick Venture | c19f5d4 | 2019-02-14 10:59:47 -0800 | [diff] [blame] | 65 | |
James Feist | 1fe0895 | 2019-05-07 09:17:16 -0700 | [diff] [blame] | 66 | /* async io context for operation */ |
| 67 | boost::asio::io_context io; |
Potin Lai | e2ec69a | 2022-09-30 17:09:34 +0800 | [diff] [blame] | 68 | /* async signal_set for signal handling */ |
| 69 | boost::asio::signal_set signals(io, SIGHUP); |
James Feist | 1fe0895 | 2019-05-07 09:17:16 -0700 | [diff] [blame] | 70 | |
| 71 | /* buses for system control */ |
| 72 | static sdbusplus::asio::connection modeControlBus(io); |
| 73 | static sdbusplus::asio::connection |
| 74 | hostBus(io, sdbusplus::bus::new_system().release()); |
| 75 | static sdbusplus::asio::connection |
| 76 | passiveBus(io, sdbusplus::bus::new_system().release()); |
| 77 | |
Patrick Venture | a076487 | 2020-08-08 07:48:43 -0700 | [diff] [blame] | 78 | namespace pid_control |
| 79 | { |
| 80 | |
Potin Lai | 79cde00 | 2023-02-16 13:53:10 +0800 | [diff] [blame] | 81 | std::filesystem::path searchConfigurationPath() |
| 82 | { |
| 83 | static constexpr auto name = "config.json"; |
| 84 | |
| 85 | for (auto pathSeg : {std::filesystem::current_path(), |
| 86 | std::filesystem::path{"/var/lib/swampd"}, |
| 87 | std::filesystem::path{"/usr/share/swampd"}}) |
| 88 | { |
| 89 | auto file = pathSeg / name; |
| 90 | if (std::filesystem::exists(file)) |
| 91 | { |
| 92 | return file; |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | return name; |
| 97 | } |
| 98 | |
James Feist | 1fe0895 | 2019-05-07 09:17:16 -0700 | [diff] [blame] | 99 | void restartControlLoops() |
Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 100 | { |
James Feist | 1fe0895 | 2019-05-07 09:17:16 -0700 | [diff] [blame] | 101 | static SensorManager mgmr; |
Johnathan Mantey | 5301aae | 2020-09-28 11:06:58 -0700 | [diff] [blame] | 102 | static std::unordered_map<int64_t, std::shared_ptr<ZoneInterface>> zones; |
| 103 | static std::vector<std::shared_ptr<boost::asio::steady_timer>> timers; |
Hao Jiang | b6a0b89 | 2021-02-21 18:00:45 -0800 | [diff] [blame] | 104 | static bool isCanceling = false; |
Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 105 | |
William A. Kennington III | 18d5bb1 | 2021-05-15 20:38:41 -0700 | [diff] [blame] | 106 | for (const auto& timer : timers) |
Johnathan Mantey | 5301aae | 2020-09-28 11:06:58 -0700 | [diff] [blame] | 107 | { |
| 108 | timer->cancel(); |
| 109 | } |
Hao Jiang | b6a0b89 | 2021-02-21 18:00:45 -0800 | [diff] [blame] | 110 | isCanceling = true; |
James Feist | 1fe0895 | 2019-05-07 09:17:16 -0700 | [diff] [blame] | 111 | timers.clear(); |
Hao Jiang | b228cea | 2021-02-20 11:53:09 -0800 | [diff] [blame] | 112 | |
| 113 | if (zones.size() > 0 && zones.begin()->second.use_count() > 1) |
| 114 | { |
| 115 | throw std::runtime_error("wait for count back to 1"); |
| 116 | } |
Johnathan Mantey | 5301aae | 2020-09-28 11:06:58 -0700 | [diff] [blame] | 117 | zones.clear(); |
Hao Jiang | b6a0b89 | 2021-02-21 18:00:45 -0800 | [diff] [blame] | 118 | isCanceling = false; |
Patrick Venture | 4cb7c05 | 2019-02-14 11:11:33 -0800 | [diff] [blame] | 119 | |
Potin Lai | 79cde00 | 2023-02-16 13:53:10 +0800 | [diff] [blame] | 120 | const std::filesystem::path path = |
| 121 | (!configPath.empty()) ? configPath : searchConfigurationPath(); |
Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 122 | |
Patrick Venture | 7f9d690 | 2020-09-10 12:09:57 -0700 | [diff] [blame] | 123 | if (std::filesystem::exists(path)) |
Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 124 | { |
Patrick Venture | 7f9d690 | 2020-09-10 12:09:57 -0700 | [diff] [blame] | 125 | /* |
| 126 | * When building the sensors, if any of the dbus passive ones aren't on |
| 127 | * the bus, it'll fail immediately. |
| 128 | */ |
| 129 | try |
| 130 | { |
| 131 | auto jsonData = parseValidateJson(path); |
| 132 | sensorConfig = buildSensorsFromJson(jsonData); |
Patrick Williams | 8c05112 | 2023-05-10 07:50:59 -0500 | [diff] [blame] | 133 | std::tie(zoneConfig, |
| 134 | zoneDetailsConfig) = buildPIDsFromJson(jsonData); |
Patrick Venture | 7f9d690 | 2020-09-10 12:09:57 -0700 | [diff] [blame] | 135 | } |
| 136 | catch (const std::exception& e) |
| 137 | { |
| 138 | std::cerr << "Failed during building: " << e.what() << "\n"; |
| 139 | exit(EXIT_FAILURE); /* fatal error. */ |
| 140 | } |
Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 141 | } |
Patrick Venture | 7f9d690 | 2020-09-10 12:09:57 -0700 | [diff] [blame] | 142 | else |
Patrick Venture | 18b1311 | 2019-02-14 11:43:59 -0800 | [diff] [blame] | 143 | { |
Patrick Venture | 7f9d690 | 2020-09-10 12:09:57 -0700 | [diff] [blame] | 144 | static boost::asio::steady_timer reloadTimer(io); |
Patrick Venture | 7382318 | 2020-10-08 15:12:51 -0700 | [diff] [blame] | 145 | if (!dbus_configuration::init(modeControlBus, reloadTimer, sensorConfig, |
| 146 | zoneConfig, zoneDetailsConfig)) |
Patrick Venture | 7f9d690 | 2020-09-10 12:09:57 -0700 | [diff] [blame] | 147 | { |
| 148 | return; // configuration not ready |
| 149 | } |
Patrick Venture | 18b1311 | 2019-02-14 11:43:59 -0800 | [diff] [blame] | 150 | } |
Patrick Venture | 4cb7c05 | 2019-02-14 11:11:33 -0800 | [diff] [blame] | 151 | |
James Feist | 1fe0895 | 2019-05-07 09:17:16 -0700 | [diff] [blame] | 152 | mgmr = buildSensors(sensorConfig, passiveBus, hostBus); |
| 153 | zones = buildZones(zoneConfig, zoneDetailsConfig, mgmr, modeControlBus); |
Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 154 | |
| 155 | if (0 == zones.size()) |
| 156 | { |
| 157 | std::cerr << "No zones defined, exiting.\n"; |
James Feist | 1fe0895 | 2019-05-07 09:17:16 -0700 | [diff] [blame] | 158 | std::exit(EXIT_FAILURE); |
Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 159 | } |
| 160 | |
James Feist | 1fe0895 | 2019-05-07 09:17:16 -0700 | [diff] [blame] | 161 | for (const auto& i : zones) |
| 162 | { |
Johnathan Mantey | 5301aae | 2020-09-28 11:06:58 -0700 | [diff] [blame] | 163 | std::shared_ptr<boost::asio::steady_timer> timer = timers.emplace_back( |
| 164 | std::make_shared<boost::asio::steady_timer>(io)); |
James Feist | 1fe0895 | 2019-05-07 09:17:16 -0700 | [diff] [blame] | 165 | std::cerr << "pushing zone " << i.first << "\n"; |
Hao Jiang | b6a0b89 | 2021-02-21 18:00:45 -0800 | [diff] [blame] | 166 | pidControlLoop(i.second, timer, &isCanceling); |
James Feist | 1fe0895 | 2019-05-07 09:17:16 -0700 | [diff] [blame] | 167 | } |
| 168 | } |
| 169 | |
Hao Jiang | b228cea | 2021-02-20 11:53:09 -0800 | [diff] [blame] | 170 | void tryRestartControlLoops(bool first) |
Yong Li | 298a95c | 2020-04-07 15:11:02 +0800 | [diff] [blame] | 171 | { |
Hao Jiang | d11a732 | 2021-03-24 11:25:57 -0700 | [diff] [blame] | 172 | static const auto delayTime = std::chrono::seconds(10); |
Hao Jiang | b228cea | 2021-02-20 11:53:09 -0800 | [diff] [blame] | 173 | static boost::asio::steady_timer timer(io); |
Hao Jiang | d11a732 | 2021-03-24 11:25:57 -0700 | [diff] [blame] | 174 | |
| 175 | auto restartLbd = [](const boost::system::error_code& error) { |
Hao Jiang | 232ffe4 | 2021-02-21 20:11:49 -0800 | [diff] [blame] | 176 | if (error == boost::asio::error::operation_aborted) |
| 177 | { |
| 178 | return; |
| 179 | } |
Hao Jiang | b228cea | 2021-02-20 11:53:09 -0800 | [diff] [blame] | 180 | |
Hao Jiang | 232ffe4 | 2021-02-21 20:11:49 -0800 | [diff] [blame] | 181 | // retry when restartControlLoops() has some failure. |
| 182 | try |
| 183 | { |
| 184 | restartControlLoops(); |
Hao Jiang | 232ffe4 | 2021-02-21 20:11:49 -0800 | [diff] [blame] | 185 | } |
| 186 | catch (const std::exception& e) |
| 187 | { |
Zev Weiss | 5293ec2 | 2023-03-06 18:58:36 -0800 | [diff] [blame] | 188 | std::cerr << "Failed during restartControlLoops, try again: " |
Hao Jiang | 232ffe4 | 2021-02-21 20:11:49 -0800 | [diff] [blame] | 189 | << e.what() << "\n"; |
| 190 | tryRestartControlLoops(false); |
| 191 | } |
Hao Jiang | d11a732 | 2021-03-24 11:25:57 -0700 | [diff] [blame] | 192 | }; |
Zev Weiss | 5293ec2 | 2023-03-06 18:58:36 -0800 | [diff] [blame] | 193 | |
Hao Jiang | d11a732 | 2021-03-24 11:25:57 -0700 | [diff] [blame] | 194 | // first time of trying to restart the control loop without a delay |
| 195 | if (first) |
| 196 | { |
| 197 | boost::asio::post(io, |
| 198 | std::bind(restartLbd, boost::system::error_code())); |
| 199 | } |
| 200 | // re-try control loop, set up a delay. |
| 201 | else |
| 202 | { |
| 203 | timer.expires_after(delayTime); |
| 204 | timer.async_wait(restartLbd); |
| 205 | } |
Yong Li | 298a95c | 2020-04-07 15:11:02 +0800 | [diff] [blame] | 206 | |
| 207 | return; |
| 208 | } |
| 209 | |
Patrick Venture | a076487 | 2020-08-08 07:48:43 -0700 | [diff] [blame] | 210 | } // namespace pid_control |
| 211 | |
Potin Lai | e2ec69a | 2022-09-30 17:09:34 +0800 | [diff] [blame] | 212 | void sighupHandler(const boost::system::error_code& error, int signal_number) |
| 213 | { |
| 214 | static boost::asio::steady_timer timer(io); |
| 215 | |
| 216 | if (error) |
| 217 | { |
| 218 | std::cout << "Signal " << signal_number |
| 219 | << " handler error: " << error.message() << "\n"; |
| 220 | return; |
| 221 | } |
| 222 | |
| 223 | timer.expires_after(std::chrono::seconds(1)); |
| 224 | timer.async_wait([](const boost::system::error_code ec) { |
| 225 | if (ec) |
| 226 | { |
| 227 | std::cout << "Signal timer error: " << ec.message() << "\n"; |
| 228 | return; |
| 229 | } |
| 230 | |
| 231 | std::cout << "reloading configuration\n"; |
| 232 | pid_control::tryRestartControlLoops(); |
| 233 | }); |
| 234 | signals.async_wait(sighupHandler); |
| 235 | } |
| 236 | |
James Feist | 1fe0895 | 2019-05-07 09:17:16 -0700 | [diff] [blame] | 237 | int main(int argc, char* argv[]) |
| 238 | { |
| 239 | loggingPath = ""; |
| 240 | loggingEnabled = false; |
| 241 | tuningEnabled = false; |
Bonnie Lo | c51ba91 | 2022-10-12 14:07:22 +0800 | [diff] [blame] | 242 | debugEnabled = false; |
Josh Lehan | de74542 | 2020-11-07 02:14:09 -0800 | [diff] [blame] | 243 | coreLoggingEnabled = false; |
James Feist | 1fe0895 | 2019-05-07 09:17:16 -0700 | [diff] [blame] | 244 | |
| 245 | CLI::App app{"OpenBMC Fan Control Daemon"}; |
| 246 | |
| 247 | app.add_option("-c,--conf", configPath, |
| 248 | "Optional parameter to specify configuration at run-time") |
| 249 | ->check(CLI::ExistingFile); |
| 250 | app.add_option("-l,--log", loggingPath, |
| 251 | "Optional parameter to specify logging folder") |
| 252 | ->check(CLI::ExistingDirectory); |
| 253 | app.add_flag("-t,--tuning", tuningEnabled, "Enable or disable tuning"); |
Bonnie Lo | c51ba91 | 2022-10-12 14:07:22 +0800 | [diff] [blame] | 254 | app.add_flag("-d,--debug", debugEnabled, "Enable or disable debug mode"); |
Josh Lehan | de74542 | 2020-11-07 02:14:09 -0800 | [diff] [blame] | 255 | app.add_flag("-g,--corelogging", coreLoggingEnabled, |
| 256 | "Enable or disable logging of core PID loop computations"); |
James Feist | 1fe0895 | 2019-05-07 09:17:16 -0700 | [diff] [blame] | 257 | |
James Feist | 1fe0895 | 2019-05-07 09:17:16 -0700 | [diff] [blame] | 258 | CLI11_PARSE(app, argc, argv); |
| 259 | |
Josh Lehan | 811f31d | 2020-09-20 23:31:55 -0700 | [diff] [blame] | 260 | static constexpr auto loggingEnablePath = "/etc/thermal.d/logging"; |
| 261 | static constexpr auto tuningEnablePath = "/etc/thermal.d/tuning"; |
Bonnie Lo | c51ba91 | 2022-10-12 14:07:22 +0800 | [diff] [blame] | 262 | static constexpr auto debugEnablePath = "/etc/thermal.d/debugging"; |
Josh Lehan | de74542 | 2020-11-07 02:14:09 -0800 | [diff] [blame] | 263 | static constexpr auto coreLoggingEnablePath = "/etc/thermal.d/corelogging"; |
Josh Lehan | 811f31d | 2020-09-20 23:31:55 -0700 | [diff] [blame] | 264 | |
Josh Lehan | f54b260 | 2021-04-09 12:17:34 -0700 | [diff] [blame] | 265 | // Set up default logging path, preferring command line if it was given |
| 266 | std::string defLoggingPath(loggingPath); |
| 267 | if (defLoggingPath.empty()) |
| 268 | { |
| 269 | defLoggingPath = std::filesystem::temp_directory_path(); |
| 270 | } |
| 271 | else |
| 272 | { |
| 273 | // Enable logging, if user explicitly gave path on command line |
| 274 | loggingEnabled = true; |
| 275 | } |
| 276 | |
Josh Lehan | 811f31d | 2020-09-20 23:31:55 -0700 | [diff] [blame] | 277 | // If this file exists, enable logging at runtime |
| 278 | std::ifstream fsLogging(loggingEnablePath); |
| 279 | if (fsLogging) |
| 280 | { |
Josh Lehan | de74542 | 2020-11-07 02:14:09 -0800 | [diff] [blame] | 281 | // Allow logging path to be changed by file content |
| 282 | std::string altPath; |
| 283 | std::getline(fsLogging, altPath); |
Josh Lehan | 811f31d | 2020-09-20 23:31:55 -0700 | [diff] [blame] | 284 | fsLogging.close(); |
| 285 | |
Josh Lehan | de74542 | 2020-11-07 02:14:09 -0800 | [diff] [blame] | 286 | if (std::filesystem::exists(altPath)) |
Josh Lehan | f54b260 | 2021-04-09 12:17:34 -0700 | [diff] [blame] | 287 | { |
Josh Lehan | de74542 | 2020-11-07 02:14:09 -0800 | [diff] [blame] | 288 | loggingPath = altPath; |
Josh Lehan | f54b260 | 2021-04-09 12:17:34 -0700 | [diff] [blame] | 289 | } |
Jinliang Wang | cdc8dca | 2023-04-20 14:36:22 -0700 | [diff] [blame] | 290 | else |
| 291 | { |
| 292 | loggingPath = defLoggingPath; |
| 293 | } |
Josh Lehan | f54b260 | 2021-04-09 12:17:34 -0700 | [diff] [blame] | 294 | |
Josh Lehan | 811f31d | 2020-09-20 23:31:55 -0700 | [diff] [blame] | 295 | loggingEnabled = true; |
Josh Lehan | f54b260 | 2021-04-09 12:17:34 -0700 | [diff] [blame] | 296 | } |
Josh Lehan | f54b260 | 2021-04-09 12:17:34 -0700 | [diff] [blame] | 297 | if (loggingEnabled) |
| 298 | { |
Josh Lehan | 811f31d | 2020-09-20 23:31:55 -0700 | [diff] [blame] | 299 | std::cerr << "Logging enabled: " << loggingPath << "\n"; |
| 300 | } |
| 301 | |
| 302 | // If this file exists, enable tuning at runtime |
| 303 | if (std::filesystem::exists(tuningEnablePath)) |
| 304 | { |
| 305 | tuningEnabled = true; |
Josh Lehan | f54b260 | 2021-04-09 12:17:34 -0700 | [diff] [blame] | 306 | } |
Josh Lehan | f54b260 | 2021-04-09 12:17:34 -0700 | [diff] [blame] | 307 | if (tuningEnabled) |
| 308 | { |
Josh Lehan | 811f31d | 2020-09-20 23:31:55 -0700 | [diff] [blame] | 309 | std::cerr << "Tuning enabled\n"; |
| 310 | } |
Kun Yi | d469559 | 2019-05-17 10:42:18 -0700 | [diff] [blame] | 311 | |
Bonnie Lo | c51ba91 | 2022-10-12 14:07:22 +0800 | [diff] [blame] | 312 | // If this file exists, enable debug mode at runtime |
| 313 | if (std::filesystem::exists(debugEnablePath)) |
| 314 | { |
| 315 | debugEnabled = true; |
| 316 | } |
| 317 | |
| 318 | if (debugEnabled) |
| 319 | { |
| 320 | std::cerr << "Debug mode enabled\n"; |
| 321 | } |
| 322 | |
Josh Lehan | de74542 | 2020-11-07 02:14:09 -0800 | [diff] [blame] | 323 | // If this file exists, enable core logging at runtime |
| 324 | if (std::filesystem::exists(coreLoggingEnablePath)) |
| 325 | { |
| 326 | coreLoggingEnabled = true; |
| 327 | } |
| 328 | if (coreLoggingEnabled) |
| 329 | { |
| 330 | std::cerr << "Core logging enabled\n"; |
| 331 | } |
| 332 | |
James Feist | 1fe0895 | 2019-05-07 09:17:16 -0700 | [diff] [blame] | 333 | static constexpr auto modeRoot = "/xyz/openbmc_project/settings/fanctrl"; |
| 334 | // Create a manager for the ModeBus because we own it. |
Patrick Williams | b228bc3 | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 335 | sdbusplus::server::manager_t(static_cast<sdbusplus::bus_t&>(modeControlBus), |
| 336 | modeRoot); |
James Feist | 1fe0895 | 2019-05-07 09:17:16 -0700 | [diff] [blame] | 337 | hostBus.request_name("xyz.openbmc_project.Hwmon.external"); |
| 338 | modeControlBus.request_name("xyz.openbmc_project.State.FanCtrl"); |
Patrick Williams | b228bc3 | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 339 | sdbusplus::server::manager_t objManager(modeControlBus, modeRoot); |
James Feist | 1fe0895 | 2019-05-07 09:17:16 -0700 | [diff] [blame] | 340 | |
Potin Lai | e2ec69a | 2022-09-30 17:09:34 +0800 | [diff] [blame] | 341 | // Enable SIGHUP handling to reload JSON config |
| 342 | signals.async_wait(sighupHandler); |
| 343 | |
Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 344 | /* |
| 345 | * All sensors are managed by one manager, but each zone has a pointer to |
| 346 | * it. |
| 347 | */ |
| 348 | |
Patrick Venture | a076487 | 2020-08-08 07:48:43 -0700 | [diff] [blame] | 349 | pid_control::tryRestartControlLoops(); |
Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 350 | |
James Feist | ce6a3f3 | 2019-03-12 11:20:16 -0700 | [diff] [blame] | 351 | io.run(); |
James Feist | 1fe0895 | 2019-05-07 09:17:16 -0700 | [diff] [blame] | 352 | return 0; |
Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 353 | } |