Skip to content
Draft
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
' *******************************************************************************
' Copyright (c) 2026 Contributors to the Eclipse Foundation
'
' See the NOTICE file(s) distributed with this work for additional
' information regarding copyright ownership.
'
' This program and the accompanying materials are made available under the
' terms of the Apache License Version 2.0 which is available at
' https://www.apache.org/licenses/LICENSE-2.0
'
' SPDX-License-Identifier: Apache-2.0
' *******************************************************************************

@startuml config_vehicle_time_seq_diagram
title score Vehicle Time - link-time configuration per machine (proposed)

skinparam sequenceMessageAlign center
skinparam ParticipantPadding 8
skinparam BoxPadding 6

participant "main()\nrun_application<TimeDaemon>()" as Main
participant "TimeDaemon" as TD

box "Integrator-provided (linked)" #LightYellow
participant "CreateTimebaseHandlers()" as Hook
end box

box "score: Vehicle Time timebase" #AliceBlue
participant "CreateVehicleTimebase()" as Factory
participant "ScoreVehicleTimebaseHandler\n(GenericTimebaseHandler<PtpTimeInfo>)" as Handler
participant "MessageBroker<PtpTimeInfo>" as Broker
participant "JobRunner" as Runner
end box

box "score: machines" #Honeydew
participant "PtpControlFlowDivider\n(ControlFlowDivider<PtpTimeInfo, kBufferSize>,\nEventDrivenMachine)" as Divider
participant "GPTPShmMachine\n(PTPMachine<ShmPTPEngine>,\nPeriodicMachine)" as Ptp
participant "SvtVerificationMachine\n(VerificationMachine<PtpTimeInfo>,\nReactiveMachine)" as Verif
participant "SvtPublisher\n(PublisherImpl<PtpTimeInfo, svt::TimeBaseSnapshot>,\nReactiveMachine)" as Pub
end box

== 1. Construction: integrator selects timebases and values ==

Main -> TD ++ : TimeDaemon()
TD -> Hook ++ : CreateTimebaseHandlers()
Hook -> Factory ++ : CreateVehicleTimebase(config)
Factory -> Handler ** : std::make_unique<ScoreVehicleTimebaseHandler>(config)
note right of Handler : stores a copy of config: VehicleTimebaseConfig\n(one struct per machine + init_timeout,\nused later in CreateComponents)
Factory --> Hook -- : std::unique_ptr<TimebaseHandler>
Hook --> TD -- : std::vector<std::unique_ptr<TimebaseHandler>>
TD --> Main --

== 2. Initialize: handler creates and wires machines from config ==

Main -> TD ++ : Initialize(context)
TD -> TD : InitializeAllTimebases()
TD -> Handler ++ : Initialize()
Handler -> Handler ++ : CreateComponents()

Handler -> Divider ** : CreatePtpControlFlowDivider(config.control_flow_divider)
Handler -> Handler : Add(divider, config.init_timeout.Get())
Handler -> Ptp ** : CreateGPTPShmMachine(config.ptp_machine)
Handler -> Handler : Add(ptp, config.init_timeout.Get())
Handler -> Verif ** : CreateSvtVerificationMachine(config.verification_machine)
note right of Verif
validators built from
config.verification_machine:
SynchronizationValidator()
TimeoutValidator(reception_timeout)
TimeJumpsValidator(max_time_jump_allowed,
sync_debounce_threshold,
valid_frames_threshold)
end note
Handler -> Handler : Add(verification, config.init_timeout.Get())
Handler -> Pub ** : CreateSvtPublisher(config.publisher)
Handler -> Handler : Add(publisher, config.init_timeout.Get())

Handler -> Broker : Subscribe(divider, "in_ptp_data")\n→ AddSubscriber()
Handler -> Broker : Subscribe(verification, "raw_ptp_data")\n→ AddSubscriber()
Handler -> Broker : Subscribe(publisher, "validated_ptp_data")\n→ AddSubscriber()
Handler -> Broker : Publish(ptp, "in_ptp_data")\n→ AddProducer()
Handler -> Broker : Publish(divider, "raw_ptp_data")\n→ AddProducer()
Handler -> Broker : Publish(verification, "validated_ptp_data")\n→ AddProducer()
deactivate Handler

