[PATCH] Fix up S390 support to work with operf and ocount

Maynard Johnson <[email protected]>
Newsgroups gmane.linux.oprofile
Message-ID <[email protected]>
Andreas,
Please see if this patch works for you.  If you see anything wrong or
something you'd like changed, please let me know.  I see many more
events defined in arch/s390/kernel/perf_cpum_cf_events.c.  I'll leave
the decision to you whether or not to add support for those now (or
maybe later, post-1.0 release). 

-Maynard

-----------------------------------------------------------

Fix up S390 support to work with operf and ocount

Signed-off-by: Maynard Johnson <[email protected]>
---
 events/s390/z10/events           |    5 +++--
 events/s390/z196/events          |    2 +-
 events/s390/zEC12/events         |    5 +++--
 libop/op_events.c                |    9 ++-------
 libpe_utils/op_pe_utils.cpp      |   19 +++++++++++++++++++
 libperf_events/operf_counter.cpp |    8 +++++++-
 pe_counting/ocount_counter.cpp   |   11 +++++++++--
 7 files changed, 44 insertions(+), 15 deletions(-)

diff --git a/events/s390/z10/events b/events/s390/z10/events
index 08a2e74..9c975ae 100644
--- a/events/s390/z10/events
+++ b/events/s390/z10/events
@@ -2,6 +2,7 @@
 # Copyright (c) International Business Machines, 2011.
 # Contributed by Andreas Krebbel <[email protected]>.
 #
-# IBM System z10 Basic Mode Sampling events
+# IBM System z10 events for operf/ocount
 #
-event:0x00 counters:0 um:zero minimum:2202 name:HWSAMPLING : Sampling using Basic Mode Hardware Sampling
+event:0x00 counters:0 um:zero minimum:2202 name:CPU_CYCLES : Processor cycles
+event:0x01 counters:0 um:zero minimum:2202 name:INSTRUCTIONS : Instructions completed
diff --git a/events/s390/z196/events b/events/s390/z196/events
index 6c4bd65..c9a7526 100644
--- a/events/s390/z196/events
+++ b/events/s390/z196/events
@@ -2,6 +2,6 @@
 # Copyright (c) International Business Machines, 2011.
 # Contributed by Andreas Krebbel <[email protected]>.
 #
-# zEnterprise z196 Basic Mode Sampling events
+# zEnterprise z196 events for operf/ocount
 #
 include:s390/z10
diff --git a/events/s390/zEC12/events b/events/s390/zEC12/events
index 3a167f7..f2fb415 100644
--- a/events/s390/zEC12/events
+++ b/events/s390/zEC12/events
@@ -2,6 +2,7 @@
 # Copyright (c) International Business Machines, 2013.
 # Contributed by Andreas Krebbel <[email protected]>.
 #
-# IBM Enterprise EC12 Basic Mode Sampling events
+# IBM Enterprise EC12 events for operf/ocount
 #
-event:0x00 counters:0 um:zero minimum:19264 name:HWSAMPLING : Sampling using Basic Mode Hardware Sampling
+event:0x00 counters:0 um:zero minimum:19264 name:CPU_CYCLES : Processor cycles
+event:0x01 counters:0 um:zero minimum:19264 name:INSTRUCTIONS : Instructions completed
diff --git a/libop/op_events.c b/libop/op_events.c
index bbeb212..74da595 100644
--- a/libop/op_events.c
+++ b/libop/op_events.c
@@ -1323,13 +1323,8 @@ void op_default_event(op_cpu cpu_type, struct op_default_event_descr * descr)
 		case CPU_S390_Z10:
 		case CPU_S390_Z196:
 		case CPU_S390_ZEC12:
- 			if (op_get_nr_counters(cpu_type) > 1) {
- 				descr->name = "HWSAMPLING";
- 				descr->count = 4127518;
- 			} else {
- 				descr->name = TIMER_EVENT_NAME;
- 				descr->count = 10000;
- 			}
+			descr->name = "CPU_CYCLES";
+			descr->count = 4127518;
   			break;
 
 		case CPU_TILE_TILE64:
diff --git a/libpe_utils/op_pe_utils.cpp b/libpe_utils/op_pe_utils.cpp
index 2cff392..bd8ab38 100644
--- a/libpe_utils/op_pe_utils.cpp
+++ b/libpe_utils/op_pe_utils.cpp
@@ -940,6 +940,25 @@ void op_pe_utils::op_process_events_list(set<string> & passed_evts,
 			place++;
 		}
 		free(event_str);
