Re: [PATCH v5 05/14] rust: hrtimer: allow timer restart from timer handler

From: Andreas Hindborg
Date: Thu Jan 09 2025 - 08:20:22 EST


"Guangbo Cui" <2407018371@xxxxxx> writes:

> On Tue, Dec 17, 2024 at 04:17:36PM +0100, Andreas Hindborg wrote:
>> This patch allows timer handlers to report that they want a timer to be
>> restarted after the timer handler has finished executing.
>>
>> Also update the `hrtimer` documentation to showcase the new feature.
>>
>> Signed-off-by: Andreas Hindborg <a.hindborg@xxxxxxxxxx>
>> ---
>> rust/kernel/time/hrtimer.rs | 37 ++++++++++++++++++++++++++++++++++++-
>> rust/kernel/time/hrtimer/arc.rs | 4 +---
>> 2 files changed, 37 insertions(+), 4 deletions(-)
>>
>> diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs
>> index 178e33c1f656d2f834e45b004486f6e5fe1813dd..38a8251ea6ba4d84dadad009ed540c150bea4775 100644
>> --- a/rust/kernel/time/hrtimer.rs
>> +++ b/rust/kernel/time/hrtimer.rs
>> @@ -167,7 +167,7 @@ pub trait TimerCallback {
>> type CallbackTargetParameter<'a>;
>>
>> /// Called by the timer logic when the timer fires.
>> - fn run(this: Self::CallbackTargetParameter<'_>)
>> + fn run(this: Self::CallbackTargetParameter<'_>) -> TimerRestart
>> where
>> Self: Sized;
>> }
>> @@ -262,6 +262,41 @@ unsafe fn start(self_ptr: *const Self, expires: Ktime) {
>> }
>> }
>>
>> +/// Restart policy for timers.
>> +pub enum TimerRestart {
>> + /// Timer should not be restarted.
>> + NoRestart,
>> + /// Timer should be restarted.
>> + Restart,
>> +}
>
> If we restart the timer, we may also want to `forward` the timer. I tried
> this series, and wrote some samples, found that it's inconvenient to write
> a loop timer.
>
> This is not a problem, just my feedback on the user experience.

Thanks! Lyude Paul has some patches that adds methods that operate
within timer context, including forwarding. I think they will send them
after this lands.


Best regards,
Andreas Hindborg