net/memif: move barrier outside loop
authorHonnappa Nagarahalli <honnappa.nagarahalli@arm.com>
Mon, 28 Sep 2020 19:03:34 +0000 (14:03 -0500)
committerFerruh Yigit <ferruh.yigit@intel.com>
Fri, 16 Oct 2020 17:18:47 +0000 (19:18 +0200)
load-acquire memory order has a barrier. Loading it inside
the loop will result in a barrier in every iteration. Hence,
load the variable once outside the loop.

Signed-off-by: Honnappa Nagarahalli <honnappa.nagarahalli@arm.com>
Reviewed-by: Phil Yang <phil.yang@arm.com>
Reviewed-by: Ruifeng Wang <ruifeng.wang@arm.com>
Reviewed-by: Jakub Grajciar <jgrajcia@cisco.com>
drivers/net/memif/rte_eth_memif.c

index 68f3e60..03e0b66 100644 (file)
@@ -249,16 +249,17 @@ memif_get_buffer(struct pmd_process_private *proc_private, memif_desc_t *d)
 static void
 memif_free_stored_mbufs(struct pmd_process_private *proc_private, struct memif_queue *mq)
 {
+       uint16_t cur_tail;
        uint16_t mask = (1 << mq->log2_ring_size) - 1;
        memif_ring_t *ring = memif_get_ring_from_queue(proc_private, mq);
 
        /* FIXME: improve performance */
        /* The ring->tail acts as a guard variable between Tx and Rx
         * threads, so using load-acquire pairs with store-release
-        * to synchronize it between threads.
+        * in function eth_memif_rx for S2M queues.
         */
-       while (mq->last_tail != __atomic_load_n(&ring->tail,
-                                               __ATOMIC_ACQUIRE)) {
+       cur_tail = __atomic_load_n(&ring->tail, __ATOMIC_ACQUIRE);
+       while (mq->last_tail != cur_tail) {
                RTE_MBUF_PREFETCH_TO_FREE(mq->buffers[(mq->last_tail + 1) & mask]);
                /* Decrement refcnt and free mbuf. (current segment) */
                rte_mbuf_refcnt_update(mq->buffers[mq->last_tail & mask], -1);