From: Johannes Weiner <hannes@saeurebad.de>
To: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Cc: Sam Ravnborg <sam@ravnborg.org>
Subject: [RFC] Sectionized printk data
Date: Mon, 04 Feb 2008 16:48:34 +0100 [thread overview]
Message-ID: <87zlugsox9.fsf@saeurebad.de> (raw)
Hi,
current approaches to have printk format strings in the corresponding
data section to the function they appear in look like the following (at
least what I have seen so far):
int __init some_function(void)
{
static char errmsg[] __initdata = "failure %s in %s\n";
[...]
printk(errmsg);
[...]
}
The attached patch allows something along the lines:
int __init some_function(void)
{
[...]
pr_init(KERN_WARNING "failure %s in %s\n", ...);
[...]
}
Another idea I had was to make printk a macro that figures out the
section of the surrounding function and then moves the data
automatically when it is a literal, but I couldn't find mechanisms that
allow this. Anyone of you got an idea?
What do you think in general?
Hannes
---
From: Johannes Weiner <hannes@saeurebad.de>
Sectionized printk wrappers
Introduce printk wrappers that place format string literals in init/exit
data sections.
Signed-off-by: Johannes Weiner <hannes@saeurebad.de>
---
The place for these wrappers is probably very wrong. Suggestions
welcome.
<Imagine diff-stat here>
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index ff356b2..6a1355d 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -192,7 +192,22 @@ static inline int __cold printk(const char *s, ...) { return 0; }
static inline int log_buf_get_len(void) { return 0; }
static inline int log_buf_read(int idx) { return 0; }
static inline int log_buf_copy(char *dest, int idx, int len) { return 0; }
-#endif
+
+/* Sectionized printk constant data */
+#include <linux/init.h>
+#define pr_section(sec, fmt, args...) ({ \
+ static const char __fmt[] sec = fmt; \
+ printk(__fmt, ## args); \
+})
+#define pr_init(fmt, args) pr_section(__initdata, fmt, ## args)
+#define pr_exit(fmt, args) pr_section(__exitdata, fmt, ## args)
+#define pr_devinit(fmt, args) pr_section(__devinitdata, fmt, ## args)
+#define pr_devexit(fmt, args) pr_section(__devexitdata, fmt, ## args)
+#define pr_cpuinit(fmt, args) pr_section(__cpuinitdata, fmt, ## args)
+#define pr_cpuexit(fmt, args) pr_section(__cpuexitdata, fmt, ## args)
+#define pr_meminit(fmt, args) pr_section(__meminitdata, fmt, ## args)
+#define pr_memexit(fmt, args) pr_section(__memexitdata, fmt, ## args)
+#endif /* CONFIG_PRINTK */
extern void __attribute__((format(printf, 1, 2)))
early_printk(const char *fmt, ...);
next reply other threads:[~2008-02-04 15:49 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-02-04 15:48 Johannes Weiner [this message]
2008-02-04 18:07 ` [RFC] Sectionized printk data Sam Ravnborg
2008-02-04 20:23 ` Johannes Weiner
2008-02-09 22:08 ` Jan Engelhardt
2008-02-09 23:54 ` Arnaldo Carvalho de Melo
2008-02-10 0:18 ` Jan Engelhardt
2008-02-10 0:27 ` Arnaldo Carvalho de Melo
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=87zlugsox9.fsf@saeurebad.de \
--to=hannes@saeurebad.de \
--cc=linux-kernel@vger.kernel.org \
--cc=sam@ravnborg.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.