On Fri, 2025-10-31 at 14:16 +0100, Christian König wrote:
> Allow implementations to not give a spinlock to protect the fence
> internal state, instead a spinlock embedded into the fence structure
> itself is used in this case.
I'd rather say sth like "Implement per-fence spinlocks. Shared
spinlocks have the problem that […]"
>
> Apart from simplifying the handling for containers and the stub fence
> this has the advantage of allowing implementations to issue fences
> without caring about theit spinlock lifetime.
s/theit/their.
But rather "it allows for completely decoupling spinlock producer and
consumer life times"
>
> That in turn is necessary for independent fences who outlive the module
> who originally issued them.
s/who/which
>
>
[…]
>
> enum dma_fence_flag_bits {
> + DMA_FENCE_FLAG_INLINE_LOCK_BIT,
> DMA_FENCE_FLAG_SEQNO64_BIT,
> DMA_FENCE_FLAG_SIGNALED_BIT,
> DMA_FENCE_FLAG_TIMESTAMP_BIT,
> @@ -351,6 +357,38 @@ dma_fence_get_rcu_safe(struct dma_fence __rcu **fencep)
> } while (1);
> }
>
> +/**
> + * dma_fence_spinlock - return pointer to the spinlock protecting the fence
> + * @fence: the fence to get the lock from
> + *
> + * Return either the pointer to the embedded or the external spin lock.
> + */
> +static inline spinlock_t *dma_fence_spinlock(struct dma_fence *fence)
> +{
> + return test_bit(DMA_FENCE_FLAG_INLINE_LOCK_BIT, &fence->flags) ?
> + &fence->inline_lock : fence->extern_lock;
Wouldn't you agree that an 'if' is much more readable? I prefer using
the ternary operator only for tiny operations.
if test_bit(…)
return &fence->inline_lock;
return fence->extern_lock;
Besides, I agree with the idea and I think I actually need a feature like that
in dma_fence.
P.