Received: by 10.213.65.68 with SMTP id h4csp157976imn; Mon, 19 Mar 2018 23:25:51 -0700 (PDT) X-Google-Smtp-Source: AG47ELuL6p2SZNsWh5CKNbjowGiUS2D9nDDzxmCeBH1+REYxuiUuCJVams2H5iyVsPDJNAdHr1pn X-Received: by 2002:a17:902:ac1:: with SMTP id 59-v6mr15281510plp.228.1521527151780; Mon, 19 Mar 2018 23:25:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521527151; cv=none; d=google.com; s=arc-20160816; b=e/h5DYpdQDHVziTnR9W2Zn/Z3ihcfZa/tICEu11ptTN8WCGWdwY1cB1buI1+ddP1dg K2S97XZ8+fiVGk85GDR+Iq+uWQvtnuiW862Kqk7mI+WiAxOdEUSGJbE7RyioAn+YtQSH w4BXEz7/yV7TERCTnau3PzzYExqD3QRKaPrqgtcDwh0u9Ytvmbe2HARLBgYNKWxFXSjR Ab8ngCK/QuXV6KupeBOIl3kMJtCY5p0ss5jKnoA/c71KapfTq3ErSMtubJl6KBHHvtoH k/WK0m3s2X4l6LmLkHwoXKqEt4vIX/Q7vWaHwUMFV/FRUp1GH703BiBt+V5/6BMyC8n4 TJrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:arc-authentication-results; bh=5WT6RIYtx0iTws8a3TDMCC/atE+pWKrS8Fkkq9/0T2o=; b=0E2v44TLvqNNbok7mLNg3Njer1RKlKXJvafq6y6DpUBvqRDmdpi0+FnD8r2TpOHuEM 9LxuLErJ4Xmf7dOluFEnYZOsX/96MjfRDYQKsNNnDfMABr7BTQ8ufB/5y9/NKrV+prj9 qBtk2NDzAsNUcLHHbPPtqeGRu2bHX8CcqKc3eKL6NoZe8rTtNVThE86ZfdY0O+PovtUI /db/MpZMjkTp5oGJ5/K2jU4Yyg9vvfgn3VBND+ej5eJcYJBciMi3hseHe3OrH3o0qxN8 4QuC9jczHjx4+DELaN9jbJzBOrM/lgiJRYQMWMBc45CtmbOGfmAysJf9HmYsw7vwbAJb J4Rw== 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 u189si789488pfu.212.2018.03.19.23.25.38; Mon, 19 Mar 2018 23:25:51 -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 S1751909AbeCTGYg (ORCPT + 99 others); Tue, 20 Mar 2018 02:24:36 -0400 Received: from terminus.zytor.com ([198.137.202.136]:50073 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751330AbeCTGYe (ORCPT ); Tue, 20 Mar 2018 02:24:34 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTP id w2K6MoFj028845; Mon, 19 Mar 2018 23:22:50 -0700 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w2K6MnlM028841; Mon, 19 Mar 2018 23:22:49 -0700 Date: Mon, 19 Mar 2018 23:22:49 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for John Garry Message-ID: Cc: ak@linux.intel.com, sukadev@linux.vnet.ibm.com, peterz@infradead.org, acme@redhat.com, hpa@zytor.com, jolsa@kernel.org, wcohen@redhat.com, will.deacon@arm.com, tglx@linutronix.de, john.garry@huawei.com, alexander.shishkin@linux.intel.com, namhyung@kernel.org, ganapatrao.kulkarni@cavium.com, linux-kernel@vger.kernel.org, mingo@kernel.org, zhangshaokun@hisilicon.com Reply-To: sukadev@linux.vnet.ibm.com, ak@linux.intel.com, hpa@zytor.com, acme@redhat.com, peterz@infradead.org, tglx@linutronix.de, john.garry@huawei.com, wcohen@redhat.com, will.deacon@arm.com, jolsa@kernel.org, zhangshaokun@hisilicon.com, linux-kernel@vger.kernel.org, mingo@kernel.org, ganapatrao.kulkarni@cavium.com, namhyung@kernel.org, alexander.shishkin@linux.intel.com In-Reply-To: <1521047452-28565-1-git-send-email-john.garry@huawei.com> References: <1520506716-197429-5-git-send-email-john.garry@huawei.com> <1521047452-28565-1-git-send-email-john.garry@huawei.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] perf vendor events: Add support for pmu events vendor subdirectory Git-Commit-ID: 51ce1dcc5d0d3e40e26893a7fa9e30538960ee7e X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00 autolearn=ham autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 51ce1dcc5d0d3e40e26893a7fa9e30538960ee7e Gitweb: https://git.kernel.org/tip/51ce1dcc5d0d3e40e26893a7fa9e30538960ee7e Author: John Garry AuthorDate: Thu, 8 Mar 2018 18:58:29 +0800 Committer: Arnaldo Carvalho de Melo CommitDate: Fri, 16 Mar 2018 13:54:16 -0300 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 --- tools/perf/pmu-events/README | 4 +++ tools/perf/pmu-events/jevents.c | 68 +++++++++++++++++++++++++++++++++++++---- 2 files changed, 66 insertions(+), 6 deletions(-) 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);