Skip to contentSkip to conversation

perf, tools: Event files for Intel x86

PATCH New Andi Kleen 3 participants 11 messages May 21, 2015 – May 22, 2015 perf events

lore
Share & tools
lore

Andi Kleen

author
#0 lore raw

This patchkit extends Sukadev builtin event list patches for Intel x86. With that perf can build in event lists.

This also adds some missing features from the older JSON patchkits, in particular the ability to print descriptions.

I am not posting the actual event files, because they are gigantic (several MB) but you can get them from git here:

git://git.kernel.org/pub/scm/linux/kernel/git/ak/linux-misc.git perf/builtion-json-1

Currently only core events are included, not uncore.

-Andi

author
#1 lore raw

PATCH 1/6 perf, tools: Handle header line in mapfile

From: Andi Kleen <[email protected]>

Support a header line in the mapfile.csv, to match the existing mapfiles

---
 tools/perf/pmu-events/jevents.c | 2 ++
 1 file changed, 2 insertions(+)
tools/perf/pmu-events/jevents.c +2 -0
index 3afa6e9..0ad5574 100644
@@ -453,6 +453,8 @@ static int process_mapfile(FILE *outfp, char *fpath)
 
 		if (line[0] == '#')
 			continue;
+		if (!strncmp(line, "Family", 6))
+			continue;
 
 		if (line[strlen(line)-1] != '\n') {
 			/* TODO Deal with lines longer than 16K */
Signature · 1 line
2.1.0
author
#2 lore raw

PATCH 2/6 perf, tools: Allow events with dot

In reply to Andi Kleen

From: Andi Kleen <[email protected]>

The Intel events use a dot to separate event name and unit mask. Allow dot in names in the scanner, and remove special handling of dot as EOF. Also remove the hack in jevents to replace dot with underscore. This way dotted events can be specified directly by the user.

I'm not fully sure this change to the scanner is correct (what was the dot special case good for?), but I haven't found anything that breaks with it so far at least.

V2: Add the dot to name too, to handle events outside cpu//

---
 tools/perf/util/parse-events.l | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
tools/perf/util/parse-events.l +2 -3
index 09e738f..13cef3c 100644
@@ -119,8 +119,8 @@ event		[^,{}/]+
 num_dec		[0-9]+
 num_hex		0x[a-fA-F0-9]+
 num_raw_hex	[a-fA-F0-9]+
-name		[a-zA-Z_*?][a-zA-Z0-9_*?]*
-name_minus	[a-zA-Z_*?][a-zA-Z0-9\-_*?]*
+name		[a-zA-Z_*?][a-zA-Z0-9_*?.]*
+name_minus	[a-zA-Z_*?][a-zA-Z0-9\-_*?.]*
 /* If you add a modifier you need to update check_modifier() */
 modifier_event	[ukhpGHSDI]+
 modifier_bp	[rwx]{1,3}
@@ -165,7 +165,6 @@ modifier_bp	[rwx]{1,3}
 			return PE_EVENT_NAME;
 		}
 
-.		|
 <<EOF>>		{
 			BEGIN(INITIAL);
 			REWIND(0);
Signature · 1 line
2.1.0
author
#3 lore raw

PATCH 3/6 perf, tools: Support CPU id matching for x86

In reply to Andi Kleen

From: Andi Kleen <[email protected]>

Implement the code to match CPU types to mapfile types for x86 based on CPUID. This extends an existing similar function, but changes it to use the x86 mapfile cpu description. This allows to resolve event lists generated by jevents.

---
 tools/perf/arch/x86/util/header.c | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)
tools/perf/arch/x86/util/header.c +20 -3
index 146d12a..28d8c08 100644
@@ -19,8 +19,8 @@ cpuid(unsigned int op, unsigned int *a, unsigned int *b, unsigned int *c,
 			: "a" (op));
 }
 
