]> git.droids-corp.org - dpdk.git/commitdiff
net/ena/base: make IO memzone unique per port
authorMichal Krawczyk <mk@semihalf.com>
Wed, 23 Feb 2022 12:19:35 +0000 (13:19 +0100)
committerFerruh Yigit <ferruh.yigit@intel.com>
Wed, 23 Feb 2022 18:01:03 +0000 (19:01 +0100)
Originally, the ena_com memzone counter was shared by ports, which
caused the memzones to be harder to identify and could potentially
lead to race and because of that the counter had to be atomic.

This atomic counter was global variable and it couldn't work in the
multiprocess implementation.

The memzone is now being identified by the local to port memzone counter
and the port ID - both of those information can be found in the shared
data, so it can be probed easily.

Signed-off-by: Michal Krawczyk <mk@semihalf.com>
Reviewed-by: Dawid Gorecki <dgr@semihalf.com>
Reviewed-by: Shai Brandes <shaibran@amazon.com>
doc/guides/nics/features/ena.ini
drivers/net/ena/base/ena_plat_dpdk.h
drivers/net/ena/ena_ethdev.c
drivers/net/ena/ena_ethdev.h

index 4db1db11f486b5f555405017097d605768cda023..55690aaf5aaf16b99bfffac3b9f8548f06c71af5 100644 (file)
@@ -17,6 +17,7 @@ L3 checksum offload  = Y
 L4 checksum offload  = Y
 Basic stats          = Y
 Extended stats       = Y
+Multiprocess aware   = Y
 Linux                = Y
 ARMv8                = Y
 x86-32               = Y
index 41db883c63138e9ae4b04051e0ceeda49deb599a..8f2b3a87c2abeef40ddeb9dc5a1687297bbe2d8a 100644 (file)
@@ -14,6 +14,7 @@
 #include <string.h>
 #include <errno.h>
 
+#include <ethdev_driver.h>
 #include <rte_atomic.h>
 #include <rte_branch_prediction.h>
 #include <rte_cycles.h>
@@ -202,35 +203,20 @@ typedef struct {
 #define ENA_GET_SYSTEM_TIMEOUT(timeout_us)                                    \
        ((timeout_us) * rte_get_timer_hz() / 1000000 + rte_get_timer_cycles())
 
-/*
- * Each rte_memzone should have unique name.
- * To satisfy it, count number of allocations and add it to name.
- */
-extern rte_atomic64_t ena_alloc_cnt;
+const struct rte_memzone *
+ena_mem_alloc_coherent(struct rte_eth_dev_data *data, size_t size,
+                      int socket_id, unsigned int alignment, void **virt_addr,
+                      dma_addr_t *phys_addr);
 
 #define ENA_MEM_ALLOC_COHERENT_ALIGNED(                                               \
        dmadev, size, virt, phys, mem_handle, alignment)                       \
        do {                                                                   \
-               const struct rte_memzone *mz = NULL;                           \
-               ENA_TOUCH(dmadev);                                             \
-               if ((size) > 0) {                                              \
-                       char z_name[RTE_MEMZONE_NAMESIZE];                     \
-                       snprintf(z_name, sizeof(z_name),                       \
-                               "ena_alloc_%" PRIi64 "",                       \
-                               rte_atomic64_add_return(&ena_alloc_cnt, 1));   \
-                       mz = rte_memzone_reserve_aligned(z_name, (size),       \
-                                       SOCKET_ID_ANY, RTE_MEMZONE_IOVA_CONTIG,\
-                                       alignment);                            \
-                       mem_handle = mz;                                       \
-               }                                                              \
-               if (mz == NULL) {                                              \
-                       virt = NULL;                                           \
-                       phys = 0;                                              \
-               } else {                                                       \
-                       memset(mz->addr, 0, (size));                           \
-                       virt = mz->addr;                                       \
-                       phys = mz->iova;                                       \
-               }                                                              \
+               void *virt_addr;                                               \
+               dma_addr_t phys_addr;                                          \
+               (mem_handle) = ena_mem_alloc_coherent((dmadev), (size),        \
+                       SOCKET_ID_ANY, (alignment), &virt_addr, &phys_addr);   \
+               (virt) = virt_addr;                                            \
+               (phys) = phys_addr;                                            \
        } while (0)
 #define ENA_MEM_ALLOC_COHERENT(dmadev, size, virt, phys, mem_handle)          \
                ENA_MEM_ALLOC_COHERENT_ALIGNED(dmadev, size, virt, phys,       \
@@ -242,25 +228,13 @@ extern rte_atomic64_t ena_alloc_cnt;
 #define ENA_MEM_ALLOC_COHERENT_NODE_ALIGNED(                                  \
        dmadev, size, virt, phys, mem_handle, node, dev_node, alignment)       \
        do {                                                                   \
-               const struct rte_memzone *mz = NULL;                           \
-               ENA_TOUCH(dmadev); ENA_TOUCH(dev_node);                        \
-               if ((size) > 0) {                                              \
-                       char z_name[RTE_MEMZONE_NAMESIZE];                     \
-                       snprintf(z_name, sizeof(z_name),                       \
-                               "ena_alloc_%" PRIi64 "",                       \
-                               rte_atomic64_add_return(&ena_alloc_cnt, 1));   \
-                       mz = rte_memzone_reserve_aligned(z_name, (size),       \
-                               node, RTE_MEMZONE_IOVA_CONTIG, alignment);     \
-                       mem_handle = mz;                                       \
-               }                                                              \
-               if (mz == NULL) {                                              \
-                       virt = NULL;                                           \
-                       phys = 0;                                              \
-               } else {                                                       \
-                       memset(mz->addr, 0, (size));                           \
-                       virt = mz->addr;                                       \
-                       phys = mz->iova;                                       \
-               }                                                              \
+               void *virt_addr;                                               \
+               dma_addr_t phys_addr;                                          \
+               ENA_TOUCH(dev_node);                                           \
+               (mem_handle) = ena_mem_alloc_coherent((dmadev), (size),        \
+                       (node), (alignment), &virt_addr, &phys_addr);      \
+               (virt) = virt_addr;                                            \
+               (phys) = phys_addr;                                            \
        } while (0)
 #define ENA_MEM_ALLOC_COHERENT_NODE(                                          \
        dmadev, size, virt, phys, mem_handle, node, dev_node)                  \
