mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: linux-kernel@vger.kernel.org
Cc: Al Viro <viro@ZenIV.linux.org.uk>, Ingo Molnar <mingo@elte.hu>,
	"H. Peter Anvin" <hpa@zytor.com>, Dave Jones <davej@redhat.com>,
	Andi Kleen <andi@firstfloor.org>,
	Randy Dunlap <randy.dunlap@oracle.com>,
	Alan Cox <alan@lxorguk.ukuu.org.uk>
Subject: [PATCH] kernel.h: Update printk_once and add pr_<level>_once variants
Date: Fri, 22 May 2009 13:48:41 -0700	[thread overview]
Message-ID: <1243025321-16747-1-git-send-email-joe@perches.com> (raw)

Changed printk_once to use bool instead of int, with default set to false not 1.
This reduces data and produces slightly smaller object code.

Changed printk_once macro definitions to (fmt, ...) to match
other printk/pr_<level> definitions.

Signed-off-by: Joe Perches <joe@perches.com>
---
 include/linux/kernel.h |   57 ++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 51 insertions(+), 6 deletions(-)

diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 883cd44..343e505 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -246,12 +246,12 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
 /*
  * Print a one-time message (analogous to WARN_ONCE() et al):
  */
-#define printk_once(x...) ({			\
-	static int __print_once = 1;		\
+#define printk_once(fmt, ...) ({		\
+	static bool __print_once;		\
 						\
-	if (__print_once) {			\
-		__print_once = 0;		\
-		printk(x);			\
+	if (!__print_once) {			\
+		__print_once = true;		\
+		printk(fmt, ##__VA_ARGS__);	\
 	}					\
 })
 
@@ -269,7 +269,7 @@ static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies, \
 		{ return false; }
 
 /* No effect, but we still get type checking even in the !PRINTK case: */
-#define printk_once(x...) printk(x)
+#define printk_once(fmt, ...) printk(fmt, ##__VA_ARGS__)
 
 static inline void log_buf_kexec_setup(void)
 {
@@ -400,6 +400,51 @@ static inline char *pack_hex_byte(char *buf, u8 byte)
 	({ if (0) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); 0; })
 #endif
 
+/* pr_<level>_once variants */
+
+#define pr_emerg_once(fmt, ...) \
+	printk_once(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
+#define pr_alert_once(fmt, ...) \
+	printk_once(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
+#define pr_crit_once(fmt, ...) \
+	printk_once(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
+#define pr_err_once(fmt, ...) \
+	printk_once(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
+#define pr_warning_once(fmt, ...) \
+	printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
+#define pr_notice_once(fmt, ...) \
+	printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
+#define pr_info_once(fmt, ...) \
+	printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
+/* No pr_cont_once, use a local guard instead */
+
+/* pr_devel_once() should produce zero code unless DEBUG is defined */
+#ifdef DEBUG
+#define pr_devel_once(fmt, ...) \
+	printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
+#else
+#define pr_devel_once(fmt, ...) \
+	({ if (0) printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); 0; })
+#endif
+
+/* If you are writing a driver, please use dev_dbg instead */
+#if defined(DEBUG)
+#define pr_debug_once(fmt, ...) \
+	printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
+#elif defined(CONFIG_DYNAMIC_DEBUG)
+/* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */
+#define pr_debug_once(fmt, ...) ({			\
+	static bool __print_once;			\
+	if (!__print_once) {				\
+		__print_once = true;			\
+		dynamic_pr_debug(fmt, ##__VA_ARGS__);	\
+	}						\
+})
+#else
+#define pr_debug_once(fmt, ...) \
+	({ if (0) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); 0; })
+#endif
+
 /*
  * General tracing related utility functions - trace_printk(),
  * tracing_on/tracing_off and tracing_start()/tracing_stop
-- 
1.6.3.1.10.g659a0.dirty


                 reply	other threads:[~2009-05-22 20:48 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1243025321-16747-1-git-send-email-joe@perches.com \
    --to=joe@perches.com \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=andi@firstfloor.org \
    --cc=davej@redhat.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=randy.dunlap@oracle.com \
    --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®