Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 147675
b: refs/heads/master
c: 6a24ed6
h: refs/heads/master
i:
  147673: 8d086a4
  147671: e960f00
v: v3
  • Loading branch information
Peter Zijlstra authored and Ingo Molnar committed Jun 5, 2009
1 parent 374aa1c commit 85f3b63
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 689802b2d0536e72281dc959ab9cb34fb3c304cf
refs/heads/master: 6a24ed6c6082ec65d19331a4bfa30c0512a1a822
3 changes: 3 additions & 0 deletions trunk/include/linux/perf_counter.h
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,9 @@ struct hw_perf_counter {
u64 sample_period;
atomic64_t period_left;
u64 interrupts;

u64 freq_count;
u64 freq_interrupts;
#endif
};

Expand Down
32 changes: 25 additions & 7 deletions trunk/kernel/perf_counter.c
Original file line number Diff line number Diff line change
Expand Up @@ -1187,17 +1187,20 @@ 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);
list_for_each_entry(counter, &ctx->counter_list, list_entry) {
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);
Expand All @@ -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);
}
Expand Down

0 comments on commit 85f3b63

Please sign in to comment.