Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[PATCH] alpha: use __ratelimit

8 views
Skip to first unread message

Akinobu Mita

unread,
Feb 28, 2010, 6:00:02 AM2/28/10
to
Replace open-coded rate limiting logic with __ratelimit().

Signed-off-by: Akinobu Mita <akinob...@gmail.com>
Cc: Richard Henderson <r...@twiddle.net>
Cc: Ivan Kokshaysky <i...@jurassic.park.msu.ru>
Cc: Matt Turner <matt...@gmail.com>
Cc: linux...@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

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majo...@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Akinobu Mita

unread,
Feb 28, 2010, 6:10:03 AM2/28/10
to
Replace open-coded rate limiting logic with __ratelimit().

Signed-off-by: Akinobu Mita <akinob...@gmail.com>
Cc: Kyle McMartin <ky...@mcmartin.ca>
Cc: Helge Deller <del...@gmx.de>
Cc: "James E.J. Bottomley" <je...@parisc-linux.org>
Cc: linux-...@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]);

Joe Perches

unread,
Feb 28, 2010, 1:50:02 PM2/28/10
to
On Sun, 2010-02-28 at 19:58 +0900, Akinobu Mita wrote:
> Replace open-coded rate limiting logic with __ratelimit().

Perhaps printk_ratelimited?

Akinobu Mita

unread,
Feb 28, 2010, 10:20:01 PM2/28/10
to
2010/3/1 Joe Perches <j...@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...

Kyle McMartin

unread,
Mar 1, 2010, 7:00:02 PM3/1/10
to
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

Matt Turner

unread,
Mar 3, 2010, 12:40:02 AM3/3/10
to

Thanks, applied.

Matt

0 new messages