Re: [PATCH 08/10] x86, perf: Support sysfs files depending on SMT status

From: Peter Zijlstra
Date: Wed Dec 16 2015 - 03:54:31 EST


On Tue, Dec 15, 2015 at 04:54:24PM -0800, Andi Kleen wrote:

> +ssize_t events_ht_sysfs_show(struct device *dev, struct device_attribute *attr,
> + char *page)
> +{
> + struct perf_pmu_events_ht_attr *pmu_attr =
> + container_of(attr, struct perf_pmu_events_ht_attr, attr);
> + bool ht_on = false;
> + int cpu;
> +
> + /*
> + * Report conditional events depending on Hyper-Threading.
> + *
> + * Check all online CPUs if any have a thread sibling,
> + * as perf may measure any of them.
> + *
> + * This is overly conservative as usually the HT special
> + * handling is not needed if the other CPU thread is idle.
> + *
> + * Note this does not (cannot) handle the case when thread
> + * siblings are invisible, for example with virtualization
> + * if they are owned by some other guest. The user tool
> + * has to re-read when a thread sibling gets onlined later.
> + */
> + for_each_online_cpu (cpu) {
> + ht_on = cpumask_weight(topology_sibling_cpumask(cpu)) > 1;
> + if (ht_on)
> + break;
> + }

At the very least you want {get,put}_online_cpus() around that I
suspect.

But I would rather we generalize and save the state from fixup_ht_bug().

That is, at that subsys_initcall() time all our SMP init is done and
userspace isn't running yet to mess things up, so we can more or less
trust the topology masks to be complete.

So at that time detect if HT is enabled or not and store that
information in x86_pmu.flags for later use here.


> +
> + return sprintf(page, "%s",
> + ht_on ?
> + pmu_attr->event_str_ht :
> + pmu_attr->event_str_noht);
> +}
--
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/