Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 191053
b: refs/heads/master
c: 8db909a
h: refs/heads/master
i:
  191051: ed33727
v: v3
  • Loading branch information
Peter Zijlstra authored and Ingo Molnar committed Mar 10, 2010
1 parent a5ec7fa commit 97f02b3
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 32 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: 1676b8a077c352085d52578fb4f29350b58b6e74
refs/heads/master: 8db909a7e3c888b5d45aef7650d74ccebe3ce725
15 changes: 13 additions & 2 deletions trunk/arch/x86/kernel/cpu/perf_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,17 @@ struct cpu_hw_events {
#define for_each_event_constraint(e, c) \
for ((e) = (c); (e)->cmask; (e)++)

union perf_capabilities {
struct {
u64 lbr_format : 6;
u64 pebs_trap : 1;
u64 pebs_arch_reg : 1;
u64 pebs_format : 4;
u64 smm_freeze : 1;
};
u64 capabilities;
};

/*
* struct x86_pmu - generic x86 pmu
*/
Expand Down Expand Up @@ -195,7 +206,8 @@ struct x86_pmu {
/*
* Intel Arch Perfmon v2+
*/
u64 intel_ctrl;
u64 intel_ctrl;
union perf_capabilities intel_cap;

/*
* Intel DebugStore bits
Expand All @@ -210,7 +222,6 @@ struct x86_pmu {
*/
unsigned long lbr_tos, lbr_from, lbr_to; /* MSR base regs */
int lbr_nr; /* hardware stack size */
int lbr_format; /* hardware format */
};

static struct x86_pmu x86_pmu __read_mostly;
Expand Down
10 changes: 10 additions & 0 deletions trunk/arch/x86/kernel/cpu/perf_event_intel.c
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,16 @@ static __init int intel_pmu_init(void)
if (version > 1)
x86_pmu.num_events_fixed = max((int)edx.split.num_events_fixed, 3);

/*
* v2 and above have a perf capabilities MSR
*/
if (version > 1) {
u64 capabilities;

rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
x86_pmu.intel_cap.capabilities = capabilities;
}

intel_ds_init();

/*
Expand Down
30 changes: 15 additions & 15 deletions trunk/arch/x86/kernel/cpu/perf_event_intel_ds.c
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,8 @@ static void intel_pmu_pebs_enable(struct perf_event *event)
val |= 1ULL << hwc->idx;
wrmsrl(MSR_IA32_PEBS_ENABLE, val);

intel_pmu_lbr_enable(event);
if (x86_pmu.intel_cap.pebs_trap)
intel_pmu_lbr_enable(event);
}

static void intel_pmu_pebs_disable(struct perf_event *event)
Expand All @@ -356,7 +357,8 @@ static void intel_pmu_pebs_disable(struct perf_event *event)

hwc->config |= ARCH_PERFMON_EVENTSEL_INT;

intel_pmu_lbr_disable(event);
if (x86_pmu.intel_cap.pebs_trap)
intel_pmu_lbr_disable(event);
}

static void intel_pmu_pebs_enable_all(void)
Expand Down Expand Up @@ -395,6 +397,12 @@ static int intel_pmu_pebs_fixup_ip(struct pt_regs *regs)
unsigned long old_to, to = cpuc->lbr_entries[0].to;
unsigned long ip = regs->ip;

/*
* We don't need to fixup if the PEBS assist is fault like
*/
if (!x86_pmu.intel_cap.pebs_trap)
return 1;

if (!cpuc->lbr_stack.nr || !from || !to)
return 0;

Expand Down Expand Up @@ -589,34 +597,26 @@ static void intel_ds_init(void)
x86_pmu.bts = boot_cpu_has(X86_FEATURE_BTS);
x86_pmu.pebs = boot_cpu_has(X86_FEATURE_PEBS);
if (x86_pmu.pebs) {
int format = 0;

if (x86_pmu.version > 1) {
u64 capabilities;
/*
* v2+ has a PEBS format field
*/
rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
format = (capabilities >> 8) & 0xf;
}
char pebs_type = x86_pmu.intel_cap.pebs_trap ? '+' : '-';
int format = x86_pmu.intel_cap.pebs_format;

switch (format) {
case 0:
printk(KERN_CONT "PEBS v0, ");
printk(KERN_CONT "PEBS fmt0%c, ", pebs_type);
x86_pmu.pebs_record_size = sizeof(struct pebs_record_core);
x86_pmu.drain_pebs = intel_pmu_drain_pebs_core;
x86_pmu.pebs_constraints = intel_core_pebs_events;
break;

case 1:
printk(KERN_CONT "PEBS v1, ");
printk(KERN_CONT "PEBS fmt1%c, ", pebs_type);
x86_pmu.pebs_record_size = sizeof(struct pebs_record_nhm);
x86_pmu.drain_pebs = intel_pmu_drain_pebs_nhm;
x86_pmu.pebs_constraints = intel_nehalem_pebs_events;
break;

default:
printk(KERN_CONT "PEBS unknown format: %d, ", format);
printk(KERN_CONT "no PEBS fmt%d%c, ", format, pebs_type);
x86_pmu.pebs = 0;
break;
}
Expand Down
18 changes: 4 additions & 14 deletions trunk/arch/x86/kernel/cpu/perf_event_intel_lbr.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ static void intel_pmu_lbr_reset_64(void)

static void intel_pmu_lbr_reset(void)
{
if (x86_pmu.lbr_format == LBR_FORMAT_32)
if (x86_pmu.intel_cap.lbr_format == LBR_FORMAT_32)
intel_pmu_lbr_reset_32();
else
intel_pmu_lbr_reset_64();
Expand Down Expand Up @@ -155,6 +155,7 @@ static void intel_pmu_lbr_read_32(struct cpu_hw_events *cpuc)
static void intel_pmu_lbr_read_64(struct cpu_hw_events *cpuc)
{
unsigned long mask = x86_pmu.lbr_nr - 1;
int lbr_format = x86_pmu.intel_cap.lbr_format;
u64 tos = intel_pmu_lbr_tos();
int i;

Expand All @@ -165,7 +166,7 @@ static void intel_pmu_lbr_read_64(struct cpu_hw_events *cpuc)
rdmsrl(x86_pmu.lbr_from + lbr_idx, from);
rdmsrl(x86_pmu.lbr_to + lbr_idx, to);

if (x86_pmu.lbr_format == LBR_FORMAT_EIP_FLAGS) {
if (lbr_format == LBR_FORMAT_EIP_FLAGS) {
flags = !!(from & LBR_FROM_FLAG_MISPRED);
from = (u64)((((s64)from) << 1) >> 1);
}
Expand All @@ -184,23 +185,14 @@ static void intel_pmu_lbr_read(void)
if (!cpuc->lbr_users)
return;

if (x86_pmu.lbr_format == LBR_FORMAT_32)
if (x86_pmu.intel_cap.lbr_format == LBR_FORMAT_32)
intel_pmu_lbr_read_32(cpuc);
else
intel_pmu_lbr_read_64(cpuc);
}

static int intel_pmu_lbr_format(void)
{
u64 capabilities;

rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
return capabilities & 0x1f;
}

static void intel_pmu_lbr_init_core(void)
{
x86_pmu.lbr_format = intel_pmu_lbr_format();
x86_pmu.lbr_nr = 4;
x86_pmu.lbr_tos = 0x01c9;
x86_pmu.lbr_from = 0x40;
Expand All @@ -209,7 +201,6 @@ static void intel_pmu_lbr_init_core(void)

static void intel_pmu_lbr_init_nhm(void)
{
x86_pmu.lbr_format = intel_pmu_lbr_format();
x86_pmu.lbr_nr = 16;
x86_pmu.lbr_tos = 0x01c9;
x86_pmu.lbr_from = 0x680;
Expand All @@ -218,7 +209,6 @@ static void intel_pmu_lbr_init_nhm(void)

static void intel_pmu_lbr_init_atom(void)
{
x86_pmu.lbr_format = intel_pmu_lbr_format();
x86_pmu.lbr_nr = 8;
x86_pmu.lbr_tos = 0x01c9;
x86_pmu.lbr_from = 0x40;
Expand Down

0 comments on commit 97f02b3

Please sign in to comment.