memif: fix the default txq placement
[vpp.git] / src / plugins / memif / memif.c
index 6bfb7b3..31dd4a5 100644 (file)
 
 #include <vlib/vlib.h>
 #include <vlib/unix/unix.h>
-#include <vppinfra/linux/syscall.h>
 #include <vnet/plugin/plugin.h>
 #include <vnet/ethernet/ethernet.h>
 #include <vnet/interface/rx_queue_funcs.h>
+#include <vnet/interface/tx_queue_funcs.h>
 #include <vpp/app/version.h>
 #include <memif/memif.h>
 #include <memif/private.h>
@@ -147,7 +147,6 @@ memif_disconnect (memif_if_t * mif, clib_error_t * err)
        }
     }
   vnet_hw_if_unregister_all_rx_queues (vnm, mif->hw_if_index);
-  vnet_hw_if_update_runtime_data (vnm, mif->hw_if_index);
 
   /* *INDENT-OFF* */
   vec_foreach_index (i, mif->tx_queues)
@@ -159,9 +158,12 @@ memif_disconnect (memif_if_t * mif, clib_error_t * err)
       {
         memif_disconnect_free_zc_queue_buffer(mq, 0);
       }
+      clib_spinlock_free (&mq->lockp);
     }
     mq->ring = 0;
   }
+  vnet_hw_if_unregister_all_tx_queues (vnm, mif->hw_if_index);
+  vnet_hw_if_update_runtime_data (vnm, mif->hw_if_index);
 
   /* free tx and rx queues */
   vec_foreach (mq, mif->rx_queues)
@@ -233,7 +235,8 @@ memif_connect (memif_if_t * mif)
   vnet_main_t *vnm = vnet_get_main ();
   clib_file_t template = { 0 };
   memif_region_t *mr;
-  int i;
+  int i, j;
+  u32 n_txqs, n_threads = vlib_get_n_threads ();
   clib_error_t *err = NULL;
 
   memif_log_debug (mif, "connect %u", mif->dev_instance);
@@ -276,6 +279,16 @@ memif_connect (memif_if_t * mif)
          err = clib_error_return (0, "wrong cookie on tx ring %u", i);
          goto error;
        }
+      mq->queue_index =
+       vnet_hw_if_register_tx_queue (vnm, mif->hw_if_index, i);
+      clib_spinlock_init (&mq->lockp);
+    }
+
+  n_txqs = vec_len (mif->tx_queues);
+  for (j = 0; j < n_threads; j++)
+    {
+      u32 qi = mif->tx_queues[j % n_txqs].queue_index;
+      vnet_hw_if_tx_queue_assign_thread (vnm, qi, j);
     }
 
   vec_foreach_index (i, mif->rx_queues)
@@ -306,8 +319,8 @@ memif_connect (memif_if_t * mif)
                                              mq->int_clib_file_index);
        }
       ti = vnet_hw_if_get_rx_queue_thread_index (vnm, qi);
-      mq->buffer_pool_index =
-       vlib_buffer_pool_get_default_for_numa (vm, vlib_mains[ti]->numa_node);
+      mq->buffer_pool_index = vlib_buffer_pool_get_default_for_numa (
+       vm, vlib_get_main_by_index (ti)->numa_node);
       rv = vnet_hw_if_set_rx_queue_mode (vnm, qi, VNET_HW_IF_RX_MODE_DEFAULT);
       vnet_hw_if_update_runtime_data (vnm, mif->hw_if_index);
 
@@ -471,6 +484,7 @@ memif_init_regions_and_queues (memif_if_t * mif)
          err = clib_error_return_unix (0, "eventfd[tx queue %u]", i);
          goto error;
        }
+
       mq->int_clib_file_index = ~0;
       mq->ring = memif_get_ring (mif, MEMIF_RING_S2M, i);
       mq->log2_ring_size = mif->cfg.log2_ring_size;
@@ -584,9 +598,10 @@ memif_process (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f)
            {
               clib_memset (sock, 0, sizeof(clib_socket_t));
              sock->config = (char *) msf->filename;
-              sock->flags = CLIB_SOCKET_F_IS_CLIENT| CLIB_SOCKET_F_SEQPACKET;
+             sock->flags = CLIB_SOCKET_F_IS_CLIENT | CLIB_SOCKET_F_SEQPACKET |
+                           CLIB_SOCKET_F_BLOCKING;
 
-              if ((err = clib_socket_init (sock)))
+             if ((err = clib_socket_init (sock)))
                {
                  clib_error_free (err);
                }
@@ -797,7 +812,6 @@ memif_delete_if (vlib_main_t * vm, memif_if_t * mif)
     }
 
   /* free interface data structures */
-  clib_spinlock_free (&mif->lockp);
   mhash_unset (&msf->dev_instance_by_id, &mif->id, 0);
 
   /* remove socket file */
@@ -952,9 +966,6 @@ memif_create_if (vlib_main_t * vm, memif_create_if_args_t * args)
   if (args->secret)
     mif->secret = vec_dup (args->secret);
 
-  if (tm->n_vlib_mains > 1)
-    clib_spinlock_init (&mif->lockp);
-
   if (mif->mode == MEMIF_INTERFACE_MODE_ETHERNET)
     {
 
@@ -1048,7 +1059,7 @@ memif_create_if (vlib_main_t * vm, memif_create_if_args_t * args)
     }
 
   hw = vnet_get_hw_interface (vnm, mif->hw_if_index);
-  hw->flags |= VNET_HW_INTERFACE_FLAG_SUPPORTS_INT_MODE;
+  hw->caps |= VNET_HW_INTERFACE_CAP_SUPPORTS_INT_MODE;
   vnet_hw_if_set_input_node (vnm, mif->hw_if_index, memif_input_node.index);
   mhash_set (&msf->dev_instance_by_id, &mif->id, mif->dev_instance, 0);
 
@@ -1060,14 +1071,6 @@ memif_create_if (vlib_main_t * vm, memif_create_if_args_t * args)
   goto done;
 
 error:
-  if (mif->hw_if_index != ~0)
-    {
-      if (mif->mode == MEMIF_INTERFACE_MODE_IP)
-       vnet_delete_hw_interface (vnm, mif->hw_if_index);
-      else
-       ethernet_delete_interface (vnm, mif->hw_if_index);
-      mif->hw_if_index = ~0;
-    }
   memif_delete_if (vm, mif);
   if (error)
     {
@@ -1089,7 +1092,14 @@ memif_interface_admin_up_down (vnet_main_t *vnm, u32 hw_if_index, u32 flags)
   static clib_error_t *error = 0;
 
   if (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP)
-    mif->flags |= MEMIF_IF_FLAG_ADMIN_UP;
+    {
+      if (mif->flags & MEMIF_IF_FLAG_CONNECTED)
+       {
+         vnet_hw_interface_set_flags (vnm, mif->hw_if_index,
+                                      VNET_HW_INTERFACE_FLAG_LINK_UP);
+       }
+      mif->flags |= MEMIF_IF_FLAG_ADMIN_UP;
+    }
   else
     mif->flags &= ~MEMIF_IF_FLAG_ADMIN_UP;