Re: [PATCH 2/6] rust: hrtimer: Add HrTimerCallbackContext and ::forward()

Thomas Gleixner
2025-04-03T11:25:14Z

On Wed, Apr 02 2025 at 17:40, Lyude Paul wrote:

> With Linux's hrtimer API, certain functions require we either acquire
> proper locking to call specific methods - or that we call said methods from
> the context of the timer callback. hrtimer_forward() is one of these
> functions, so we start by adding a new HrTimerCallbackContext type which
> provides a way of calling these methods that is inaccessible outside of
> hrtimer callbacks.

Just for completeness:

When hrtimer_forward() is invoked from non-callback context, then there
is not necessarily a locking requirement. The caller has to make sure
that the timer is neither armed, nor running the callback.

hrtimer_cancel();
hrtimer_forward();

is a legitimate sequence, if there is no way that the timer is re-armed
concurrently. That works just without locks.

That said, I really like that callback context concept you are doing!

Thanks,

tglx