Received: by 10.213.65.68 with SMTP id h4csp1225579imn; Wed, 14 Mar 2018 13:28:50 -0700 (PDT) X-Google-Smtp-Source: AG47ELsCnkxVYDXtkmTxawAhbIdA7BfS21vGCMXr3sdWCdtrPpT1DQ3GJhAglTZ9TCUb4xTq8WnF X-Received: by 10.101.67.2 with SMTP id j2mr4754942pgq.147.1521059330211; Wed, 14 Mar 2018 13:28:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521059330; cv=none; d=google.com; s=arc-20160816; b=gu3KqrfDr4tOM9lvK3UU0fTV3JsYdNw9jAl0ULbGC08UMtWNj3PLsycBDv5FyaxOJG 0/jAaX1z0sDy6aHcHk7AacgyY2nr5wjvFIZMJDAHuZ3URh5SJCXT95otMVWXcdbjD4rj uxv37ph+R3GrNUEkO0akyHuM2qZWjABxrGcDOr0Oazcaq2IAlIX0We5UCbdf8KwYPcS0 99epdniY0Jq5bUn9V5PnKvRKwoG5qQkLKpuavV6y/T1JJYwq3vwQB678nsyqm4h3hSIA i30gi3zN/h2DLEjWfUln7ui4QIms4M1Z0XLT9qUkF3STFv60oTK6WOM3FldbIUXiaoil Zl9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dmarc-filter:arc-authentication-results; bh=23maxaH3BwjSm1/LbMWZkzxetBBhNsEprj6IPp2qWJQ=; b=eNrgtpLmq9HzuuooyXYWu6abx1uWkssH2EhZG/fmAJ1QGrlWT5KFGlLZ+Z2SsCJeZ3 YMU8ls04PFgkYqkcGNR+Q/pnhbBomu9mCTW7tuF50Q2VA1vNuhP7UEu/cGYZzQdUhW4g IP0eOnVbz3f/ysbo6d6SObRJfZKVngExLj4f2qDfVqM9oK33pBFiCKBkSz6hORxZJA4Q 7pvXo80Ro1E9qEWD6+c4dSP1Xj1MymRPIFPOjCpt2yA51qWbkjZQLnRjs7tfyjL4ePZk CSSn75e8Dh1iHLimYhBwVSxN4FPjUmvCauVv8fPRrzORjf8DMRbPQfm0L0zW1vLXk4xi QoYw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q4si2376243pgc.269.2018.03.14.13.28.34; Wed, 14 Mar 2018 13:28:50 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752341AbeCNU0u (ORCPT + 99 others); Wed, 14 Mar 2018 16:26:50 -0400 Received: from mail.kernel.org ([198.145.29.99]:55358 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751413AbeCNU0r (ORCPT ); Wed, 14 Mar 2018 16:26:47 -0400 Received: from jouet.infradead.org (unknown [179.97.41.186]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3F7F3204EE; Wed, 14 Mar 2018 20:26:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3F7F3204EE Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=acme@kernel.org Received: by jouet.infradead.org (Postfix, from userid 1000) id F12D1143FAF; Wed, 14 Mar 2018 17:26:43 -0300 (-03) Date: Wed, 14 Mar 2018 17:26:43 -0300 From: Arnaldo Carvalho de Melo To: John Garry Cc: peterz@infradead.org, mingo@redhat.com, alexander.shishkin@linux.intel.com, jolsa@redhat.com, namhyung@kernel.org, ak@linux.intel.com, wcohen@redhat.com, sukadev@linux.vnet.ibm.com, linux-kernel@vger.kernel.org, linuxarm@huawei.com Subject: Re: [PATCH] perf vendor events: fix processing for xfs Message-ID: <20180314202643.GG27335@kernel.org> References: <1521047452-28565-1-git-send-email-john.garry@huawei.com> <20180314185355.GC27335@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Url: http://acmel.wordpress.com User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Wed, Mar 14, 2018 at 07:39:25PM +0000, John Garry escreveu: > On 14/03/2018 18:53, Arnaldo Carvalho de Melo wrote: > > Em Thu, Mar 15, 2018 at 01:10:52AM +0800, John Garry escreveu: > > > In the recently introduced support for vendor subdirectory, > > > the checking for directory entries under xfs (or any other fs > > > which does not support dirent.d_type) is missing the check > > > for links for current and parent directory. This can result > > > in a broken pmu_events.c being generated. > > > > > > Fix this by adding the appropriate check in is_leaf_dir(). > > > > So I'll lookup the patch that introduced the patch and squash this one > > with it, so that we don't break 'git bisect' on ppc. > > Right, so it's going to be "perf vendor events: add support for pmu events > vendor subdirectory". > > BTW, I don't think it's specifically ppc which was broken, but just when > building from xfs. > > Much appreciated, > John This is the ammended cset, and yes, I mentioned just XFS not ppc, added Sukadev to the CC list and the link to your patch that he tested. Also stamped his Tested-by there. This will all go again the container build test set before a new pull req to Ingo, where I'll avoid sending the previous 31 patches to the mailing list, just the ones that came after it, as perf/core keeps growing :-) - Arnaldo commit d24081387a00d2e10789eb012429144c549598be Author: John Garry Date: Thu Mar 8 18:58:29 2018 +0800 perf vendor events: Add support for pmu events vendor subdirectory For some architectures (like arm), it is required to support a vendor subdirectory and not locate all the JSONs for a specific vendor in the same folder. This is because all the events for the same vendor will be placed in the same pmu events table, which may cause conflict. This conflict would be in the instance that a vendor's custom implemented events do have the same meaning on different platforms, so events in the pmu table would conflict. In addition, per list command may show events which are not even supported for a given platform. This patch adds support for a arch/vendor/platform directory hierarchy, while maintaining backwards-compatibility for existing arch/platform structure. In this, each platform would always have its own pmu events table. In generated file pmu_events.c, each platform table name is in the format pme{_vendor}_platform, like this: struct pmu_events_map pmu_events_map[] = { { .cpuid = "0x00000000420f5160", .version = "v1", .type = "core", .table = pme_cavium_thunderx2 }, { .cpuid = 0, .version = 0, .type = 0, .table = 0, }, }; Signed-off-by: John Garry Acked-by: Jiri Olsa Tested-by: Sukadev Bhattiprolu Cc: Alexander Shishkin Cc: Andi Kleen Cc: Ganapatrao Kulkarni Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Shaokun Zhang Cc: Sukadev Bhattiprolu Cc: Will Deacon Cc: William Cohen Cc: linux-arm-kernel@lists.infradead.org Cc: linuxarm@huawei.com Link: http://lkml.kernel.org/r/1520506716-197429-5-git-send-email-john.garry@huawei.com Link: http://lkml.kernel.org/r/1521047452-28565-1-git-send-email-john.garry@huawei.com [ Add missing limits.h include, fixing the build on at least all Alpine Linux versions tested (3.4 to 3.7 + edge), ] [ Applied a patch to fix reading ./.. directories in XFS, see second Link tag ] Signed-off-by: Arnaldo Carvalho de Melo diff --git a/tools/perf/pmu-events/README b/tools/perf/pmu-events/README index 2407abc1d441..655286ff8767 100644 --- a/tools/perf/pmu-events/README +++ b/tools/perf/pmu-events/README @@ -28,6 +28,10 @@ sub directory. Thus for the Silvermont X86 CPU: Cache.json Memory.json Virtual-Memory.json Frontend.json Pipeline.json +The JSONs folder for a CPU model/family may be placed in the root arch +folder, or may be placed in a vendor sub-folder under the arch folder +for instances where the arch and vendor are not the same. + Using the JSON files and the mapfile, 'jevents' generates the C source file, 'pmu-events.c', which encodes the two sets of tables: diff --git a/tools/perf/pmu-events/jevents.c b/tools/perf/pmu-events/jevents.c index 1d02fafdc34d..0981d313064f 100644 --- a/tools/perf/pmu-events/jevents.c +++ b/tools/perf/pmu-events/jevents.c @@ -39,6 +39,7 @@ #include #include #include +#include #include #include /* getrlimit */ #include /* getrlimit */ @@ -572,7 +573,7 @@ static char *file_name_to_table_name(char *fname) * Derive rest of table name from basename of the JSON file, * replacing hyphens and stripping out .json suffix. */ - n = asprintf(&tblname, "pme_%s", basename(fname)); + n = asprintf(&tblname, "pme_%s", fname); if (n < 0) { pr_info("%s: asprintf() error %s for file %s\n", prog, strerror(errno), fname); @@ -582,7 +583,7 @@ static char *file_name_to_table_name(char *fname) for (i = 0; i < strlen(tblname); i++) { c = tblname[i]; - if (c == '-') + if (c == '-' || c == '/') tblname[i] = '_'; else if (c == '.') { tblname[i] = '\0'; @@ -739,25 +740,80 @@ static int get_maxfds(void) static FILE *eventsfp; static char *mapfile; +static int is_leaf_dir(const char *fpath) +{ + DIR *d; + struct dirent *dir; + int res = 1; + + d = opendir(fpath); + if (!d) + return 0; + + while ((dir = readdir(d)) != NULL) { + if (!strcmp(dir->d_name, ".") || !strcmp(dir->d_name, "..")) + continue; + + if (dir->d_type == DT_DIR) { + res = 0; + break; + } else if (dir->d_type == DT_UNKNOWN) { + char path[PATH_MAX]; + struct stat st; + + sprintf(path, "%s/%s", fpath, dir->d_name); + if (stat(path, &st)) + break; + + if (S_ISDIR(st.st_mode)) { + res = 0; + break; + } + } + } + + closedir(d); + + return res; +} + static int process_one_file(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf) { - char *tblname, *bname = (char *) fpath + ftwbuf->base; + char *tblname, *bname; int is_dir = typeflag == FTW_D; int is_file = typeflag == FTW_F; int level = ftwbuf->level; int err = 0; + if (level == 2 && is_dir) { + /* + * For level 2 directory, bname will include parent name, + * like vendor/platform. So search back from platform dir + * to find this. + */ + bname = (char *) fpath + ftwbuf->base - 2; + for (;;) { + if (*bname == '/') + break; + bname--; + } + bname++; + } else + bname = (char *) fpath + ftwbuf->base; + pr_debug("%s %d %7jd %-20s %s\n", is_file ? "f" : is_dir ? "d" : "x", level, sb->st_size, bname, fpath); - /* base dir */ - if (level == 0) + /* base dir or too deep */ + if (level == 0 || level > 3) return 0; + /* model directory, reset topic */ - if (level == 1 && is_dir) { + if ((level == 1 && is_dir && is_leaf_dir(fpath)) || + (level == 2 && is_dir)) { if (close_table) print_events_table_suffix(eventsfp);