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 D26D0A0A0F; Wed, 30 Jun 2021 14:48:05 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 11E9F412B6; Wed, 30 Jun 2021 14:47:03 +0200 (CEST) Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2044.outbound.protection.outlook.com [40.107.243.44]) by mails.dpdk.org (Postfix) with ESMTP id EE7EB412A9 for ; Wed, 30 Jun 2021 14:47:00 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BMx9sVt1ZzYpeDiHBFtxlofe00qxqO8/stPwDucdYp0BOff6ebwvySUeNkKNmyQ0G0DtTVaezXUfOTxdeMBqDpSyy2stX63yug4aD4k3cJPoyWVubIqKsClUhLCLGAMmOklSRIloaUFmmI1lx0eOm/xe+gPIezSd7JMMxQsQuMlnD3CnehFPentRm557B3N7OvSvY5LZ7mzqdxPPdsnXNaC3leRoZ9Afmj2wxc0/TY4favNXOfOLKS6MU1MgjTvlOziB3RpTpnezITpJDWBEm3J88qGqXLxHS+icPkKaxrz0FhqZhgUL1kk2nme0LMoHncg3CfAETxpFXIHjnvQPpw== 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=yebRP0iTp7vCAoEeLpr/MWGorslGnP9cghFz6fYYhRo=; b=Gzqv0/xwFMXNDzj9FKK5S4mzqAwi20qBTP7Vgms7XYvPWNwYxOO5K4F3LLBa0iHdFdZprlP13YGBsfaE3wnMco31yi26SsT4zGw21eM2erkB1fd4wZ8uxfVP+Di6ouynqlsU1k25vBoe1/cfmKL1E5kwJZjVQm7CbizQUmQpLWnfWnXUCo8Jix+vXoYrNpuBb12AQY83bRBmlvPpDiNUPCdvdqxHyo1fTfS880TrXXxzEfie1XmFrMvRk90W8UeP5OcggUUSWdV3rlSkRGBVSbqfPqWADHPxkbBInYq6ORAp7w532jUESislI4rFdEk6SnWfzthOkRhPNWYAwLtzbA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=dpdk.org smtp.mailfrom=nvidia.com; dmarc=pass (p=none sp=none 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=yebRP0iTp7vCAoEeLpr/MWGorslGnP9cghFz6fYYhRo=; b=oaY0o17BbxQ3FnxO1v4kC7l7qVqqrl+JorIkR04PwRMRHEC8ht7fQhfJ5NTNQI5llS1ov5YVv0nzIUMKSbmDauw107TA1CyjU3wFRv7PgLnhvVmC/3fav5/Nru9+KqOwaZZN8+84mflq7uEsts0viU5/Py2NAG2DwU73Wk/z0jUzgfpUCneI1MNt0wkdwcwO+LU3Dsj2J5YZEn/uS7OlBl3PTn36GLIDNRaxZErhZOXhyVF3OQ6OfRzRT5lapxJ4s9Y7JD8qBIqO6JC3rzphQ9FiXrEVQoW5bsLck28/38NGg21pLKLVUVAgYc4fiYEMlDRHmynFdVnqb5RLlYM2yQ== Received: from BN6PR1701CA0021.namprd17.prod.outlook.com (2603:10b6:405:15::31) by MW3PR12MB4523.namprd12.prod.outlook.com (2603:10b6:303:5b::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4287.22; Wed, 30 Jun 2021 12:46:58 +0000 Received: from BN8NAM11FT045.eop-nam11.prod.protection.outlook.com (2603:10b6:405:15:cafe::d6) by BN6PR1701CA0021.outlook.office365.com (2603:10b6:405:15::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4287.21 via Frontend Transport; Wed, 30 Jun 2021 12:46:58 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) smtp.mailfrom=nvidia.com; dpdk.org; dkim=none (message not signed) header.d=none;dpdk.org; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.34 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.34; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.34) by BN8NAM11FT045.mail.protection.outlook.com (10.13.177.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4287.22 via Frontend Transport; Wed, 30 Jun 2021 12:46:58 +0000 Received: from nvidia.com (172.20.187.6) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 30 Jun 2021 12:46:49 +0000 From: Suanming Mou To: , CC: , , Date: Wed, 30 Jun 2021 15:46:00 +0300 Message-ID: <20210630124609.8711-14-suanmingm@nvidia.com> X-Mailer: git-send-email 2.18.1 In-Reply-To: <20210630124609.8711-1-suanmingm@nvidia.com> References: <20210527093403.1153127-1-suanmingm@nvidia.com> <20210630124609.8711-1-suanmingm@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [172.20.187.6] X-ClientProxiedBy: HQMAIL101.nvidia.com (172.20.187.10) To HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 16cc2714-d371-4744-dbda-08d93bc5261a X-MS-TrafficTypeDiagnostic: MW3PR12MB4523: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5797; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 44tZ1cWeWJHREXcUbuN1XS69gCP//SyBxOajlPqsi5DGiyUU5WB+g4tKOrVkvS+9Tz0UCIAjrRB5eMshy8yP1zoNwJKawRzVsc7CAo8whyBI8iEGp2lCoOFeLJtbG9Zh8yNJA4+IpJRsC6+qvs8mgDm30150k7Da5R6dMP+lDPg8r7e28Z8Q0m3qoO1ne2lfILOqzD8rSsJDV9rSQWMSJTbLg3jUaik0I9ZmbUdX2ItojdZR89j46/pne3Fh+brf8ltY7oAk41qIiMJLmhqOdtPdy6kR3q5cf1MAZMeWGYUucAu6PXRNG4Oi1XVNz3ejQxCyOmEYnfI3IPWFbhQMSjRwddH2PVE2FfJY1RlNfEjP1Wqq8hGdargEzgKea4N0GriIyXRjrxspbwdzIxTr8L6zZMN2oDbgNh+sYThBC5LTIuVWHkhlSnrJspXZ9MStp6qfXIwXZT0H6v74GEpo9MGWwKzaJCt88MElfAB2VQTSQkHkopp43TLLoStCQFYDllzxNJK/i2bj2oVYaiyrKVgNUfp4qdbq7axD/uFMYE0Og5Wtl93Ic0kI0kkiPyuI+1apGX93zFwVMaFWO05cVV4ODsjpa7p+T9l1ix6zTkB3hoX9rA+zc4rqlkW03UUpxR962WG8fmKT/pX9YL635CQrMFShptZsQtWyTkufC2Z/T1/kRe26Zq8+RuN+PLzRCmRqyhgKWi1HBac3P1IQLA== X-Forefront-Antispam-Report: CIP:216.228.112.34; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid03.nvidia.com; CAT:NONE; SFS:(4636009)(346002)(136003)(376002)(39860400002)(396003)(36840700001)(46966006)(36860700001)(8676002)(26005)(47076005)(7696005)(82310400003)(478600001)(83380400001)(356005)(55016002)(8936002)(5660300002)(186003)(16526019)(1076003)(6666004)(86362001)(7636003)(82740400003)(70206006)(54906003)(110136005)(336012)(2616005)(70586007)(426003)(4326008)(6286002)(316002)(6636002)(2906002)(36756003); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jun 2021 12:46:58.1737 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 16cc2714-d371-4744-dbda-08d93bc5261a X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.34]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT045.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW3PR12MB4523 Subject: [dpdk-dev] [PATCH v2 13/22] net/mlx5: move modify header allocator to ipool 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 Sender: "dev" From: Matan Azrad Modify header actions are allocated by mlx5_malloc which has a big overhead of memory and allocation time. One of the action types under the modify header object is SET_TAG, The SET_TAG action is commonly not reused by the flows and each flow has its own value. Hence, the mlx5_malloc becomes a bottleneck in flow insertion rate in the common cases of SET_TAG. Use ipool allocator for SET_TAG action. Ipool allocator has less overhead of memory and insertion rate and has better synchronization mechanism in multithread cases. Different ipool is created for each optional size of modify header handler. Signed-off-by: Matan Azrad Acked-by: Suanming Mou --- drivers/net/mlx5/mlx5.c | 4 ++ drivers/net/mlx5/mlx5.h | 14 ++++++ drivers/net/mlx5/mlx5_flow.h | 14 +----- drivers/net/mlx5/mlx5_flow_dv.c | 79 ++++++++++++++++++++++++++++----- 4 files changed, 86 insertions(+), 25 deletions(-) diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c index 0e80408511..713accf675 100644 --- a/drivers/net/mlx5/mlx5.c +++ b/drivers/net/mlx5/mlx5.c @@ -801,6 +801,7 @@ mlx5_flow_ipool_create(struct mlx5_dev_ctx_shared *sh, } } + /** * Release the flow resources' indexed mempool. * @@ -814,6 +815,9 @@ mlx5_flow_ipool_destroy(struct mlx5_dev_ctx_shared *sh) for (i = 0; i < MLX5_IPOOL_MAX; ++i) mlx5_ipool_destroy(sh->ipool[i]); + for (i = 0; i < MLX5_MAX_MODIFY_NUM; ++i) + if (sh->mdh_ipools[i]) + mlx5_ipool_destroy(sh->mdh_ipools[i]); } /* diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h index 896c0c2da1..5774f63244 100644 --- a/drivers/net/mlx5/mlx5.h +++ b/drivers/net/mlx5/mlx5.h @@ -36,6 +36,19 @@ #define MLX5_SH(dev) (((struct mlx5_priv *)(dev)->data->dev_private)->sh) +/* + * Number of modification commands. + * The maximal actions amount in FW is some constant, and it is 16 in the + * latest releases. In some old releases, it will be limited to 8. + * Since there is no interface to query the capacity, the maximal value should + * be used to allow PMD to create the flow. The validation will be done in the + * lower driver layer or FW. A failure will be returned if exceeds the maximal + * supported actions number on the root table. + * On non-root tables, there is no limitation, but 32 is enough right now. + */ +#define MLX5_MAX_MODIFY_NUM 32 +#define MLX5_ROOT_TBL_MODIFY_NUM 16 + enum mlx5_ipool_index { #if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H) MLX5_IPOOL_DECAP_ENCAP = 0, /* Pool for encap/decap resource. */ @@ -1123,6 +1136,7 @@ struct mlx5_dev_ctx_shared { struct mlx5_flow_counter_mng cmng; /* Counters management structure. */ void *default_miss_action; /* Default miss action. */ struct mlx5_indexed_pool *ipool[MLX5_IPOOL_MAX]; + struct mlx5_indexed_pool *mdh_ipools[MLX5_MAX_MODIFY_NUM]; /* Memory Pool for mlx5 flow resources. */ struct mlx5_l3t_tbl *cnt_id_tbl; /* Shared counter lookup table. */ /* Shared interrupt handler section. */ diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h index ab4e8c5c4f..4552aaa803 100644 --- a/drivers/net/mlx5/mlx5_flow.h +++ b/drivers/net/mlx5/mlx5_flow.h @@ -504,23 +504,11 @@ struct mlx5_flow_dv_tag_resource { uint32_t tag_id; /**< Tag ID. */ }; -/* - * Number of modification commands. - * The maximal actions amount in FW is some constant, and it is 16 in the - * latest releases. In some old releases, it will be limited to 8. - * Since there is no interface to query the capacity, the maximal value should - * be used to allow PMD to create the flow. The validation will be done in the - * lower driver layer or FW. A failure will be returned if exceeds the maximal - * supported actions number on the root table. - * On non-root tables, there is no limitation, but 32 is enough right now. - */ -#define MLX5_MAX_MODIFY_NUM 32 -#define MLX5_ROOT_TBL_MODIFY_NUM 16 - /* Modify resource structure */ struct mlx5_flow_dv_modify_hdr_resource { struct mlx5_list_entry entry; void *action; /**< Modify header action object. */ + uint32_t idx; /* Key area for hash list matching: */ uint8_t ft_type; /**< Flow table type, Rx or Tx. */ uint8_t actions_num; /**< Number of modification actions. */ diff --git a/drivers/net/mlx5/mlx5_flow_dv.c b/drivers/net/mlx5/mlx5_flow_dv.c index 1dfd5db361..08704d892a 100644 --- a/drivers/net/mlx5/mlx5_flow_dv.c +++ b/drivers/net/mlx5/mlx5_flow_dv.c @@ -5304,6 +5304,45 @@ flow_dv_modify_match_cb(void *tool_ctx __rte_unused, memcmp(&ref->ft_type, &resource->ft_type, key_len); } +static struct mlx5_indexed_pool * +flow_dv_modify_ipool_get(struct mlx5_dev_ctx_shared *sh, uint8_t index) +{ + struct mlx5_indexed_pool *ipool = __atomic_load_n + (&sh->mdh_ipools[index], __ATOMIC_SEQ_CST); + + if (!ipool) { + struct mlx5_indexed_pool *expected = NULL; + struct mlx5_indexed_pool_config cfg = + (struct mlx5_indexed_pool_config) { + .size = sizeof(struct mlx5_flow_dv_modify_hdr_resource) + + (index + 1) * + sizeof(struct mlx5_modification_cmd), + .trunk_size = 64, + .grow_trunk = 3, + .grow_shift = 2, + .need_lock = 1, + .release_mem_en = 1, + .malloc = mlx5_malloc, + .free = mlx5_free, + .type = "mlx5_modify_action_resource", + }; + + cfg.size = RTE_ALIGN(cfg.size, sizeof(ipool)); + ipool = mlx5_ipool_create(&cfg); + if (!ipool) + return NULL; + if (!__atomic_compare_exchange_n(&sh->mdh_ipools[index], + &expected, ipool, false, + __ATOMIC_SEQ_CST, + __ATOMIC_SEQ_CST)) { + mlx5_ipool_destroy(ipool); + ipool = __atomic_load_n(&sh->mdh_ipools[index], + __ATOMIC_SEQ_CST); + } + } + return ipool; +} + struct mlx5_list_entry * flow_dv_modify_create_cb(void *tool_ctx, void *cb_ctx) { @@ -5312,12 +5351,20 @@ flow_dv_modify_create_cb(void *tool_ctx, void *cb_ctx) struct mlx5dv_dr_domain *ns; struct mlx5_flow_dv_modify_hdr_resource *entry; struct mlx5_flow_dv_modify_hdr_resource *ref = ctx->data; + struct mlx5_indexed_pool *ipool = flow_dv_modify_ipool_get(sh, + ref->actions_num - 1); int ret; uint32_t data_len = ref->actions_num * sizeof(ref->actions[0]); uint32_t key_len = sizeof(*ref) - offsetof(typeof(*ref), ft_type); + uint32_t idx; - entry = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*entry) + data_len, 0, - SOCKET_ID_ANY); + if (unlikely(!ipool)) { + rte_flow_error_set(ctx->error, ENOMEM, + RTE_FLOW_ERROR_TYPE_UNSPECIFIED, + NULL, "cannot allocate modify ipool"); + return NULL; + } + entry = mlx5_ipool_zmalloc(ipool, &idx); if (!entry) { rte_flow_error_set(ctx->error, ENOMEM, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, @@ -5337,25 +5384,29 @@ flow_dv_modify_create_cb(void *tool_ctx, void *cb_ctx) (sh->ctx, ns, entry, data_len, &entry->action); if (ret) { - mlx5_free(entry); + mlx5_ipool_free(sh->mdh_ipools[ref->actions_num - 1], idx); rte_flow_error_set(ctx->error, ENOMEM, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, "cannot create modification action"); return NULL; } + entry->idx = idx; return &entry->entry; } struct mlx5_list_entry * -flow_dv_modify_clone_cb(void *tool_ctx __rte_unused, - struct mlx5_list_entry *oentry, void *cb_ctx) +flow_dv_modify_clone_cb(void *tool_ctx, struct mlx5_list_entry *oentry, + void *cb_ctx) { + struct mlx5_dev_ctx_shared *sh = tool_ctx; struct mlx5_flow_cb_ctx *ctx = cb_ctx; struct mlx5_flow_dv_modify_hdr_resource *entry; struct mlx5_flow_dv_modify_hdr_resource *ref = ctx->data; uint32_t data_len = ref->actions_num * sizeof(ref->actions[0]); + uint32_t idx; - entry = mlx5_malloc(0, sizeof(*entry) + data_len, 0, SOCKET_ID_ANY); + entry = mlx5_ipool_malloc(sh->mdh_ipools[ref->actions_num - 1], + &idx); if (!entry) { rte_flow_error_set(ctx->error, ENOMEM, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, @@ -5363,14 +5414,18 @@ flow_dv_modify_clone_cb(void *tool_ctx __rte_unused, return NULL; } memcpy(entry, oentry, sizeof(*entry) + data_len); + entry->idx = idx; return &entry->entry; } void -flow_dv_modify_clone_free_cb(void *tool_ctx __rte_unused, - struct mlx5_list_entry *entry) +flow_dv_modify_clone_free_cb(void *tool_ctx, struct mlx5_list_entry *entry) { - mlx5_free(entry); + struct mlx5_dev_ctx_shared *sh = tool_ctx; + struct mlx5_flow_dv_modify_hdr_resource *res = + container_of(entry, typeof(*res), entry); + + mlx5_ipool_free(sh->mdh_ipools[res->actions_num - 1], res->idx); } /** @@ -13699,14 +13754,14 @@ flow_dv_jump_tbl_resource_release(struct rte_eth_dev *dev, } void -flow_dv_modify_remove_cb(void *tool_ctx __rte_unused, - struct mlx5_list_entry *entry) +flow_dv_modify_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry) { struct mlx5_flow_dv_modify_hdr_resource *res = container_of(entry, typeof(*res), entry); + struct mlx5_dev_ctx_shared *sh = tool_ctx; claim_zero(mlx5_flow_os_destroy_flow_action(res->action)); - mlx5_free(entry); + mlx5_ipool_free(sh->mdh_ipools[res->actions_num - 1], res->idx); } /** -- 2.25.1