session: avoid double dispatch of new events 28/23128/6
authorFlorin Coras <fcoras@cisco.com>
Thu, 31 Oct 2019 02:22:51 +0000 (19:22 -0700)
committerDave Barach <openvpp@barachs.net>
Thu, 31 Oct 2019 16:52:24 +0000 (16:52 +0000)
Type: fix

Avoid re-dispatching new events if they've just been added to the old
events linked list.

Change-Id: Ie5d0b799eae6cebb118d97204e5111eb194c0b8e
Signed-off-by: Florin Coras <fcoras@cisco.com>
src/vnet/session/session_node.c

index 4f0251b..b4b384f 100644 (file)
@@ -1293,6 +1293,8 @@ session_queue_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node,
    */
 
   new_he = pool_elt_at_index (wrk->event_elts, wrk->new_head);
+  old_he = pool_elt_at_index (wrk->event_elts, wrk->old_head);
+  old_ti = clib_llist_prev_index (old_he, evt_list);
 
   /* *INDENT-OFF* */
   clib_llist_foreach_safe (wrk->event_elts, evt_list, new_he, elt, ({
@@ -1314,25 +1316,26 @@ session_queue_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node,
   /* *INDENT-ON* */
 
   /*
-   * Handle the old io events
+   * Handle the old io events, if we had any prior to processing the new ones
    */
 
-  old_he = pool_elt_at_index (wrk->event_elts, wrk->old_head);
-  old_ti = clib_llist_prev_index (old_he, evt_list);
-
-  while (n_tx_packets < VLIB_FRAME_SIZE
-        && !clib_llist_is_empty (wrk->event_elts, evt_list, old_he))
+  if (old_ti != wrk->old_head)
     {
-      clib_llist_index_t ei;
+      old_he = pool_elt_at_index (wrk->event_elts, wrk->old_head);
+      while (n_tx_packets < VLIB_FRAME_SIZE)
+       {
+         clib_llist_index_t ei;
 
-      clib_llist_pop_first (wrk->event_elts, evt_list, elt, old_he);
-      ei = clib_llist_entry_index (wrk->event_elts, elt);
-      session_event_dispatch_io (wrk, node, elt, thread_index, &n_tx_packets);
+         clib_llist_pop_first (wrk->event_elts, evt_list, elt, old_he);
+         ei = clib_llist_entry_index (wrk->event_elts, elt);
+         session_event_dispatch_io (wrk, node, elt, thread_index,
+                                    &n_tx_packets);
 
-      old_he = pool_elt_at_index (wrk->event_elts, wrk->old_head);
-      if (ei == old_ti)
-       break;
-    };
+         old_he = pool_elt_at_index (wrk->event_elts, wrk->old_head);
+         if (ei == old_ti)
+           break;
+       };
+    }
 
   if (vec_len (wrk->pending_tx_buffers))
     session_flush_pending_tx_buffers (wrk, node);