vlib: pre-alloc dma backend batches 75/38475/2
authorMarvin Liu <yong.liu@intel.com>
Tue, 14 Mar 2023 15:43:28 +0000 (23:43 +0800)
committerFlorin Coras <florin.coras@gmail.com>
Tue, 14 Mar 2023 16:40:41 +0000 (16:40 +0000)
Allocate and initialize dma batch structure when adding dma config.
The number of required dma batches is set by max_batches parameter.
Thus dma batches are not allocated dynamically in worker thread.
Application need to check the return value of vlib_dma_batch_new.

Type: improvement

Signed-off-by: Marvin Liu <yong.liu@intel.com>
Change-Id: I5d05a67b59634cf2862a377d5ab77cb1040343ce

src/plugins/dma_intel/dsa.c
src/vlib/dma/dma.h

index 7e1cdc2..a1efcfa 100644 (file)
@@ -212,6 +212,29 @@ intel_dsa_check_channel (intel_dsa_channel_t *ch, vlib_dma_config_data_t *cd)
   return 0;
 }
 
+static_always_inline void
+intel_dsa_alloc_dma_batch (vlib_main_t *vm, intel_dsa_config_t *idc)
+{
+  intel_dsa_batch_t *b;
+  b = vlib_physmem_alloc (vm, idc->alloc_size);
+  /* if no free space in physmem, force quit */
+  ASSERT (b != NULL);
+  *b = idc->batch_template;
+  b->max_transfers = idc->max_transfers;
+
+  u32 def_flags = (INTEL_DSA_OP_MEMMOVE << INTEL_DSA_OP_SHIFT) |
+                 INTEL_DSA_FLAG_CACHE_CONTROL;
+  if (b->ch->block_on_fault)
+    def_flags |= INTEL_DSA_FLAG_BLOCK_ON_FAULT;
+
+  for (int i = 0; i < idc->max_transfers; i++)
+    {
+      intel_dsa_desc_t *dsa_desc = b->descs + i;
+      dsa_desc->op_flags = def_flags;
+    }
+  vec_add1 (idc->freelist, b);
+}
+
 static int
 intel_dsa_config_add_fn (vlib_main_t *vm, vlib_dma_config_data_t *cd)
 {
@@ -259,6 +282,10 @@ intel_dsa_config_add_fn (vlib_main_t *vm, vlib_dma_config_data_t *cd)
        "config %d in thread %d stride %d src/dst/size offset %d-%d-%d",
        cd->config_index, thread, b->stride, b->src_ptr_off, b->dst_ptr_off,
        b->size_off);
+
+      /* allocate dma batch in advance */
+      for (u32 index = 0; index < cd->cfg.max_batches; index++)
+       intel_dsa_alloc_dma_batch (vm, idc);
     }
 
   dsa_log_info ("config %u added", cd->private_data);
index eaeba8b..62d0411 100644 (file)
@@ -38,6 +38,7 @@ typedef struct
     };
     u32 features;
   };
+  u16 max_batches;
   u16 max_transfers;
   u32 max_transfer_size;
   vlib_dma_batch_callback_fn *callback_fn;