Time Sync Client Detailed Design#
Time Sync Client Detailed Design
|
status: draft
security: NO
safety: ASIL_B
|
||||
Description#
The ts_client component provides shared memory-based IPC for gPTP time synchronization data exchange between TimeSlave and TimeDaemon processes. It implements a lock-free, single-writer/multi-reader communication channel using the seqlock protocol over POSIX shared memory.
Use Cases#
Publishing time synchronization snapshots from TimeSlave to shared memory
Reading time synchronization snapshots from TimeDaemon
Lock-free concurrent access with bounded retry on torn reads
Rationale Behind Decomposition into Units#
The ts_client component is decomposed into two implementation units:
GptpIpcPublisher — Creates and writes to the shared memory segment (TimeSlave side)
GptpIpcReceiver — Opens and reads from the shared memory segment (TimeDaemon side)
This separation enables independent deployment in different processes while maintaining a consistent IPC protocol.
Static Diagrams for Unit Interactions#
Class View#
Main classes and their relationships:
Units within Time Sync Client#
GptpIpcPublisher Unit#
The GptpIpcPublisher component creates and manages the POSIX shared memory segment and writes GptpIpcData using the seqlock protocol.
Implementation Requirements#
The GptpIpcPublisher has the following requirements:
The
GptpIpcPublishershall create a POSIX shared memory segment viashm_open()withO_CREATflagThe
GptpIpcPublishershall map the shared memory region asGptpIpcRegionaligned to 64 bytesThe
GptpIpcPublishershall initialize the magic number field to0x47505450(‘GPTP’)The
GptpIpcPublishershall writeGptpIpcDatausing the seqlock protocol:Increment
seq(becomes odd — signals write in progress)Apply a release memory fence
memcpytheGptpIpcDatapayloadStore
seq_confirm = seq + 1Increment
seq(bothseqandseq_confirmbecome even — signals write complete)
The
GptpIpcPublishershall use the default shared memory name/gptp_ptp_infounless overriddenThe
GptpIpcPublishershall supportDestroy()to unmap and unlink the shared memory segment
GptpIpcReceiver Unit#
The GptpIpcReceiver component opens the shared memory segment read-only and reads GptpIpcData with bounded retry on torn reads.
Implementation Requirements#
The GptpIpcReceiver has the following requirements:
The
GptpIpcReceivershall open the POSIX shared memory segment viashm_open()withO_RDONLYflagThe
GptpIpcReceivershall map the shared memory region as read-only (PROT_READ)The
GptpIpcReceivershall validate the magic number (0x47505450) onInit()The
GptpIpcReceivershall readGptpIpcDatausing the seqlock protocol with up to 20 retries:Read
seq1with acquire ordering (must be even, otherwise retry)memcpytheGptpIpcDatapayloadApply an acquire-release fence
Read
seq_confirmasseq2and re-readseqasseq3If
seq1 == seq2 == seq3, the read is consistent; otherwise retry
The
GptpIpcReceivershall returnstd::optional<GptpIpcData>(empty if all retries exhausted)The
GptpIpcReceivershall supportClose()to unmap the shared memory region
Seqlock Protocol Workflow#
The seqlock protocol ensures lock-free communication between publisher and receiver:
Using in Test Environment#
The GptpIpcPublisher and GptpIpcReceiver rely on POSIX shared memory (shm_open), which works on any Linux host. Component tests can run end-to-end using real IPC without platform-specific mocks.
Inspection Checklist#
The checklist for verification of the detailed design and code can be found here: