From: Rasmus Villemoes <linux@rasmusvillemoes.dk>
To: "Uwe Kleine-König" <uwe@kleine-koenig.org>,
"Andy Shevchenko" <andy.shevchenko@gmail.com>
Cc: Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>,
Petr Mladek <pmladek@suse.com>,
Andrew Morton <akpm@linux-foundation.org>,
Jani Nikula <jani.nikula@linux.intel.com>,
Joe Perches <joe@perches.com>, Juergen Gross <jgross@suse.com>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] printf: add support for printing symbolic error codes
Date: Thu, 5 Sep 2019 13:40:23 +0200 [thread overview]
Message-ID: <30ffb8a4-1fdb-5260-f6e5-57ea78a85174@rasmusvillemoes.dk> (raw)
In-Reply-To: <bf898c97-5f72-93c4-e6b7-be81c6903b50@kleine-koenig.org>
On 04/09/2019 18.28, Uwe Kleine-König wrote:
> On 9/4/19 6:19 PM, Andy Shevchenko wrote:
>> On Sat, Aug 31, 2019 at 12:48 AM Rasmus Villemoes
>> <linux@rasmusvillemoes.dk> wrote:
>>>
>>
>>> +/*
>>> + * Ensure these tables to not accidentally become gigantic if some
>>> + * huge errno makes it in. On most architectures, the first table will
>>> + * only have about 140 entries, but mips and parisc have more sparsely
>>> + * allocated errnos (with EHWPOISON = 257 on parisc, and EDQUOT = 1133
>>> + * on mips), so this wastes a bit of space on those - though we
>>> + * special case the EDQUOT case.
>>> + */
>>> +#define E(err) [err + BUILD_BUG_ON_ZERO(err <= 0 || err > 300)] = #err
>>
>> Hmm... Perhaps better to define the upper boundary with something like
>>
>> #define __E_POSIX_UPPER_BOUNDARY 300 // name sucks, I know
>>
>>> +#define E(err) [err - 512 + BUILD_BUG_ON_ZERO(err < 512 || err > 550)] = #err
>>
>> Similar to 550?
>
> I'd not add "POSIX" in the name. Given that the arrays are called
> codes_0 and codes_512 I don't think using plain numbers hurts much and
> choosing a good name is hard, so I suggest to keep the explicit numbers.
I agree, adding random macro names for these essentially arbitrary (and
one-time use) numbers doesn't make sense. Remember that the sizing of
the arrays is done automatically by gcc. I suppose an alternative is to
drop the BUILD_BUG_ON_ZEROs from the E() defines and then just have some
static_assert(ARRAY_SIZE(codes_0) < 300) - but the advantage of the
above is that one gets to know _which_ E* has a huge value (that is how
I caught EDQUOT on MIPS).
>>> +const char *errcode(int err)
>>> +{
>>> + /* Might as well accept both -EIO and EIO. */
>>> + if (err < 0)
>>> + err = -err;
>>> + if (err <= 0) /* INT_MIN or 0 */
>>> + return NULL;
>>> + if (err < ARRAY_SIZE(codes_0))
>>> + return codes_0[err];
>>> + if (err >= 512 && err - 512 < ARRAY_SIZE(codes_512))
>>> + return codes_512[err - 512];
>>> + /* But why? */
>>> + if (IS_ENABLED(CONFIG_MIPS) && err == EDQUOT) /* 1133 */
>>> + return "EDQUOT";
>>
>> Another possibility is to initialize the errors at run time with radix tree.
>
> The idea was to save space. But when using a radix tree this has
> overhead compared to the lists here, and you still need a map for
> error-code -> error-name to initialize the radix tree. Also a lookup is
> slower than with the idea implemented here. So it's bigger, slower and
> more complicated ... I don't think we should do that.
Yes, a radix tree is unlikely to end up saving space at all.
Moreover, any initialization at run-time means there's some window where
we don't have them, and printk() should work as early as possible (and I
really don't want to add any kind of synchronization "are we initialized
yet", just see what that did to the pointer hashing). So I'll stick with
the arrays.
>>> @@ -2111,6 +2112,31 @@ static noinline_for_stack
>>> char *pointer(const char *fmt, char *buf, char *end, void *ptr,
>>> struct printf_spec spec)
>>> {
>>> + /* %px means the user explicitly wanted the pointer formatted as a hex value. */
>>> + if (*fmt == 'x')
>>> + return pointer_string(buf, end, ptr, spec);
>>
>> But instead of breaking switch case apart can we use...
>>
>>> +
>>> + /* If it's an ERR_PTR, try to print its symbolic representation. */
>>> + if (IS_ERR(ptr)) {
>>
>> ... if (IS_ERR() && *fmt != 'x') {
>> here?
This makes sense, I think I'll do it that way. Thanks.
Rasmus
next prev parent reply other threads:[~2019-09-05 11:40 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-30 21:46 [PATCH] printf: add support for printing symbolic error codes Rasmus Villemoes
2019-08-30 21:53 ` Joe Perches
2019-08-30 22:03 ` Rasmus Villemoes
2019-08-30 22:21 ` Joe Perches
2019-08-30 22:50 ` Rasmus Villemoes
2019-09-02 9:07 ` David Laight
2019-08-31 9:38 ` kbuild test robot
2019-09-02 15:29 ` Uwe Kleine-König
2019-09-04 9:13 ` Rasmus Villemoes
2019-09-04 9:21 ` Uwe Kleine-König
2019-09-04 16:19 ` Andy Shevchenko
2019-09-04 16:28 ` Uwe Kleine-König
2019-09-05 11:40 ` Rasmus Villemoes [this message]
2019-09-09 20:38 ` [PATCH v2] " Rasmus Villemoes
2019-09-10 15:26 ` Andy Shevchenko
2019-09-11 0:15 ` Joe Perches
2019-09-11 6:43 ` Rasmus Villemoes
2019-09-11 9:37 ` Uwe Kleine-König
2019-09-11 10:14 ` Rasmus Villemoes
2019-09-15 9:43 ` Pavel Machek
2019-09-16 12:23 ` Uwe Kleine-König
2019-09-16 13:23 ` Rasmus Villemoes
2019-09-16 13:36 ` Uwe Kleine-König
2019-09-17 6:59 ` [PATCH v3] " Rasmus Villemoes
2019-09-25 14:36 ` Petr Mladek
2019-09-29 20:09 ` Rasmus Villemoes
2019-10-02 8:34 ` Petr Mladek
2019-10-05 21:48 ` Andrew Morton
2019-10-11 13:36 ` [PATCH v4 0/1] printf: add support for printing symbolic error names Rasmus Villemoes
2019-10-11 13:36 ` [PATCH v4 1/1] " Rasmus Villemoes
2019-10-14 5:51 ` Uwe Kleine-König
2019-10-14 13:02 ` Petr Mladek
2019-10-14 13:10 ` Andy Shevchenko
2019-10-15 12:17 ` Rasmus Villemoes
2019-10-15 13:44 ` David Laight
2019-10-15 19:07 ` [PATCH v5] " Rasmus Villemoes
2019-10-16 13:49 ` Andy Shevchenko
2019-10-16 14:52 ` Petr Mladek
2019-10-16 16:31 ` Andy Shevchenko
2019-10-17 15:02 ` Petr Mladek
2019-11-26 14:04 ` [PATCH v4 0/1] " Geert Uytterhoeven
2019-11-27 8:54 ` Petr Mladek
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=30ffb8a4-1fdb-5260-f6e5-57ea78a85174@rasmusvillemoes.dk \
--to=linux@rasmusvillemoes.dk \
--cc=akpm@linux-foundation.org \
--cc=andy.shevchenko@gmail.com \
--cc=jani.nikula@linux.intel.com \
--cc=jgross@suse.com \
--cc=joe@perches.com \
--cc=linux-kernel@vger.kernel.org \
--cc=pmladek@suse.com \
--cc=sergey.senozhatsky.work@gmail.com \
--cc=uwe@kleine-koenig.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 NNTP newsgroup(s).