Commit c891b99d authored by Philipp Stanner's avatar Philipp Stanner
Browse files

dma-buf/dma-fence: Add dma_fence_check_and_signal()



The overwhelming majority of users of dma_fence signaling functions
don't care about whether the fence had already been signaled by someone
else. Therefore, the return code shall be removed from those functions.

For the few users who rely on the check, a new, specialized function
shall be provided.

Add dma_fence_check_and_signal(), which signals a fence if it had not
yet been signaled, and informs the user about that.

Add a counter part, dma_fence_check_and_signal_locked(), which doesn't
take the spinlock.

Reviewed-by: default avatarChristian König <christian.koenig@amd.com>
Signed-off-by: default avatarPhilipp Stanner <phasta@kernel.org>
Link: https://patch.msgid.link/20251201105011.19386-4-phasta@kernel.org
parent e58b4dea
Loading
Loading
Loading
Loading
+44 −0
Original line number Diff line number Diff line
@@ -443,6 +443,50 @@ int dma_fence_signal_locked(struct dma_fence *fence)
}
EXPORT_SYMBOL(dma_fence_signal_locked);

/**
 * dma_fence_check_and_signal_locked - signal the fence if it's not yet signaled
 * @fence: the fence to check and signal
 *
 * Checks whether a fence was signaled and signals it if it was not yet signaled.
 *
 * Unlike dma_fence_check_and_signal(), this function must be called with
 * &struct dma_fence.lock being held.
 *
 * Return: true if fence has been signaled already, false otherwise.
 */
bool dma_fence_check_and_signal_locked(struct dma_fence *fence)
{
	bool ret;

	ret = dma_fence_test_signaled_flag(fence);
	dma_fence_signal_locked(fence);

	return ret;
}
EXPORT_SYMBOL(dma_fence_check_and_signal_locked);

/**
 * dma_fence_check_and_signal - signal the fence if it's not yet signaled
 * @fence: the fence to check and signal
 *
 * Checks whether a fence was signaled and signals it if it was not yet signaled.
 * All this is done in a race-free manner.
 *
 * Return: true if fence has been signaled already, false otherwise.
 */
bool dma_fence_check_and_signal(struct dma_fence *fence)
{
	unsigned long flags;
	bool ret;

	spin_lock_irqsave(fence->lock, flags);
	ret = dma_fence_check_and_signal_locked(fence);
	spin_unlock_irqrestore(fence->lock, flags);

	return ret;
}
EXPORT_SYMBOL(dma_fence_check_and_signal);

/**
 * dma_fence_signal - signal completion of a fence
 * @fence: the fence to signal
+2 −0
Original line number Diff line number Diff line
@@ -365,6 +365,8 @@ static inline void __dma_fence_might_wait(void) {}
#endif

int dma_fence_signal(struct dma_fence *fence);
bool dma_fence_check_and_signal(struct dma_fence *fence);
bool dma_fence_check_and_signal_locked(struct dma_fence *fence);
int dma_fence_signal_locked(struct dma_fence *fence);
int dma_fence_signal_timestamp(struct dma_fence *fence, ktime_t timestamp);
int dma_fence_signal_timestamp_locked(struct dma_fence *fence,