From: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
To: joe@perches.com
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: Wed, 1 Jan 2014 14:34:03 +0900 [thread overview]
Message-ID: <201401011434.GAF34360.FFQOVtFOHJSMLO@I-love.SAKURA.ne.jp> (raw)
In-Reply-To: <1388507067.2259.24.camel@joe-AO722>
Joe Perches wrote:
> > Please describe your format and rules (e.g. what byte starts a built-in token;
> > what bytes are used for representing variable name, what separates flags, field
> > width and precision options from variable name if these options are specified,
> > what byte terminates a built-in token) using examples below.
> >
> > pr_info("%s(%d)\n", current->comm, current->pid);
>
> pr_info(CURRENT_COMM "(" CURRENT_PID ")\n");
>
> > pr_info("[%-6.6s]\n", current->comm);
>
> I think using formatting controls for field widths and
> such shouldn't be supported but if it is, then using yet
> another macro form like below is possible
>
> either:
> #define CURRENT_COMM_FORMAT(fmt) \
> CURRENT_SUB fmt "2"
> or
> #define CURRENT_COMM_FORMATTED(fmt) \
> CURRENT_SUB __stringify(fmt) "2"
>
> So maybe,
> pr_info(CURRENT_COMM_FORMAT("-6.6") "\n");
> or
> pr_info(CURRENT_COMM_FORMATTED(-6.6) "\n");
>
> depending on taste could work.
>
> "2" would need changing to something like "t2" so any
> leading format directives like field width and precision
> could be done properly.
>
> In other words: using a separating byte may be necessary if
> some formatting directive support is required.
>
I think we want formatting directive support because we have users shown below.
fs/afs/internal.h: printk("[%-6.6s] "FMT"\n", current->comm ,##__VA_ARGS__)
fs/cachefiles/internal.h: printk(KERN_DEBUG "[%-6.6s] "FMT"\n", current->comm, ##__VA_ARGS__)
fs/fscache/internal.h: printk(KERN_DEBUG "[%-6.6s] "FMT"\n", current->comm, ##__VA_ARGS__)
Though I think that
> This wouldn't/couldn't work with formats where field length
> is specified via "*" with a separate int.
>
> Perhaps that's a good enough reason not to support using
> format directives.
we don't need to support complete set like '*'.
> The goal of a single leading char is simply resource
> economy. Using fewer chars from the available pool may be
> better than using more. Using a couple more bytes in the
> format string doesn't seem an excessive overhead.
Then, I think we can choose as
Byte for beginning of built-in token:
'\xFF'
Bytes for specifying flags, field width, precision options:
'0' to '9', '-' and '.'
Bytes for specifying built-in variable:
All but '\xFF', '0' to '9', '-', '.', '%' and '\x00'
and define 241 built-in variables, while using only single leading char (i.e.
'\xFF') from the available pool (all but '%' and '\x00').
#define EMBED_FORMAT "\xFF"
#define EMBED_CURRENT_COMM "\xFF" "\x80"
#define EMBED_CURRENT_PID "\xFF" "\x81"
pr_info("%s(%d)\n", current->comm, current->pid);
=> pr_info(EMBED_CURRENT_COMM "(" EMBED_CURRENT_PID ")\n");
pr_info("[%-6.6s]\n", current->comm);
=> pr_info(EMBED_FORMAT "-6.6" EMBED_CURRENT_COMM "\n");
Since I assume that 241 built-in variables are sufficient, I'm laying
"Bytes for specifying built-in variable" under obligation of also acting as
"Bytes for ending of built-in token".
This choice works because once format_decode() encounters '\xFF' byte, it can
continue reading until it encounters one of "Bytes for ending of built-in
token", and split them into "Bytes for specifying flags, field width, precision
options" and "Bytes for specifying built-in variable" without any fuzziness.
\xFF\x80(\xFF\x80)\n
^ ^ ^ ^
| | | +- Decoder interprets as variable name and understands that this
| | | is a trailing byte.
| | +----- Decoder interprets as a leading byte because decoder sees
| | this byte for the first time.
| +---------- Decoder interprets as variable name and understands that this
| is a trailing byte.
+-------------- Decoder interprets as a leading byte because decoder sees
this byte for the first time.
[\xFF-6.6\xFF\x80]\n
^ ^ ^ ^
| | | +- Decoder interprets as variable name and understands that
| | | this is a trailing byte.
| | +----- Decoder ignores this byte because decoder already saw
| | this byte.
| +--------- Decoder interprets as format specifier.
+------------- Decoder interprets as leading byte because decoder sees
this byte for the first time.
This choice (i.e. reserve only '\xFF') is more resource economy than my
previous choice (i.e. reserve '\x7F' to '\xFF') at the cost of wasting only
one byte compared to my previous choice.
next prev parent reply other threads:[~2014-01-01 5:35 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-25 12:37 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
2013-12-31 6:53 ` Tetsuo Handa
2013-12-31 16:24 ` Joe Perches
2014-01-01 5:34 ` Tetsuo Handa [this message]
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=201401011434.GAF34360.FFQOVtFOHJSMLO@I-love.SAKURA.ne.jp \
--to=penguin-kernel@i-love.sakura.ne.jp \
--cc=akpm@linux-foundation.org \
--cc=davem@davemloft.net \
--cc=geert@linux-m68k.org \
--cc=jkosina@suse.cz \
--cc=joe@perches.com \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--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
all inboxes | Powered by JetHome®