From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 14504A04FF; Tue, 24 May 2022 17:21:48 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 652C642B9A; Tue, 24 May 2022 17:21:35 +0200 (CEST) Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2048.outbound.protection.outlook.com [40.107.237.48]) by mails.dpdk.org (Postfix) with ESMTP id 760E142B9A for ; Tue, 24 May 2022 17:21:34 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ly4np/xmbBdK4tXd4XR8zEqvsHBApwTLHka/OIb/sprFvFyqAJFQQMklBvOfaGmgk+sYYHyAaIvep42Ik8NN8Ebi7KRNK7DhUZXkIK6fDN99SW+E40hli5jMjjJEX4Sy7Pal5YDtgCruurLHLXp+a8ztnTbge4yCAV/mSrQhoOSczzxsoVel8SyIZF5Sen5QqfyhoId39M01w17w8ELG3sJJWeAvi/RLMHrsRJz3i+NVcWkdhKKr+tt+UQRXRvJe4EsGZtq+xvUO5N/BN8bgaSdsbCQGz1TCScmaIXe83OZo1KFzBthCF9xXkDdmGz289bfMbfX2lQWAoc08zfPoow== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=/wyChl4TO7LAyMJDTcBUROD0teiH9HC5ovOe0zn5JMo=; b=IHyBfH/BKxb3sMayr3xgABdW0i0V9EOlrocxO9iWrwd+H+U+gW5tLGqjDr0saLW/gg+xulGC93806O98hBDzh7wChWGmzHZDryaH9O8m0NN/c/8LyGdeLgd7UZhyyOYCp4UmhJkZozhxK/vRD/vTyvjYwadArKslyWPbVXNWyIjVHRnrFHi9pUHWahENjayWeRnaeiCN26uja44fAqPf7qHi22hboWLQFuJ2/ALikFkoMwINfqlB7A6G7O/V1w/GYs8YIUtQoxoqvPsXGXQvmzjRV1Tx+VQR4+ABefyChloiOiwZWxfuMWFY46ktR4gBIu/133iF17/uaNVSKuR4Iw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.234) smtp.rcpttodomain=dpdk.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=/wyChl4TO7LAyMJDTcBUROD0teiH9HC5ovOe0zn5JMo=; b=Al2p5McYrnMjTn+HmR0vqghj9UbqZsg2/15Z2lVI7/oJSPnOXV9ejBtCSwSLBwY6qMBiGOt3g8UCkYA4LTcu13rQljAe4c6/4XeidTVhXBpClUdnck7fr/YpLAqRMWSQ1tgGmRQN109djw8GCWtLoeKYlw85QyiJu44L3CbalablE3w14XggB9/b88m/u4VCClrmyryzNvLr8EdThz4HJ4gkZYv6Pt9/XISG5zMaHc0r93yTOPb8FXt11B20Gog8BHw2y8cAaqdwyDui8ulVus1kZdrT8hcAae546Z88ZPG9/PefZs3Brt0tGbIueBTSUhGaos5UJ4HAzVPuoww0kg== Received: from CO2PR05CA0096.namprd05.prod.outlook.com (2603:10b6:104:1::22) by DS0PR12MB6630.namprd12.prod.outlook.com (2603:10b6:8:d2::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5293.13; Tue, 24 May 2022 15:21:33 +0000 Received: from CO1NAM11FT009.eop-nam11.prod.protection.outlook.com (2603:10b6:104:1:cafe::c2) by CO2PR05CA0096.outlook.office365.com (2603:10b6:104:1::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5293.13 via Frontend Transport; Tue, 24 May 2022 15:21:33 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.234) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 12.22.5.234 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.234; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (12.22.5.234) by CO1NAM11FT009.mail.protection.outlook.com (10.13.175.61) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5273.14 via Frontend Transport; Tue, 24 May 2022 15:21:32 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by DRHQMAIL101.nvidia.com (10.27.9.10) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Tue, 24 May 2022 15:21:10 +0000 Received: from nvidia.com (10.126.231.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Tue, 24 May 2022 08:21:07 -0700 From: Spike Du To: , , , CC: , Subject: [PATCH v3 5/7] net/mlx5: support Rx queue based limit watermark Date: Tue, 24 May 2022 18:20:39 +0300 Message-ID: <20220524152041.737154-6-spiked@nvidia.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220524152041.737154-1-spiked@nvidia.com> References: <20220522055900.417282-1-spiked@nvidia.com> <20220524152041.737154-1-spiked@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.126.231.35] X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: cbf83dc3-1e93-4d05-198e-08da3d9915c1 X-MS-TrafficTypeDiagnostic: DS0PR12MB6630:EE_ X-LD-Processed: 43083d15-7273-40c1-b7db-39efd9ccc17a,ExtAddr X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: qq2tLOJ6TaErpTHqwogVyVfteiY9B/honNd7vq6Fh5ki40lM1rkt65uXrvDb5zSJDA2blyrFoU3ceOinNtqmSgDO95CrkvhbFwY0ezeZQ9KnpcQ4xZQTjV84c1yWkLNgMXodrdQNuPA1h/7z1r3jVYHg841wnQAAtXcUsSCvc9GYHCJV7Js5O7wt05HcDS7oZkSPeK1/MzbVw3b//8vCVYTNYpaH1iPacHgFNHwYOdug5XpYvK6VzEzP18xxlLjnml0AEZ6GSTEjr5zu7ZO+H1laUeWOPJwgJdBc2f1tMgVnL+tlgBx3hAW5khTTOZp/HU7fLlbaEeRIYQDvNMkY8bW69Iq1o8c5+jwbl3Oxfio/2C2j09mkR9lcckeiDML8lsE5cL3/0cfOFKnvZcAbNND+ysQs1Y69NSXsLrZXtELYxJruiuws2axsQ8M+p3sFJ5jkmtGdLx4GDEu2xv6Ru0HGhkaeEbe6vaIuVGHdgT5KUQzBAJ3P7DwFD35VHK6DO7/7hjrHgEZWMvMG2YvsAK1hBAXc3HK8GEjzhuz3PdHhlAU0F+ol+gSnEd8JqcCA0vwnbK+wRo+5YPPAxIo7ObGVcUc7lBWAaXmaDERwrJkAgpJSUm/0z83V2caOEsEqN3hsjhVc+hed+dP7ET4Xm6KB8Cuxo9eJwbgbQ3JK6JgDSRu1kJnGvhOs4JoKKWHd+FN5wip6HwbbTgzeCpiIeQ== X-Forefront-Antispam-Report: CIP:12.22.5.234; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:InfoNoRecords; CAT:NONE; SFS:(13230001)(4636009)(36840700001)(40470700004)(46966006)(5660300002)(54906003)(55016003)(110136005)(6666004)(316002)(2906002)(86362001)(8936002)(508600001)(356005)(40460700003)(81166007)(70206006)(70586007)(4326008)(8676002)(107886003)(36860700001)(336012)(1076003)(47076005)(426003)(16526019)(186003)(2616005)(26005)(83380400001)(7696005)(6286002)(82310400005)(36756003)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 May 2022 15:21:32.9363 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: cbf83dc3-1e93-4d05-198e-08da3d9915c1 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[12.22.5.234]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT009.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB6630 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Add mlx5 specific LWM(limit watermark) configuration and query handler. While the Rx queue fullness reaches the LWM limit, the driver catches an HW event and invokes the user callback. The query handler finds the next RX queue with pending LWM event if any, starting from the given RX queue index. Signed-off-by: Spike Du --- doc/guides/nics/mlx5.rst | 12 ++ doc/guides/rel_notes/release_22_07.rst | 1 + drivers/common/mlx5/mlx5_prm.h | 1 + drivers/net/mlx5/mlx5.c | 2 + drivers/net/mlx5/mlx5_rx.c | 156 +++++++++++++++++++++++++ drivers/net/mlx5/mlx5_rx.h | 5 + 6 files changed, 177 insertions(+) diff --git a/doc/guides/nics/mlx5.rst b/doc/guides/nics/mlx5.rst index d83c56de11..79f56018ef 100644 --- a/doc/guides/nics/mlx5.rst +++ b/doc/guides/nics/mlx5.rst @@ -93,6 +93,7 @@ Features - Connection tracking. - Sub-Function representors. - Sub-Function. +- Rx queue LWM (Limit WaterMark) configuration. Limitations @@ -520,6 +521,9 @@ Limitations - The NIC egress flow rules on representor port are not supported. +- LWM: + + - Doesn't support shared Rx queue and Hairpin Rx queue. Statistics ---------- @@ -1680,3 +1684,11 @@ The procedure below is an example of using a ConnectX-5 adapter card (pf0) with #. For each VF PCIe, using the following command to bind the driver:: $ echo "0000:82:00.2" >> /sys/bus/pci/drivers/mlx5_core/bind + +LWM introduction +---------------- + +LWM (Limit WaterMark) is a per Rx queue attribute, it should be configured as +a percentage of the Rx queue size. +When Rx queue fullness is above LWM, an event is sent to PMD. + diff --git a/doc/guides/rel_notes/release_22_07.rst b/doc/guides/rel_notes/release_22_07.rst index 0ed4f92820..34f86eaffa 100644 --- a/doc/guides/rel_notes/release_22_07.rst +++ b/doc/guides/rel_notes/release_22_07.rst @@ -89,6 +89,7 @@ New Features * Added support for promiscuous mode on Windows. * Added support for MTU on Windows. * Added matching and RSS on IPsec ESP. + * Added Rx queue LWM(Limit WaterMark) support. * **Updated Marvell cnxk crypto driver.** diff --git a/drivers/common/mlx5/mlx5_prm.h b/drivers/common/mlx5/mlx5_prm.h index 630b2c5100..3b5e60532a 100644 --- a/drivers/common/mlx5/mlx5_prm.h +++ b/drivers/common/mlx5/mlx5_prm.h @@ -3293,6 +3293,7 @@ struct mlx5_aso_wqe { enum { MLX5_EVENT_TYPE_OBJECT_CHANGE = 0x27, + MLX5_EVENT_TYPE_SRQ_LIMIT_REACHED = 0x14, }; enum { diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c index e04a66625e..35ae51b3af 100644 --- a/drivers/net/mlx5/mlx5.c +++ b/drivers/net/mlx5/mlx5.c @@ -2071,6 +2071,8 @@ const struct eth_dev_ops mlx5_dev_ops = { .dev_supported_ptypes_get = mlx5_dev_supported_ptypes_get, .vlan_filter_set = mlx5_vlan_filter_set, .rx_queue_setup = mlx5_rx_queue_setup, + .rx_queue_lwm_set = mlx5_rx_queue_lwm_set, + .rx_queue_lwm_query = mlx5_rx_queue_lwm_query, .rx_hairpin_queue_setup = mlx5_rx_hairpin_queue_setup, .tx_queue_setup = mlx5_tx_queue_setup, .tx_hairpin_queue_setup = mlx5_tx_hairpin_queue_setup, diff --git a/drivers/net/mlx5/mlx5_rx.c b/drivers/net/mlx5/mlx5_rx.c index 7d556c2b45..406eae9b39 100644 --- a/drivers/net/mlx5/mlx5_rx.c +++ b/drivers/net/mlx5/mlx5_rx.c @@ -19,12 +19,14 @@ #include #include #include +#include #include "mlx5_autoconf.h" #include "mlx5_defs.h" #include "mlx5.h" #include "mlx5_utils.h" #include "mlx5_rxtx.h" +#include "mlx5_devx.h" #include "mlx5_rx.h" @@ -128,6 +130,17 @@ mlx5_rx_descriptor_status(void *rx_queue, uint16_t offset) return RTE_ETH_RX_DESC_AVAIL; } +/* Get rxq lwm percentage according to lwm number. */ +static uint8_t +mlx5_rxq_lwm_to_percentage(struct mlx5_rxq_priv *rxq) +{ + struct mlx5_rxq_data *rxq_data = &rxq->ctrl->rxq; + uint32_t wqe_cnt = 1 << rxq_data->elts_n; + + /* ethdev LWM describes fullness, mlx5 LWM describes emptiness. */ + return rxq->lwm ? (100 - rxq->lwm * 100 / wqe_cnt) : 0; +} + /** * DPDK callback to get the RX queue information. * @@ -150,6 +163,7 @@ mlx5_rxq_info_get(struct rte_eth_dev *dev, uint16_t rx_queue_id, { struct mlx5_rxq_ctrl *rxq_ctrl = mlx5_rxq_ctrl_get(dev, rx_queue_id); struct mlx5_rxq_data *rxq = mlx5_rxq_data_get(dev, rx_queue_id); + struct mlx5_rxq_priv *rxq_priv = mlx5_rxq_get(dev, rx_queue_id); if (!rxq) return; @@ -169,6 +183,8 @@ mlx5_rxq_info_get(struct rte_eth_dev *dev, uint16_t rx_queue_id, qinfo->nb_desc = mlx5_rxq_mprq_enabled(rxq) ? RTE_BIT32(rxq->elts_n) * RTE_BIT32(rxq->log_strd_num) : RTE_BIT32(rxq->elts_n); + qinfo->lwm = rxq_priv ? + mlx5_rxq_lwm_to_percentage(rxq_priv) : 0; } /** @@ -1188,6 +1204,34 @@ mlx5_check_vec_rx_support(struct rte_eth_dev *dev __rte_unused) return -ENOTSUP; } +int +mlx5_rx_queue_lwm_query(struct rte_eth_dev *dev, + uint16_t *queue_id, uint8_t *lwm) +{ + struct mlx5_priv *priv = dev->data->dev_private; + unsigned int rxq_id, found = 0, n; + struct mlx5_rxq_priv *rxq; + + if (!queue_id) + return -EINVAL; + /* Query all the Rx queues of the port in a circular way. */ + for (rxq_id = *queue_id, n = 0; n < priv->rxqs_n; n++) { + rxq = mlx5_rxq_get(dev, rxq_id); + if (rxq && rxq->lwm_event_pending) { + pthread_mutex_lock(&priv->sh->lwm_config_lock); + rxq->lwm_event_pending = 0; + pthread_mutex_unlock(&priv->sh->lwm_config_lock); + *queue_id = rxq_id; + found = 1; + if (lwm) + *lwm = mlx5_rxq_lwm_to_percentage(rxq); + break; + } + rxq_id = (rxq_id + 1) % priv->rxqs_n; + } + return found; +} + /** * Rte interrupt handler for LWM event. * It first checks if the event arrives, if so process the callback for @@ -1220,3 +1264,115 @@ mlx5_dev_interrupt_handler_lwm(void *args) } rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_RX_LWM, NULL); } + +/** + * DPDK callback to arm an Rx queue LWM(limit watermark) event. + * While the Rx queue fullness reaches the LWM limit, the driver catches + * an HW event and invokes the user event callback. + * After the last event handling, the user needs to call this API again + * to arm an additional event. + * + * @param dev + * Pointer to the device structure. + * @param[in] rx_queue_id + * Rx queue identificator. + * @param[in] lwm + * The LWM value, is defined by a percentage of the Rx queue size. + * [1-99] to set a new LWM (update the old value). + * 0 to unarm the event. + * + * @return + * 0 : operation success. + * Otherwise: + * - ENOMEM - not enough memory to create LWM event channel. + * - EINVAL - the input Rxq is not created by devx. + * - E2BIG - lwm is bigger than 99. + */ +int +mlx5_rx_queue_lwm_set(struct rte_eth_dev *dev, uint16_t rx_queue_id, + uint8_t lwm) +{ + struct mlx5_priv *priv = dev->data->dev_private; + uint16_t port_id = PORT_ID(priv); + struct mlx5_rxq_priv *rxq = mlx5_rxq_get(dev, rx_queue_id); + uint16_t event_nums[1] = {MLX5_EVENT_TYPE_SRQ_LIMIT_REACHED}; + struct mlx5_rxq_data *rxq_data; + uint32_t wqe_cnt; + uint64_t cookie; + int ret = 0; + + if (!rxq) { + rte_errno = EINVAL; + return -rte_errno; + } + rxq_data = &rxq->ctrl->rxq; + /* Ensure the Rq is created by devx. */ + if (priv->obj_ops.rxq_obj_new != devx_obj_ops.rxq_obj_new) { + rte_errno = EINVAL; + return -rte_errno; + } + if (lwm > 99) { + DRV_LOG(WARNING, "Too big LWM configuration."); + rte_errno = E2BIG; + return -rte_errno; + } + /* Start config LWM. */ + pthread_mutex_lock(&priv->sh->lwm_config_lock); + if (rxq->lwm == 0 && lwm == 0) { + /* Both old/new values are 0, do nothing. */ + ret = 0; + goto end; + } + wqe_cnt = 1 << rxq_data->elts_n; + if (lwm) { + if (!priv->sh->devx_channel_lwm) { + ret = mlx5_lwm_setup(priv); + if (ret) { + DRV_LOG(WARNING, + "Failed to create shared_lwm."); + rte_errno = ENOMEM; + ret = -rte_errno; + goto end; + } + } + if (!rxq->lwm_devx_subscribed) { + cookie = ((uint32_t) + (port_id << LWM_COOKIE_PORTID_OFFSET)) | + (rx_queue_id << LWM_COOKIE_RXQID_OFFSET); + ret = mlx5_os_devx_subscribe_devx_event + (priv->sh->devx_channel_lwm, + rxq->devx_rq.rq->obj, + sizeof(event_nums), + event_nums, + cookie); + if (ret) { + rte_errno = rte_errno ? rte_errno : EINVAL; + ret = -rte_errno; + goto end; + } + rxq->lwm_devx_subscribed = 1; + } + } + /* The ethdev LWM describes fullness, mlx5 lwm describes emptiness. */ + if (lwm) + lwm = 100 - lwm; + /* Save LWM to rxq and send modify_rq devx command. */ + rxq->lwm = lwm * wqe_cnt / 100; + /* Prevent integer division loss when switch lwm number to percentage. */ + if (lwm && (lwm * wqe_cnt % 100)) { + rxq->lwm = ((uint32_t)(rxq->lwm + 1) >= wqe_cnt) ? + rxq->lwm : (rxq->lwm + 1); + } + if (lwm && !rxq->lwm) { + /* With mprq, wqe_cnt may be < 100. */ + DRV_LOG(WARNING, "Too small LWM configuration."); + rte_errno = EINVAL; + ret = -rte_errno; + goto end; + } + ret = mlx5_devx_modify_rq(rxq, MLX5_RXQ_MOD_RDY2RDY); +end: + pthread_mutex_unlock(&priv->sh->lwm_config_lock); + return ret; +} + diff --git a/drivers/net/mlx5/mlx5_rx.h b/drivers/net/mlx5/mlx5_rx.h index 068dff5863..e078aaf3dc 100644 --- a/drivers/net/mlx5/mlx5_rx.h +++ b/drivers/net/mlx5/mlx5_rx.h @@ -177,6 +177,7 @@ struct mlx5_rxq_priv { uint32_t hairpin_status; /* Hairpin binding status. */ uint32_t lwm:16; uint32_t lwm_event_pending:1; + uint32_t lwm_devx_subscribed:1; }; /* External RX queue descriptor. */ @@ -297,6 +298,10 @@ int mlx5_rx_burst_mode_get(struct rte_eth_dev *dev, uint16_t rx_queue_id, struct rte_eth_burst_mode *mode); int mlx5_get_monitor_addr(void *rx_queue, struct rte_power_monitor_cond *pmc); void mlx5_dev_interrupt_handler_lwm(void *args); +int mlx5_rx_queue_lwm_set(struct rte_eth_dev *dev, uint16_t rx_queue_id, + uint8_t lwm); +int mlx5_rx_queue_lwm_query(struct rte_eth_dev *dev, uint16_t *rx_queue_id, + uint8_t *lwm); /* Vectorized version of mlx5_rx.c */ int mlx5_rxq_check_vec_support(struct mlx5_rxq_data *rxq_data); -- 2.27.0