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 D8205A0597; Thu, 9 Apr 2020 16:16:10 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id B89421C29B; Thu, 9 Apr 2020 16:16:10 +0200 (CEST) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by dpdk.org (Postfix) with ESMTP id 7968D1C29A for ; Thu, 9 Apr 2020 16:16:08 +0200 (CEST) IronPort-SDR: lMPihAQg7LH2fyyFXLgaqf0c7oJz8m7y/gPFEJe6Ev9bUBxCc8yXuIzdHjYSkF4hZsP4BTuIE2 4O2v6XXyxg1w== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Apr 2020 07:16:07 -0700 IronPort-SDR: aGoMm17hAPMmDfySgi3SR6RhKTzL77Ttveyc8prJ5af6eWpbbOCQ1HfFKj4hXgGiGV4dIaFk9u kQNCtiLcCMcg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.72,363,1580803200"; d="scan'208";a="251906253" Received: from fmsmsx108.amr.corp.intel.com ([10.18.124.206]) by orsmga003.jf.intel.com with ESMTP; 09 Apr 2020 07:16:07 -0700 Received: from fmsmsx126.amr.corp.intel.com (10.18.125.43) by FMSMSX108.amr.corp.intel.com (10.18.124.206) with Microsoft SMTP Server (TLS) id 14.3.439.0; Thu, 9 Apr 2020 07:16:06 -0700 Received: from FMSEDG001.ED.cps.intel.com (10.1.192.133) by FMSMSX126.amr.corp.intel.com (10.18.125.43) with Microsoft SMTP Server (TLS) id 14.3.439.0; Thu, 9 Apr 2020 07:16:06 -0700 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (104.47.70.105) by edgegateway.intel.com (192.55.55.68) with Microsoft SMTP Server (TLS) id 14.3.439.0; Thu, 9 Apr 2020 07:16:06 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=S8DA0dfPBqxrnYFjb7UCnxLfgXPelYia9bUARzEOjOYBOt0rdK+KHqDdWpbCZyl2aixBaHboQf9HRvHYlKvm05y175K7oyFqoVOi06ymxuxIfqHNlb4hs9ekFaMjI3eg5k0lx5aOrBgAOB9XTDAmf7nGwHYXz1gd6qsZJvC8uFHxftKVuenAdduUfvJ59Hi7gTsP+pYxoCy53r6ajosaHFOAcg6DxxaofQrK3xPbmh8nMySGXG64sFxcGaMXau1ipoQ2jkiIFBWx9s+PkyBJqbzbUut65tnRmN5nEjQvuF/jK5m5yVf6DOwRpQ9UxAjG5+5seZQazOkdyuUoujk25A== 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=IeFtPuYMXMpF0WxhTkYMEQAjQmhg4iowoWvuQwyuzxY=; b=SSVPONOMgp70gASqxVBMBTL31Rp6ZnNZ698si214lrVzehGY0+3oDW3/ujxLHTN1o5tIKlDqEy4SCWbaKo1iEUhWJiC+xZRqo2D+9vxEXMZzKDbgSeMdIfdA+BdFwjIoVpAGrXSbbix0/lrwE6r3/th1vitJVcr0udmY6FslpJsn2VexT9ufS6pd8VsPj3I8QhcwjD9Czfc0ADKRwRZvVf1BpgtXeKr7ZyPEGbeqzAcEmsKy3WVu7LoIMvJe2/6vnmWCsZyPhym3vwjtih30R/AJW/qFxezq4E77kLROkeef9LbcdgMRFZ2T9/71fnAZX+Lc34UCOV+aCvHya+R9fQ== 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=IeFtPuYMXMpF0WxhTkYMEQAjQmhg4iowoWvuQwyuzxY=; b=vaWdsG1uUDibtnpmLfKxYd8xIitzStDlAva/Sr+JTq5Lk363run6kYmPcCCU5Q43sGkEu5DgA096qDqMU+hrYlXt62gDoi7EaMjvMaAYfuefpjvowDvVEiPcuJkwfZTiKHJCtvvlmxeV4v3PmPD5SA/ipFZuK1ENBHs0s9Hp7P8= Received: from BYAPR11MB2935.namprd11.prod.outlook.com (2603:10b6:a03:82::24) by BYAPR11MB2936.namprd11.prod.outlook.com (2603:10b6:a03:8c::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2878.21; Thu, 9 Apr 2020 14:16:03 +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; Thu, 9 Apr 2020 14:16:03 +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+EmFcxhqhw1RVQ Date: Thu, 9 Apr 2020 14:16:03 +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: <1586315145-6633-2-git-send-email-suanmingm@mellanox.com> 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.170] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: c548e94a-bacd-4a22-6b32-08d7dc9089a2 x-ms-traffictypediagnostic: BYAPR11MB2936: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:8273; x-forefront-prvs: 0368E78B5B 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)(136003)(39860400002)(366004)(346002)(396003)(376002)(5660300002)(52536014)(9686003)(71200400001)(8936002)(66476007)(86362001)(53546011)(2906002)(66446008)(66556008)(81156014)(8676002)(81166007)(6506007)(33656002)(478600001)(7696005)(316002)(54906003)(55016002)(4326008)(66946007)(186003)(26005)(64756008)(76116006)(6916009); DIR:OUT; SFP:1102; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: /C7L4hpOTbnIf1c7YFQXAdz//ceqJsuvKpdEL0UsZxCmhlrMAlLwB2wlwphNaf8wb5P7M/DzcfUw0+WMEDPFtLQoq+WIKREHsoZyfSgmx+JiBYObN74d3Fmcif8XYRQnsW9WVmSLDJfghr4gBgPeWQl6HYbgB90bvwJnZKQXgP15EjF+qZGB/wPpR7BLFR8fcJqM+Ze1qXDnPGOJiV0egxJctYv/pRmJosydb+lr+feWq/DkjYElNcdXoFBtmSIOzDsJJl2H8QLyvawoSWd8RkhuYCTdMVFk7NUh9okzYfWNifXxAkfruxThPrZ9AwHC4CQi59tUDhuVghH0m6gTVObw5HW2CqeGm283I5TmJZgnilvpdCybeRjriMrNL+ZcZVxUGc+rin/APf8FoXyjsw1w6z+b7aHeObiqIv1LrvfEpaP1duXSupZWAluG0Lok x-ms-exchange-antispam-messagedata: 6nD18H3hEzLhPGA3MjvgCNDDCj8s46cUeU+SO+fhb1WhlIEZ/OpIncmGgRXHQRyQlSoRt6TY4h6PfyTzw14Cc16GZn0OkZ74vPSNjgf1LS6orxetqX0w++p1kJKa5lKGMs4h7YRHigeL9gWLxaidbw== 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: c548e94a-bacd-4a22-6b32-08d7dc9089a2 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2020 14:16:03.6969 (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: B0mzd66O8AvjWdqbRJen+ue7Ubxx5VgB0O70ZHGBp3HGQIcNnSTZcVEx6CCvFhPyQnKQeAm67+355q+5vPMhlOvVqXv363QIQKCQ6kehLu0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR11MB2936 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" 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 >=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 time 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 > --- > lib/librte_eal/common/include/rte_bitmap.h | 113 > ++++++++++++++++++++++------- > 1 file changed, 85 insertions(+), 28 deletions(-) >=20 > 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; > } >=20 > +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; >=20 > - /* 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; > } >=20 Can we please leave the function rte_bitmap_init() unmodified and put all c= hanges in the new function rte_bitmap_init_with_all_set(). I realize this m= eans duplicating a few lines of code between the two init functions, but IM= O easier to maintain going forward. > @@ -483,6 +493,53 @@ struct rte_bitmap { > return 0; > } >=20 > +/** > + * 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 implement, a= s 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 that = 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 from = position (index1, offset1) to the end What do you think? Thanks, Cristian