Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions score/launch_manager/src/daemon/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ cc_binary(
"//score/launch_manager/src/daemon/src/process_group_manager:alive_monitor_thread",
"//score/launch_manager/src/daemon/src/process_state_client:process_state_notifier",
"//score/launch_manager/src/daemon/src/recovery_client",
"//score/launch_manager/src/daemon/src/watchdog:i_watchdog_if",
"@score_baselibs//score/language/futurecpp",
] + select({
"//config:lm_use_new_configuration": [
"//score/launch_manager/src/daemon/src/configuration:flatbuffer_config_loader",
"//score/launch_manager/src/daemon/src/watchdog/details:watchdog_impl",
],
"//conditions:default": [],
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include <score/assert.hpp>

#include "score/mw/launch_manager/alive_monitor/details/daemon/AliveMonitorImpl.hpp"
#include "score/mw/launch_manager/watchdog/details/WatchdogImpl.hpp"

namespace score
{
Expand All @@ -31,21 +30,17 @@ namespace daemon

#ifdef USE_NEW_CONFIGURATION
AliveMonitorImpl::AliveMonitorImpl(SptrIRecoveryClient recovery_client,
UptrIWatchdogIf watchdog,
UptrIProcessStateReceiver process_state_receiver,
const Config& config)
: m_recovery_client(recovery_client),
m_watchdog(std::move(watchdog)),
m_process_state_receiver{std::move(process_state_receiver)},
m_config(config)
{
}
#else
AliveMonitorImpl::AliveMonitorImpl(SptrIRecoveryClient recovery_client,
UptrIWatchdogIf watchdog,
UptrIProcessStateReceiver process_state_receiver)
: m_recovery_client(recovery_client),
m_watchdog(std::move(watchdog)),
m_process_state_receiver{std::move(process_state_receiver)}
{
}
Expand All @@ -58,8 +53,7 @@ EInitCode AliveMonitorImpl::init() noexcept
{
m_osClock.startMeasurement();

m_daemon = std::make_unique<PhmDaemon>(m_osClock, std::move(m_watchdog),
std::move(m_process_state_receiver));
m_daemon = std::make_unique<PhmDaemon>(m_osClock, std::move(m_process_state_receiver));
#ifdef USE_NEW_CONFIGURATION
initResult = m_daemon->init(m_recovery_client, m_config);
#else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,11 @@ namespace lcm {

class IRecoveryClient;

namespace watchdog {
class IWatchdogIf;
}

namespace saf {

namespace daemon {

using SptrIRecoveryClient = std::shared_ptr<score::lcm::IRecoveryClient>;
using UptrIWatchdogIf = std::unique_ptr<watchdog::IWatchdogIf>;
using UptrIProcessStateReceiver = std::unique_ptr<score::lcm::IProcessStateReceiver>;
using UptrPhmDaemon = std::unique_ptr<score::lcm::saf::daemon::PhmDaemon>;
using OsClock = score::lcm::saf::timers::OsClockInterface;
Expand All @@ -47,12 +42,10 @@ class AliveMonitorImpl : public IAliveMonitor {
public:
#ifdef USE_NEW_CONFIGURATION
AliveMonitorImpl(SptrIRecoveryClient recovery_client,
UptrIWatchdogIf watchdog,
UptrIProcessStateReceiver process_state_receiver,
const Config& config);
#else
AliveMonitorImpl(SptrIRecoveryClient recovery_client,
UptrIWatchdogIf watchdog,
AliveMonitorImpl(SptrIRecoveryClient recovery_client,
UptrIProcessStateReceiver process_state_receiver);
#endif

Expand All @@ -62,7 +55,6 @@ class AliveMonitorImpl : public IAliveMonitor {

private:
SptrIRecoveryClient m_recovery_client{nullptr};
UptrIWatchdogIf m_watchdog{nullptr};
UptrPhmDaemon m_daemon{nullptr};
OsClock m_osClock{};
UptrIProcessStateReceiver m_process_state_receiver;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ cc_library(
"//score/launch_manager/src/daemon/src/alive_monitor/details/timers:cycle_timer",
"//score/launch_manager/src/daemon/src/alive_monitor/details/timers:timers_os_clock",
"//score/launch_manager/src/daemon/src/common:log",
"//score/launch_manager/src/daemon/src/watchdog:i_watchdog_if",
"//score/launch_manager/src/lifecycle_client",
] + select({
"//config:lm_use_new_configuration": [
Expand Down Expand Up @@ -106,7 +105,6 @@ cc_library(
visibility = ["//score/launch_manager/src/daemon:__subpackages__"],
deps = [
":i_health_monitor",
"//score/launch_manager/src/daemon/src/watchdog/details:watchdog_impl",
"@score_baselibs//score/language/futurecpp",
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,17 @@ namespace daemon
true_no_defect) */
/* RULECHECKER_comment(0, 4, check_incomplete_data_member_construction, "Default constructor is used for\
processStateReader.", true_no_defect) */
PhmDaemon::PhmDaemon(OsClock& f_osClock,
std::unique_ptr<Watchdog> f_watchdog,
std::unique_ptr<ProcessStateReceiver> f_process_state_receiver)
PhmDaemon::PhmDaemon(OsClock& f_osClock, std::unique_ptr<ProcessStateReceiver> f_process_state_receiver)
: osClock{f_osClock},
cycleTimer{&osClock},
swClusterHandlers{},
processStateReader{std::move(f_process_state_receiver)},
watchdog(std::move(f_watchdog))
processStateReader{std::move(f_process_state_receiver)}
{
static_cast<void>(f_osClock);
}

void PhmDaemon::performCyclicTriggers(void)
{
bool isCriticalFailure{false};

NanoSecondType syncTimestamp{timers::OsClock::getMonotonicSystemClock()};
if (syncTimestamp == 0U)
{
Expand All @@ -55,29 +50,13 @@ void PhmDaemon::performCyclicTriggers(void)
syncTimestamp = UINT64_MAX;
}

isCriticalFailure = (!processStateReader.distributeChanges(syncTimestamp));

if (!isCriticalFailure)
if (processStateReader.distributeChanges(syncTimestamp))
{
for (auto& phmHandler : swClusterHandlers)
{
phmHandler.performCyclicTriggers(syncTimestamp);
isCriticalFailure = isCriticalFailure || phmHandler.hasAnyRecoveryEnqueueFailed();
}
}

// watchdog is fired iff:
// * isCriticalFailure is set (e.g. process state distribution error, recovery ring buffer full)
// else:
// * watchdog is serviced
if (!isCriticalFailure)
{
watchdog->serviceWatchdog();
}
else
{
watchdog->fireWatchdogReaction();
}
}

#ifdef USE_NEW_CONFIGURATION
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include "score/mw/launch_manager/alive_monitor/details/ifexm/ProcessStateReader.hpp"
#include "score/mw/launch_manager/alive_monitor/details/timers/CycleTimeValidator.hpp"
#include "score/mw/launch_manager/alive_monitor/details/timers/CycleTimer.hpp"
#include "score/mw/launch_manager/watchdog/IWatchdogIf.hpp"
#ifdef USE_NEW_CONFIGURATION
#include "score/mw/launch_manager/configuration/config.hpp"
#endif
Expand All @@ -45,8 +44,6 @@ enum class EInitCode : std::int8_t
kNotInitialized, ///< Init was not performed
kCycleTimeInitFailed, ///< Cyclic Timer initialization failed
kConstructFlatCfgFactoryFailed, ///< FlatCfgFactory failed loading SWCL configurations
kWatchdogInitFailed, ///< Watchdog Initialization failed
kWatchdogEnableFailed, ///< Enabling watchdog device failed
kMachineConfigInitFailed, ///< MachineConfigFactory failed loading the machine configuration
kSignalHandlerRegistrationFailed, ///< Failed to register signal handler for termination signals
kGeneralError ///< General error
Expand All @@ -60,7 +57,6 @@ class PhmDaemon
{
public:
using OsClock = score::lcm::saf::timers::OsClockInterface;
using Watchdog = watchdog::IWatchdogIf;
using ProcessStateReceiver = score::lcm::IProcessStateReceiver;
using RecoveryClient = score::lcm::IRecoveryClient;
using MachineConfigFactory = factory::MachineConfigFactory;
Expand All @@ -77,12 +73,10 @@ class PhmDaemon
as same as generated function", true_no_defect) */
/// @brief Set the OS clock interface
/// @param[in] f_osClock Access to the system clock (dependency injection possible in tests)
/// @param[in] f_watchdog watchdog implementation (dependency injection possible in tests)
/// @param[in] f_process_state_receiver process state receiver implementation (dependency injection possible in tests)
/* RULECHECKER_comment(3,1, check_expensive_to_copy_in_parameter, "Move only types cannot be passed by const ref",
true_no_defect) */
PhmDaemon(OsClock& f_osClock,
std::unique_ptr<Watchdog> f_watchdog,
std::unique_ptr<ProcessStateReceiver> f_process_state_receiver);

/* RULECHECKER_comment(0, 4, check_min_instructions, "Default destructor is not provided\
Expand Down Expand Up @@ -150,18 +144,6 @@ class PhmDaemon
return EInitCode::kCycleTimeInitFailed;
}

if (!watchdog->init(cycleTimeModified, machineConfig))
{
LM_LOG_ERROR() << "Phm Daemon: Initialization of watchdog failed!";
return EInitCode::kWatchdogInitFailed;
}

if (!watchdog->enable())
{
LM_LOG_ERROR() << "Phm Daemon: Enabling of watchdog failed!";
return EInitCode::kWatchdogEnableFailed;
}

return EInitCode::kNoError;
}

Expand Down Expand Up @@ -234,7 +216,6 @@ class PhmDaemon
}
LM_LOG_INFO() << "Phm Daemon: Received termination request - shutting down";

watchdog->disable();
return true;
}

Expand Down Expand Up @@ -267,9 +248,6 @@ class PhmDaemon

/// @brief Process State Reader for PHM daemon
ProcessStateReader processStateReader;

/// @brief Connection to watchdog devices
std::unique_ptr<Watchdog> watchdog;
};

} // namespace daemon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ cc_library(
}),
include_prefix = "score/mw/launch_manager/alive_monitor/details/factory",
strip_include_prefix = "/score/launch_manager/src/daemon/src/alive_monitor/details/factory",
visibility = ["//score/launch_manager/src/daemon/src/alive_monitor:__subpackages__"],
visibility = ["//score/launch_manager/src/daemon:__subpackages__"],
deps = [
":static_config",
"//score/launch_manager/src/daemon/src/alive_monitor/config",
Expand Down
3 changes: 3 additions & 0 deletions score/launch_manager/src/daemon/src/common/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ constexpr std::chrono::milliseconds kMaxRunningDelay{1000}; ///< report_running
constexpr std::chrono::milliseconds kControlClientMaxIpcDelay{500}; ///< The maximum time to wait, when trying to communicate with LCM. When this time is exceeded kCommunicationError will be returned
constexpr std::chrono::milliseconds kControlClientBgThreadSleepTime{100};

constexpr std::int64_t kMainLoopCycleTimeMs{50}; ///< The period at which the main loop services the watchdog
constexpr std::int64_t kMainLoopCycleTimeNs{kMainLoopCycleTimeMs * 1'000'000LL};

enum class ControlClientLimits : uint16_t {
kControlClientMaxInstances =
256U, ///< Maximum number of ControlClient instances that should be created by state manager. If state manager create more instances than kMaxInstances, those instances will always return kCommunicationError when used
Expand Down
4 changes: 2 additions & 2 deletions score/launch_manager/src/daemon/src/configuration/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
#ifndef CONFIG_HPP
#define CONFIG_HPP

#include <sys/types.h>
#include <cstdint>
#include <optional>
#include <string>
#include <string_view>
#include <sys/types.h>
#include <vector>

namespace score::mw::launch_manager::configuration
Expand Down Expand Up @@ -291,4 +291,4 @@ class ConfigBuilder

} // namespace score::mw::launch_manager::configuration

#endif // CONFIG_HPP
#endif // CONFIG_HPP
17 changes: 11 additions & 6 deletions score/launch_manager/src/daemon/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "score/mw/launch_manager/common/log.hpp"

#include "score/mw/launch_manager/alive_monitor/details/daemon/AliveMonitorImpl.hpp"
#include "score/mw/launch_manager/watchdog/details/WatchdogImpl.hpp"
#include "score/mw/launch_manager/watchdog/IWatchdogIf.hpp"
#include "score/mw/launch_manager/process_group_manager/alive_monitor_thread.hpp"
#include "score/mw/launch_manager/process_group_manager/process_group_manager.hpp"
#include "score/mw/launch_manager/process_state_client/process_state_notifier.hpp"
Expand Down Expand Up @@ -205,21 +205,26 @@ int main([[maybe_unused]] int argc, [[maybe_unused]] const char* argv[])
#endif
LM_LOG_DEBUG() << "Launch Manager Started !!!!";
std::shared_ptr<score::lcm::IRecoveryClient> recoveryClient{std::make_shared<score::lcm::RecoveryClient>()};
std::unique_ptr<score::lcm::watchdog::IWatchdogIf> watchdog{
std::make_unique<score::lcm::watchdog::WatchdogImpl>()};
auto process_state_notifier = std::make_unique<score::lcm::internal::ProcessStateNotifier>();
std::unique_ptr<score::lcm::saf::daemon::IAliveMonitor> healthMonitor{
std::make_unique<score::lcm::saf::daemon::AliveMonitorImpl>(
recoveryClient, std::move(watchdog), process_state_notifier->constructReceiver()
recoveryClient, process_state_notifier->constructReceiver()
#ifdef USE_NEW_CONFIGURATION
, *config_result
#endif
)};
std::unique_ptr<score::lcm::internal::IAliveMonitorThread> aliveMonitorThread{
std::make_unique<score::lcm::internal::AliveMonitorThread>(std::move(healthMonitor))};

std::unique_ptr<ProcessGroupManager> process_group_manager = std::make_unique<ProcessGroupManager>(
std::move(aliveMonitorThread), recoveryClient, std::move(process_state_notifier));
#ifdef USE_NEW_CONFIGURATION
auto watchdog = score::lcm::watchdog::createWatchdog();
auto process_group_manager = std::make_unique<ProcessGroupManager>(
std::move(aliveMonitorThread), recoveryClient, std::move(process_state_notifier), std::move(watchdog));
#else
// Legacy configuration wires no watchdog; the watchdog usage in PGM is #ifdef-guarded off.
auto process_group_manager = std::make_unique<ProcessGroupManager>(
std::move(aliveMonitorThread), recoveryClient, std::move(process_state_notifier), nullptr);
#endif

#ifdef USE_NEW_CONFIGURATION
if (process_group_manager->initialize(*config_result))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ cc_library(
"//score/launch_manager/src/daemon/src/process_group_manager/details:safe_process_map",
"//score/launch_manager/src/daemon/src/process_state_client:iprocess_state_notifier",
"//score/launch_manager/src/daemon/src/recovery_client",
"//score/launch_manager/src/daemon/src/watchdog:i_watchdog_if",
"@score_baselibs//score/language/futurecpp",
] + select({
"//config:lm_use_new_configuration": [
Expand Down
Loading
Loading