mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Vegard Nossum <vegard.nossum@gmail.com>
To: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>,
	Andrew Morton <akpm@linux-foundation.org>,
	Lai Jiangshan <laijs@cn.fujitsu.com>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	Peter Zijlstra <peterz@infradead.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 5/5 v3] vsprintf: unify the format decoding layer for its  3 users
Date: Thu, 5 Mar 2009 08:53:14 +0100	[thread overview]
Message-ID: <19f34abd0903042353i58c8e72eh33be515bf09a36f@mail.gmail.com> (raw)
In-Reply-To: <49af5f1b.1818d00a.209c.ffff9783@mx.google.com>

2009/3/5 Frederic Weisbecker <fweisbec@gmail.com>:
> An new optimization is making its way to ftrace. Its purpose is to
> make ftrace_printk() consuming less memory and be faster.
>
> Written by Lai Jiangshan, the approach is to delay the formatting
> job from tracing time to output time.
> Currently, a call to ftrace_printk will format the whole string and
> insert it into the ring buffer. Then you can read it on /debug/tracing/trace
> file.
>
> The new implementation stores the address of the format string and
> the binary parameters into the ring buffer, making the packet more compact
> and faster to insert.
> Later, when the user exports the traces, the format string is retrieved
> with the binary parameters and the formatting job is eventually done.
>
> The new implementation rewrites a lot of format decoding bits from
> vsnprintf() function, making now 3 differents functions to maintain
> in their duplicated parts of printf format decoding bits.
>
> Suggested by Ingo Molnar, this patch tries to factorize the most
> possible common bits from these functions.
> The real common part between them is the format decoding. Although
> they do somewhat similar jobs, their way to export or import the parameters
> is very different. Thus, only the decoding layer is extracted, unless you see
> other parts that could be worth factorized.
>

Just one small nit from me :-)

> @@ -726,18 +961,9 @@ static char *pointer(const char *fmt, char *buf, char *end, void *ptr, int field
>  int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
>  {
>        unsigned long long num;
> -       int base;
>        char *str, *end, c;
> -
> -       int flags;              /* flags to number() */
> -
> -       int field_width;        /* width of output field */
> -       int precision;          /* min. # of digits for integers; max
> -                                  number of chars for from string */
> -       int qualifier;          /* 'h', 'l', or 'L' for integer fields */
> -                               /* 'z' support added 23/7/1999 S.H.    */
> -                               /* 'z' changed to 'Z' --davidm 1/25/99 */
> -                               /* 't' added for ptrdiff_t */
> +       int read;
> +       struct printf_spec spec = {0};
>
>        /* Reject out-of-range values early.  Large positive sizes are
>           used for unknown buffer sizes. */
> @@ -758,184 +984,144 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
>                size = end - buf;
>        }
>
> -       for (; *fmt ; ++fmt) {
> -               if (*fmt != '%') {
> -                       if (str < end)
> -                               *str = *fmt;
> -                       ++str;
> -                       continue;
> -               }
> +       while (*fmt) {
> +               char *old_fmt = (char *)fmt;

This looks a bit strange. We can't ever change the format string, so
it doesn't make sense to try to use it as a non-const pointer anyway.
Why not make the variable "const char *" and drop the cast?

The same for another case.


Vegard

-- 
"The animistic metaphor of the bug that maliciously sneaked in while
the programmer was not looking is intellectually dishonest as it
disguises that the error is the programmer's own creation."
	-- E. W. Dijkstra, EWD1036

  reply	other threads:[~2009-03-05  7:53 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-05  4:50 Frederic Weisbecker
2009-03-05  7:53 ` Vegard Nossum [this message]
2009-03-05  9:34   ` [PATCH 5/5 v4] " Frederic Weisbecker
  -- strict thread matches above, loose matches on Subject: below --
2009-03-06 16:21 [PATCH 0/5 v3] Binary ftrace_printk Frederic Weisbecker
2009-03-06 16:21 ` [PATCH 5/5 v3] vsprintf: unify the format decoding layer for its 3 users Frederic Weisbecker
2009-02-28  9:13 [PATCH][RFC] " Ingo Molnar
2009-03-01  2:34 ` [PATCH 5/5 v3] " Frederic Weisbecker

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=19f34abd0903042353i58c8e72eh33be515bf09a36f@mail.gmail.com \
    --to=vegard.nossum@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=fweisbec@gmail.com \
    --cc=laijs@cn.fujitsu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=torvalds@linux-foundation.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

all inboxes | Powered by JetHome®