Files
rt-thread/components/drivers/clock_time
GUIandseteiro 8d8dc96b67 [ARCH/RISC-V] Next RISC-V (#10320)
* [libcpu][risc-v] Refactor the RISC-V architecture port

Introduce an opt-in unified RISC-V common layer for RV32 and RV64 while keeping existing BSPs on the legacy implementation during migration.

- use ARCH_RISCV and ARCH_CPU_64BIT for architecture and XLEN selection
- unify context, trap, MMU, cache, timer, SBI, SMP and ISA handling
- add PLIC, CLIC, ACLINT, APLIC and IMSIC support
- map physical hart IDs to contiguous logical CPU IDs
- add T-Head vendor overrides while preserving legacy ports
- migrate qemu-virt64-riscv with RV32 and RV64 support
- update clock_time, MM, LWP, OFW, PCI and Rust integration

Existing BSPs continue using legacy_common or common64 unless they select RT_USING_RISCV_NEW_COMMON.

Signed-off-by: GuEe-GUI <2991707448@qq.com>

* [libcpu][risc-v] skip disabled CPU nodes in early FDT walk

Rbb666 noted that rt_hw_fdt_install_early() walked every /cpus child
without checking status, so disabled cores still joined hart registration
and MMU capability probing. Skip nodes that are not okay/ok via
rt_fdt_device_is_available() before reading reg or mmu-type.

Signed-off-by: seteiro <chenmoushun@163.com>

* [libcpu][risc-v] Fix per-CPU page table mapping

- reuse existing non-leaf page table entries when mapping per-CPU areas
- reject leaf entry conflicts instead of overwriting mappings

Signed-off-by: GuEe-GUI <2991707448@qq.com>

---------

Signed-off-by: GuEe-GUI <2991707448@qq.com>
Signed-off-by: seteiro <chenmoushun@163.com>
Co-authored-by: seteiro <chenmoushun@163.com>
2026-10-17 09:44:26 +08:00
..
2026-10-17 09:44:26 +08:00
2026-10-17 09:44:26 +08:00

Clock Time Subsystem

The clock_time subsystem provides a unified time base and event scheduling for RT-Thread. It separates timekeeping (a monotonic counter) from event delivery (a programmable timer interrupt) so platforms can combine different hardware sources while the kernel sees consistent behavior.

Design Principles

  • Monotonic time: time readings never go backward.
  • Separation of roles: a clock source provides a counter, a clock event triggers deadlines.
  • Scaled integer conversion: counters are converted to nanoseconds with a resolution scale factor, avoiding floating point.
  • Graceful fallback: if a hardware event is unavailable, software timers keep the system functional.

Building Blocks

  • Clock source: provides a stable counter and its frequency.
  • Clock event: can be programmed to fire at the next deadline.
  • Clock timer adapter: exposes a general timer peripheral as a clock source or event device.
  • Clock hrtimer: software scheduler that orders high-resolution timeouts and programs the next event.
  • Clock boottime helpers: translate the monotonic counter into common time formats for use by higher layers.

Time Flow

  • Read path: counter -> scaled resolution -> nanoseconds.
  • Timeout path: hrtimer queue -> next expiry -> program event -> interrupt -> dispatch callbacks.

BSP Integration Guidance

  • Provide a stable counter or a programmable timer. One device can serve both roles.
  • Select a default source and event device to enable accurate timekeeping and efficient scheduling.
  • Keep ISRs minimal; the core handles conversion and scheduling.
  • POSIX time APIs are layered on top of this subsystem and reuse its monotonic base.