-int
-get_cpuid(char *buffer, size_t sz)
+static int
+__get_cpuid(char *buffer, size_t sz, const char *fmt)
 {
 	unsigned int a, b, c, d, lvl;
 	int family = -1, model = -1, step = -1;
@@ -48,7 +48,7 @@ get_cpuid(char *buffer, size_t sz)
 		if (family >= 0x6)
 			model += ((a >> 16) & 0xf) << 4;
 	}
-	nb = scnprintf(buffer, sz, "%s,%u,%u,%u$", vendor, family, model, step);
+	nb = scnprintf(buffer, sz, fmt, vendor, family, model, step);
 
 	/* look for end marker to ensure the entire data fit */
 	if (strchr(buffer, '$')) {
@@ -57,3 +57,20 @@ get_cpuid(char *buffer, size_t sz)
 	}
 	return -1;
 }
+
+int
+get_cpuid(char *buffer, size_t sz)
+{
+	return __get_cpuid(buffer, sz, "%s,%u,%u,%u$");
+}
+
+bool arch_pmu_events_match_cpu(const char *vfm,
+			       const char *version __maybe_unused,
+			       const char *type __maybe_unused)
+{
+	char buf[128];
+
+	if (__get_cpuid(buf, sizeof buf, "%s-%u-%X$") < 0)
+		return false;
+	return !strcmp(vfm, buf);
+}
Signature · 1 line
2.1.0
author
#4 lore raw

PATCH 4/6 perf, tools: Support alias descriptions

In reply to Andi Kleen

From: Andi Kleen <[email protected]>

Add support to print alias descriptions in perf list, which are taken from the generated event files.

The sorting code is changed to put the events with descriptions at the end. The descriptions are printed as possibly multiple word wrapped lines.

Example output:

% perf list
...
arith.fpu_div
[Divide operations executed]
arith.fpu_div_active
[Cycles when divider is busy executing divide operations]

---
 tools/perf/util/pmu.c | 84 +++++++++++++++++++++++++++++++++++++++------------
 tools/perf/util/pmu.h |  1 +
 2 files changed, 65 insertions(+), 20 deletions(-)
tools/perf/util/pmu.c +64 -20
index 99af5d4..a90a8ee 100644
@@ -232,10 +232,7 @@ static int __perf_pmu__new_alias(struct list_head *list, char *name, char *dir,
 		perf_pmu__parse_snapshot(alias, dir, name);
 	}
 
-	/*
-	 * TODO: pickup description from Andi's patchset
-	 */
-	//alias->desc = desc ? strdpu(desc) : NULL;
+	alias->desc = desc ? strdup(desc) : NULL;
 
 	list_add_tail(&alias->list, list);
 
@@ -982,11 +979,42 @@ static char *format_alias_or(char *buf, int len, struct perf_pmu *pmu,
 	return buf;
 }
 
-static int cmp_string(const void *a, const void *b)
+struct pair {
+	char *name;
+	char *desc;
+};
+
+static int cmp_pair(const void *a, const void *b)
 {
-	const char * const *as = a;
-	const char * const *bs = b;
-	return strcmp(*as, *bs);
+	const struct pair *as = a;
+	const struct pair *bs = b;
+
+	/* Put extra events last */
+	if (!!as->desc != !!bs->desc)
+		return !!as->desc - !!bs->desc;
+	return strcmp(as->name, bs->name);
+}
+
+static void wordwrap(char *s, int start, int max, int corr)
+{
+	int column = start;
+	int n;
+
+	while (*s) {
+		int wlen = strcspn(s, " \t");
+
+		if (column + wlen >= max && column > start) {
+			printf("\n%*s", start, "");
+			column = start + corr;
+		}
+		n = printf("%s%.*s", column > start ? " " : "", wlen, s);
+		if (n <= 0)
+			break;
+		s += wlen;
+		column += n;
+		while (isspace(*s))
+			s++;
+	}
 }
 
 void print_pmu_events(const char *event_glob, bool name_only)
