From patchwork Tue Dec 5 07:12:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ganapatrao Kulkarni X-Patchwork-Id: 10092373 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D016060327 for ; Tue, 5 Dec 2017 07:12:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BF27129489 for ; Tue, 5 Dec 2017 07:12:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B26AF2948B; Tue, 5 Dec 2017 07:12:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.2 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM, HK_RANDOM_FROM, RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 195A529489 for ; Tue, 5 Dec 2017 07:12:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:Subject:Message-ID:Date:From: References:In-Reply-To:MIME-Version:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=PztlUW29TKoDPs/zEpfEZC55uUaMOt4RrvY6BokMp/A=; b=NXVT1SWpomS2fn KbEj9PEUGGEMufROr+Hn73umFEMC5TDTJwy9M2lq4lnsIdUxKaSaBWE+Pd9neOxrxxnEpNRV6OrKs p3OuHeh87MJ/vg4wSCFovbpSgTZ2ojXQ3G+tKM7LwJeBhi1DODyGkF1ZcKqjm3mcBTd8umYePbPi2 Hup/Yg+wzMK1EOsnZEUc/Q3oJkMrh3W+qDUndCF3D1J3wSI+MMQ51lqfqZ39FCL3WkzgbW64Wb4RO 5iNE0MTXG5PQ2YTeTpXSZ6xQJTRdKE4DK8arlYuCriZxiq7OKc/EothJj6r9roFIFYKv0KAj/W4e9 1Z2LLOxavP89ZEz0KJMQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1eM7PV-0003wk-P6; Tue, 05 Dec 2017 07:12:57 +0000 Received: from mail-lf0-x241.google.com ([2a00:1450:4010:c07::241]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eM7PR-0003v3-TP for linux-arm-kernel@lists.infradead.org; Tue, 05 Dec 2017 07:12:55 +0000 Received: by mail-lf0-x241.google.com with SMTP id a12so22050194lfe.4 for ; Mon, 04 Dec 2017 23:12:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=UrwAI8iKXTcHh8j2JQwdU6nqMONROoS50KCt6xO5UW8=; b=mGzs319CMhISte3zJaWnvT38BJCcaut/8//fg9n/QG7yYEjUT7xFxXxqIa+21kYuzg ZkJpEJcldaAryoIK6Hro1xlIVYVUWirVDAmH1WEkKao5T3idHL2MVuD0nTfOXsCn+vKj IvQ4x0KBgTRDgHQL1VdEdRp0bryVhuvvz2kT7NUWiB/Y3S/9gDI28daiCprCw9ngz+iG N6hcmEFU7PF3yyea+IWZJnnHAYejkDSEq2zzVGNv+Vz3WSvB81HVY4kipc7ricwkOF+m ++bavHJn4pwCWKNTFbmLxCoNrFrcCq8+JaoTeW/xPrRAvfBM3wiefA68cghloIBX1E99 9ooA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=UrwAI8iKXTcHh8j2JQwdU6nqMONROoS50KCt6xO5UW8=; b=OM4A8AcncI8TL3jw3fvnC9oxxjphlsb9y2wM+99NWakIVE4Ouf2Yx3V0CpEg+y1719 ChHhgc8pnGOZeaQIww6PE97ELhsqlgfbVkwJG5+OxDIQpx/42L4EHFMVkkIDv+MOa6tV onXbXg4I4T8Ms48WbGqS1jOsbbVh840SpQFFGpto8SYZ2LmLpGVE5w5sf9c1DB5Zchr0 GUFHlFPyIXfxn3fXPP8u/5y7ms58uDJ66aEUE2z5jTU0cGVILygZdIw/o4LML9vxH9dV jj9J0jFA7/BLRE7ZzBhNDBwBqUckn75o3ioY8RvF2G+BeHaLdz9ifJID7kErl5juzje/ 9sqA== X-Gm-Message-State: AJaThX7kDGEL5aYptPtibBvbLJ8chJFhOIo90/dW9plW5KO+E8LnKzO0 wBmUsI6g2UQa4a+puDQkva1hk16AKtlvYoZ3Ogw= X-Google-Smtp-Source: AGs4zMbkxQ4pZkCNSnGRFT1QpqLRARfu2RC6ko8ywy9PEB/roUagS4MUwBc2XMkgFOnPUyeJk8JgVoJ+slPEbIahjHk= X-Received: by 10.25.143.211 with SMTP id s80mr8533409lfk.85.1512457951289; Mon, 04 Dec 2017 23:12:31 -0800 (PST) MIME-Version: 1.0 Received: by 10.25.225.85 with HTTP; Mon, 4 Dec 2017 23:12:30 -0800 (PST) In-Reply-To: <6fdad34d-1612-0447-e58e-5c748f92668d@linux.intel.com> References: <20171016183222.25750-1-ganapatrao.kulkarni@cavium.com> <20171016183222.25750-4-ganapatrao.kulkarni@cavium.com> <6fdad34d-1612-0447-e58e-5c748f92668d@linux.intel.com> From: Ganapatrao Kulkarni Date: Tue, 5 Dec 2017 12:42:30 +0530 Message-ID: Subject: Re: [PATCH v9 3/5] perf utils: use pmu->is_uncore to detect PMU UNCORE devices To: "Jin, Yao" X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171204_231254_149100_A0671730 X-CRM114-Status: GOOD ( 24.09 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, Alexander Shishkin , catalin.marinas@arm.com, Jonathan.Cameron@huawei.com, Will Deacon , linux-kernel@vger.kernel.org, Arnaldo Carvalho de Melo , Zhangshaokun , Peter Zijlstra , Robert Richter , Ingo Molnar , jnair@caviumnetworks.com, Ganapatrao Kulkarni , "Jin, Yao" , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP thanks Jin Yao for point this out. looks like logic of leveraging uncore device type(which i have changed in v9) does not go well with some json events of x86. can you please try below diff(logic used till v8), which keeps the original logic of identifying core/cpu PMUs. continue; i have tried this diff on my x86 PC(haswell) and looks to be ok. please confirm your testing on skylake. gkulkarni@gkFc25>perf>> ./perf stat --per-thread -p 12663 -M CPI,IPC sleep 1 Performance counter stats for process id '12663': bash-12663 278,886 inst_retired.any:u bash-12663 482,284 cycles:u bash-12663 278,886 inst_retired.any:u bash-12663 483,597 cpu_clk_unhalted.thread:u 1.000923760 seconds time elapsed On Tue, Dec 5, 2017 at 7:42 AM, Jin, Yao wrote: > Hi Kulkarni, Arnaldo, > > This patch has been merged in perf/core branch today. > > But I see a regression issue when I run the 'perf stat'. > > With bisect checking, I locate to this patch. > > commit ad8737a08973f5dca632bdd63cf2abc99670e540 > Author: Ganapatrao Kulkarni > Date: Tue Oct 17 00:02:20 2017 +0530 > > perf pmu: Use pmu->is_uncore to detect UNCORE devices > > For example (on Intel skylake desktop), > > 1. The correct output should be (without this patch): > > root@skl:/tmp# perf stat --per-thread -p 1754 -M CPI,IPC > ^C > Performance counter stats for process id '1754': > > vmstat-1754 1,882,798 inst_retired.any # > 0.8 CPI > vmstat-1754 1,589,720 cycles > vmstat-1754 1,882,798 inst_retired.any # > 1.2 IPC > vmstat-1754 1,589,720 cpu_clk_unhalted.thread > > 2.647443167 seconds time elapsed > > 2. With this patch, the output will be: > > root@skl:/tmp# perf stat --per-thread -p 1754 -M CPI,IPC > ^C > Performance counter stats for process id '1754': > > vmstat-1754 1,945,589 inst_retired.any > vmstat-1754 inst_retired.any > vmstat-1754 1,609,892 cycles > vmstat-1754 1,945,589 inst_retired.any > vmstat-1754 inst_retired.any > vmstat-1754 1,609,892 cpu_clk_unhalted.thread > vmstat-1754 cpu_clk_unhalted.thread > > 3.051274166 seconds time elapsed > > Could you please help to take a look? > > Thanks > Jin Yao > > > On 10/17/2017 2:32 AM, Ganapatrao Kulkarni wrote: >> >> PMU CORE devices are identified using sysfs filename cpu, however >> on some platforms(like arm/arm64), PMU CORE sysfs name is not cpu. >> Hence cpu cannot be used to differentiate PMU CORE/UNCORE devices. >> >> commit: >> 66ec1191 ("perf pmu: Unbreak perf record for arm/arm64 with events with >> explicit PMU") >> >> has introduced pmu->is_uncore, which is set to PMU UNCORE devices only. >> Adding changes to use pmu->is_uncore to identify UNCORE devices. >> >> Acked-by: Will Deacon >> Tested-by: Shaokun Zhang >> Signed-off-by: Ganapatrao Kulkarni >> --- >> tools/perf/util/pmu.c | 11 +++++++---- >> 1 file changed, 7 insertions(+), 4 deletions(-) >> >> diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c >> index 8b17db5..9110718 100644 >> --- a/tools/perf/util/pmu.c >> +++ b/tools/perf/util/pmu.c >> @@ -603,7 +603,6 @@ static void pmu_add_cpu_aliases(struct list_head >> *head, struct perf_pmu *pmu) >> */ >> i = 0; >> while (1) { >> - const char *pname; >> pe = &map->table[i++]; >> if (!pe->name) { >> @@ -612,9 +611,13 @@ static void pmu_add_cpu_aliases(struct list_head >> *head, struct perf_pmu *pmu) >> break; >> } >> - pname = pe->pmu ? pe->pmu : "cpu"; >> - if (strncmp(pname, name, strlen(pname))) >> - continue; >> + if (pmu->is_uncore) { >> + /* 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, >> > thanks Ganapat diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 5ad8a18..57e38fd 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -538,6 +538,34 @@ static bool pmu_is_uncore(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(); + + if (!sysfs) + return 0; + + /* Look for cpu sysfs (x86 and others) */ + scnprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu", sysfs); + if ((stat(path, &st) == 0) && + (strncmp(name, "cpu", strlen("cpu")) == 0)) + return 1; + + /* Look for cpu sysfs (specific to arm) */ + scnprintf(path, PATH_MAX, "%s/bus/event_source/devices/%s/cpus", + sysfs, name); + if (stat(path, &st) == 0) + return 1; + + return 0; +} + +/* * Return the CPU id as a raw string. * * Each architecture should provide a more precise id string that @@ -641,7 +669,7 @@ static void pmu_add_cpu_aliases(struct list_head *head, struct perf_pmu *pmu) break; } - if (pmu->is_uncore) { + if (!is_pmu_core(name)) { /* check for uncore devices */ if (pe->pmu == NULL)