session: avoid double dispatch of new events 55/23255/2
authorFlorin Coras <fcoras@cisco.com>
Thu, 31 Oct 2019 02:22:51 +0000 (19:22 -0700)
committerAndrew Yourtchenko <ayourtch@gmail.com>
Fri, 15 Nov 2019 07:20:32 +0000 (07:20 +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>
(cherry picked from commit 45b7973dddc9f1b50d7f20cc1abe150b2ad9931f)

src/vnet/session/session_node.c

index e8b68da..824085a 100644 (file)
@@ -1295,6 +1295,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, ({
@@ -1316,25 +1318,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;
+       };
+    }
 
   vlib_node_increment_counter (vm, session_queue_node.index,
                               SESSION_QUEUE_ERROR_TX, n_tx_packets);