Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp2762587rdh; Wed, 27 Sep 2023 11:55:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGEXM35X6ekzBXZpiBGR59srIrL8O3DL3exoNBs++lAVLovjneULlXzWR4lEniciJiKfk99 X-Received: by 2002:a17:90a:6903:b0:26c:f6d2:2694 with SMTP id r3-20020a17090a690300b0026cf6d22694mr2538566pjj.12.1695840900158; Wed, 27 Sep 2023 11:55:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695840900; cv=none; d=google.com; s=arc-20160816; b=FNyNWPp3I236GaznPfFv7qa64sq+grfKAVhTtXVxqd0amaGAIZhx+N6AXUMmu8LBl0 dEQWSEAMDyV+gM7Mw9j6B+BWlr5cfymWVuft2AREcxL6HnADeWJzcaLkP0hM/9G5031J CYZTXH6x8etQ8di9JRnWL9CoKJM/4PKBHLKo2CuCiMNsy1+gunniRW9Mb8p2drHqQ5O0 t2/g4322D6G4dN5ttKvpVH0EihvTZPxuCINdRcteXrjOAMCrQdLIQC0ll2hASa//DlvQ yGEKnDdjOW/+ZwiqxWbVOPsPjUy0BfAj2YUHPBj6Hs6Poy41OQaPBs4LmZSHVAWY47Xa UCOA== 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=6VX1VbN/R1Df99Rte7ugMYValGuErmybLlYIivM/MXw=; fh=UHpi0mWO8Pq5Bag+v19BTFUUAWWXhz7peZnBe+BgdPg=; b=xSfj8q69sJCq+w9fUOjlfCtFYQp4zrYxMkiwEHiYbvmBxePwOKRuC0oV/QEOtpTy+L n5afeRhqvyh/Er02YdJDxLW6iK+VGQ8bt5py+cDPLWQuen0TrOXdeMkkb+XD3MiKu2Km ar1vLWR3jrvd8bxZVBcFLL9Ds5MG7vVLDyObSVwXDnIZTuwk3+TL8intunHi9PoheNUB TypR4INYP+tuzU3EPVYXfNHDNi6/Mzzrqf0dXsUR9tK0HooMxR77hBekaHJDlQb7802+ nEeyVkGeTfkVvJriiWVV7+b/oRcz2nRmW7HSAkrNmWbzd3q7pUTNO9Sv2HuyoIpqAE0Z cLhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=IJJsyIY+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id lj10-20020a17090b344a00b002776794a75csi7254297pjb.171.2023.09.27.11.54.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 11:55:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=IJJsyIY+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (Postfix) with ESMTP id 4FEE6807385E; Wed, 27 Sep 2023 05:10:41 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231545AbjI0MKa (ORCPT + 99 others); Wed, 27 Sep 2023 08:10:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231169AbjI0MK2 (ORCPT ); Wed, 27 Sep 2023 08:10:28 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD45CBE; Wed, 27 Sep 2023 05:10:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695816627; x=1727352627; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=qpBb1Dvmlu54LR+5l2f0lLgg+l2XFidwR6LH6371XtU=; b=IJJsyIY+Ej30BCLnOzlb0CS/zL68eYAYkA/SJKkokQlWaEzfBkHZYvju dox7SYwg6jg9mJbUg7Gl9KjqRkm3jRct0d31vdI+11X8M5bSMmxrviDMs qm0tVFjVWop9FN+QYbJUEgwpMbDv4XxqhGk7fyeT98EzF9LjffKgaW+jJ KomjhBx1tLSpupGwNMm34b0e65lK+iaWDNJfeCbqzZApc9an/LgtEzKbr 2S+TkbtiJRWJeR3EgFIrunWTGLW+A1YXHWgzbZ9K5gbrN2Nr78CT8sTFM MZPI4yuetKFFFAxfAzdj0B2MmPv3AEX55IsaHyjSZe6Dk9YEXkq6AgxWm g==; X-IronPort-AV: E=McAfee;i="6600,9927,10845"; a="372150467" X-IronPort-AV: E=Sophos;i="6.03,181,1694761200"; d="scan'208";a="372150467" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Sep 2023 05:10:27 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10845"; a="892580517" X-IronPort-AV: E=Sophos;i="6.03,181,1694761200"; d="scan'208";a="892580517" Received: from smile.fi.intel.com ([10.237.72.54]) by fmsmga001.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Sep 2023 05:09:16 -0700 Received: from andy by smile.fi.intel.com with local (Exim 4.97-RC0) (envelope-from ) id 1qlTFT-00000000sRB-0Bl3; Wed, 27 Sep 2023 15:02:35 +0300 Date: Wed, 27 Sep 2023 15:02:34 +0300 From: Andy Shevchenko To: Yury Norov Cc: Linus Walleij , Bartosz Golaszewski , linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Shubhrajyoti Datta , Srinivas Neeli , Michal Simek , Bartosz Golaszewski , Rasmus Villemoes , Marek =?iso-8859-1?Q?Beh=FAn?= Subject: Re: [PATCH v1 2/5] lib/bitmap: Introduce bitmap_scatter() and bitmap_gather() helpers Message-ID: References: <20230926052007.3917389-1-andriy.shevchenko@linux.intel.com> <20230926052007.3917389-3-andriy.shevchenko@linux.intel.com> 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 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.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 (lipwig.vger.email [0.0.0.0]); Wed, 27 Sep 2023 05:10:41 -0700 (PDT) On Tue, Sep 26, 2023 at 05:25:13PM -0700, Yury Norov wrote: > On Tue, Sep 26, 2023 at 08:20:04AM +0300, Andy Shevchenko wrote: > > These helpers are the optimized versions of the bitmap_remap() > > where one of the bitmaps (source or destination) is of sequential bits. > > If so, can you add a test that makes sure that new API is consistent > with the old bitmap_remap? And also provide numbers how well are they > optimized, comparing to bitmap_remap. It's impossible. bitmap_remap() is universal, these APIs only for the specific domain. > > See more in the kernel documentation of the helpers. > > I grepped the whole kernel, not only Documentation directory, and found > nothing... It's added in this patch in the format of kernel doc. ... > > + * Returns: the weight of the @mask. > > Returning a weight of the mask is somewhat non-trivial... To me it > would be logical to return a weight of destination, for example... > But I see that in the following patch you're using the returned value. > Maybe add a few words to advocate that? I'll look into it again, maybe dst would work as well, I don't remember why I have chosen mask. Maybe because it's invariant here, dunno. ... > > + int n = 0; > > Is n signed for purpose? I think it should be consistent with > return value. OK. No purpose there. Perhaps it's a leftover from the first experiments on the implementation of these APIs. ... > > + * Example: > > + * If @src bitmap = 0x0302, with @mask = 0x1313, @dst will be 0x001a. > > Not sure about others, but to me hex representation is quite useless, > moreover it's followed by binary one. Somebody is better at hex, somebody at binary one, I would leave both. > > + * Or in binary form > > + * @src @mask @dst > > + * 0000001100000010 0001001100010011 0000000000011010 > > + * > > + * (Bits 0, 1, 4, 8, 9, 12 are copied to the bits 0, 1, 2, 3, 4, 5) > > + * > > + * Returns: the weight of the @mask. > > + */ > > It looks like those are designed complement to each other. Is that > true? If so, can you make your example showing that > scatter -> gather -> scatter > would restore the original bitmap? It looks like you stopped reading documentation somewhere on the middle. The two APIs are documented with the same example which makes it clear that they are data-loss transformations. Do you need something like this to be added (in both documentations): The bitmap_scatter(), when executed over the @dst bitmap, will restore the @src one if the @mask is kept the same, see the example in the function description. ? > If I'm wrong, can you please underline that they are not complement, > and why? No, you are not. ... > I feel like they should reside in header, because they are quite a small > functions indeed, and they would benefit from compile-time optimizations > without bloating the kernel. > > Moreover, you are using them in patch #3 on 64-bit bitmaps, which > would benefit from small_const_nbits() optimization. I can move them into header. ... > > + DECLARE_BITMAP(bmap, 1024); > Can you make it 1000? That way we'll test non-aligned case. Sure. But it's not related to the patch. It will test bitmap_weight() and not the new APIs, so, whatever is bigger 64 will suffice the purpose and won't anyhow affect the newly added APIs. ... > Would be interesting to compare bitmap scatter/gather performance > against bitmap_remap. Do you have a code in mind? I can incorporate it. Again, you should understand that it's only applicable to the certain cases, otherwise it makes no sense (it's like comparing performance of ffs() on a single word against find_first_bit() on the arbitrary amount of words). -- With Best Regards, Andy Shevchenko