Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp433388rdb; Fri, 6 Oct 2023 07:48:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG3WM8iY34e7oPp797kr5SIHBCjshr0+WY6Ad69DEaeoOKcPT14RZj6qT77OK85YBPrJqXG X-Received: by 2002:a05:6a20:7f9a:b0:163:a041:336c with SMTP id d26-20020a056a207f9a00b00163a041336cmr9739544pzj.48.1696603692357; Fri, 06 Oct 2023 07:48:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696603692; cv=none; d=google.com; s=arc-20160816; b=I6k0LyaA6mNhpO8feiXI+exYN+558GMqezJSc0uymzzhdrr9Y/3OCl7X8ud8uDFoU6 ggdlTU2weGI8+WzOEzhN0iy0IswfsGjgXP0oAQZ0xZpi6qN0B8lCmf+yyoB8RTh8Ri3o 44BeNDAuQIGicK4Wuz+nLftWxvBhZ4LFtWWp0l4Dl6X4eD5K12giRwwSewDa+Zd4NY7R dwDOgBL3JqVMXuNgJy9htjZj4iN7Sy3Oa++FKFYZT0zkQ21OUNhuQGf0OjeffYbyF36v 9Bs9Z7a1b4KH8vHGaKvmuM02NR+G++sHo+p5/fadY45bbrtRN7TA1n1aAtgdH6IEFsnI A5WQ== 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=zj9V7MmoPg+F2S5lSLhEnce3iUjrvU2WaOaopiZUZus=; fh=tXLkCaj7t+ckNvujl+Rdj9T8X1qsMb1gVU2CPoGueeg=; b=FYCX0lKs2Suk/Vco9eGQUzHo9WHcd8oupvsMinUhxmvXOLcLKh8U+uCIJlEfNtMUsR 1D/vkNo10olB3jekXEtULw/Dqy7zzLf2fKZJkRwsVhzdiS2YSKxF47WzBX0kuNI3nIBl 9XRx8/Q/bI1C/8xa1Gobpk6S1jj5r86uo3xxYh5EkJtyagjX94s6PllcBVweUjbqXjRV 1ZxbL48Wa5sYh6N/vTOP55HCUjDOnYJ0FL1oWhsteDrhhyIRT5wwg4kvTViUr4omgNU0 lTvZBqTUVi0+wVyTpn0axQCUZH4Aa/um02RcH0JX+3df0fKROHLEO3SgMWDg0xez1BND XafA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ajoWItSF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id fc6-20020a056a002e0600b0068fcca7b3f7si1611196pfb.2.2023.10.06.07.48.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 07:48:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ajoWItSF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (Postfix) with ESMTP id A87DC8022A9A; Fri, 6 Oct 2023 07:48:09 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232583AbjJFOsA (ORCPT + 99 others); Fri, 6 Oct 2023 10:48:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232506AbjJFOr7 (ORCPT ); Fri, 6 Oct 2023 10:47:59 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7E51A6 for ; Fri, 6 Oct 2023 07:47:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1696603677; x=1728139677; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=Q6cQelynE4rTwAzTODBvQckDdOlp9FgcGKV65uBI6Pw=; b=ajoWItSFg/Gxuww7DJ6z5RiA57pPLUg01HMZHE1a8DmCxQg8+I39NGJE xE9fp5oQlnSwjIyCtG0wH/wzNUArleOg+MXFvg/MbJBTWwLlne2d3xeur O+a6IayskSFQGIpnnOM3TscBvhlQWJUJVP8LTyTydGVXD1klw3FnZS9Iq MldsuNOl6gh8r+wvlC36wxKfn+S9DnY2I7QU66Mudr9ycsMHI5MeAgJ7l zxlQEl7oHo0dthgzEsUElmIDwcRvbvGj4YU3j9oBaaEA8okmtJg51KD7F 8iMpBWTobLMq9OSSiG8YvlWUqCVc/U5t3Rn/tr256QYVgYCGjC9don5VU w==; X-IronPort-AV: E=McAfee;i="6600,9927,10855"; a="387642136" X-IronPort-AV: E=Sophos;i="6.03,204,1694761200"; d="scan'208";a="387642136" 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-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231006134529.2816540-2-glider@google.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo X-Spam-Status: No, score=2.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email 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 (howler.vger.email [0.0.0.0]); Fri, 06 Oct 2023 07:48:09 -0700 (PDT) X-Spam-Level: ** 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