public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: "H.J. Lu" <hjl.tools@gmail.com>
To: Florian Weimer <fw@deneb-ng.enyo.de>
Cc: "H.J. Lu via Libc-alpha" <libc-alpha@sourceware.org>
Subject: Re: [PATCH] elf: Replace memcmp with __memcmpeq for variable size
Date: Sun, 6 Feb 2022 16:20:34 -0800	[thread overview]
Message-ID: <CAMe9rOrFXL-v38HU3eAk3VMayqrR5oY33w3FpT+j1gL9G0yQow@mail.gmail.com> (raw)
In-Reply-To: <874k5b3afx.fsf@mid.deneb.enyo.de>

On Sun, Feb 6, 2022 at 2:19 PM Florian Weimer <fw@deneb-ng.enyo.de> wrote:
>
> * H. J. Lu via Libc-alpha:
>
> > diff --git a/elf/dl-cache.c b/elf/dl-cache.c
> > index 88bf78ad7c..8574d4ded1 100644
> > --- a/elf/dl-cache.c
> > +++ b/elf/dl-cache.c
> > @@ -72,7 +72,7 @@ glibc_hwcaps_compare (uint32_t left_index, struct dl_hwcaps_priority *right)
> >      to_compare = left_name_length;
> >    else
> >      to_compare = right->name_length;
> > -  int cmp = memcmp (left_name, right->name, to_compare);
> > +  int cmp = memcmp_eq (left_name, right->name, to_compare);
> >    if (cmp != 0)
> >      return cmp;
> >    if (left_name_length < right->name_length)
>
> This change is not correct.

Fixed.

> The x86-specific <memcmp-eq.h> optimization probably applies to other
> targets as well.  I also do not quite see where the performance

It is useful only if __memcmpeq isn't an alias of memcmp.  I certainly
don't mind moving x86-64 <memcmp-eq.h> to generic.

> benefits come from.  None of the changed spots look particularly hot
> to me.

These are noises.  Here are the new data:

The cycles to run "elf/tst-relsort1 --direct" which calls __memcmpeq
24 times in ld.so:

Before:

     62704:
     62704: runtime linker statistics:
     62704:   total startup time in dynamic loader: 130771 cycles
     62704:             time needed for relocation: 32153 cycles (24.5%)
     62704:                  number of relocations: 97
     62704:       number of relocations from cache: 3
     62704:         number of relative relocations: 1347
     62704:            time needed to load objects: 43704 cycles (33.4%)
     62704:
     62704: runtime linker statistics:
     62704:            final number of relocations: 131
     62704: final number of relocations from cache: 3

After:

     62705:
     62705: runtime linker statistics:
     62705:   total startup time in dynamic loader: 117103 cycles
     62705:             time needed for relocation: 28327 cycles (24.1%)
     62705:                  number of relocations: 97
     62705:       number of relocations from cache: 3
     62705:         number of relative relocations: 1347
     62705:            time needed to load objects: 39550 cycles (33.7%)
     62705:
     62705: runtime linker statistics:
     62705:            final number of relocations: 131
     62705: final number of relocations from cache: 3

These numbers change for each run.  __memcmpeq has the lower
cycles.

> And I thought the assumption was that GCC would perform this optimization?

Yes, but it will take a while to implement it in GCC.

-- 
H.J.

  reply	other threads:[~2022-02-07  0:21 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-06 21:09 H.J. Lu
2022-02-06 22:19 ` Florian Weimer
2022-02-07  0:20   ` H.J. Lu [this message]
2022-02-07 10:40     ` Florian Weimer
2022-02-07 13:13       ` H.J. Lu
2022-02-07 13:19         ` Florian Weimer
2022-02-07 13:27           ` H.J. Lu
2022-02-07 13:30             ` Adhemerval Zanella
2022-02-07 14:00               ` H.J. Lu
2022-02-07 20:35 ` Joseph Myers
2022-02-08 22:30 Wilco Dijkstra
2022-02-08 23:00 ` Adhemerval Zanella
2022-02-09  0:07   ` Noah Goldstein
2022-02-09  1:42     ` Wilco Dijkstra

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=CAMe9rOrFXL-v38HU3eAk3VMayqrR5oY33w3FpT+j1gL9G0yQow@mail.gmail.com \
    --to=hjl.tools@gmail.com \
    --cc=fw@deneb-ng.enyo.de \
    --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).