From 718e35999c963449b90de14d25670cd0abd5c847 Mon Sep 17 00:00:00 2001 From: Anatoly Burakov Date: Wed, 11 Apr 2018 13:30:19 +0100 Subject: [PATCH] net/mlx5: use virt2memseg instead of iteration Reduce dependency on internal details of EAL memory subsystem, and simplify code. Signed-off-by: Anatoly Burakov Tested-by: Santosh Shukla Tested-by: Hemant Agrawal Tested-by: Gowrishankar Muthukrishnan --- drivers/net/mlx5/mlx5_mr.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/drivers/net/mlx5/mlx5_mr.c b/drivers/net/mlx5/mlx5_mr.c index 58afeb72a1..c96e134f79 100644 --- a/drivers/net/mlx5/mlx5_mr.c +++ b/drivers/net/mlx5/mlx5_mr.c @@ -234,10 +234,9 @@ struct mlx5_mr * mlx5_mr_new(struct rte_eth_dev *dev, struct rte_mempool *mp) { struct priv *priv = dev->data->dev_private; - const struct rte_memseg *ms = rte_eal_get_physmem_layout(); + const struct rte_memseg *ms; uintptr_t start; uintptr_t end; - unsigned int i; struct mlx5_mr *mr; mr = rte_zmalloc_socket(__func__, sizeof(*mr), 0, mp->socket_id); @@ -261,17 +260,15 @@ mlx5_mr_new(struct rte_eth_dev *dev, struct rte_mempool *mp) /* Save original addresses for exact MR lookup. */ mr->start = start; mr->end = end; + /* Round start and end to page boundary if found in memory segments. */ - for (i = 0; (i < RTE_MAX_MEMSEG) && (ms[i].addr != NULL); ++i) { - uintptr_t addr = (uintptr_t)ms[i].addr; - size_t len = ms[i].len; - unsigned int align = ms[i].hugepage_sz; + ms = rte_mem_virt2memseg((void *)start); + if (ms != NULL) + start = RTE_ALIGN_FLOOR(start, ms->hugepage_sz); + ms = rte_mem_virt2memseg((void *)end); + if (ms != NULL) + end = RTE_ALIGN_CEIL(end, ms->hugepage_sz); - if ((start > addr) && (start < addr + len)) - start = RTE_ALIGN_FLOOR(start, align); - if ((end > addr) && (end < addr + len)) - end = RTE_ALIGN_CEIL(end, align); - } DRV_LOG(DEBUG, "port %u mempool %p using start=%p end=%p size=%zu for memory" " region", -- 2.20.1