With this commit, a new device argument is introduced to control
the memory allocation for Tx queues.

By default, without specifying any value. A default alignment with
system page size will be used. All SQ / CQ memory of Tx queues will
be allocated once and a single umem & MR will be used.

When setting to 0, the legacy way of per queue umem allocation will
be selected in the following commit.

If the value is smaller than the system page size, the starting
address alignment will be rounded up to the page size.

The value is a logarithm value based to 2.

Signed-off-by: Bing Zhao <bi...@nvidia.com>
---
 doc/guides/nics/mlx5.rst | 18 ++++++++++++++++++
 drivers/net/mlx5/mlx5.c  | 36 ++++++++++++++++++++++++++++++++++++
 drivers/net/mlx5/mlx5.h  |  7 ++++---
 3 files changed, 58 insertions(+), 3 deletions(-)

diff --git a/doc/guides/nics/mlx5.rst b/doc/guides/nics/mlx5.rst
index c1dcb9ca68..82cb06909d 100644
--- a/doc/guides/nics/mlx5.rst
+++ b/doc/guides/nics/mlx5.rst
@@ -1682,6 +1682,24 @@ for an additional list of options shared with other mlx5 
drivers.
 
   By default, the PMD will set this value to 1.
 
+- ``txq_mem_algn`` parameter [int]
+
+  A The logarithm value to the base 2 for the memory starting
+  address alignment for Tx queues' WQ and associated CQ. Different CPU
+  architectures and generations may have different cache systems. The memory
+  accessing order may impact the cache misses rate on different CPUs. This 
devarg
+  gives the ability to control the alignment and gaps between TxQs without
+  rebuilding the application binary. User can tune the SW performance by 
specifying
+  this devarg after benchmark testing on their servers and systems.
+
+  By default, the PMD will set it to log(4096), or log(64*1024) on some 
specific OS
+  distributions - based on the system page size configuration.
+  All TxQs will use unique memory region and umem area, each TxQs will 
starting at an
+  address with 4K/64K (default system page size) alignment. If the user's 
input value is
+  less then the page size, it will be rounded up. If bigger than the maximal 
queue size,
+  a warning message will be shown, there will be some waste of the memory 
space. 0 indicates
+  that the legacy per queue memory allocation and separate MRs will be used as 
before.
+
 
 Multiport E-Switch
 ------------------
diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c
index 1bad8a9e90..a167d75aeb 100644
--- a/drivers/net/mlx5/mlx5.c
+++ b/drivers/net/mlx5/mlx5.c
@@ -185,6 +185,14 @@
 /* Device parameter to control representor matching in ingress/egress flows 
with HWS. */
 #define MLX5_REPR_MATCHING_EN "repr_matching_en"
 
+/*
+ * Alignment of the Tx queue starting address,
+ * If not set, using separate umem and MR for each TxQ.
+ * If set, using consecutive memory address and single MR for all Tx queues, 
each TxQ will start at
+ * the alignment specified.
+ */
+#define MLX5_TXQ_MEM_ALGN "txq_mem_algn"
+
 /* Shared memory between primary and secondary processes. */
 struct mlx5_shared_data *mlx5_shared_data;
 
@@ -1447,6 +1455,8 @@ mlx5_dev_args_check_handler(const char *key, const char 
*val, void *opaque)
                config->cnt_svc.cycle_time = tmp;
        } else if (strcmp(MLX5_REPR_MATCHING_EN, key) == 0) {
                config->repr_matching = !!tmp;
+       } else if (strcmp(MLX5_TXQ_MEM_ALGN, key) == 0) {
+               config->txq_mem_algn = (uint32_t)tmp;
        }
        return 0;
 }
@@ -1486,9 +1496,17 @@ mlx5_shared_dev_ctx_args_config(struct 
mlx5_dev_ctx_shared *sh,
                MLX5_HWS_CNT_SERVICE_CORE,
                MLX5_HWS_CNT_CYCLE_TIME,
                MLX5_REPR_MATCHING_EN,
+               MLX5_TXQ_MEM_ALGN,
                NULL,
        };
        int ret = 0;
