CI results indicate excessive time spent on processing of wait_backward selftest. The test case enables signaling on each link of a 4096 links long chain, then signals those links one after another in reverse order. That scanario corresponds to user space potentially building a dma_fence chain of an arbitrary length step by step, e.g. via drm_syncobj IOCTLs, and each step waiting on a chain link it has added.
When first user starts waiting on a not yet signaled fence of a chain link, or signaling is explicitly enabled on it, a dma_fence_chain callback is added to a user fence of that link. When the user fence of that chain link is then signaled, the chain is traversed in search for a first not signaled link and the callback is rearmed on a user fence of that link. Each time an arbitrary user fence is signaled, all dma_fence_chain callbacks added to it so far must be rearmed to another user fence of the chain. In extreme scenarios, when all N links of a chain are awaited and then signaled in reverse order, the dma_fence_chain callback may be called up to N * (N + 1) / 2 times (an arithmetic series). To avoid that potential excessive accumulation of dma_fence_chain callbacks, rearm a trimmed-down, signal only callback version to the base fence of a previous link, if not yet signaled, otherwise just signal the base fence of the current link instead of traversing the chain in search for a first not signaled link and moving all callbacks collected so far to a user fence of that link. For more clear correspondence to a potential userspace scenario, update the wait_* selftests so they actually wait on each link fence of the chain instead of just enabling signaling. For easy evaluation of the change impact, report processing time of signaling loop of each wait_* test case. Janusz Krzysztofik (4): dma-buf/fence-chain: Report time spent in wait_* test cases dma-buf/fence-chain: Let test cases decide which fence to wait on dma-buf/fence-chain: Wait on each tested chain link dma-buf/fence-chain: Speed up processing of rearmed callbacks drivers/dma-buf/dma-fence-chain.c | 101 ++++++++++++++++---- drivers/dma-buf/st-dma-fence-chain.c | 133 +++++++++++++++++++++------ 2 files changed, 189 insertions(+), 45 deletions(-) -- 2.50.1