Skip to content
Merged
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
1 change: 1 addition & 0 deletions score/launch_manager/src/daemon/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ 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:watchdog_factory",
"@score_baselibs//score/language/futurecpp",
] + select({
"//config:lm_use_new_configuration": [
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 @@ -33,7 +33,7 @@ cc_library(
visibility = ["//score/launch_manager/src/daemon/src/alive_monitor:__subpackages__"],
deps = [
"//score/launch_manager/src/daemon/src/alive_monitor/details/factory:flat_cfg_factory",
"//score/launch_manager/src/daemon/src/alive_monitor/details/factory:machine_config_factory",
"//score/launch_manager/src/daemon/src/alive_monitor/details/factory:static_config",
"//score/launch_manager/src/daemon/src/alive_monitor/details/ifappl:checkpoint",
"//score/launch_manager/src/daemon/src/alive_monitor/details/ifappl:data_structures",
"//score/launch_manager/src/daemon/src/alive_monitor/details/ifappl:monitor_if_daemon",
Expand Down Expand Up @@ -66,21 +66,22 @@ cc_library(
":sw_cluster_handler",
"//score/launch_manager/src/control_client",
"//score/launch_manager/src/daemon/src/alive_monitor/details/factory:flat_cfg_factory",
"//score/launch_manager/src/daemon/src/alive_monitor/details/factory:machine_config_factory",
"//score/launch_manager/src/daemon/src/alive_monitor/details/factory:static_config",
"//score/launch_manager/src/daemon/src/alive_monitor/details/ifappl:monitor_if_daemon",
"//score/launch_manager/src/daemon/src/alive_monitor/details/ifexm:process_state_reader",
"//score/launch_manager/src/daemon/src/alive_monitor/details/supervision:alive",
"//score/launch_manager/src/daemon/src/alive_monitor/details/timers:cycle_time_validator",
"//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": [
"//score/launch_manager/src/daemon/src/configuration:config",
],
"//conditions:default": [],
"//conditions:default": [
"//score/launch_manager/src/daemon/src/alive_monitor/details/factory:machine_config_factory",
],
}),
)

Expand All @@ -106,7 +107,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,28 +50,17 @@ 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();
// distributeChanges may fail due to buffer overflow,
// which is checked on the sender side and results in a watchdog timeout.
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@
#include "score/launch_manager/src/daemon/src/common/log.hpp"
#include "score/mw/launch_manager/alive_monitor/details/daemon/PhmDaemonConfig.hpp"
#include "score/mw/launch_manager/alive_monitor/details/daemon/SwClusterHandler.hpp"
#include "score/mw/launch_manager/alive_monitor/details/factory/MachineConfigFactory.hpp"
#include "score/mw/launch_manager/alive_monitor/details/factory/StaticConfig.hpp"
#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"
#include "score/mw/launch_manager/alive_monitor/details/timers/TimeConversion.hpp"
#ifdef USE_NEW_CONFIGURATION
#include "score/mw/launch_manager/configuration/config.hpp"
#else
#include "score/mw/launch_manager/alive_monitor/details/factory/MachineConfigFactory.hpp"
#endif
namespace score
{
Expand All @@ -41,30 +43,28 @@ namespace daemon
/// @brief Return codes for PhmDaemon Initialization
enum class EInitCode : std::int8_t
{
kNoError, ///< Init Successful (no error occurred)
kNotInitialized, ///< Init was not performed
kNoError, ///< Init Successful (no error occurred)
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
};


/// @brief PHM daemon main class wraps the functionality for initialization and cyclic execution.
/// @details This is the main class responsible to execute the main functionalities of PHM daemon,
/// by using the necessary classes from this software component.
class PhmDaemon
{
public:
public:
using OsClock = score::lcm::saf::timers::OsClockInterface;
using Watchdog = watchdog::IWatchdogIf;
using ProcessStateReceiver = score::lcm::IProcessStateReceiver;
using RecoveryClient = score::lcm::IRecoveryClient;
#ifndef USE_NEW_CONFIGURATION
using MachineConfigFactory = factory::MachineConfigFactory;
using SupervisionBufferConfig = MachineConfigFactory::SupervisionBufferConfig;
#endif
using SupervisionBufferConfig = factory::SupervisionBufferConfig;
using CycleTimer = score::lcm::saf::timers::CycleTimer;
using CycleTimeValidator = score::lcm::saf::timers::CycleTimeValidator;
using NanoSecondType = score::lcm::saf::timers::NanoSecondType;
Expand All @@ -77,13 +77,11 @@ 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)
/// @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);
PhmDaemon(OsClock& f_osClock, std::unique_ptr<ProcessStateReceiver> f_process_state_receiver);

/* RULECHECKER_comment(0, 4, check_min_instructions, "Default destructor is not provided\
a function body", true_no_defect) */
Expand All @@ -108,13 +106,13 @@ class PhmDaemon
{
recoveryClient = recovery_client;

MachineConfigFactory machineConfig{};
if (!machineConfig.init(config))
if (!construct(config, factory::StaticConfig::kDefaultSupervisionBufferConfig))
{
return EInitCode::kMachineConfigInitFailed;
return EInitCode::kConstructFlatCfgFactoryFailed;
}

if (!construct(config, machineConfig.getSupervisionBufferConfig()))
int64_t cycleTimeModified{static_cast<std::int64_t>(
timers::TimeConversion::convertMilliSecToNanoSec(config.aliveSupervision().evaluation_cycle_ms))};
#else
EInitCode init(std::shared_ptr<RecoveryClient> recovery_client) noexcept(false)
{
Expand All @@ -126,15 +124,14 @@ class PhmDaemon
return EInitCode::kMachineConfigInitFailed;
}

if (!construct(machineConfig.getSupervisionBufferConfig()))
#endif
if (!construct(factory::StaticConfig::kDefaultSupervisionBufferConfig))
{
return EInitCode::kConstructFlatCfgFactoryFailed;
}

int64_t cycleTimeModified{static_cast<std::int64_t>(machineConfig.getCycleTimeInNs())};
cycleTimeModified =
CycleTimeValidator::adjustCycleTimeOnClockAccuracy(cycleTimeModified, osClock);
#endif
cycleTimeModified = CycleTimeValidator::adjustCycleTimeOnClockAccuracy(cycleTimeModified, osClock);

const int64_t timerInit{cycleTimer.init(cycleTimeModified)};
if (timerInit > 0)
Expand All @@ -150,18 +147,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,11 +219,10 @@ class PhmDaemon
}
LM_LOG_INFO() << "Phm Daemon: Received termination request - shutting down";

watchdog->disable();
return true;
}

private:
private:
/// @brief Create SwCluster objects & Invoke construction of worker objects
/// @details Create the SwclusterHandler objects and the workers for the SwclusterHandler
/// @param[in] f_bufferConfig_r The buffer configuration used for worker construction
Expand Down Expand Up @@ -267,9 +251,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 @@ -51,7 +51,7 @@ bool SwClusterHandler::constructWorkers(
#endif
std::shared_ptr<score::lcm::IRecoveryClient> f_recoveryClient_r,
ifexm::ProcessStateReader& f_processStateReader_r,
const factory::MachineConfigFactory::SupervisionBufferConfig& f_bufferConfig_r) noexcept(false)
const factory::SupervisionBufferConfig& f_bufferConfig_r) noexcept(false)
{
bool isSuccess{false};
factory::FlatCfgFactory flatCfgFactory{f_bufferConfig_r};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
#ifndef SWCLUSTERHANDLER_HPP_INCLUDED
#define SWCLUSTERHANDLER_HPP_INCLUDED

#include "score/mw/launch_manager/alive_monitor/details/factory/MachineConfigFactory.hpp"
#include "score/mw/launch_manager/alive_monitor/details/factory/StaticConfig.hpp"
#include "score/mw/launch_manager/alive_monitor/details/ifappl/DataStructures.hpp"
#include "score/mw/launch_manager/alive_monitor/details/ifexm/ProcessState.hpp"
#include "score/mw/launch_manager/alive_monitor/details/ifexm/ProcessStateReader.hpp"
#include "score/mw/launch_manager/alive_monitor/details/timers/Timers_OsClock.hpp"

#ifdef USE_NEW_CONFIGURATION
#include "score/mw/launch_manager/configuration/config.hpp"
#endif
Expand Down Expand Up @@ -99,7 +100,7 @@ class SwClusterHandler
#endif
std::shared_ptr<score::lcm::IRecoveryClient> f_recoveryClient_r,
ifexm::ProcessStateReader& f_processStateReader_r,
const factory::MachineConfigFactory::SupervisionBufferConfig& f_bufferConfig_r) noexcept(false);
const factory::SupervisionBufferConfig& f_bufferConfig_r) noexcept(false);

/// @brief Perform cyclic execution
/// @details Perform cyclic execution required for supervision of the Software Cluster
Expand Down
Loading
Loading