+       size_t alignment = rte_mem_page_size();
+       uint32_t max_queue_umem_size = MLX5_WQE_SIZE * 
mlx5_dev_get_max_wq_size(sh);
+
+       if (alignment == (size_t)-1) {
+               DRV_LOG(WARNING, "Failed to get page_size, using default 4K 
size.");
+               alignment = 4 * 1024;
+       }
 
        /* Default configuration. */
        memset(config, 0, sizeof(*config));
@@ -1501,6 +1519,7 @@ mlx5_shared_dev_ctx_args_config(struct 
mlx5_dev_ctx_shared *sh,
        config->cnt_svc.cycle_time = MLX5_CNT_SVC_CYCLE_TIME_DEFAULT;
        config->cnt_svc.service_core = rte_get_main_lcore();
        config->repr_matching = 1;
+       config->txq_mem_algn = log2above(alignment);
        if (mkvlist != NULL) {
                /* Process parameters. */
                ret = mlx5_kvargs_process(mkvlist, params,
@@ -1567,6 +1586,16 @@ mlx5_shared_dev_ctx_args_config(struct 
mlx5_dev_ctx_shared *sh,
                config->hw_fcs_strip = 0;
        else
                config->hw_fcs_strip = sh->dev_cap.hw_fcs_strip;
+       if (config->txq_mem_algn != 0 && config->txq_mem_algn < 
log2above(alignment)) {
+               DRV_LOG(WARNING,
+                       "\"txq_mem_algn\" too small %u, round up to %u.",
+                       config->txq_mem_algn, log2above(alignment));
+               config->txq_mem_algn = log2above(alignment);
+       } else if (config->txq_mem_algn > log2above(max_queue_umem_size)) {
+               DRV_LOG(WARNING,
+                       "\"txq_mem_algn\" with value %u bigger than %u.",
+                       config->txq_mem_algn, log2above(max_queue_umem_size));
+       }
        DRV_LOG(DEBUG, "FCS stripping configuration is %ssupported",
                (config->hw_fcs_strip ? "" : "not "));
        DRV_LOG(DEBUG, "\"tx_pp\" is %d.", config->tx_pp);
@@ -1584,6 +1613,7 @@ mlx5_shared_dev_ctx_args_config(struct 
mlx5_dev_ctx_shared *sh,
                config->allow_duplicate_pattern);
        DRV_LOG(DEBUG, "\"fdb_def_rule_en\" is %u.", config->fdb_def_rule);
        DRV_LOG(DEBUG, "\"repr_matching_en\" is %u.", config->repr_matching);
+       DRV_LOG(DEBUG, "\"txq_mem_algn\" is %u.", config->txq_mem_algn);
        return 0;
 }
 
@@ -3151,6 +3181,12 @@ mlx5_probe_again_args_validate(struct mlx5_common_device 
*cdev,
                        sh->ibdev_name);
                goto error;
        }
+       if (sh->config.txq_mem_algn != config->txq_mem_algn) {
+               DRV_LOG(ERR, "\"TxQ memory alignment\" "
+                       "configuration mismatch for shared %s context. %u - %u",
+                       sh->ibdev_name, sh->config.txq_mem_algn, 
config->txq_mem_algn);
+               goto error;
+       }
        mlx5_free(config);
        return 0;
 error:
diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h
index f085656196..6b8d29a2bf 100644
--- a/drivers/net/mlx5/mlx5.h
+++ b/drivers/net/mlx5/mlx5.h
@@ -386,13 +386,14 @@ struct mlx5_sh_config {
        uint32_t hw_fcs_strip:1; /* FCS stripping is supported. */
        uint32_t allow_duplicate_pattern:1;
        uint32_t lro_allowed:1; /* Whether LRO is allowed. */
+       /* Allow/Prevent the duplicate rules pattern. */
+       uint32_t fdb_def_rule:1; /* Create FDB default jump rule */
+       uint32_t repr_matching:1; /* Enable implicit vport matching in HWS FDB. 
*/
+       uint32_t txq_mem_algn; /* logarithm value of the TxQ address alignment. 
*/
        struct {
                uint16_t service_core;
                uint32_t cycle_time; /* query cycle time in milli-second. */
        } cnt_svc; /* configure for HW steering's counter's service. */
-       /* Allow/Prevent the duplicate rules pattern. */
-       uint32_t fdb_def_rule:1; /* Create FDB default jump rule */
-       uint32_t repr_matching:1; /* Enable implicit vport matching in HWS FDB. 
*/
 };
 
 /* Structure for VF VLAN workaround. */
-- 
2.34.1

Reply via email to