Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp2268246ybt; Tue, 16 Jun 2020 01:16:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz2FhE3ws7LNGz5P/LSvnFYlj6wSOOMgfkYeZShShpOfKs9W75yu/Hmp8bKvXMWJsRBLka6 X-Received: by 2002:aa7:dc57:: with SMTP id g23mr1438321edu.352.1592295412690; Tue, 16 Jun 2020 01:16:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592295412; cv=none; d=google.com; s=arc-20160816; b=UUL7+C6LqdMWWYd4xT8z5PZtNsFwSPCPMjJIT8WPu9UHeuNelUMsuoGT7LcJ21R8+T a8uMu/kYm0zGixaTNV5BQ5tZdT6TIISacNaxl8DomCmWt3yoV4lt3w/zBoU1GHoLQmWP h3YmMjbaqR2VbHYvkpLKipCh7HQUS/76yzThv6tLk5eCuirbqirAmb0DlLu6H03c9VJt PmYSjhKuMGJkg9VJGOPS9JazuhS/OEttN/cAv5fpe3BMvajHeQPgd73aN12EfGZhykF2 85MfTEHFGcdszlDD3zL62SKbC8a3W4AvN0/EZUPR9ki/pHwlSXQhjAN0hGs9dUiLeQJk F2Fg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:organization:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:ironport-sdr:ironport-sdr; bh=JrgRt+P7AJNE+sq16EtJtGVWxmsHo4M5QJgzin94VCs=; b=VmJbrJYM2rULM4W+N4OLJ5TWtcReqQa4GmCPSaiXbLtNKxlKtAt9ioU/9jYaVN+mdy jYhmkHmst0vIOmDY2kF2CAuUZ0nNLiYsy4P46OTbpl8ejRUZ+6IlXz6bd3Pf7hJ+AEmJ WcG9WPgNXIQfGi3NWId3U5YtOksMTRY8z/+27ts1CalbJK4KfpJN291eTphQRk0KIAhW iYHHqKikrMwacxl/pvdk6mC0Bpi7JrsNZD1XB3kM3EzhUZARIfffj4ya4AA1vPBrARY7 YZSrBZfcIIn3PTHJ6CpcIgWo2ULev+iJHEQTbhhLcCGUCjnb9O1Znu1QcATSNLw2CEnT V+qQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f9si7258949ejl.52.2020.06.16.01.16.30; Tue, 16 Jun 2020 01:16:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727027AbgFPIOa (ORCPT + 99 others); Tue, 16 Jun 2020 04:14:30 -0400 Received: from mga07.intel.com ([134.134.136.100]:63987 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726112AbgFPIO2 (ORCPT ); Tue, 16 Jun 2020 04:14:28 -0400 IronPort-SDR: VjF7EhjUJZC/gDac0uLwgddFY/LmBl0lzFa09CLc/oRPKpdFHWRS5Y4DwV+WMIuZUcH3ImsM9s +TPs++Ds6bNg== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jun 2020 01:14:27 -0700 IronPort-SDR: iVknjRVF13XZH0gD8Jhr/izjiPVFRea5kevTpSrhIL3CDBHqaAWBOMfZ+S1kS7FViiDdc3O5rX kYCDPvJO4xOQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,518,1583222400"; d="scan'208";a="476351950" Received: from smile.fi.intel.com (HELO smile) ([10.237.68.40]) by fmsmga005.fm.intel.com with ESMTP; 16 Jun 2020 01:14:25 -0700 Received: from andy by smile with local (Exim 4.94) (envelope-from ) id 1jl6jk-00Dmpc-EB; Tue, 16 Jun 2020 11:14:28 +0300 Date: Tue, 16 Jun 2020 11:14:28 +0300 From: Andy Shevchenko To: Syed Nayyar Waris Cc: linus.walleij@linaro.org, akpm@linux-foundation.org, vilhelm.gray@gmail.com, arnd@arndb.de, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v8 1/4] bitops: Introduce the for_each_set_clump macro Message-ID: <20200616081428.GP2428291@smile.fi.intel.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jun 15, 2020 at 06:21:18PM +0530, Syed Nayyar Waris wrote: > This macro iterates for each group of bits (clump) with set bits, > within a bitmap memory region. For each iteration, "start" is set to > the bit offset of the found clump, while the respective clump value is > stored to the location pointed by "clump". Additionally, the > bitmap_get_value and bitmap_set_value functions are introduced to > respectively get and set a value of n-bits in a bitmap memory region. > The n-bits can have any size less than or equal to BITS_PER_LONG. > Moreover, during setting value of n-bit in bitmap, if a situation arise > that the width of next n-bit is exceeding the word boundary, then it > will divide itself such that some portion of it is stored in that word, > while the remaining portion is stored in the next higher word. Similar > situation occurs while retrieving value of n-bits from bitmap. On the second view... > +static inline unsigned long bitmap_get_value(const unsigned long *map, > + unsigned long start, > + unsigned long nbits) > +{ > + const size_t index = BIT_WORD(start); > + const unsigned long offset = start % BITS_PER_LONG; > + const unsigned long ceiling = roundup(start + 1, BITS_PER_LONG); This perhaps should use round_up() > + const unsigned long space = ceiling - start; And I think I see a scenario to complain. If start == 0, then ceiling will be 64. space == 64. Not good. > + unsigned long value_low, value_high; > + > + if (space >= nbits) > + return (map[index] >> offset) & GENMASK(nbits - 1, 0); > + else { > + value_low = map[index] & BITMAP_FIRST_WORD_MASK(start); > + value_high = map[index + 1] & BITMAP_LAST_WORD_MASK(start + nbits); > + return (value_low >> offset) | (value_high << space); > + } > +} ... > +/** > + * bitmap_set_value - set n-bit value within a memory region > + * @map: address to the bitmap memory region > + * @value: value of nbits > + * @start: bit offset of the n-bit value > + * @nbits: size of value in bits > + */ > +static inline void bitmap_set_value(unsigned long *map, > + unsigned long value, > + unsigned long start, unsigned long nbits) > +{ > + const size_t index = BIT_WORD(start); > + const unsigned long offset = start % BITS_PER_LONG; > + const unsigned long ceiling = roundup(start + 1, BITS_PER_LONG); > + const unsigned long space = ceiling - start; Ditto for both lines. > + value &= GENMASK(nbits - 1, 0); > + > + if (space >= nbits) { > + map[index] &= ~(GENMASK(nbits + offset - 1, offset)); > + map[index] |= value << offset; > + } else { > + map[index] &= ~BITMAP_FIRST_WORD_MASK(start); > + map[index] |= value << offset; > + map[index + 1] &= ~BITMAP_LAST_WORD_MASK(start + nbits); > + map[index + 1] |= (value >> space); > + } > +} -- With Best Regards, Andy Shevchenko