]> git.droids-corp.org - dpdk.git/commitdiff
net/mlx5: allocate verbs object into shared memory
authorXueming Li <xuemingl@mellanox.com>
Fri, 6 Oct 2017 15:45:50 +0000 (23:45 +0800)
committerFerruh Yigit <ferruh.yigit@intel.com>
Thu, 12 Oct 2017 00:36:57 +0000 (01:36 +0100)
PMD uses Verbs object which were not available in the shared memory.

This patch modify the location where Verbs objects are allocated (from
process memory address space to shared memory address space) and thus
allow a secondary process to use those object by mapping this shared
memory space its own memory space.

Signed-off-by: Xueming Li <xuemingl@mellanox.com>
Acked-by: Nelio Laranjeiro <nelio.laranjeiro@6wind.com>
drivers/net/mlx5/mlx5.c

index f0e1099d11795949a9bf0e6258ce394340be7139..6541ee369358a1290a6906646bc28b5336d3daec 100644 (file)
@@ -131,6 +131,52 @@ mlx5_getenv_int(const char *name)
        return atoi(val);
 }
 
+/**
+ * Verbs callback to allocate a memory. This function should allocate the space
+ * according to the size provided residing inside a huge page.
+ * Please note that all allocation must respect the alignment from libmlx5
+ * (i.e. currently sysconf(_SC_PAGESIZE)).
+ *
+ * @param[in] size
+ *   The size in bytes of the memory to allocate.
+ * @param[in] data
+ *   A pointer to the callback data.
+ *
+ * @return
+ *   a pointer to the allocate space.
+ */
+static void *
+mlx5_alloc_verbs_buf(size_t size, void *data)
+{
+       struct priv *priv = data;
+       void *ret;
+       size_t alignment = sysconf(_SC_PAGESIZE);
+
+       assert(data != NULL);
+       assert(!mlx5_is_secondary());
+       ret = rte_malloc_socket(__func__, size, alignment,
+                               priv->dev->device->numa_node);
+       DEBUG("Extern alloc size: %lu, align: %lu: %p", size, alignment, ret);
+       return ret;
+}
+
+/**
+ * Verbs callback to free a memory.
+ *
+ * @param[in] ptr
+ *   A pointer to the memory to free.
+ * @param[in] data
+ *   A pointer to the callback data.
+ */
+static void
+mlx5_free_verbs_buf(void *ptr, void *data __rte_unused)
+{
+       assert(data != NULL);
+       assert(!mlx5_is_secondary());
+       DEBUG("Extern free request: %p", ptr);
+       rte_free(ptr);
+}
+
 /**
  * DPDK callback to close the device.
  *
@@ -826,6 +872,15 @@ mlx5_pci_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
                eth_dev->dev_ops = &mlx5_dev_ops;
                TAILQ_INIT(&priv->flows);
 
+               /* Hint libmlx5 to use PMD allocator for data plane resources */
+               struct mlx5dv_ctx_allocators alctr = {
+                       .alloc = &mlx5_alloc_verbs_buf,
+                       .free = &mlx5_free_verbs_buf,
+                       .data = priv,
+               };
+               mlx5dv_set_context_attr(ctx, MLX5DV_CTX_ATTR_BUF_ALLOCATORS,
+                                       (void *)((uintptr_t)&alctr));
+
                /* Bring Ethernet device up. */
                DEBUG("forcing Ethernet interface up");
                priv_set_flags(priv, ~IFF_UP, IFF_UP);