rdma: use per-thread buffer template 78/25578/3
authorDamjan Marion <damarion@cisco.com>
Mon, 2 Mar 2020 16:36:30 +0000 (17:36 +0100)
committerDamjan Marion <damarion@cisco.com>
Mon, 2 Mar 2020 18:27:31 +0000 (19:27 +0100)
Type: improvement
Change-Id: Ie6f2c79e0a769f70eab079c75a500b9308dd51e6
Signed-off-by: Damjan Marion <damarion@cisco.com>
src/plugins/rdma/device.c
src/plugins/rdma/input.c
src/plugins/rdma/rdma.h

index 7316edb..29d9842 100644 (file)
@@ -796,9 +796,23 @@ clib_error_t *
 rdma_init (vlib_main_t * vm)
 {
   rdma_main_t *rm = &rdma_main;
+  vlib_thread_main_t *tm = vlib_get_thread_main ();
 
   rm->log_class = vlib_log_register_class ("rdma", 0);
 
+  /* vlib_buffer_t template */
+  vec_validate_aligned (rm->per_thread_data, tm->n_vlib_mains - 1,
+                       CLIB_CACHE_LINE_BYTES);
+
+  for (int i = 0; i < tm->n_vlib_mains; i++)
+    {
+      rdma_per_thread_data_t *ptd = vec_elt_at_index (rm->per_thread_data, i);
+      clib_memset (&ptd->buffer_template, 0, sizeof (vlib_buffer_t));
+      ptd->buffer_template.flags = VLIB_BUFFER_TOTAL_LENGTH_VALID;
+      ptd->buffer_template.ref_count = 1;
+      vnet_buffer (&ptd->buffer_template)->sw_if_index[VLIB_TX] = (u32) ~ 0;
+    }
+
   return 0;
 }
 
index 95909f4..8f3bdb7 100644 (file)
@@ -269,7 +269,10 @@ static_always_inline uword
 rdma_device_input_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
                          vlib_frame_t * frame, rdma_device_t * rd, u16 qid)
 {
+  rdma_main_t *rm = &rdma_main;
   vnet_main_t *vnm = vnet_get_main ();
+  rdma_per_thread_data_t *ptd = vec_elt_at_index (rm->per_thread_data,
+                                                 vm->thread_index);
   rdma_rxq_t *rxq = vec_elt_at_index (rd->rxqs, qid);
   struct ibv_wc wc[VLIB_FRAME_SIZE];
   vlib_buffer_t bt;
@@ -290,13 +293,9 @@ rdma_device_input_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
     }
 
   /* init buffer template */
-  clib_memset_u64 (&bt, 0,
-                  STRUCT_OFFSET_OF (vlib_buffer_t,
-                                    template_end) / sizeof (u64));
+  vlib_buffer_copy_template (&bt, &ptd->buffer_template);
   vnet_buffer (&bt)->sw_if_index[VLIB_RX] = rd->sw_if_index;
-  vnet_buffer (&bt)->sw_if_index[VLIB_TX] = ~0;
   bt.buffer_pool_index = rd->pool;
-  bt.ref_count = 1;
 
   /* update buffer template for input feature arcs if any */
   next_index = rd->per_interface_next_index;
index 470309a..302d238 100644 (file)
@@ -95,6 +95,13 @@ typedef struct
 
 typedef struct
 {
+  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
+  vlib_buffer_t buffer_template;
+} rdma_per_thread_data_t;
+
+typedef struct
+{
+  rdma_per_thread_data_t *per_thread_data;
   rdma_device_t *devices;
   vlib_log_class_t log_class;
   u16 msg_id_base;