From: Thomas Renninger <trenn@suse.de>
To: Ingo Molnar <mingo@elte.hu>
Cc: davej@redhat.com, sfr@canb.auug.org.au,
linux-next@vger.kernel.org, cpufreq@vger.kernel.org
Subject: Re: [tip:core/printk] printk: introduce printk_once()
Date: Thu, 5 Feb 2009 15:12:10 +0100 [thread overview]
Message-ID: <200902051512.11140.trenn@suse.de> (raw)
In-Reply-To: <20090205130420.GA10525@elte.hu>
On Thursday 05 February 2009 14:04:20 Ingo Molnar wrote:
>
> * Ingo Molnar <mingo@elte.hu> 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 <mingo@elte.hu>
> AuthorDate: Thu, 5 Feb 2009 13:45:43 +0100
> Commit: Ingo Molnar <mingo@elte.hu>
> 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 <mingo@elte.hu>
>
>
> ---
> 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
>
next prev parent reply other threads:[~2009-02-05 14:12 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-02-05 10:18 On top fixes for my last patches Thomas Renninger
2009-02-05 10:18 ` [PATCH 1/2] CPUFREQ: powernow-k8: Forgot to use printk instead of WARN_ONCE in last patch Thomas Renninger
2009-02-05 12:02 ` Ingo Molnar
2009-02-05 12:09 ` Thomas Renninger
2009-02-05 12:33 ` Ingo Molnar
2009-02-05 12:53 ` Thomas Renninger
2009-02-05 13:26 ` Ingo Molnar
2009-02-05 12:27 ` Thomas Renninger
2009-02-05 12:42 ` Ingo Molnar
2009-02-05 13:04 ` [tip:core/printk] printk: introduce printk_once() Ingo Molnar
2009-02-05 14:12 ` Thomas Renninger [this message]
2009-02-05 10:18 ` [PATCH 2/2] CPUFREQ: Use static or it won't compile if conservative and ondemand are set =y Thomas Renninger
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=200902051512.11140.trenn@suse.de \
--to=trenn@suse.de \
--cc=cpufreq@vger.kernel.org \
--cc=davej@redhat.com \
--cc=linux-next@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=sfr@canb.auug.org.au \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).