Re: [PATCH 12/12] perf, x86: implement the ibs interrupt handler

From: Stephane Eranian
Date: Mon Apr 19 2010 - 08:20:12 EST


Robert,

Some comments below.

On Tue, Apr 13, 2010 at 10:23 PM, Robert Richter <robert.richter@xxxxxxx> wrote:
> This patch implements code to handle ibs interrupts. If ibs data is
> available a raw perf_event data sample is created and sent back to the
> userland. Currently only the data is stored only in the raw data, but
> this could be extended in a later patch by generating generic event
> data such as the rip from the ibs sampling data.
>
> Signed-off-by: Robert Richter <robert.richter@xxxxxxx>
> ---
> Âarch/x86/include/asm/msr-index.h   |  Â3 ++
> Âarch/x86/kernel/cpu/perf_event_amd.c | Â 65 +++++++++++++++++++++++++++++++++-
> Â2 files changed, 67 insertions(+), 1 deletions(-)
>
> diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-index.h
> index bc473ac..a7e4aa5 100644
> --- a/arch/x86/include/asm/msr-index.h
> +++ b/arch/x86/include/asm/msr-index.h
> @@ -113,6 +113,7 @@
> Â#define MSR_AMD64_IBSFETCHCTL Â Â Â Â Â0xc0011030
> Â#define MSR_AMD64_IBSFETCHLINAD Â Â Â Â Â Â Â Â0xc0011031
> Â#define MSR_AMD64_IBSFETCHPHYSAD Â Â Â 0xc0011032
> +#define MSR_AMD64_IBSFETCH_SIZE Â Â Â Â Â Â Â Â3

I would use COUNT instead of size given the unit is registers not bytes.

> Â#define MSR_AMD64_IBSOPCTL Â Â Â Â Â Â 0xc0011033
> Â#define MSR_AMD64_IBSOPRIP Â Â Â Â Â Â 0xc0011034
> Â#define MSR_AMD64_IBSOPDATA Â Â Â Â Â Â0xc0011035
> @@ -120,7 +121,9 @@
> Â#define MSR_AMD64_IBSOPDATA3 Â Â Â Â Â 0xc0011037
> Â#define MSR_AMD64_IBSDCLINAD Â Â Â Â Â 0xc0011038
> Â#define MSR_AMD64_IBSDCPHYSAD Â Â Â Â Â0xc0011039
> +#define MSR_AMD64_IBSOP_SIZE Â Â Â Â Â 7

Idem here for IBSOP.

> Â#define MSR_AMD64_IBSCTL Â Â Â Â Â Â Â 0xc001103a
> +#define MSR_AMD64_IBS_SIZE_MAX Â Â Â Â MSR_AMD64_IBSOP_SIZE
>
Idem.

> Â/* Fam 10h MSRs */
> Â#define MSR_FAM10H_MMIO_CONF_BASE Â Â Â0xc0010058
> diff --git a/arch/x86/kernel/cpu/perf_event_amd.c b/arch/x86/kernel/cpu/perf_event_amd.c
> index 3dc327c..78b0b34 100644
> --- a/arch/x86/kernel/cpu/perf_event_amd.c
> +++ b/arch/x86/kernel/cpu/perf_event_amd.c
> @@ -283,6 +283,69 @@ static inline void __amd_pmu_enable_ibs_event(struct hw_perf_event *hwc)
> Â Â Â Â Â Â Â Â__x86_pmu_enable_event(hwc, IBS_OP_ENABLE);
> Â}
>
> +static int amd_pmu_check_ibs(int idx, unsigned int msr, u64 valid,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Âu64 reenable, int size, struct pt_regs *iregs)
> +{
> + Â Â Â struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
> + Â Â Â struct perf_event *event = cpuc->events[idx];
> + Â Â Â struct perf_sample_data data;
> + Â Â Â struct perf_raw_record raw;
> + Â Â Â struct pt_regs regs;
> + Â Â Â u64 buffer[MSR_AMD64_IBS_SIZE_MAX];
> + Â Â Â u64 *buf = buffer;
> + Â Â Â int i;
> +
> + Â Â Â if (!test_bit(idx, cpuc->active_mask))
> + Â Â Â Â Â Â Â return 0;
> +
> + Â Â Â rdmsrl(msr++, *buf);
> + Â Â Â if (!(*buf++ & valid))
> + Â Â Â Â Â Â Â return 0;
> +
> + Â Â Â perf_sample_data_init(&data, 0);
> + Â Â Â if (event->attr.sample_type & PERF_SAMPLE_RAW) {
> + Â Â Â Â Â Â Â for (i = 1; i < size; i++)
> + Â Â Â Â Â Â Â Â Â Â Â rdmsrl(msr++, *buf++);
> + Â Â Â Â Â Â Â raw.size = sizeof(u64) * size;
> + Â Â Â Â Â Â Â raw.data = buffer;
> + Â Â Â Â Â Â Â data.raw = &raw;
> + Â Â Â }
> +

Need to add the padding: raw.size = sizeof(u64) * size + sizeof(u32);

> + Â Â Â regs = *iregs; /* later: update ip from ibs sample */
> +
> + Â Â Â if (perf_event_overflow(event, 1, &data, &regs))
> + Â Â Â Â Â Â Â x86_pmu_stop(event);
> + Â Â Â else
> + Â Â Â Â Â Â Â __x86_pmu_enable_event(&event->hw, reenable);
> +
> + Â Â Â return 1;
> +}
> +
> +static int amd_pmu_handle_irq(struct pt_regs *regs)
> +{
> + Â Â Â int handled, handled2;
> +
> + Â Â Â handled = x86_pmu_handle_irq(regs);
> +
> + Â Â Â if (!x86_pmu.ibs)
> + Â Â Â Â Â Â Â return handled;
> +
> + Â Â Â handled2 = 0;
> + Â Â Â handled2 += amd_pmu_check_ibs(X86_PMC_IDX_SPECIAL_IBS_FETCH,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â MSR_AMD64_IBSFETCHCTL, IBS_FETCH_VAL,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â IBS_FETCH_ENABLE, MSR_AMD64_IBSFETCH_SIZE,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â regs);
> + Â Â Â handled2 += amd_pmu_check_ibs(X86_PMC_IDX_SPECIAL_IBS_OP,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â MSR_AMD64_IBSOPCTL, IBS_OP_VAL,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â IBS_OP_ENABLE, MSR_AMD64_IBSOP_SIZE,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â regs);
> +
> + Â Â Â if (handled2)
> + Â Â Â Â Â Â Â inc_irq_stat(apic_perf_irqs);
> +

If you have both regular counter intr + IBS you will double-count
apic_perf_irqs.
I would do: if (handled2 && !handled) inc_irq_stat().
--
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/