Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 147204
b: refs/heads/master
c: 1b023a9
h: refs/heads/master
v: v3
  • Loading branch information
Mike Galbraith authored and Ingo Molnar committed Jan 23, 2009
1 parent 72062ca commit f1ef0fe
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 7 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: 05e3423c8577126800841bc55de8a509f2433dca
refs/heads/master: 1b023a96d9b44f50f4d8ff28c15f5b80e354760f
2 changes: 2 additions & 0 deletions trunk/arch/x86/kernel/apic.c
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,8 @@ static void local_apic_timer_interrupt(void)
inc_irq_stat(apic_timer_irqs);

evt->event_handler(evt);

perf_counter_unthrottle();
}

/*
Expand Down
38 changes: 32 additions & 6 deletions trunk/arch/x86/kernel/cpu/perf_counter.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ static int nr_counters_fixed __read_mostly;
struct cpu_hw_counters {
struct perf_counter *counters[X86_PMC_IDX_MAX];
unsigned long used[BITS_TO_LONGS(X86_PMC_IDX_MAX)];
u64 last_interrupt;
u64 global_enable;
int throttled;
};

/*
Expand Down Expand Up @@ -474,16 +477,19 @@ perf_handle_group(struct perf_counter *sibling, u64 *status, u64 *overflown)
static void __smp_perf_counter_interrupt(struct pt_regs *regs, int nmi)
{
int bit, cpu = smp_processor_id();
u64 ack, status, saved_global;
struct cpu_hw_counters *cpuc;
u64 ack, status, now;
struct cpu_hw_counters *cpuc = &per_cpu(cpu_hw_counters, cpu);

rdmsrl(MSR_CORE_PERF_GLOBAL_CTRL, saved_global);
rdmsrl(MSR_CORE_PERF_GLOBAL_CTRL, cpuc->global_enable);

/* Disable counters globally */
wrmsrl(MSR_CORE_PERF_GLOBAL_CTRL, 0);
ack_APIC_irq();

cpuc = &per_cpu(cpu_hw_counters, cpu);
now = sched_clock();
if (now - cpuc->last_interrupt < PERFMON_MIN_PERIOD_NS)
cpuc->throttled = 1;
cpuc->last_interrupt = now;

rdmsrl(MSR_CORE_PERF_GLOBAL_STATUS, status);
if (!status)
Expand Down Expand Up @@ -533,9 +539,29 @@ static void __smp_perf_counter_interrupt(struct pt_regs *regs, int nmi)
goto again;
out:
/*
* Restore - do not reenable when global enable is off:
* Restore - do not reenable when global enable is off or throttled:
*/
wrmsrl(MSR_CORE_PERF_GLOBAL_CTRL, saved_global);
if (!cpuc->throttled)
wrmsrl(MSR_CORE_PERF_GLOBAL_CTRL, cpuc->global_enable);
}

void perf_counter_unthrottle(void)
{
struct cpu_hw_counters *cpuc;

if (!cpu_has(&boot_cpu_data, X86_FEATURE_ARCH_PERFMON))
return;

if (unlikely(!perf_counters_initialized))
return;

cpuc = &per_cpu(cpu_hw_counters, smp_processor_id());
if (cpuc->throttled) {
if (printk_ratelimit())
printk(KERN_WARNING "PERFMON: max event frequency exceeded!\n");
wrmsrl(MSR_CORE_PERF_GLOBAL_CTRL, cpuc->global_enable);
cpuc->throttled = 0;
}
}

void smp_perf_counter_interrupt(struct pt_regs *regs)
Expand Down
4 changes: 4 additions & 0 deletions trunk/include/linux/perf_counter.h
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ extern void perf_counter_init_task(struct task_struct *child);
extern void perf_counter_exit_task(struct task_struct *child);
extern void perf_counter_notify(struct pt_regs *regs);
extern void perf_counter_print_debug(void);
extern void perf_counter_unthrottle(void);
extern u64 hw_perf_save_disable(void);
extern void hw_perf_restore(u64 ctrl);
extern int perf_counter_task_disable(void);
Expand All @@ -270,6 +271,8 @@ static inline int is_software_counter(struct perf_counter *counter)
return !counter->hw_event.raw && counter->hw_event.type < 0;
}

#define PERFMON_MIN_PERIOD_NS 10000

#else
static inline void
perf_counter_task_sched_in(struct task_struct *task, int cpu) { }
Expand All @@ -281,6 +284,7 @@ static inline void perf_counter_init_task(struct task_struct *child) { }
static inline void perf_counter_exit_task(struct task_struct *child) { }
static inline void perf_counter_notify(struct pt_regs *regs) { }
static inline void perf_counter_print_debug(void) { }
static inline void perf_counter_unthrottle(void) { }
static inline void hw_perf_restore(u64 ctrl) { }
static inline u64 hw_perf_save_disable(void) { return 0; }
static inline int perf_counter_task_disable(void) { return -EINVAL; }
Expand Down

0 comments on commit f1ef0fe

Please sign in to comment.