@@ -996,7 +1024,9 @@ void print_pmu_events(const char *event_glob, bool name_only)
 	char buf[1024];
 	int printed = 0;
 	int len, j;
-	char **aliases;
+	struct pair *aliases;
+	int numdesc = 0;
+	int columns = 78;
 
 	pmu = NULL;
 	len = 0;
@@ -1006,14 +1036,15 @@ void print_pmu_events(const char *event_glob, bool name_only)
 		if (pmu->selectable)
 			len++;
 	}
-	aliases = zalloc(sizeof(char *) * len);
+	aliases = zalloc(sizeof(struct pair) * len);
 	if (!aliases)
 		goto out_enomem;
 	pmu = NULL;
 	j = 0;
 	while ((pmu = perf_pmu__scan(pmu)) != NULL) {
 		list_for_each_entry(alias, &pmu->aliases, list) {
-			char *name = format_alias(buf, sizeof(buf), pmu, alias);
+			char *name = alias->desc ? alias->name :
+				format_alias(buf, sizeof(buf), pmu, alias);
 			bool is_cpu = !strcmp(pmu->name, "cpu");
 
 			if (event_glob != NULL &&
@@ -1022,37 +1053,50 @@ void print_pmu_events(const char *event_glob, bool name_only)
 						       event_glob))))
 				continue;
 
-			if (is_cpu && !name_only)
+			if (is_cpu && !name_only && !alias->desc)
 				name = format_alias_or(buf, sizeof(buf), pmu, alias);
 
-			aliases[j] = strdup(name);
-			if (aliases[j] == NULL)
-				goto out_enomem;
+			aliases[j].name = name;
+			if (is_cpu && !name_only && !alias->desc)
+				aliases[j].name = format_alias_or(buf, sizeof(buf),
+								  pmu, alias);
+			aliases[j].name = strdup(aliases[j].name);
+			/* failure harmless */
+			aliases[j].desc = alias->desc;
 			j++;
 		}
 		if (pmu->selectable) {
 			char *s;
 			if (asprintf(&s, "%s//", pmu->name) < 0)
 				goto out_enomem;
-			aliases[j] = s;
+			aliases[j].name = s;
 			j++;
 		}
 	}
 	len = j;
-	qsort(aliases, len, sizeof(char *), cmp_string);
+	qsort(aliases, len, sizeof(struct pair), cmp_pair);
 	for (j = 0; j < len; j++) {
 		if (name_only) {
-			printf("%s ", aliases[j]);
+			printf("%s ", aliases[j].name);
 			continue;
 		}
-		printf("  %-50s [Kernel PMU event]\n", aliases[j]);
+		if (aliases[j].desc) {
+			if (numdesc++ == 0)
+				printf("\n");
+			printf("  %-50s\n", aliases[j].name);
+			printf("%*s", 8, "[");
+			wordwrap(aliases[j].desc, 8, columns, 0);
+			printf("]\n");
+		} else
+			printf("  %-50s [Kernel PMU event]\n", aliases[j].name);
+		free(aliases[j].name);
 		printed++;
 	}
 	if (printed)
 		printf("\n");
 out_free:
 	for (j = 0; j < len; j++)
-		zfree(&aliases[j]);
+		zfree(&aliases[j].name);
 	zfree(&aliases);
 	return;
 
