linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] alpha: use __ratelimit
@ 2010-02-28 10:58 Akinobu Mita
  2010-02-28 10:58 ` [PATCH] ia64: " Akinobu Mita
                   ` (5 more replies)
  0 siblings, 6 replies; 10+ messages in thread
From: Akinobu Mita @ 2010-02-28 10:58 UTC (permalink / raw)
  To: linux-kernel
  Cc: Akinobu Mita, Richard Henderson, Ivan Kokshaysky, Matt Turner,
	linux-alpha

Replace open-coded rate limiting logic with __ratelimit().

Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Richard Henderson <rth@twiddle.net>
Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
Cc: Matt Turner <mattst88@gmail.com>
Cc: linux-alpha@vger.kernel.org
---
 arch/alpha/kernel/traps.c |   10 +++-------
 1 files changed, 3 insertions(+), 7 deletions(-)

diff --git a/arch/alpha/kernel/traps.c b/arch/alpha/kernel/traps.c
index 6ee7655..b14f015 100644
--- a/arch/alpha/kernel/traps.c
+++ b/arch/alpha/kernel/traps.c
@@ -17,6 +17,7 @@
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/kallsyms.h>
+#include <linux/ratelimit.h>
 
 #include <asm/gentrap.h>
 #include <asm/uaccess.h>
