Re: [PATCH v13 11/17] rust: sync: lock: Add `Backend::BackendInContext`

From: Andreas Hindborg

Date: Wed Nov 05 2025 - 07:46:06 EST


Lyude Paul <lyude@xxxxxxxxxx> writes:

> From: Boqun Feng <boqun.feng@xxxxxxxxx>
>
> `SpinLock`'s backend can be used for `SpinLockIrq`, if the interrupts are
> disabled. And it actually provides performance gains since interrupts are
> not needed to be disabled anymore. So add `Backend::BackendInContext` to
> describe the case where one backend can be used for another. Use it to
> implement the `lock_with()` so that `SpinLockIrq` can avoid disabling
> interrupts by using `SpinLock`'s backend.
>
> Signed-off-by: Boqun Feng <boqun.feng@xxxxxxxxx>
> Co-developed-by: Lyude Paul <lyude@xxxxxxxxxx>
> Signed-off-by: Lyude Paul <lyude@xxxxxxxxxx>

I am not convinced this makes sense. This saves us only a few
instructions. We already have a counter on C side, so we are not going
to update the interrupt control register if we don't need to.

I'd like to see a micro benchmark showcasing the gains that we get from
this complexity.


Best regards,
Andreas Hindborg