lkml.org 
[lkml]   [2008]   [Feb]   [4]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[RFC] Sectionized printk data
Date
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, ...);

\
 
 \ /
  Last update: 2008-02-04 16:53    [W:0.054 / U:0.584 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site