All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC] Sectionized printk data
@ 2008-02-04 15:48 Johannes Weiner
  2008-02-04 18:07 ` Sam Ravnborg
  0 siblings, 1 reply; 7+ messages in thread
From: Johannes Weiner @ 2008-02-04 15:48 UTC (permalink / raw)
  To: Linux Kernel Mailing List; +Cc: Sam Ravnborg

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, ...);

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2008-02-10  0:27 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-02-04 15:48 [RFC] Sectionized printk data Johannes Weiner
2008-02-04 18:07 ` 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

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.