Fix MP hazard in interrupt node scheduling 73/10173/3
authorDave Barach <dave@barachs.net>
Fri, 19 Jan 2018 18:09:20 +0000 (13:09 -0500)
committerFlorin Coras <florin.coras@gmail.com>
Fri, 19 Jan 2018 22:15:52 +0000 (22:15 +0000)
Change-Id: Iff14ed6ffd822eb2286aac6af467d9c8660e3d81
Signed-off-by: Dave Barach <dave@barachs.net>
src/vlib/main.c

index d32ca7b..f915aa4 100644 (file)
@@ -1514,13 +1514,19 @@ vlib_main_or_worker_loop (vlib_main_t * vm, int is_main)
 
       /* Next handle interrupts. */
       {
+       /* unlocked read, for performance */
        uword l = _vec_len (nm->pending_interrupt_node_runtime_indices);
        uword i;
-       if (l > 0)
+       if (PREDICT_FALSE (l > 0))
          {
            u32 *tmp;
            if (!is_main)
-             clib_spinlock_lock (&nm->pending_interrupt_lock);
+             {
+               clib_spinlock_lock (&nm->pending_interrupt_lock);
+               /* Re-read w/ lock held, in case another thread added an item */
+               l = _vec_len (nm->pending_interrupt_node_runtime_indices);
+             }
+
            tmp = nm->pending_interrupt_node_runtime_indices;
            nm->pending_interrupt_node_runtime_indices =
              last_node_runtime_indices;