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 5919FA059F; Fri, 10 Apr 2020 13:21:32 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 8E74C1C298; Fri, 10 Apr 2020 13:21:31 +0200 (CEST) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by dpdk.org (Postfix) with ESMTP id 0D1DA1C1AA for ; Fri, 10 Apr 2020 13:21:29 +0200 (CEST) IronPort-SDR: pj/bxwprb8n0Or5HYm6iJaQIU7gQHpMoJtTOvT1w5ZghHRAdPSkUnjTYl/qwkmOQUlVwE8GNLz rgpRTEsi5S3w== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Apr 2020 04:21:29 -0700 IronPort-SDR: UtHPh78WaOZNF7ZTeFnFhLNT3sJypPEAS5GI2O3x6DP2o2vGKQsDzPjAufwc3XZR6xIUADVaCL DpjuQtq98ZnA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.72,366,1580803200"; d="scan'208";a="260337368" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by orsmga008.jf.intel.com with ESMTP; 10 Apr 2020 04:21:28 -0700 Received: from fmsmsx153.amr.corp.intel.com (10.18.125.6) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.439.0; Fri, 10 Apr 2020 04:21:28 -0700 Received: from FMSEDG002.ED.cps.intel.com (10.1.192.134) by FMSMSX153.amr.corp.intel.com (10.18.125.6) with Microsoft SMTP Server (TLS) id 14.3.439.0; Fri, 10 Apr 2020 04:21:27 -0700 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (104.47.55.104) by edgegateway.intel.com (192.55.55.69) with Microsoft SMTP Server (TLS) id 14.3.439.0; Fri, 10 Apr 2020 04:21:27 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=d3qkiLdq9D/pXdNslmNRQjr+w76Wq6faKSAEOjXYDrMhau7sK5rv8kkUSEKNzXHC8Hi1EE3JVUUdQisP0OXEUydbpmvWoagXN5xsjxV+0ObiXVI2hE5Kc3a4kpPjpXOdU3vblXgvZnmeIH1/iBopAXNvM/Jji+zHuvg884aN9u8Ov1qX2pJaiAkFz+Y+S2gtlvYU7SrzGu5Bid4mZj350C1sU8Zp0KZTF/3X1Fapdyo5EMaapboC+47868GzfzkhbHSH9H6/LtjL4I10ZkpWC2gmQp2rgjxphTjFinqAz2gl2mWVYt1jAuY1MEECvpKd4NCZ/9SczX/6E1kUTxh5mg== 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=UpWMAuinjpym+aX8RyMficGLptTaQIXzUq+A4rvndB8=; b=jf++LqiLfYkrlFBvCuGK16FSF2seXDHO01HzKQVNjDPJlyj7GwJZmHAf9N2jN/Kzj9dIsYQWN6SdpjRtxSquM0H4H3GMsZTfMUC1dzGqBdnwb5/F3VloyPH+B/kUwO8l2dOlPOckjyJMHzvxvzulA98Z2Bv+hjtyVRg1ymcNrAAi4534l6j9oIQDlF/4IrEG8WW+4ko+KrfFAbQMLsLq7OrzTCnsRC8xYQzoDzof8uGz7cvNCh0Yo6UmbWMaewOGIbUbFAu2DHZAlCbamsejlYAkd09oQOEr2OqJglYceKbWoFYTsEc20VDVdKKECikuNK8yTdQOmJcF/mcHV9Le1w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.onmicrosoft.com; s=selector2-intel-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=UpWMAuinjpym+aX8RyMficGLptTaQIXzUq+A4rvndB8=; b=WUFLWUmxyzgLc14TCtN5Jn7w+wq2nDcr9uRTyjyfEi/LAQmrrxayZ192p6fCTX86n2vPSuanmJciObz8h3ceVcjfxDzuaGvifVnx5XuzmeXscAD03ewAK69RfhvlyDkU4eKOdjduPWRbH9gAPxRZrP4EF4FsATm5HyyF++qpgRk= Received: from BYAPR11MB2935.namprd11.prod.outlook.com (2603:10b6:a03:82::24) by BYAPR11MB3079.namprd11.prod.outlook.com (2603:10b6:a03:92::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2900.20; Fri, 10 Apr 2020 11:21:25 +0000 Received: from BYAPR11MB2935.namprd11.prod.outlook.com ([fe80::786e:a42b:df03:a829]) by BYAPR11MB2935.namprd11.prod.outlook.com ([fe80::786e:a42b:df03:a829%5]) with mapi id 15.20.2878.021; Fri, 10 Apr 2020 11:21:25 +0000 From: "Dumitrescu, Cristian" To: Suanming Mou CC: "dev@dpdk.org" , "amo@semihalf.com" Thread-Topic: [PATCH v2 1/2] bitmap: add create bitmap with all bits set Thread-Index: AQHWDVLCGAx7wbO030GjaH+EmFcxhqhw1RVQgAEqGgCAADmIUA== Date: Fri, 10 Apr 2020 11:21:24 +0000 Message-ID: References: <1583828479-204084-1-git-send-email-suanmingm@mellanox.com> <1586315145-6633-1-git-send-email-suanmingm@mellanox.com> <1586315145-6633-2-git-send-email-suanmingm@mellanox.com> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-version: 11.2.0.6 dlp-reaction: no-action dlp-product: dlpe-windows authentication-results: spf=none (sender IP is ) smtp.mailfrom=cristian.dumitrescu@intel.com; x-originating-ip: [192.198.151.175] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: aea608e1-8d74-46e5-ff38-08d7dd414e2b x-ms-traffictypediagnostic: BYAPR11MB3079: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:8273; x-forefront-prvs: 0369E8196C x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BYAPR11MB2935.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(10019020)(346002)(396003)(366004)(136003)(376002)(39860400002)(6916009)(4326008)(55016002)(71200400001)(86362001)(54906003)(52536014)(316002)(5660300002)(9686003)(33656002)(66476007)(66556008)(66946007)(7696005)(6506007)(53546011)(26005)(2906002)(8676002)(64756008)(66446008)(81156014)(76116006)(186003)(8936002)(478600001); DIR:OUT; SFP:1102; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: s6oz2vl4hjLqxfDdA7C44glWE4rtHE2HJu/6qDr2NZxdzlcdXhFBl25PVydQVsEvm965zOXysermx4iHCsYPXtpsoytbnso58vIvFHDpVycm4MoRsX4ZlEfWZxPIFk6IaACG2UXAC+NNgcGYQcE+wmknB6umUrINVck1xznIRtxnAFeZVPquWPVSqXpBKzXRRRfftegMzpdLcWn48RU5/wMnto/b1+Q/4b+cXnFB2IqeaYfDERuS5HOT0qqWk7nuYl+dFKV7VFM5+i0lr47uIS1UXJ08eUChJcfKUwUPhsNHL9W2Pg+y9A4zf7kJ57sVYI1moVL7yCLBvch+DpZUh0UatuDy2f5hbQbVl4ocC1rBZTkH8QWw+HvJRnRZY7fmRkWf8LMgOUUVEDqVH0FD3BKuEwVXp366cbzNi1Tri3PzFEfu7ngAl14rA8nnAb85 x-ms-exchange-antispam-messagedata: KRQ67ZG3ffEGRjB7bjnpm5anOlPm3AdFUKmT9EoBaNDJCppuB5ycuBMCGCDRP1St/YhZdejxf4uU8eHZtmKOhZNnHTHHWl89L2cQ/KlW7lB3TB8nT+WojGCr7W4yUNx9AnTaJixZ+ND9kD+wYfPGwg== x-ms-exchange-transport-forked: True Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: aea608e1-8d74-46e5-ff38-08d7dd414e2b X-MS-Exchange-CrossTenant-originalarrivaltime: 10 Apr 2020 11:21:24.6615 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: huvXWeMCn368C9HXvEhbyWYr0a4zyvOF5Y0DsWhJTkBs6eMVtjo9NS/sRQsr1+IgKRQMprIwYvOTck6myEamXsbxDD1Tpp1fy9hmmPcII64= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR11MB3079 X-OriginatorOrg: intel.com Subject: Re: [dpdk-dev] [PATCH v2 1/2] bitmap: add create bitmap 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" > -----Original Message----- > From: Suanming Mou > Sent: Friday, April 10, 2020 11:34 AM > To: Dumitrescu, Cristian > Cc: dev@dpdk.org; amo@semihalf.com > Subject: RE: [PATCH v2 1/2] bitmap: add create bitmap with all bits set >=20 >=20 >=20 > > -----Original Message----- > > From: Dumitrescu, Cristian > > Sent: Thursday, April 9, 2020 10:16 PM > > To: Suanming Mou > > Cc: dev@dpdk.org; amo@semihalf.com > > Subject: RE: [PATCH v2 1/2] bitmap: add create bitmap with all bits set > > > > Hi Sunaming, > > > > > -----Original Message----- > > > From: Suanming Mou > > > Sent: Wednesday, April 8, 2020 4:06 AM > > > To: Dumitrescu, Cristian > > > Cc: dev@dpdk.org; amo@semihalf.com > > > Subject: [PATCH v2 1/2] bitmap: add create bitmap with all bits set > > > > > > Currently, in the case to use bitmap as resource allocator, after > > > bitmap creation, all the bitmap bits should be set to indicate the bi= t > > > available. Every time when allocate one bit, search for the set bits > > > and clear it to make it in use. > > > > > > Add a new rte_bitmap_init_with_all_set() function to have a quick fil= l > > > up the bitmap bits. > > > > > > Comparing with the case create the bitmap as empty and set the bitmap > > > one by one, the new function costs less cycles. > > > > > > Signed-off-by: Suanming Mou > > > --- > > > lib/librte_eal/common/include/rte_bitmap.h | 113 > > > ++++++++++++++++++++++------- > > > 1 file changed, 85 insertions(+), 28 deletions(-) > > > > > > diff --git a/lib/librte_eal/common/include/rte_bitmap.h > > > b/lib/librte_eal/common/include/rte_bitmap.h > > > index 6b846f2..740076b 100644 > > > --- a/lib/librte_eal/common/include/rte_bitmap.h > > > +++ b/lib/librte_eal/common/include/rte_bitmap.h > > > @@ -136,6 +136,40 @@ struct rte_bitmap { > > > bmp->go2 =3D 0; > > > } > > > > > > +static inline struct rte_bitmap * > > > +__rte_bitmap_init(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 =3D=3D 0) > > > + return NULL; > > > + > > > + if ((mem =3D=3D NULL) || (((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); > > > + > > > + return bmp; > > > +} > > > + > > > /** > > > * Bitmap memory footprint calculation > > > * > > > @@ -170,36 +204,12 @@ struct rte_bitmap { rte_bitmap_init(uint32_t > > > n_bits, uint8_t *mem, uint32_t mem_size) { > > > struct rte_bitmap *bmp; > > > - uint32_t array1_byte_offset, array1_slabs, array2_byte_offset, > > > array2_slabs; > > > - uint32_t size; > > > > > > - /* Check input arguments */ > > > - if (n_bits =3D=3D 0) { > > > - return NULL; > > > - } > > > - > > > - if ((mem =3D=3D NULL) || (((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) { > > > + bmp =3D __rte_bitmap_init(n_bits, mem, mem_size); > > > + if (!bmp) > > > return NULL; > > > - } > > > - > > > - /* Setup bitmap */ > > > - memset(mem, 0, size); > > > - 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, 0, bmp->array1_size * sizeof(uint64_t)); > > > + memset(bmp->array2, 0, bmp->array2_size * sizeof(uint64_t)); > > > return bmp; > > > } > > > > > > > Can we please leave the function rte_bitmap_init() unmodified and put a= ll > > changes in the new function rte_bitmap_init_with_all_set(). I realize t= his > means > > duplicating a few lines of code between the two init functions, but IMO > easier to > > maintain going forward. >=20 > Sure. Agree with that, so let's keep the rte_bitmap_init() unmodified. > > > > > @@ -483,6 +493,53 @@ struct rte_bitmap { > > > return 0; > > > } > > > > > > +/** > > > + * 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. > > > + */ > > > +static inline struct rte_bitmap * > > > +rte_bitmap_init_with_all_set(uint32_t n_bits, uint8_t *mem, uint32_t > > > mem_size) > > > +{ > > > + uint32_t i; > > > + uint32_t slabs, array1_bits; > > > + struct rte_bitmap *bmp; > > > + > > > + bmp =3D __rte_bitmap_init(n_bits, mem, mem_size); > > > + if (!bmp) > > > + return NULL; > > > + > > > + array1_bits =3D bmp->array2_size >> > > > RTE_BITMAP_CL_SLAB_SIZE_LOG2; > > > + /* Fill the arry1 slab aligned bits. */ > > > + slabs =3D array1_bits >> RTE_BITMAP_SLAB_BIT_SIZE_LOG2; > > > + memset(bmp->array1, 0xff, slabs * sizeof(bmp->array1[0])); > > > + /* Clear the array1 left slabs. */ > > > + memset(&bmp->array1[slabs], 0, (bmp->array1_size - slabs) * > > > + sizeof(bmp->array1[0])); > > > + /* Fill the array1 middle not full set slab. */ > > > + for (i =3D 0; i < (array1_bits & RTE_BITMAP_SLAB_BIT_MASK); i++) > > > + bmp->array1[slabs] |=3D 1llu << i; > > > + > > > + /* Fill the arry2 slab aligned bits. */ > > > + slabs =3D n_bits >> RTE_BITMAP_SLAB_BIT_SIZE_LOG2; > > > + memset(bmp->array2, 0xff, slabs * sizeof(bmp->array2[0])); > > > + /* Clear the array2 left slabs. */ > > > + memset(&bmp->array2[slabs], 0, (bmp->array2_size - slabs) * > > > + sizeof(bmp->array2[0])); > > > + /* Fill the array2 middle not full set slab. */ > > > + for (i =3D 0; i < (n_bits & RTE_BITMAP_SLAB_BIT_MASK); i++) > > > + bmp->array2[slabs] |=3D 1llu << i; > > > + > > > + return bmp; > > > +} > > > + > > > #ifdef __cplusplus > > > } > > > #endif > > > -- > > > 1.8.3.1 > > > > This code is not that easy to read. This function is tricky to implemen= t, as > we > > basically need to correct some overhead bits in array1 and array2. > > > > What I suggest for the layout of this function: > > -call essentially the same code as rte_bitmap_init(), with the change t= hat > we set > > ALL the bits in array1 and array2 to 1 instead of 0 -call a new helper = function > to > > correct (set to 0) all the array2 bits from position (index2, offset2)= to the > end - > > call a new helper function to correct (set to 0) all the array1 bits fr= om > position > > (index1, offset1) to the end >=20 > Good suggestion. > What about the function below, it will help both arry1 and array2 clear t= he > not needed bits: > /** > * Bitmap clear slab overhead bits. > * > * @param slab > * Slab arrary. > * @param size > * Slab array size. For more clarity, maybe document the size parameter as: number of 64-bit sl= abs in the slabs array. > * @param pos > * The start bit position in the slabs to be cleared. > */ > static inline void > __rte_bitmap_clear_slab_overhead_bits(uint64_t *slabs, uint32_t slab_size= , > 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; >=20 > 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)); > } > Excellent, I like it, thanks Suanming! =20 > It seems that is a bit difficult to find a none tricky way to clear the b= its. > > > > What do you think? > > > > Thanks, > > Cristian