Re: per-cpu operation madness vs validation

From: Christoph Lameter
Date: Wed Jul 27 2011 - 13:04:27 EST


On Wed, 27 Jul 2011, Peter Zijlstra wrote:

> Also things like the below hunk are just plain ugly and obfuscate the
> code to safe one load at best. I'm sorely tempted to revert such crap.
>
> @@ -1468,14 +1465,12 @@ static void x86_pmu_start_txn(struct pmu *pmu)
> */
> static void x86_pmu_cancel_txn(struct pmu *pmu)
> {
> - struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
> -
> - cpuc->group_flag &= ~PERF_EVENT_TXN;
> + __this_cpu_and(cpu_hw_events.group_flag, ~PERF_EVENT_TXN);
> /*
> * Truncate the collected events.
> */
> - cpuc->n_added -= cpuc->n_txn;
> - cpuc->n_events -= cpuc->n_txn;
> + __this_cpu_sub(cpu_hw_events.n_added, __this_cpu_read(cpu_hw_events.n_txn));
> + __this_cpu_sub(cpu_hw_events.n_events, __this_cpu_read(cpu_hw_events.n_txn));
> perf_pmu_enable(pmu);
> }

Yea that is pretty ugly and went overboard. Too many segment
overrides there. The following patch will make that easier to read. We
could also remove the whole hunk. __this_cpu ops there only causes the
generation of simple xadds avoiding register operations.

---
arch/x86/kernel/cpu/perf_event.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

Index: linux-2.6/arch/x86/kernel/cpu/perf_event.c
===================================================================
--- linux-2.6.orig/arch/x86/kernel/cpu/perf_event.c 2011-07-27 11:59:35.000000000 -0500
+++ linux-2.6/arch/x86/kernel/cpu/perf_event.c 2011-07-27 12:03:41.000000000 -0500
@@ -1612,12 +1612,14 @@ static void x86_pmu_start_txn(struct pmu
*/
static void x86_pmu_cancel_txn(struct pmu *pmu)
{
+ int x = __this_cpu_read(cpu_hw_events.n_txn);
+
__this_cpu_and(cpu_hw_events.group_flag, ~PERF_EVENT_TXN);
/*
* Truncate the collected events.
*/
- __this_cpu_sub(cpu_hw_events.n_added, __this_cpu_read(cpu_hw_events.n_txn));
- __this_cpu_sub(cpu_hw_events.n_events, __this_cpu_read(cpu_hw_events.n_txn));
+ __this_cpu_sub(cpu_hw_events.n_added, x);
+ __this_cpu_sub(cpu_hw_events.n_events, x);
perf_pmu_enable(pmu);
}





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