From patchwork Tue Feb 6 17:44:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 127038 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp3094605ljc; Tue, 6 Feb 2018 08:57:59 -0800 (PST) X-Google-Smtp-Source: AH8x225hCZai3dCdwvnq1k8f3pIsqnakFf2sIYyaoHqPBriy+YdTI5dH42pEkzxD7REZfZ+EgvLq X-Received: by 2002:a17:902:9306:: with SMTP id bc6-v6mr2974955plb.29.1517936279844; Tue, 06 Feb 2018 08:57:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517936279; cv=none; d=google.com; s=arc-20160816; b=1B3RQLWGhkbzk/woki0Ksgs/tPpxbpARShb7CuvsD4JKwiFrGdwWq7TZVwY2Ip9L3k LEDTI3YTJqTyGLEvnLLtVkQzXDDlvTA+yqMnr1nCjrpUMTtqfiltsYHm/250Rv9/nHfp 28/zv40VkvqFnuYfHDa/NJSO5ruY3w2UpbW86y4DSK55uN1yqxvliaUrA/we1FS/hbHQ U9fHd4frUYmMl7xl7nsOGvzi/Gmq9hqGzLRATX90YNxua4nOsk7OXRrePHjrAyrkKrQg qLZRCOjy8ysyXLnEVYeUlgEOczv262zCck9MP4TvnPwwlJku3QRt6uaNJbQ0r66TUsrj io2Q== 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=xosBcxsOCe3AURc8SXBlveIzWFq9uQJfKBWIZpw0Koc=; b=DiXCGFUWp9+rTeQ/o6AF49kPD0N/s+UNZOVvOwbsNyzax7PLB00Z7qrU4jlmSQzxlF znULH9rHeh6TC9O+BdmW4xKWE2oelsLnmx9GNaLaSzQ95a5CArlV5Bfmb9OToZ6aByeV boyrQkHBGuroBAMbPO8tkwPJFNMa7nuE9ykK+DEIVxvoE4yITyenC8VvGT6+C0egBp9S qtHVfyFCE40y6rBVemyHWpmwuwdYB1rvgkAvnh8DpEq2KxfzSFVPVYE9SYFzlnTQB0LJ 4ZyJIC6c6KzebIqwT/E9E6QqQC1v59y6naMLVWJPmByeybBdDB0JIY0VRaAMaiymG1GD VTJA== 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 h61-v6si1701971pld.816.2018.02.06.08.57.59; Tue, 06 Feb 2018 08:57:59 -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 S1753022AbeBFQ56 (ORCPT + 21 others); Tue, 6 Feb 2018 11:57:58 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:51534 "EHLO huawei.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1752589AbeBFQ4D (ORCPT ); Tue, 6 Feb 2018 11:56:03 -0500 Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 4E74111ECF883; Wed, 7 Feb 2018 00:55:58 +0800 (CST) Received: from localhost.localdomain (10.67.212.75) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.361.1; Wed, 7 Feb 2018 00:55:51 +0800 From: John Garry To: , , , , , , , , , CC: , , , , "John Garry" Subject: [PATCH 2/9] perf utils: add support for pmu events vendor sub-directory Date: Wed, 7 Feb 2018 01:44:57 +0800 Message-ID: <1517939104-230881-3-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1517939104-230881-1-git-send-email-john.garry@huawei.com> References: <1517939104-230881-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 arm), it is required to support a vendor sub-directory 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 --- tools/perf/pmu-events/README | 4 +++ tools/perf/pmu-events/jevents.c | 70 ++++++++++++++++++++++++++++++++++++++--- 2 files changed, 70 insertions(+), 4 deletions(-) -- 1.9.1 Acked-by: Jiri Olsa diff --git a/tools/perf/pmu-events/README b/tools/perf/pmu-events/README index 2407abc..655286f 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 9e0a21e..eb183b1 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,65 @@ 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 (dir->d_type == DT_DIR && dir->d_name[0] != '.') { + 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); @@ -773,7 +823,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 && is_leaf_dir(fpath)) { if (close_table) print_events_table_suffix(eventsfp); @@ -791,6 +841,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); } /*