From: Tim Bird <tim.bird@am.sony.com>
To: Marc Andre Tanner <mat@brain-dump.org>
Cc: linux-embedded@vger.kernel.org
Subject: Re: [PATCH 7/7] printk: provide a filtering macro for printk
Date: Tue, 1 Sep 2009 16:24:27 -0700 [thread overview]
Message-ID: <4A9DAD2B.3080909@am.sony.com> (raw)
In-Reply-To: <1251844269-12394-8-git-send-email-mat@brain-dump.org>
Marc Andre Tanner wrote:
> The macro filters out printk messages based on a configurable verbosity
> level (CONFIG_PRINTK_VERBOSITY).
>
> Signed-off-by: Marc Andre Tanner <mat@brain-dump.org>
> ---
> include/linux/kernel.h | 24 ++++++++++++++++++++++++
> 1 files changed, 24 insertions(+), 0 deletions(-)
>
> diff --git a/include/linux/kernel.h b/include/linux/kernel.h
> index c2b3047..1f5d01f 100644
> --- a/include/linux/kernel.h
> +++ b/include/linux/kernel.h
> @@ -242,6 +242,30 @@ asmlinkage int printk(const char * fmt, ...)
> asmlinkage int printk_unfiltered(const char *fmt, ...)
> __attribute__ ((format (printf, 1, 2))) __cold;
>
> +#if defined(CONFIG_PRINTK_VERBOSITY) && CONFIG_PRINTK_VERBOSITY > 0
> +/*
> + * The idea here is to wrap the actual printk function with a macro which
> + * will filter out all messages above a certain verbosity level. Because
> + * the if condition evaluates to a constant expression the compiler will be
> + * able to eliminate it and the resulting kernel image will be smaller.
> + *
> + * The check with sizeof(void*) should make sure that we don't operate on
> + * pointers, which the compiler wouldn't be able to optimize out, but only
> + * on string constants.
> + */
> +
> +#include <linux/stringify.h>
> +
> +#define printk(fmt, ...) ({ \
> + if (sizeof(fmt) == sizeof(void *) || \
> + (((const char *)(fmt))[0] != '<' && CONFIG_PRINTK_VERBOSITY >= 4) || \
> + (((const char *)(fmt))[0] == '<' && \
> + ((const char *)(fmt))[1] <= *__stringify(CONFIG_PRINTK_VERBOSITY))) \
> + printk((fmt), ##__VA_ARGS__); \
> +})
> +
> +#endif /* CONFIG_PRINTK_VERBOSITY */
> +
> extern struct ratelimit_state printk_ratelimit_state;
> extern int printk_ratelimit(void);
> extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
Some places in the kernel break the message into pieces, like so:
printk(KERN_ERR, "Error: first part ");
...
printk(" more info for error.\n");
These parts would not be handled consistently under certain
conditions.
It would be confusing to see only part of the message,
but I don't know how often this construct is used. Maybe
another mechanism is needed to ensure that continuation
printk lines have the same log level as their start strings.
But, overall, very slick! It's nice to see a solution that doesn't
require changing all printks statements in the kernel.
-- Tim
=============================
Tim Bird
Architecture Group Chair, CE Linux Forum
Senior Staff Engineer, Sony Corporation of America
=============================
next prev parent reply other threads:[~2009-09-01 23:24 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-09-01 22:31 [RFC|PATCH] Compile time printk verbosity Marc Andre Tanner
2009-09-01 22:31 ` [PATCH 1/7] printk: introduce CONFIG_PRINTK_VERBOSITY Marc Andre Tanner
2009-09-01 22:31 ` [PATCH 2/7] printk: move printk to the end of the file Marc Andre Tanner
2009-09-01 22:31 ` [PATCH 3/7] printk: introduce printk_unfiltered as an alias to printk Marc Andre Tanner
2009-09-01 22:31 ` [PATCH 4/7] drivers: replace printk with printk_unfiltered Marc Andre Tanner
2009-09-01 22:31 ` [PATCH 5/7] drivers: make macro independent of printk's return value Marc Andre Tanner
2009-09-01 22:31 ` [PATCH 6/7] video/stk-webcam: change use of STK_ERROR Marc Andre Tanner
2009-09-01 22:31 ` [PATCH 7/7] printk: provide a filtering macro for printk Marc Andre Tanner
2009-09-01 23:24 ` Tim Bird [this message]
2009-09-01 23:32 ` H Hartley Sweeten
2009-09-02 13:09 ` Marc Andre Tanner
2009-09-02 17:05 ` Tim Bird
2009-09-02 17:31 ` Tim Bird
2009-09-02 18:22 ` H Hartley Sweeten
2009-09-02 18:22 ` H Hartley Sweeten
2009-09-04 14:05 ` Marc Andre Tanner
2009-09-10 9:22 ` Geert Uytterhoeven
2009-09-01 23:35 ` Jamie Lokier
2009-09-02 9:03 ` Marc Andre Tanner
2009-09-02 9:54 ` Marc Andre Tanner
2009-09-02 11:06 ` Jamie Lokier
2009-09-02 12:25 ` Bill Gatliff
2009-09-02 12:44 ` Marc Andre Tanner
2009-09-02 12:54 ` Mike Frysinger
2009-09-02 14:07 ` Marc Andre Tanner
2009-09-02 14:30 ` Jamie Lokier
2009-09-01 23:37 ` [RFC|PATCH] Compile time printk verbosity Mike Frysinger
2009-09-02 8:57 ` Marc Andre Tanner
2009-09-02 9:11 ` Mike Frysinger
2009-09-02 9:47 ` Marc Andre Tanner
2009-09-02 9:56 ` Mike Frysinger
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=4A9DAD2B.3080909@am.sony.com \
--to=tim.bird@am.sony.com \
--cc=linux-embedded@vger.kernel.org \
--cc=mat@brain-dump.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.