linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: John Garry <john.garry@huawei.com>
To: <peterz@infradead.org>, <mingo@redhat.com>, <acme@kernel.org>,
	<jolsa@redhat.com>, <alexander.shishkin@linux.intel.com>,
	<namhyung@kernel.org>, <ak@linux.intel.com>, <wcohen@redhat.com>,
	<will.deacon@arm.com>, <ganapatrao.kulkarni@cavium.com>,
	<catalin.marinas@arm.com>, <mark.rutland@arm.com>
Cc: <xuwei5@hisilicon.com>, <linuxarm@huawei.com>,
	<zhangshaokun@hisilicon.com>,
	<linux-arm-kernel@lists.infradead.org>,
	<linux-kernel@vger.kernel.org>,
	John Garry <john.garry@huawei.com>
Subject: [RFC PATCH 1/5] perf jevents: add support for pmu events vendor subdirectory
Date: Wed, 6 Dec 2017 00:13:15 +0800	[thread overview]
Message-ID: <1512490399-94107-2-git-send-email-john.garry@huawei.com> (raw)
In-Reply-To: <1512490399-94107-1-git-send-email-john.garry@huawei.com>

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 <john.garry@huawei.com>
---
 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);
 	}
 
 	/*
-- 
1.9.1

  reply	other threads:[~2017-12-05 15:31 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-05 16:13 [RFC PATCH 0/5] perf events patches for improved ARM64 support John Garry
2017-12-05 16:13 ` John Garry [this message]
2017-12-06 13:38   ` [RFC PATCH 1/5] perf jevents: add support for pmu events vendor subdirectory Jiri Olsa
2017-12-06 14:41     ` John Garry
2017-12-05 16:13 ` [RFC PATCH 2/5] perf jevents: add support for arch recommended events John Garry
2017-12-05 17:27   ` Andi Kleen
2017-12-06  8:34     ` John Garry
2017-12-06 13:36   ` Jiri Olsa
2017-12-06 15:20     ` John Garry
2017-12-08 12:29       ` Jiri Olsa
2017-12-08 15:42         ` John Garry
2017-12-09  7:31           ` Jiri Olsa
2017-12-11 10:25             ` John Garry
2017-12-15 11:22             ` John Garry
2017-12-16 18:47               ` Andi Kleen
2018-01-02 12:07                 ` John Garry
2018-01-02 17:48                   ` Andi Kleen
2018-01-03 12:22                     ` John Garry
2017-12-21 19:39               ` Jiri Olsa
2018-01-04 17:17                 ` John Garry
2018-01-08 14:08                   ` Jiri Olsa
2017-12-06 13:37   ` Jiri Olsa
2017-12-06 14:40     ` John Garry
2017-12-08 12:31       ` Jiri Olsa
2017-12-08 15:38         ` John Garry
2017-12-09  7:26           ` Jiri Olsa
2017-12-05 16:13 ` [RFC PATCH 3/5] perf vendor events arm64: add armv8 recommended events JSON John Garry
2017-12-05 16:13 ` [RFC PATCH 4/5] perf vendor events arm64: relocate thunderx2 JSON John Garry
2017-12-05 16:13 ` [RFC PATCH 5/5] perf vendor events arm64: add HiSilicon hip08 JSON John Garry
2017-12-06 16:42 ` [RFC PATCH 0/5] perf events patches for improved ARM64 support William Cohen
2017-12-06 17:35   ` John Garry

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1512490399-94107-2-git-send-email-john.garry@huawei.com \
    --to=john.garry@huawei.com \
    --cc=acme@kernel.org \
    --cc=ak@linux.intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=catalin.marinas@arm.com \
    --cc=ganapatrao.kulkarni@cavium.com \
    --cc=jolsa@redhat.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxarm@huawei.com \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=wcohen@redhat.com \
    --cc=will.deacon@arm.com \
    --cc=xuwei5@hisilicon.com \
    --cc=zhangshaokun@hisilicon.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).