From patchwork Tue Dec 5 16:13:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 120692 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp5889319qgn; Tue, 5 Dec 2017 07:31:50 -0800 (PST) X-Google-Smtp-Source: AGs4zMaJHqGBxjBS2+BilAMUnrSKSp3ZbeYtLZ55kTV6y4wPnDqvHkNbRxsEs3f4M8b+Gm2WILw9 X-Received: by 10.98.70.132 with SMTP id o4mr24071974pfi.102.1512487910214; Tue, 05 Dec 2017 07:31:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512487910; cv=none; d=google.com; s=arc-20160816; b=ML6cCo5alFtvWSrTx6nlOi4mjvyvjyJ3T5Z5DAafDWp3hJtRohFuHcvrk+k3Qt+fMn l/2YHbbqeoigLOxL1N5bqPUk9c3sDgI7AGIpX+fwpSaUVSPQJ66qORi0XYI/pOnl+LuX VRNVi1QTqBtLEwLdYH4vN8xJdfW1PHzcsZkK/sAs0kFzeo9hslzZWmtqE48Dl3GGYgWp YajYzXc3c1k3XC/ZLeJwcYG7RHUYhk7arvF3tXEvqRRbBy2vJrxvufYuVTmvOx54mc6M PVm9RcXmIFu7lNbiiBKsiZp7MktHnO0AIICZsnP0WNYvpw95ch/bFt715edePA3HVab3 Z0QA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=UM4iNWz6rR06PItGO/pDa/mAb4o9YLAacc/pvSPM7AY=; b=jfqERwYtyEE5wQJqc96WLul2B2UDJf48rI8joWrhBLvGVs+J6tIQQ3AefnvT0TQeBn LPPHwyE1HvaSUKxu0snYhEJnlkUKTln1pYYj9jZiWm64hb51YexGZGKJGzaw5DPinRST RPHAjr5acFH679IgeCnA4JtsAvAYMQietPC92O7Yj7d1szRZ6Cy8E0ubpFa7lZf5GRWA r577gHDP4oCLunuuJlF0qCWfLTMZLD2fOFK9prX5PIsJ8ax26ArnpwGJv8Hn2PRFIVw7 vSM3u9ELOO1GjVc0HFhQ4SPqlmx2VaPBj8lQzl5/xsyviIoaTDWMG9MbN0vEQCXMB5Yx pdLA== 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 6si234193pfs.283.2017.12.05.07.31.49; Tue, 05 Dec 2017 07:31:50 -0800 (PST) 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 S1752792AbdLEPbi (ORCPT + 28 others); Tue, 5 Dec 2017 10:31:38 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:2257 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752611AbdLEPbY (ORCPT ); Tue, 5 Dec 2017 10:31:24 -0500 Received: from DGGEMS414-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 58D6365FF8E9D; Tue, 5 Dec 2017 23:31:08 +0800 (CST) Received: from localhost.localdomain (10.67.212.75) by DGGEMS414-HUB.china.huawei.com (10.3.19.214) with Microsoft SMTP Server id 14.3.361.1; Tue, 5 Dec 2017 23:31:03 +0800 From: John Garry To: , , , , , , , , , , , CC: , , , , , John Garry Subject: [RFC PATCH 1/5] perf jevents: add support for pmu events vendor subdirectory Date: Wed, 6 Dec 2017 00:13:15 +0800 Message-ID: <1512490399-94107-2-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1512490399-94107-1-git-send-email-john.garry@huawei.com> References: <1512490399-94107-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.212.75] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org For some architectures (like arm64), it is required to support a vendor sub-directory and not put all the JSONs for a given vendor in the same dir. This is because all the events for the same vendor will be 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. In addition, "perf list" command may list events which are not even supported for a given platform. This patch adds support for an arch/vendor/platform directory hierarchy, while maintaining support for 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, }, }; or this: struct pmu_events_map pmu_events_map[] = { { .cpuid = "GenuineIntel-6-56", .version = "v5", .type = "core", .table = pme_broadwellde }, [snip] { .cpuid = 0, .version = 0, .type = 0, .table = 0, }, }; Signed-off-by: John Garry --- tools/perf/pmu-events/jevents.c | 57 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 53 insertions(+), 4 deletions(-) -- 1.9.1 diff --git a/tools/perf/pmu-events/jevents.c b/tools/perf/pmu-events/jevents.c index b578aa2..a0d489e 100644 --- a/tools/perf/pmu-events/jevents.c +++ b/tools/perf/pmu-events/jevents.c @@ -588,7 +588,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); @@ -598,7 +598,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'; @@ -755,15 +755,52 @@ static int get_maxfds(void) static FILE *eventsfp; static char *mapfile; +static int isLeafDir(const char *fpath) +{ + DIR *d; + struct dirent *dir; + int res = 1; + d = opendir(fpath); + if (!d) + return 0; + + while ((dir = readdir(d)) != NULL) { + if (dir-> d_type == DT_DIR && dir->d_name[0] != '.') { + 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; + while (true) { + 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); @@ -773,7 +810,7 @@ static int process_one_file(const char *fpath, const struct stat *sb, return 0; /* model directory, reset topic */ - if (level == 1 && is_dir) { + if (level == 1 && is_dir && isLeafDir(fpath)) { if (close_table) print_events_table_suffix(eventsfp); @@ -791,6 +828,18 @@ static int process_one_file(const char *fpath, const struct stat *sb, print_events_table_prefix(eventsfp, tblname); return 0; + } else if (level == 2 && is_dir) { + if (close_table) + print_events_table_suffix(eventsfp); + + tblname = file_name_to_table_name(bname); + if (!tblname) { + pr_info("%s: Error determining table name for %s, exiting\n", prog, + bname); + return -1; + } + + print_events_table_prefix(eventsfp, tblname); } /*