From: Timo Teras <timo.teras@iki.fi>
To: Alexander Monakov <amonakov@ispras.ru>
Cc: musl@lists.openwall.com
Subject: Re: [musl] [PATCH] improve strerror speed
Date: Wed, 4 Mar 2020 11:17:31 +0200 [thread overview]
Message-ID: <20200304111731.642b8b58@vostro.wlan> (raw)
In-Reply-To: <alpine.LNX.2.20.13.2003041151460.17709@monopod.intra.ispras.ru>
On Wed, 4 Mar 2020 12:06:21 +0300 (MSK)
Alexander Monakov <amonakov@ispras.ru> wrote:
> Hi,
>
> On Tue, 3 Mar 2020, Timo Teräs wrote:
>
> > change the current O(n) lookup to O(1) based on the machinery
> > described in "How To Write Shared Libraries" (Appendix B).
>
> I'm curious about the background of this change, did the inefficiency
> came up in practice?
Yes, it's the openssl querying all possible strerrors:
https://github.com/openssl/openssl/blob/master/crypto/err/err.c#L181
That makes it up to valgrind --tool=callgrind to peak the strerror_l in
performance analysis on short running programs:
673,622 /data/aports/main/musl/src/musl-1.1.24/src/errno/strerror.c:strerror_l [/lib/ld-musl-x86_64.so.1]
This change completely removes strerror from there.
> > --- a/src/errno/__strerror.h
> > +++ b/src/errno/__strerror.h
> > @@ -1,8 +1,9 @@
> > -/* This file is sorted such that 'errors' which represent
> > exceptional
> > - * conditions under which a correct program may fail come first,
> > followed
> > - * by messages that indicate an incorrect program or system
> > failure. The
> > - * macro E() along with double-inclusion is used to ensure that
> > ordering
> > - * of the strings remains synchronized. */
> > +/* The first '0' mapping will be used for error codes that
> > + * are not explicitly mentioned here.
> > + * This file is included multiple times to generate struct
> > + * populate it's content and create a fast lookup index to it. */
>
> The last sentence seems to have typos ("a struct,", "its").
> I would write the comment like this:
>
> /* The first entry is a catch-all for codes not enumerated here.
> * This file is included multiple times to declare and define a
> structure
> * with messages, and then to define a lookup table translating error
> codes
> * to offsets of corresponding fields in the structure. */
>
> > + if (e < 0 || e >= sizeof(errmsgidx)/sizeof(errmsgidx[0]))
> > e = 0;
>
> I think usually in musl such range checks are written in an
> easier-to-optimize form that tests the argument in an unsigned type,
> e.g. like this:
>
> if ((size_t)e >= sizeof errmsgidx / sizeof *errmsgidx) e = 0;
Thanks, will update and resend.
Timo
next prev parent reply other threads:[~2020-03-04 9:17 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-03 21:33 Timo Teräs
2020-03-04 9:06 ` Alexander Monakov
2020-03-04 9:17 ` Timo Teras [this message]
2020-03-04 9:27 ` [musl] [PATCH v2] " Timo Teräs
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=20200304111731.642b8b58@vostro.wlan \
--to=timo.teras@iki.fi \
--cc=amonakov@ispras.ru \
--cc=musl@lists.openwall.com \
/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.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
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 NNTP newsgroup(s).