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=-7.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no 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 70CA8C43461 for ; Fri, 2 Apr 2021 17:31:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 450FE61155 for ; Fri, 2 Apr 2021 17:31:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236214AbhDBRbS (ORCPT ); Fri, 2 Apr 2021 13:31:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236037AbhDBRbF (ORCPT ); Fri, 2 Apr 2021 13:31:05 -0400 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A63ECC06178C; Fri, 2 Apr 2021 10:31:03 -0700 (PDT) Received: by mail-pj1-x102d.google.com with SMTP id j6-20020a17090adc86b02900cbfe6f2c96so2871713pjv.1; Fri, 02 Apr 2021 10:31:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=FZh3mSDQYQE4cryDjboNauvPGmXp8rg2ygYGDJ2001s=; b=uti1Q7UenDxJjSzrbi/Y+R9MqhtCk5ki73a/PkSsfbXLG2vCctRNOtellfI/d77Pbe KpJ5TO2lQxQ6HWlZ8YIEdneuOV1gPhhwKQO5PkgHsJvv6k/rtcJ7vqarbSoFIGVY5R35 NRAa5szbAjGqdKjSRv6eizO5naZBpUBWvqIP46n9+3CjECqvRcrgKxdhbbZYymx6YmJX DBJ+xah/0RKHOmC8RXzQKsI8FcBiGqw8o69IQlcXrAiS8EUPQGHlSAgMm7x2gZ+lSqEc guyhTWR2cY1VHsknOiTZpJz+MYH8oXYG6qYJMRjbpkbqqW3XF/qvEdMFeFGPcW27k2ec GQIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=FZh3mSDQYQE4cryDjboNauvPGmXp8rg2ygYGDJ2001s=; b=Ra/4vrGSZJufyD4yPtue9EppOeJyKs+G3sO4CMKy5u0pVFX6mv1gbtI9urIUIwic7A nG2ec+KteZBC9JqBOBnfhkEMLs+x11vipiiBjHxXKTXE3hdXMC86aXjryEsNVPtglZfH c1hyOSTH8TefiliBwZKMo2Ibpdv7ANU0dA59HKX5DwVpqGbjh+SF17Dn1Kq+zz+AaHkA FK82D7TwJag/zjk6Z4L+pEOm0atIiRh5BnMY2vuVfcHsSy1+FatwKqJ9/CA+G4t29xc+ 0mk4tzbitFs5ENHhtDhTKRTMeItVVbfnP/1PGQsQQRRxVdy2OWu7C4X34n1vXa6jik5H Eufg== X-Gm-Message-State: AOAM532/KEy2EcKyJfnhIm07D2A+t+DMDWYA7MSWdwodgkHpCgZt6y4x bAKQuETsMAmXevkO5jwqHGUrEkjfhKdBG/XwdaZEpRwvJHc= X-Google-Smtp-Source: ABdhPJxCTl+Sc6X0Z4Dse3zRWdNYRmPss0rGxu3wQV2szTOEDu9IZf9Q9PG0rFPR5VkGvD0TXyjN+3Q3K64Fclz9qjY= X-Received: by 2002:a17:90a:db49:: with SMTP id u9mr15258280pjx.181.1617384663176; Fri, 02 Apr 2021 10:31:03 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Andy Shevchenko Date: Fri, 2 Apr 2021 20:30:45 +0300 Message-ID: Subject: Re: [RESEND PATCH v4 0/3] Introduce the for_each_set_nbits macro To: Syed Nayyar Waris Cc: Bartosz Golaszewski , Andy Shevchenko , William Breathitt Gray , Michal Simek , Arnd Bergmann , Robert Richter , Linus Walleij , Masahiro Yamada , Andrew Morton , "Zhang, Rui" , Daniel Lezcano , Amit Kucheria , Linux-Arch , "open list:GPIO SUBSYSTEM" , Linux Kernel Mailing List , linux-arm Mailing List , Linux PM Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org On Fri, Apr 2, 2021 at 7:36 PM Syed Nayyar Waris wrote: > > Hello Bartosz, > > Since this patchset primarily affects GPIO drivers, would you like > to pick it up through your GPIO tree? > > This patchset introduces a new generic version of for_each_set_nbits. > The previous version of for_each_set_clump8 used a fixed size 8-bit > clump, but the new generic version can work with clump of any size but clumps > less than or equal to BITS_PER_LONG. The patchset utilizes the new macro > in several GPIO drivers. > > The earlier 8-bit for_each_set_clump8 facilitated a > for-loop syntax that iterates over a memory region entire groups of set > bits at a time. > > For example, suppose you would like to iterate over a 32-bit integer 8 > bits at a time, skipping over 8-bit groups with no set bit, where > XXXXXXXX represents the current 8-bit group: > > Example: 10111110 00000000 11111111 00110011 > First loop: 10111110 00000000 11111111 XXXXXXXX > Second loop: 10111110 00000000 XXXXXXXX 00110011 > Third loop: XXXXXXXX 00000000 11111111 00110011 > > Each iteration of the loop returns the next 8-bit group that has at > least one set bit. > > But with the new for_each_set_nbits the clump size can be different from 8 bits. > Moreover, the clump can be split at word boundary in situations where word boundaries > size is not multiple of clump size. Following are examples showing the working > of new macro for clump sizes of 24 bits and 6 bits. > > Example 1: > clump size: 24 bits, Number of clumps (or ports): 10 > bitmap stores the bit information from where successive clumps are retrieved. > > /* bitmap memory region */ > 0x00aa0000ff000000; /* Most significant bits */ > 0xaaaaaa0000ff0000; > 0x000000aa000000aa; > 0xbbbbabcdeffedcba; /* Least significant bits */ > > Different iterations of for_each_set_nbits:- > 'offset' is the bit position and 'clump' is the 24 bit clump from the > above bitmap. > Iteration first: offset: 0 clump: 0xfedcba > Iteration second: offset: 24 clump: 0xabcdef > Iteration third: offset: 48 clump: 0xaabbbb > Iteration fourth: offset: 96 clump: 0xaa > Iteration fifth: offset: 144 clump: 0xff > Iteration sixth: offset: 168 clump: 0xaaaaaa > Iteration seventh: offset: 216 clump: 0xff > Loop breaks because in the end the remaining bits (0x00aa) size was less > than clump size of 24 bits. > > In above example it can be seen that in iteration third, the 24 bit clump > that was retrieved was split between bitmap[0] and bitmap[1]. This example > also shows that 24 bit zeroes if present in between, were skipped (preserving > the previous for_each_set_macro8 behaviour). > > Example 2: > clump size = 6 bits, Number of clumps (or ports) = 3. > > /* bitmap memory region */ > 0x00aa0000ff000000; /* Most significant bits */ > 0xaaaaaa0000ff0000; > 0x0f00000000000000; > 0x0000000000000ac0; /* Least significant bits */ > > Different iterations of for_each_set_nbits: > 'offset' is the bit position and 'clump' is the 6 bit clump from the > above bitmap. > Iteration first: offset: 6 clump: 0x2b > Loop breaks because 6 * 3 = 18 bits traversed in bitmap. > Here 6 * 3 is clump size * no. of clumps. Bart, I would like to have a fresh look at this. (missed changelog) > Changes in v4: > - [Patch 3/3]: Remove extra line and add few comments. > - [Patch 3/3]: Use single lock (and unlock) call instead of two > lock (and two unlock) calls. > - [Patch 3/3]: Use bitmap_from_arr32() where applicalble. > - [Patch 3/3]: Remove unnecessary 'const'. > > Changes in v3: > - [Patch 1/3]: Rename for_each_set_clump to for_each_set_nbits. > - [Patch 1/3]: Shift function definitions outside 'ifdef CONFIG_DEBUG_FS' > macro guard to resolve build (linking) error in xilinx Patch[3/3]. > - [Patch 2/3]: Rename for_each_set_clump to for_each_set_nbits. > > Changes in v2: > - [Patch 1/3]: Shift the macros and related functions to gpiolib inside > gpio/. Reduce the visibilty of 'for_each_set_clump' to gpio. > - [Patch 1/3]: Remove __builtin_unreachable and simply use return > statement. > - Remove tests from lib/test_bitmap.c as 'for_each_set_clump' is > now localised inside gpio/ only. > > Syed Nayyar Waris (3): > gpiolib: Introduce the for_each_set_nbits macro > gpio: thunderx: Utilize for_each_set_nbits macro > gpio: xilinx: Utilize generic bitmap_get_value and _set_value > > drivers/gpio/gpio-thunderx.c | 13 ++++-- > drivers/gpio/gpio-xilinx.c | 52 ++++++++++----------- > drivers/gpio/gpiolib.c | 90 ++++++++++++++++++++++++++++++++++++ > drivers/gpio/gpiolib.h | 28 +++++++++++ > 4 files changed, 152 insertions(+), 31 deletions(-) > > > base-commit: e1b7033ecdac56c1cc4dff72d67cac25d449efc6 > -- > 2.29.0 > -- With Best Regards, Andy Shevchenko 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=-5.7 required=3.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no 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 5B19EC433ED for ; Fri, 2 Apr 2021 17:32:58 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 E710A61155 for ; Fri, 2 Apr 2021 17:32:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E710A61155 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+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=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:Cc:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=ZywJKR1hi069PXL5iRHw+X0Q52IFzE1M/gSwFR8KkqI=; b=OvElvBa4j9apsRD3RdCy6tBns QmZpww44EbmlP2omj3L0uFGK8DvemHoJwDdSR2zqXE4D7ojdBIgFB87XTJPSeKBx8PehnUohz9Jcj RDkZQ7Xz9HjJGz963uTYz4E1RopM7gLRhbF7ywxPcsRRW+RoJEGbAEKT/mWePlfkL8z3kOKxT44W8 Gu+U2rfNihm4ePVjTXhdF9qMeqE/Z0j4c5cFKiD4GnkWP/oNoFq5IsKfoIkw/PduLAizlXGddzCb2 9ayVM3uhHtFvhYDFF/sjn1DfHBN0jzHKQMXf8rag8v3DakC+tXczmvtpG7eIGtI4Qtzbc1kmpIFsd 9o+WKcI5A==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lSNdc-00DVDE-Iy; Fri, 02 Apr 2021 17:31:16 +0000 Received: from mail-pj1-x1036.google.com ([2607:f8b0:4864:20::1036]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lSNdR-00DVCL-6v for linux-arm-kernel@lists.infradead.org; Fri, 02 Apr 2021 17:31:08 +0000 Received: by mail-pj1-x1036.google.com with SMTP id kk2-20020a17090b4a02b02900c777aa746fso2854773pjb.3 for ; Fri, 02 Apr 2021 10:31:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=FZh3mSDQYQE4cryDjboNauvPGmXp8rg2ygYGDJ2001s=; b=uti1Q7UenDxJjSzrbi/Y+R9MqhtCk5ki73a/PkSsfbXLG2vCctRNOtellfI/d77Pbe KpJ5TO2lQxQ6HWlZ8YIEdneuOV1gPhhwKQO5PkgHsJvv6k/rtcJ7vqarbSoFIGVY5R35 NRAa5szbAjGqdKjSRv6eizO5naZBpUBWvqIP46n9+3CjECqvRcrgKxdhbbZYymx6YmJX DBJ+xah/0RKHOmC8RXzQKsI8FcBiGqw8o69IQlcXrAiS8EUPQGHlSAgMm7x2gZ+lSqEc guyhTWR2cY1VHsknOiTZpJz+MYH8oXYG6qYJMRjbpkbqqW3XF/qvEdMFeFGPcW27k2ec GQIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=FZh3mSDQYQE4cryDjboNauvPGmXp8rg2ygYGDJ2001s=; b=rVWqJ1YKW0IsiJvbpZnOwcfBXteyJYfun6hsOPq0p5x7qeYp6AShLnN3p2MyOhKkNt e9JPxv8FtXkwZx/yp8m4KBh/b6GPsYa4MRvCNlxwLn5rpPAy0NxpI6JSdlan6q2QhZoC E1rD28Xl5kDbkmWNxlWdHwbb0xIy4G7fG81+c3PLskl8W1l6BWN0G0VDaXkvh1hlW3Lg IZz3M/HkAAJjlnZe00JcMVRNygYgAINVXyxVyFxjuyTNRToBv2GLlU9gcVLMaKZMMwRX bm3qA0c8wTN3soOp4Z1cggDmwSIWcNOgh+7XrTHsjzfTempAHOLF3NYK8nxsbjftWlgA 8aug== X-Gm-Message-State: AOAM5323lMT9B+L9YZZWTkNQmnRb2ndi9f+4MCVpspHKixZ61n2YWSSH TjdWbIu2junPyB9EfDYPNNQ45WW3mKlAofH1zEU= X-Google-Smtp-Source: ABdhPJxCTl+Sc6X0Z4Dse3zRWdNYRmPss0rGxu3wQV2szTOEDu9IZf9Q9PG0rFPR5VkGvD0TXyjN+3Q3K64Fclz9qjY= X-Received: by 2002:a17:90a:db49:: with SMTP id u9mr15258280pjx.181.1617384663176; Fri, 02 Apr 2021 10:31:03 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Andy Shevchenko Date: Fri, 2 Apr 2021 20:30:45 +0300 Message-ID: Subject: Re: [RESEND PATCH v4 0/3] Introduce the for_each_set_nbits macro To: Syed Nayyar Waris Cc: Bartosz Golaszewski , Andy Shevchenko , William Breathitt Gray , Michal Simek , Arnd Bergmann , Robert Richter , Linus Walleij , Masahiro Yamada , Andrew Morton , "Zhang, Rui" , Daniel Lezcano , Amit Kucheria , Linux-Arch , "open list:GPIO SUBSYSTEM" , Linux Kernel Mailing List , linux-arm Mailing List , Linux PM X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210402_183105_363191_386B5683 X-CRM114-Status: GOOD ( 30.84 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Fri, Apr 2, 2021 at 7:36 PM Syed Nayyar Waris wrote: > > Hello Bartosz, > > Since this patchset primarily affects GPIO drivers, would you like > to pick it up through your GPIO tree? > > This patchset introduces a new generic version of for_each_set_nbits. > The previous version of for_each_set_clump8 used a fixed size 8-bit > clump, but the new generic version can work with clump of any size but clumps > less than or equal to BITS_PER_LONG. The patchset utilizes the new macro > in several GPIO drivers. > > The earlier 8-bit for_each_set_clump8 facilitated a > for-loop syntax that iterates over a memory region entire groups of set > bits at a time. > > For example, suppose you would like to iterate over a 32-bit integer 8 > bits at a time, skipping over 8-bit groups with no set bit, where > XXXXXXXX represents the current 8-bit group: > > Example: 10111110 00000000 11111111 00110011 > First loop: 10111110 00000000 11111111 XXXXXXXX > Second loop: 10111110 00000000 XXXXXXXX 00110011 > Third loop: XXXXXXXX 00000000 11111111 00110011 > > Each iteration of the loop returns the next 8-bit group that has at > least one set bit. > > But with the new for_each_set_nbits the clump size can be different from 8 bits. > Moreover, the clump can be split at word boundary in situations where word boundaries > size is not multiple of clump size. Following are examples showing the working > of new macro for clump sizes of 24 bits and 6 bits. > > Example 1: > clump size: 24 bits, Number of clumps (or ports): 10 > bitmap stores the bit information from where successive clumps are retrieved. > > /* bitmap memory region */ > 0x00aa0000ff000000; /* Most significant bits */ > 0xaaaaaa0000ff0000; > 0x000000aa000000aa; > 0xbbbbabcdeffedcba; /* Least significant bits */ > > Different iterations of for_each_set_nbits:- > 'offset' is the bit position and 'clump' is the 24 bit clump from the > above bitmap. > Iteration first: offset: 0 clump: 0xfedcba > Iteration second: offset: 24 clump: 0xabcdef > Iteration third: offset: 48 clump: 0xaabbbb > Iteration fourth: offset: 96 clump: 0xaa > Iteration fifth: offset: 144 clump: 0xff > Iteration sixth: offset: 168 clump: 0xaaaaaa > Iteration seventh: offset: 216 clump: 0xff > Loop breaks because in the end the remaining bits (0x00aa) size was less > than clump size of 24 bits. > > In above example it can be seen that in iteration third, the 24 bit clump > that was retrieved was split between bitmap[0] and bitmap[1]. This example > also shows that 24 bit zeroes if present in between, were skipped (preserving > the previous for_each_set_macro8 behaviour). > > Example 2: > clump size = 6 bits, Number of clumps (or ports) = 3. > > /* bitmap memory region */ > 0x00aa0000ff000000; /* Most significant bits */ > 0xaaaaaa0000ff0000; > 0x0f00000000000000; > 0x0000000000000ac0; /* Least significant bits */ > > Different iterations of for_each_set_nbits: > 'offset' is the bit position and 'clump' is the 6 bit clump from the > above bitmap. > Iteration first: offset: 6 clump: 0x2b > Loop breaks because 6 * 3 = 18 bits traversed in bitmap. > Here 6 * 3 is clump size * no. of clumps. Bart, I would like to have a fresh look at this. (missed changelog) > Changes in v4: > - [Patch 3/3]: Remove extra line and add few comments. > - [Patch 3/3]: Use single lock (and unlock) call instead of two > lock (and two unlock) calls. > - [Patch 3/3]: Use bitmap_from_arr32() where applicalble. > - [Patch 3/3]: Remove unnecessary 'const'. > > Changes in v3: > - [Patch 1/3]: Rename for_each_set_clump to for_each_set_nbits. > - [Patch 1/3]: Shift function definitions outside 'ifdef CONFIG_DEBUG_FS' > macro guard to resolve build (linking) error in xilinx Patch[3/3]. > - [Patch 2/3]: Rename for_each_set_clump to for_each_set_nbits. > > Changes in v2: > - [Patch 1/3]: Shift the macros and related functions to gpiolib inside > gpio/. Reduce the visibilty of 'for_each_set_clump' to gpio. > - [Patch 1/3]: Remove __builtin_unreachable and simply use return > statement. > - Remove tests from lib/test_bitmap.c as 'for_each_set_clump' is > now localised inside gpio/ only. > > Syed Nayyar Waris (3): > gpiolib: Introduce the for_each_set_nbits macro > gpio: thunderx: Utilize for_each_set_nbits macro > gpio: xilinx: Utilize generic bitmap_get_value and _set_value > > drivers/gpio/gpio-thunderx.c | 13 ++++-- > drivers/gpio/gpio-xilinx.c | 52 ++++++++++----------- > drivers/gpio/gpiolib.c | 90 ++++++++++++++++++++++++++++++++++++ > drivers/gpio/gpiolib.h | 28 +++++++++++ > 4 files changed, 152 insertions(+), 31 deletions(-) > > > base-commit: e1b7033ecdac56c1cc4dff72d67cac25d449efc6 > -- > 2.29.0 > -- With Best Regards, Andy Shevchenko _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel