From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 26D3EA0613 for ; Thu, 26 Sep 2019 11:34:08 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 337FE1BF4F; Thu, 26 Sep 2019 11:34:02 +0200 (CEST) Received: from EUR02-AM5-obe.outbound.protection.outlook.com (mail-eopbgr00060.outbound.protection.outlook.com [40.107.0.60]) by dpdk.org (Postfix) with ESMTP id 566CB1BF2B for ; Thu, 26 Sep 2019 11:34:01 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Qq1LdVH6Dits7wlWrYUOcxS/NsAebVetHPtm6OSOLmMGtGjJ67p5vpqX4Ih/6/b76Pv2sLztw2ka34uprTEyFTKpBTHR2Gf/f/lg2ynANW1PbdjqP4xnnT/s9MZKu9BH3IlmDscO0PqevheERuJ7rwpwV+SU5LcyIexK7tOwQDh2vqLlfrqUt9h6LkpQ7ZmPyAT6X/ajhXnnPyt5DdoQpSE5X6GQ5Pv1BTf7bAQqwoMIJz8a2clMDI+Vrj3+VwigMTT16Td7kW51Znx3n7omnxv1uCHN/CPQoTDw8CTDiaCx2+vX1x/C8L4VG0353b6CABl6aXZ8oJuxO7ACk/axAg== 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=ct2ssXYiNvwGXt21Ape3ogju86GMjOZcFbs3O03iGIw=; b=SzgqPqD3hEKthPQ/+oy9dCtcFhhjquHl7IwF9LrMyb+7Rqk8bc4v3xj1+dUEs3kd9AM7kNu+1sWjR/sf+b+EsN5uyLQa1MxkWPmKFHbJxI/dlpUKyEMLOIx5mZxGVx5IXA4isfNYKedaIPNjsbFYv6wBkH7K+NKl3PUywmBwpMdyLDr/dZZjEY1PY8/TcmQL2vZk24ClCa8hwZKaOnaWfXbKlGdaPGuG4SjYLJeMSxjvQ6lT2BeVicJtUDSib4TgTkhH5TqD2PLyM0ke5veTWdWnJF1Yn7RZ73JDYP4WYMd77ghZ3Iec+6Znhi6Yv1Mhr8Hr0T1Y+3ekfXiiC1QXUA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=mellanox.com; dmarc=pass action=none header.from=mellanox.com; dkim=pass header.d=mellanox.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ct2ssXYiNvwGXt21Ape3ogju86GMjOZcFbs3O03iGIw=; b=aWDBgMJE9nOFkhKv9kAzb8BYl/h3JRP2tAbmeVTKPQ7D7abbKzcQXm1wgGrpZe/hik9Bl6geeSSggBAtwWELcC4hE/NlaUQXzaCbNs+NpZXhWQG7sBzdINK4hK/aZ0buEVj1UimnW7LfDXqW548uFCjOP27m4uog+rcg9Dw5svA= Received: from AM4PR05MB3265.eurprd05.prod.outlook.com (10.171.188.154) by AM4PR05MB3281.eurprd05.prod.outlook.com (10.171.188.158) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2305.15; Thu, 26 Sep 2019 09:34:00 +0000 Received: from AM4PR05MB3265.eurprd05.prod.outlook.com ([fe80::da9:65ba:1323:a39b]) by AM4PR05MB3265.eurprd05.prod.outlook.com ([fe80::da9:65ba:1323:a39b%7]) with mapi id 15.20.2305.017; Thu, 26 Sep 2019 09:34:00 +0000 From: Slava Ovsiienko To: Ori Kam , Matan Azrad , Shahaf Shuler CC: "dev@dpdk.org" , Ori Kam , "jingjing.wu@intel.com" , "stephen@networkplumber.org" Thread-Topic: [PATCH 10/13] net/mlx5: add id generation function Thread-Index: AQHVdDPm9+k/PhP2l0KBEEq6IPzcz6c9spRg Date: Thu, 26 Sep 2019 09:34:00 +0000 Message-ID: References: <1569479349-36962-1-git-send-email-orika@mellanox.com> <1569479349-36962-11-git-send-email-orika@mellanox.com> In-Reply-To: <1569479349-36962-11-git-send-email-orika@mellanox.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=viacheslavo@mellanox.com; x-originating-ip: [95.67.35.250] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: d20e2524-c073-46b0-38c0-08d74264a994 x-ms-office365-filtering-ht: Tenant x-ms-traffictypediagnostic: AM4PR05MB3281:|AM4PR05MB3281: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:2512; x-forefront-prvs: 0172F0EF77 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(4636009)(39860400002)(136003)(396003)(346002)(376002)(366004)(13464003)(199004)(189003)(71190400001)(71200400001)(33656002)(316002)(6246003)(7696005)(6436002)(76176011)(6506007)(53546011)(99286004)(110136005)(8936002)(8676002)(3846002)(9686003)(14444005)(476003)(6116002)(256004)(486006)(102836004)(229853002)(2906002)(54906003)(26005)(81156014)(81166006)(11346002)(66446008)(66946007)(66476007)(66556008)(64756008)(76116006)(6636002)(55016002)(186003)(74316002)(66066001)(5660300002)(25786009)(52536014)(478600001)(446003)(305945005)(7736002)(4326008)(14454004)(86362001); DIR:OUT; SFP:1101; SCL:1; SRVR:AM4PR05MB3281; H:AM4PR05MB3265.eurprd05.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 7hVFpAmqHU53pcKpznWasn8f7bMmu2EClbJWg5nGd85wPdCvG/wVXnGNomGFyH25pK4oXZFfCJKmeXTJPhZwJ3KwUQGuA/g+bYHb3gOt5E9U9srdRb2QZRCwMjY25jLBAVEwFF0tJ7ID7jryOrohCOdEQv41IJqeBKxQpk6HIBOtYwXui7AFxnpA+DisjdFELUEui44HBLT2xCaltF2VWNjVxJEBgOYKljKV0+AtrA6JOSMID/ePIRrX8EHc31QJP9pu+QaAEv3XTZ/ujYz1KGd/I01s5cq6Uu4ZNXsSxPydHHD5QMV1XIZ4bQlSeFeU5SgcRncyvBl3oyxkW9wdUcs3zaNvWLM+WdKvJg9OXFy4xPGizTp6h1Py2DtwpEhMP/143ZfTm+eoaN61jlzGzN9epdGJoI6dWX8yKgIUYmg= Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-Network-Message-Id: d20e2524-c073-46b0-38c0-08d74264a994 X-MS-Exchange-CrossTenant-originalarrivaltime: 26 Sep 2019 09:34:00.3971 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 7ZcQMod8npLiMozJfjzadmUXdacWeurCnnPQ+aEt/+rJ70mERijWhuV9MKd1gkcCoXc3u9LA5mKp67GiaeUBNLgRtVFQ1eyCVMPapougYsg= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM4PR05MB3281 Subject: Re: [dpdk-dev] [PATCH 10/13] net/mlx5: add id generation 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" > -----Original Message----- > From: Ori Kam > Sent: Thursday, September 26, 2019 9:29 > To: Matan Azrad ; Shahaf Shuler > ; Slava Ovsiienko > Cc: dev@dpdk.org; Ori Kam ; jingjing.wu@intel.com; > stephen@networkplumber.org > Subject: [PATCH 10/13] net/mlx5: add id generation function >=20 > When splitting flows for example in hairpin / metering, there is a need t= o > combine the flows. This is done using ID. > This commit introduce a simple way to generate such IDs. >=20 > The reason why bitmap was not used is due to fact that the release and > allocation are O(n) while in the chosen approch the allocation and releas= e > are O(1) >=20 > Signed-off-by: Ori Kam Acked-by: Viacheslav Ovsiienko > --- > drivers/net/mlx5/mlx5.c | 120 > ++++++++++++++++++++++++++++++++++++++++++- > drivers/net/mlx5/mlx5_flow.h | 14 +++++ > 2 files changed, 133 insertions(+), 1 deletion(-) >=20 > diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c index > ad36743..940503d 100644 > --- a/drivers/net/mlx5/mlx5.c > +++ b/drivers/net/mlx5/mlx5.c > @@ -179,6 +179,124 @@ struct mlx5_dev_spawn_data { static LIST_HEAD(, > mlx5_ibv_shared) mlx5_ibv_list =3D LIST_HEAD_INITIALIZER(); static > pthread_mutex_t mlx5_ibv_list_mutex =3D PTHREAD_MUTEX_INITIALIZER; >=20 > +#define MLX5_FLOW_MIN_ID_POOL_SIZE 512 > +#define MLX5_ID_GENERATION_ARRAY_FACTOR 16 > + > +/** > + * Allocate ID pool structure. > + * > + * @return > + * Pointer to pool object, NULL value otherwise. > + */ > +struct mlx5_flow_id_pool * > +mlx5_flow_id_pool_alloc(void) > +{ > + struct mlx5_flow_id_pool *pool; > + void *mem; > + > + pool =3D rte_zmalloc("id pool allocation", sizeof(*pool), > + RTE_CACHE_LINE_SIZE); > + if (!pool) { > + DRV_LOG(ERR, "can't allocate id pool"); > + rte_errno =3D ENOMEM; > + return NULL; > + } > + mem =3D rte_zmalloc("", MLX5_FLOW_MIN_ID_POOL_SIZE * > sizeof(uint32_t), > + RTE_CACHE_LINE_SIZE); > + if (!mem) { > + DRV_LOG(ERR, "can't allocate mem for id pool"); > + rte_errno =3D ENOMEM; > + goto error; > + } > + pool->free_arr =3D mem; > + pool->curr =3D pool->free_arr; > + pool->last =3D pool->free_arr + MLX5_FLOW_MIN_ID_POOL_SIZE; > + pool->base_index =3D 0; > + return pool; > +error: > + rte_free(pool); > + return NULL; > +} > + > +/** > + * Release ID pool structure. > + * > + * @param[in] pool > + * Pointer to flow id pool object to free. > + */ > +void > +mlx5_flow_id_pool_release(struct mlx5_flow_id_pool *pool) { > + rte_free(pool->free_arr); > + rte_free(pool); > +} > + > +/** > + * Generate ID. > + * > + * @param[in] pool > + * Pointer to flow id pool. > + * @param[out] id > + * The generated ID. > + * > + * @return > + * 0 on success, error value otherwise. > + */ > +uint32_t > +mlx5_flow_id_get(struct mlx5_flow_id_pool *pool, uint32_t *id) { > + if (pool->curr =3D=3D pool->free_arr) { > + if (pool->base_index =3D=3D UINT32_MAX) { > + rte_errno =3D ENOMEM; > + DRV_LOG(ERR, "no free id"); > + return -rte_errno; > + } > + *id =3D ++pool->base_index; > + return 0; > + } > + *id =3D *(--pool->curr); > + return 0; > +} > + > +/** > + * Release ID. > + * > + * @param[in] pool > + * Pointer to flow id pool. > + * @param[out] id > + * The generated ID. > + * > + * @return > + * 0 on success, error value otherwise. > + */ > +uint32_t > +mlx5_flow_id_release(struct mlx5_flow_id_pool *pool, uint32_t id) { > + uint32_t size; > + uint32_t size2; > + void *mem; > + > + if (pool->curr =3D=3D pool->last) { > + size =3D pool->curr - pool->free_arr; > + size2 =3D size * MLX5_ID_GENERATION_ARRAY_FACTOR; > + assert(size2 > size); > + mem =3D rte_malloc("", size2 * sizeof(uint32_t), 0); > + if (!mem) { > + DRV_LOG(ERR, "can't allocate mem for id pool"); > + rte_errno =3D ENOMEM; > + return -rte_errno; > + } > + memcpy(mem, pool->free_arr, size * sizeof(uint32_t)); > + rte_free(pool->free_arr); > + pool->free_arr =3D mem; > + pool->curr =3D pool->free_arr + size; > + pool->last =3D pool->free_arr + size2; > + } > + *pool->curr =3D id; > + pool->curr++; > + return 0; > +} > + > /** > * Initialize the counters management structure. > * > @@ -329,7 +447,7 @@ struct mlx5_dev_spawn_data { > struct mlx5_devx_tis_attr tis_attr =3D { 0 }; #endif >=20 > - assert(spawn); > +assert(spawn); > /* Secondary process should not create the shared context. */ > assert(rte_eal_process_type() =3D=3D RTE_PROC_PRIMARY); > pthread_mutex_lock(&mlx5_ibv_list_mutex); > diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h > index 0148c1b..1b14fb7 100644 > --- a/drivers/net/mlx5/mlx5_flow.h > +++ b/drivers/net/mlx5/mlx5_flow.h > @@ -495,8 +495,22 @@ struct mlx5_flow_driver_ops { #define > MLX5_CNT_CONTAINER_UNUSED(sh, batch, thread) (&(sh)->cmng.ccont \ > [(~((sh)->cmng.mhi[batch] >> (thread)) & 0x1) * 2 + (batch)]) >=20 > +/* ID generation structure. */ > +struct mlx5_flow_id_pool { > + uint32_t *free_arr; /**< Pointer to the a array of free values. */ > + uint32_t base_index; > + /**< The next index that can be used without any free elements. */ > + uint32_t *curr; /**< Pointer to the index to pop. */ > + uint32_t *last; /**< Pointer to the last element in the empty arrray. > +*/ }; > + > /* mlx5_flow.c */ >=20 > +struct mlx5_flow_id_pool *mlx5_flow_id_pool_alloc(void); void > +mlx5_flow_id_pool_release(struct mlx5_flow_id_pool *pool); uint32_t > +mlx5_flow_id_get(struct mlx5_flow_id_pool *pool, uint32_t *id); > +uint32_t mlx5_flow_id_release(struct mlx5_flow_id_pool *pool, > + uint32_t id); > int mlx5_flow_group_to_table(const struct rte_flow_attr *attributes, > bool external, uint32_t group, uint32_t *table, > struct rte_flow_error *error); > -- > 1.8.3.1