From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.2 required=3.0 tests=DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_PASS,USER_AGENT_MUTT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8634EC43381 for ; Tue, 26 Mar 2019 10:07:45 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 52B542075D for ; Tue, 26 Mar 2019 10:07:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="m0zeEG0i"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IzxlXlve" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 52B542075D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=AazhdiNtokFpWef+VLRfH9hje5N5uZj5ttFH78/LvbY=; b=m0zeEG0iO6tKVq iFp3rh7xYKzihfwHvvufwYSRZRKgxeUfbPd51P+PxTUk7qtQbw2wX/30GV8dKvDPi/hAsYXAoEVlf Ghy9w4+E6dvfxBQ6qc5somQbq3GCErf8dRsnC9KEMg3Sqjel5ICFgzdkcEZe3uUt16z8f6pKVmald w8IE7WvDgkYJ2mkQfsTodz5gLB7u2dnyK3WYUg6RHwOF21WLQBDcjAlbA5oyuyvSLjiLbVVTnUpje Ugcom6G6y+k/1PXzOtEMadgMZuUWJ2sFs06sX0OuX95dmoljKIcVXlaOqeTFrKzrZSOslgDH5NhyF xlCcN0oBaZQP7X8CxxBA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h8izb-0003bH-Lr; Tue, 26 Mar 2019 10:07:39 +0000 Received: from mail-it1-x144.google.com ([2607:f8b0:4864:20::144]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h8izX-0003aq-Ce for linux-arm-kernel@lists.infradead.org; Tue, 26 Mar 2019 10:07:37 +0000 Received: by mail-it1-x144.google.com with SMTP id 139so18966161ita.4 for ; Tue, 26 Mar 2019 03:07:34 -0700 (PDT) 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=K7hooZ3G6onOEeayZK4JiqpFMx2K/uTaEbwPOFqkQEY=; b=IzxlXlvejcGQZU1t79O5kLco59xuNTtjx3mVzWH/wUO2vrulEZUcCFIADrYhLIrJ1c xv8tgA50pwHfvG4ECP1DqRqHSUWHNE46zKs10GcdgLHa0e6snyHmpSE9LarNcLVISWJT IEJroBxgUPUwQu419fGneQKidMLFyy1dXwYEVBsAR/lqjPbcW/hSqmKuWUid1i2Rx5Dd 6Sn4J4nBEc/SDy2iSt6LPWzdbnzSdwd26t8U29y1xvP4lmNiq7oTdLe7fV9YnB75OSnU pbsRpfAlCZ92x57iJUZFH19uOSmpCWYGV5HyazmarrtjfyM7V6QOZZcPZDDrnksUhg70 GykA== 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=K7hooZ3G6onOEeayZK4JiqpFMx2K/uTaEbwPOFqkQEY=; b=tU3abXpxRjEF21ja3TBm9KseWHRK7ODiRGhTOcukq8PDxi1hemqPFN3MewStj8AM48 rU0r2+YAShA6V7UpualKTZeRV7/EhslHJgFKQuD9FzkCZjQufK7upoQzaduP5AJZr8Xv y+hhL116DsxLOT2FNsY3v4QF6TZDDwh5GuEhEDp5LaXl16tPWPWsq9tlZ+3u8W+YqWm7 H6sXBeM5CQaSFT6KImnL/GMRKMoSaiON2S+HJUHgBbDNiRgQDVWlUYiJvJUs141DBbRG cOcqHmSbBmpX/YxmA7oZ9LM9B/U7PmKaXNKCqaUsaUqfqdEqiZ+cxjDPqoPrIk6w8phI 2f4w== X-Gm-Message-State: APjAAAWoFV5BGqUdKaT50/reYzRyDtJr4Xxx9SYBnLF7TD+h8zMk66yl y/ItPHm8r0j29e1th7YQSq0= X-Google-Smtp-Source: APXvYqxSpQ84IA7VmN5bmVRjcpdBlLstMDdFL8tkFu7b4VG0fj2FhjRwbrBlPj5VvA1EiVEggfnoiw== X-Received: by 2002:a24:a50c:: with SMTP id k12mr15764383itf.6.1553594853706; Tue, 26 Mar 2019 03:07:33 -0700 (PDT) Received: from icarus ([2001:268:c0a3:6e7a:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id 76sm7163127itk.40.2019.03.26.03.07.24 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 26 Mar 2019 03:07:33 -0700 (PDT) Date: Tue, 26 Mar 2019 19:08:18 +0900 From: William Breathitt Gray To: Lukas Wunner , Andy Shevchenko Subject: Re: [PATCH v12 01/11] bitops: Introduce the for_each_set_clump8 macro Message-ID: <20190326100743.GA10005@icarus> References: <9afc30a574ce3e6a86b51dd522146a1d2156dedd.1553494625.git.vilhelm.gray@gmail.com> <20190325093854.jzkkwaksxi7zvtrg@wunner.de> <20190326031422.GB3356@icarus> <20190326094345.v7l7xjvfs2scbvbv@wunner.de> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20190326094345.v7l7xjvfs2scbvbv@wunner.de> User-Agent: Mutt/1.11.4 (2019-03-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190326_030735_480166_061EB2FB X-CRM114-Status: GOOD ( 22.64 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, preid@electromag.com.au, Arnd Bergmann , linux-gpio@vger.kernel.org, yamada.masahiro@socionext.com, linus.walleij@linaro.org, linux-pm@vger.kernel.org, linux@rasmusvillemoes.dk, linux-kernel@vger.kernel.org, bgolaszewski@baylibre.com, geert@linux-m68k.org, akpm@linux-foundation.org, andriy.shevchenko@linux.intel.com, linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Tue, Mar 26, 2019 at 10:43:45AM +0100, Lukas Wunner wrote: > On Tue, Mar 26, 2019 at 12:14:22PM +0900, William Breathitt Gray wrote: > > On Mon, Mar 25, 2019 at 10:38:54AM +0100, Lukas Wunner wrote: > > > On Mon, Mar 25, 2019 at 03:22:23PM +0900, William Breathitt Gray wrote: > > > > +/** > > > > + * find_next_clump8 - find next 8-bit clump with set bits in a memory region > > > > + * @clump: location to store copy of found clump > > > > + * @addr: address to base the search on > > > > + * @offset: bit offset at which to start searching > > > > + * @size: bitmap size in number of bits > > > > + * > > > > + * Returns the bit offset for the next set clump; the found clump value is > > > > + * copied to the location pointed by @clump. If no bits are set, returns @size. > > > > + */ > > > > +unsigned int find_next_clump8(unsigned long *const clump, > > > > + const unsigned long *const addr, > > > > + unsigned int offset, const unsigned int size) > > > > +{ > > > > + for (; offset < size; offset += 8) { > > > > + *clump = bitmap_get_value8(addr, size, offset); > > > > + if (!*clump) > > > > + continue; > > > > + > > > > + return offset; > > > > + } > > > > + > > > > + return size; > > > > +} > > > > +EXPORT_SYMBOL(find_next_clump8); > > > > > > Just use find_first_bit() / find_next_bit() to use optimized arch-specific > > > bitops instead of open-coding the iteration over the bitmap. > > > > > > See max3191x_get_multiple() for an example. > > > > Is this the sort of implementation you had in mind: > > > > offset = find_next_bit(addr, size, offset); > > if (offset == size) > > return size; > > > > offset -= offset % 8; > > *clump = bitmap_get_value8(addr, size, offset); > > > > return offset; > > Almost. I'd use round_down() instead of "offset -= offset % 8". > Then it's just a single cheap logical and operation at runtime. All right I'll try this setup using round_down() then. > > I'd try to avoid copying around the clump value and use a pointer > to u8 instead. Although in this case we are handling 8-bit clumps, I anticipate device drivers in the future which may benefit from larger size clumps (e.g. GPIO devices with 24-bit ports). It'll be better to define clumps similar to how we're defining bitmaps now (unsigned long *) so that we can support these sizes if need be in the future without requiring data type changes. > > I don't understand the calculations in bitmap_get_value8() at all. > Why is it so complicated, does it allow passing in a start value > that's not a multiple of 8? Do you really need that? I imagine > a simplification is possible if that assumption can be made (and > is spelled out in the kerneldoc). That's a good point. Originally, I had envisioned the possibility of calling bitmap_get_value8/bitmap_set_value8 at odd start offsets; this would open up the possibility of a clump landing as a split between 2 words, thus requiring this complicated case handling code. However, I'm not sure how often users would need this case; none of the drivers right now require clumps at odd offsets. Andy, would you have any objection to restricting the start offset values for bitmap_get_value8/bitmap_set_value8 to multiples of 8? That would prevent the split word case, and thus allow the implementation for those functions to be a lot simpler. William Breathitt Gray > > > > Should the offset and size parameters be redefined as unsigned long to > > match the find_first_bit/find_next_bit function parameters? > > Yes, probably. It's just the CPU's native length anyway. > > Thanks, > > Lukas _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel