perf_counter: Rework the perf counter disable/enable
Commit-ID: 9e35ad388bea89f7d6f375af4c0ae98803688666 Gitweb: http://git.kernel.org/tip/9e35ad388bea89f7d6f375af4c0ae98803688666 Author: Peter Zijlstra <[email protected]> AuthorDate: Wed, 13 May 2009 16:21:38 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Fri, 15 May 2009 09:47:02 +0200
perf_counter: Rework the perf counter disable/enable
The current disable/enable mechanism is:
token = hw_perf_save_disable(); ... /* do bits */ ... hw_perf_restore(token);
This works well, provided that the use nests properly. Except we don't.
x86 NMI/INT throttling has non-nested use of this, breaking things. Therefore provide a reference counter disable/enable interface, where the first disable disables the hardware, and the last enable enables the hardware again.
[ Impact: refactor, simplify the PMU disable/enable logic ]
LKML-Reference: <new-submission>
--- arch/powerpc/kernel/perf_counter.c | 24 ++++---- arch/x86/kernel/cpu/perf_counter.c | 113 +++++++++++++---------------------- drivers/acpi/processor_idle.c | 6 +- include/linux/perf_counter.h | 10 ++- kernel/perf_counter.c | 76 +++++++++++++++--------- 5 files changed, 109 insertions(+), 120 deletions(-)
arch/powerpc/kernel/perf_counter.c +12 -12
@@ -386,7 +386,7 @@ static void write_mmcr0(struct cpu_hw_counters *cpuhw, unsigned long mmcr0)* Disable all counters to prevent PMU interrupts and to allow * counters to be added or removed. */ -u64 hw_perf_save_disable (void ) +void hw_perf_disable (void ) {struct cpu_hw_counters *cpuhw;unsigned long ret;
@@ -428,7 +428,6 @@ u64 hw_perf_save_disable(void)mb (); }local_irq_restore (flags); -return ret; }/*
@@ -436,7 +435,7 @@ u64 hw_perf_save_disable(void)* If we were previously disabled and counters were added, then * put the new config on the PMU. */ -void hw_perf_restore (u64 disable) +void hw_perf_enable (void ) {struct perf_counter *counter;struct cpu_hw_counters *cpuhw;
@@ -448,9 +447,12 @@ void hw_perf_restore(u64 disable)int n_lim;int idx; -if (disable) -return ;local_irq_save (flags); +if (!cpuhw->disabled) { +local_irq_restore (flags); +return ; + } + cpuhw = &__get_cpu_var (cpu_hw_counters); cpuhw->disabled =0 ;
@@ -649,19 +651,18 @@ int hw_perf_group_sched_in(struct perf_counter *group_leader,/* * Add a counter to the PMU. * If all counters are not already frozen, then we disable and -* re-enable the PMU in order to get hw_perf_restore to do the +* re-enable the PMU in order to get hw_perf_enable to do the * actual work of reconfiguring the PMU. */ static int power_pmu_enable (struct perf_counter *counter) {struct cpu_hw_counters *cpuhw;unsigned long flags; -u64 pmudis;int n0;int ret = -EAGAIN ;local_irq_save (flags); - pmudis =hw_perf_save_disable (); +perf_disable ();/* * Add the counter to the list (if there is room)
@@ -685,7 +686,7 @@ static int power_pmu_enable(struct perf_counter *counter) ret =0 ; out: -hw_perf_restore (pmudis); +perf_enable ();local_irq_restore (flags);return ret; }
@@ -697,11 +698,10 @@ static void power_pmu_disable(struct perf_counter *counter) {struct cpu_hw_counters *cpuhw;long i; -u64 pmudis;unsigned long flags;local_irq_save (flags); - pmudis =hw_perf_save_disable (); +perf_disable ();power_pmu_read (counter);
@@ -735,7 +735,7 @@ static void power_pmu_disable(struct perf_counter *counter) cpuhw->mmcr[0 ] &= ~(MMCR0_PMXE |MMCR0_FCECE ); } -hw_perf_restore (pmudis); +perf_enable ();local_irq_restore (flags); }
arch/x86/kernel/cpu/perf_counter.c +42 -71
237 lines not on this page · raw message
drivers/acpi/processor_idle.c +2 -4
@@ -763,11 +763,9 @@ static int acpi_idle_bm_check(void)*/ static inline void acpi_idle_do_entry (struct acpi_processor_cx *cx) { -u64 perf_flags; -/* Don't trace irqs off for idle */ stop_critical_timings (); - perf_flags =hw_perf_save_disable (); +perf_disable ();if (cx->entry_method ==ACPI_CSTATE_FFH ) {/* Call into architectural FFH based C-state */ acpi_processor_ffh_cstate_enter (cx);
@@ -782,7 +780,7 @@ static inline void acpi_idle_do_entry(struct acpi_processor_cx *cx)gets asserted in time to freeze execution properly. */ unused =inl (acpi_gbl_FADT.xpm_timer_block.address); } -hw_perf_restore (perf_flags); +perf_enable ();start_critical_timings (); }
include/linux/perf_counter.h +6 -4
@@ -544,8 +544,10 @@ extern void perf_counter_exit_task(struct task_struct *child);extern void perf_counter_do_pending (void );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 void __perf_disable (void ); +extern bool __perf_enable (void ); +extern void perf_disable (void ); +extern void perf_enable (void );extern int perf_counter_task_disable (void );extern int perf_counter_task_enable (void ); extern int hw_perf_group_sched_in(struct perf_counter *group_leader,
@@ -600,8 +602,8 @@ static inline void perf_counter_exit_task(struct task_struct *child) { }static inline void perf_counter_do_pending (void ) { }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 void perf_disable (void ) { } +static inline void perf_enable (void ) { }static inline int perf_counter_task_disable (void ) {return -EINVAL ; }static inline int perf_counter_task_enable (void ) {return -EINVAL ; }
kernel/perf_counter.c +47 -29
241 lines not on this page · raw message
Quoted 3 lines · tip-bot for Peter Zijlstra
x86 NMI/INT throttling has non-nested use of this, breaking things. Therefore provide a reference counter disable/enable interface, where the first disable disables the hardware, and the last enable enables the hardware again.
It looks to me like what you've done for powerpc enables the hardware again on the first enable, not the last one:
Quoted 13 lines
arch/powerpc/kernel/perf_counter.c +1
-1@@ -436,7 +435,7 @@ u64 hw_perf_save_disable(void)* If we were previously disabled and counters were added, then * put the new config on the PMU. */ -void hw_perf_restore (u64 disable) +void hw_perf_enable (void ) {struct perf_counter *counter;struct cpu_hw_counters *cpuhw;@@ -448,9 +447,12 @@ void hw_perf_restore(u64 disable)int n_lim;int idx;
arch/powerpc/kernel/perf_counter.c void hw_perf_restore(u64 disable) · line 457
Quoted 10 lines
arch/powerpc/kernel/perf_counter.c +5
-2-if (disable) -return ;local_irq_save (flags); +if (!cpuhw->disabled) { +local_irq_restore (flags); +return ; + } + cpuhw = &__get_cpu_var (cpu_hw_counters); cpuhw->disabled =0 ;
I do rely on nesting the disable/enable calls and only having the hardware re-enabled on the last enable. I can't see anything here that detects the last enable. Have I missed it somewhere?
Paul.
Quoted 22 lines · Paul Mackerras
Quoted 3 lines · tip-bot for Peter Zijlstra
x86 NMI/INT throttling has non-nested use of this, breaking things. Therefore provide a reference counter disable/enable interface, where the first disable disables the hardware, and the last enable enables the hardware again.
It looks to me like what you've done for powerpc enables the hardware again on the first enable, not the last one:
Quoted 13 lines
arch/powerpc/kernel/perf_counter.c +1
-1@@ -436,7 +435,7 @@ u64 hw_perf_save_disable(void)* If we were previously disabled and counters were added, then * put the new config on the PMU. */ -void hw_perf_restore (u64 disable) +void hw_perf_enable (void ) {struct perf_counter *counter;struct cpu_hw_counters *cpuhw;@@ -448,9 +447,12 @@ void hw_perf_restore(u64 disable)int n_lim;int idx;
Quoted 14 lines
arch/powerpc/kernel/perf_counter.c void hw_perf_restore(u64 disable) · line 457
Quoted 10 lines
arch/powerpc/kernel/perf_counter.c +5
-2-if (disable) -return ;local_irq_save (flags); +if (!cpuhw->disabled) { +local_irq_restore (flags); +return ; + } + cpuhw = &__get_cpu_var (cpu_hw_counters); cpuhw->disabled =0 ;I do rely on nesting the disable/enable calls and only having the hardware re-enabled on the last enable. I can't see anything here that detects the last enable. Have I missed it somewhere?
+void perf_disable(void)
+{
+ __perf_disable();
+ hw_perf_disable();
+}
+void perf_enable(void)
+{
+ if (__perf_enable())
+ hw_perf_enable();
+}