From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8735CE81E02 for ; Fri, 6 Oct 2023 14:48:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=hnv11RvZ0CN4BxYGMrm2oc/I0jvLCEXVTl0L1rRBxWo=; b=FlqILXVtFW/Ag3 eI/dgd5OUtAMIZRoXGGx63G6MtjvpS5/fhXGQej4rPUAHtJgJVObpL+teR1Aokn/rI8ICyWfD1Xq6 iM3E5MpsPqFip/nbyFpyL0k6tM+/KQoDSWp8r1uxhxLy4zxREn0uhDLYzlqMpx7bZg0BNzT0wn4N2 stj/+fB7FzXi/rS75UUnz/1pl2MJ1vvNC/e6X4pooMe0ugIN1dP4I4SF7BlJesw1DePOizRnDVJSr dqUm27Zd1QjkKOisyFGbG9UZawjUWWbyN+T7zOvu1mzPwqwdJTD7Z0bQs2PfnOoAWTUGKgzVE5Hcc bpr+0Kb1BgMWZH7JZIXA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qom7a-0060sV-0Z; Fri, 06 Oct 2023 14:48:06 +0000 Received: from mgamail.intel.com ([134.134.136.65]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qom7U-0060rK-34 for linux-arm-kernel@lists.infradead.org; Fri, 06 Oct 2023 14:48:04 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1696603680; x=1728139680; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=Q6cQelynE4rTwAzTODBvQckDdOlp9FgcGKV65uBI6Pw=; b=VMwhPEGicHQ0pOLunnJYHBweeFNudYqAzlFjQufCu6z3b65Tm67IXEJg Fp83/1eB/Ao6Grf3OMrg0U+MSj168XVPsY/AS9IybVEfvVP85Efeup533 ineA0xfowr42WQoUFsnu3AsGJrfzGyOo8wB/pdtV/2a4AV1OYchvLnLqY sXF2qn7uW5q4yHIXDgZTDiu0DHobYlA8suTcNXYT07F3kyJLTy2oxWWZK 0QVQm21Tq0eva/4xJ1cuvbRzOHUyEsGTH3iboVFA5ZT58IvuYq/6V2Xfr IuuwIDb7/RxDJedjciIiFbnTv/97t4jI27Js3fhVZd51CUC8H46Inejya Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10855"; a="387642141" X-IronPort-AV: E=Sophos;i="6.03,204,1694761200"; d="scan'208";a="387642141" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Oct 2023 07:47:57 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10855"; a="752212944" X-IronPort-AV: E=Sophos;i="6.03,204,1694761200"; d="scan'208";a="752212944" Received: from smile.fi.intel.com ([10.237.72.54]) by orsmga002.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Oct 2023 07:47:53 -0700 Received: from andy by smile.fi.intel.com with local (Exim 4.97-RC1) (envelope-from ) id 1qom7K-00000003L89-0Ik7; Fri, 06 Oct 2023 17:47:50 +0300 Date: Fri, 6 Oct 2023 17:47:49 +0300 From: Andy Shevchenko To: Alexander Potapenko Cc: catalin.marinas@arm.com, will@kernel.org, pcc@google.com, andreyknvl@gmail.com, aleksander.lobakin@intel.com, linux@rasmusvillemoes.dk, yury.norov@gmail.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, eugenis@google.com, syednwaris@gmail.com, william.gray@linaro.org, Arnd Bergmann Subject: Re: [PATCH v6 1/5] lib/bitmap: add bitmap_{read,write}() Message-ID: References: <20231006134529.2816540-1-glider@google.com> <20231006134529.2816540-2-glider@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20231006134529.2816540-2-glider@google.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231006_074801_060048_C61115C9 X-CRM114-Status: GOOD ( 21.25 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Fri, Oct 06, 2023 at 03:45:25PM +0200, Alexander Potapenko wrote: > From: Syed Nayyar Waris > > The two new functions allow reading/writing values of length up to > BITS_PER_LONG bits at arbitrary position in the bitmap. > > The code was taken from "bitops: Introduce the for_each_set_clump macro" > by Syed Nayyar Waris with a number of changes and simplifications: > - instead of using roundup(), which adds an unnecessary dependency > on , we calculate space as BITS_PER_LONG-offset; > - indentation is reduced by not using else-clauses (suggested by > checkpatch for bitmap_get_value()); > - bitmap_get_value()/bitmap_set_value() are renamed to bitmap_read() > and bitmap_write(); > - some redundant computations are omitted. ... > v6: > - As suggested by Yury Norov, do not require bitmap_read(..., 0) to > return 0. Hmm... See below. ... > * bitmap_to_arr32(buf, src, nbits) Copy nbits from buf to u32[] dst > * bitmap_to_arr64(buf, src, nbits) Copy nbits from buf to u64[] dst With the grouping as below I would add a blank line here. But was the intention to group _arrXX() to these groups? > * bitmap_get_value8(map, start) Get 8bit value from map at start > + * bitmap_read(map, start, nbits) Read an nbits-sized value from > + * map at start > * bitmap_set_value8(map, value, start) Set 8bit value to map at start > + * bitmap_write(map, value, start, nbits) Write an nbits-sized value to > + * map at start ... > +static inline unsigned long bitmap_read(const unsigned long *map, > + unsigned long start, > + unsigned long nbits) > +{ > + size_t index = BIT_WORD(start); > + unsigned long offset = start % BITS_PER_LONG; > + unsigned long space = BITS_PER_LONG - offset; > + unsigned long value_low, value_high; > + if (unlikely(!nbits)) > + return 0; Hmm... I didn't get was the comment to add or to remove these checks? > + if (space >= nbits) > + return (map[index] >> offset) & GENMASK(nbits - 1, 0); And don't you want to replace this GENMASK() as well? > + 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); > +} -- With Best Regards, Andy Shevchenko _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel