// SPDX-License-Identifier: GPL-2.0-only /* * fence-chain: chain fences together in a timeline * * Copyright (C) 2018 Advanced Micro Devices, Inc. * Authors: * Christian König <christian.koenig@amd.com>
*/
/** * dma_fence_chain_get_prev - use RCU to get a reference to the previous fence * @chain: chain node to get the previous node from * * Use dma_fence_get_rcu_safe to get a reference to the previous fence of the * chain node.
*/ staticstruct dma_fence *dma_fence_chain_get_prev(struct dma_fence_chain *chain)
{ struct dma_fence *prev;
/** * dma_fence_chain_walk - chain walking function * @fence: current chain node * * Walk the chain to the next node. Returns the next fence or NULL if we are at * the end of the chain. Garbage collects chain nodes which are already * signaled.
*/ struct dma_fence *dma_fence_chain_walk(struct dma_fence *fence)
{ struct dma_fence_chain *chain, *prev_chain; struct dma_fence *prev, *replacement, *tmp;
chain = to_dma_fence_chain(fence); if (!chain) {
dma_fence_put(fence); return NULL;
}
while ((prev = dma_fence_chain_get_prev(chain))) {
prev_chain = to_dma_fence_chain(prev); if (prev_chain) { if (!dma_fence_is_signaled(prev_chain->fence)) break;
replacement = dma_fence_chain_get_prev(prev_chain);
} else { if (!dma_fence_is_signaled(prev)) break;
/** * dma_fence_chain_find_seqno - find fence chain node by seqno * @pfence: pointer to the chain node where to start * @seqno: the sequence number to search for * * Advance the fence pointer to the chain node which will signal this sequence * number. If no sequence number is provided then this is a no-op. * * Returns EINVAL if the fence is not a chain node or the sequence number has * not yet advanced far enough.
*/ int dma_fence_chain_find_seqno(struct dma_fence **pfence, uint64_t seqno)
{ struct dma_fence_chain *chain;
/* Try to rearm the callback */ if (!dma_fence_chain_enable_signaling(&chain->base)) /* Ok, we are done. No more unsignaled fences left */
dma_fence_signal(&chain->base);
dma_fence_put(&chain->base);
}
/* Manually unlink the chain as much as possible to avoid recursion * and potential stack overflow.
*/ while ((prev = rcu_dereference_protected(chain->prev, true))) { struct dma_fence_chain *prev_chain;
if (kref_read(&prev->refcount) > 1) break;
prev_chain = to_dma_fence_chain(prev); if (!prev_chain) break;
/* No need for atomic operations since we hold the last * reference to prev_chain.
*/
chain->prev = prev_chain->prev;
RCU_INIT_POINTER(prev_chain->prev, NULL);
dma_fence_put(prev);
}
dma_fence_put(prev);
/** * dma_fence_chain_init - initialize a fence chain * @chain: the chain node to initialize * @prev: the previous fence * @fence: the current fence * @seqno: the sequence number to use for the fence chain * * Initialize a new chain node and either start a new chain or add the node to * the existing chain of the previous fence.
*/ void dma_fence_chain_init(struct dma_fence_chain *chain, struct dma_fence *prev, struct dma_fence *fence,
uint64_t seqno)
{ struct dma_fence_chain *prev_chain = to_dma_fence_chain(prev);
uint64_t context;
/* Try to reuse the context of the previous chain node. */ if (prev_chain && __dma_fence_is_later(prev, seqno, prev->seqno)) {
context = prev->context;
chain->prev_seqno = prev->seqno;
} else {
context = dma_fence_context_alloc(1); /* Make sure that we always have a valid sequence number. */ if (prev_chain)
seqno = max(prev->seqno, seqno);
}
/* * Chaining dma_fence_chain container together is only allowed through * the prev fence and not through the contained fence. * * The correct way of handling this is to flatten out the fence * structure into a dma_fence_array by the caller instead.
*/
WARN_ON(dma_fence_is_chain(fence));
}
EXPORT_SYMBOL(dma_fence_chain_init);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.