From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thomas Renninger Subject: Re: [tip:core/printk] printk: introduce printk_once() Date: Thu, 5 Feb 2009 15:12:10 +0100 Message-ID: <200902051512.11140.trenn@suse.de> References: <1233829109-23358-1-git-send-email-trenn@suse.de> <20090205124234.GD8799@elte.hu> <20090205130420.GA10525@elte.hu> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Return-path: Received: from cantor.suse.de ([195.135.220.2]:39471 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751863AbZBEOMR (ORCPT ); Thu, 5 Feb 2009 09:12:17 -0500 In-Reply-To: <20090205130420.GA10525@elte.hu> Content-Disposition: inline Sender: linux-next-owner@vger.kernel.org List-ID: To: Ingo Molnar Cc: davej@redhat.com, sfr@canb.auug.org.au, linux-next@vger.kernel.org, cpufreq@vger.kernel.org On Thursday 05 February 2009 14:04:20 Ingo Molnar wrote: > > * Ingo Molnar wrote: > > > printk_once() would be nice indeed - it's a frequent construct. > > Something like the patch below? Yes, nice. Sorry, I can't test it right now, I really have to do something else. I can give it a test in some hours or tomorrow. I'd also wait a week with the WARN_ONCE cleanup until this is in linux-next and then fix it up correctly just "once" :) powernow-k8 printing a backtrace in linux-next in broken BIOS case for a week or two shouldn't be an issue. No need to answer, just tell me if this does not work out. Thanks for your suggestions, Thomas > Ingo > > ----------------> > Author: Ingo Molnar > AuthorDate: Thu, 5 Feb 2009 13:45:43 +0100 > Commit: Ingo Molnar > CommitDate: Thu, 5 Feb 2009 13:52:29 +0100 > > printk: introduce printk_once() > > This pattern shows up frequently in the kernel: > > static int once = 1; > ... > > if (once) { > once = 0; > printk(KERN_ERR "message\n"); > } > ... > > So add a printk_once() helper macro that reduces this to a single line > of: > > printk_once(KERN_ERR "message\n"); > > It works analogously to WARN_ONCE() & friends. (We use a macro not > an inline because vararg expansion in inlines looks awkward and the > macro is simple enough.) > > Signed-off-by: Ingo Molnar > > > --- > include/linux/kernel.h | 17 +++++++++++++++++ > 1 files changed, 17 insertions(+), 0 deletions(-) > > diff --git a/include/linux/kernel.h b/include/linux/kernel.h > index 343df9e..3c183d9 100644 > --- a/include/linux/kernel.h > +++ b/include/linux/kernel.h > @@ -242,6 +242,19 @@ extern struct ratelimit_state printk_ratelimit_state; > extern int printk_ratelimit(void); > extern bool printk_timed_ratelimit(unsigned long *caller_jiffies, > unsigned int interval_msec); > + > +/* > + * Print a one-time message (analogous to WARN_ONCE() et al): > + */ > +#define printk_once(x...) ({ \ > + static int __print_once = 1; \ > + \ > + if (__print_once) { \ > + __print_once = 0; \ > + printk(x); \ > + } \ > +}) > + > #else > static inline int vprintk(const char *s, va_list args) > __attribute__ ((format (printf, 1, 0))); > @@ -253,6 +266,10 @@ static inline int printk_ratelimit(void) { return 0; } > static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies, \ > unsigned int interval_msec) \ > { return false; } > + > +/* No effect, but we still get type checking even in the !PRINTK case: */ > +#define printk_once(x...) printk(x) > + > #endif > > extern int printk_needs_cpu(int cpu); > -- > To unsubscribe from this list: send the line "unsubscribe cpufreq" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html >