@@ -771,8 +772,7 @@ asmlinkage void
 do_entUnaUser(void __user * va, unsigned long opcode,
 	      unsigned long reg, struct pt_regs *regs)
 {
-	static int cnt = 0;
-	static unsigned long last_time;
+	static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
 
 	unsigned long tmp1, tmp2, tmp3, tmp4;
 	unsigned long fake_reg, *reg_addr = &fake_reg;
@@ -783,15 +783,11 @@ do_entUnaUser(void __user * va, unsigned long opcode,
 	   with the unaliged access.  */
 
 	if (!test_thread_flag (TIF_UAC_NOPRINT)) {
-		if (cnt >= 5 && time_after(jiffies, last_time + 5 * HZ)) {
-			cnt = 0;
-		}
-		if (++cnt < 5) {
+		if (__ratelimit(&ratelimit)) {
 			printk("%s(%d): unaligned trap at %016lx: %p %lx %ld\n",
 			       current->comm, task_pid_nr(current),
 			       regs->pc - 4, va, opcode, reg);
 		}
-		last_time = jiffies;
 	}
 	if (test_thread_flag (TIF_UAC_SIGBUS))
 		goto give_sigbus;
-- 
1.6.0.6


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH] ia64: use __ratelimit
  2010-02-28 10:58 [PATCH] alpha: use __ratelimit Akinobu Mita
@ 2010-02-28 10:58 ` Akinobu Mita
  2010-02-28 10:58 ` [PATCH] parisc: " Akinobu Mita
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 10+ messages in thread
From: Akinobu Mita @ 2010-02-28 10:58 UTC (permalink / raw)
  To: linux-kernel; +Cc: Akinobu Mita, Tony Luck, Fenghua Yu, linux-ia64

Replace open-coded rate limiting logic with __ratelimit().

Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Tony Luck <tony.luck@intel.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Cc: linux-ia64@vger.kernel.org
---
 arch/ia64/kernel/irq_ia64.c  |    9 +++------
 arch/ia64/kernel/unaligned.c |   24 +++++-------------------
 2 files changed, 8 insertions(+), 25 deletions(-)

diff --git a/arch/ia64/kernel/irq_ia64.c b/arch/ia64/kernel/irq_ia64.c
index d4093a1..d5150d0 100644
--- a/arch/ia64/kernel/irq_ia64.c
+++ b/arch/ia64/kernel/irq_ia64.c
@@ -30,6 +30,7 @@
 #include <linux/threads.h>
 #include <linux/bitops.h>
 #include <linux/irq.h>
+#include <linux/ratelimit.h>
 
 #include <asm/delay.h>
 #include <asm/intrinsics.h>
@@ -468,13 +469,9 @@ ia64_handle_irq (ia64_vector vector, struct pt_regs *regs)
 		sp = ia64_getreg(_IA64_REG_SP);
 
 		if ((sp - bsp) < 1024) {
-			static unsigned char count;
-			static long last_time;
+			static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
 
-			if (time_after(jiffies, last_time + 5 * HZ))
-				count = 0;
-			if (++count < 5) {
-				last_time = jiffies;
+			if (__ratelimit(&ratelimit)) {
 				printk("ia64_handle_irq: DANGER: less than "
 				       "1KB of free stack space!!\n"
 				       "(bsp=0x%lx, sp=%lx)\n", bsp, sp);
diff --git a/arch/ia64/kernel/unaligned.c b/arch/ia64/kernel/unaligned.c
index 776dd40..622772b 100644
--- a/arch/ia64/kernel/unaligned.c
+++ b/arch/ia64/kernel/unaligned.c
@@ -17,6 +17,7 @@
 #include <linux/kernel.h>
 #include <linux/sched.h>
 #include <linux/tty.h>
+#include <linux/ratelimit.h>
 
 #include <asm/intrinsics.h>
 #include <asm/processor.h>
@@ -1283,24 +1284,9 @@ emulate_store_float (unsigned long ifa, load_store_t ld, struct pt_regs *regs)
 /*
  * Make sure we log the unaligned access, so that user/sysadmin can notice it and
  * eventually fix the program.  However, we don't want to do that for every access so we
- * pace it with jiffies.  This isn't really MP-safe, but it doesn't really have to be
- * either...
+ * pace it with jiffies.
  */
-static int
-within_logging_rate_limit (void)
-{
-	static unsigned long count, last_time;
-
-	if (time_after(jiffies, last_time + 5 * HZ))
-		count = 0;
-	if (count < 5) {
-		last_time = jiffies;
-		count++;
-		return 1;
-	}
-	return 0;
-
-}
+static DEFINE_RATELIMIT_STATE(logging_rate_limit, 5 * HZ, 5);
 
 void
 ia64_handle_unaligned (unsigned long ifa, struct pt_regs *regs)
@@ -1337,7 +1323,7 @@ ia64_handle_unaligned (unsigned long ifa, struct pt_regs *regs)
 
 		if (!no_unaligned_warning &&
 		    !(current->thread.flags & IA64_THREAD_UAC_NOPRINT) &&
-		    within_logging_rate_limit())
+		    __ratelimit(&logging_rate_limit))
 		{
 			char buf[200];	/* comm[] is at most 16 bytes... */
 			size_t len;
@@ -1370,7 +1356,7 @@ ia64_handle_unaligned (unsigned long ifa, struct pt_regs *regs)
 			}
 		}
 	} else {
-		if (within_logging_rate_limit()) {
+		if (__ratelimit(&logging_rate_limit)) {
 			printk(KERN_WARNING "kernel unaligned access to 0x%016lx, ip=0x%016lx\n",
 			       ifa, regs->cr_iip + ipsr->ri);
 			if (unaligned_dump_stack)
-- 
1.6.0.6


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH] parisc: use __ratelimit
  2010-02-28 10:58 [PATCH] alpha: use __ratelimit Akinobu Mita
  2010-02-28 10:58 ` [PATCH] ia64: " Akinobu Mita
@ 2010-02-28 10:58 ` Akinobu Mita
  2010-03-01 23:54   ` Kyle McMartin
  2010-02-28 10:58 ` [PATCH] powerpc: " Akinobu Mita
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 10+ messages in thread
From: Akinobu Mita @ 2010-02-28 10:58 UTC (permalink / raw)
  To: linux-kernel
  Cc: Akinobu Mita, Kyle McMartin, Helge Deller, James E.J. Bottomley,
	linux-parisc

Replace open-coded rate limiting logic with __ratelimit().

Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Kyle McMartin <kyle@mcmartin.ca>
Cc: Helge Deller <deller@gmx.de>
Cc: "James E.J. Bottomley" <jejb@parisc-linux.org>
Cc: linux-parisc@vger.kernel.org
---
 arch/parisc/kernel/unaligned.c |   14 ++++----------
 1 files changed, 4 insertions(+), 10 deletions(-)

diff --git a/arch/parisc/kernel/unaligned.c b/arch/parisc/kernel/unaligned.c
index e6f4b7a..92d977b 100644
--- a/arch/parisc/kernel/unaligned.c
+++ b/arch/parisc/kernel/unaligned.c
@@ -25,6 +25,7 @@
 #include <linux/module.h>
 #include <linux/sched.h>
 #include <linux/signal.h>
+#include <linux/ratelimit.h>
 #include <asm/uaccess.h>
 
 /* #define DEBUG_UNALIGNED 1 */
@@ -446,8 +447,7 @@ static int emulate_std(struct pt_regs *regs, int frreg, int flop)
 
 void handle_unaligned(struct pt_regs *regs)
 {
-	static unsigned long unaligned_count = 0;
-	static unsigned long last_time = 0;
+	static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
 	unsigned long newbase = R1(regs->iir)?regs->gr[R1(regs->iir)]:0;
 	int modify = 0;
 	int ret = ERR_NOTHANDLED;
@@ -460,14 +460,8 @@ void handle_unaligned(struct pt_regs *regs)
 			goto force_sigbus;
 		}
 
-		if (unaligned_count > 5 &&
-				time_after(jiffies, last_time + 5 * HZ)) {
-			unaligned_count = 0;
-			last_time = jiffies;
-		}
-
-		if (!(current->thread.flags & PARISC_UAC_NOPRINT) 
-		    && ++unaligned_count < 5) {
+		if (!(current->thread.flags & PARISC_UAC_NOPRINT) &&
+			__ratelimit(&ratelimit)) {
 			char buf[256];
 			sprintf(buf, "%s(%d): unaligned access to 0x" RFMT " at ip=0x" RFMT "\n",
 				current->comm, task_pid_nr(current), regs->ior, regs->iaoq[0]);
-- 
1.6.0.6


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH] powerpc: use __ratelimit
  2010-02-28 10:58 [PATCH] alpha: use __ratelimit Akinobu Mita
  2010-02-28 10:58 ` [PATCH] ia64: " Akinobu Mita
  2010-02-28 10:58 ` [PATCH] parisc: " Akinobu Mita
@ 2010-02-28 10:58 ` Akinobu Mita
  2010-02-28 10:58 ` [PATCH] sparc: " Akinobu Mita
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 10+ messages in thread
From: Akinobu Mita @ 2010-02-28 10:58 UTC (permalink / raw)
  To: linux-kernel
  Cc: Akinobu Mita, Benjamin Herrenschmidt, Paul Mackerras, linuxppc-dev

Replace open-coded rate limiting logic with __ratelimit().

Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: linuxppc-dev@ozlabs.org
---
 arch/powerpc/platforms/iseries/pci.c |   10 +++-------
 1 files changed, 3 insertions(+), 7 deletions(-)

diff --git a/arch/powerpc/platforms/iseries/pci.c b/arch/powerpc/platforms/iseries/pci.c
index 175aac8..5873a47 100644
--- a/arch/powerpc/platforms/iseries/pci.c
+++ b/arch/powerpc/platforms/iseries/pci.c
@@ -31,6 +31,7 @@
 #include <linux/module.h>
 #include <linux/pci.h>
 #include <linux/of.h>
+#include <linux/ratelimit.h>
 
 #include <asm/types.h>
 #include <asm/io.h>
@@ -583,14 +584,9 @@ static inline struct device_node *xlate_iomm_address(
 
 	orig_addr = (unsigned long __force)addr;
 	if ((orig_addr < BASE_IO_MEMORY) || (orig_addr >= max_io_memory)) {
-		static unsigned long last_jiffies;
-		static int num_printed;
+		static DEFINE_RATELIMIT_STATE(ratelimit, 60 * HZ, 10);
 
-		if (time_after(jiffies, last_jiffies + 60 * HZ)) {
-			last_jiffies = jiffies;
-			num_printed = 0;
-		}
-		if (num_printed++ < 10)
+		if (__ratelimit(&ratelimit))
 			printk(KERN_ERR
 				"iSeries_%s: invalid access at IO address %p\n",
 				func, addr);
-- 
1.6.0.6


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH] sparc: use __ratelimit
  2010-02-28 10:58 [PATCH] alpha: use __ratelimit Akinobu Mita
                   ` (2 preceding siblings ...)
  2010-02-28 10:58 ` [PATCH] powerpc: " Akinobu Mita
@ 2010-02-28 10:58 ` Akinobu Mita
  2010-02-28 11:31   ` David Miller
  2010-02-28 18:42 ` [PATCH] alpha: " Joe Perches
  2010-03-03  5:32 ` Matt Turner
  5 siblings, 1 reply; 10+ messages in thread
From: Akinobu Mita @ 2010-02-28 10:58 UTC (permalink / raw)
  To: linux-kernel; +Cc: Akinobu Mita, David S. Miller, sparclinux

Replace open-coded rate limiting logic with __ratelimit().

Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: sparclinux@vger.kernel.org
---
 arch/sparc/kernel/unaligned_64.c |    9 +++------
 1 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
index 378ca82..f03641f 100644
--- a/arch/sparc/kernel/unaligned_64.c
+++ b/arch/sparc/kernel/unaligned_64.c
@@ -21,6 +21,7 @@
 #include <linux/smp.h>
 #include <linux/bitops.h>
 #include <linux/perf_event.h>
+#include <linux/ratelimit.h>
 #include <asm/fpumacro.h>
 
 enum direction {
@@ -274,13 +275,9 @@ static void kernel_mna_trap_fault(int fixup_tstate_asi)
 
 static void log_unaligned(struct pt_regs *regs)
 {
-	static unsigned long count, last_time;
+	static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
 
-	if (time_after(jiffies, last_time + 5 * HZ))
-		count = 0;
-	if (count < 5) {
-		last_time = jiffies;
-		count++;
+	if (__ratelimit(&ratelimit)) {
 		printk("Kernel unaligned access at TPC[%lx] %pS\n",
 		       regs->tpc, (void *) regs->tpc);
 	}
-- 
1.6.0.6


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH] sparc: use __ratelimit
  2010-02-28 10:58 ` [PATCH] sparc: " Akinobu Mita
@ 2010-02-28 11:31   ` David Miller
  0 siblings, 0 replies; 10+ messages in thread
From: David Miller @ 2010-02-28 11:31 UTC (permalink / raw)
  To: akinobu.mita; +Cc: linux-kernel, sparclinux

From: Akinobu Mita <akinobu.mita@gmail.com>
Date: Sun, 28 Feb 2010 19:58:17 +0900

> Replace open-coded rate limiting logic with __ratelimit().
> 
> Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>

Applied, thanks.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] alpha: use __ratelimit
  2010-02-28 10:58 [PATCH] alpha: use __ratelimit Akinobu Mita
                   ` (3 preceding siblings ...)
  2010-02-28 10:58 ` [PATCH] sparc: " Akinobu Mita
@ 2010-02-28 18:42 ` Joe Perches
  2010-03-01  3:13   ` Akinobu Mita
  2010-03-03  5:32 ` Matt Turner
  5 siblings, 1 reply; 10+ messages in thread
From: Joe Perches @ 2010-02-28 18:42 UTC (permalink / raw)
  To: Akinobu Mita; +Cc: linux-kernel

On Sun, 2010-02-28 at 19:58 +0900, Akinobu Mita wrote:
> Replace open-coded rate limiting logic with __ratelimit().

Perhaps printk_ratelimited?



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] alpha: use __ratelimit
  2010-02-28 18:42 ` [PATCH] alpha: " Joe Perches
@ 2010-03-01  3:13   ` Akinobu Mita
  0 siblings, 0 replies; 10+ messages in thread
From: Akinobu Mita @ 2010-03-01  3:13 UTC (permalink / raw)
  To: Joe Perches; +Cc: linux-kernel

2010/3/1 Joe Perches <joe@perches.com>:
> On Sun, 2010-02-28 at 19:58 +0900, Akinobu Mita wrote:
>> Replace open-coded rate limiting logic with __ratelimit().
>
> Perhaps printk_ratelimited?

This patch is cleanup only and no functionnal change (it does not change
the rate limit interval and burst).

But using printk_ratelimited() changes the burst count from 5 to 10.
It may not be big difference but I'm not sure...

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] parisc: use __ratelimit
  2010-02-28 10:58 ` [PATCH] parisc: " Akinobu Mita
@ 2010-03-01 23:54   ` Kyle McMartin
  0 siblings, 0 replies; 10+ messages in thread
From: Kyle McMartin @ 2010-03-01 23:54 UTC (permalink / raw)
  To: Akinobu Mita
  Cc: linux-kernel, Kyle McMartin, Helge Deller, James E.J. Bottomley,
	linux-parisc

On Sun, Feb 28, 2010 at 07:58:15PM +0900, Akinobu Mita wrote:
> Replace open-coded rate limiting logic with __ratelimit().
> 

Thanks, I'll apply this.

regards, Kyle

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] alpha: use __ratelimit
  2010-02-28 10:58 [PATCH] alpha: use __ratelimit Akinobu Mita
                   ` (4 preceding siblings ...)
  2010-02-28 18:42 ` [PATCH] alpha: " Joe Perches
@ 2010-03-03  5:32 ` Matt Turner
  5 siblings, 0 replies; 10+ messages in thread
From: Matt Turner @ 2010-03-03  5:32 UTC (permalink / raw)
  To: Akinobu Mita
  Cc: linux-kernel, Richard Henderson, Ivan Kokshaysky, linux-alpha

On Sun, Feb 28, 2010 at 5:58 AM, Akinobu Mita <akinobu.mita@gmail.com> wrote:
> Replace open-coded rate limiting logic with __ratelimit().
>
> Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
> Cc: Richard Henderson <rth@twiddle.net>
> Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
> Cc: Matt Turner <mattst88@gmail.com>
> Cc: linux-alpha@vger.kernel.org
> ---
>  arch/alpha/kernel/traps.c |   10 +++-------
>  1 files changed, 3 insertions(+), 7 deletions(-)
>
> diff --git a/arch/alpha/kernel/traps.c b/arch/alpha/kernel/traps.c
> index 6ee7655..b14f015 100644
> --- a/arch/alpha/kernel/traps.c
> +++ b/arch/alpha/kernel/traps.c
> @@ -17,6 +17,7 @@
>  #include <linux/module.h>
>  #include <linux/init.h>
>  #include <linux/kallsyms.h>
> +#include <linux/ratelimit.h>
>
>  #include <asm/gentrap.h>
>  #include <asm/uaccess.h>
> @@ -771,8 +772,7 @@ asmlinkage void
>  do_entUnaUser(void __user * va, unsigned long opcode,
>              unsigned long reg, struct pt_regs *regs)
>  {
> -       static int cnt = 0;
> -       static unsigned long last_time;
> +       static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
>
>        unsigned long tmp1, tmp2, tmp3, tmp4;
>        unsigned long fake_reg, *reg_addr = &fake_reg;
> @@ -783,15 +783,11 @@ do_entUnaUser(void __user * va, unsigned long opcode,
>           with the unaliged access.  */
>
>        if (!test_thread_flag (TIF_UAC_NOPRINT)) {
> -               if (cnt >= 5 && time_after(jiffies, last_time + 5 * HZ)) {
> -                       cnt = 0;
> -               }
> -               if (++cnt < 5) {
> +               if (__ratelimit(&ratelimit)) {
>                        printk("%s(%d): unaligned trap at %016lx: %p %lx %ld\n",
>                               current->comm, task_pid_nr(current),
>                               regs->pc - 4, va, opcode, reg);
>                }
> -               last_time = jiffies;
>        }
>        if (test_thread_flag (TIF_UAC_SIGBUS))
>                goto give_sigbus;
> --
> 1.6.0.6

Thanks, applied.

Matt

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2010-03-03  5:32 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-02-28 10:58 [PATCH] alpha: use __ratelimit Akinobu Mita
2010-02-28 10:58 ` [PATCH] ia64: " Akinobu Mita
2010-02-28 10:58 ` [PATCH] parisc: " Akinobu Mita
2010-03-01 23:54   ` Kyle McMartin
2010-02-28 10:58 ` [PATCH] powerpc: " Akinobu Mita
2010-02-28 10:58 ` [PATCH] sparc: " Akinobu Mita
2010-02-28 11:31   ` David Miller
2010-02-28 18:42 ` [PATCH] alpha: " Joe Perches
2010-03-01  3:13   ` Akinobu Mita
2010-03-03  5:32 ` Matt Turner

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).