[PATCH 09/12] perf/core, x86: use test_and_set_bit() to when grabbing a counter

From: Robert Richter
Date: Fri Jan 22 2010 - 09:56:44 EST


Using test_and_set_bit() in the generic counter allocator makes this
atomic. Otherwise a counter could have been allocated twice.

Signed-off-by: Robert Richter <robert.richter@xxxxxxx>
---
arch/x86/kernel/cpu/perf_event.c | 8 ++++++--
1 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
index 4eb0355..3f81f91 100644
--- a/arch/x86/kernel/cpu/perf_event.c
+++ b/arch/x86/kernel/cpu/perf_event.c
@@ -1395,8 +1395,13 @@ gen_get_event_idx(struct cpu_hw_events *cpuc, struct hw_perf_event *hwc)
{
int idx;

+again:
idx = find_first_zero_bit(cpuc->used_mask, x86_pmu.num_counters);
- return idx == x86_pmu.num_counters ? -1 : idx;
+ if (idx == x86_pmu.num_counters)
+ return -1;
+ if (test_and_set_bit(idx, cpuc->used_mask))
+ goto again;
+ return idx;
}

/*
@@ -1465,7 +1470,6 @@ try_generic:
if (idx == -1)
return -EAGAIN;

- set_bit(idx, cpuc->used_mask);
hwc->idx = idx;
}
hwc->config_base = x86_pmu.eventsel;
--
1.6.6


--
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/