From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754696AbbLPIxr (ORCPT ); Wed, 16 Dec 2015 03:53:47 -0500 Received: from bombadil.infradead.org ([198.137.202.9]:42369 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754639AbbLPIxq (ORCPT ); Wed, 16 Dec 2015 03:53:46 -0500 Date: Wed, 16 Dec 2015 09:53:34 +0100 From: Peter Zijlstra To: Andi Kleen Cc: acme@kernel.org, jolsa@kernel.org, mingo@kernel.org, linux-kernel@vger.kernel.org, eranian@google.com, namhyung@kernel.org, Andi Kleen Subject: Re: [PATCH 08/10] x86, perf: Support sysfs files depending on SMT status Message-ID: <20151216085334.GL6357@twins.programming.kicks-ass.net> References: <1450227266-2501-1-git-send-email-andi@firstfloor.org> <1450227266-2501-9-git-send-email-andi@firstfloor.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1450227266-2501-9-git-send-email-andi@firstfloor.org> User-Agent: Mutt/1.5.21 (2012-12-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); > +}