Skip to contentSkip to conversation

rust: time: Pass correct timer mode ID to hrtimer_start_range_ns

PATCH In review Lyude Paul 4 participants 7 messages Jul 10, 2025 – Jul 17, 2025

Subsystems (2)
lore
Share & tools
lore

Lyude Paul

author reviewer
#0 lore raw

PATCH 1/1 rust: time: Pass correct timer mode ID to hrtimer_start_range_ns

While rebasing rvkms I noticed that timers I was setting seemed to have pretty random timer values that amounted slightly over 2x the time value I set each time. After a lot of debugging, I finally managed to figure out
why: it seems that since we moved to Instant and Delta, we mistakenly began passing the clocksource ID to hrtimer_start_range_ns, when we should be passing the timer mode instead. Presumably, this works fine for simple relative timers - but immediately breaks on other types of timers.

So, fix this by passing the ID for the timer mode instead.

Cc FUJITA Tomonori <[email protected]>
Fixes fcc1dd8c8656 ("rust: time: Make HasHrTimer generic over HrTimerMode")
---
 rust/kernel/time/hrtimer.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
rust/kernel/time/hrtimer.rs +1 -1
index 8818775afaf69..e227fa95ab05c 100644
@@ -398,7 +398,7 @@ unsafe fn start(this: *const Self, expires: <Self::TimerMode as HrTimerMode>::Ex
                 Self::c_timer_ptr(this).cast_mut(),
                 expires.as_nanos(),
                 0,
-                <Self::TimerMode as HrTimerMode>::Clock::ID as u32,
+                <Self::TimerMode as HrTimerMode>::C_MODE as u32
             );
         }
     }

base-commit: d4b29ddf82a458935f1bd4909b8a7a13df9d3bdc

Signature · 1 line
2.50.0
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · Lyude Paul

While rebasing rvkms I noticed that timers I was setting seemed to have pretty random timer values that amounted slightly over 2x the time value I set each time. After a lot of debugging, I finally managed to figure out
why: it seems that since we moved to Instant and Delta, we mistakenly began passing the clocksource ID to hrtimer_start_range_ns, when we should be passing the timer mode instead. Presumably, this works fine for simple relative timers - but immediately breaks on other types of timers.

Quoted 5 lines

So, fix this by passing the ID for the timer mode instead.

Cc FUJITA Tomonori <[email protected]>
Fixes fcc1dd8c8656 ("rust: time: Make HasHrTimer generic over HrTimerMode")

Wow, thanks! Miguel, can you take this through rust-fixes?

Best regards,
Andreas Hindborg

#2 lore raw
Quoted 10 lines · On Fri, 11 Jul 2025 08:18:37 +0200 Andreas Hindborg <[email protected]>…
Quoted 8 lines · Lyude Paul

While rebasing rvkms I noticed that timers I was setting seemed to have pretty random timer values that amounted slightly over 2x the time value I set each time. After a lot of debugging, I finally managed to figure out
why: it seems that since we moved to Instant and Delta, we mistakenly began passing the clocksource ID to hrtimer_start_range_ns, when we should be passing the timer mode instead. Presumably, this works fine for simple relative timers - but immediately breaks on other types of timers.

Quoted 7 lines
Quoted 5 lines

So, fix this by passing the ID for the timer mode instead.

Cc FUJITA Tomonori <[email protected]>
Fixes fcc1dd8c8656 ("rust: time: Make HasHrTimer generic over HrTimerMode")

Wow, thanks! Miguel, can you take this through rust-fixes?

I think that this patch fixes the commit in timekeeping-next.

fcc1dd8c8656 doesn't match to the commit in the current timekeeping-next (this patch might have been made against the tree before it was rebased).

maintainer
#3 lore raw
Quoted 19 lines · FUJITA Tomonori
Quoted 16 lines · On Fri, 11 Jul 2025 08:18:37 +0200 Andreas Hindborg <[email protected]>…
Quoted 13 lines · Lyude Paul

While rebasing rvkms I noticed that timers I was setting seemed to have pretty random timer values that amounted slightly over 2x the time value I set each time. After a lot of debugging, I finally managed to figure out
why: it seems that since we moved to Instant and Delta, we mistakenly began passing the clocksource ID to hrtimer_start_range_ns, when we should be passing the timer mode instead. Presumably, this works fine for simple relative timers - but immediately breaks on other types of timers.

So, fix this by passing the ID for the timer mode instead.

Cc FUJITA Tomonori <[email protected]>
Fixes fcc1dd8c8656 ("rust: time: Make HasHrTimer generic over HrTimerMode")
Quoted 7 lines
Quoted 1 line

Wow, thanks! Miguel, can you take this through rust-fixes?

I think that this patch fixes the commit in timekeeping-next.

fcc1dd8c8656 doesn't match to the commit in the current timekeeping-next (this patch might have been made against the tree before it was rebased).

Maybe Miguel can put the correct hash when he applies the patch.

Best regards,
Andreas Hindborg

#4 lore raw
Quoted 2 lines · Andreas Hindborg

Maybe Miguel can put the correct hash when he applies the patch.

Sure:

Fixes e0c0ab04f678 ("rust: time: Make HasHrTimer generic over HrTimerMode")

Cheers,
Miguel

reviewer Reviewed-by on v1 1/1
#5 lore raw
In reply to Lyude Paul
Quoted 8 lines · On Thu, 10 Jul 2025 18:51:13 -0400 Lyude Paul <[email protected]> wrote:

While rebasing rvkms I noticed that timers I was setting seemed to have pretty random timer values that amounted slightly over 2x the time value I set each time. After a lot of debugging, I finally managed to figure out
why: it seems that since we moved to Instant and Delta, we mistakenly began passing the clocksource ID to hrtimer_start_range_ns, when we should be passing the timer mode instead. Presumably, this works fine for simple relative timers - but immediately breaks on other types of timers.

Quoted 8 lines

So, fix this by passing the ID for the timer mode instead.

Cc FUJITA Tomonori <[email protected]>
Fixes fcc1dd8c8656 ("rust: time: Make HasHrTimer generic over HrTimerMode")
---
 rust/kernel/time/hrtimer.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Ah, my bad! Thanks a lot for the fix.

#6 lore raw
In reply to Lyude Paul
Quoted 9 lines · Lyude Paul

While rebasing rvkms I noticed that timers I was setting seemed to have pretty random timer values that amounted slightly over 2x the time value I set each time. After a lot of debugging, I finally managed to figure out
why: it seems that since we moved to Instant and Delta, we mistakenly began passing the clocksource ID to hrtimer_start_range_ns, when we should be passing the timer mode instead. Presumably, this works fine for simple relative timers - but immediately breaks on other types of timers.

Quoted 5 lines

So, fix this by passing the ID for the timer mode instead.

Cc FUJITA Tomonori <[email protected]>
Fixes fcc1dd8c8656 ("rust: time: Make HasHrTimer generic over HrTimerMode")

Applied to rust-next (on top of the timekeeping merge) -- thanks everyone!

[ Removed cast, applied rustfmt, fixed Fixes: tag. - Miguel ]

I assume the cast was there just because the original line (Clock::ID) had it.

Cheers,
Miguel