mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Johannes Berg <johannes@sipsolutions.net>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Arjan van de Ven <arjan@infradead.org>,
	linux-kernel@vger.kernel.org, mingo@elte.hu
Subject: Re: [patch 13/17] Use WARN() in drivers/base/
Date: Sat, 12 Jul 2008 02:51:22 +0200	[thread overview]
Message-ID: <1215823882.10052.5.camel@johannes.berg> (raw)
In-Reply-To: <1215817836.10052.2.camel@johannes.berg>


> #define WARN_ON(test, fmt...)           	\
>   do {                                  	\
>       if (test) {                       	\
>           warn_on_slowpath(cnt(fmt) , ## fmt);	\
>           printf("WARN\n");             	\
>       }                                 	\
>   } while (0)

That doesn't play well with the bugtrap stuff, obviously. This one is a
bit better, but still has more overhead than the bugtrap stuff, but
avoids the overhead in the no-argument case.


#include <stdarg.h>
#include <stdio.h>

#define unlikely(x) (x)

#define hasargs(...) _hasargs( , ## __VA_ARGS__)
#define _hasargs(...) __hasargs(__VA_ARGS__,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0)
#define __hasargs(x0,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,x16,x17,x18,x19,n,ys...) n

static void warn_slowpath(int count, ...)
{
	va_list args;
	char *fmt;

	printf("WARNING: <<\n");

	if (count) {
		va_start(args, count);
		fmt = va_arg(args, char *);
		vprintf(fmt, args);
		va_end(args);
	}
	printf(">>\n");
}

/*
 * This is the original arch WARN_ON that just emits
 * a trap instruction and a bugtrap section entry for
 * example on powerpc.
 *
 * Obviously this isn't, but it could be.
 */
#define BUGTRAP_WARN_ON(test) ({			\
	if (unlikely(test))				\
		printf("WARNING: %s\n", #test);		\
	unlikely(test);					\
})

/*
 * This is a WARN_ON for some other architectures that don't
 * use the bugtrap section, it calls the slowpath function
 * which leads to more code size. But when you've added
 * parameters to your WARN_ON those need to be calculated
 * as well so you've already increased code size.
 */
#define OUT_OF_LINE_WARN_ON(test, fmt...) ({		\
	if (unlikely(test))				\
		warn_slowpath(hasargs(fmt) , ## fmt);	\
	unlikely(test);					\
})

/*
 * This new version determines whether to do a bugtrap
 * entry or not depending on whether there were any extra
 * arguments given.
 */
#define CONFIG_BUG_EXTRA_VERBOSE
#ifdef CONFIG_BUG_EXTRA_VERBOSE
#define WARN_ON(test, fmt...) ({			\
	if (!hasargs(fmt))				\
		BUGTRAP_WARN_ON(test);			\
	else						\
		OUT_OF_LINE_WARN_ON(test , ## fmt);	\
})
#else
#define WARN_ON(test, fmt...) BUGTRAP_WARN_ON(test)
#endif

int main(void)
{
	WARN_ON(1);
	WARN_ON(2, "asdf %d %d\n", 7, 8);
	WARN_ON(3, "asdf\n");

	return 0;
}



  reply	other threads:[~2008-07-12  0:51 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-08 16:38 [patch 0/17] Series to introduce WARN()... a WARN_ON() variant that takes printk arguments Arjan van de Ven
2008-07-08 16:39 ` [patch 1/17] Clear the WARN() namespace Arjan van de Ven
2008-07-11 19:19   ` Andrew Morton
2008-07-08 16:40 ` [patch 2/17] Add a WARN() macro that acts like WARN_ON()+printk Arjan van de Ven
2008-07-08 18:00   ` Joe Perches
2008-07-08 18:18     ` Arjan van de Ven
2008-07-11 19:19   ` Andrew Morton
2008-07-11 20:51     ` Arjan van de Ven
2008-07-08 16:41 ` [patch 3/17] Introduce WARN() usage in the kobject code Arjan van de Ven
2008-07-08 16:42 ` [patch 4/17] Use WARN() in kernel/irq/manage.c Arjan van de Ven
2008-07-08 16:45 ` [patch 5/17] Use WARN() in kernel/panic.c Arjan van de Ven
2008-07-08 16:46 ` [patch 6/17] Use WARN() in mm/vmalloc.c Arjan van de Ven
2008-07-08 16:47 ` [patch 7/17] use WARN() in kernel/lockdep.c Arjan van de Ven
2008-07-08 16:48 ` [patch 8/17] use WARN() in kernel/irq/chip.c Arjan van de Ven
2008-07-08 16:50 ` [patch 9/17] Use WARN() in arch/x86/mm/ioremap.c Arjan van de Ven
2008-07-08 16:51 ` [patch 10/17] use WARN() in arch/x86/mm/pageattr.c Arjan van de Ven
2008-07-08 16:51 ` [patch 11/17] Use WARN() in arch/x86/kernel Arjan van de Ven
2008-07-08 16:52 ` [patch 12/17] Use WARN() in block/ Arjan van de Ven
2008-07-08 16:53 ` [patch 13/17] Use WARN() in drivers/base/ Arjan van de Ven
2008-07-11 19:20   ` Andrew Morton
2008-07-11 20:54     ` Arjan van de Ven
2008-07-11 22:11       ` Andrew Morton
2008-07-11 22:35         ` Arjan van de Ven
2008-07-11 22:51         ` Arjan van de Ven
2008-07-11 23:02           ` Andrew Morton
2008-07-11 23:56             ` Arjan van de Ven
2008-07-11 23:10         ` Johannes Berg
2008-07-12  0:51           ` Johannes Berg [this message]
2008-07-08 16:53 ` [patch 14/17] Use WARN() in lib/ Arjan van de Ven
2008-07-08 16:54 ` [patch 15/17] Use WARN() in fs/ Arjan van de Ven
2008-07-08 16:54 ` Arjan van de Ven
2008-07-08 16:55 ` Arjan van de Ven
2008-07-08 16:56 ` [patch 16/17] Usr WARN() in fs/sysfs Arjan van de Ven
2008-07-08 16:57 ` [patch 17/17] Use WARN() in fs/proc/ Arjan van de Ven
2008-07-09 10:13 ` [patch 0/17] Series to introduce WARN()... a WARN_ON() variant that takes printk arguments Ingo Molnar
2008-07-09 11:19   ` Andrew Morton
2008-07-09 11:37     ` Ingo Molnar
2008-07-09 11:46       ` Andrew Morton
2008-07-09 12:13         ` Ingo Molnar
2008-07-09 13:31         ` Arjan van de Ven

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=1215823882.10052.5.camel@johannes.berg \
    --to=johannes@sipsolutions.net \
    --cc=akpm@linux-foundation.org \
    --cc=arjan@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    /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

all inboxes | Powered by JetHome®