From: Marc Andre Tanner <mat@brain-dump.org>
To: linux-embedded@vger.kernel.org
Cc: mat@brain-dump.org
Subject: [PATCH 5/5] printk: provide a filtering macro for printk
Date: Wed, 2 Sep 2009 16:25:05 +0200 [thread overview]
Message-ID: <1251901505-4313-6-git-send-email-mat@brain-dump.org> (raw)
In-Reply-To: <1251901505-4313-1-git-send-email-mat@brain-dump.org>
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 | 23 +++++++++++++++++++++++
1 files changed, 23 insertions(+), 0 deletions(-)
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index c2b3047..1ecc338 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -242,6 +242,29 @@ 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.
+ */
+
+#include <linux/stringify.h>
+
+#define PRINTK_FILTER(fmt) ( \
+ (((const char *)(fmt))[0] != '<' && CONFIG_PRINTK_VERBOSITY >= 4) || \
+ (((const char *)(fmt))[0] == '<' && \
+ ((const char *)(fmt))[1] <= *__stringify(CONFIG_PRINTK_VERBOSITY)) \
+)
+
+#define printk(fmt, ...) ( \
+ (!__builtin_constant_p(PRINTK_FILTER((fmt))) || PRINTK_FILTER((fmt))) ? \
+ printk((fmt), ##__VA_ARGS__) : 0 \
+)
+
+#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,
--
1.6.3.3
next prev parent reply other threads:[~2009-09-02 14:25 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-09-02 14:25 [RFC|PATCHv2] Compile time printk verbosity Marc Andre Tanner
2009-09-02 14:25 ` [PATCH 1/5] printk: introduce CONFIG_PRINTK_VERBOSITY Marc Andre Tanner
2009-09-02 16:44 ` Marco Stornelli
2009-09-02 17:32 ` Marc Andre Tanner
2009-09-02 14:25 ` [PATCH 2/5] printk: move printk to the end of the file Marc Andre Tanner
2009-09-02 14:25 ` [PATCH 3/5] printk: introduce printk_unfiltered as an alias to printk Marc Andre Tanner
2009-09-02 14:25 ` [PATCH 4/5] char/mem: replace printk with printk_unfiltered Marc Andre Tanner
2009-09-02 14:25 ` Marc Andre Tanner [this message]
2009-09-02 16:44 ` [PATCH 5/5] printk: provide a filtering macro for printk Marco Stornelli
2009-09-02 17:27 ` Marc Andre Tanner
2009-09-03 6:29 ` Marco Stornelli
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=1251901505-4313-6-git-send-email-mat@brain-dump.org \
--to=mat@brain-dump.org \
--cc=linux-embedded@vger.kernel.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).