Move odp_packet_main structure to shared memory. 05/8005/9
authorMichal Mazur <[email protected]>
Fri, 11 Aug 2017 18:40:47 +0000 (20:40 +0200)
committerMichal Mazur <[email protected]>
Thu, 14 Dec 2017 14:18:05 +0000 (15:18 +0100)
This structure contains data shared among multiple threads and
must be globally accessible.

Change-Id: Ibde8222e9ed3f61561f7902750a1716da5c0bd81
Signed-off-by: Michal Mazur <[email protected]>
src/plugins/odp/buffer.c
src/plugins/odp/device.c
src/plugins/odp/node.c
src/plugins/odp/odp_packet.c
src/plugins/odp/odp_packet.h

index b347bba..7c410c2 100644 (file)
@@ -18,7 +18,7 @@
 u32
 odp_packet_buffer_alloc (vlib_main_t * vm, u32 * buffers, u32 n_buffers)
 {
-  odp_packet_main_t *om = &odp_packet_main;
+  odp_packet_main_t *om = odp_packet_main;
   u32 len = SHM_PKT_BUF_SIZE, total = 0;
   odp_packet_t pkt;
 
index da8f483..e904f65 100755 (executable)
@@ -36,7 +36,7 @@ static u8 *
 format_odp_packet_device_name (u8 * s, va_list * args)
 {
   u32 i = va_arg (*args, u32);
-  odp_packet_main_t *om = &odp_packet_main;
+  odp_packet_main_t *om = odp_packet_main;
   odp_packet_if_t *oif = pool_elt_at_index (om->interfaces, i);
 
   s = format (s, "odp-%s", oif->host_if_name);
@@ -62,7 +62,7 @@ odp_packet_interface_tx (vlib_main_t * vm,
                         vlib_node_runtime_t * node, vlib_frame_t * frame)
 {
 
-  odp_packet_main_t *om = &odp_packet_main;
+  odp_packet_main_t *om = odp_packet_main;
   u32 *buffers = vlib_frame_args (frame);
   u32 n_left = frame->n_vectors;
   vnet_interface_output_runtime_t *rd = (void *) node->runtime_data;
@@ -151,7 +151,7 @@ static void
 odp_packet_set_interface_next_node (vnet_main_t * vnm, u32 hw_if_index,
                                    u32 node_index)
 {
-  odp_packet_main_t *om = &odp_packet_main;
+  odp_packet_main_t *om = odp_packet_main;
   vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, hw_if_index);
   odp_packet_if_t *oif = pool_elt_at_index (om->interfaces, hw->dev_instance);
 
@@ -176,7 +176,7 @@ static clib_error_t *
 odp_packet_interface_admin_up_down (vnet_main_t * vnm, u32 hw_if_index,
                                    u32 flags)
 {
-  odp_packet_main_t *om = &odp_packet_main;
+  odp_packet_main_t *om = odp_packet_main;
   vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, hw_if_index);
   odp_packet_if_t *oif = pool_elt_at_index (om->interfaces, hw->dev_instance);
   u32 hw_flags;
index a1ebce0..bd3fb8a 100755 (executable)
@@ -255,7 +255,7 @@ odp_packet_input_fn (vlib_main_t * vm, vlib_node_runtime_t * node,
   int i;
   u32 n_rx_packets = 0;
   u32 thread_index = vlib_get_thread_index ();
-  odp_packet_main_t *om = &odp_packet_main;
+  odp_packet_main_t *om = odp_packet_main;
   odp_packet_if_t *oif;
 
   for (i = 0; i < vec_len (om->interfaces); i++)
index b7e5a8f..1ee12ff 100755 (executable)
@@ -14,6 +14,8 @@
 #include <vnet/plugin/plugin.h>
 #include <vpp/app/version.h>
 
+odp_packet_main_t *odp_packet_main;
+
 static u32
 odp_packet_eth_flag_change (vnet_main_t * vnm, vnet_hw_interface_t * hi,
                            u32 flags)
@@ -146,7 +148,7 @@ u32
 odp_packet_create_if (vlib_main_t * vm, u8 * host_if_name, u8 * hw_addr_set,
                      u32 * sw_if_index, u32 mode)
 {
-  odp_packet_main_t *om = &odp_packet_main;
+  odp_packet_main_t *om = odp_packet_main;
   int ret = 0;
   odp_packet_if_t *oif = 0;
   u8 hw_addr[6];
@@ -240,7 +242,7 @@ u32
 odp_packet_delete_if (vlib_main_t * vm, u8 * host_if_name)
 {
   vnet_main_t *vnm = vnet_get_main ();
-  odp_packet_main_t *om = &odp_packet_main;
+  odp_packet_main_t *om = odp_packet_main;
   odp_packet_if_t *oif = 0;
   uword *p;
   vlib_thread_main_t *tm = vlib_get_thread_main ();
@@ -283,7 +285,7 @@ odp_packet_delete_if (vlib_main_t * vm, u8 * host_if_name)
 static clib_error_t *
 odp_packet_init (vlib_main_t * vm)
 {
-  odp_packet_main_t *om = &odp_packet_main;
+  odp_packet_main_t *om;
   vlib_thread_main_t *tm = vlib_get_thread_main ();
   vlib_thread_registration_t *tr;
   vlib_physmem_main_t *vpm = &vm->physmem_main;
@@ -291,25 +293,37 @@ odp_packet_init (vlib_main_t * vm)
   odp_platform_init_t platform_params;
   odp_pool_param_t params;
   odp_pool_capability_t capa;
-
-  memset (om, 0, sizeof (odp_packet_main_t));
-  om->input_cpu_first_index = 0;
-  om->input_cpu_count = 1;
-  om->if_count = 0;
+  odp_shm_t shm;
+  odp_instance_t instance;
 
   memset (&platform_params, 0, sizeof (platform_params));
   platform_params.memory = 100;
 
-  if (odp_init_global (&om->instance, NULL, &platform_params))
+  if (odp_init_global (&instance, NULL, &platform_params))
     clib_warning ("Error:ODP global init failed");
 
-  if (odp_init_local (om->instance, ODP_THREAD_CONTROL) != 0)
+  if (odp_init_local (instance, ODP_THREAD_CONTROL) != 0)
     {
       clib_warning ("Error: ODP local init failed");
-      odp_term_global (om->instance);
+      odp_term_global (instance);
+
+    }
 
+  shm = odp_shm_reserve ("odp_packet_main", sizeof (odp_packet_main_t),
+                        ODP_CACHE_LINE_SIZE, 0);
+  odp_packet_main = odp_shm_addr (shm);
+  if (odp_packet_main == NULL)
+    {
+      return clib_error_return (0, "Failed to initialize odp_packet");
     }
 
+  om = odp_packet_main;
+  memset (om, 0, sizeof (odp_packet_main_t));
+  om->input_cpu_first_index = 0;
+  om->input_cpu_count = 1;
+  om->if_count = 0;
+  om->instance = instance;
+
   odp_pool_capability (&capa);
   if (capa.pkt.min_headroom != VLIB_BUFFER_PRE_DATA_SIZE)
     {
index c3906a4..e511f40 100755 (executable)
@@ -43,7 +43,7 @@ typedef struct
   u32 if_count;
 } odp_packet_main_t;
 
-odp_packet_main_t odp_packet_main;
+extern odp_packet_main_t *odp_packet_main;
 extern vnet_device_class_t odp_packet_device_class;
 extern vlib_node_registration_t odp_packet_input_node;