Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755068AbYBDPto (ORCPT ); Mon, 4 Feb 2008 10:49:44 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751520AbYBDPth (ORCPT ); Mon, 4 Feb 2008 10:49:37 -0500 Received: from saeurebad.de ([85.214.36.134]:35872 "EHLO saeurebad.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751291AbYBDPtg (ORCPT ); Mon, 4 Feb 2008 10:49:36 -0500 From: Johannes Weiner To: Linux Kernel Mailing List Cc: Sam Ravnborg Subject: [RFC] Sectionized printk data Date: Mon, 04 Feb 2008 16:48:34 +0100 Message-ID: <87zlugsox9.fsf@saeurebad.de> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2647 Lines: 81 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 Sectionized printk wrappers Introduce printk wrappers that place format string literals in init/exit data sections. Signed-off-by: Johannes Weiner --- The place for these wrappers is probably very wrong. Suggestions welcome. 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 +#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, ...); -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/