aboutsummaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorPeter Zijlstra <a.p.zijlstra@chello.nl>2009-06-05 18:01:29 +0200
committerIngo Molnar <mingo@elte.hu>2009-06-05 18:07:48 +0200
commit6a24ed6c6082ec65d19331a4bfa30c0512a1a822 (patch)
tree0d8beed316cf34cd8e986eb2f9b230a29caa6c88 /kernel
parent689802b2d0536e72281dc959ab9cb34fb3c304cf (diff)
perf_counter: Fix frequency adjustment for < HZ
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Mike Galbraith <efault@gmx.de> Cc: Paul Mackerras <paulus@samba.org> Cc: Arnaldo Carvalho de Melo <acme@redhat.com> LKML-Reference: <new-submission> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/perf_counter.c32
1 files changed, 25 insertions, 7 deletions
diff --git a/kernel/perf_counter.c b/kernel/perf_counter.c
index f8390668c39..47c92fb927f 100644
--- a/kernel/perf_counter.c
+++ b/kernel/perf_counter.c
@@ -1187,8 +1187,9 @@ static void perf_log_period(struct perf_counter *counter, u64 period);
static void perf_adjust_freq(struct perf_counter_context *ctx)
{
struct perf_counter *counter;
+ struct hw_perf_counter *hwc;
u64 interrupts, sample_period;
- u64 events, period;
+ u64 events, period, freq;
s64 delta;
spin_lock(&ctx->lock);
@@ -1196,8 +1197,10 @@ static void perf_adjust_freq(struct perf_counter_context *ctx)
if (counter->state != PERF_COUNTER_STATE_ACTIVE)
continue;
- interrupts = counter->hw.interrupts;
- counter->hw.interrupts = 0;
+ hwc = &counter->hw;
+
+ interrupts = hwc->interrupts;
+ hwc->interrupts = 0;
if (interrupts == MAX_INTERRUPTS) {
perf_log_throttle(counter, 1);
@@ -1208,20 +1211,35 @@ static void perf_adjust_freq(struct perf_counter_context *ctx)
if (!counter->attr.freq || !counter->attr.sample_freq)
continue;
- events = HZ * interrupts * counter->hw.sample_period;
+ if (counter->attr.sample_freq < HZ) {
+ freq = counter->attr.sample_freq;
+
+ hwc->freq_count += freq;
+ hwc->freq_interrupts += interrupts;
+
+ if (hwc->freq_count < HZ)
+ continue;
+
+ interrupts = hwc->freq_interrupts;
+ hwc->freq_interrupts = 0;
+ hwc->freq_count -= HZ;
+ } else
+ freq = HZ;
+
+ events = freq * interrupts * hwc->sample_period;
period = div64_u64(events, counter->attr.sample_freq);
- delta = (s64)(1 + period - counter->hw.sample_period);
+ delta = (s64)(1 + period - hwc->sample_period);
delta >>= 1;
- sample_period = counter->hw.sample_period + delta;
+ sample_period = hwc->sample_period + delta;
if (!sample_period)
sample_period = 1;
perf_log_period(counter, sample_period);
- counter->hw.sample_period = sample_period;
+ hwc->sample_period = sample_period;
}
spin_unlock(&ctx->lock);
}