Re: [PATCH] perf_events: update PEBS event constraints (v2)

From: Stephane Eranian
Date: Wed Mar 02 2011 - 02:45:46 EST


On Wed, Mar 2, 2011 at 1:56 AM, Lin Ming <ming.m.lin@xxxxxxxxx> wrote:
> On Wed, 2011-03-02 at 04:20 +0800, Stephane Eranian wrote:
>> This patch updates PEBS event constraints for Intel Atom, Nehalem, Westmere.
>>
>> This patch also reorganizes the PEBS format/constraint detection code. It is
>> now based on processor model and not PEBS format. Two processors may use the
>> same PEBS format without have the same list of PEBS events.
>>
>> In this second version, we simplified the initialization of the PEBS constraints
>> by leveraging the existing switch() statement in perf_event_intel.c. We also
>> renamed the constraint tables to be more consistent with regular constraints.
>
> Hi, Stephane
>
> Nice updates.
> Wondering where did you get these PEBS event constraints? I didn't find
> these in the latest manual.
>
Yeah, the manual is lacking some information. The other source of information
is the PTU event files (whatif.intel.com).

> And some small things, see below.
>
>>
>> Signed-off-by: Stephane Eranian <eranian@xxxxxxxxxx>
>> ---
>>
>> diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
>> index 084b383..ddf6c4f 100644
>> --- a/arch/x86/kernel/cpu/perf_event_intel.c
>> +++ b/arch/x86/kernel/cpu/perf_event_intel.c
>> @@ -1024,6 +1024,7 @@ static __init int intel_pmu_init(void)
>> Â Â Â Â Â Â Â intel_pmu_lbr_init_core();
>>
>> Â Â Â Â Â Â Â x86_pmu.event_constraints = intel_core2_event_constraints;
>> + Â Â Â Â Â Â x86_pmu.pebs_constraints = intel_core2_pebs_event_constraints;
>> Â Â Â Â Â Â Â pr_cont("Core2 events, ");
>> Â Â Â Â Â Â Â break;
>>
>> @@ -1036,6 +1037,7 @@ static __init int intel_pmu_init(void)
>> Â Â Â Â Â Â Â intel_pmu_lbr_init_nhm();
>>
>> Â Â Â Â Â Â Â x86_pmu.event_constraints = intel_nehalem_event_constraints;
>> + Â Â Â Â Â Â x86_pmu.pebs_constraints = intel_nehalem_pebs_event_constraints;
>> Â Â Â Â Â Â Â x86_pmu.enable_all = intel_pmu_nhm_enable_all;
>> Â Â Â Â Â Â Â pr_cont("Nehalem events, ");
>> Â Â Â Â Â Â Â break;
>> @@ -1047,6 +1049,7 @@ static __init int intel_pmu_init(void)
>> Â Â Â Â Â Â Â intel_pmu_lbr_init_atom();
>>
>> Â Â Â Â Â Â Â x86_pmu.event_constraints = intel_gen_event_constraints;
>> + Â Â Â Â Â Â x86_pmu.pebs_constraints = intel_atom_pebs_event_constraints;
>> Â Â Â Â Â Â Â pr_cont("Atom events, ");
>> Â Â Â Â Â Â Â break;
>>
>> @@ -1059,6 +1062,8 @@ static __init int intel_pmu_init(void)
>>
>> Â Â Â Â Â Â Â x86_pmu.event_constraints = intel_westmere_event_constraints;
>> Â Â Â Â Â Â Â x86_pmu.enable_all = intel_pmu_nhm_enable_all;
>> + Â Â Â Â Â Â x86_pmu.pebs_constraints =
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â intel_westmere_pebs_event_constraints;
>> Â Â Â Â Â Â Â pr_cont("Westmere events, ");
>> Â Â Â Â Â Â Â break;
>>
>> diff --git a/arch/x86/kernel/cpu/perf_event_intel_ds.c b/arch/x86/kernel/cpu/perf_event_intel_ds.c
>> index b7dcd9f..916e6c7 100644
>> --- a/arch/x86/kernel/cpu/perf_event_intel_ds.c
>> +++ b/arch/x86/kernel/cpu/perf_event_intel_ds.c
>> @@ -361,30 +361,49 @@ static int intel_pmu_drain_bts_buffer(void)
>> Â/*
>> Â * PEBS
>> Â */
>> -
>> -static struct event_constraint intel_core_pebs_events[] = {
>> +static struct event_constraint intel_core2_pebs_event_constraints[] = {
>> Â Â Â PEBS_EVENT_CONSTRAINT(0x00c0, 0x1), /* INSTR_RETIRED.ANY */
>> Â Â Â PEBS_EVENT_CONSTRAINT(0xfec1, 0x1), /* X87_OPS_RETIRED.ANY */
>> Â Â Â PEBS_EVENT_CONSTRAINT(0x00c5, 0x1), /* BR_INST_RETIRED.MISPRED */
>> Â Â Â PEBS_EVENT_CONSTRAINT(0x1fc7, 0x1), /* SIMD_INST_RETURED.ANY */
>> - Â Â PEBS_EVENT_CONSTRAINT(0x01cb, 0x1), /* MEM_LOAD_RETIRED.L1D_MISS */
>> - Â Â PEBS_EVENT_CONSTRAINT(0x02cb, 0x1), /* MEM_LOAD_RETIRED.L1D_LINE_MISS */
>> - Â Â PEBS_EVENT_CONSTRAINT(0x04cb, 0x1), /* MEM_LOAD_RETIRED.L2_MISS */
>> - Â Â PEBS_EVENT_CONSTRAINT(0x08cb, 0x1), /* MEM_LOAD_RETIRED.L2_LINE_MISS */
>> - Â Â PEBS_EVENT_CONSTRAINT(0x10cb, 0x1), /* MEM_LOAD_RETIRED.DTLB_MISS */
>> + Â Â INTEL_EVENT_CONSTRAINT(0xcb, 0x1), Â/* MEM_LOAD_RETIRED.* */
>> + Â Â EVENT_CONSTRAINT_END
>> +};
>> +
>> +static struct event_constraint intel_atom_pebs_event_constraints[] = {
>> + Â Â PEBS_EVENT_CONSTRAINT(0x00c0, 0x1), /* INSTR_RETIRED.ANY */
>> + Â Â PEBS_EVENT_CONSTRAINT(0x00c5, 0x1), /* BR_INST_RETIRED.MISPRED */
>> + Â Â PEBS_EVENT_CONSTRAINT(0x0ac4, 0x1), /* BR_INST_RETIRED.MISPRED */
>> + Â Â INTEL_EVENT_CONSTRAINT(0xcb, 0x1), Â/* MEM_LOAD_RETIRED.* */
>> Â Â Â EVENT_CONSTRAINT_END
>> Â};
>>
>> -static struct event_constraint intel_nehalem_pebs_events[] = {
>> - Â Â PEBS_EVENT_CONSTRAINT(0x00c0, 0xf), /* INSTR_RETIRED.ANY */
>> - Â Â PEBS_EVENT_CONSTRAINT(0xfec1, 0xf), /* X87_OPS_RETIRED.ANY */
>> - Â Â PEBS_EVENT_CONSTRAINT(0x00c5, 0xf), /* BR_INST_RETIRED.MISPRED */
>> - Â Â PEBS_EVENT_CONSTRAINT(0x1fc7, 0xf), /* SIMD_INST_RETURED.ANY */
>> - Â Â PEBS_EVENT_CONSTRAINT(0x01cb, 0xf), /* MEM_LOAD_RETIRED.L1D_MISS */
>> - Â Â PEBS_EVENT_CONSTRAINT(0x02cb, 0xf), /* MEM_LOAD_RETIRED.L1D_LINE_MISS */
>> - Â Â PEBS_EVENT_CONSTRAINT(0x04cb, 0xf), /* MEM_LOAD_RETIRED.L2_MISS */
>> - Â Â PEBS_EVENT_CONSTRAINT(0x08cb, 0xf), /* MEM_LOAD_RETIRED.L2_LINE_MISS */
>> - Â Â PEBS_EVENT_CONSTRAINT(0x10cb, 0xf), /* MEM_LOAD_RETIRED.DTLB_MISS */
>> +static struct event_constraint intel_nehalem_pebs_event_constraints[] = {
>> + Â Â INTEL_EVENT_CONSTRAINT(0x0b, 0xf), Â/* MEM_INST_RETIRED.* */
>> + Â Â INTEL_EVENT_CONSTRAINT(0x0f, 0xf), Â/* MEM_UNCORE_RETIRED.* */
>> + Â Â PEBS_EVENT_CONSTRAINT(0x010c, 0xf), /* MEM_STORE_RETIRED.DTLB_MISS */
>> + Â Â INTEL_EVENT_CONSTRAINT(0xc0, 0xf), Â/* INST_RETIRED.ANY */
>> + Â Â INTEL_EVENT_CONSTRAINT(0xc2, 0xf), Â/* UOPS_RETIRED.* */
>> + Â Â INTEL_EVENT_CONSTRAINT(0x00c4, 0xf),/* BR_INST_RETIRED.* */
>
> - INTEL_EVENT_CONSTRAINT(0x00c4, 0xf)
> + INTEL_EVENT_CONSTRAINT(0xc4, 0xf)
>
yep.

>> + Â Â PEBS_EVENT_CONSTRAINT(0x02c5, 0xf), /* BR_MISP_RETIRED.NEAR_CALL */
>> + Â Â INTEL_EVENT_CONSTRAINT(0xc7, 0xf), Â/* SSEX_UOPS_RETIRED.* */
>> + Â Â PEBS_EVENT_CONSTRAINT(0x20c8, 0xf), /* ITLB_MISS_RETIRED */
>> + Â Â INTEL_EVENT_CONSTRAINT(0xcb, 0xf), Â/* MEM_LOAD_RETIRED.* */
>> + Â Â EVENT_CONSTRAINT_END
>> +};
>> +
>> +static struct event_constraint intel_westmere_pebs_event_constraints[] = {
>> + Â Â INTEL_EVENT_CONSTRAINT(0x0b, 0xf), /* MEM_INST_RETIRED.* */
>> + Â Â INTEL_EVENT_CONSTRAINT(0x0f, 0xf), /* MEM_UNCORE_RETIRED.* */
>> + Â Â PEBS_EVENT_CONSTRAINT(0x010c, 0xf), /* MEM_STORE_RETIRED.DTLB_MISS */
>> + Â Â INTEL_EVENT_CONSTRAINT(0xc0, 0xf), Â/* INSTR_RETIRED.* */
>> + Â Â INTEL_EVENT_CONSTRAINT(0xc2, 0xf), Â/* UOPS_RETIRED.* */
>> +
>> + Â Â INTEL_EVENT_CONSTRAINT(0xc4, 0xf), Â/* BR_INST_RETIRED.* */
>> + Â Â INTEL_EVENT_CONSTRAINT(0xc5, 0xf), Â/* BR_MISP_RETIRED.* */
>> + Â Â INTEL_EVENT_CONSTRAINT(0xc7, 0xf), Â/* SSEX_UOPS_RETIRED.* */
>> + Â Â PEBS_EVENT_CONSTRAINT(0x20c8, 0xf), /* ITLB_MISS_RETIRED */
>> + Â Â INTEL_EVENT_CONSTRAINT(0xcb, 0xf), Â/* MEM_LOAD_RETIRED.* */
>> Â Â Â EVENT_CONSTRAINT_END
>> Â};
>>
>> @@ -695,20 +714,18 @@ static void intel_ds_init(void)
>> Â Â Â Â Â Â Â Â Â Â Â 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 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 "no PEBS fmt%d%c, ", format, pebs_type);
>> + Â Â Â Â Â Â Â Â Â Â printk(KERN_CONT "no PEBS fmt%d%c, ",
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Âformat, pebs_type);
>
> No changes?
>
>> Â Â Â Â Â Â Â Â Â Â Â x86_pmu.pebs = 0;
>> - Â Â Â Â Â Â Â Â Â Â break;
>> Â Â Â Â Â Â Â }
>> Â Â Â }
>> Â}
>
>
>
--
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/