Re: [PATCH] perf/x86: check ucode before disabling PEBS on SandyBridge

From: Stephane Eranian
Date: Thu Jun 07 2012 - 06:35:29 EST


On Thu, Jun 7, 2012 at 12:18 PM, Peter Zijlstra <peterz@xxxxxxxxxxxxx> wrote:
> On Thu, 2012-06-07 at 09:15 +0200, Stephane Eranian wrote:
>> +static int check_pebs_quirks(void)
>> +{
>> + Â Â Â int uversion = cpu_data(smp_processor_id()).microcode;
>> + Â Â Â int model = cpu_data(smp_processor_id()).x86_model;
>> +
>> + Â Â Â /* do not have PEBS to begin with */
>> + Â Â Â if (!x86_pmu.pebs)
>> + Â Â Â Â Â Â Â return 0;
>> +
>> + Â Â Â /*
>> + Â Â Â Â* check ucode version for SNB, SNB-EP
>> + Â Â Â Â*/
>> + Â Â Â if ((model == 42 || model == 45) && uversion < 0x28) {
>> + Â Â Â Â Â Â Â pr_warn("SandyBridge PEBS unavailable due to CPU erratum, "
>> + Â Â Â Â Â Â Â Â Â Â Â " update microcode (was 0x%x, needs at least 0x28).\n",
>> + Â Â Â Â Â Â Â Â Â Â Â uversion);
>> + Â Â Â Â Â Â Â return -ENOTSUPP;
>> + Â Â Â }
>> + Â Â Â return 0;
>> +}
>> +
>> Âstatic int intel_pmu_hw_config(struct perf_event *event)
>> Â{
>> Â Â Â Â int ret = x86_pmu_hw_config(event);
>> @@ -1401,8 +1422,14 @@ static int intel_pmu_hw_config(struct perf_event *event)
>> Â Â Â Â if (ret)
>> Â Â Â Â Â Â Â Â return ret;
>>
>> - Â Â Â if (event->attr.precise_ip && x86_pmu.pebs_aliases)
>> - Â Â Â Â Â Â Â x86_pmu.pebs_aliases(event);
>> + Â Â Â if (event->attr.precise_ip) {
>> +
>> + Â Â Â Â Â Â Â if (check_pebs_quirks())
>> + Â Â Â Â Â Â Â Â Â Â Â return -ENOTSUPP;
>
> This will only warn about the PEBS issue once you try and use a PEBS
> counter. Shouldn't we do this on boot? IOW. put check_pebs_quirks()
> inside the existing quirk code instead of here?
>
The warning could also be done on boot. But the check has to be done
when the event is created. The other thing is that as it is now, if you
get an error, you check dmesg and it's obvious what is wrong. With
the boot warning, you'd have to look back all the way to the early boot
messages. Whatever you prefer, I am fine.

>> +
>> + Â Â Â Â Â Â Â if (x86_pmu.pebs_aliases)
>> + Â Â Â Â Â Â Â Â Â Â Â x86_pmu.pebs_aliases(event);
>> + Â Â Â }
>>
>> Â Â Â Â if (intel_pmu_needs_lbr_smpl(event)) {
>> Â Â Â Â Â Â Â Â ret = intel_pmu_setup_lbr_filter(event);
>> @@ -1714,13 +1741,6 @@ static __init void intel_clovertown_quirk(void)
>> Â Â Â Â x86_pmu.pebs_constraints = NULL;
>> Â}
--
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/