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 3C28BA00BE; Thu, 10 Feb 2022 17:30:41 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 5B5F7426EE; Thu, 10 Feb 2022 17:30:04 +0100 (CET) Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam08on2043.outbound.protection.outlook.com [40.107.100.43]) by mails.dpdk.org (Postfix) with ESMTP id D37D7411EE for ; Thu, 10 Feb 2022 17:30:02 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=O/O3y+m4HAbNKVzmTBLDo+VSlqeuj03qmztQDZpF8t5tOTnrFudQfD7ologTpikq6d97bkSXqatd18i+FC9Hy1A3IDj4fzc5Ek3RXLlVAgB+DS8oH08wwHtTbp2HuMsYJAyGCSIzF4fylJggif09KxHoIiETbu+GVep2GjUON3H9jirLu8dDuPf0wt5I50I9UV+tArkEokD97z/KSM3p7uACplBsrfGLxJaVkeSRqkXlz13JW8arJuGchsMBF5WCTpXxMyUuRvEdVRzPHgC0Cq0XptXN1EX1wIo2tZOFxDN2aTvN1F0Kw7vv84h7nIuLLi5ORi+97C8aZYo5robmbw== 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=5AfLIzt00jlmliMzQsYmy8ZmhsvWu3NlBvlRYpaXueg=; b=LHbtl5p21NUaeP1t3Mzy+eR96qB0ZUErXnzEXSClMTaDjM8igQN9nmiTOud6Y7qMt7AuOWWSdEDjqQ74eZW52Hnb24Fmmdg6HK8Bbvys6Zy4yuVFfGnhS3Q1azO4V3AcGTMx4scVcU27biSg2x0riH0FFQeVpXRgun7LxwdX8qXLcfmkntWEnqlPp5f3x6D7Ggfz/UnP+yGQFz8K8BkxusuRFKVqaec993NQm/E7kMcomhh+57ThQZHWho5JVvvcbVhu/7pxVT3iE6qGIamnorRcwOSHhhwzQ5Ih3d1RaZxawGsz+6pBJwvbyXSoahW1SqVEbHOeADyyQehn75MojA== 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=5AfLIzt00jlmliMzQsYmy8ZmhsvWu3NlBvlRYpaXueg=; b=aqycy20AqNuNbAwi/N0fXGIjd0/ybeiMrczUnzOENEcljsTH3JhuC3xZ41ZDX1zT8+B0mMhxlxttxtv3CNth1JoVPSeTKIRW+8jm5WuQJYWy2s1KcXrpsDXpQM7itOsfrG+KqcNYCJ9b6CDOfVwcRmQub5tT8JCCkOnmH2uBAX8kDROnmgmpoD5mYvSG+jPOidsFouCe3RTMK5MoJjywXuf0rKG9FbM0ewavlt8/wN8N8fESpfYjEb3p/1ews9umircd4snVogRl3vN8sL9n7sloQDlPXwsLl8as5JSguZe/SCVNQttAmD+dy32nQ62xaQvDPT7QmNnCzzzEVGiJxg== Received: from MWHPR22CA0004.namprd22.prod.outlook.com (2603:10b6:300:ef::14) by DM6PR12MB2812.namprd12.prod.outlook.com (2603:10b6:5:44::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4975.11; Thu, 10 Feb 2022 16:30:00 +0000 Received: from CO1NAM11FT058.eop-nam11.prod.protection.outlook.com (2603:10b6:300:ef:cafe::a) by MWHPR22CA0004.outlook.office365.com (2603:10b6:300:ef::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.19 via Frontend Transport; Thu, 10 Feb 2022 16:30:00 +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; Received: from mail.nvidia.com (12.22.5.234) by CO1NAM11FT058.mail.protection.outlook.com (10.13.174.164) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4975.11 via Frontend Transport; Thu, 10 Feb 2022 16:30:00 +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.18; Thu, 10 Feb 2022 16:29:55 +0000 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.986.9; Thu, 10 Feb 2022 08:29:53 -0800 From: Suanming Mou To: , CC: , , Subject: [PATCH 05/13] net/mlx5: add action template management Date: Thu, 10 Feb 2022 18:29:18 +0200 Message-ID: <20220210162926.20436-6-suanmingm@nvidia.com> X-Mailer: git-send-email 2.18.1 In-Reply-To: <20220210162926.20436-1-suanmingm@nvidia.com> References: <20220210162926.20436-1-suanmingm@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.126.230.35] X-ClientProxiedBy: rnnvmail203.nvidia.com (10.129.68.9) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d6c76ff8-a7fb-43c2-b7b4-08d9ecb2955b X-MS-TrafficTypeDiagnostic: DM6PR12MB2812:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:381; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +zEczKWV4qhZH7NfLqNCo54NCjGwQTuLr7NPOEE+f7QmfoGHHVHiZ5JB7nd/l+xLyvgBYOAHBOs0hqtdlr/pNrH5j/lcXRKavaCizNRr/F/ng51Uhe57/Qo5wDXRwXN/6EdLdyCNAVlsjVDjwkAPYJcLEudYcUqjBeO3G2HgNSHGMMShvabzdMR2+VGtSR/5MiWPhdhZ9TyUo71TrXVWbhtaogEEXttEl6/cc+F/0rgFYgQqDdvluvkfzGv7VHeuSDw2J4XdV9vXsjuSWSxeMExDW7GV1VfINn5Z1/NKg1dNjmBpoj2K7DxxuPIQp91BC8s06uw9qKmZDEXMqbODY5Jcfvo8tEgwHzH8cIxYeY36vqtedHEd+yFBr4AG4smUuIAgZZXfNprbZWZzM/XvUHiwPJzXH4j/OYoQEntvJ3Ea4HVQZw44tXu62zVRW6DNI3NhYn4bMQ1Y/bTM5Wre6npA/th8lSk3+qBBiLVEl4zqs238nxlRJ7kYzQwlfsdidkRQKVQBA469F5e3Ta2w+lC1zSNMMFazd/JV2PQqUaljy6jEFtJqQkonqd9sqHP5ght0Qv2GL+xN1CdhAAguAGXuTSn6ZxDdRMraSbejto80lgX+dz11iqP591ZDgFpB9ML3RLRXfqlABQpw/yff8G8+rG3v6QpTQnttX3meUNahiDEmv3xX/GYjZ94VVufOysxzCgmTs1oJ0m/jDMAujA== X-Forefront-Antispam-Report: CIP:12.22.5.234; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:mail.nvidia.com; PTR:InfoNoRecords; CAT:NONE; SFS:(13230001)(4636009)(46966006)(36840700001)(40470700004)(86362001)(55016003)(2906002)(70586007)(8676002)(8936002)(83380400001)(2616005)(30864003)(4326008)(1076003)(508600001)(70206006)(47076005)(82310400004)(426003)(40460700003)(5660300002)(36756003)(6666004)(316002)(6636002)(110136005)(36860700001)(356005)(7696005)(54906003)(336012)(81166007)(6286002)(26005)(16526019)(186003)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Feb 2022 16:30:00.2691 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d6c76ff8-a7fb-43c2-b7b4-08d9ecb2955b 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: CO1NAM11FT058.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB2812 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 The action template holds a list of action types that will be used together on the same rule. The template's actions instances will be created only when the template bind to the dedicated group. And the created actions will be saved to each individual group in order for best performance. The actions will not be shared with each other. This commit adds the action template management which caches the flow action template. Signed-off-by: Suanming Mou --- drivers/net/mlx5/mlx5.h | 2 + drivers/net/mlx5/mlx5_flow.c | 66 ++++++++++++++++++ drivers/net/mlx5/mlx5_flow.h | 27 ++++++++ drivers/net/mlx5/mlx5_flow_hw.c | 116 ++++++++++++++++++++++++++++++++ 4 files changed, 211 insertions(+) diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h index 96048ad0ea..80dc72175d 100644 --- a/drivers/net/mlx5/mlx5.h +++ b/drivers/net/mlx5/mlx5.h @@ -1502,6 +1502,8 @@ struct mlx5_priv { uint32_t flex_item_map; /* Map of allocated flex item elements. */ /* Item template list. */ LIST_HEAD(flow_hw_itt, rte_flow_pattern_template) flow_hw_itt; + /* Action template list. */ + LIST_HEAD(flow_hw_at, rte_flow_actions_template) flow_hw_at; struct mlx5dr_context *dr_ctx; /**< HW steering DR context. */ uint32_t nb_queue; /* HW steering queue number. */ /* HW steering queue polling mechanism job descriptor LIFO. */ diff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c index 27a40a9627..be6a7ff336 100644 --- a/drivers/net/mlx5/mlx5_flow.c +++ b/drivers/net/mlx5/mlx5_flow.c @@ -822,6 +822,16 @@ static int mlx5_flow_pattern_template_destroy(struct rte_eth_dev *dev, struct rte_flow_pattern_template *template, struct rte_flow_error *error); +static struct rte_flow_actions_template * +mlx5_flow_actions_template_create(struct rte_eth_dev *dev, + const struct rte_flow_actions_template_attr *attr, + const struct rte_flow_action actions[], + const struct rte_flow_action masks[], + struct rte_flow_error *error); +static int +mlx5_flow_actions_template_destroy(struct rte_eth_dev *dev, + struct rte_flow_actions_template *template, + struct rte_flow_error *error); static const struct rte_flow_ops mlx5_flow_ops = { .validate = mlx5_flow_validate, @@ -846,6 +856,8 @@ static const struct rte_flow_ops mlx5_flow_ops = { .configure = mlx5_flow_port_configure, .pattern_template_create = mlx5_flow_pattern_template_create, .pattern_template_destroy = mlx5_flow_pattern_template_destroy, + .actions_template_create = mlx5_flow_actions_template_create, + .actions_template_destroy = mlx5_flow_actions_template_destroy, }; /* Tunnel information. */ @@ -7915,6 +7927,60 @@ mlx5_flow_pattern_template_destroy(struct rte_eth_dev *dev, return fops->pattern_template_destroy(dev, template, error); } +/** + * Create flow item template. + * + * @param[in] dev + * Pointer to the rte_eth_dev structure. + * @param[in] attr + * Pointer to the action template attributes. + * @param[in] actions + * Associated actions (list terminated by the END action). + * @param[in] masks + * List of actions that marks which of the action's member is constant. + * @param[out] error + * Pointer to error structure. + * + * @return + * 0 on success, a negative errno value otherwise and rte_errno is set. + */ +static struct rte_flow_actions_template * +mlx5_flow_actions_template_create(struct rte_eth_dev *dev, + const struct rte_flow_actions_template_attr *attr, + const struct rte_flow_action actions[], + const struct rte_flow_action masks[], + struct rte_flow_error *error) +{ + const struct mlx5_flow_driver_ops *fops = + flow_get_drv_ops(MLX5_FLOW_TYPE_HW); + + return fops->actions_template_create(dev, attr, actions, masks, error); +} + +/** + * Destroy flow action template. + * + * @param[in] dev + * Pointer to the rte_eth_dev structure. + * @param[in] template + * Pointer to the action template to be destroyed. + * @param[out] error + * Pointer to error structure. + * + * @return + * 0 on success, a negative errno value otherwise and rte_errno is set. + */ +static int +mlx5_flow_actions_template_destroy(struct rte_eth_dev *dev, + struct rte_flow_actions_template *template, + struct rte_flow_error *error) +{ + const struct mlx5_flow_driver_ops *fops = + flow_get_drv_ops(MLX5_FLOW_TYPE_HW); + + return fops->actions_template_destroy(dev, template, error); +} + /** * Allocate a new memory for the counter values wrapped by all the needed * management. diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h index 88102f0991..f5ababb32f 100644 --- a/drivers/net/mlx5/mlx5_flow.h +++ b/drivers/net/mlx5/mlx5_flow.h @@ -1024,6 +1024,21 @@ struct rte_flow_pattern_template { uint32_t refcnt; /* Reference counter. */ }; +/* Flow action template attribute. */ +struct rte_flow_actions_template_attr { + int32_t reserve; +}; + +/* Flow action template struct. */ +struct rte_flow_actions_template { + LIST_ENTRY(rte_flow_actions_template) next; + /* Template attributes. */ + struct rte_flow_actions_template_attr attr; + struct rte_flow_action *actions; /* Cached flow actions. */ + struct rte_flow_action *masks; /* Cached action masks.*/ + uint32_t refcnt; /* Reference counter. */ +}; + /* * Define list of valid combinations of RX Hash fields * (see enum ibv_rx_hash_fields). @@ -1281,6 +1296,16 @@ typedef int (*mlx5_flow_pattern_template_destroy_t) (struct rte_eth_dev *dev, struct rte_flow_pattern_template *template, struct rte_flow_error *error); +typedef struct rte_flow_actions_template *(*mlx5_flow_actions_template_create_t) + (struct rte_eth_dev *dev, + const struct rte_flow_actions_template_attr *attr, + const struct rte_flow_action actions[], + const struct rte_flow_action masks[], + struct rte_flow_error *error); +typedef int (*mlx5_flow_actions_template_destroy_t) + (struct rte_eth_dev *dev, + struct rte_flow_actions_template *template, + struct rte_flow_error *error); struct mlx5_flow_driver_ops { mlx5_flow_validate_t validate; @@ -1322,6 +1347,8 @@ struct mlx5_flow_driver_ops { mlx5_flow_port_configure_t configure; mlx5_flow_pattern_template_create_t pattern_template_create; mlx5_flow_pattern_template_destroy_t pattern_template_destroy; + mlx5_flow_actions_template_create_t actions_template_create; + mlx5_flow_actions_template_destroy_t actions_template_destroy; }; /* mlx5_flow.c */ diff --git a/drivers/net/mlx5/mlx5_flow_hw.c b/drivers/net/mlx5/mlx5_flow_hw.c index c984e520cd..349c12a849 100644 --- a/drivers/net/mlx5/mlx5_flow_hw.c +++ b/drivers/net/mlx5/mlx5_flow_hw.c @@ -12,6 +12,115 @@ const struct mlx5_flow_driver_ops mlx5_flow_hw_drv_ops; +/** + * Create flow action template. + * + * @param[in] dev + * Pointer to the rte_eth_dev structure. + * @param[in] attr + * Pointer to the action template attributes. + * @param[in] actions + * Associated actions (list terminated by the END action). + * @param[in] masks + * List of actions that marks which of the action's member is constant. + * @param[out] error + * Pointer to error structure. + * + * @return + * Action template pointer on success, NULL otherwise and rte_errno is set. + */ +static struct rte_flow_actions_template * +flow_hw_actions_template_create(struct rte_eth_dev *dev, + const struct rte_flow_actions_template_attr *attr, + const struct rte_flow_action actions[], + const struct rte_flow_action masks[], + struct rte_flow_error *error) +{ + struct mlx5_priv *priv = dev->data->dev_private; + int len, act_len, mask_len, i; + struct rte_flow_actions_template *at; + + act_len = rte_flow_conv(RTE_FLOW_CONV_OP_ACTIONS, + NULL, 0, actions, error); + if (act_len <= 0) + return NULL; + len = RTE_ALIGN(act_len, 16); + mask_len = rte_flow_conv(RTE_FLOW_CONV_OP_ACTIONS, + NULL, 0, masks, error); + if (mask_len <= 0) + return NULL; + len += RTE_ALIGN(mask_len, 16); + at = mlx5_malloc(MLX5_MEM_ZERO, len + sizeof(*at), 64, SOCKET_ID_ANY); + if (!at) { + rte_flow_error_set(error, ENOMEM, + RTE_FLOW_ERROR_TYPE_UNSPECIFIED, + NULL, + "cannot allocate action template"); + return NULL; + } + at->attr = *attr; + at->actions = (struct rte_flow_action *)(at + 1); + act_len = rte_flow_conv(RTE_FLOW_CONV_OP_ACTIONS, at->actions, len, + actions, error); + if (act_len <= 0) + goto error; + at->masks = (struct rte_flow_action *) + (((uint8_t *)at->actions) + act_len); + mask_len = rte_flow_conv(RTE_FLOW_CONV_OP_ACTIONS, at->masks, + len - act_len, masks, error); + if (mask_len <= 0) + goto error; + /* + * mlx5 PMD hacks indirect action index directly to the action conf. + * The rte_flow_conv() function copies the content from conf pointer. + * Need to restore the indirect action index from action conf here. + */ + for (i = 0; actions->type != RTE_FLOW_ACTION_TYPE_END; + actions++, masks++, i++) { + if (actions->type == RTE_FLOW_ACTION_TYPE_INDIRECT) { + at->actions[i].conf = actions->conf; + at->masks[i].conf = masks->conf; + } + } + __atomic_fetch_add(&at->refcnt, 1, __ATOMIC_RELAXED); + LIST_INSERT_HEAD(&priv->flow_hw_at, at, next); + return at; +error: + mlx5_free(at); + return NULL; +} + +/** + * Destroy flow action template. + * + * @param[in] dev + * Pointer to the rte_eth_dev structure. + * @param[in] template + * Pointer to the action template to be destroyed. + * @param[out] error + * Pointer to error structure. + * + * @return + * 0 on success, a negative errno value otherwise and rte_errno is set. + */ +static int +flow_hw_actions_template_destroy(struct rte_eth_dev *dev __rte_unused, + struct rte_flow_actions_template *template, + struct rte_flow_error *error __rte_unused) +{ + if (__atomic_load_n(&template->refcnt, __ATOMIC_RELAXED) > 1) { + DRV_LOG(WARNING, "Action template %p is still in use.", + (void *)template); + return rte_flow_error_set(error, EBUSY, + RTE_FLOW_ERROR_TYPE_UNSPECIFIED, + NULL, + "action template in using"); + } + LIST_REMOVE(template, next); + mlx5_free(template); + return 0; +} + /** * Create flow item template. * @@ -204,6 +313,7 @@ flow_hw_resource_release(struct rte_eth_dev *dev) { struct mlx5_priv *priv = dev->data->dev_private; struct rte_flow_pattern_template *it; + struct rte_flow_actions_template *at; if (!priv->dr_ctx) return; @@ -211,6 +321,10 @@ flow_hw_resource_release(struct rte_eth_dev *dev) it = LIST_FIRST(&priv->flow_hw_itt); flow_hw_pattern_template_destroy(dev, it, NULL); } + while (!LIST_EMPTY(&priv->flow_hw_at)) { + at = LIST_FIRST(&priv->flow_hw_at); + flow_hw_actions_template_destroy(dev, at, NULL); + } mlx5_free(priv->hw_q); priv->hw_q = NULL; claim_zero(mlx5dr_context_close(priv->dr_ctx)); @@ -222,6 +336,8 @@ const struct mlx5_flow_driver_ops mlx5_flow_hw_drv_ops = { .configure = flow_hw_configure, .pattern_template_create = flow_hw_pattern_template_create, .pattern_template_destroy = flow_hw_pattern_template_destroy, + .actions_template_create = flow_hw_actions_template_create, + .actions_template_destroy = flow_hw_actions_template_destroy, }; #endif -- 2.25.1