Handler -> Runner ** : JobRunner(init_jobs_, name_ + "_init")
Handler --> TD -- : void (is_configured_ = true)
TD --> Main -- : EXIT_SUCCESS

@enduml
186 changes: 130 additions & 56 deletions score/time_daemon/docs/detailed_design/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -698,71 +698,145 @@ The daemon should have the following logging contexts:
Variability
~~~~~~~~~~~

Configuration files
^^^^^^^^^^^^^^^^^^^
Link-time timebase configuration
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Timebases are configured in code, and their configuration is fixed when the daemon is linked. The configuration
passes through the factory composition described in :ref:`time_daemon_factory_composition`: from
``CreateTimebaseHandlers()`` to the timebase handlers, and from each handler to its machines.

The integrator provides and links ``CreateTimebaseHandlers()``, selecting the timebases to include and returning
their handlers. The configuration mirrors the machine composition of a timebase:

- Each machine defines its own configuration struct, which its factory function accepts. The struct contains
only the settings of that machine, so the machine and its configuration can be reused in any timebase.
- The configuration struct of a timebase is a struct of structs: it holds one machine configuration struct for
each machine of the timebase, together with the initialization timeout that the handler applies when
registering the machines.

All members of the configuration structs are ``const`` and have literal types; for example, a machine name holds
a ``std::string_view`` that refers to a string literal, not a ``std::string``. The integrator defines the
configuration as a ``constexpr`` object, so its values are specified once, at compile time. Neither this object
nor any copy of it, such as the copy that the handler retains, can be changed afterwards.

The integrator must specify every value. Aggregate initialization initializes an omitted member from ``{}``, so a
forgotten value of a plain type such as ``std::chrono::nanoseconds`` would silently become zero. Each value
therefore has its own type, ``ConfigValue<T, Tag>``, which has an ``explicit`` constructor and no default
constructor. A forgotten value, or a forgotten machine configuration struct, is then a compile error in the
integrator's code, independent of the compiler warnings enabled there. This guarantee requires that each member
of a configuration struct is either a ``ConfigValue`` or a machine configuration struct, and that no member has a
default member initializer. Because a ``using`` alias does not create a new type, the alias of each value declares
its own ``Tag`` type, which is never defined and only distinguishes the types of values that share ``T``, such as
the ``std::chrono::nanoseconds`` values of the verification machine. The distinct types also reject values in the
wrong order and name each value in the integrator's initializer.

.. code-block:: cpp

template <typename T, typename Tag>
class ConfigValue
{
public:
constexpr explicit ConfigValue(const T value) noexcept : value_{value} {}

constexpr T Get() const noexcept
{
return value_;
}

private:
const T value_;
};

using MachineName = ConfigValue<std::string_view, struct MachineNameTag>;
using InitTimeout = ConfigValue<std::chrono::seconds, struct InitTimeoutTag>;

For the standard Vehicle Time setup, the proposed factory ``CreateVehicleTimebase()`` accepts the following
configuration struct:

The ``TimeDaemon`` uses structured configuration files to enable customization of its runtime behavior. These data could be configured:
.. code-block:: cpp

1. Component-specific Configuration:
struct VehicleTimebaseConfig
{
const PtpControlFlowDividerConfig control_flow_divider;
const GPTPShmMachineConfig ptp_machine;
const SvtVerificationMachineConfig verification_machine;
const SvtPublisherConfig publisher;
const InitTimeout init_timeout;
};

a. Each component can have dedicated configuration sections
b. Parameters such as update rates, timeouts, and thresholds can be specified
std::unique_ptr<TimebaseHandler> CreateVehicleTimebase(const VehicleTimebaseConfig& config);

2. Topic Configuration:
The handler retains the configuration. In ``CreateComponents()``, it passes each machine configuration struct to
the factory of that machine, registers each machine with ``init_timeout`` and connects the machines through the
message broker.

a. Topics for the ``Message Broker`` can be defined in configuration
b. Publisher and subscriber relationships can be specified externally
c. Component roles (publisher/subscriber) can be assigned through configuration
For example, ``SvtVerificationMachineConfig`` contains the instance name of the verification machine and the
parameters of its timeout and time-jump validators. The synchronization validator has no parameters.

3. File Format and Structure: The configuration files use JSON format for readability and easy parsing:
.. code-block:: cpp

.. code-block:: json
using ReceptionTimeout = ConfigValue<std::chrono::milliseconds, struct ReceptionTimeoutTag>;
using MaxTimeJumpAllowed = ConfigValue<std::chrono::microseconds, struct MaxTimeJumpAllowedTag>;
using SyncDebounceThreshold = ConfigValue<std::chrono::seconds, struct SyncDebounceThresholdTag>;
using ValidFramesThreshold = ConfigValue<std::uint8_t, struct ValidFramesThresholdTag>;

struct SvtVerificationMachineConfig
{
"message_broker": {
"topics": [
{
"name": "raw_ptp_data",
"publishers": ["PtpMachine"],
"subscribers": ["ControlFlowDivider"]
},
{
"name": "input_ptp_data",
"publishers": ["ControlFlowDivider"],
"subscribers": ["VerificationMachine"]
},
{
"name": "verified_ptp_data",
"publishers": ["VerificationMachine"],
"subscribers": ["IPCMachine"]
}
]
},
"ptp_machine": {
"update_interval_ms": 50,
"ptp_stack_type": "ptp",
"ptp_stack_parameters": {
"device": "/dev/ptp0"
}
},
"control_flow_divider": {
"timeout_ms": 500,
"publishing_rate_ms": 100
},
"verification_machine": {
"validation_stages": ["synchronization", "timejumps", "timeout"],
"timejumps_parameters": {
"max_backward_jump_ns": 100000
},
"timeout_parameters": {
"threshold_ns": 100000
}
},
"ipc_machine": {
"shared_memory_name": "vehicle_time",
"shared_memory_size": 4096
}
}
const MachineName name;

// TimeoutValidator
const ReceptionTimeout reception_timeout;

// TimeJumpsValidator
const MaxTimeJumpAllowed max_time_jump_allowed;
const SyncDebounceThreshold sync_debounce_threshold;
const ValidFramesThreshold valid_frames_threshold;
};

std::shared_ptr<SvtVerificationMachine> CreateSvtVerificationMachine(const SvtVerificationMachineConfig& config);

The integrator specifies the values once, in ``constexpr`` objects, and composes the timebase configuration from
the machine configurations. The configurations of the other machines are defined in the same way:

.. code-block:: cpp

constexpr SvtVerificationMachineConfig kVerificationMachineConfig{
MachineName{"time_verification_worker"},
ReceptionTimeout{std::chrono::milliseconds{3300}},
MaxTimeJumpAllowed{std::chrono::microseconds{500}},
SyncDebounceThreshold{std::chrono::seconds{5}},
ValidFramesThreshold{2U},
};

constexpr VehicleTimebaseConfig kVehicleTimebaseConfig{
kControlFlowDividerConfig,
kPtpMachineConfig,
kVerificationMachineConfig,
kPublisherConfig,
InitTimeout{std::chrono::seconds{20}},
};

An integrator can instead provide a custom handler and factory for a timebase with a different machine
composition. For example, a vendor-specific Vehicle Time handler can use a different PTP machine while
reusing suitable S-CORE machines. Its timebase configuration struct then combines the configuration struct of
the vendor PTP machine with those of the reused S-CORE machines. The custom handler is responsible for
selecting, configuring and wiring its machines; the standard Vehicle Time factory does not select a replacement
machine.

The following sequence illustrates the proposed standard Vehicle Time configuration. Handler setup creates
the initialization job runner; machine initialization and startup occur later, as described in
:ref:`time_daemon_handler_lifecycle`.

.. raw:: html

<div style="overflow-x: auto; max-width: 100%;">

.. uml:: _assets/config/config_vehicle_time_seq.puml
:alt: Proposed link-time configuration of the Vehicle Time handler and machines

.. raw:: html

</div>

Scalability
^^^^^^^^^^^
Expand Down
Loading