lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <YSgDI9NpC51GhB/2@yury-ThinkPad>
Date:   Thu, 26 Aug 2021 14:09:55 -0700
From:   Yury Norov <yury.norov@...il.com>
To:     Petr Mladek <pmladek@...e.com>
Cc:     Andrew Morton <akpm@...ux-foundation.org>,
        linux-kernel@...r.kernel.org, linux-mm@...ck.org,
        linux-arch@...r.kernel.org, linux-kselftest@...r.kernel.org,
        linux-mmc@...r.kernel.org, linux-perf-users@...r.kernel.org,
        kvm@...r.kernel.org,
        "James E.J. Bottomley" <James.Bottomley@...senpartnership.com>,
        Alexander Lobakin <alobakin@...me>,
        Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
        Alexey Klimov <aklimov@...hat.com>,
        Andrea Merello <andrea.merello@...il.com>,
        Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
        Arnaldo Carvalho de Melo <acme@...hat.com>,
        Arnd Bergmann <arnd@...db.de>, Ben Gardon <bgardon@...gle.com>,
        Benjamin Herrenschmidt <benh@...nel.crashing.org>,
        Brian Cain <bcain@...eaurora.org>,
        Catalin Marinas <catalin.marinas@....com>,
        Christoph Lameter <cl@...ux.com>,
        Daniel Bristot de Oliveira <bristot@...hat.com>,
        David Hildenbrand <david@...hat.com>,
        Dennis Zhou <dennis@...nel.org>,
        Geert Uytterhoeven <geert@...ux-m68k.org>,
        Heiko Carstens <hca@...ux.ibm.com>,
        Ian Rogers <irogers@...gle.com>,
        Ingo Molnar <mingo@...hat.com>,
        Jaegeuk Kim <jaegeuk@...nel.org>,
        Jakub Kicinski <kuba@...nel.org>, Jiri Olsa <jolsa@...hat.com>,
        Joe Perches <joe@...ches.com>, Jonas Bonn <jonas@...thpole.se>,
        Leo Yan <leo.yan@...aro.org>,
        Mark Rutland <mark.rutland@....com>,
        Namhyung Kim <namhyung@...nel.org>,
        Palmer Dabbelt <palmer@...belt.com>,
        Paolo Bonzini <pbonzini@...hat.com>,
        Peter Xu <peterx@...hat.com>,
        Peter Zijlstra <peterz@...radead.org>,
        Rasmus Villemoes <linux@...musvillemoes.dk>,
        Rich Felker <dalias@...c.org>,
        Samuel Mendoza-Jonas <sam@...dozajonas.com>,
        Sean Christopherson <seanjc@...gle.com>,
        Sergey Senozhatsky <senozhatsky@...omium.org>,
        Shuah Khan <shuah@...nel.org>,
        Stefan Kristiansson <stefan.kristiansson@...nalahti.fi>,
        Steven Rostedt <rostedt@...dmis.org>,
        Tejun Heo <tj@...nel.org>,
        Thomas Bogendoerfer <tsbogend@...ha.franken.de>,
        Ulf Hansson <ulf.hansson@...aro.org>,
        Will Deacon <will@...nel.org>,
        Wolfram Sang <wsa+renesas@...g-engineering.com>,
        Yoshinori Sato <ysato@...rs.sourceforge.jp>
Subject: Re: [PATCH 11/17] find: micro-optimize for_each_{set,clear}_bit()

On Thu, Aug 26, 2021 at 03:57:13PM +0200, Petr Mladek wrote:
> On Sat 2021-08-14 14:17:07, Yury Norov wrote:
> > The macros iterate thru all set/clear bits in a bitmap. They search a
> > first bit using find_first_bit(), and the rest bits using find_next_bit().
> > 
> > Since find_next_bit() is called shortly after find_first_bit(), we can
> > save few lines of I-cache by not using find_first_bit().
> 
> Is this only a speculation or does it fix a real performance problem?
> 
> The macro is used like:
> 
> 	for_each_set_bit(bit, addr, size) {
> 		fn(bit);
> 	}
> 
> IMHO, the micro-opimization does not help when fn() is non-trivial.
 
The effect is measurable:

Start testing for_each_bit()
for_each_set_bit:                15296 ns,   1000 iterations
for_each_set_bit_from:           15225 ns,   1000 iterations

Start testing for_each_bit() with cash flushing
for_each_set_bit:               547626 ns,   1000 iterations
for_each_set_bit_from:          497899 ns,   1000 iterations

Refer this:

https://www.mail-archive.com/dri-devel@lists.freedesktop.org/msg356151.html

Thanks,
Yury
 
> > --- a/include/linux/find.h
> > +++ b/include/linux/find.h
> > @@ -280,7 +280,7 @@ unsigned long find_next_bit_le(const void *addr, unsigned
> >  #endif
> >  
> >  #define for_each_set_bit(bit, addr, size) \
> > -	for ((bit) = find_first_bit((addr), (size));		\
> > +	for ((bit) = find_next_bit((addr), (size), 0);		\
> >  	     (bit) < (size);					\
> >  	     (bit) = find_next_bit((addr), (size), (bit) + 1))
> >  
> 
> It is not a big deal. I just think that the original code is slightly
> more self-explaining.
> 
> Best Regards,
> Petr

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