Re: [PATCH V4 1/2] perf ignore LBR and extra_regs.

From: Peter Zijlstra
Date: Wed Jul 09 2014 - 05:19:31 EST


On Tue, Jul 08, 2014 at 09:49:40AM -0700, kan.liang@xxxxxxxxx wrote:
> + /*
> + * Access LBR MSR may cause #GP under certain circumstances.
> + * E.g. KVM doesn't support LBR MSR
> + * Check all LBT MSR here.
> + * Disable LBR access if any LBR MSRs can not be accessed.
> + */
> + if (x86_pmu.lbr_nr) {
> + access = check_msr(x86_pmu.lbr_tos);
> + for (i = 0; i < x86_pmu.lbr_nr; i++) {
> + access &= check_msr(x86_pmu.lbr_from + i);
> + access &= check_msr(x86_pmu.lbr_to + i);
> + }
> + if (!access)
> + x86_pmu.lbr_nr = 0;
> + }

You _could_ write that as:

if (x86_pmu.lbr_nr) {
if (!check_msr(x86_pmu.lbr_tos))
x86_pmu.lbr_nr = 0;
for (i = 0; i < x86_pmu.lbr_nr; i++) {
if (!(check_msr(x86_pmu.lbr_from + i) &&
check_msr(x86_pmu.lbr_to + i)))
x86_pmu.lbr_nr = 0;
}
}

There is no point in checking any more MSRs after the first fail after
all.

Attachment: pgpM2vGobDwtR.pgp
Description: PGP signature