aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Galbraith <efault@gmx.de>2009-01-23 04:13:01 -0500
committerIngo Molnar <mingo@elte.hu>2009-01-23 05:33:18 -0500
commit1b023a96d9b44f50f4d8ff28c15f5b80e354760f (patch)
tree8b6a5956c4461c13c2e2b3769096afac5b767524
parent05e3423c8577126800841bc55de8a509f2433dca (diff)
perfcounters: throttle on too high IRQ rates
Starting kerneltop with only -c 100 seems to be a bad idea, it can easily lock the system due to perfcounter IRQ overload. So add throttling: if a new IRQ arrives in a shorter than PERFMON_MIN_PERIOD_NS time, turn off perfcounters and untrottle them from the next timer tick. Signed-off-by: Mike Galbraith <efault@gmx.de> Signed-off-by: Ingo Molnar <mingo@elte.hu>
-rw-r--r--arch/x86/kernel/apic.c2
-rw-r--r--arch/x86/kernel/cpu/perf_counter.c38
-rw-r--r--include/linux/perf_counter.h4
3 files changed, 38 insertions, 6 deletions
diff --git a/arch/x86/kernel/apic.c b/arch/x86/kernel/apic.c
index 7b434e5b14c9..849c23009bf5 100644
--- a/arch/x86/kernel/apic.c
+++ b/arch/x86/kernel/apic.c
@@ -781,6 +781,8 @@ static void local_apic_timer_interrupt(void)
781 inc_irq_stat(apic_timer_irqs); 781 inc_irq_stat(apic_timer_irqs);
782 782
783 evt->event_handler(evt); 783 evt->event_handler(evt);
784
785 perf_counter_unthrottle();
784} 786}
785 787
786/* 788/*
diff --git a/arch/x86/kernel/cpu/perf_counter.c b/arch/x86/kernel/cpu/perf_counter.c
index 9376771f757b..1a040b179b53 100644
--- a/arch/x86/kernel/cpu/perf_counter.c
+++ b/arch/x86/kernel/cpu/perf_counter.c
@@ -33,6 +33,9 @@ static int nr_counters_fixed __read_mostly;
33struct cpu_hw_counters { 33struct cpu_hw_counters {
34 struct perf_counter *counters[X86_PMC_IDX_MAX]; 34 struct perf_counter *counters[X86_PMC_IDX_MAX];
35 unsigned long used[BITS_TO_LONGS(X86_PMC_IDX_MAX)]; 35 unsigned long used[BITS_TO_LONGS(X86_PMC_IDX_MAX)];
36 u64 last_interrupt;
37 u64 global_enable;
38 int throttled;
36}; 39};
37 40
38/* 41/*
@@ -474,16 +477,19 @@ perf_handle_group(struct perf_counter *sibling, u64 *status, u64 *overflown)
474static void __smp_perf_counter_interrupt(struct pt_regs *regs, int nmi) 477static void __smp_perf_counter_interrupt(struct pt_regs *regs, int nmi)
475{ 478{
476 int bit, cpu = smp_processor_id(); 479 int bit, cpu = smp_processor_id();
477 u64 ack, status, saved_global; 480 u64 ack, status, now;
478 struct cpu_hw_counters *cpuc; 481 struct cpu_hw_counters *cpuc = &per_cpu(cpu_hw_counters, cpu);
479 482
480 rdmsrl(MSR_CORE_PERF_GLOBAL_CTRL, saved_global); 483 rdmsrl(MSR_CORE_PERF_GLOBAL_CTRL, cpuc->global_enable);
481 484
482 /* Disable counters globally */ 485 /* Disable counters globally */
483 wrmsrl(MSR_CORE_PERF_GLOBAL_CTRL, 0); 486 wrmsrl(MSR_CORE_PERF_GLOBAL_CTRL, 0);
484 ack_APIC_irq(); 487 ack_APIC_irq();
485 488
486 cpuc = &per_cpu(cpu_hw_counters, cpu); 489 now = sched_clock();
490 if (now - cpuc->last_interrupt < PERFMON_MIN_PERIOD_NS)
491 cpuc->throttled = 1;
492 cpuc->last_interrupt = now;
487 493
488 rdmsrl(MSR_CORE_PERF_GLOBAL_STATUS, status); 494 rdmsrl(MSR_CORE_PERF_GLOBAL_STATUS, status);
489 if (!status) 495 if (!status)
@@ -533,9 +539,29 @@ again:
533 goto again; 539 goto again;
534out: 540out:
535 /* 541 /*
536 * Restore - do not reenable when global enable is off: 542 * Restore - do not reenable when global enable is off or throttled:
537 */ 543 */
538 wrmsrl(MSR_CORE_PERF_GLOBAL_CTRL, saved_global); 544 if (!cpuc->throttled)
545 wrmsrl(MSR_CORE_PERF_GLOBAL_CTRL, cpuc->global_enable);
546}
547
548void perf_counter_unthrottle(void)
549{
550 struct cpu_hw_counters *cpuc;
551
552 if (!cpu_has(&boot_cpu_data, X86_FEATURE_ARCH_PERFMON))
553 return;
554
555 if (unlikely(!perf_counters_initialized))
556 return;
557
558 cpuc = &per_cpu(cpu_hw_counters, smp_processor_id());
559 if (cpuc->throttled) {
560 if (printk_ratelimit())
561 printk(KERN_WARNING "PERFMON: max event frequency exceeded!\n");
562 wrmsrl(MSR_CORE_PERF_GLOBAL_CTRL, cpuc->global_enable);
563 cpuc->throttled = 0;
564 }
539} 565}
540 566
541void smp_perf_counter_interrupt(struct pt_regs *regs) 567void smp_perf_counter_interrupt(struct pt_regs *regs)
diff --git a/include/linux/perf_counter.h b/include/linux/perf_counter.h
index 33ba9fe0a781..91f1ca4c01c0 100644
--- a/include/linux/perf_counter.h
+++ b/include/linux/perf_counter.h
@@ -254,6 +254,7 @@ extern void perf_counter_init_task(struct task_struct *child);
254extern void perf_counter_exit_task(struct task_struct *child); 254extern void perf_counter_exit_task(struct task_struct *child);
255extern void perf_counter_notify(struct pt_regs *regs); 255extern void perf_counter_notify(struct pt_regs *regs);
256extern void perf_counter_print_debug(void); 256extern void perf_counter_print_debug(void);
257extern void perf_counter_unthrottle(void);
257extern u64 hw_perf_save_disable(void); 258extern u64 hw_perf_save_disable(void);
258extern void hw_perf_restore(u64 ctrl); 259extern void hw_perf_restore(u64 ctrl);
259extern int perf_counter_task_disable(void); 260extern int perf_counter_task_disable(void);
@@ -270,6 +271,8 @@ static inline int is_software_counter(struct perf_counter *counter)
270 return !counter->hw_event.raw && counter->hw_event.type < 0; 271 return !counter->hw_event.raw && counter->hw_event.type < 0;
271} 272}
272 273
274#define PERFMON_MIN_PERIOD_NS 10000
275
273#else 276#else
274static inline void 277static inline void
275perf_counter_task_sched_in(struct task_struct *task, int cpu) { } 278perf_counter_task_sched_in(struct task_struct *task, int cpu) { }
@@ -281,6 +284,7 @@ static inline void perf_counter_init_task(struct task_struct *child) { }
281static inline void perf_counter_exit_task(struct task_struct *child) { } 284static inline void perf_counter_exit_task(struct task_struct *child) { }
282static inline void perf_counter_notify(struct pt_regs *regs) { } 285static inline void perf_counter_notify(struct pt_regs *regs) { }
283static inline void perf_counter_print_debug(void) { } 286static inline void perf_counter_print_debug(void) { }
287static inline void perf_counter_unthrottle(void) { }
284static inline void hw_perf_restore(u64 ctrl) { } 288static inline void hw_perf_restore(u64 ctrl) { }
285static inline u64 hw_perf_save_disable(void) { return 0; } 289static inline u64 hw_perf_save_disable(void) { return 0; }
286static inline int perf_counter_task_disable(void) { return -EINVAL; } 290static inline int perf_counter_task_disable(void) { return -EINVAL; }