Skip to content

๐Ÿ•“ Time โ€‹

The Time module provides the global runtime time source for Xila services.

Role in system โ€‹

  • Supplies current time to modules that stamp metadata (for example VFS attributes).
  • Supplies uptime-like elapsed time since manager initialization.
  • Acts as the canonical time source adapter for platform drivers.

Responsibilities and boundaries โ€‹

In scope

  • One-time manager initialization with a direct character device source.
  • get_current_time() and get_current_time_since_startup() query APIs.
  • Conversion between device byte payload and core::time::Duration.

Out of scope

  • Time synchronization protocols.
  • Timezone/calendar policy.
  • Multi-source clock arbitration.

Internal architecture โ€‹

  • Singleton manager in OnceLock.
  • Manager stores:
    • device: &'static dyn DirectCharacterDevice,
    • start_time: Duration captured at initialization.
  • Current-time reads deserialize Duration directly from device bytes.

Contract vs implementation

  • Contract: callers get Duration values and error on device/read failures.
  • Implementation: exact wire representation assumes device emits in-memory Duration layout expected by this build.

Lifecycle and execution model โ€‹

  1. Platform provides time device implementation.
  2. time::initialize(driver) captures startup timestamp.
  3. Runtime callers use singleton for current time or elapsed since startup.

Data/control flow โ€‹

  • Read path: module caller -> time manager -> direct character device read -> Duration.
  • Uptime path: current read - cached startup time.

Concurrency and synchronization model โ€‹

  • Manager state is immutable after initialization (device handle + start time).
  • Read calls are lock-free in manager layer and depend on driver thread-safety guarantees.

Dependency model โ€‹

  • Upstream dependency: platform DirectCharacterDevice implementation.
  • Downstream consumers: VFS, graphics tick callback, network time conversion.

Failure semantics and recovery behavior โ€‹

  • Initialization fails if initial time read fails.
  • Runtime queries propagate device read failures as time::Error.
  • No internal retry/backoff policy; callers decide recovery strategy.

Extension points โ€‹

  • Replace time source driver per target.
  • Add higher-level synchronization layers above this module.
  • Extend manager with optional monotonic/wall-clock source separation.

Known limitations and trade-offs โ€‹

  • Read-only API surface (no set-time operation in current module).
  • Accuracy/monotonic behavior depends entirely on device implementation.
  • Wire contract currently assumes compatible Duration representation at device boundary.

References / See also โ€‹