From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 2753BA0540; Tue, 14 Jul 2020 16:21:34 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id B76471D53B; Tue, 14 Jul 2020 16:21:15 +0200 (CEST) Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-eopbgr60074.outbound.protection.outlook.com [40.107.6.74]) by dpdk.org (Postfix) with ESMTP id 1959D1D516 for ; Tue, 14 Jul 2020 16:21:12 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=csSPx9tXXG2rY5lWz2QEx6XuHPOMa2poZajfTeUHJ+ZGwYmsxRyaGswwZfsDoyk0YDTmNgBuEPH9cbhuGUF1Y/Q289pGUM6HkAp8S5ocUpVJGZ9yjxtllJX4UTNS99jHI0qfCGgQ8YHaLhETY2UFGVZCKweX4M7D3e0ztpCxdP4bZG5R+sZAg0ToZpgLeHB9K2zx+uKqdoYhmQ4tcDh/+pF0bbvOU472ftf9CUfv34SZGU9M5ADI52tZIg+KcX8fwL+0mYjzgNZTRGTIsRakvyJhG6lKdTiDLARJtm+T2CmLBTV0R7aidYk7v4EVe+jUbSgpaFS2Z8FxYrgKnHENnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=IYkcX3ux1PIQ2AOJ0+yJOhpRIJLdTA93tiGrbVCnLwE=; b=Y4xUgyZ+4KPWT6oG3q+5AZ5zH+uD7lLXU9+alLhl4NssUif1nvIFOzSoomi0KZM9sskMchmUoLV1yn0avJk5cSrrNeFDADUmee5zTLsHZ8SFjM4gXvbmglRGURH7xwmId2zuxqDwrWFPLEIwecB4NaslPLe1ZTqdiD/cKMo8lYpG+ydQI7dXvma+5WLXfSEu7rLIkIBlQR/SltCQLbPcw0CshhSUH09qJG3f8APgB0vqfdT6qLwLsISCXSDA+cHIASsQDH8MZylpa8NwZ8DRLkPTx/a6/FZ4MqxeUc85UV9f+INeW5q6CLRbO0l3bn2vNcrjJIyfEvdEHGLvAP/m2A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=mellanox.com; dmarc=pass action=none header.from=mellanox.com; dkim=pass header.d=mellanox.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=IYkcX3ux1PIQ2AOJ0+yJOhpRIJLdTA93tiGrbVCnLwE=; b=i7fHjDrSCMh0dwViYMD4YEAqrPoefUXtPk+rdWtK4UVCUjq+GuanJwlCRpdbpb6DelZrX1PgJgh9FayihsKqZGC9C29Tjh25HVSAV+cABdcr3hSJoR48KUWn5g8G72DzuZtZnC9okYrYVpgvmkzCbpDuac/J45XJKXwVxaECTDc= Authentication-Results: dpdk.org; dkim=none (message not signed) header.d=none;dpdk.org; dmarc=none action=none header.from=mellanox.com; Received: from AM0PR05MB4209.eurprd05.prod.outlook.com (2603:10a6:208:61::22) by AM0PR05MB4625.eurprd05.prod.outlook.com (2603:10a6:208:b6::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.24; Tue, 14 Jul 2020 14:21:11 +0000 Received: from AM0PR05MB4209.eurprd05.prod.outlook.com ([fe80::3949:70c3:126:3972]) by AM0PR05MB4209.eurprd05.prod.outlook.com ([fe80::3949:70c3:126:3972%7]) with mapi id 15.20.3174.026; Tue, 14 Jul 2020 14:21:11 +0000 From: Ophir Munk To: dev@dpdk.org Cc: Raslan Darawsheh , Ophir Munk , Matan Azrad Date: Tue, 14 Jul 2020 14:20:56 +0000 Message-Id: <20200714142102.30606-3-ophirmu@mellanox.com> X-Mailer: git-send-email 2.8.4 In-Reply-To: <20200714142102.30606-1-ophirmu@mellanox.com> References: <20200714142102.30606-1-ophirmu@mellanox.com> Content-Type: text/plain X-ClientProxiedBy: AM3PR05CA0100.eurprd05.prod.outlook.com (2603:10a6:207:1::26) To AM0PR05MB4209.eurprd05.prod.outlook.com (2603:10a6:208:61::22) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mellanox.com (37.142.13.130) by AM3PR05CA0100.eurprd05.prod.outlook.com (2603:10a6:207:1::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.21 via Frontend Transport; Tue, 14 Jul 2020 14:21:10 +0000 X-Mailer: git-send-email 2.8.4 X-Originating-IP: [37.142.13.130] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 3cd431df-b717-4ff7-88b6-08d828012854 X-MS-TrafficTypeDiagnostic: AM0PR05MB4625: X-LD-Processed: a652971c-7d2e-4d9b-a6a4-d149256f461b,ExtFwd X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3383; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: D8L21QJ2Rd19F3n26JryKLbaPD7GlCMCr40C/0XFhk2RCMKXqc8HiTAjRulGae2tdyWYVjW9XHqUNy3wrZhxboVrqlvin64hk9x/mb3nfCRKV6Use8Sma4pRFhynINOviwi7pAB5k/Dg7DT7AzxbEZu9lRAvAQ9h1gxIHGVQspKecMaCuI+Boab+FEpJWQlqTACY/xGM27ZG+r8kmEuR8uR9xEqUmlv9etw2zgkIT3QyUKZ1Kaf4O3baWSWsFpI8wwvbzTjFLXTXDE6us8Vkdu/ORs9O5TH3k31/cDV+M93I9F1HiWq9spg3lnR+GTZQ1bRcclX52TPKx7tde9xX9Q== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM0PR05MB4209.eurprd05.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(4636009)(136003)(366004)(376002)(39850400004)(346002)(396003)(36756003)(86362001)(1076003)(8886007)(6666004)(66946007)(316002)(66476007)(52116002)(7696005)(5660300002)(26005)(66556008)(54906003)(478600001)(6916009)(83380400001)(16526019)(8676002)(8936002)(4326008)(956004)(2616005)(107886003)(2906002)(55016002)(186003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: TKkONIrTPOHRlNG/jc4sJGclUqe1DyWradKH//TSkobrC0iYdu6guW2/dW0I51+a66vbhMP56thn1BiVovJaN6IBYr5adF4ZW0wB7tofEALuzcfdJt79wO6mwx2k9XihIe7tzJzicN56jkmidkXwqgqbylBGUpe7tNKueN8H4NIK3yIj7sVR9Sz+rRJwEJBOA381FaBykFkjdxiIWMzloXxgFKNOa4kx3ppp4mc6oWWymmdTmLjj6kzgmrtPd921lnR14jNzPd3VjuMRzKHSTFHV9HArdkSgfM4PScc4MMlTZdnYJEZOKsXpECz2O2+L6epU3TThoaWtla5OmvYIdNgI0pstIVvCb+ulRHonz812XM4+i7mgMNVC37TL/G7eIbnHYZ6LQPvi9tKf1HAmRGLhWneeCAZb+l7zhsNRinMkvsVBFXptPCUlFgmKrvUQkN4jomdJS5vrTKByukxDUwt5ReVlu79KrVWUB4mvSXmRkUTq7x1pNKFc9BAQmvts X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3cd431df-b717-4ff7-88b6-08d828012854 X-MS-Exchange-CrossTenant-AuthSource: AM0PR05MB4209.eurprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jul 2020 14:21:11.1760 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: UNc76Aj/q8ZBjX8Op2X2MpyfOW65+rX3loZ9Xw2owB1n9NK2N48/P8vSJ80Us3EGMpmUZ1fgg8FYlQVaa49r7w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR05MB4625 Subject: [dpdk-dev] [PATCH v1 2/8] net/mlx5: replace Linux specific calls with rte API X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 Acked-by: Matan Azrad --- 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 #include +#include #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 #include #include -#include #include #include #include @@ -37,6 +36,7 @@ #include #include #include +#include #include #include @@ -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 #include #include -#include #include /* 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 #include #include +#include #include #include @@ -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 #include #include +#include #include #include @@ -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 #include #include -#include #include /* Verbs header. */ @@ -26,6 +25,7 @@ #include #include #include +#include #include #include @@ -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