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 74023A0563; Wed, 15 Apr 2020 16:22:54 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id E7D001D5E0; Wed, 15 Apr 2020 16:22:53 +0200 (CEST) Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-eopbgr70052.outbound.protection.outlook.com [40.107.7.52]) by dpdk.org (Postfix) with ESMTP id DBFED1D56E for ; Wed, 15 Apr 2020 16:22:52 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=axV8Vc5JgXEavxeIjCOT2Mz4LuqBRaY7Sy1ePeSHVipWmPzw+XWipp8Tv4jIAVeZ1cPSGx8qtCc47X5QSS8+ro3xAfvRE9jGDGp/OlMD3FF3zByt16qNirtm1DOi4vK/Kaa/6aNaIevuvFG7e1YGVLj2D8C+p6C5eK7t++MiXGMirpVxS6pAjLJkHCD4bx6tbndFZrk2yxXOIaE8HcXLube/t/1w9VAad9pG1SYhJKr6jpM4NgQy9w1t9v6hN7rynnxSoDRbbuog7h2HG2HmFW4ifJztkNYH2alnp8DP2rGQOofnqtWYVKo3Elti/GKz5woobeBftatCNko92DhOpg== 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=7Vz0VPdxE3F8x9wfXd7g4Rk7T5SGgRkLNsrt5FH981Y=; b=kHR5Jgx8Hn97KecewxicDFUqS4iNNEud0kP0QAlQUN4ZW+wGMrJ+CFk18kcWZ40A6itchBsTviYLyyR92l+uP16TjHFCn+Jp+iTkqoaRoOQTgiSeFb/dzpqE3XIcgD9qiZ5r4lQGt5HnLWarH3yfZt0cq49+Y+R1UdxqYymOWwITPBv0X6ptKzCyKdUPQf3mFpMsBpGe7ypxnu1JebsiSchMuY6xF7qPgosj3lJq0VhJqSAcLCW5EUgimTGpUGQIfLiTXd7JirQrmfyDZZrdSw+ikrsz21NJnnV6i3ZyX8NGOi4budFiTMMYwZIjLnYZKA6V6c7QWV7fulTCAR5i+g== 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=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=7Vz0VPdxE3F8x9wfXd7g4Rk7T5SGgRkLNsrt5FH981Y=; b=jUUVD9v2hCkA3g8MOOqUFN3JW+2ijQOwMIoCYvDfatrLqilwOLKMzsR9uHUEEmN3J5i/ZF2SvN1psMe1W0XDUOUMhIDS9kB8Q+M5rx8ABxSMWEu81tTlE2fberqoExR08Ec5/CAwVoQs6pu2HQvVvBM95dDDq3xrIp/Z/nzjcmY= Received: from HE1PR05MB3484.eurprd05.prod.outlook.com (2603:10a6:7:2f::12) by HE1PR05MB3436.eurprd05.prod.outlook.com (2603:10a6:7:2e::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2900.26; Wed, 15 Apr 2020 14:22:50 +0000 Received: from HE1PR05MB3484.eurprd05.prod.outlook.com ([fe80::3022:cbe2:4523:718a]) by HE1PR05MB3484.eurprd05.prod.outlook.com ([fe80::3022:cbe2:4523:718a%4]) with mapi id 15.20.2900.028; Wed, 15 Apr 2020 14:22:50 +0000 From: Suanming Mou To: Thomas Monjalon , "dev@dpdk.org" CC: "amo@semihalf.com" , Cristian Dumitrescu Thread-Topic: [PATCH v4] bitmap: add init with all bits set Thread-Index: AQHWEzBY30Fx2Amc+0+wCDHeIEE/Lah6O33g Date: Wed, 15 Apr 2020 14:22:50 +0000 Message-ID: References: <1583828479-204084-1-git-send-email-suanmingm@mellanox.com> <20200415141529.2057898-1-thomas@monjalon.net> In-Reply-To: <20200415141529.2057898-1-thomas@monjalon.net> 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=suanmingm@mellanox.com; x-originating-ip: [115.193.229.2] x-ms-publictraffictype: Email x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: d7293bb9-22c6-49dc-2e20-08d7e1487a84 x-ms-traffictypediagnostic: HE1PR05MB3436: x-ld-processed: a652971c-7d2e-4d9b-a6a4-d149256f461b,ExtAddr x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:7691; x-forefront-prvs: 0374433C81 x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:HE1PR05MB3484.eurprd05.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(10009020)(4636009)(376002)(366004)(136003)(396003)(39860400002)(346002)(76116006)(316002)(110136005)(7696005)(6506007)(53546011)(66946007)(66476007)(54906003)(64756008)(4326008)(26005)(5660300002)(66446008)(66556008)(478600001)(8676002)(52536014)(186003)(8936002)(9686003)(81156014)(86362001)(55016002)(71200400001)(33656002)(2906002); DIR:OUT; SFP:1101; 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: ZNyB3EdpVurfm8RNbwmpdzwgXxOGorC01qNKyj1zPngas2lNT781JsFGq8/3yz5AtBtoCl/YNtaqn5z+GefxIfk7RsjOx5p0t68j+mODspH12m8G1pjhQNzzlwIluPjauU9wxVBrcZluHYtlXx2qPM52A52tgKSAhPqKKonAMOAaXeM7eEXeVuozLGp8rNmDcNErOuojqn4J9HFSBRE/w0AZBt1R9iQi+TNJE7Bw11vcRUR1jgyonqW8+XLC8AR50HVeKOyGQd1TVoJE9KJe+MudrfTMO/03ekLWHcLEcJo3hVogek4kco1kgQOd96NcqpUWpRUNzxfUnrKdiVj72qkpdBAUeP8YmHdrfDE7txezvFtz7DHkLn7ra5ofaEyJznr0RVo1fyMvDXMmUM/8pxD+x5tqulAbdLm8WEXqktzfjiRcCrgtGS7mf0V4E0/t x-ms-exchange-antispam-messagedata: juLlmkHbQ/AeZVBioy5IEAb3zfoIv+xz6F35U9sF5BYQThF5GJvk7wbivwMZ6kNbwZcg89iY6vsji9ZWYMidnhCidoSaF/Z73INVo0zRaniozHz/dRZPc8LYHRu2RRJklY515oUNVfl5+5ewm7elng== x-ms-exchange-transport-forked: True 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: d7293bb9-22c6-49dc-2e20-08d7e1487a84 X-MS-Exchange-CrossTenant-originalarrivaltime: 15 Apr 2020 14:22:50.3923 (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: GAsZkOF4sT9NTcW1g5Y2FcTIr/02SKZzqMDzf39vnUkQh85FViZy2s/9JCsyITucAqC6QzhWmMM3GvjEPX65Ww== X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR05MB3436 Subject: Re: [dpdk-dev] [PATCH v4] bitmap: add init with all bits set 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" Hi Thomas, Thanks for the update. > -----Original Message----- > From: Thomas Monjalon > Sent: Wednesday, April 15, 2020 10:15 PM > To: dev@dpdk.org > Cc: amo@semihalf.com; Suanming Mou ; Cristian > Dumitrescu > Subject: [PATCH v4] bitmap: add init with all bits set >=20 > From: Suanming Mou >=20 > Currently, in the case to use bitmap as resource allocator, after bitmap = creation, > all the bitmap bits should be set to indicate the bit available. Every ti= me when > allocate one bit, search for the set bits and clear it to make it in use. >=20 > Add a new rte_bitmap_init_with_all_set() function to have a quick fill up= the > bitmap bits. >=20 > Comparing with the case create the bitmap as empty and set the bitmap one= by > one, the new function costs less cycles. >=20 > Signed-off-by: Suanming Mou > Acked-by: Cristian Dumitrescu Reviewed-by: Suanming Mou > --- >=20 > v4: > - add experimental tags and comments > - move functions near original init function > - squash test patch > - use "init" word in title >=20 > v3 updates: > 1. Implement individual rte_bitmap_init_with_all_set() function. > 2. Add new function to clear the overhead bits. >=20 > v2 updates: > 1. Split the common part to __rte_bitmap_init(). > 2. Set the slab bits more customized. >=20 > --- > app/test/test_bitmap.c | 57 ++++++++++++++++++- > lib/librte_eal/include/rte_bitmap.h | 85 +++++++++++++++++++++++++++++ > 2 files changed, 141 insertions(+), 1 deletion(-) >=20 > diff --git a/app/test/test_bitmap.c b/app/test/test_bitmap.c index > 95c5184882..a8204d329f 100644 > --- a/app/test/test_bitmap.c > +++ b/app/test/test_bitmap.c > @@ -146,7 +146,7 @@ test_bitmap_set_get_clear(struct rte_bitmap *bmp) } >=20 > static int > -test_bitmap(void) > +test_bitmap_all_clear(void) > { > void *mem; > uint32_t bmp_size; > @@ -182,4 +182,59 @@ test_bitmap(void) > return TEST_SUCCESS; > } >=20 > +static int > +test_bitmap_all_set(void) > +{ > + void *mem; > + uint32_t i; > + uint64_t slab; > + uint32_t pos; > + uint32_t bmp_size; > + struct rte_bitmap *bmp; > + > + bmp_size =3D > + rte_bitmap_get_memory_footprint(MAX_BITS); > + > + mem =3D rte_zmalloc("test_bmap", bmp_size, RTE_CACHE_LINE_SIZE); > + if (mem =3D=3D NULL) { > + printf("Failed to allocate memory for bitmap\n"); > + return TEST_FAILED; > + } > + > + bmp =3D rte_bitmap_init_with_all_set(MAX_BITS, mem, bmp_size); > + if (bmp =3D=3D NULL) { > + printf("Failed to init bitmap\n"); > + return TEST_FAILED; > + } > + > + for (i =3D 0; i < MAX_BITS; i++) { > + pos =3D slab =3D 0; > + if (!rte_bitmap_scan(bmp, &pos, &slab)) { > + printf("Failed with init bitmap.\n"); > + return TEST_FAILED; > + } > + pos +=3D (slab ? __builtin_ctzll(slab) : 0); > + rte_bitmap_clear(bmp, pos); > + } > + > + if (rte_bitmap_scan(bmp, &pos, &slab)) { > + printf("Too much bits set.\n"); > + return TEST_FAILED; > + } > + > + rte_bitmap_free(bmp); > + rte_free(mem); > + > + return TEST_SUCCESS; > + > +} > + > +static int > +test_bitmap(void) > +{ > + if (test_bitmap_all_clear() !=3D TEST_SUCCESS) > + return TEST_FAILED; > + return test_bitmap_all_set(); > +} > + > REGISTER_TEST_COMMAND(bitmap_test, test_bitmap); diff --git > a/lib/librte_eal/include/rte_bitmap.h b/lib/librte_eal/include/rte_bitmap= .h > index 6b846f251b..7c90ef333f 100644 > --- a/lib/librte_eal/include/rte_bitmap.h > +++ b/lib/librte_eal/include/rte_bitmap.h > @@ -203,6 +203,91 @@ rte_bitmap_init(uint32_t n_bits, uint8_t *mem, > uint32_t mem_size) > return bmp; > } >=20 > +/** > + * @warning > + * @b EXPERIMENTAL: this API may change without prior notice. > + * > + * Bitmap clear slab overhead bits. > + * > + * @param slabs > + * Slab array. > + * @param slab_size > + * Number of 64-bit slabs in the slabs array. > + * @param pos > + * The start bit position in the slabs to be cleared. > + */ > +__rte_experimental > +static inline void > +__rte_bitmap_clear_slab_overhead_bits(uint64_t *slabs, uint32_t slab_siz= e, > + uint32_t pos) > +{ > + uint32_t i; > + uint32_t index =3D pos / RTE_BITMAP_SLAB_BIT_SIZE; > + uint32_t offset =3D pos & RTE_BITMAP_SLAB_BIT_MASK; > + > + if (offset) { > + for (i =3D offset; i < RTE_BITMAP_SLAB_BIT_SIZE; i++) > + slabs[index] &=3D ~(1llu << i); > + index++; > + } > + if (index < slab_size) > + memset(&slabs[index], 0, sizeof(slabs[0]) * > + (slab_size - index)); > +} > + > +/** > + * @warning > + * @b EXPERIMENTAL: this API may change without prior notice. > + * > + * Bitmap initialization with all bits set > + * > + * @param n_bits > + * Number of pre-allocated bits in array2. > + * @param mem > + * Base address of array1 and array2. > + * @param mem_size > + * Minimum expected size of bitmap. > + * @return > + * Handle to bitmap instance. > + */ > +__rte_experimental > +static inline struct rte_bitmap * > +rte_bitmap_init_with_all_set(uint32_t n_bits, uint8_t *mem, uint32_t > +mem_size) { > + struct rte_bitmap *bmp; > + uint32_t array1_byte_offset, array1_slabs; > + uint32_t array2_byte_offset, array2_slabs; > + uint32_t size; > + > + /* Check input arguments */ > + if (!n_bits || !mem || (((uintptr_t) mem) & RTE_CACHE_LINE_MASK)) > + return NULL; > + > + size =3D __rte_bitmap_get_memory_footprint(n_bits, > + &array1_byte_offset, &array1_slabs, > + &array2_byte_offset, &array2_slabs); > + if (size < mem_size) > + return NULL; > + > + /* Setup bitmap */ > + bmp =3D (struct rte_bitmap *) mem; > + bmp->array1 =3D (uint64_t *) &mem[array1_byte_offset]; > + bmp->array1_size =3D array1_slabs; > + bmp->array2 =3D (uint64_t *) &mem[array2_byte_offset]; > + bmp->array2_size =3D array2_slabs; > + > + __rte_bitmap_scan_init(bmp); > + > + memset(bmp->array1, 0xff, bmp->array1_size * sizeof(bmp->array1[0])); > + memset(bmp->array2, 0xff, bmp->array2_size * sizeof(bmp->array2[0])); > + /* Clear overhead bits. */ > + __rte_bitmap_clear_slab_overhead_bits(bmp->array1, bmp- > >array1_size, > + bmp->array2_size >> > RTE_BITMAP_CL_SLAB_SIZE_LOG2); > + __rte_bitmap_clear_slab_overhead_bits(bmp->array2, bmp- > >array2_size, > + n_bits); > + return bmp; > +} > + > /** > * Bitmap free > * > -- > 2.26.0