The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Cc: akpm@linux-foundation.org, geert@linux-m68k.org, jkosina@suse.cz,
	viro@zeniv.linux.org.uk, davem@davemloft.net,
	keescook@chromium.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] lib/vsprintf: add %pT[C012] format specifier
Date: Mon, 30 Dec 2013 08:55:45 -0800	[thread overview]
Message-ID: <1388422545.26796.36.camel@joe-AO722> (raw)
In-Reply-To: <201312292113.FIJ60946.tFOVOJOHLQSFFM@I-love.SAKURA.ne.jp>

On Sun, 2013-12-29 at 21:13 +0900, Tetsuo Handa wrote:
> Tetsuo Handa wrote:
> > Joe Perches wrote:
> > > On Sat, 2013-12-28 at 12:08 -0800, Andrew Morton wrote:
> > > > On Sat, 28 Dec 2013 11:53:25 -0800 Joe Perches <joe@perches.com> wrote:
> > > > 
> > > > > > > #define PRINTK_PID      "\002"
> > > > > > > #define PRINTK_TASK_ID  "\003"  /* "comm:pid" */
> > > 
> > > > > > >
> > > > > > >         printk(PRINTK_TASK_ID ": hair on fire\n");
> > > > > > >
> > > > > > > It's certainly compact.  I doubt if there's any existing code which
> > > > > > > deliberately prints control chars?
> > 
> > What about using bytes from \x7F to \xFF ?
> 
> Here is a draft patch. With this approach, we can embed whatever variables
> vsnprintf() can access (not only current thread's attributes seen from init and
> current namespace but also other variables like current time) into the format
> string without passing corresponding argument.
> 
> Is this approach acceptable? (Of course, I'll add lines like
> 
>   #define PRINT_FORMAT    "\x7F"
>   #define PRINT_TASK_COMM "\x80"
>   #define PRINT_TASK_PID  "\x81"
> 
> for final version.) What variables (e.g. current->comm, current->pid,
> task_tgid_vnr(current)) do we want to pass using builtin tokens?
[]
> The vast majority of ->comm accesses are accessing current->comm, for
> debug reasons. I'm counting 350-odd sites. At all these sites it's
> pointless passing `current' to the printk function at all!

I get:

$ grep-2.5.4 -rP --include=*.[ch] -oh \
  "\b(?:printk|[a-z_]+_(?:printk|emerg|alert|crit|err|warn|notice|info|debug|dbg))[^;]*\bcurrent->[\w_]+" * | \
  grep -P -oh "\bcurrent->[\w_]+"| sort | uniq -c | sort -rn
    380 current->pid
    267 current->comm
     34 current->mm
     25 current->thread
     17 current->journal_info
      8 current->flags
      7 current->tgid
      5 current->active_mm
      2 current->sas_ss_sp
      2 current->addr_limit
      1 current->uid
      1 current->signal
      1 current->sas_ss_size
      1 current->ret_stack
      1 current->memcg_batch
      1 current->kernel_stack_page
      1 current->group_leader
      1 current->exit_code
      1 current->cred
      1 current->blocked

> This patch introduces a set of vsprintf tokens for embedding globally visible
> arguments into the format string, so that we can reduce text size a bit (and
> in the future make reading of task_struct->comm consistent) by stop generating
> the code to pass an argument which the callee already has access to, with an
> assumption that we can avoid using bytes >= 0x7F within the format string.
> 
> Some examples for converting direct ->comm users are shown below.
> 
>   pr_info("comm=%s\n", current->comm); => pr_info("comm=\x80\n");
>   pr_info("pid=%d\n", current->pid);   => pr_info("pid=\x81\n");
>   pr_info("%s(%d)\n", current->comm, current->pid); => pr_info("\x80(\x81)\n");
>   pr_info("[%-6.6s]\n", current->comm); => pr_info("\x7F-6.6\x80\n");

I too prefer using the #define CURRENT_<FOO> string approach
rather than direct embedding of string.

	pr_info("comm=" CURRENT_COMM "\n");

Also I prefer using ASCII SUB (26 \x1a \032 ^z) or maybe
PU1 - 145 or PU2 - 146, as an initiator byte as it takes
up much less of the control word space instead of using
multiple values like \x80, \x81, \x82, etc.  Using an
initiator byte seems more extensible too.

http://en.wikipedia.org/wiki/C0_and_C1_control_codes



  reply	other threads:[~2013-12-30 16:55 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-25 12:37 [PATCH] lib/vsprintf: add %pT[C012] format specifier Tetsuo Handa
2013-12-26  8:43 ` Joe Perches
2013-12-27 23:02 ` Andrew Morton
2013-12-28  3:43   ` Tetsuo Handa
2013-12-28 18:57     ` Geert Uytterhoeven
2013-12-28 19:25       ` Andrew Morton
2013-12-28 19:25         ` Geert Uytterhoeven
2013-12-28 19:53           ` Joe Perches
2013-12-28 20:08             ` Andrew Morton
2013-12-28 20:24               ` Joe Perches
2013-12-29  0:32                 ` Tetsuo Handa
2013-12-29  2:07                   ` Joe Perches
2013-12-29 12:13                     ` Tetsuo Handa
2013-12-30 16:55                       ` Joe Perches [this message]
2013-12-31  6:53                         ` Tetsuo Handa
2013-12-31 16:24                           ` Joe Perches
2014-01-01  5:34                             ` Tetsuo Handa
2014-01-01  5:49                               ` Joe Perches
2014-01-01 10:02                                 ` Tetsuo Handa
2014-01-02  1:33                                   ` Joe Perches
2014-01-02  4:49                                     ` Tetsuo Handa
2014-01-03 17:08                                       ` Kees Cook
2014-01-03 17:39                                         ` Joe Perches
2014-01-03 17:49                                           ` Kees Cook
2014-01-04  2:26                                             ` Tetsuo Handa
2014-01-05  3:15                                               ` Tetsuo Handa
2014-01-05 18:09                                                 ` Joe Perches
2014-01-06 14:00                                                   ` Tetsuo Handa
2014-01-06 17:34                                                     ` Joe Perches
2014-01-06 21:41                                                       ` Tetsuo Handa
2014-01-06 22:25                                                         ` Joe Perches
2014-01-07  0:16                                                           ` Pavel Machek
2014-01-07  1:03                                                             ` Joe Perches
2014-01-07  8:37                                                               ` Pavel Machek
2014-01-07 17:34                                                                 ` Joe Perches
2014-01-07 17:56                                                                   ` Pavel Machek
2014-01-07 18:28                                                                     ` Geert Uytterhoeven
2014-01-08 14:19                                                                     ` Tetsuo Handa
2014-01-08 14:46                                                                       ` Pavel Machek
2014-01-06 21:34                                                     ` Pavel Machek
2014-01-05 22:27                                                 ` Pavel Machek
2014-01-06 14:02                                                   ` Tetsuo Handa
2014-01-10 13:15                                                     ` Tetsuo Handa
2014-01-02  1:38                                   ` Joe Perches
2014-01-02 11:51               ` Pavel Machek

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=1388422545.26796.36.camel@joe-AO722 \
    --to=joe@perches.com \
    --cc=akpm@linux-foundation.org \
    --cc=davem@davemloft.net \
    --cc=geert@linux-m68k.org \
    --cc=jkosina@suse.cz \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=penguin-kernel@I-love.SAKURA.ne.jp \
    --cc=viro@zeniv.linux.org.uk \
    /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