[PATCH] perf_counter: fix possible /0 bug in swcounters

From: Peter Zijlstra
Date: Fri Aug 28 2009 - 11:10:58 EST


We have a race in the swcounter stuff where we can start counting a
counter that has never been enabled, this leads to a /0 situation.

The below avoids the /0 but doesn't close the race, this would need a
new counter state.

The race is due to perf_swcounter_is_counting() which cannot discern
between disabled due to scheduled out, and disabled for any other
reason.

Signed-off-by: Peter Zijlstra <a.p.zijlstra@xxxxxxxxx>
---
kernel/perf_counter.c | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/kernel/perf_counter.c b/kernel/perf_counter.c
index 53abcbe..2b90d26 100644
--- a/kernel/perf_counter.c
+++ b/kernel/perf_counter.c
@@ -4103,6 +4103,7 @@ perf_counter_alloc(struct perf_counter_attr *attr,
hwc->sample_period = attr->sample_period;
if (attr->freq && attr->sample_freq)
hwc->sample_period = 1;
+ hwc->last_period = hwc->sample_period;

atomic64_set(&hwc->period_left, hwc->sample_period);



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