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

Borislav Petkov
2012-06-08T14:15:34Z

On Fri, Jun 08, 2012 at 03:54:29PM +0200, Peter Zijlstra wrote:
> On Fri, 2012-06-08 at 15:51 +0200, Borislav Petkov wrote:
> > Reportedly, there are some obscure systems which need different
> > microcode versions per CPU:
> >
> > http://lkml.indiana.edu/hypermail/linux/kernel/1105.3/01010.html
>
> *groan*,.. ok.

Tell me about it - if we didn't have to support this, we could've killed
a lot of code from the thing.

> > > The biggest problem is finding when the minimum revision changes, at
> > > best this is a n log n sorting problem due to the per-cpu setup, but I
> > > couldn't be arsed to implement a tree or anything fancy since it all
> > > stinks anyway.
> >
> > I know. Can't you just iterate over all CPUs and collect the lowest
> > ucode version? Provided, of course, newer microcode versions means a
> > higher version number.
>
> That's what I do.. but that's O(n) per cpu, so if you update all cpus,
> that's O(n^2).
>
> You don't know when userspace is done updating the 'last' cpu, so you
> have to scan all cpus for every cpu.
>
> I'm sure the SGI people with their silly CPU counts aren't too thrilled
> to have this.

Ok, hmm, I don't have a bright idea right now except maybe a stupid one:

have a variable which gets initialized to the number of all CPUs and
each time ->apply_microcode() finishes by returning 0, we decrement it
once.

"Finishes by returning 0" means ucode successfully updated.

When it has reached 0, microcode_notifier_done() says
MICROCODE_SUCCESSFULLY_UPDATED_ON_ALL_CPUS and only then you run
intel_snb_verify_ucode().

However(!),

* what do you do when you boot the box with less CPUs than present? All
the offline CPUs cannot get to userspace to get the chance to update
ucode. In that case, counter stays !0 and bo PEBS, tough luck.

* hotplug: we don't care about it because once we ONLINE a CPU again, it
automatically gets the ucode applied.

Hmm, I'm probably missing some obscure case.

--
Regards/Gruss,
Boris.

Advanced Micro Devices GmbH
Einsteinring 24, 85609 Dornach
GM: Alberto Bozzo
Reg: Dornach, Landkreis Muenchen
HRB Nr. 43632 WEEE Registernr: 129 19551