tools/perf/util/pmu.h +1 -0
index 7b9c8cf..e7b1010 100644
@@ -38,6 +38,7 @@ struct perf_pmu_info {
 
 struct perf_pmu_alias {
 	char *name;
+	char *desc;
 	struct list_head terms; /* HEAD struct parse_events_term -> list */
 	struct list_head list;  /* ELEM */
 	char unit[UNIT_MAX_LEN+1];
Signature · 1 line
2.1.0
author
#5 lore raw

PATCH 5/6 perf, tools: Query terminal width and use in perf list

In reply to Andi Kleen

From: Andi Kleen <[email protected]>

Automatically adapt the now wider and word wrapped perf list output to wider terminals. This requires querying the terminal before the auto pager takes over, and exporting this information from the pager subsystem.

---
 tools/perf/util/cache.h |  1 +
 tools/perf/util/pager.c | 15 +++++++++++++++
 tools/perf/util/pmu.c   |  3 ++-
 3 files changed, 18 insertions(+), 1 deletion(-)
tools/perf/util/cache.h +1 -0
index fbcca21..edf0398 100644
@@ -33,6 +33,7 @@ extern void setup_pager(void);
 extern const char *pager_program;
 extern int pager_in_use(void);
 extern int pager_use_color;
+int pager_get_columns(void);
 
 char *alias_lookup(const char *alias);
 int split_cmdline(char *cmdline, const char ***argv);
tools/perf/util/pager.c +15 -0
index 31ee02d..9761202 100644
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "run-command.h"
 #include "sigchain.h"
+#include <sys/ioctl.h>
 
 /*
  * This is split up from the rest of git so that we can do
@@ -8,6 +9,7 @@
  */
 
 static int spawned_pager;
+static int pager_columns;
 
 static void pager_preexec(void)
 {
@@ -47,9 +49,12 @@ static void wait_for_pager_signal(int signo)
 void setup_pager(void)
 {
 	const char *pager = getenv("PERF_PAGER");
+	struct winsize sz;
 
 	if (!isatty(1))
 		return;
+	if (ioctl(1, TIOCGWINSZ, &sz) == 0)
+		pager_columns = sz.ws_col;
 	if (!pager) {
 		if (!pager_program)
 			perf_config(perf_default_config, NULL);
@@ -98,3 +103,13 @@ int pager_in_use(void)
 	env = getenv("PERF_PAGER_IN_USE");
 	return env ? perf_config_bool("PERF_PAGER_IN_USE", env) : 0;
 }
+
+int pager_get_columns(void)
+{
+	char *s;
+
+	s = getenv("COLUMNS");
+	if (s)
+		return atoi(s);
+	return (pager_columns ? pager_columns : 80) - 2;
+}
tools/perf/util/pmu.c +2 -1
index a90a8ee..a34cbdb 100644
@@ -13,6 +13,7 @@
 #include "pmu-events/pmu-events.h"	// Move to global file???
 #include "cpumap.h"
 #include "header.h"
+#include "cache.h"
 
 struct perf_pmu_format {
 	char *name;
@@ -1026,7 +1027,7 @@ void print_pmu_events(const char *event_glob, bool name_only)
 	int len, j;
 	struct pair *aliases;
 	int numdesc = 0;
-	int columns = 78;
+	int columns = pager_get_columns();
 
 	pmu = NULL;
 	len = 0;
Signature · 1 line
2.1.0
author
#6 lore raw

PATCH 6/6 perf, tools: Add a --no-desc flag to perf list

In reply to Andi Kleen

From: Andi Kleen <[email protected]>

Add a --no-desc flag to perf list to not print the event descriptions that were earlier added for JSON events. This may be useful to get a less crowded listing.

It's still default to print descriptions as that is the more useful default for most users.

v2: Rename --quiet to --no-desc. Add option to man page.

---
 tools/perf/Documentation/perf-list.txt |  8 +++++++-
 tools/perf/builtin-list.c              | 12 ++++++++----
 tools/perf/util/parse-events.c         |  4 ++--
 tools/perf/util/parse-events.h         |  2 +-
 tools/perf/util/pmu.c                  |  4 ++--
 tools/perf/util/pmu.h                  |  2 +-
 6 files changed, 21 insertions(+), 11 deletions(-)
tools/perf/Documentation/perf-list.txt +7 -1
index bada893..9507552 100644
@@ -8,13 +8,19 @@ perf-list - List all symbolic event types
 SYNOPSIS
 --------
 [verse]
-'perf list' [hw|sw|cache|tracepoint|pmu|event_glob]
+'perf list' [--no-desc] [hw|sw|cache|tracepoint|pmu|event_glob]
 
 DESCRIPTION
 -----------
 This command displays the symbolic event types which can be selected in the
 various perf commands with the -e option.
 
+OPTIONS
+-------
+--no-desc::
+Don't print descriptions.
+
+
 [[EVENT_MODIFIERS]]
 EVENT MODIFIERS
 ---------------
tools/perf/builtin-list.c +8 -4
index af5bd05..3f058f7 100644
@@ -16,16 +16,20 @@
 #include "util/pmu.h"
 #include "util/parse-options.h"
 
+static bool desc_flag = true;
+
 int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused)
 {
 	int i;
 	bool raw_dump = false;
 	struct option list_options[] = {
 		OPT_BOOLEAN(0, "raw-dump", &raw_dump, "Dump raw events"),
+		OPT_BOOLEAN('d', "desc", &desc_flag,
+			    "Print extra event descriptions. --no-desc to not print."),
 		OPT_END()
 	};
 	const char * const list_usage[] = {
-		"perf list [hw|sw|cache|tracepoint|pmu|event_glob]",
+		"perf list [--no-desc] [hw|sw|cache|tracepoint|pmu|event_glob]",
 		NULL
 	};
 
@@ -40,7 +44,7 @@ int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused)
 		printf("\nList of pre-defined events (to be used in -e):\n\n");
 
 	if (argc == 0) {
-		print_events(NULL, raw_dump);
+		print_events(NULL, raw_dump, !desc_flag);
 		return 0;
 	}
 
@@ -59,13 +63,13 @@ int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused)
 			 strcmp(argv[i], "hwcache") == 0)
 			print_hwcache_events(NULL, raw_dump);
 		else if (strcmp(argv[i], "pmu") == 0)
-			print_pmu_events(NULL, raw_dump);
+			print_pmu_events(NULL, raw_dump, !desc_flag);
 		else {
 			char *sep = strchr(argv[i], ':'), *s;
 			int sep_idx;
 
 			if (sep == NULL) {
-				print_events(argv[i], raw_dump);
+				print_events(argv[i], raw_dump, !desc_flag);
 				continue;
 			}
 			sep_idx = sep - argv[i];
tools/perf/util/parse-events.c +2 -2
index 80a50fd..750dbd7 100644
@@ -1527,7 +1527,7 @@ out_enomem:
 /*
  * Print the help text for the event symbols:
  */
-void print_events(const char *event_glob, bool name_only)
+void print_events(const char *event_glob, bool name_only, bool quiet_flag)
 {
 	print_symbol_events(event_glob, PERF_TYPE_HARDWARE,
 			    event_symbols_hw, PERF_COUNT_HW_MAX, name_only);
@@ -1537,7 +1537,7 @@ void print_events(const char *event_glob, bool name_only)
 
 	print_hwcache_events(event_glob, name_only);
 
-	print_pmu_events(event_glob, name_only);
+	print_pmu_events(event_glob, name_only, quiet_flag);
 
 	if (event_glob != NULL)
 		return;
tools/perf/util/parse-events.h +1 -1
index e236f1b..9f2b57d 100644
@@ -127,7 +127,7 @@ void parse_events_update_lists(struct list_head *list_event,
 void parse_events_evlist_error(struct parse_events_evlist *data,
 			       int idx, const char *str);
 
-void print_events(const char *event_glob, bool name_only);
+void print_events(const char *event_glob, bool name_only, bool quiet);
 
 struct event_symbol {
 	const char	*symbol;
tools/perf/util/pmu.c +2 -2
index a34cbdb..4376182 100644
@@ -1018,7 +1018,7 @@ static void wordwrap(char *s, int start, int max, int corr)
 	}
 }
 
-void print_pmu_events(const char *event_glob, bool name_only)
+void print_pmu_events(const char *event_glob, bool name_only, bool quiet_flag)
 {
 	struct perf_pmu *pmu;
 	struct perf_pmu_alias *alias;
@@ -1081,7 +1081,7 @@ void print_pmu_events(const char *event_glob, bool name_only)
 			printf("%s ", aliases[j].name);
 			continue;
 		}
-		if (aliases[j].desc) {
+		if (aliases[j].desc && !quiet_flag) {
 			if (numdesc++ == 0)
 				printf("\n");
 			printf("  %-50s\n", aliases[j].name);
tools/perf/util/pmu.h +1 -1
index e7b1010..9966c1a 100644
@@ -69,7 +69,7 @@ int perf_pmu__format_parse(char *dir, struct list_head *head);
 
 struct perf_pmu *perf_pmu__scan(struct perf_pmu *pmu);
 
-void print_pmu_events(const char *event_glob, bool name_only);
+void print_pmu_events(const char *event_glob, bool name_only, bool quiet);
 bool pmu_have_event(const char *pname, const char *name);
 
 int perf_pmu__scan_file(struct perf_pmu *pmu, const char *name, const char *fmt,
Signature · 1 line
2.1.0
#7 lore raw
In reply to Andi Kleen
Quoted 2 lines · Andi Kleen

This patchkit extends Sukadev builtin event list patches for Intel x86. With that perf can build in event lists.

Sukadev,
could you please pick it up fr your next patchset version, so we have only single patchset?

Quoted 10 lines

This also adds some missing features from the older JSON patchkits, in particular the ability to print descriptions.

I am not posting the actual event files, because they are gigantic (several MB) but you can get them from git here:

git://git.kernel.org/pub/scm/linux/kernel/git/ak/linux-misc.git perf/builtion-json-1

Currently only core events are included, not uncore.

hum, not sure how you guys want to handle this, but it'd be nice to have all the bits in one place.. Could one of you guys please arrange branch with all this?

thanks,
jirka

author
#8 lore raw
Quoted 5 lines
Quoted 1 line

Currently only core events are included, not uncore.

hum, not sure how you guys want to handle this, but it'd be nice to have all the bits in one place.. Could one of you guys please arrange branch with all this?

I would suggest to handle the code together in a single branch. And then handle the events separately per architecture, just as pull requests without posting. I doubt anyone on linux-kernel would be happy about getting that large files in mail; in fact the list software may not allow it.

-Andi

Signature · 1 line
[email protected] -- Speaking for myself only.
#9 lore raw
Quoted 11 lines · Andi Kleen
Quoted 5 lines
Quoted 1 line

Currently only core events are included, not uncore.

hum, not sure how you guys want to handle this, but it'd be nice to have all the bits in one place.. Could one of you guys please arrange branch with all this?

I would suggest to handle the code together in a single branch. And then handle the events separately per architecture, just as pull requests without posting. I doubt anyone on linux-kernel would be happy about getting that large files in mail; in fact the list software may not allow it.

sounds good

jirka

#10 lore raw
In reply to Jiri Olsa

Jiri Olsa [[email protected]] wrote:

| On Wed, May 20, 2015 at 09:11:27PM -0700, Andi Kleen wrote:
| > This patchkit extends Sukadev builtin event list patches for Intel x86.
| > With that perf can build in event lists.
| 
| Sukadev,
| could you please pick it up fr your next patchset version,
| so we have only single patchset?

Sure.

| 
| > 
| > This also adds some missing features from the older JSON patchkits,
| > in particular the ability to print descriptions.
| > 
| > I am not posting the actual event files, because they are gigantic
| > (several MB) but you can get them from git here:
| > 
| > git://git.kernel.org/pub/scm/linux/kernel/git/ak/linux-misc.git perf/builtion-json-1
| > 
| > Currently only core events are included, not uncore.
| 
| hum, not sure how you guys want to handle this, but it'd be nice
| to have all the bits in one place.. Could one of you guys please 
| arrange branch with all this?

Are you referring to the patches or the Intel JSON files? For the latter, I would leave it to Andi to checkin the files.

| 
| thanks,
| jirka