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

Andreas Hindborg
2025-11-05T12:46:06Z

Lyude Paul <lyude@redhat.com> writes:

> From: Boqun Feng <boqun.feng@gmail.com>
>
> `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@gmail.com>
> Co-developed-by: Lyude Paul <lyude@redhat.com>
> Signed-off-by: Lyude Paul <lyude@redhat.com>

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