Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp5740106imb; Fri, 8 Mar 2019 00:57:29 -0800 (PST) X-Google-Smtp-Source: APXvYqwvZEjYTe5dRr4KxFS+XeMO+IQXBfnibrqKB1rXeiOnwMEXwMjlSPRhqjlusRj/H9H999nH X-Received: by 2002:a62:1c45:: with SMTP id c66mr17506651pfc.90.1552035449469; Fri, 08 Mar 2019 00:57:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1552035449; cv=none; d=google.com; s=arc-20160816; b=jSIwFn5FnU/Jr50dzExm8NuxMt88iyFEJHJk+CdRMLJibErbxdhL9SDHMdV47Lh24F gADdpmWwFOCr0PdAaauVe6Ha1RhFdZyH9n67BEhhQtM3rhrcLUToKk0m0+tyEq0fxX5o +tGYj6ymJWwn2qr3WbZ51FE1Yi6w2ZXHG7tDL9KSeNSm0i1H2nbY4jFTgEU0Rw2ringU eHOE9d528eGEEVanYf7Vm4XozPPiJXaGyZ/VPj5btG0jw1fkIJsS5dJuKPOhcId6CR5J h3dD9uzGFiRHn5zJRU+mTPoyoauG/72seNlJ7Bsu9B+oBWZ/dwOLxYIfDDD0Y/EsFbPc xyrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=EvaF26RI7c5HyTPz/s7fr3l3YkC9rN6qerGwkguRTR8=; b=LRWso6yb6jTLJOCCGYGU81FQY0j7vPO+S3a5iQeqrj+7pKeFz9d/bItqNEV3cu3kNd V2pWoqklznZhr5SjykeWp4B0i0FfXZhL1qVDuFnhe7uWO6+J+5ptpyOj9+UJ5HX0h3+C g1J1bezU3+lEp5PlAZyaWq+Wfn/2eYqUxPijMMSbzh0/4DzxuSe1vLvE1ckNZhriYjXv QJMlFEJznCPlmnHhFjvtjdvUf0ndwnOiEhKwtJcs4vSQudiw+RukoxlySShwCiGrdQOm oSzuaMfSKHM52D2IqckoLzbX7VCWG7HkP0EhowZUB43zODxkShgnLCiGKBhVbu/CIO1+ Q/kw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=gHL3NkzM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r133si6155833pgr.175.2019.03.08.00.57.13; Fri, 08 Mar 2019 00:57:29 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=gHL3NkzM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726308AbfCHI4z (ORCPT + 99 others); Fri, 8 Mar 2019 03:56:55 -0500 Received: from mail-pg1-f195.google.com ([209.85.215.195]:42237 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725308AbfCHI4z (ORCPT ); Fri, 8 Mar 2019 03:56:55 -0500 Received: by mail-pg1-f195.google.com with SMTP id b2so13615092pgl.9; Fri, 08 Mar 2019 00:56:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=EvaF26RI7c5HyTPz/s7fr3l3YkC9rN6qerGwkguRTR8=; b=gHL3NkzMk1rMibDf4b7nqUDivvpIM8faxWPoOea5c8ln2b9GzJbwW8+kqpdb3KQOVS S0ttHMbEGe3tlrF4cP3chkm3KHKGufEgDPpEDDqHkV2xTEEyDaB+35pywPK++4lc4cYt G3NjQ1JZXfQvS87kPipvCvbmUTwntS3owjOPIst5LqYyq/pMd+ZUmDsWsJleAuHpWJ/J +cap0A5siHiHMcJSbS1YotI/T0OAlaJiVKwHy10y4gYbs6i3ak87ruIjJa8vhKeQaYW8 Cb/iwj+81A1k4vA0pBEvuiMqyw/bZUTj0FZWGxIxCo42BP8SJgM9px39W3D6XBHqzx3p aGRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=EvaF26RI7c5HyTPz/s7fr3l3YkC9rN6qerGwkguRTR8=; b=hySY9qt5XYJbLHv5sfNLC3SPJMmjZRasbMg+kFq0xMdBCKeEWLJHSpO+KIcRTBjBtD nLpAYNzrqjtCz+aqwXCz8SUGAyP1IQreOzS2dCEQf+QD+jVJNI+OzZTD6kWQTT+en0Rl Ui0lc155Kz0HHSJek8cskzMxtPvI50lgkwM4/5yVaLy2XiJiyTiD/M5M86W0AtZ5Op6k 8EQ9OLHIp3lfl4Db+2Sa7xvrHyy5i+o/H/VjfwC2u3vc5DYmPjlrVa8PI0U4q7Yair3p ZcHP3ZvsyBPZPSWPyQu5JlRuGWdjv6XS7hIkgMrd8XifrCkj6qHYBMkssmhzBQX6u+Lq /BwA== X-Gm-Message-State: APjAAAUYvYGZ/XFVcQWUeAoJziINW7QKaJN8os7Rjnzf21VxO1VFh/n4 v98ck2eO+7EXMticvSDTgJyu7fng8TI= X-Received: by 2002:aa7:8497:: with SMTP id u23mr17544958pfn.253.1552035414114; Fri, 08 Mar 2019 00:56:54 -0800 (PST) Received: from icarus ([2001:268:c0a4:4f3d:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id n10sm9524340pfa.139.2019.03.08.00.56.49 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 08 Mar 2019 00:56:53 -0800 (PST) Date: Fri, 8 Mar 2019 17:57:33 +0900 From: William Breathitt Gray To: Linus Walleij Cc: Andrew Morton , "open list:GPIO SUBSYSTEM" , linux-arch@vger.kernel.org, "linux-kernel@vger.kernel.org" , Andy Shevchenko , Rasmus Villemoes , Masahiro Yamada , Bartosz Golaszewski , Linux ARM , Andy Shevchenko , Arnd Bergmann Subject: Re: [PATCH v9 1/9] bitops: Introduce the for_each_set_clump8 macro Message-ID: <20190308085733.GA3903@icarus> References: <12b3a364ac7fc32194fa6f55911dd800aca92a56.1551598603.git.vilhelm.gray@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.11.3 (2019-02-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Mar 08, 2019 at 09:31:00AM +0100, Linus Walleij wrote: > On Sun, Mar 3, 2019 at 8:47 AM William Breathitt Gray > wrote: > > > This macro iterates for each 8-bit group of bits (clump) with set bits, > > within a bitmap memory region. For each iteration, "start" is set to the > > bit offset of the found clump, while the respective clump value is > > stored to the location pointed by "clump". Additionally, the > > bitmap_get_value8 and bitmap_set_value8 functions are introduced to > > respectively get and set an 8-bit value in a bitmap memory region. > > > > Suggested-by: Andy Shevchenko > > Suggested-by: Rasmus Villemoes > > Cc: Arnd Bergmann > > Cc: Andrew Morton > > Reviewed-by: Andy Shevchenko > > Reviewed-by: Linus Walleij > > Signed-off-by: William Breathitt Gray > > Andrew: would you be OK with this being merged in v5.1? > > If we need to move the code to drivers/gpio that's OK (though > I think it's generally useful) but I need to know to proceed with > the William's nice optimization of these drivers. > > Yours, > Linus Walleij I was waiting on Andy to suggest some examples out of the GPIO realm, but he may be under a heavy workload right so I decided to do a quick search for one. In drivers/of/unittest.c, there is loop across a bitmap in the of_unittest_destroy_tracked_overlays function: for (id = MAX_UNITTEST_OVERLAYS - 1; id >= 0; id--) { if (!(overlay_id_bits[BIT_WORD(id)] & BIT_MASK(id))) continue; This section of code is checking each bit individually, and skipping if that bit is not set. This looping can be optimized by using the for_each_set_clump8 macro to skip clumps of nonset bits (not to mention make the logic of the code much simpler and easier to follow by reducing the code to a single line): for_each_set_clump8(id, clump, overlay_id_bits, MAX_UNITTEST_OVERLAYS-1) The for_each_set_clump8 macro is not specific to the GPIO subsystem; I just happen to use it in these GPIO drivers simply because I am most familar with this section of the kernel (it's where most of my contributions occur afterall). Consider this, if I am able to find a use for this macro outside of the GPIO subsystem within a matter minutes, then there must be some benefit in allowing the rest of the kernel to use the for_each_set_clump8 macro. So let's put it in bitops.h rather than restrict it to just the GPIO subsystem. William Breathitt Gray