Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp1426499rdb; Mon, 2 Oct 2023 09:09:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEiy3k4PYYF8ezw0K+rlpUmzNiwwEi7W6nKLhgpKz1lwnZ3RoeKTQKvl7ZQyVxGGteWb1Yo X-Received: by 2002:a05:6a20:549a:b0:14b:8023:33cb with SMTP id i26-20020a056a20549a00b0014b802333cbmr14829610pzk.11.1696262940251; Mon, 02 Oct 2023 09:09:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696262940; cv=none; d=google.com; s=arc-20160816; b=GkuDLlhh+3sLsZq5cSimH3+NlMQMA4WnHViOp2EhyOXpFJvE+YtcNM+Vq5g6OzKuJ+ yccl2sKEQgvxyx/PHr7c3CKCRA6DskB/0d63Ej3aKFWNR4djvBFk7yM5gLupCYnJBGkp P1LKrJd91v3apkqMMrSIFwtInoDImYk2/FQ7Aq089xAvLlGje4MEYVnYu3R9+OvyqjPd dVetQpLFXN1my7hfSqN2o/ywDC5SWKsk9qDd1yTiNHP2+bYs8LAG8dLR2YS4Q272IRy+ H7ycOg+a9D/Dq9NzpC27w3Voq2+TssZKGKPBn2a65/2VtSl+3RTLnw29MU7D6up/3CFg /kiA== 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=IdTNC+YEjDKpU4++SFmuR6hDpjFemoO+x6FsNeFujRE=; fh=UHpi0mWO8Pq5Bag+v19BTFUUAWWXhz7peZnBe+BgdPg=; b=yoOqbK18BuwmDk53J3dCAZumJBHti48x+8GoCxIkQp6UkYZYrSBkn+XKnSeTvsrxgX 7xi39LS8gmyrL2oj5M8TJBmv/OUxm9N/D/lihXEnnXf33qhIOlXydI8dC0s8ajcYbu2M lsgg0aNzURsbkLrp4WDVjXNlrbx7NP5GwpD0T+mYsS7jTchXKX65+duVdM/ZXgmyaaOW Osg/1BxAWvP+J8Wsru3THCzfahz5bp71SBKVTacv5wfT3O0sRCVl0M87obErI6v6jGif qqeYA9znyHMwmY+W4E64ikKwWcoGINTvCUeNno3elPaqz0iHSROQVEsxgTgSdySuyL49 /feQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=UM9SnUNW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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. [23.128.96.34]) by mx.google.com with ESMTPS id bu3-20020a056a00410300b0068fe12efae9si27137157pfb.15.2023.10.02.09.08.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 09:09:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=UM9SnUNW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 4757080ECFA2; Mon, 2 Oct 2023 01:23:30 -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 S235835AbjJBIX3 (ORCPT + 99 others); Mon, 2 Oct 2023 04:23:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229981AbjJBIX2 (ORCPT ); Mon, 2 Oct 2023 04:23:28 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E587AC; Mon, 2 Oct 2023 01:23:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1696235005; x=1727771005; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=SOlIFOn2hk256CLpF+8BPrLncA78Y2Z964ZdqXYyHSc=; b=UM9SnUNWn7HS4b5Er/pVFaxviH450KRgQccsotd9owe/4XBvh1msYPxq GywIUoOCFk6At/tXeJgAmIEQuvGmVsvvdSJpLWY5YB1ZNESZmRgwtlzuM oANXMy3MtiO5+RBlAsEbBINcMaQVHHk8noi9i0b/fDNSqQcGT4spA+YTo WFfhm+v61pBZg5lCXwru4iUWCrWczHAUHqXr/QlEhjTzFWNJIWvUGrKiZ e+8Y2/IEQmaXdKj3YSD3Fu7ms1rrPfGjqn6g9dKv67SOG/M30i4Ce7/5X PX0OmuwGJin8q9wBGdZ7A0fdNjqUxNm7ljqo4mnMRXhhPmj7dtVktwhRp A==; X-IronPort-AV: E=McAfee;i="6600,9927,10850"; a="4178066" X-IronPort-AV: E=Sophos;i="6.03,193,1694761200"; d="scan'208";a="4178066" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Oct 2023 01:23:25 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10850"; a="820822711" X-IronPort-AV: E=Sophos;i="6.03,193,1694761200"; d="scan'208";a="820822711" Received: from smile.fi.intel.com ([10.237.72.54]) by fmsmga004.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Oct 2023 01:23:21 -0700 Received: from andy by smile.fi.intel.com with local (Exim 4.97-RC0) (envelope-from ) id 1qnED0-000000026Fx-18m8; Mon, 02 Oct 2023 11:23:18 +0300 Date: Mon, 2 Oct 2023 11:23:17 +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=-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 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 (howler.vger.email [0.0.0.0]); Mon, 02 Oct 2023 01:23:30 -0700 (PDT) On Sun, Oct 01, 2023 at 09:06:24PM -0700, Yury Norov wrote: > On Wed, Sep 27, 2023 at 03:02:34PM +0300, Andy Shevchenko wrote: [...] > > > 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. > > What a wonderful week of strong statements... Whatever... > > > The two APIs are documented with the same example which makes it clear > > that they are data-loss transformations. Oh, should be read as data-lossleess. > > 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 should be confused even more. You're saying that I'm not wrong here, and few > lines above you're saying it's a data loss... data-lossless, sorry, I was missing that. > I don't mind this new 3-liners, but I'd like you to have a well better > wording and testing around them because those bitmap_scatter/gather are > all about performance, readability and usability. > > To begin with, the whole name of the series: "get rid of bitmap_remap() and > bitmap_biremap() uses" is wrong because the functions are still here, and are > still used. > > Even worse, instead of getting rid of some useless code, you're > bloating the kernel with something that duplicates existing > functionality. Wasn't Rasmus clear about the intention: 1) get rid of active users of bitmap_remap() outside of NUMA; 2) move that APIs to be private for NUMA users exclusively? Towards that direction is my series. > But I understand your motivation, and as I already said, I like this > series in general. So let's please figure out a better wording before > moving forward? > > Below are some my of thought. > > 1. Stop saying that you're getting rid of something when you're not. > I'd suggest something like: "add simple and verbose alternatives to > bitmap_remap(), and use them where appropriate". I'm getting rid of the users of the bitmap_remap() outside of NUMA. Why should I stop telling that? I think I have to elaborate what that means. > 2. Don't blame people considering a parameter named 'mask' as a mask. > I mean this sentence: > > > You should get the mask meaning. It's not the bit provider, it's a bit > > positions provider. > > If it's a 'bit position provider', please give it a proper name, > for example 'pos'. I'd suggest something like: > unsigned long bitmap_scatter(unsigned long *dst, unsigned long *pos, It's not pos in the sense of what pos means. pos means a position of a single bit, mask is about many bits. And mask meaning is still the same despite how we call it, it's bit positions provider, i.e. bits that are set in the mask will be considered to be worked on. It's mask, why should I rename it? > 3. If you're saying that new API is a simplified replacement for > something, I'd like to see the full contract, i.e. explicit list of all > simplifications and limitations implied: > - val == dst is not handled; > - when 'pos' is empty, val is not copied to dst; > - new API doesn't wrap around 0, like bitmap_remap() does; > - set bits in 'val' are not copied to 'dst' when not in 'pos' (?)' > - anything else else? I see, I should have not used word "simplification" at all. I will reword to not mention bitmap_remap() _at all_. > 4. Similarly to previous item, I'd like to have explicit understanding > and examples where and how bitmap_remap may be replaced. You're > only saying that it is possible when either 'new' or 'old' are > dense. Is that the only case? Can you add a test that explicitly > checks that bitmap_remap and bitmap_scatter/gather produce the same > output. Something like this: > bitmap_remap(dst1, val, dense_map, pos, nbits); > bitmap_scatter(dst2, val, pos, nbits); > check_eq_bitmap(dst1, dst2, nbits); No, I won't do that. This is out of the scope as see comment on 3. above. > 5. Can you add a picture like this to explain the algorithm even more: > > mask: ...v..vv..v...vv > bits: 0000001100000010 > 1. ^ ^^ ^ 0 > 2. | || | 10 > 3. | || +> 010 > 4. | |+--> 1010 > 5. | +--> 11010 > 6. +----> 011010 > gather: ..........011010 Why? Is it so complicated? > 5. Regarding my confusion, I had to draw the picture above to realise > how it's possible that scatter/gather are inverse and data-loss > (i.e. not inverse) at the same time. Can you explain it with a > wording like this: "For bits selected by 'pos' bitmap, gathering a > 'val' bitmap with the following scattering restores the original map. > All other bits values are lost and replaced with zeros." Similarly > for gathering. And please add a test case. Let's not make a big deal out of a small typo. I admit that it confused people, but that was neither in the documentation, nor in the code, just in our discussion. > 6. Regarding performance. I think it's wrong to say that that your > code is better optimized then some other, and then ask your > reviewers to figure out how to measure the difference. If you make > such statement, you should already have some test or real-life > measurement. Same as for 4. above. I drop the comparison and mentioning of bitmap_remap(). It was a big mistake by me to even mentioned that. > However, if you ask me, I can suggest you to pull this patch: > https://lore.kernel.org/lkml/20230828184353.5145-4-yury.norov@gmail.com/ > > and modify/extend it in a way that both bitmap_remap and > bitmap_scatter/gather take the same 'val' and 'pos' bitmaps, > produce the same output, and then see which code is faster. > > Worth to mention that since all current users of your API are working > on 64-bit maps, performance is doubty an issue. So you can drop the > 'optimization' part of your wording, and don't add performance test. -- With Best Regards, Andy Shevchenko