index 38fbe1618e9f89d65876a700e457b1cf7fd3e807..73c1d63174c318e2804b4d9d174c836b51444eba 100644 (file)
@@ -2110,8 +2110,10 @@ static int eth_ena_dev_init(struct rte_eth_dev *eth_dev)
        }
 
        ena_dev->reg_bar = adapter->regs;
-       /* This is a dummy pointer for ena_com functions. */
-       ena_dev->dmadev = adapter;
+       /* Pass device data as a pointer which can be passed to the IO functions
+        * by the ena_com (for example - the memory allocation).
+        */
+       ena_dev->dmadev = eth_dev->data;
 
        adapter->id_number = adapters_found;
 
@@ -3488,6 +3490,52 @@ int ena_mp_indirect_table_get(struct ena_adapter *adapter,
                indirect_table);
 }
 
+/*********************************************************************
+ *  ena_plat_dpdk.h functions implementations
+ *********************************************************************/
+
+const struct rte_memzone *
+ena_mem_alloc_coherent(struct rte_eth_dev_data *data, size_t size,
+                      int socket_id, unsigned int alignment, void **virt_addr,
+                      dma_addr_t *phys_addr)
+{
+       char z_name[RTE_MEMZONE_NAMESIZE];
+       struct ena_adapter *adapter = data->dev_private;
+       const struct rte_memzone *memzone;
+       int rc;
+
+       rc = snprintf(z_name, RTE_MEMZONE_NAMESIZE, "ena_p%d_mz%" PRIu64 "",
+               data->port_id, adapter->memzone_cnt);
+       if (rc >= RTE_MEMZONE_NAMESIZE) {
+               PMD_DRV_LOG(ERR,
+                       "Name for the ena_com memzone is too long. Port: %d, mz_num: %" PRIu64 "\n",
+                       data->port_id, adapter->memzone_cnt);
+               goto error;
+       }
+       adapter->memzone_cnt++;
+
+       memzone = rte_memzone_reserve_aligned(z_name, size, socket_id,
+               RTE_MEMZONE_IOVA_CONTIG, alignment);
+       if (memzone == NULL) {
+               PMD_DRV_LOG(ERR, "Failed to allocate ena_com memzone: %s\n",
+                       z_name);
+               goto error;
+       }
+
+       memset(memzone->addr, 0, size);
+       *virt_addr = memzone->addr;
+       *phys_addr = memzone->iova;
+
+       return memzone;
+
+error:
+       *virt_addr = NULL;
+       *phys_addr = 0;
+
+       return NULL;
+}
+
+
 /*********************************************************************
  *  PMD configuration
  *********************************************************************/
index 01cf0ef5db72780e3ca20b2e77adc709e7137d02..ca3e5ed691db886a662fef4987da94e01b17519a 100644 (file)
@@ -308,6 +308,8 @@ struct ena_adapter {
        uint64_t missing_tx_completion_to;
        uint64_t missing_tx_completion_budget;
        uint64_t tx_cleanup_stall_delay;
+
+       uint64_t memzone_cnt;
 };
 
 int ena_mp_indirect_table_set(struct ena_adapter *adapter);