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: 10093249 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 228596035E for ; Tue, 5 Dec 2017 15:33:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0A46C299B7 for ; Tue, 5 Dec 2017 15:33:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D267629B62; Tue, 5 Dec 2017 15:33:50 +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=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 E8C0029D6D for ; Tue, 5 Dec 2017 15:32:25 +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:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=tZqQKwKQCrcu2tU0G7UDLlK3A4yGOYh77nAG0gPPhns=; b=pHlXzr3sxUrYt1 UICfvozZbavc3yPUEAtuSH3znNWQ/0weceVYoOe+vQAcIr5dOwFjTOoMSiNWbKk9CNcFmFL9yupt+ sCSyuMJ1P0jlPA7mokoSYBWLcQhULIY4bnT9cgx5wOXQHCMfRS7Q0gzQb2ZC/1twySJAj07LhQoPh 9RtEckvKrdRjSkLaz51iRosOsPQ3BFbHeapxHUs2TxQhAL+X0igaCDCoHOztf6IyLTOH9O5RdPUEL v6/+fJRREsfa+zeFjCpzrqDtT6gnvyrbR4aX/zUDi9vZQVakMa58uhapL4V7se+I0806O9fCN+nBb 1zm17El2ZAW6CKxYXDrw==; 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 1eMFCq-0001fl-Lz; Tue, 05 Dec 2017 15:32:24 +0000 Received: from szxga05-in.huawei.com ([45.249.212.191] helo=huawei.com) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eMFCH-0000qI-3f for linux-arm-kernel@lists.infradead.org; Tue, 05 Dec 2017 15:31:52 +0000 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: , , , , , , , , , , , 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171205_073149_857288_C7452A72 X-CRM114-Status: GOOD ( 15.73 ) 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: John Garry , linux-kernel@vger.kernel.org, xuwei5@hisilicon.com, linuxarm@huawei.com, zhangshaokun@hisilicon.com, 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 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(-) 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); } /*