lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Wed,  4 Jul 2012 00:00:45 +0200
From:	Jiri Olsa <jolsa@...hat.com>
To:	acme@...hat.com, a.p.zijlstra@...llo.nl, mingo@...e.hu,
	paulus@...ba.org, cjashfor@...ux.vnet.ibm.com, fweisbec@...il.com,
	eranian@...gle.com
Cc:	linux-kernel@...r.kernel.org, Jiri Olsa <jolsa@...hat.com>
Subject: [PATCH 07/10] perf, tool: Add support to specify hw event as pmu event term

Adding a way to specify hw event as pmu event term like:
 'cpu/event=cycles/u'
 'cpu/event=instructions,.../u'

The 'event=cycles' term needs to be replaced/translated by the hw
events term translation, which is exposed by sysfs 'events' group
attribute.

The 'events' attribute is handled by the pmu alias code, so the
only thing we need to ensure is to map the event name to the proper
sysfs attribute name.

It's possible to use sysfs attribute name as 'event' term value,
or any possible alias for hw event, e.g.:
  cycles                     OR cpu-cycles
  branch_misses              OR branch-misses
  bus_cycles                 OR bus-cycles
  cache_misses               OR cache-misses
  cache_references           OR cache-references
  ref_cycles                 OR ref-cycles
  stalled_cycles_backend     OR stalled-cycles-backend
  stalled_cycles_frontend    OR stalled-cycles-frontend

Signed-off-by: Jiri Olsa <jolsa@...hat.com>
---
 tools/perf/util/parse-events.c |   29 +++++++++++++++++++++++++++++
 tools/perf/util/parse-events.h |    2 ++
 tools/perf/util/parse-events.y |    9 +++++++++
 3 files changed, 40 insertions(+)

diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 6d12b39..a0fb567 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -21,6 +21,11 @@
 struct event_symbol {
 	const char	*symbol;
 	const char	*alias;
+	/*
+	 * The attribute name inside the 'events' sysfs
+	 * group. Only for HW events.
+	 */
+	const char	*sysfs;
 };
 
 #ifdef PARSER_DEBUG
@@ -32,42 +37,52 @@ static struct event_symbol event_symbols_hw[PERF_COUNT_HW_MAX] = {
 	[PERF_COUNT_HW_CPU_CYCLES] = {
 		.symbol = "cpu-cycles",
 		.alias  = "cycles",
+		.sysfs  = "cycles",
 	},
 	[PERF_COUNT_HW_INSTRUCTIONS] = {
 		.symbol = "instructions",
 		.alias  = "",
+		.sysfs  = "instructions",
 	},
 	[PERF_COUNT_HW_CACHE_REFERENCES] = {
 		.symbol = "cache-references",
 		.alias  = "",
+		.sysfs  = "cache_references",
 	},
 	[PERF_COUNT_HW_CACHE_MISSES] = {
 		.symbol = "cache-misses",
 		.alias  = "",
+		.sysfs  = "cache_misses",
 	},
 	[PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = {
 		.symbol = "branch-instructions",
 		.alias  = "branches",
+		.sysfs  = "branch_instructions",
 	},
 	[PERF_COUNT_HW_BRANCH_MISSES] = {
 		.symbol = "branch-misses",
 		.alias  = "",
+		.sysfs  = "branch_misses",
 	},
 	[PERF_COUNT_HW_BUS_CYCLES] = {
 		.symbol = "bus-cycles",
 		.alias  = "",
+		.sysfs  = "bus_cycles",
 	},
 	[PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] = {
 		.symbol = "stalled-cycles-frontend",
 		.alias  = "idle-cycles-frontend",
+		.sysfs  = "stalled_cycles_frontend",
 	},
 	[PERF_COUNT_HW_STALLED_CYCLES_BACKEND] = {
 		.symbol = "stalled-cycles-backend",
 		.alias  = "idle-cycles-backend",
+		.sysfs  = "stalled_cycles_backend",
 	},
 	[PERF_COUNT_HW_REF_CPU_CYCLES] = {
 		.symbol = "ref-cycles",
 		.alias  = "",
+		.sysfs  = "ref_cycles",
 	},
 };
 
@@ -1037,6 +1052,20 @@ int parse_events__term_str(struct parse_events__term **term,
 			config, str, 0);
 }
 
+int parse_events__term_sym_hw(struct parse_events__term **term,
+			      char *config, unsigned idx)
+{
+	struct event_symbol *sym;
+
+	BUG_ON(idx >= PERF_COUNT_HW_MAX);
+	sym = &event_symbols_hw[idx];
+	BUG_ON(!sym->sysfs);
+
+	return new_term(term, PARSE_EVENTS__TERM_TYPE_STR,
+			PARSE_EVENTS__TERM_TYPE_USER, config,
+			(char *) sym->sysfs, 0);
+}
+
 int parse_events__term_clone(struct parse_events__term **new,
 			     struct parse_events__term *term)
 {
diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h
index ee9c218..eaf2fd7 100644
--- a/tools/perf/util/parse-events.h
+++ b/tools/perf/util/parse-events.h
@@ -76,6 +76,8 @@ int parse_events__term_num(struct parse_events__term **_term,
 			   int type_term, char *config, long num);
 int parse_events__term_str(struct parse_events__term **_term,
 			   int type_term, char *config, char *str);
+int parse_events__term_sym_hw(struct parse_events__term **term,
+			      char *config, unsigned idx);
 int parse_events__term_clone(struct parse_events__term **new,
 			     struct parse_events__term *term);
 void parse_events__free_terms(struct list_head *terms);
diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y
index 2bc5fbf..9c74d8a 100644
--- a/tools/perf/util/parse-events.y
+++ b/tools/perf/util/parse-events.y
@@ -269,6 +269,15 @@ PE_NAME '=' PE_VALUE
 	$$ = term;
 }
 |
+PE_NAME '=' PE_VALUE_SYM_HW
+{
+	struct parse_events__term *term;
+	int config = $3 & 255;
+
+	ABORT_ON(parse_events__term_sym_hw(&term, $1, config));
+	$$ = term;
+}
+|
 PE_NAME
 {
 	struct parse_events__term *term;
-- 
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