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 36A2143C2C; Wed, 28 Feb 2024 18:02:36 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 80BE042F47; Wed, 28 Feb 2024 18:01:54 +0100 (CET) Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2058.outbound.protection.outlook.com [40.107.223.58]) by mails.dpdk.org (Postfix) with ESMTP id DEB9942F23 for ; Wed, 28 Feb 2024 18:01:50 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GERmOGwTzcwWT8/ZX0daPDEJcibDpzJOUyUdnvpgXf3zDfkQ3Cpu8CjMSECHgEtHqJ/P2MoLZGVQmq7+Y0XaCNZBcVgOAdu+heZophPd4R1dUOCheaGE9gJwfD3hgXBqBVlfON8mHG1ha4SlgPZ3wqe8CoUqWiKaFpd7P9ZQZ15liXT0Wkv1fIicwjRrHLNdYn04+QUJaTr+ROVKSw18BJ0SwhDA9/p9tluRyXTbfNGi4MKSruiJPlWL0KmrnmECYwY2sUjem9rhRmo4JJQMHj5jZeXLjuShAg+9Han/zkEzeuu0cFzKa586yCArBa3MuxlGY+vZZD13F0NfiJCnVA== 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=85oW0FR/VaKiJuUnu05JCYmxaQKgpt/mHqhNNZ5fGl0=; b=H93bq2weimiEY/a+5jOEFZaN5Hl+eumc2pxbcJ0yWxFlI88YU7oncBNgib1pZYPzK6pMngViC00HhqN/PC6imGTkrSuullNz5+jbtbMhvm5z+x5TU7OE1BFb8uQHgNz7vrMbQWfLYuGByfL4j4YOk/vulEZNGqYho0GgdwoD+UIf/mc/whMCPgBDLbkxO4UPR2Puit2+vjZgTetXYCS9Gu3zzdqGGErzeNIv9pJgGJcNbIA3RSDR7ZcNWY40LoO/Pt7Vmi7ujInCCvyf5NWR4B1z20fPTKGYiKnKL77ElJpzsi2GETwtwLOBpbH+0vX2jeWk6gDVtlu1+alyiU1Q7g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) 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 (0) 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=85oW0FR/VaKiJuUnu05JCYmxaQKgpt/mHqhNNZ5fGl0=; b=PfB0yf1wUt2/kpDt50Y6aOLMNV8zavUW2YWRYC9LDBMv55bz35Z9Kv5i6Lxq2lRhJEKEHpP3KhGZGzW1qE8b43XL4Ki7nuycmK3qhmULGk6MjBWI2zLI/6HFF5/wDIZ9C8q7CgUJJ6GvZVzFbEZA30h0GM6mLpX2AHtKQUhMB9an5hVbT7h/biw95cxr7h86YDZEkL85RlturiEcgWLF2/6y2r1ZjBRPix6LvKrNBONXPwnJm7nPH8qEqD3h5kmI76N4kafhIBsl+YeIwgNhT6BNCqSwz89m0sGxu2puWMpCHSu7AgSbroOFMEXZz8msFpTq7kra38NdivU03KfEWQ== Received: from BY3PR10CA0011.namprd10.prod.outlook.com (2603:10b6:a03:255::16) by PH7PR12MB7820.namprd12.prod.outlook.com (2603:10b6:510:268::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.39; Wed, 28 Feb 2024 17:01:44 +0000 Received: from SJ1PEPF00001CE3.namprd05.prod.outlook.com (2603:10b6:a03:255:cafe::eb) by BY3PR10CA0011.outlook.office365.com (2603:10b6:a03:255::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7339.28 via Frontend Transport; Wed, 28 Feb 2024 17:01:43 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) 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 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by SJ1PEPF00001CE3.mail.protection.outlook.com (10.167.242.11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7292.25 via Frontend Transport; Wed, 28 Feb 2024 17:01:43 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Wed, 28 Feb 2024 09:01:19 -0800 Received: from nvidia.com (10.126.230.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.1258.12; Wed, 28 Feb 2024 09:01:17 -0800 From: Dariusz Sosnowski To: Viacheslav Ovsiienko , Ori Kam , Suanming Mou , Matan Azrad CC: , Raslan Darawsheh , Bing Zhao Subject: [PATCH 07/11] net/mlx5: remove updated flow from job Date: Wed, 28 Feb 2024 18:00:42 +0100 Message-ID: <20240228170046.176600-8-dsosnowski@nvidia.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240228170046.176600-1-dsosnowski@nvidia.com> References: <20240228170046.176600-1-dsosnowski@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.126.230.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-TrafficTypeDiagnostic: SJ1PEPF00001CE3:EE_|PH7PR12MB7820:EE_ X-MS-Office365-Filtering-Correlation-Id: 69cdf7f5-dea5-47f0-0a1f-08dc387ef0fe X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: dnquq3Q8brpnaQMnbu1/CD5BVmPGu4WGc7BvtvD/sEWHuxA+6zyDBV1lbJuFtTRxOThLrb2VJahp54+WYGlWZ6L3uPBZN/5UKifc+WXtnX5vje7E58aU0y7EVLMwnIAzHdDMEmw0DFTvUvfbohxF4phWGTguQ6F5mHZk4Khy51G+JcEXL7AUlcURb2x8O3AJDcyoU3DuIvxarUVyyuCrO0XU6QGIMJoCZ7eeSnHbxiKYy1LPJMCsIX2YvJAhG4kVemQM/GzALYNyJt5Yu4ioeFE04YoRGk8f/uB+OM9D1FjQeFhozTKdYj7nv5z0P9NC5jwqJY1mwzwy2B8iQ3LAISKp6BeAEowiAz3lqdBjvfirK8azO6dPAGmkOA9E9QsBxVmiv6gWrv1VKnfsqKRImYxPhGKOVuG+4SWlhIUGL+dOx0J5eIzYUDtunq7obiIQS8eG5AlCtT8WWRCZsZe+/0bQfzGVRv9TkvqLykzU+p9b5eSaPgOU5UV61i8jnd6S7JiCIPosiJuOoRQ48r/GIO99FDWmT/dnPbtLVa26Jk4QGUtYIHUsgqzpbMRBWF3OkT3mKOjhP4EjiNutV3jI0QGiVN/pxm9RgoXZt+ePWQF9tVTOSF+ALCW7GRpyaqeClC6ziBeaKxAJDR6ndOJ8bknuJxi8nsAdvhjaf4Jdw7SHhYQN2wbePnf5tiONsYUm1Lt2OsmoVZs0C7OYO4vs/Op2D6ZTdEj3i5gqdMMgaTkO+hlAB4pzg3pIdkxXTOxv X-Forefront-Antispam-Report: CIP:216.228.117.161; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc6edge2.nvidia.com; CAT:NONE; SFS:(13230031)(82310400014)(36860700004); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Feb 2024 17:01:43.9358 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 69cdf7f5-dea5-47f0-0a1f-08dc387ef0fe X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.117.161]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: SJ1PEPF00001CE3.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB7820 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 mlx5_hw_q_job struct held a reference to a temporary flow rule struct, used during flow rule update operation. It serves as a container for flow actions data calculated during actions construction. After flow rule update operation succeeds, data from temporary flow rule is copied over to original flow rule. Although access to this temporary flow rule struct is required during both operation enqueue step and completion polling step, there can be only one ongoing flow update operation for a given flow rule. As a result there is no need to store it per job. This patch removes all references to temporary flow rule struct stored in mlx5_hw_q_job and removes relevant allocations to reduce job memory footprint. Temporary flow rule struct stored per job is replaced with: - If table is not resizable - An array of rte_flow_hw_aux structs, stored in template table. This array holds one entry per each flow rule, each containing a single mentioned temporary struct. - If table is resizable - Additional rte_flow_hw_aux struct, allocated alongside rte_flow_hw in resizable ipool. Signed-off-by: Dariusz Sosnowski --- drivers/net/mlx5/mlx5.h | 1 - drivers/net/mlx5/mlx5_flow.h | 7 +++ drivers/net/mlx5/mlx5_flow_hw.c | 100 ++++++++++++++++++++++++++------ 3 files changed, 89 insertions(+), 19 deletions(-) diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h index fc3d28e6f2..0cc32bf67b 100644 --- a/drivers/net/mlx5/mlx5.h +++ b/drivers/net/mlx5/mlx5.h @@ -407,7 +407,6 @@ struct mlx5_hw_q_job { /* Data extracted from hardware */ void *hw; } query; - struct rte_flow_hw *upd_flow; /* Flow with updated values. */ }; /* HW steering job descriptor LIFO pool. */ diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h index 96b43ce61e..8fd07bdce4 100644 --- a/drivers/net/mlx5/mlx5_flow.h +++ b/drivers/net/mlx5/mlx5_flow.h @@ -1281,6 +1281,12 @@ struct rte_flow_hw { uint8_t rule[]; /* HWS layer data struct. */ } __rte_packed; +/** Auxiliary data stored per flow which is not required to be stored in main flow structure. */ +struct rte_flow_hw_aux { + /** Placeholder flow struct used during flow rule update operation. */ + struct rte_flow_hw upd_flow; +}; + #ifdef PEDANTIC #pragma GCC diagnostic error "-Wpedantic" #endif @@ -1589,6 +1595,7 @@ struct rte_flow_template_table { /* Action templates bind to the table. */ struct mlx5_hw_action_template ats[MLX5_HW_TBL_MAX_ACTION_TEMPLATE]; struct mlx5_indexed_pool *flow; /* The table's flow ipool. */ + struct rte_flow_hw_aux *flow_aux; /**< Auxiliary data stored per flow. */ struct mlx5_indexed_pool *resource; /* The table's resource ipool. */ struct mlx5_flow_template_table_cfg cfg; uint32_t type; /* Flow table type RX/TX/FDB. */ diff --git a/drivers/net/mlx5/mlx5_flow_hw.c b/drivers/net/mlx5/mlx5_flow_hw.c index c3d9eef999..acc56819eb 100644 --- a/drivers/net/mlx5/mlx5_flow_hw.c +++ b/drivers/net/mlx5/mlx5_flow_hw.c @@ -79,6 +79,66 @@ struct mlx5_indlst_legacy { #define MLX5_CONST_ENCAP_ITEM(encap_type, ptr) \ (((const struct encap_type *)(ptr))->definition) +/** + * Returns the size of a struct with a following layout: + * + * @code{.c} + * struct rte_flow_hw { + * // rte_flow_hw fields + * uint8_t rule[mlx5dr_rule_get_handle_size()]; + * }; + * @endcode + * + * Such struct is used as a basic container for HW Steering flow rule. + */ +static size_t +mlx5_flow_hw_entry_size(void) +{ + return sizeof(struct rte_flow_hw) + mlx5dr_rule_get_handle_size(); +} + +/** + * Returns the size of "auxed" rte_flow_hw structure which is assumed to be laid out as follows: + * + * @code{.c} + * struct { + * struct rte_flow_hw { + * // rte_flow_hw fields + * uint8_t rule[mlx5dr_rule_get_handle_size()]; + * } flow; + * struct rte_flow_hw_aux aux; + * }; + * @endcode + * + * Such struct is used whenever rte_flow_hw_aux cannot be allocated separately from the rte_flow_hw + * e.g., when table is resizable. + */ +static size_t +mlx5_flow_hw_auxed_entry_size(void) +{ + size_t rule_size = mlx5dr_rule_get_handle_size(); + + return sizeof(struct rte_flow_hw) + rule_size + sizeof(struct rte_flow_hw_aux); +} + +/** + * Returns a valid pointer to rte_flow_hw_aux associated with given rte_flow_hw + * depending on template table configuration. + */ +static __rte_always_inline struct rte_flow_hw_aux * +mlx5_flow_hw_aux(uint16_t port_id, struct rte_flow_hw *flow) +{ + struct rte_flow_template_table *table = flow->table; + + if (rte_flow_template_table_resizable(port_id, &table->cfg.attr)) { + size_t offset = sizeof(struct rte_flow_hw) + mlx5dr_rule_get_handle_size(); + + return RTE_PTR_ADD(flow, offset); + } else { + return &table->flow_aux[flow->idx - 1]; + } +} + static int mlx5_tbl_multi_pattern_process(struct rte_eth_dev *dev, struct rte_flow_template_table *tbl, @@ -3632,6 +3692,7 @@ flow_hw_async_flow_update(struct rte_eth_dev *dev, struct mlx5_flow_hw_action_params ap; struct rte_flow_hw *of = (struct rte_flow_hw *)flow; struct rte_flow_hw *nf; + struct rte_flow_hw_aux *aux; struct rte_flow_template_table *table = of->table; struct mlx5_hw_q_job *job = NULL; uint32_t res_idx = 0; @@ -3642,7 +3703,8 @@ flow_hw_async_flow_update(struct rte_eth_dev *dev, rte_errno = ENOMEM; goto error; } - nf = job->upd_flow; + aux = mlx5_flow_hw_aux(dev->data->port_id, of); + nf = &aux->upd_flow; memset(nf, 0, sizeof(struct rte_flow_hw)); rule_acts = flow_hw_get_dr_action_buffer(priv, table, action_template_index, queue); /* @@ -3689,11 +3751,8 @@ flow_hw_async_flow_update(struct rte_eth_dev *dev, rte_errno = EINVAL; goto error; } - /* - * Switch the old flow and the new flow. - */ + /* Switch to the old flow. New flow will retrieved from the table on completion. */ job->flow = of; - job->upd_flow = nf; ret = mlx5dr_rule_action_update((struct mlx5dr_rule *)of->rule, action_template_index, rule_acts, &rule_attr); if (likely(!ret)) @@ -3966,8 +4025,10 @@ hw_cmpl_flow_update_or_destroy(struct rte_eth_dev *dev, mlx5_ipool_free(table->flow, flow->idx); } } else { - rte_memcpy(flow, job->upd_flow, - offsetof(struct rte_flow_hw, rule)); + struct rte_flow_hw_aux *aux = mlx5_flow_hw_aux(dev->data->port_id, flow); + struct rte_flow_hw *upd_flow = &aux->upd_flow; + + rte_memcpy(flow, upd_flow, offsetof(struct rte_flow_hw, rule)); if (table->resource) mlx5_ipool_free(table->resource, res_idx); } @@ -4456,7 +4517,6 @@ flow_hw_table_create(struct rte_eth_dev *dev, .data = &flow_attr, }; struct mlx5_indexed_pool_config cfg = { - .size = sizeof(struct rte_flow_hw) + mlx5dr_rule_get_handle_size(), .trunk_size = 1 << 12, .per_core_cache = 1 << 13, .need_lock = 1, @@ -4477,6 +4537,9 @@ flow_hw_table_create(struct rte_eth_dev *dev, if (!attr->flow_attr.group) max_tpl = 1; cfg.max_idx = nb_flows; + cfg.size = !rte_flow_template_table_resizable(dev->data->port_id, attr) ? + mlx5_flow_hw_entry_size() : + mlx5_flow_hw_auxed_entry_size(); /* For table has very limited flows, disable cache. */ if (nb_flows < cfg.trunk_size) { cfg.per_core_cache = 0; @@ -4507,6 +4570,11 @@ flow_hw_table_create(struct rte_eth_dev *dev, tbl->flow = mlx5_ipool_create(&cfg); if (!tbl->flow) goto error; + /* Allocate table of auxiliary flow rule structs. */ + tbl->flow_aux = mlx5_malloc(MLX5_MEM_ZERO, sizeof(struct rte_flow_hw_aux) * nb_flows, + RTE_CACHE_LINE_SIZE, rte_dev_numa_node(dev->device)); + if (!tbl->flow_aux) + goto error; /* Register the flow group. */ ge = mlx5_hlist_register(priv->sh->groups, attr->flow_attr.group, &ctx); if (!ge) @@ -4627,6 +4695,8 @@ flow_hw_table_create(struct rte_eth_dev *dev, if (tbl->grp) mlx5_hlist_unregister(priv->sh->groups, &tbl->grp->entry); + if (tbl->flow_aux) + mlx5_free(tbl->flow_aux); if (tbl->flow) mlx5_ipool_destroy(tbl->flow); mlx5_free(tbl); @@ -4865,6 +4935,7 @@ flow_hw_table_destroy(struct rte_eth_dev *dev, mlx5_hlist_unregister(priv->sh->groups, &table->grp->entry); if (table->resource) mlx5_ipool_destroy(table->resource); + mlx5_free(table->flow_aux); mlx5_ipool_destroy(table->flow); mlx5_free(table); return 0; @@ -9991,8 +10062,7 @@ flow_hw_configure(struct rte_eth_dev *dev, goto err; } mem_size += (sizeof(struct mlx5_hw_q_job *) + - sizeof(struct mlx5_hw_q_job) + - sizeof(struct rte_flow_hw)) * _queue_attr[i]->size; + sizeof(struct mlx5_hw_q_job)) * _queue_attr[i]->size; } priv->hw_q = mlx5_malloc(MLX5_MEM_ZERO, mem_size, 64, SOCKET_ID_ANY); @@ -10001,23 +10071,17 @@ flow_hw_configure(struct rte_eth_dev *dev, goto err; } for (i = 0; i < nb_q_updated; i++) { - struct rte_flow_hw *upd_flow = NULL; - priv->hw_q[i].job_idx = _queue_attr[i]->size; priv->hw_q[i].size = _queue_attr[i]->size; if (i == 0) priv->hw_q[i].job = (struct mlx5_hw_q_job **) &priv->hw_q[nb_q_updated]; else - priv->hw_q[i].job = (struct mlx5_hw_q_job **) - &job[_queue_attr[i - 1]->size - 1].upd_flow[1]; + priv->hw_q[i].job = (struct mlx5_hw_q_job **)&job[_queue_attr[i - 1]->size]; job = (struct mlx5_hw_q_job *) &priv->hw_q[i].job[_queue_attr[i]->size]; - upd_flow = (struct rte_flow_hw *)&job[_queue_attr[i]->size]; - for (j = 0; j < _queue_attr[i]->size; j++) { - job[j].upd_flow = &upd_flow[j]; + for (j = 0; j < _queue_attr[i]->size; j++) priv->hw_q[i].job[j] = &job[j]; - } /* Notice ring name length is limited. */ priv->hw_q[i].indir_cq = mlx5_hwq_ring_create (dev->data->port_id, i, _queue_attr[i]->size, "indir_act_cq"); -- 2.39.2