Blame SOURCES/oprofile-num_symbolic.patch

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