vlib: fix trace number accounting
[vpp.git] / src / plugins / avf / input.c
index 8d1ded8..4e4f116 100644 (file)
@@ -125,8 +125,7 @@ avf_rxq_refill (vlib_main_t * vm, vlib_node_runtime_t * node, avf_rxq_t * rxq,
       n_alloc -= 8;
     }
 
-  CLIB_MEMORY_STORE_BARRIER ();
-  *(rxq->qrx_tail) = slot;
+  clib_atomic_store_rel_n (rxq->qrx_tail, slot);
 }
 
 
@@ -364,12 +363,6 @@ no_more_desc:
   or_qw1 |= or_q1x4[0] | or_q1x4[1] | or_q1x4[2] | or_q1x4[3];
 #endif
 
-  /* refill rx ring */
-  if (ad->flags & AVF_DEVICE_F_VA_DMA)
-    avf_rxq_refill (vm, node, rxq, 1 /* use_va_dma */ );
-  else
-    avf_rxq_refill (vm, node, rxq, 0 /* use_va_dma */ );
-
   vlib_get_buffers (vm, to_next, ptd->bufs, n_rx_packets);
 
   vnet_buffer (bt)->sw_if_index[VLIB_RX] = ad->sw_if_index;
@@ -390,20 +383,24 @@ no_more_desc:
 
       while (n_trace && n_left)
        {
-         vlib_buffer_t *b;
-         avf_input_trace_t *tr;
-         b = vlib_get_buffer (vm, bi[0]);
-         vlib_trace_buffer (vm, node, next_index, b, /* follow_chain */ 0);
-         tr = vlib_add_trace (vm, node, b, sizeof (*tr));
-         tr->next_index = next_index;
-         tr->qid = qid;
-         tr->hw_if_index = ad->hw_if_index;
-         tr->qw1s[0] = ptd->qw1s[i];
-         for (j = 1; j < AVF_RX_MAX_DESC_IN_CHAIN; j++)
-           tr->qw1s[j] = ptd->tails[i].qw1s[j - 1];
+         vlib_buffer_t *b = vlib_get_buffer (vm, bi[0]);
+         if (PREDICT_TRUE
+             (vlib_trace_buffer
+              (vm, node, next_index, b, /* follow_chain */ 0)))
+           {
+             avf_input_trace_t *tr =
+               vlib_add_trace (vm, node, b, sizeof (*tr));
+             tr->next_index = next_index;
+             tr->qid = qid;
+             tr->hw_if_index = ad->hw_if_index;
+             tr->qw1s[0] = ptd->qw1s[i];
+             for (j = 1; j < AVF_RX_MAX_DESC_IN_CHAIN; j++)
+               tr->qw1s[j] = ptd->tails[i].qw1s[j - 1];
+
+             n_trace--;
+           }
 
          /* next */
-         n_trace--;
          n_left--;
          bi++;
          i++;
@@ -437,6 +434,12 @@ no_more_desc:
                                   ad->hw_if_index, n_rx_packets, n_rx_bytes);
 
 done:
+  /* refill rx ring */
+  if (ad->flags & AVF_DEVICE_F_VA_DMA)
+    avf_rxq_refill (vm, node, rxq, 1 /* use_va_dma */ );
+  else
+    avf_rxq_refill (vm, node, rxq, 0 /* use_va_dma */ );
+
   return n_rx_packets;
 }
 
@@ -444,14 +447,13 @@ VLIB_NODE_FN (avf_input_node) (vlib_main_t * vm, vlib_node_runtime_t * node,
                               vlib_frame_t * frame)
 {
   u32 n_rx = 0;
-  avf_main_t *am = &avf_main;
   vnet_device_input_runtime_t *rt = (void *) node->runtime_data;
   vnet_device_and_queue_t *dq;
 
   foreach_device_and_queue (dq, rt->devices_and_queues)
   {
     avf_device_t *ad;
-    ad = vec_elt_at_index (am->devices, dq->dev_instance);
+    ad = avf_get_device (dq->dev_instance);
     if ((ad->flags & AVF_DEVICE_F_ADMIN_UP) == 0)
       continue;
     n_rx += avf_device_input_inline (vm, node, frame, ad, dq->queue_id);