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

From: Borislav Petkov
Date: Fri Jun 08 2012 - 16:42:52 EST


On Fri, Jun 08, 2012 at 08:52:17PM +0200, Peter Zijlstra wrote:
> Checking a bitmap of n bits for being all zero is O(n), so the total is
> still O(n^2). Still, probably faster than the for_each_online_cpu() scan
> I do now.

Ok, here's what I mean:

On init you do:

cpumask_copy(ucode_mask, cpu_online_mask);

In the notifier:

cpumask_clear_cpu(this_cpu, ucode_mask);

if (cpumask_empty(ucode_mask))
verify_pebs();

So, on each cpu you do cpumask_clear_cpu() which should be O(k) for some
constant k.

And ok, cpumask_empty() aka __bitmap_empty() iterates over
nbits/BITS_PER_LONG, so here's the O(n), I see what you mean.

Well, you could probably replace cpumask_empty() with cpumask_weight()
which should use POPCNT in newer hardware and should be almost for free.

--
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

--
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/