Blame SOURCES/oprofile-num_symbolic.patch

6a578a
From 6f10a5b14f5b7f43568d109633533a8ecc057fc6 Mon Sep 17 00:00:00 2001
6a578a
From: Lars Friend <l.friend@f5.com>
6a578a
Date: Tue, 15 Oct 2013 01:14:53 -0400
6a578a
Subject: [PATCH] Allow events with extra flags to also set unit_mask
6a578a
6a578a
Older distributions may be running kernels that still use the
6a578a
/dev/opcontrol interface.  On an Intel Ivy Bridge machine and similar
6a578a
processors may want to do something like:
6a578a
6a578a
opcontrol --setup --no-vmlinux \
6a578a
 --event CPU_CLK_UNHALTED:2000000:0:0:1 \
6a578a
 --event uops_executed:2000000:stall_cycles:0:1
6a578a
6a578a
For the uops_executed event in the above example need to both set the
6a578a
extra and the unit_mask bits.  The current code in opcontrol would
6a578a
never set the unit_mask bits when the extra bits were set.  This
6a578a
change allows both to be set when required.
6a578a
6a578a
Signed-off-by: William Cohen <wcohen@redhat.com>
6a578a
---
6a578a
 doc/ophelp.1.in |  4 ++++
6a578a
 utils/opcontrol |  9 +++++++--
6a578a
 utils/ophelp.c  | 27 ++++++++++++++++++++++++++-
6a578a
 3 files changed, 37 insertions(+), 3 deletions(-)
6a578a
6a578a
diff --git a/doc/ophelp.1.in b/doc/ophelp.1.in
6a578a
index 083cc85..97383bf 100644
6a578a
--- a/doc/ophelp.1.in
6a578a
+++ b/doc/ophelp.1.in
6a578a
@@ -49,6 +49,10 @@ Show the default unit mask for the given event.
6a578a
 Show the default unit mask for the given event.
6a578a
 .br
6a578a
 .TP
6a578a
+.BI "--symbolic-unit-mask / -U [event]"
6a578a
+Show the numerical unit and extra mask for given event.
6a578a
+.br
6a578a
+.TP
6a578a
 .BI "--extra-mask / -E [event]"
6a578a
 Show the extra unit mask for given event.
6a578a
 .br
6a578a
diff --git a/utils/opcontrol b/utils/opcontrol
6a578a
index 38bb1ac..a3a6a3c 100644
6a578a
--- a/utils/opcontrol
6a578a
+++ b/utils/opcontrol
6a578a
@@ -1522,9 +1522,14 @@ do_param_setup()
6a578a
 				set_ctr_param $CTR count $COUNT
6a578a
 				set_ctr_param $CTR kernel $KERNEL
6a578a
 				set_ctr_param $CTR user $USER
6a578a
-				set_ctr_param $CTR unit_mask $UNIT_MASK
6a578a
 
6a578a
-				EXTRA=`$OPHELP --extra-mask $EVENT:$COUNT:$UNIT_MASK_NAMED`
6a578a
+				# Resolve a [potentially] symbolic unit mask to a numeric
6a578a
+				# unit mask and extra mask.
6a578a
+				TMP_SYMBOLIC="`$OPHELP --symbolic-unit-mask $EVENT:$COUNT:$UNIT_MASK`"
6a578a
+				UNIT_MASK_NUM=`echo $TMP_SYMBOLIC | awk '{print $1}'`
6a578a
+				EXTRA=`echo $TMP_SYMBOLIC | awk '{print $2}'`
6a578a
+				set_ctr_param $CTR unit_mask $UNIT_MASK_NUM
6a578a
+
6a578a
 				if test "$EXTRA" -ne 0 ; then
6a578a
 				# A value >= 0x40000 returned by 'ophelp --extra-mask' (EXTRA_MIN_VAL) is interpreted
6a578a
 				# as a valid extra value; otherwise we interpret as a simple unit mask value
6a578a
diff --git a/utils/ophelp.c b/utils/ophelp.c
6a578a
index 7543c6f..f77a19a 100644
6a578a
--- a/utils/ophelp.c
6a578a
+++ b/utils/ophelp.c
6a578a
@@ -282,6 +282,22 @@ static void resolve_events(void)
6a578a
 	free(counter_map);
6a578a
 }
6a578a
 
6a578a
+static void resolve_symbolic_unit_mask(void)
6a578a
+{
6a578a
+	size_t count;
6a578a
+	unsigned extra = 0;
6a578a
+
6a578a
+	count = parse_events(parsed_events, num_chosen_events, chosen_events,
6a578a
+	                     ignore_count ? 0 : 1);
6a578a
+	if (count > 1) {
6a578a
+		fprintf(stderr, "More than one event specified.\n");
6a578a
+                exit(EXIT_FAILURE);
6a578a
+        }
6a578a
+
6a578a
+	op_resolve_unit_mask(parsed_events, &extra);
6a578a
+
6a578a
+	printf("%d %d\n", parsed_events[0].unit_mask, extra);
6a578a
+}
6a578a
 
6a578a
 static void show_unit_mask(void)
6a578a
 {
6a578a
@@ -334,6 +349,7 @@ static int check_events;
6a578a
 static int unit_mask;
6a578a
 static int get_default_event;
6a578a
 static int extra_mask;
6a578a
+static int symbolic_unit_mask;
6a578a
 
6a578a
 static struct poptOption options[] = {
6a578a
 	{ "cpu-type", 'c', POPT_ARG_STRING, &cpu_string, 0,
6a578a
@@ -356,6 +372,9 @@ static struct poptOption options[] = {
6a578a
 	   "list events as XML", NULL, },
6a578a
 	{ "extra-mask", 'E', POPT_ARG_NONE, &extra_mask, 0,
6a578a
 	  "print extra mask for event", NULL, },
6a578a
+	{ "symbolic-unit-mask", 'U', POPT_ARG_NONE, &symbolic_unit_mask, 0,
6a578a
+	  "resolve an event with symbolic unit mask into numeric unit "
6a578a
+	  "and extra masks", NULL, },
6a578a
 	POPT_AUTOHELP
6a578a
 	{ NULL, 0, 0, NULL, 0, NULL, NULL, },
6a578a
 };
6a578a
@@ -457,11 +476,17 @@ int main(int argc, char const * argv[])
6a578a
 
6a578a
 	events = op_events(cpu_type);
6a578a
 
6a578a
-	if (!chosen_events && (unit_mask || check_events || extra_mask)) {
6a578a
+	if (!chosen_events && (unit_mask || check_events || extra_mask ||
6a578a
+			symbolic_unit_mask)) {
6a578a
 		fprintf(stderr, "No events given.\n");
6a578a
 		exit(EXIT_FAILURE);
6a578a
 	}
6a578a
 
6a578a
+	if (symbolic_unit_mask) {
6a578a
+		resolve_symbolic_unit_mask();
6a578a
+		exit(EXIT_SUCCESS);
6a578a
+	}
6a578a
+
6a578a
 	if (unit_mask) {
6a578a
 		show_unit_mask();
6a578a
 		exit(EXIT_SUCCESS);
6a578a
-- 
6a578a
1.8.3.1
6a578a