Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932697AbdHVK3V (ORCPT ); Tue, 22 Aug 2017 06:29:21 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:4990 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932222AbdHVK3R (ORCPT ); Tue, 22 Aug 2017 06:29:17 -0400 Date: Tue, 22 Aug 2017 11:27:31 +0100 From: Jonathan Cameron To: Ganapatrao Kulkarni CC: , , , , , , , , , , , , Subject: Re: [PATCH v4 3/4] perf utils: Add helper function is_pmu_core to detect PMU CORE devices Message-ID: <20170822112731.000015e2@huawei.com> In-Reply-To: <20170720055608.5333-4-ganapatrao.kulkarni@cavium.com> References: <20170720055608.5333-1-ganapatrao.kulkarni@cavium.com> <20170720055608.5333-4-ganapatrao.kulkarni@cavium.com> Organization: Huawei X-Mailer: Claws Mail 3.15.0 (GTK+ 2.24.31; x86_64-w64-mingw32) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.206.48.115] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020201.599C072B.011C,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0, ip=0.0.0.0, so=2014-11-16 11:51:01, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 253305e051b620d9cb44b6b7cff7cce7 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2960 Lines: 99 On Thu, 20 Jul 2017 11:26:07 +0530 Ganapatrao Kulkarni wrote: > On some platforms, PMU core devices sysfs name is not cpu. > Adding function is_pmu_core to detect as core device using > core device specific hints in sysfs. > > For arm64 platforms, all core devices have file "cpus" in sysfs. > > Signed-off-by: Ganapatrao Kulkarni One really trivial point inline. Otherwise looks good to me. Jonathan > --- > tools/perf/util/pmu.c | 44 ++++++++++++++++++++++++++++++++++++++++---- > 1 file changed, 40 insertions(+), 4 deletions(-) > > diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c > index aefdbd1..0057d1c 100644 > --- a/tools/perf/util/pmu.c > +++ b/tools/perf/util/pmu.c > @@ -506,6 +506,39 @@ static struct cpu_map *pmu_cpumask(const char *name) > } > > /* > + * PMU CORE devices have different name other than cpu in sysfs on some > + * platforms. looking for possible sysfs files to identify as core device. > + */ > +static int is_pmu_core(const char *name) > +{ > + struct stat st; > + char path[PATH_MAX]; > + const char *sysfs = sysfs__mountpoint(); > + const char **template; > + const char *templates[] = { > + "%s/bus/event_source/devices/%s/cpus", > + NULL > + }; > + > + if (!sysfs) > + return 0; > + > + /* Look for cpu sysfs */ > + snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu", sysfs); > + if ((stat(path, &st) == 0) && > + (strncmp(name, "cpu", strlen("cpu")) == 0)) > + return 1; > + > + for (template = templates; *template; template++) { > + snprintf(path, PATH_MAX, *template, sysfs, name); > + if (stat(path, &st) == 0) > + return 1; > + } Adding generic infrastructure for one entry where we already know the other case doesn't fit the pattern, seems a little premature. If we can't make these two fit it seems like we should just hard code the second case as well for now. Refactoring to this may be make sense once we have a few different cases that do share a common form (of including the name) You could actually put both options in templates and rely on the fact that snprintf will ignore excess parameters, but that feels fragile. > + > + return 0; > +} > + > +/* > * Return the CPU id as a raw string. > * > * Each architecture should provide a more precise id string that > @@ -558,15 +591,18 @@ static void pmu_add_cpu_aliases(struct list_head *head, const char *name, > */ > i = 0; > while (1) { > - const char *pname; > > pe = &map->table[i++]; > if (!pe->name) > break; > > - pname = pe->pmu ? pe->pmu : "cpu"; > - if (strncmp(pname, name, strlen(pname))) > - continue; > + if (!is_pmu_core(name)) { > + /* check for uncore devices */ > + if (pe->pmu == NULL) > + continue; > + if (strncmp(pe->pmu, name, strlen(pe->pmu))) > + continue; > + } > > /* need type casts to override 'const' */ > __perf_pmu__new_alias(head, NULL, (char *)pe->name,