From: Noah Goldstein <goldstein.w.n@gmail.com>
To: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Cc: Paul Eggert <eggert@cs.ucla.edu>,
Florian Weimer <fweimer@redhat.com>,
crrodriguez@opensuse.org,
Adhemerval Zanella via Libc-alpha <libc-alpha@sourceware.org>
Subject: Re: [PATCH 1/4] Remove architecture specific sched_cpucount optimizations
Date: Thu, 6 May 2021 14:34:44 -0400 [thread overview]
Message-ID: <CAFUsyfKh67fogjBHy55-B825ZwxNitdKqCUYgSknt0zB5Y253g@mail.gmail.com> (raw)
In-Reply-To: <fccf5cb7-4cea-0bda-158c-9d417355dafd@linaro.org>
On Thu, May 6, 2021 at 8:22 AM Adhemerval Zanella
<adhemerval.zanella@linaro.org> wrote:
>
>
>
> On 05/05/2021 16:52, Noah Goldstein via Libc-alpha wrote:
> > On Wed, May 5, 2021 at 12:32 PM Paul Eggert <eggert@cs.ucla.edu> wrote:
> >>
> >> On 5/5/21 10:28 AM, Florian Weimer via Libc-alpha wrote:
> >>>> diff --git a/posix/sched_cpucount.c b/posix/sched_cpucount.c
> >>>> index b0ca4ea7bc..529286e777 100644
> >>>> --- a/posix/sched_cpucount.c
> >>>> +++ b/posix/sched_cpucount.c
> >>>> @@ -22,31 +22,11 @@ int
> >>>> __sched_cpucount (size_t setsize, const cpu_set_t *setp)
> >>>> {
> >>>> int s = 0;
> >>>> + for (int i = 0; i < setsize / sizeof (__cpu_mask); i++)
> >>>> {
> >>>> + __cpu_mask si = setp->__bits[i];
> >>>> + /* Clear the least significant bit set. */
> >>>> + for (; si != 0; si &= si - 1, s++);
> >>>> }
> >>>> -
> >>>> return s;
> >>>> }
> >>> Why “si”? It think si &= si - 1 clears the*most* significant bit in
> >>> si. If you agree, please update the comment.
> >>
> >> Better yet, define a static function 'popcount' that uses Kernighan's
> >> trick and call that function. As things stand it's not obvious what the
> >> code is doing, regardless of which bit it's clearing. The function's
> >> comment should explain why it's not using __builtin_popcount.
> >
> > It looks to me like GCC is still having a bit of trouble with the new
> > implementation. With skylake as a target it seems to be throwing
> > in a cmovcc in the outer loop:
> >
> > https://godbolt.org/z/ocn1KWGPx
> >
>
> It seems that come from using a signed int as the counter, I got a slight
> better version using unsigned: https://godbolt.org/z/4MrMq1zKb
>
> It is not as better as the builtin, but do we really need that
> micro-optimization in this specific implementation? This is exactly what
> added the current complexity and using a open-coded popcount implementation
> is slight better on architectures that do not provided such instruction
> (where builtin_popcount will issue a call to __popcountsi2 and gcc seems
> to aiming for open code such scenarios [1]).
>
> In any case I would go for simplicity (and the builtin requires know the
> underlying type size, which requires the ugly size of check to call the
> correct one).
>
> [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92135
I agree. Definetly not opposed to the patch.
next prev parent reply other threads:[~2021-05-06 18:34 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-29 18:25 Adhemerval Zanella
2021-03-29 18:25 ` [PATCH 2/4] linux: Use sched_getaffinity for __get_nprocs (BZ #27645) Adhemerval Zanella
2021-04-27 15:38 ` Florian Weimer
2021-03-29 18:25 ` [PATCH 3/4] linux: Use /sys/devices/system/cpu/possible on __get_nprocs_conf Adhemerval Zanella
2021-05-05 16:53 ` Adhemerval Zanella
2021-05-05 17:54 ` Florian Weimer
2021-05-05 18:06 ` Florian Weimer
2021-05-06 13:03 ` Adhemerval Zanella
2021-05-06 13:51 ` Florian Weimer
2021-05-06 20:07 ` Adhemerval Zanella
2021-05-07 11:07 ` Florian Weimer
2021-05-07 12:43 ` Adhemerval Zanella
2021-05-06 13:17 ` Adhemerval Zanella
2021-03-29 18:25 ` [PATCH 4/4] linux: Remove /proc/cpuinfo fallback on alpha and sparc Adhemerval Zanella
2021-05-05 16:53 ` Adhemerval Zanella
2021-05-05 16:52 ` [PATCH 1/4] Remove architecture specific sched_cpucount optimizations Adhemerval Zanella
2021-05-05 17:28 ` Florian Weimer
2021-05-05 18:25 ` Paul Eggert
2021-05-05 19:52 ` Noah Goldstein
2021-05-06 12:22 ` Adhemerval Zanella
2021-05-06 18:34 ` Noah Goldstein [this message]
2021-05-06 13:33 ` Adhemerval Zanella
2021-05-06 13:43 ` Florian Weimer
2021-05-06 16:16 ` Adhemerval Zanella
2021-05-06 16:42 ` Florian Weimer
2021-05-06 16:54 ` Adhemerval Zanella
2021-05-06 17:12 ` Paul Eggert
2021-05-06 17:51 ` Adhemerval Zanella
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAFUsyfKh67fogjBHy55-B825ZwxNitdKqCUYgSknt0zB5Y253g@mail.gmail.com \
--to=goldstein.w.n@gmail.com \
--cc=adhemerval.zanella@linaro.org \
--cc=crrodriguez@opensuse.org \
--cc=eggert@cs.ucla.edu \
--cc=fweimer@redhat.com \
--cc=libc-alpha@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).