Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1442919pxf; Fri, 2 Apr 2021 10:33:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxSNDwxwm9AB3CZnFoA4zGPCuV+XK21zqI+7q5mCscZdsLm0d36Vm9sx5g4VihD2Yn1zb37 X-Received: by 2002:a05:6402:3550:: with SMTP id f16mr16420971edd.134.1617384820173; Fri, 02 Apr 2021 10:33:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617384820; cv=none; d=google.com; s=arc-20160816; b=fOeMxWEQbVUyRYIHB774L+/Ue1YbMtVpWGqQi43BURAPX3WvWKRPwaf73e/Qs82zmK OpnP0fFIfpAiIo/fgbss/tebTMonMwpDSBEeVEDoQgkmCjcs6K4qPpDu+ChUZmT3Cvo0 WS0xxv19u9OIzKbx3aYMYy69ZT8y/dww8DIsrD/X/ceWRObRxYyUfppHBExTGWSZcwzV ZgsXmmcg1tXQNsgVu1RZYUkMjbunnbpbOeAJ5f5X/LWxsrq9TOFIkZNO3nf/uh9AtJSE TvG9rhquYQIEr6WocyaCoXZ4jwwmdJ6TethaXU++563HVqSFtpB9j/bWJhXipuvxkpGw 3Bdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=FZh3mSDQYQE4cryDjboNauvPGmXp8rg2ygYGDJ2001s=; b=0LQ0l3Plovasgm0CWGSXLG2QbRv4xfNwX16yLWlHeItPG1wyXj80UNkA1n+0subO1k 4+18N1xF4dRIV1qXPsBTHT4FKnb6IUuo/eDCxnkY/RoEYL1+yC9eB7sbN/iDviihbUH5 Tmngqy3pRNTSk9mt7ksbTY8/NXSK5jxE8HNHfbAmUp2/hMzAeRg07d4n/YuvGu1Tgps5 EQwl+T4v+9NVBDIn7kuOFms8+8w83a1vsVqq31kNuIHzjkabza59odlUbCTpHq6iHmk1 TAYM8ZU6kId3L8WBuJNJAn8gbiW5Xsfze7TnJGFZWd+Xa8cbU27qS4suNeoPNaYMWlSc 7o9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=uti1Q7Ue; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id v4si7064851ejx.329.2021.04.02.10.33.17; Fri, 02 Apr 2021 10:33:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=uti1Q7Ue; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S234207AbhDBRbx (ORCPT + 99 others); Fri, 2 Apr 2021 13:31:53 -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-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-kernel@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