From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR03-AM5-obe.outbound.protection.outlook.com (mail-eopbgr30057.outbound.protection.outlook.com [40.107.3.57]) by dpdk.org (Postfix) with ESMTP id C9FE01B64C for ; Thu, 2 Nov 2017 17:43:17 +0100 (CET) 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; bh=rYQqKmLVhUaO2mHsuQgESpFRMjlf6JchQFnXno8KnqI=; b=rKuaoP09PtLH5cRHCv7QfV5nRkNt9OWGwFGtXfQJ5xEyBALLfQUgSApDVPX9fLUX5kEJRM4X9uue4oGhzVLFoZn39okqrGsWZnGxmih9ET/erwRTJwp1yIaA6YYrguc4/O9MAosi2MJOM1RWAy8ShGd/SIEnBBRmxDTPk1Cw8Nk= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=matan@mellanox.com; Received: from mellanox.com (37.142.13.130) by HE1PR0502MB3659.eurprd05.prod.outlook.com (2603:10a6:7:85::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.197.13; Thu, 2 Nov 2017 16:43:15 +0000 From: Matan Azrad To: Adrien Mazarguil Cc: dev@dpdk.org, Ophir Munk Date: Thu, 2 Nov 2017 16:42:45 +0000 Message-Id: <1509640971-8637-3-git-send-email-matan@mellanox.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1509640971-8637-1-git-send-email-matan@mellanox.com> References: <1509358049-18854-1-git-send-email-matan@mellanox.com> <1509640971-8637-1-git-send-email-matan@mellanox.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [37.142.13.130] X-ClientProxiedBy: VI1PR0801CA0068.eurprd08.prod.outlook.com (2603:10a6:800:7d::12) To HE1PR0502MB3659.eurprd05.prod.outlook.com (2603:10a6:7:85::17) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 50d64a73-d394-440a-d1d9-08d52210d0ef X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(48565401081)(2017052603199); SRVR:HE1PR0502MB3659; X-Microsoft-Exchange-Diagnostics: 1; HE1PR0502MB3659; 3:jxopKqTGGZcjl/GS5HeD2rXjU+052D5GRGqM6VwUX9pr7iImw6Ftv1soiLzFC6PFuAaC2KcwlS79lfffZe2zTxJVUZqmOradqJr/QdK62snFAC37onczWee8+/noIe6trJWDSdAIfXKvkW06eiuhFEDWfrZc4CwPbyWv3yICqEEtSFdnaSAsMY0JJF+t6dJx6z6ix233sWucemb8LLOVcheaPJGAIGc0OwVdXR1cV9flCiUC1/VPWsxj3Qsl7bbr; 25:UWlQiYOOpV2sowSJ3K5Tal0vmEsYf3g8i8db0Yf+BL5Y08yHhIHmlRrsHk1aW6CRBAaPlPoYP38nqp9Gvept94CuavtO4RhhGtgH5cPDQL9xfD1+8esvOn+5sOLhWAxhl4D/Z2edH+kAWltS5gAlj8uxtpl5+SeJtV3z3zRIkoo6L6Te+DGOXK7Dg4TR45Z4x60qPzbtMvETaFVuSDIeJ2Z06C7p+fkxpVRk9zznrQu34MG8NNQiKuRS0L2yrGcVyFMKakSa23wS7UGMfe7ciYClRDnY1VVudSsqAVK5e7kcjiyWkquxqrPhc/AbAy3zLT5gyQQfFf8kG/Tdhqe2QA==; 31:P8Mz7lBqm6wOjLrRqM/2CNyB1mYHV6v3XF2/Tc4OHEeUlhRjyjWP/QxJSwuC8+Re+zq/vfyT33lxZGjBSXgBXfe/no54Hei2H+2LIQjNwnnVI0s6s+MeV9PmEfimVPn5bamwDaP4pqXing0AaOEcieDHWemXkdW9jGrapC8me4XQtsr0wqvtr2y3ogYcsS2B19YfOkVrIRw9NjNWjw70Lu/icCGCVNZA5/IOwe8GYDc= X-MS-TrafficTypeDiagnostic: HE1PR0502MB3659: X-LD-Processed: a652971c-7d2e-4d9b-a6a4-d149256f461b,ExtAddr X-Microsoft-Exchange-Diagnostics: 1; HE1PR0502MB3659; 20:9dRKz9f+6/aD+RigbuXhutzTyQZQU/oj1kzvjm5qV/YGqspwG4GrMWHaSadYOpptA5Dtx3HgUGs3K8lQN790nf4GXZJWWXI0lkSU322QcSsevH415qbj5SgCSthN0szryPb6eWUc2SuG9goR7gD8AIKyNATXIa7imiDwsx5bgBaJP8zn420FY+4QhqGLfs2SE2oldz+1BZxTHzFHWTtr/qym9wefPH5coI4Xe4rZgnPMI8QGb4D9hQdT+qTUqFdisWhz0VlZ1OXb9wVVUtwqa7pze11n2HrbAjf0N+iFIqLNd/+0GtDniqcWIE6XMBHt7883hEugKj0mfubZntn/EBrRY7YPjWUSi2Ow2KQB7QGK3iMY0t3zFUaglByTvOJBdkTtjM2atGN04Syypw9ayR1Ovxxu82vrvYRBRZHblOL3FqdzNC6bH/h7XvOtY6psca4pwGcLXM8GgkVWR/rGQM2RrvsPB7/xzTk51nvOqtaDwHM/1GA+pP8+Hg6D212a; 4:NfpSBNu3HXidkIC8faHQk+eZGIVZoTD1suj54cpulaGZXYZCZMe+nXrc2ZhGGCF+FVswiqrbfM3LZ3PkFyTUXT7L6HFC95vJSwzpMb9g7TlLAVN2Ki1ooN/Lu93dTt8TjMqx1KkKctl+cSc9rKlX2Mqs1/XgcFoG2LI/UDcxM3qdyP+l4xx3EH+Jtf8v/DIUK9dXx8a7xjy7QRhiIhQkekZjyCH3Q0DKbqenOV3WiFblC/phK2AjsahweTropOJMjRgfh4qQHobvZza4YYGhWg== X-Exchange-Antispam-Report-Test: UriScan:; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(2401047)(5005006)(8121501046)(10201501046)(3231020)(93006095)(93001095)(3002001)(100000703101)(100105400095)(6055026)(6041248)(20161123560025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123558100)(20161123555025)(20161123564025)(20161123562025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:HE1PR0502MB3659; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:HE1PR0502MB3659; X-Forefront-PRVS: 047999FF16 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(376002)(346002)(39860400002)(189002)(199003)(16586007)(50226002)(316002)(106356001)(105586002)(101416001)(21086003)(25786009)(8936002)(478600001)(4720700003)(8676002)(81156014)(189998001)(36756003)(33026002)(81166006)(97736004)(4326008)(5003940100001)(2906002)(55016002)(68736007)(33646002)(5660300001)(305945005)(107886003)(7736002)(50466002)(53936002)(48376002)(66066001)(16526018)(2950100002)(6916009)(6666003)(50986999)(47776003)(76176999)(3846002)(86362001)(69596002)(575784001)(6116002); DIR:OUT; SFP:1101; SCL:1; SRVR:HE1PR0502MB3659; H:mellanox.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; HE1PR0502MB3659; 23:368K099UXWdB55ZjNTeKQQgWSkIGBftpSoyNHCT?= =?us-ascii?Q?s/3S9pmwebDwmrCM4jSUAlfEAqRoziIj4C7dlfJv4HPzsMeLJxaYzO+cQZ+c?= =?us-ascii?Q?hM7Ga31beN/KRA/qCfEPRLjby/UlzSNt7Pfa6WOAV1Mo2I7e+SAKMCqQ+4g1?= =?us-ascii?Q?hXroG+LppXsxd6mhDDYETSoyjBWogI/EWqihGISEI2NzcW4fcaOL/mtIZ9N6?= =?us-ascii?Q?CVnreOHa3wbIV4K4N8zwXCM+I780TvphOgJWdHUYysbLYaikZ/+BIMASrIBi?= =?us-ascii?Q?GixLT+37wFPMo8itz8LRrPJ8E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7cEGJvIyx9c8=3D?= X-Microsoft-Exchange-Diagnostics: 1; HE1PR0502MB3659; 6:VAWLN4J14Po6NLgWbToTFPIEbLSWpm1650mfPDXj8f2ABBMeUU+7EpgDb+Gf4CrMLxmSx1M7xb4QMycUUE87wvUBLueqpqMDgsNF0frOHoQxm22FFCdD+Ntc1BJ1kKXCcUnIG7tl0k86fVRqalT5hPSkAspbHgm8K5QpKkbrUYxCCL/4aMRm9cSyIO2yE2SSQBDd0y3uYq6DgnmBmsde7xjPj++ZXigrlKklENnNxzEDHzQF83E3anTEShnW2c+sA4wt/gC/ATOsFL5UK38IPZZTN9rWaqxVS7Hi3ZRp2Ezr9QXxf/VDuCeAfxf91KLX1zU85WCA4zgDauIGH/gpCTOU0Zppwa7cfFighyXYM6c=; 5:oCaduq4RSNfAIOGYvHvm2Etv1dK8ZqumbSAkjuR5DAna3OPf5lio6OuiGqBxdUu0nbLRiHy6Z18gtwzmxV250ULMWMbcliJIeZsoxSRzSSvl9RDACkLnXpDBX/IojWy0uc1blNg8C81f1gIzSCzUD2Fsc0nFCT7BBOSbV2eE8so=; 24:JcNwmUkd3LmW0TiEVbTCMnQCjTIq0F/5+sG9/FF94H/XxkMQq4QYi2R6DaMczJcoNy7POipczmXVQGqYu6MHTdnDj05LhYYa5Va7r4ORC94=; 7:PDD/yD8j8XlxEhQTvAEWX/TsST904ki/CtzBd2jS/2oijZv1NHadFgwFNg0I4EYZQcYhAJqk0X9wnOJJoLqphT0RpRgg0L+TxS4Tiy+SU+rNYZjPU5av+ViHhy5E7meg5+GI7NAKuU8a8ArLkZsz9UAnsJO/+rqmdHP2X8YkVsYSbqcilx2KOOiBlhJzubsaZwpzyaHNvcS5rs8SlAzmj1KeXZzW3qwUKYoMAsQUek413GAaIls9NgAGb303aHzU SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Nov 2017 16:43:15.5335 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 50d64a73-d394-440a-d1d9-08d52210d0ef X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0502MB3659 Subject: [dpdk-dev] [PATCH v5 2/8] net/mlx4: associate MR to MP in a short function 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: , X-List-Received-Date: Thu, 02 Nov 2017 16:43:18 -0000 From: Ophir Munk Associate memory region to mempool (on data path) in a short function. Handle the less common case of adding a new memory region to mempool in a separate function. Signed-off-by: Ophir Munk Acked-by: Adrien Mazarguil --- drivers/net/mlx4/mlx4.h | 2 ++ drivers/net/mlx4/mlx4_mr.c | 50 ++++++++++++++++++++++++++++++++++++++ drivers/net/mlx4/mlx4_rxtx.c | 58 -------------------------------------------- drivers/net/mlx4/mlx4_rxtx.h | 31 ++++++++++++++++++++++- 4 files changed, 82 insertions(+), 59 deletions(-) diff --git a/drivers/net/mlx4/mlx4.h b/drivers/net/mlx4/mlx4.h index e0a9853..70cf453 100644 --- a/drivers/net/mlx4/mlx4.h +++ b/drivers/net/mlx4/mlx4.h @@ -160,5 +160,7 @@ int mlx4_flow_ctrl_set(struct rte_eth_dev *dev, /* mlx4_mr.c */ struct ibv_mr *mlx4_mp2mr(struct ibv_pd *pd, struct rte_mempool *mp); +uint32_t mlx4_txq_add_mr(struct txq *txq, struct rte_mempool *mp, + uint32_t i); #endif /* RTE_PMD_MLX4_H_ */ diff --git a/drivers/net/mlx4/mlx4_mr.c b/drivers/net/mlx4/mlx4_mr.c index 9700884..8105cc5 100644 --- a/drivers/net/mlx4/mlx4_mr.c +++ b/drivers/net/mlx4/mlx4_mr.c @@ -36,7 +36,9 @@ * Memory management functions for mlx4 driver. */ +#include #include +#include #include #include #include @@ -50,11 +52,13 @@ #pragma GCC diagnostic error "-Wpedantic" #endif +#include #include #include #include #include +#include "mlx4_rxtx.h" #include "mlx4_utils.h" struct mlx4_check_mempool_data { @@ -181,3 +185,49 @@ struct ibv_mr * rte_errno = errno ? errno : EINVAL; return mr; } + +/** + * Add memory region (MR) <-> memory pool (MP) association to txq->mp2mr[]. + * If mp2mr[] is full, remove an entry first. + * + * @param txq + * Pointer to Tx queue structure. + * @param[in] mp + * Memory pool for which a memory region lkey must be added. + * @param[in] i + * Index in memory pool (MP) where to add memory region (MR). + * + * @return + * Added mr->lkey on success, (uint32_t)-1 on failure. + */ +uint32_t +mlx4_txq_add_mr(struct txq *txq, struct rte_mempool *mp, uint32_t i) +{ + struct ibv_mr *mr; + + /* Add a new entry, register MR first. */ + DEBUG("%p: discovered new memory pool \"%s\" (%p)", + (void *)txq, mp->name, (void *)mp); + mr = mlx4_mp2mr(txq->priv->pd, mp); + if (unlikely(mr == NULL)) { + DEBUG("%p: unable to configure MR, ibv_reg_mr() failed.", + (void *)txq); + return (uint32_t)-1; + } + if (unlikely(i == RTE_DIM(txq->mp2mr))) { + /* Table is full, remove oldest entry. */ + DEBUG("%p: MR <-> MP table full, dropping oldest entry.", + (void *)txq); + --i; + claim_zero(ibv_dereg_mr(txq->mp2mr[0].mr)); + memmove(&txq->mp2mr[0], &txq->mp2mr[1], + (sizeof(txq->mp2mr) - sizeof(txq->mp2mr[0]))); + } + /* Store the new entry. */ + txq->mp2mr[i].mp = mp; + txq->mp2mr[i].mr = mr; + txq->mp2mr[i].lkey = mr->lkey; + DEBUG("%p: new MR lkey for MP \"%s\" (%p): 0x%08" PRIu32, + (void *)txq, mp->name, (void *)mp, txq->mp2mr[i].lkey); + return txq->mp2mr[i].lkey; +} diff --git a/drivers/net/mlx4/mlx4_rxtx.c b/drivers/net/mlx4/mlx4_rxtx.c index 79c7fa2..f1c8dae 100644 --- a/drivers/net/mlx4/mlx4_rxtx.c +++ b/drivers/net/mlx4/mlx4_rxtx.c @@ -37,7 +37,6 @@ */ #include -#include #include #include @@ -239,63 +238,6 @@ struct pv { } /** - * Get memory region (MR) <-> memory pool (MP) association from txq->mp2mr[]. - * Add MP to txq->mp2mr[] if it's not registered yet. If mp2mr[] is full, - * remove an entry first. - * - * @param txq - * Pointer to Tx queue structure. - * @param[in] mp - * Memory pool for which a memory region lkey must be returned. - * - * @return - * mr->lkey on success, (uint32_t)-1 on failure. - */ -uint32_t -mlx4_txq_mp2mr(struct txq *txq, struct rte_mempool *mp) -{ - unsigned int i; - struct ibv_mr *mr; - - for (i = 0; (i != RTE_DIM(txq->mp2mr)); ++i) { - if (unlikely(txq->mp2mr[i].mp == NULL)) { - /* Unknown MP, add a new MR for it. */ - break; - } - if (txq->mp2mr[i].mp == mp) { - assert(txq->mp2mr[i].lkey != (uint32_t)-1); - assert(txq->mp2mr[i].mr->lkey == txq->mp2mr[i].lkey); - return txq->mp2mr[i].lkey; - } - } - /* Add a new entry, register MR first. */ - DEBUG("%p: discovered new memory pool \"%s\" (%p)", - (void *)txq, mp->name, (void *)mp); - mr = mlx4_mp2mr(txq->priv->pd, mp); - if (unlikely(mr == NULL)) { - DEBUG("%p: unable to configure MR, ibv_reg_mr() failed.", - (void *)txq); - return (uint32_t)-1; - } - if (unlikely(i == RTE_DIM(txq->mp2mr))) { - /* Table is full, remove oldest entry. */ - DEBUG("%p: MR <-> MP table full, dropping oldest entry.", - (void *)txq); - --i; - claim_zero(ibv_dereg_mr(txq->mp2mr[0].mr)); - memmove(&txq->mp2mr[0], &txq->mp2mr[1], - (sizeof(txq->mp2mr) - sizeof(txq->mp2mr[0]))); - } - /* Store the new entry. */ - txq->mp2mr[i].mp = mp; - txq->mp2mr[i].mr = mr; - txq->mp2mr[i].lkey = mr->lkey; - DEBUG("%p: new MR lkey for MP \"%s\" (%p): 0x%08" PRIu32, - (void *)txq, mp->name, (void *)mp, txq->mp2mr[i].lkey); - return txq->mp2mr[i].lkey; -} - -/** * Posts a single work request to a send queue. * * @param txq diff --git a/drivers/net/mlx4/mlx4_rxtx.h b/drivers/net/mlx4/mlx4_rxtx.h index 7d67748..185dbdf 100644 --- a/drivers/net/mlx4/mlx4_rxtx.h +++ b/drivers/net/mlx4/mlx4_rxtx.h @@ -165,7 +165,6 @@ int mlx4_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, /* mlx4_rxtx.c */ -uint32_t mlx4_txq_mp2mr(struct txq *txq, struct rte_mempool *mp); uint16_t mlx4_tx_burst(void *dpdk_txq, struct rte_mbuf **pkts, uint16_t pkts_n); uint16_t mlx4_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts, @@ -182,4 +181,34 @@ int mlx4_tx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, const struct rte_eth_txconf *conf); void mlx4_tx_queue_release(void *dpdk_txq); +/** + * Get memory region (MR) <-> memory pool (MP) association from txq->mp2mr[]. + * Call mlx4_txq_add_mr() if MP is not registered yet. + * + * @param txq + * Pointer to Tx queue structure. + * @param[in] mp + * Memory pool for which a memory region lkey must be returned. + * + * @return + * mr->lkey on success, (uint32_t)-1 on failure. + */ +static inline uint32_t +mlx4_txq_mp2mr(struct txq *txq, struct rte_mempool *mp) +{ + unsigned int i; + + for (i = 0; (i != RTE_DIM(txq->mp2mr)); ++i) { + if (unlikely(txq->mp2mr[i].mp == NULL)) { + /* Unknown MP, add a new MR for it. */ + break; + } + if (txq->mp2mr[i].mp == mp) { + /* MP found MP. */ + return txq->mp2mr[i].lkey; + } + } + return mlx4_txq_add_mr(txq, mp, i); +} + #endif /* MLX4_RXTX_H_ */ -- 1.8.3.1