Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1194681 > unrolled thread
| Started by | Yury <yury.norov@gmail.com> |
|---|---|
| First post | 2015-07-28 23:30 +0200 |
| Last post | 2015-07-29 22:50 +0200 |
| Articles | 5 — 4 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: [PATCH] lib: Make _find_next_bit helper function inline Yury <yury.norov@gmail.com> - 2015-07-28 23:30 +0200
Re: [PATCH] lib: Make _find_next_bit helper function inline Yury <yury.norov@gmail.com> - 2015-07-28 23:40 +0200
Re: [PATCH] lib: Make _find_next_bit helper function inline Andrew Morton <akpm@linux-foundation.org> - 2015-07-28 23:50 +0200
Re: [PATCH] lib: Make _find_next_bit helper function inline Alexey Klimov <klimov.linux@gmail.com> - 2015-07-29 15:40 +0200
Re: [PATCH] lib: Make _find_next_bit helper function inline Cassidy Burden <cburden@codeaurora.org> - 2015-07-29 22:50 +0200
| From | Yury <yury.norov@gmail.com> |
|---|---|
| Date | 2015-07-28 23:30 +0200 |
| Subject | Re: [PATCH] lib: Make _find_next_bit helper function inline |
| Message-ID | <pRkBJ-4uH-19@gated-at.bofh.it> |
On 28.07.2015 22:09, Cassidy Burden wrote:
> I've tested Yury Norov's find_bit reimplementation with the test_find_bit
> module (https://lkml.org/lkml/2015/3/8/141) and measured about 35-40%
> performance degradation on arm64 3.18 run with fixed CPU frequency.
>
> The performance degradation appears to be caused by the
> helper function _find_next_bit. After inlining this function into
> find_next_bit and find_next_zero_bit I get slightly better performance
> than the old implementation:
>
> find_next_zero_bit find_next_bit
> old new inline old new inline
> 26 36 24 24 33 23
> 25 36 24 24 33 23
> 26 36 24 24 33 23
> 25 36 24 24 33 23
> 25 36 24 24 33 23
> 25 37 24 24 33 23
> 25 37 24 24 33 23
> 25 37 24 24 33 23
> 25 36 24 24 33 23
> 25 37 24 24 33 23
>
> Signed-off-by: Cassidy Burden <cburden@codeaurora.org>
> Cc: Alexey Klimov <klimov.linux@gmail.com>
> Cc: David S. Miller <davem@davemloft.net>
> Cc: Daniel Borkmann <dborkman@redhat.com>
> Cc: Hannes Frederic Sowa <hannes@stressinduktion.org>
> Cc: Lai Jiangshan <laijs@cn.fujitsu.com>
> Cc: Mark Salter <msalter@redhat.com>
> Cc: AKASHI Takahiro <takahiro.akashi@linaro.org>
> Cc: Thomas Graf <tgraf@suug.ch>
> Cc: Valentin Rothberg <valentinrothberg@gmail.com>
> Cc: Chris Wilson <chris@chris-wilson.co.uk>
> ---
> lib/find_bit.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/lib/find_bit.c b/lib/find_bit.c
> index 18072ea..d0e04f9 100644
> --- a/lib/find_bit.c
> +++ b/lib/find_bit.c
> @@ -28,7 +28,7 @@
> * find_next_zero_bit. The difference is the "invert" argument, which
> * is XORed with each fetched word before searching it for one bits.
> */
> -static unsigned long _find_next_bit(const unsigned long *addr,
> +static inline unsigned long _find_next_bit(const unsigned long *addr,
> unsigned long nbits, unsigned long start, unsigned long invert)
> {
> unsigned long tmp;
Hi Cassidi,
At first, I'm really surprised that there's no assembler implementation
of find_bit routines for aarch64. Aarch32 has ones...
I was thinking on inlining the helper, but decided not to do this....
1. Test is not too realistic. https://lkml.org/lkml/2015/2/1/224
The typical usage pattern is to look for a single bit or range of bits.
So in practice nobody calls find_next_bit thousand times.
2. Way more important to fit functions into as less cache lines as
possible. https://lkml.org/lkml/2015/2/12/114
In this case, inlining increases cache lines consumption almost twice...
3. Inlining prevents compiler from some other possible optimizations. It's
probable that in real module compiler will inline callers of _find_next_bit,
and final output will be better. I don't like to point out the compiler how
it should do its work.
Nevertheless, if this is your real case, and inlining helps, I'm OK with it.
But I think, before/after for x86 is needed as well.
And why don't you consider '__always_inline__'? Simple inline is only a
hint and
guarantees nothing.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [next] | [standalone]
| From | Yury <yury.norov@gmail.com> |
|---|---|
| Date | 2015-07-28 23:40 +0200 |
| Message-ID | <pRkLo-4Fc-21@gated-at.bofh.it> |
| In reply to | #1194681 |
On 29.07.2015 00:23, Yury wrote:
> On 28.07.2015 22:09, Cassidy Burden wrote:
>> I've tested Yury Norov's find_bit reimplementation with the
>> test_find_bit
>> module (https://lkml.org/lkml/2015/3/8/141) and measured about 35-40%
>> performance degradation on arm64 3.18 run with fixed CPU frequency.
>>
>> The performance degradation appears to be caused by the
>> helper function _find_next_bit. After inlining this function into
>> find_next_bit and find_next_zero_bit I get slightly better performance
>> than the old implementation:
>>
>> find_next_zero_bit find_next_bit
>> old new inline old new inline
>> 26 36 24 24 33 23
>> 25 36 24 24 33 23
>> 26 36 24 24 33 23
>> 25 36 24 24 33 23
>> 25 36 24 24 33 23
>> 25 37 24 24 33 23
>> 25 37 24 24 33 23
>> 25 37 24 24 33 23
>> 25 36 24 24 33 23
>> 25 37 24 24 33 23
>>
>> Signed-off-by: Cassidy Burden <cburden@codeaurora.org>
>> Cc: Alexey Klimov <klimov.linux@gmail.com>
>> Cc: David S. Miller <davem@davemloft.net>
>> Cc: Daniel Borkmann <dborkman@redhat.com>
>> Cc: Hannes Frederic Sowa <hannes@stressinduktion.org>
>> Cc: Lai Jiangshan <laijs@cn.fujitsu.com>
>> Cc: Mark Salter <msalter@redhat.com>
>> Cc: AKASHI Takahiro <takahiro.akashi@linaro.org>
>> Cc: Thomas Graf <tgraf@suug.ch>
>> Cc: Valentin Rothberg <valentinrothberg@gmail.com>
>> Cc: Chris Wilson <chris@chris-wilson.co.uk>
>> ---
>> lib/find_bit.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/lib/find_bit.c b/lib/find_bit.c
>> index 18072ea..d0e04f9 100644
>> --- a/lib/find_bit.c
>> +++ b/lib/find_bit.c
>> @@ -28,7 +28,7 @@
>> * find_next_zero_bit. The difference is the "invert" argument, which
>> * is XORed with each fetched word before searching it for one bits.
>> */
>> -static unsigned long _find_next_bit(const unsigned long *addr,
>> +static inline unsigned long _find_next_bit(const unsigned long *addr,
>> unsigned long nbits, unsigned long start, unsigned long
>> invert)
>> {
>> unsigned long tmp;
>
> Hi Cassidi,
>
> At first, I'm really surprised that there's no assembler implementation
> of find_bit routines for aarch64. Aarch32 has ones...
>
> I was thinking on inlining the helper, but decided not to do this....
>
> 1. Test is not too realistic. https://lkml.org/lkml/2015/2/1/224
> The typical usage pattern is to look for a single bit or range of bits.
> So in practice nobody calls find_next_bit thousand times.
>
> 2. Way more important to fit functions into as less cache lines as
> possible. https://lkml.org/lkml/2015/2/12/114
> In this case, inlining increases cache lines consumption almost twice...
>
> 3. Inlining prevents compiler from some other possible optimizations.
> It's
> probable that in real module compiler will inline callers of
> _find_next_bit,
> and final output will be better. I don't like to point out the
> compiler how
> it should do its work.
>
> Nevertheless, if this is your real case, and inlining helps, I'm OK
> with it.
>
> But I think, before/after for x86 is needed as well.
> And why don't you consider '__always_inline__'? Simple inline is only
> a hint and
> guarantees nothing.
(Sorry for typo in your name. Call me Yuri next time.)
Adding Rasmus and George to CC
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Andrew Morton <akpm@linux-foundation.org> |
|---|---|
| Date | 2015-07-28 23:50 +0200 |
| Message-ID | <pRkV4-4Qy-7@gated-at.bofh.it> |
| In reply to | #1194681 |
On Wed, 29 Jul 2015 00:23:18 +0300 Yury <yury.norov@gmail.com> wrote: > But I think, before/after for x86 is needed as well. That would be nice. > And why don't you consider '__always_inline__'? Simple inline is only a > hint and > guarantees nothing. Yup. My x86_64 compiler just ignores the "inline". When I use __always_inline, find_bit.o's text goes from 776 bytes to 863. Hopefully we get something in return for that bloat! Also, if _find_next_bit() benefits from this then _find_next_bit_le() will presumably also benefit. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Alexey Klimov <klimov.linux@gmail.com> |
|---|---|
| Date | 2015-07-29 15:40 +0200 |
| Message-ID | <pRzKs-15P-61@gated-at.bofh.it> |
| In reply to | #1194698 |
On Вт., 2015-07-28 at 14:45 -0700, Andrew Morton wrote: > On Wed, 29 Jul 2015 00:23:18 +0300 Yury <yury.norov@gmail.com> wrote: > > > But I think, before/after for x86 is needed as well. > > That would be nice. > > > And why don't you consider '__always_inline__'? Simple inline is only a > > hint and > > guarantees nothing. > > Yup. My x86_64 compiler just ignores the "inline". When I use > __always_inline, find_bit.o's text goes from 776 bytes to 863. > Hopefully we get something in return for that bloat! On my x86_64 (core-i5 something, with disabled cpufreq) i got following numbers: find_next_zero_bit old new __always_inline 20 21 22 20 21 22 20 22 23 21 21 22 21 21 23 20 21 22 20 21 23 21 22 23 20 22 22 21 21 22 find_next_bit old new __always_inline 19 21 24 19 22 24 19 22 24 19 21 24 20 22 24 19 21 23 19 21 23 20 21 24 19 22 24 19 21 24 I will re-check on another machine. It's really interesting if __always_inline makes things better for aarch64 and worse for x86_64. It will be nice if someone will check it on x86_64 too. Best regards, Alexey Klimov. > Also, if _find_next_bit() benefits from this then _find_next_bit_le() > will presumably also benefit. > > -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Cassidy Burden <cburden@codeaurora.org> |
|---|---|
| Date | 2015-07-29 22:50 +0200 |
| Message-ID | <pRGsy-2ir-11@gated-at.bofh.it> |
| In reply to | #1195192 |
I changed the test module to now set the entire array to all 0/1s and only flip a few bits. There appears to be a performance benefit, but it's only 2-3% better (if that). If the main benefit of the original patch was to save space then inlining definitely doesn't seem worth the small gains in real use cases. find_next_zero_bit (us) old new inline 14440 17080 17086 4779 5181 5069 10844 12720 12746 9642 11312 11253 3858 3818 3668 10540 12349 12307 12470 14716 14697 5403 6002 5942 2282 1820 1418 13632 16056 15998 11048 13019 13030 6025 6790 6706 13255 15586 15605 3038 2744 2539 10353 12219 12239 10498 12251 12322 14767 17452 17454 12785 15048 15052 1655 1034 691 9924 11611 11558 find_next_bit (us) old new inline 8535 9936 9667 14666 17372 16880 2315 1799 1355 6578 9092 8806 6548 7558 7274 9448 11213 10821 3467 3497 3449 2719 3079 2911 6115 7989 7796 13582 16113 15643 4643 4946 4766 3406 3728 3536 7118 9045 8805 3174 3011 2701 13300 16780 16252 14285 16848 16330 11583 13669 13207 13063 15455 14989 12661 14955 14500 12068 14166 13790 On 7/29/2015 6:30 AM, Alexey Klimov wrote: > I will re-check on another machine. It's really interesting if > __always_inline makes things better for aarch64 and worse for x86_64. It > will be nice if someone will check it on x86_64 too. Very odd, this may be related to the other compiler optimizations Yuri mentioned? -- The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web