[PATCH v4 0/3] rust: time: Introduce typed clock sources and generalize Instant

FUJITA Tomonori posted 3 patches 4 months ago
rust/helpers/helpers.c      |   1 +
rust/helpers/time.c         |  18 ++++
rust/kernel/time.rs         | 201 ++++++++++++++++++++++--------------
rust/kernel/time/hrtimer.rs |   6 +-
4 files changed, 148 insertions(+), 78 deletions(-)
create mode 100644 rust/helpers/time.c
[PATCH v4 0/3] rust: time: Introduce typed clock sources and generalize Instant
Posted by FUJITA Tomonori 4 months ago
This patch series introduces a type-safe abstraction over clock
sources. The goal is to remove the need for runtime clock selection
(via ClockId) and instead leverage Rust's type system to statically
associate the Instant type with a specific clock.

This approach enables compile-time enforcement of clock correctness
across the APIs of Instant type.

v4:
- make a one-to-one mapping between Rust helper functions and their C counterparts
v3: https://lore.kernel.org/rust-for-linux/20250609010415.3302835-1-fujita.tomonori@gmail.com/
- rebased on 6.16-rc1
v2: https://lore.kernel.org/rust-for-linux/20250504042436.237756-1-fujita.tomonori@gmail.com/
- removed most of changes to hrtimer code 
v1: https://lore.kernel.org/rust-for-linux/20250413105629.162349-1-fujita.tomonori@gmail.com/


FUJITA Tomonori (3):
  rust: time: Replace ClockId enum with ClockSource trait
  rust: time: Make Instant generic over ClockSource
  rust: time: Add ktime_get() to ClockSource trait

 rust/helpers/helpers.c      |   1 +
 rust/helpers/time.c         |  18 ++++
 rust/kernel/time.rs         | 201 ++++++++++++++++++++++--------------
 rust/kernel/time/hrtimer.rs |   6 +-
 4 files changed, 148 insertions(+), 78 deletions(-)
 create mode 100644 rust/helpers/time.c


base-commit: 19272b37aa4f83ca52bdf9c16d5d81bdd1354494
-- 
2.43.0
Re: [PATCH v4 0/3] rust: time: Introduce typed clock sources and generalize Instant
Posted by Andreas Hindborg 3 months, 3 weeks ago
On Tue, 10 Jun 2025 18:32:53 +0900, FUJITA Tomonori wrote:
> This patch series introduces a type-safe abstraction over clock
> sources. The goal is to remove the need for runtime clock selection
> (via ClockId) and instead leverage Rust's type system to statically
> associate the Instant type with a specific clock.
> 
> This approach enables compile-time enforcement of clock correctness
> across the APIs of Instant type.
> 
> [...]

Applied, thanks!

[1/3] rust: time: Replace ClockId enum with ClockSource trait
      commit: 1664a671be46a0b0daf5250eb124d94a5501a64c
[2/3] rust: time: Make Instant generic over ClockSource
      commit: 768dfbfc98e26cfad45f7165a1801d188f3cbd81
[3/3] rust: time: Add ktime_get() to ClockSource trait
      commit: cc6d1098b4cca6ec8e659de8361457c59a90b583

Best regards,
-- 
Andreas Hindborg <a.hindborg@kernel.org>