Skip to content

Repository files navigation

Time

Unified time service library and distributed time synchronization infrastructure for automotive ECU software.

Documentation

Overview

Portable and high-performance implementation of time services for the S-CORE project.

This repository contains source code for time clocks, time distribution infrastructure, and PTP synchronization. The Time module is implemented in C++ and provides working examples demonstrating usage patterns.

High-level functionality provided by the Time module:

  • Clock Domains: Four time sources accessed through unified Clock<Tag> API; all domains support nanosecond resolution and compile-time domain selection preventing cross-domain timing errors; mock backends and ScopedClockOverride available for testing
    • SystemTime: Wall-clock time (Unix epoch) for timestamps and user-visible time displays
    • SteadyTime: Monotonic time for duration measurements and timeouts
    • HighResSteadyTime: High-resolution monotonic time for precise timing applications
    • VehicleTime: PTP-synchronized time for distributed automotive applications requiring initialization
  • Clock API: Type-safe Clock<Tag>::GetInstance().Now() returns time and status information
  • Event Subscription: Subscribe<EventType>() / Unsubscribe<EventType>() for status changes and PTP timebase data
  • Time Infrastructure
    • TimeDaemon: Standalone daemon that retrieves synchronized time from TimeSlave, validates timepoints, sets synchronization status, and distributes VehicleTime to applications
    • TimeSlave: gPTP (IEEE 802.1AS) slave endpoint that implements network synchronization protocol, calculates time offset, and publishes synchronization time data to the TimeDaemon

πŸ“‹ Public API

Clock Domains

SystemTime

Target Purpose
//score/time/system_time Wall-clock time (Unix epoch) for timestamps
//score/time/system_time:system_time_mock Mock backend for SystemTime testing
//score/time/system_time:interface Header-only interface (no backend)

SteadyTime

Target Purpose
//score/time/steady_time Monotonic time for duration measurement
//score/time/steady_time:steady_time_mock Mock backend for SteadyTime testing
//score/time/steady_time:interface Header-only interface (no backend)

HighResSteadyTime

Target Purpose
//score/time/high_res_steady_time High-resolution monotonic time
//score/time/high_res_steady_time:high_res_steady_time_mock Mock backend for HighResSteadyTime testing
//score/time/high_res_steady_time:interface Header-only interface (no backend)

VehicleTime

Target Purpose
//score/time/vehicle_time PTP-synchronized vehicle time
//score/time/vehicle_time:vehicle_time_mock Mock backend for VehicleTime testing
//score/time/vehicle_time:interface Header-only interface (no backend)

Test Utilities

Target Purpose
//score/time/clock:clock_test_utils ScopedClockOverride and ClockTestFactory utilities

βš™οΈ Using as Dependency

Add to your MODULE.bazel:

bazel_dep(name = "score_time", version = "x.x.x")

Check available versions in the S-CORE Bazel Registry.

Using Unreleased Versions

To depend on an unreleased version (for development or testing), use a git override in your MODULE.bazel:

git_override(
    module_name = "score_time",
    commit = "abc123...",
    remote = "https://github.com/eclipse-score/time.git",
)

Replace the commit value with the specific git hash you want to use.

Executable Artifacts

For deployment, use these executable targets:

Available binaries:

  • @score_time//score/time_daemon:time_daemon - TimeDaemon executable for time distribution
  • @score_time//score/time_slave:time_slave - TimeSlave executable for PTP synchronization

Run artifacts directly:

bazel run @score_time//score/time_daemon:time_daemon
bazel run @score_time//score/time_slave:time_slave

Do not add these to deps as libraries. Use them as runtime artifacts for your deployment system.


πŸ“– Documentation

Generate module documentation locally:

bazel run //:docs

πŸš€ Getting Started

This section contains information on how to build and use the Time module.

Clone the Repository

git clone https://github.com/eclipse-score/time.git
cd time

Prerequisites

  • C++ Compiler: gcc/clang with C++17 support
  • Build System: Bazel 8+ (managed via Bazelisk)
  • Operating System: Linux (Ubuntu 24.04+)
  • Dependencies: S-CORE Baselibs, Google Test
  • For QNX targets: QNX 8.0 SDP

Development Environment

Use devcontainer as default path. It includes Bazel tooling and dependencies.

  1. Install Docker.
  2. Open repository in a devcontainer-capable editor (for example VS Code with Dev Containers extension).
  3. Reopen workspace in container.

Follow the S-CORE Development Environment Guide for Linux host setup requirements.

Building the Project

Build all components for Linux x86_64 by running:

bazel build --config=time-x86_64-linux //score/... //examples/...

Run all tests:

bazel test --config=time-x86_64-linux //score/... //examples/...

Other Platforms

Linux AArch64:

bazel build --config=time-arm64-linux //score/... //examples/...
bazel test --config=time-arm64-linux //score/... //examples/...

QNX x86_64:

bazel build --config=time-x86_64-qnx //score/... //examples/...
bazel test --config=time-x86_64-qnx //score/... //examples/...

QNX AArch64:

bazel build --config=time-aarch64-qnx //score/... //examples/...
bazel test --config=time-aarch64-qnx //score/... //examples/...

Testing with Sanitizers

To test with AddressSanitizer, UBSan, and LeakSanitizer enabled:

bazel test --config=time-x86_64-linux --config=asan_ubsan_lsan --build_tests_only //score/... //examples/...

πŸ’‘ Examples

Working examples demonstrating clock usage patterns, testing approaches, and integration techniques are available in the examples/ directory:

  • examples/time/system_time β€” SystemTime usage for wall-clock timestamps
  • examples/time/steady_time β€” SteadyTime usage for duration measurements
  • examples/time/high_res_steady_time β€” HighResSteadyTime usage for high-resolution timing
  • examples/time/vehicle_time β€” VehicleTime usage with PTP synchronization

Each example includes a handler demonstrating the Clock API and corresponding unit tests.


πŸ“‚ Repository Structure

β”œβ”€β”€ score/
β”‚   β”œβ”€β”€ time/                    # Clock domains (SystemTime, SteadyTime, etc.)
β”‚   β”œβ”€β”€ time_daemon/             # Time distribution daemon
β”‚   β”œβ”€β”€ time_slave/              # PTP timebase implementation
β”‚   └── ts_client/               # Library for time slave communication
β”œβ”€β”€ examples/                    # Usage examples and patterns
β”œβ”€β”€ docs/                        # Module documentation
└── tools/                       # Build and development utilities

🀝 Contributing

See our Contributing Guide for contribution guidelines and development workflow.


πŸ”— Support

Community

About

Time synchronization module

Resources

Security policy

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages