Time Daemon Detailed Design#
Time Daemon Detailed Design
|
status: draft
security: YES
safety: ASIL_B
|
||||
Description#
Use Cases#
TimeDaemon is the non Autosar adaptive process who is intended to get the Vehicle Time from the ptp slave daemon (ptpd or any other), verify and validate the timepoints and distribute time information across the clients.
More precisely we can specify the following use cases for the time daemon:
Providing current Vehicle time to different applications
Setting the synchronization qualifier (aka Synchronized, Timeout, so on)
Providing needed information for diagnostics
Providing needed information for addition verification, ex SafeCarTime
The raw architectural diagram is represented below.
Rationale Behind Decomposition into Units#
TimeDaemon is decomposed into six implementation units following SOLID principles (Single Responsibility, Open/Closed) and design patterns (Publish-Subscribe, State Machines):
Application — Orchestrates initialization and lifecycle of all daemon components
Message Broker — Central publish-subscribe hub for decoupled inter-unit communication
ControlFlowDivider — Separates execution threads to prevent blocking and maintain data flow consistency
PTP Machine — Retrieves raw time data from PTP stack at consistent rates
Verification Machine — Validates and qualifies time data (sync status, jump detection, timeout)
IPC Machine — Exports qualified time snapshots to client applications via shared-memory interface
This separation enables independent testing, reusable implementations (e.g., different PTP stacks), and clear responsibility boundaries critical for ASIL_B safety qualification.
Static Diagrams for Unit Interactions#
Class View#
Main classes and unit relationships are presented on this diagram:
Deployment View#
The design deployment and process architecture is represented on this diagram:
Dynamic Diagrams for Unit Interactions#
Data and Control Flow#
The data and control flow between units is presented in the following diagram:
On this view you can see several execution scopes:
PTP retrieving scope — retrieves latest PTP data and publishes to
input_ptp_datatopicPTP decoupling scope — decouples the retrieving scope from the following scopes for cases when PTP data is coming in rapidly or new data is missing too long. It publishes PTP data to
raw_ptp_datatopic.PTPTimeInfo handling scope — validates time data and publishes to
verified_ptp_datatopicPTPTimeInfo receiving scope — propagates qualified time to client applications```
Each control flow is implemented with a dedicated thread and is independent from the others.
Data Types or Events#
Main data exchanged between units via MessageBroker topics:
PtpTimeInfo— internal time snapshot struct containing sync data, peer delay, status flags, and timestamps
Topic names:
input_ptp_data
Input PTP snapshot from PtpMachine; published to ControlFlowDivider for thread separation.
raw_ptp_data
Same data as input_ptp_data but republished at consistent rate by ControlFlowDivider; consumed by VerificationMachine.
verified_ptp_data
Validated and qualified time snapshot from VerificationMachine; includes sync status, timeout flags, time jump detection; published to PublisherImpl.
Units within the Component#
The following units comprise TimeDaemon’s internal implementation:
TimeDaemon— main entry point orchestrating lifecycle and initializationMessageBroker— publish-subscribe hub for decoupled inter-unit communicationControlFlowDivider— separates execution threads to prevent blockingPtpMachine— retrieves raw time data from PTP stackShmPtpEngine— reads gPTP data from TimeSlave shared memory channelVerificationMachine— validates and qualifies time dataPublisherImpl— publishes qualified time snapshots via shared memoryReceiverImpl— receives time data from shared memory
Per-Unit Diagrams#
Application#
The Application component is the main entry point for TimeDaemon, orchestrating lifecycle and initialization of all daemon components.
The TimebaseHandler component implements timebase-specific logic. Multiple handlers may exist per supported timebase count, allowing different timebase implementations while maintaining consistent application structure.
During initialization, the Application uses a factory pattern to create components in specific order:
Create
MessageBrokerfirst (other components depend on it)Create ProactiveMachines (
PtpMachine,ControlFlowDivider) that drive system behavior, then initialize and wire subscriptionsCreate ReactiveMachines (
VerificationMachine,IPCMachine) that respond to events, then initialize and wire subscriptions
During execution, ProactiveMachines start in correct order. On termination, they stop in reverse order.
Class diagram:
Initialization sequence showing component creation order and MessageBroker subscription wiring:
Runtime workflow showing ProactiveMachine startup and shutdown coordination:
MessageBroker#
Class diagram:
Initialization workflow:
Message flow through MessageBroker showing topic distribution to multiple subscribers:
ControlFlowDivider#
Class diagram:
Initialization workflow:
Thread separation and periodic republishing workflow:
PTPMachine#
Class diagram:
Initialization workflow:
PTP data retrieval cycle from shared memory:
ShmPTPEngine#
Class diagram:
Initialization workflow:
Shared memory read from TimeSlave gPTP publisher:
VerificationMachine#
Class diagram:
Initialization workflow:
Time data validation stages (sync check, timeout, jump detection):
IPC Machine#
Class diagram:
Initialization workflow:
Qualified time snapshot publishing to client shared memory:
Client-side receive from TimeDaemon shared memory channel:
Logging configuration#
The daemon should have the following logging contexts:
component |
App/Context ID |
Comments |
|---|---|---|
TimeDaemon |
TDON |
TimeDaemON |
Application |
TDAP |
TimeDaemon APplication |
MessageBroker |
TDMB |
TimeDaemon MessageBroker |
ControlFlowDivider |
TDCD |
TimeDaemon ControlFlowDivider |
PTPMachine |
TDPM |
TimeDaemon PTPMachine |
ShmPTPEngine |
GPTP |
GPTP Shm adapter (Initialize / ReadPTPSnapshot) |
VerificationMachine |
TDVM |
TimeDaemon VerificationMachine |
IPCMachine::receiver |
TDIR |
TimeDaemon IPCMachine::Receiver |
IPCMachine::publisher |
TDIP |
TimeDaemon IPCMachine::Publisher |
Variability#
Configuration files#
The TimeDaemon uses structured configuration files to enable customization of its runtime behavior. These data could be configured:
Component-specific Configuration:
Each component can have dedicated configuration sections
Parameters such as update rates, timeouts, and thresholds can be specified
Topic Configuration:
Topics for the
Message Brokercan be defined in configurationPublisher and subscriber relationships can be specified externally
Component roles (publisher/subscriber) can be assigned through configuration
File Format and Structure: The configuration files use JSON format for readability and easy parsing:
{
"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
}
}
Scalability#
The TimeDaemon’s architecture supports scalability in the following ways:
Component Extensibility:#
New machine components can be added by implementing the
BaseMachineinterfaceAdditional validation stages can be plugged into the
VerificationMachinepipelineAlternative IPC mechanisms or communication with ptp stack can be implemented by alternative the
IPCMachineorPTPMachineimplementation
Example based on Qualified Vehicle Time integration#
The Qualified Vehicle Time integration extends the standard TimeDaemon architecture with:
A
Qualified Vehicle Timecomponent that performs additional time qualification and provide new topics:qualified_ptp_dataanddiagnostic_sct_dataA dedicated IPC channel for SCT diagnostic data
A
score::time::qvtlibrary for diagnostic applications
The Qualified Vehicle Time component is integrated into the existing processing pipeline:
It subscribes to the verified_ptp_data topic from the
VerificationMachineIt processes and qualifies the time data with additional QVT-specific checks
It publishes two types of data:
Qualified time data to the standard IPC Machine towards clients interested in the qualified Vehicle Time
Diagnostic data to a dedicated QVT IPC channel towards Diagnostic and Central Validator notifications
The extended data flow with Qualified Vehicle Time integration is shown below:
Example based on Absolute Time integration#
Another example of the TimeDaemon extension is the integration of an Absolute Time source, such as GNSS, to provide absolute time information alongside the relative Vehicle Time from PTP.
The Absolute Time integration extends the standard TimeDaemon architecture with:
An
SDatMachinecomponent that retrieves absolute time from GNSS via SOMEIP or other sources and provide new topics:absolute_time_dataA dedicated verification stage in the
VerificationMachinefor Absolute Time qualificationA dedicated IPC channel for Absolute Time data
A
score::time::abslibrary for applications requiring absolute time on Clients side.
The way how it is integrated is presented below.
The control and data flow with Absolute Time integration is shown below.
Using in test environment#
Using in ITF#
Normal behavior is expected.
Using in Component Tests on the host#
Overview#
The TimeDaemon can be utilized in the Component Tests environment to enable comprehensive testing of time-dependent components without relying on physical PTP hardware.
This approach allows test cases to manipulate time values and synchronization states to validate application behavior under various timing conditions.
For the Component tests the PtpMachine::PtpEngine library is the only one platform-dependent.
Thus the TimeDaemon components remain largely unchanged except for the PTPMachine component, which is replaced with an test-specific implementation that can be controlled via test cases
This component shall:
simulate “normal”
PTPMachinebehaviorhave the communication channel to the test case and react on the manipulations
Next steps: plugin system#
The TimeDaemon could be extended with a flexible plugin system that enables dynamic component loading, configuration, subscription and extension without requiring code changes or recompilation.
Plugin Architecture#
The plugin system is structured around the following key elements:
Component Registry: A central registry that maintains information about available component implementationsComponent Factory: Creates component instances based on configurationPlugin Manager: Loads and initializes plugins at runtimeConfiguration-Driven Assembly: Components and their relationships defined in configuration files
Component Creation Process#
During TimeDaemon initialization:
The
Plugin Managerloads all specified plugins from configured directories or bazel targetsEach plugin registers its component factories with the registry
The
Applicationreads the component configurationFor each component in the configuration:
The appropriate factory is retrieved from the registry
The component is created with its specified parameters
Components are connected based on the
MessageBrokertopic configuration
ASIL-B qualification#
Clean separation of concerns allows the VehicleClock td_impl backend as well as TimeDaemon to be qualified according to ASIL-B requirements following ISO 26262 standard.
Inspection Checklist#
The checklist for verification of the detailed design and code can be found here: