Skip to contentSkip to conversation

ratelimit performance counter interrupts

PATCH Applied Mike Galbraith 3 participants 4 messages Jan 23, 2009 x86

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ratelimit performance counter interrupts

While fiddling around with kerneltop, I found that an unwary user can lock his box up quite thoroughly if he does something really clever like starting kerneltop with -c 100.

Ratelimit performance counter interrupts to 100KHz per CPU.

---
 arch/x86/kernel/apic.c             |    2 +
 arch/x86/kernel/cpu/perf_counter.c |   43 ++++++++++++++++++++++++++++++-------
 include/linux/perf_counter.h       |    2 +
 3 files changed, 40 insertions(+), 7 deletions(-)
arch/x86/kernel/apic.c +2 -0
Index: linux-2.6/arch/x86/kernel/apic.c
===================================================================
@@ -781,6 +781,8 @@ static void local_apic_timer_interrupt(v
 	inc_irq_stat(apic_timer_irqs);
 
 	evt->event_handler(evt);
+
+	perf_counter_unthrottle();
 }
 
 /*
arch/x86/kernel/cpu/perf_counter.c +36 -7

74 lines not on this page · raw message

include/linux/perf_counter.h +2 -0
Index: linux-2.6/include/linux/perf_counter.h
===================================================================
@@ -254,6 +254,7 @@ extern void perf_counter_init_task(struc
 extern void perf_counter_exit_task(struct task_struct *child);
 extern void perf_counter_notify(struct pt_regs *regs);
 extern void perf_counter_print_debug(void);
+extern void perf_counter_unthrottle(void);
 extern u64 hw_perf_save_disable(void);
 extern void hw_perf_restore(u64 ctrl);
 extern int perf_counter_task_disable(void);
@@ -281,6 +282,7 @@ static inline void perf_counter_init_tas
 static inline void perf_counter_exit_task(struct task_struct *child)	{ }
 static inline void perf_counter_notify(struct pt_regs *regs)		{ }
 static inline void perf_counter_print_debug(void)			{ }
+static inline void perf_counter_unthrottle(void)			{ }
 static inline void hw_perf_restore(u64 ctrl)			{ }
 static inline u64 hw_perf_save_disable(void)		      { return 0; }
 static inline int perf_counter_task_disable(void)	{ return -EINVAL; }
#1 lore raw
Quoted 2 lines · Mike Galbraith

+ * Mamimum interrupt frequency of 100KHz per CPU
+ */

Hi Mike, I think you misspelled the word Maximum here.

Thanks,
Rakib

#2 lore raw
Quoted 6 lines · Rakib Mullick
Quoted 2 lines · Mike Galbraith

+ * Mamimum interrupt frequency of 100KHz per CPU
+ */

Hi Mike, I think you misspelled the word Maximum here.

Yup, thanks.

Ratelimit performance counter interrupts to 100KHz per CPU.

---
 arch/x86/kernel/apic.c             |    2 +
 arch/x86/kernel/cpu/perf_counter.c |   43 ++++++++++++++++++++++++++++++-------
 include/linux/perf_counter.h       |    2 +
 3 files changed, 40 insertions(+), 7 deletions(-)
arch/x86/kernel/apic.c +2 -0
Index: linux-2.6/arch/x86/kernel/apic.c
===================================================================
@@ -781,6 +781,8 @@ static void local_apic_timer_interrupt(v
 	inc_irq_stat(apic_timer_irqs);
 
 	evt->event_handler(evt);
+
+	perf_counter_unthrottle();
 }
 
 /*
arch/x86/kernel/cpu/perf_counter.c +36 -7

74 lines not on this page · raw message

include/linux/perf_counter.h +2 -0
Index: linux-2.6/include/linux/perf_counter.h
===================================================================
@@ -254,6 +254,7 @@ extern void perf_counter_init_task(struc
 extern void perf_counter_exit_task(struct task_struct *child);
 extern void perf_counter_notify(struct pt_regs *regs);
 extern void perf_counter_print_debug(void);
+extern void perf_counter_unthrottle(void);
 extern u64 hw_perf_save_disable(void);
 extern void hw_perf_restore(u64 ctrl);
 extern int perf_counter_task_disable(void);
@@ -281,6 +282,7 @@ static inline void perf_counter_init_tas
 static inline void perf_counter_exit_task(struct task_struct *child)	{ }
 static inline void perf_counter_notify(struct pt_regs *regs)		{ }
 static inline void perf_counter_print_debug(void)			{ }
+static inline void perf_counter_unthrottle(void)			{ }
 static inline void hw_perf_restore(u64 ctrl)			{ }
 static inline u64 hw_perf_save_disable(void)		      { return 0; }
 static inline int perf_counter_task_disable(void)	{ return -EINVAL; }
Applied
#3 lore raw
Quoted 12 lines · Mike Galbraith
Quoted 6 lines · Rakib Mullick
Quoted 2 lines · Mike Galbraith

+ * Mamimum interrupt frequency of 100KHz per CPU
+ */

Hi Mike, I think you misspelled the word Maximum here.

Yup, thanks.

Ratelimit performance counter interrupts to 100KHz per CPU.

Quoted 7 lines
---
 arch/x86/kernel/apic.c             |    2 +
 arch/x86/kernel/cpu/perf_counter.c |   43 ++++++++++++++++++++++++++++++-------
 include/linux/perf_counter.h       |    2 +
 3 files changed, 40 insertions(+), 7 deletions(-)

Applied to tip/perfcounters/core, thanks Mike!

Ingo