Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp388025rdh; Thu, 26 Oct 2023 05:16:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG30LLuCzSP0Mjv1Kcy4M1R87MTNgHAFwfiNjx6UPwnB7X6OAXJZ3Y9lHrN3G1oEEyBizzd X-Received: by 2002:a81:a10f:0:b0:5a7:b4ab:9d7d with SMTP id y15-20020a81a10f000000b005a7b4ab9d7dmr19145142ywg.20.1698322581892; Thu, 26 Oct 2023 05:16:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698322581; cv=none; d=google.com; s=arc-20160816; b=h3BROYYtVhwChbVqET30/prcQDzEEZH+6dgxdZYwqSDuoTykWVuyIWiU9FrcLet63e STFzVxLsvn4hcyrRcsuFvzqV8adQDdXTyZz5k3wK4iOzvIGaMCCTIPx/1jKbePXisNMF K8GfRRzX9T/sQ8/yzFRQqocOrR81+MkxYSYxNH2pcsx81n9tDWtvFbs/6yACp9isPNll 4lK6+NrJPHazny9fCwmGeEoubSH+qVy/LUMei5jl+0PyZGQWIYc9yQQvvYf3SZ+BDkzH zUFP5S3mjIUYfM+KGbALaMqxBvOgvnVsHeXsAoO3xrD6cUokeedeYt5O5gyU6qRqL5Sw 5aOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:organization:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=OJWVlmp/HSXARPN81UTFJMdpGFomB6JWTP4ijnHOELo=; fh=QEGGfnzgLB1PJNzeZDNHIJJxryNQqqD8yjdtP5TLpzQ=; b=KyP8Vu9xURuAXafBf/PfU9izkMLnWxeuzi7QoTrhVZIKVnCV4SFLlzhYWQdPzFv5Bs NzEimp9Owf7UBNscgaVI54b/QJksyUCCedgKwvPw/JkahWIkn2+6eK/tmnmwBitA9lsa kZNVWUm/qd2Rl86ugdttRfOQnZleAMnkT0wHpr9TU/4VuFgBH3sxOX3VqGV+DvQr71eR ciICYZ8MPQ8bc0kq1TwR7Qp2PDt7eklaBGgIi3Ph4B+eyvlhksBKQpgfQPpu8xsg4Py4 XsBL8uyiX4JlUZ5XhyB+wRzBtAhHtq0Uc8VijJq1pd0fU2zQxtHjuoufAC1SbLBzB+o9 Ba8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=WK09NWvu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id b63-20020a0df242000000b0058418123e3csi15418610ywf.373.2023.10.26.05.16.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Oct 2023 05:16:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=WK09NWvu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 9EEA08045967; Thu, 26 Oct 2023 05:16:02 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344865AbjJZMPw (ORCPT + 99 others); Thu, 26 Oct 2023 08:15:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54638 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230413AbjJZMPu (ORCPT ); Thu, 26 Oct 2023 08:15:50 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7F96B9 for ; Thu, 26 Oct 2023 05:15:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698322548; x=1729858548; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=PVAv9bGwxt5kvEjJKPI54bMwvQAwbEv1pym1jtK6Uxg=; b=WK09NWvutb9wmQwR9t18v7+xDi2CbO94k7FR92U8HPhAcRkK/cpwhR52 fqZinbG65vnn8BOjDXaxcg8lZxaxsjGqys1Ytxg+HJwEt/wfBdfLEVqJF 1SmMr9TkFnxUTPSc1z9rDBsWaaoGycjWVjdjiwi3EIAxbkk5vzhjHYXYT 3EEU+qsHtRTArfBxb2qR7Ht/NFJsYGhUrzyrA3kU8V5nRyWDI01bwQrHP ao8zrddBElZyY83pUE/E0jXan/OpageXFXD3AcQgmEo2pxvbmkRbxEHNu Op/mLwXMUx69fHzgIE6aov4yXWChgcBukbpxqXJ86E9ugjJf2V+UGzr14 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10874"; a="391395439" X-IronPort-AV: E=Sophos;i="6.03,253,1694761200"; d="scan'208";a="391395439" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Oct 2023 05:15:47 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10874"; a="759164502" X-IronPort-AV: E=Sophos;i="6.03,253,1694761200"; d="scan'208";a="759164502" Received: from smile.fi.intel.com ([10.237.72.54]) by orsmga002.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Oct 2023 05:15:43 -0700 Received: from andy by smile.fi.intel.com with local (Exim 4.97-RC3) (envelope-from ) id 1qvzH2-00000008qkb-2TBo; Thu, 26 Oct 2023 15:15:40 +0300 Date: Thu, 26 Oct 2023 15:15:40 +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, alexandru.elisei@arm.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 v9 1/2] lib/bitmap: add bitmap_{read,write}() Message-ID: References: <20231025083812.456916-1-glider@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231025083812.456916-1-glider@google.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 26 Oct 2023 05:16:02 -0700 (PDT) On Wed, Oct 25, 2023 at 10:38:11AM +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. ... > * bitmap_to_arr64(buf, src, nbits) Copy nbits from buf to u64[] dst > * bitmap_get_value8(map, start) Get 8bit value from map at start > * bitmap_set_value8(map, value, start) Set 8bit value to map at start > + * bitmap_read(map, start, nbits) Read an nbits-sized value from > + * map at start > + * bitmap_write(map, value, start, nbits) Write an nbits-sized value to > + * map at start I still didn't get the grouping you implied with this... > * Note, bitmap_zero() and bitmap_fill() operate over the region of > * unsigned longs, that is, bits behind bitmap till the unsigned long ... > +/** > + * bitmap_read - read a value of n-bits from the memory region > + * @map: address to the bitmap memory region > + * @start: bit offset of the n-bit value > + * @nbits: size of value in bits, nonzero, up to BITS_PER_LONG > + * > + * Returns: value of nbits located at the @start bit offset within the @map > + * memory region. > + * > + * Note: callers on 32-bit systems must be careful to not attempt reading more > + * than sizeof(unsigned long). sizeof() here is misleading, We talk about bits, BITS_PER_LONG (which is 32), here it's better to be explicit that reading more than 32 bits at a time on 32-bit platform will return 0. Actually what you need is to describe... > + */ > +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 || nbits > BITS_PER_LONG)) > + return 0; ...this return in the Return section. > + > + if (space >= nbits) > + return (map[index] >> offset) & BITMAP_LAST_WORD_MASK(nbits); > + > + 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_write - write n-bit value within a memory region > + * @map: address to the bitmap memory region > + * @value: value to write, clamped to nbits > + * @start: bit offset of the n-bit value > + * @nbits: size of value in bits, nonzero, up to BITS_PER_LONG. > + * > + * bitmap_write() behaves as-if implemented as @nbits calls of __assign_bit(), > + * i.e. bits beyond @nbits are ignored: > + * > + * for (bit = 0; bit < nbits; bit++) > + * __assign_bit(start + bit, bitmap, val & BIT(bit)); > + * Note: callers on 32-bit systems must be careful to not attempt writing more > + * than sizeof(unsigned long). Ditto. > + */ -- With Best Regards, Andy Shevchenko