[PATCH v6-S1 3/6] dma/dpaa2: use memcpy to fill completion index ring

Prashant Gupta prashant.gupta_3 at nxp.com
Tue Oct 6 17:07:46 CEST 2026


From: Jun Yang <jun.yang at nxp.com>

qdma_cntx_idx_ring_eq() copied the completion indices into the ring one
element at a time, masking the tail against DPAA2_QDMA_MAX_DESC on every
iteration. The number of elements and the available free space are both
known on entry, so the per-element masking is avoidable work in the
dequeue path.

Replace the loop with at most two memcpy() calls, one for the region up
to the end of the ring and one for the wrapped remainder, and advance
ring->tail by the full count once.

No functional change.

Signed-off-by: Jun Yang <jun.yang at nxp.com>
Signed-off-by: Prashant Gupta <prashant.gupta_3 at nxp.com>
---
 drivers/dma/dpaa2/dpaa2_qdma.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/drivers/dma/dpaa2/dpaa2_qdma.c b/drivers/dma/dpaa2/dpaa2_qdma.c
index f7d94bb799..7d3f3d2003 100644
--- a/drivers/dma/dpaa2/dpaa2_qdma.c
+++ b/drivers/dma/dpaa2/dpaa2_qdma.c
@@ -66,16 +66,19 @@ qdma_cntx_idx_ring_eq(struct qdma_cntx_idx_ring *ring,
 	const uint16_t *elem, uint16_t nb,
 	uint16_t *free_space)
 {
-	uint16_t i;
+	uint16_t first;
 
 	if (unlikely(nb > ring->free_space))
 		return 0;
 
-	for (i = 0; i < nb; i++) {
-		ring->cntx_idx_ring[ring->tail] = elem[i];
-		ring->tail = (ring->tail + 1) &
-			(DPAA2_QDMA_MAX_DESC - 1);
-	}
+	first = RTE_MIN(nb, (uint16_t)(DPAA2_QDMA_MAX_DESC - ring->tail));
+	memcpy(&ring->cntx_idx_ring[ring->tail], elem,
+		first * sizeof(uint16_t));
+	if (nb > first)
+		memcpy(&ring->cntx_idx_ring[0], &elem[first],
+			(nb - first) * sizeof(uint16_t));
+
+	ring->tail = (ring->tail + nb) & (DPAA2_QDMA_MAX_DESC - 1);
 	ring->free_space -= nb;
 	ring->nb_in_ring += nb;
 
-- 
2.43.0



More information about the dev mailing list