From: Ophir Munk <ophirmu@mellanox.com>
To: dev@dpdk.org
Cc: Raslan Darawsheh <rasland@mellanox.com>,
Ophir Munk <ophirmu@mellanox.com>,
Matan Azrad <matan@mellanox.com>
Subject: [dpdk-dev] [PATCH v1 2/8] net/mlx5: replace Linux specific calls with rte API
Date: Tue, 14 Jul 2020 14:20:56 +0000 [thread overview]
Message-ID: <20200714142102.30606-3-ophirmu@mellanox.com> (raw)
In-Reply-To: <20200714142102.30606-1-ophirmu@mellanox.com>
The following Linux calls are replaced by their matching rte APIs.
mmap ==> rte_mem_map()
munmap == >rte_mem_unmap()
sysconf(_SC_PAGESIZE) ==> rte_mem_page_size()
Signed-off-by: Ophir Munk <ophirmu@mellanox.com>
Acked-by: Matan Azrad <matan@mellanox.com>
---
drivers/common/mlx5/mlx5_devx_cmds.c | 8 +++++++-
drivers/common/mlx5/mlx5_prm.h | 2 +-
drivers/net/mlx5/linux/mlx5_os.c | 11 ++++++++---
drivers/net/mlx5/linux/mlx5_verbs.c | 1 -
drivers/net/mlx5/mlx5_flow_dv.c | 9 ++++++++-
drivers/net/mlx5/mlx5_rxq.c | 9 ++++++++-
drivers/net/mlx5/mlx5_txq.c | 29 +++++++++++++++++++++--------
7 files changed, 53 insertions(+), 16 deletions(-)
diff --git a/drivers/common/mlx5/mlx5_devx_cmds.c b/drivers/common/mlx5/mlx5_devx_cmds.c
index 2179a83..795e85f 100644
--- a/drivers/common/mlx5/mlx5_devx_cmds.c
+++ b/drivers/common/mlx5/mlx5_devx_cmds.c
@@ -5,6 +5,7 @@
#include <rte_errno.h>
#include <rte_malloc.h>
+#include <rte_eal_paging.h>
#include "mlx5_prm.h"
#include "mlx5_devx_cmds.h"
@@ -158,7 +159,12 @@ mlx5_devx_cmd_mkey_create(void *ctx,
return NULL;
}
memset(in, 0, in_size_dw * 4);
- pgsize = sysconf(_SC_PAGESIZE);
+ pgsize = rte_mem_page_size();
+ if (pgsize == (size_t)-1) {
+ DRV_LOG(ERR, "Failed to get page size");
+ rte_errno = ENOMEM;
+ return NULL;
+ }
MLX5_SET(create_mkey_in, in, opcode, MLX5_CMD_OP_CREATE_MKEY);
mkc = MLX5_ADDR_OF(create_mkey_in, in, memory_key_mkey_entry);
if (klm_num > 0) {
diff --git a/drivers/common/mlx5/mlx5_prm.h b/drivers/common/mlx5/mlx5_prm.h
index c63795f..1b7b4c7 100644
--- a/drivers/common/mlx5/mlx5_prm.h
+++ b/drivers/common/mlx5/mlx5_prm.h
@@ -253,7 +253,7 @@
#define MLX5_MAX_LOG_RQ_SEGS 5u
/* The alignment needed for WQ buffer. */
-#define MLX5_WQE_BUF_ALIGNMENT sysconf(_SC_PAGESIZE)
+#define MLX5_WQE_BUF_ALIGNMENT rte_mem_page_size()
/* Completion mode. */
enum mlx5_completion_mode {
diff --git a/drivers/net/mlx5/linux/mlx5_os.c b/drivers/net/mlx5/linux/mlx5_os.c
index 2dc57b2..e5f024a 100644
--- a/drivers/net/mlx5/linux/mlx5_os.c
+++ b/drivers/net/mlx5/linux/mlx5_os.c
@@ -10,7 +10,6 @@
#include <stdlib.h>
#include <errno.h>
#include <net/if.h>
-#include <sys/mman.h>
#include <linux/rtnetlink.h>
#include <linux/sockios.h>
#include <linux/ethtool.h>
@@ -37,6 +36,7 @@
#include <rte_spinlock.h>
#include <rte_string_fns.h>
#include <rte_alarm.h>
+#include <rte_eal_paging.h>
#include <mlx5_glue.h>
#include <mlx5_devx_cmds.h>
@@ -133,7 +133,7 @@ mlx5_os_get_dev_attr(void *ctx, struct mlx5_dev_attr *device_attr)
* 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)).
+ * (i.e. currently rte_mem_page_size()).
*
* @param[in] size
* The size in bytes of the memory to allocate.
@@ -148,8 +148,13 @@ mlx5_alloc_verbs_buf(size_t size, void *data)
{
struct mlx5_priv *priv = data;
void *ret;
- size_t alignment = sysconf(_SC_PAGESIZE);
unsigned int socket = SOCKET_ID_ANY;
+ size_t alignment = rte_mem_page_size();
+ if (alignment == (size_t)-1) {
+ DRV_LOG(ERR, "Failed to get mem page size");
+ rte_errno = ENOMEM;
+ return NULL;
+ }
if (priv->verbs_alloc_ctx.type == MLX5_VERBS_ALLOC_TYPE_TX_QUEUE) {
const struct mlx5_txq_ctrl *ctrl = priv->verbs_alloc_ctx.obj;
diff --git a/drivers/net/mlx5/linux/mlx5_verbs.c b/drivers/net/mlx5/linux/mlx5_verbs.c
index 6b59fa1..5ac6982 100644
--- a/drivers/net/mlx5/linux/mlx5_verbs.c
+++ b/drivers/net/mlx5/linux/mlx5_verbs.c
@@ -7,7 +7,6 @@
#include <string.h>
#include <stdint.h>
#include <unistd.h>
-#include <sys/mman.h>
#include <inttypes.h>
/* Verbs header. */
diff --git a/drivers/net/mlx5/mlx5_flow_dv.c b/drivers/net/mlx5/mlx5_flow_dv.c
index 8b5b683..7ce30e0 100644
--- a/drivers/net/mlx5/mlx5_flow_dv.c
+++ b/drivers/net/mlx5/mlx5_flow_dv.c
@@ -29,6 +29,7 @@
#include <rte_gre.h>
#include <rte_vxlan.h>
#include <rte_gtp.h>
+#include <rte_eal_paging.h>
#include <mlx5_devx_cmds.h>
#include <mlx5_prm.h>
@@ -4175,7 +4176,13 @@ flow_dv_create_counter_stat_mem_mng(struct rte_eth_dev *dev, int raws_n)
MLX5_COUNTERS_PER_POOL +
sizeof(struct mlx5_counter_stats_raw)) * raws_n +
sizeof(struct mlx5_counter_stats_mem_mng);
- uint8_t *mem = rte_calloc(__func__, 1, size, sysconf(_SC_PAGESIZE));
+ size_t pgsize = rte_mem_page_size();
+ if (pgsize == (size_t)-1) {
+ DRV_LOG(ERR, "Failed to get mem page size");
+ rte_errno = ENOMEM;
+ return NULL;
+ }
+ uint8_t *mem = rte_calloc(__func__, 1, size, pgsize);
int i;
if (!mem) {
diff --git a/drivers/net/mlx5/mlx5_rxq.c b/drivers/net/mlx5/mlx5_rxq.c
index b436f06..637b131 100644
--- a/drivers/net/mlx5/mlx5_rxq.c
+++ b/drivers/net/mlx5/mlx5_rxq.c
@@ -28,6 +28,7 @@
#include <rte_interrupts.h>
#include <rte_debug.h>
#include <rte_io.h>
+#include <rte_eal_paging.h>
#include <mlx5_glue.h>
#include <mlx5_devx_cmds.h>
@@ -1230,7 +1231,13 @@ mlx5_devx_rq_new(struct rte_eth_dev *dev, uint16_t idx, uint32_t cqn)
/* Calculate and allocate WQ memory space. */
wqe_size = 1 << log_wqe_size; /* round up power of two.*/
wq_size = wqe_n * wqe_size;
- buf = rte_calloc_socket(__func__, 1, wq_size, MLX5_WQE_BUF_ALIGNMENT,
+ size_t alignment = MLX5_WQE_BUF_ALIGNMENT;
+ if (alignment == (size_t)-1) {
+ DRV_LOG(ERR, "Failed to get mem page size");
+ rte_errno = ENOMEM;
+ return NULL;
+ }
+ buf = rte_calloc_socket(__func__, 1, wq_size, alignment,
rxq_ctrl->socket);
if (!buf)
return NULL;
diff --git a/drivers/net/mlx5/mlx5_txq.c b/drivers/net/mlx5/mlx5_txq.c
index 35b3ade..a9bf42d 100644
--- a/drivers/net/mlx5/mlx5_txq.c
+++ b/drivers/net/mlx5/mlx5_txq.c
@@ -8,7 +8,6 @@
#include <string.h>
#include <stdint.h>
#include <unistd.h>
-#include <sys/mman.h>
#include <inttypes.h>
/* Verbs header. */
@@ -26,6 +25,7 @@
#include <rte_malloc.h>
#include <rte_ethdev_driver.h>
#include <rte_common.h>
+#include <rte_eal_paging.h>
#include <mlx5_glue.h>
#include <mlx5_devx_cmds.h>
@@ -340,10 +340,14 @@ txq_uar_init(struct mlx5_txq_ctrl *txq_ctrl)
{
struct mlx5_priv *priv = txq_ctrl->priv;
struct mlx5_proc_priv *ppriv = MLX5_PROC_PRIV(PORT_ID(priv));
- const size_t page_size = sysconf(_SC_PAGESIZE);
#ifndef RTE_ARCH_64
unsigned int lock_idx;
#endif
+ const size_t page_size = rte_mem_page_size();
+ if (page_size == (size_t)-1) {
+ DRV_LOG(ERR, "Failed to get mem page size");
+ rte_errno = ENOMEM;
+ }
if (txq_ctrl->type != MLX5_TXQ_TYPE_STANDARD)
return;
@@ -382,7 +386,12 @@ txq_uar_init_secondary(struct mlx5_txq_ctrl *txq_ctrl, int fd)
void *addr;
uintptr_t uar_va;
uintptr_t offset;
- const size_t page_size = sysconf(_SC_PAGESIZE);
+ const size_t page_size = rte_mem_page_size();
+ if (page_size == (size_t)-1) {
+ DRV_LOG(ERR, "Failed to get mem page size");
+ rte_errno = ENOMEM;
+ return -rte_errno;
+ }
if (txq_ctrl->type != MLX5_TXQ_TYPE_STANDARD)
return 0;
@@ -393,9 +402,9 @@ txq_uar_init_secondary(struct mlx5_txq_ctrl *txq_ctrl, int fd)
*/
uar_va = (uintptr_t)txq_ctrl->bf_reg;
offset = uar_va & (page_size - 1); /* Offset in page. */
- addr = mmap(NULL, page_size, PROT_WRITE, MAP_SHARED, fd,
- txq_ctrl->uar_mmap_offset);
- if (addr == MAP_FAILED) {
+ addr = rte_mem_map(NULL, page_size, RTE_PROT_WRITE, RTE_MAP_SHARED,
+ fd, txq_ctrl->uar_mmap_offset);
+ if (!addr) {
DRV_LOG(ERR,
"port %u mmap failed for BF reg of txq %u",
txq->port_id, txq->idx);
@@ -418,13 +427,17 @@ static void
txq_uar_uninit_secondary(struct mlx5_txq_ctrl *txq_ctrl)
{
struct mlx5_proc_priv *ppriv = MLX5_PROC_PRIV(PORT_ID(txq_ctrl->priv));
- const size_t page_size = sysconf(_SC_PAGESIZE);
void *addr;
+ const size_t page_size = rte_mem_page_size();
+ if (page_size == (size_t)-1) {
+ DRV_LOG(ERR, "Failed to get mem page size");
+ rte_errno = ENOMEM;
+ }
if (txq_ctrl->type != MLX5_TXQ_TYPE_STANDARD)
return;
addr = ppriv->uar_table[txq_ctrl->txq.idx];
- munmap(RTE_PTR_ALIGN_FLOOR(addr, page_size), page_size);
+ rte_mem_unmap(RTE_PTR_ALIGN_FLOOR(addr, page_size), page_size);
}
/**
--
2.8.4
next prev parent reply other threads:[~2020-07-14 14:21 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-14 14:20 [dpdk-dev] [PATCH v1 0/8] mlx5 PMD multi OS support - part #3 Ophir Munk
2020-07-14 14:20 ` [dpdk-dev] [PATCH v1 1/8] net/mlx5: move flow prio discovery and adjust under verbs Ophir Munk
2020-07-14 14:20 ` Ophir Munk [this message]
2020-07-14 14:20 ` [dpdk-dev] [PATCH v1 3/8] net/mlx5: refactor Linux MAC operations Ophir Munk
2020-07-14 14:20 ` [dpdk-dev] [PATCH v1 4/8] linux/mlx5: add setters for promiscuous and all-multi Ophir Munk
2020-07-14 14:20 ` [dpdk-dev] [PATCH v1 5/8] net/mlx5: eliminate dependency on Linux in shared header Ophir Munk
2020-07-14 14:21 ` [dpdk-dev] [PATCH v1 6/8] net/mlx5: header file cleanup Ophir Munk
2020-07-14 14:21 ` [dpdk-dev] [PATCH v1 7/8] net/mlx5: refactor multi process communication Ophir Munk
2020-07-14 14:21 ` [dpdk-dev] [PATCH v1 8/8] mlx5: remove inclusion of verbs header files Ophir Munk
2020-07-19 7:11 ` [dpdk-dev] [PATCH v2 0/8] mlx5 PMD multi OS support - part #3 Ophir Munk
2020-07-19 7:11 ` [dpdk-dev] [PATCH v2 1/8] net/mlx5: move flow prio discovery and adjust under Verbs Ophir Munk
2020-07-19 7:11 ` [dpdk-dev] [PATCH v2 2/8] net/mlx5: replace Linux specific calls with rte API Ophir Munk
2020-07-19 7:11 ` [dpdk-dev] [PATCH v2 3/8] net/mlx5: refactor Linux MAC operations Ophir Munk
2020-07-19 7:11 ` [dpdk-dev] [PATCH v2 4/8] linux/mlx5: add setters for promiscuous and all-multi Ophir Munk
2020-07-19 7:11 ` [dpdk-dev] [PATCH v2 5/8] net/mlx5: eliminate dependency on Linux in shared header Ophir Munk
2020-07-19 7:11 ` [dpdk-dev] [PATCH v2 6/8] net/mlx5: header file cleanup Ophir Munk
2020-07-19 7:11 ` [dpdk-dev] [PATCH v2 7/8] net/mlx5: refactor multi process communication Ophir Munk
2020-07-19 7:11 ` [dpdk-dev] [PATCH v2 8/8] mlx5: remove inclusion of Verbs header files Ophir Munk
2020-07-19 10:18 ` [dpdk-dev] [PATCH v3 0/8] mlx5 PMD multi OS support - part #3 Ophir Munk
2020-07-19 10:18 ` [dpdk-dev] [PATCH v3 1/8] net/mlx5: move flow prio discovery and adjust under Verbs Ophir Munk
2020-07-19 10:18 ` [dpdk-dev] [PATCH v3 2/8] net/mlx5: replace Linux specific calls with rte API Ophir Munk
2020-07-19 10:18 ` [dpdk-dev] [PATCH v3 3/8] net/mlx5: refactor Linux MAC operations Ophir Munk
2020-07-19 10:18 ` [dpdk-dev] [PATCH v3 4/8] linux/mlx5: add setters for promiscuous and all-multi Ophir Munk
2020-07-19 10:18 ` [dpdk-dev] [PATCH v3 5/8] net/mlx5: eliminate dependency on Linux in shared header Ophir Munk
2020-07-19 10:18 ` [dpdk-dev] [PATCH v3 6/8] net/mlx5: header file cleanup Ophir Munk
2020-07-19 10:18 ` [dpdk-dev] [PATCH v3 7/8] net/mlx5: refactor multi process communication Ophir Munk
2020-07-19 10:18 ` [dpdk-dev] [PATCH v3 8/8] mlx5: remove inclusion of Verbs header files Ophir Munk
2020-07-19 14:56 ` [dpdk-dev] [PATCH v3 0/8] mlx5 PMD multi OS support - part #3 Raslan Darawsheh
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200714142102.30606-3-ophirmu@mellanox.com \
--to=ophirmu@mellanox.com \
--cc=dev@dpdk.org \
--cc=matan@mellanox.com \
--cc=rasland@mellanox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).