From: Andrew Morton Date: Fri, 6 Oct 2006 07:43:49 +0000 (-0700) Subject: [PATCH] Fix WARN_ON / WARN_ON_ONCE regression X-Git-Tag: firefly_0821_release~32365 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=d69a892268c66c13fcb445a8274baa9d7befb7b5;p=firefly-linux-kernel-4.4.55.git [PATCH] Fix WARN_ON / WARN_ON_ONCE regression Tim and Ananiev report that the recent WARN_ON_ONCE changes cause increased cache misses with the tbench workload. Apparently due to the access to the newly-added static variable. Rearrange the code so that we don't touch that variable unless the warning is going to trigger. Also rework the logic so that the static variable starts out at zero, so we can move it into bss. It would seem logical to mark the static variable as __read_mostly too. But it would be wrong, because that would put it back into the vmlinux image, and the kernel will never read from this variable in normal operation anyway. Unless the compiler or hardware go and do some prefetching on us? For some reason this patch shrinks softirq.o text by 40 bytes. Cc: Tim Chen Cc: Herbert Xu Cc: "Ananiev, Leonid I" Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- diff --git a/include/asm-generic/bug.h b/include/asm-generic/bug.h index a5250895155e..1d9573cf4a0b 100644 --- a/include/asm-generic/bug.h +++ b/include/asm-generic/bug.h @@ -41,14 +41,14 @@ #endif #endif -#define WARN_ON_ONCE(condition) ({ \ - static int __warn_once = 1; \ - typeof(condition) __ret_warn_once = (condition);\ - \ - if (likely(__warn_once)) \ - if (WARN_ON(__ret_warn_once)) \ - __warn_once = 0; \ - unlikely(__ret_warn_once); \ +#define WARN_ON_ONCE(condition) ({ \ + static int __warned; \ + typeof(condition) __ret_warn_once = (condition); \ + \ + if (unlikely(__ret_warn_once)) \ + if (WARN_ON(!__warned)) \ + __warned = 1; \ + unlikely(__ret_warn_once); \ }) #ifdef CONFIG_SMP