+
+#ifdef __s390__
+		if (do_profiling) {
+			if (strncmp(event.name, "CPU_CYCLES", strlen(event.name)) != 0) {
+				cerr << "Profiling with " << event.name << " is not supported." << endl
+				     << "Only CPU_CYCLES is allowed to use with operf." << endl;
+				exit(EXIT_FAILURE);
+			}
+		} else {
+			if (!event.no_kernel && event.no_user) {
+				cerr << "Counting for just the kernel is not supported." << endl
+				     << "Re-run the command and simply pass the event name " << endl
+				     << "(" << event.name << ") for the event spec, without" << endl
+				     << "unit mask/kernel/user bits." << endl;
+				exit(EXIT_FAILURE);
+			}
+		}
+#endif
+
 		_get_event_code(&event, cpu_type);
 		events.push_back(event);
 	}
diff --git a/libperf_events/operf_counter.cpp b/libperf_events/operf_counter.cpp
index 936d612..8a75709 100644
--- a/libperf_events/operf_counter.cpp
+++ b/libperf_events/operf_counter.cpp
@@ -208,7 +208,14 @@ operf_counter::operf_counter(operf_event_t & evt,  bool enable_on_exec, bool do_
 		attr.sample_type |= PERF_SAMPLE_CALLCHAIN;
 	if (separate_cpu)
 		attr.sample_type |= PERF_SAMPLE_CPU;
+
+#ifdef __s390__
+	attr.type = PERF_TYPE_HARDWARE;
+	attr.exclude_hv = 0;
+#else
 	attr.type = PERF_TYPE_RAW;
+	attr.exclude_hv = evt.no_hv;
+#endif
 #if ((defined(__i386__) || defined(__x86_64__)) && (HAVE_PERF_PRECISE_IP))
 	if (evt.evt_code & EXTRA_PEBS) {
 		attr.precise_ip = 2;
@@ -223,7 +230,6 @@ operf_counter::operf_counter(operf_event_t & evt,  bool enable_on_exec, bool do_
 	attr.disabled  = 1;
 	attr.exclude_idle = 0;
 	attr.exclude_kernel = evt.no_kernel;
-	attr.exclude_hv = evt.no_hv;
 	attr.read_format = PERF_FORMAT_ID;
 	event_name = evt.name;
 	fd = id = -1;
diff --git a/pe_counting/ocount_counter.cpp b/pe_counting/ocount_counter.cpp
index eb327b1..2dd6210 100644
--- a/pe_counting/ocount_counter.cpp
+++ b/pe_counting/ocount_counter.cpp
@@ -68,15 +68,22 @@ ocount_counter::ocount_counter(operf_event_t & evt,  bool enable_on_exec,
 {
 	memset(&attr, 0, sizeof(attr));
 	attr.size = sizeof(attr);
-	attr.type = PERF_TYPE_RAW;
 	attr.config = evt.evt_code;
+#ifdef __s390__
+	attr.type = PERF_TYPE_HARDWARE;
+	attr.exclude_hv = 0;
+	if (evt.no_kernel && !evt.no_user)
+		attr.config |= 32;
+#else
+	attr.type = PERF_TYPE_RAW;
+	attr.exclude_hv = evt.no_hv;
+#endif
 	attr.inherit = inherit ? 1 : 0;
 	attr.enable_on_exec = enable_on_exec ? 1 : 0;
 	attr.disabled  = attr.enable_on_exec;
 	attr.exclude_idle = 0;
 	attr.exclude_kernel = evt.no_kernel;
 	attr.exclude_user = evt.no_user;
-	attr.exclude_hv = evt.no_hv;
 	// This format allows us to tell user percent of time an event was scheduled
 	// when multiplexing has been done by the kernel.
 	attr.read_format = PERF_FORMAT_TOTAL_TIME_ENABLED |
-- 
1.7.1


------------------------------------------------------------------------------
Infragistics Professional
Build stunning WinForms apps today!
Reboot your WinForms applications with our WinForms controls. 
Build a bridge from your legacy apps to the future.
http://pubads.g.doubleclick.net/gampad/clk?id=153845071&iu=/4140/ostg.clktrk
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.