All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH/RFC 0/4] perf kvm: add stat support for s390
@ 2014-07-03 14:29 Alexander Yarygin
  2014-07-03 14:29 ` [PATCH 1/4] perf kvm: Use defines of kvm events Alexander Yarygin
                   ` (5 more replies)
  0 siblings, 6 replies; 23+ messages in thread
From: Alexander Yarygin @ 2014-07-03 14:29 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: David Ahern, Peter Zijlstra, Paul Mackerras, Ingo Molnar,
	Arnaldo Carvalho de Melo, Christian Borntraeger, Cornelia Huck,
	linux-kernel, Alexander Yarygin

Currently, a lot of code in buildin-kvm.c are x86 specific.
In accordance with the proposal of David Ahern, we moved the code under
#ifdefs from buildin-kvm.c into tools/perf/arch/*/kvm-stat.c. Architecture
specific constants were added in arch/*/include/uapi/perf-kvm.h. Also,
generic perf kvm stat structures were moved into the new file util/kvm-stat.h.

So, patches 1-3 reduce architecture dependency of buildin-kvm.c.
Patch 4 implements s390 specific functions. Since some events on s390
can have tree-like structure, the patch also adds functions to handle
these events in generic code.

The patch set based on linux-3.16-rc1 including patches in
"perf kvm: refactoring and small changes".

Link to the "perf kvm: refactoring and small changes" patch series:
https://lkml.org/lkml/2014/7/3/461
Link to the previous thread: https://lkml.org/lkml/2014/4/25/331

Alexander Yarygin (4):
  perf kvm: Use defines of kvm events
  perf kvm: Move arch specific code into arch/
  perf kvm: Add skip_event() for --duration option
  perf kvm: Add stat support on s390

 arch/s390/include/uapi/asm/Kbuild     |    1 +
 arch/s390/include/uapi/asm/kvm_perf.h |   25 +++
 arch/x86/include/uapi/asm/Kbuild      |    1 +
 arch/x86/include/uapi/asm/kvm_perf.h  |   16 ++
 tools/perf/Documentation/perf-kvm.txt |   10 +-
 tools/perf/MANIFEST                   |    3 +
 tools/perf/Makefile.perf              |    1 +
 tools/perf/arch/s390/Makefile         |    2 +
 tools/perf/arch/s390/util/kvm-stat.c  |  105 +++++++++
 tools/perf/arch/x86/Makefile          |    1 +
 tools/perf/arch/x86/util/kvm-stat.c   |  156 ++++++++++++++
 tools/perf/builtin-kvm.c              |  384 +++++++++------------------------
 tools/perf/util/kvm-stat.h            |  140 ++++++++++++
 13 files changed, 561 insertions(+), 284 deletions(-)
 create mode 100644 arch/s390/include/uapi/asm/kvm_perf.h
 create mode 100644 arch/x86/include/uapi/asm/kvm_perf.h
 create mode 100644 tools/perf/arch/s390/util/kvm-stat.c
 create mode 100644 tools/perf/arch/x86/util/kvm-stat.c
 create mode 100644 tools/perf/util/kvm-stat.h

--
1.7.9.5


^ permalink raw reply	[flat|nested] 23+ messages in thread

* [PATCH 1/4] perf kvm: Use defines of kvm events
  2014-07-03 14:29 [PATCH/RFC 0/4] perf kvm: add stat support for s390 Alexander Yarygin
@ 2014-07-03 14:29 ` Alexander Yarygin
  2014-07-07 14:06   ` Christian Borntraeger
                     ` (2 more replies)
  2014-07-03 14:29 ` [PATCH 2/4] perf kvm: Move arch specific code into arch/ Alexander Yarygin
                   ` (4 subsequent siblings)
  5 siblings, 3 replies; 23+ messages in thread
From: Alexander Yarygin @ 2014-07-03 14:29 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: David Ahern, Peter Zijlstra, Paul Mackerras, Ingo Molnar,
	Arnaldo Carvalho de Melo, Christian Borntraeger, Cornelia Huck,
	linux-kernel, Alexander Yarygin

Currently perf-kvm uses string literals for kvm event names,
but it works only for x86, because other architectures may have
other names for those events.

To reduce dependence on architecture, we add <asm/kvm_perf.h> file with
defines for:
- kvm_entry and kvm_exit events,
- exit reason field name in kvm_exit event,
- length of exit reasons strings,
- vcpu_id field name in kvm trace events,

and replace literals in perf-kvm.

Signed-off-by: Alexander Yarygin <yarygin@linux.vnet.ibm.com>
Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
---
 arch/x86/include/uapi/asm/Kbuild     |    1 +
 arch/x86/include/uapi/asm/kvm_perf.h |   16 ++++++++++++++++
 tools/perf/MANIFEST                  |    1 +
 tools/perf/builtin-kvm.c             |   34 ++++++++++++++++------------------
 4 files changed, 34 insertions(+), 18 deletions(-)
 create mode 100644 arch/x86/include/uapi/asm/kvm_perf.h

diff --git a/arch/x86/include/uapi/asm/Kbuild b/arch/x86/include/uapi/asm/Kbuild
index 09409c4..3dec769 100644
--- a/arch/x86/include/uapi/asm/Kbuild
+++ b/arch/x86/include/uapi/asm/Kbuild
@@ -22,6 +22,7 @@ header-y += ipcbuf.h
 header-y += ist.h
 header-y += kvm.h
 header-y += kvm_para.h
+header-y += kvm_perf.h
 header-y += ldt.h
 header-y += mce.h
 header-y += mman.h
diff --git a/arch/x86/include/uapi/asm/kvm_perf.h b/arch/x86/include/uapi/asm/kvm_perf.h
new file mode 100644
index 0000000..3bb964f
--- /dev/null
+++ b/arch/x86/include/uapi/asm/kvm_perf.h
@@ -0,0 +1,16 @@
+#ifndef _ASM_X86_KVM_PERF_H
+#define _ASM_X86_KVM_PERF_H
+
+#include <asm/svm.h>
+#include <asm/vmx.h>
+#include <asm/kvm.h>
+
+#define DECODE_STR_LEN 20
+
+#define VCPU_ID "vcpu_id"
+
+#define KVM_ENTRY_TRACE "kvm:kvm_entry"
+#define KVM_EXIT_TRACE "kvm:kvm_exit"
+#define KVM_EXIT_REASON "exit_reason"
+
+#endif /* _ASM_X86_KVM_PERF_H */
diff --git a/tools/perf/MANIFEST b/tools/perf/MANIFEST
index 45da209..02b485d 100644
--- a/tools/perf/MANIFEST
+++ b/tools/perf/MANIFEST
@@ -37,3 +37,4 @@ arch/x86/include/asm/kvm_host.h
 arch/x86/include/uapi/asm/svm.h
 arch/x86/include/uapi/asm/vmx.h
 arch/x86/include/uapi/asm/kvm.h
+arch/x86/include/uapi/asm/kvm_perf.h
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index 41dbeaf..6d73346 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -30,9 +30,7 @@
 #include <math.h>
 
 #ifdef HAVE_KVM_STAT_SUPPORT
-#include <asm/svm.h>
-#include <asm/vmx.h>
-#include <asm/kvm.h>
+#include <asm/kvm_perf.h>
 
 struct event_key {
 	#define INVALID_KEY     (~0ULL)
@@ -75,7 +73,7 @@ struct kvm_events_ops {
 	bool (*is_end_event)(struct perf_evsel *evsel,
 			     struct perf_sample *sample, struct event_key *key);
 	void (*decode_key)(struct perf_kvm_stat *kvm, struct event_key *key,
-			   char decode[20]);
+			   char *decode);
 	const char *name;
 };
 
@@ -126,12 +124,12 @@ static void exit_event_get_key(struct perf_evsel *evsel,
 			       struct event_key *key)
 {
 	key->info = 0;
-	key->key = perf_evsel__intval(evsel, sample, "exit_reason");
+	key->key = perf_evsel__intval(evsel, sample, KVM_EXIT_REASON);
 }
 
 static bool kvm_exit_event(struct perf_evsel *evsel)
 {
-	return !strcmp(evsel->name, "kvm:kvm_exit");
+	return !strcmp(evsel->name, KVM_EXIT_TRACE);
 }
 
 static bool exit_event_begin(struct perf_evsel *evsel,
@@ -147,7 +145,7 @@ static bool exit_event_begin(struct perf_evsel *evsel,
 
 static bool kvm_entry_event(struct perf_evsel *evsel)
 {
-	return !strcmp(evsel->name, "kvm:kvm_entry");
+	return !strcmp(evsel->name, KVM_ENTRY_TRACE);
 }
 
 static bool exit_event_end(struct perf_evsel *evsel,
@@ -182,12 +180,12 @@ static const char *get_exit_reason(struct perf_kvm_stat *kvm,
 
 static void exit_event_decode_key(struct perf_kvm_stat *kvm,
 				  struct event_key *key,
-				  char decode[20])
+				  char *decode)
 {
 	const char *exit_reason = get_exit_reason(kvm, kvm->exit_reasons,
 						  key->key);
 
-	scnprintf(decode, 20, "%s", exit_reason);
+	scnprintf(decode, DECODE_STR_LEN, "%s", exit_reason);
 }
 
 static struct kvm_events_ops exit_events = {
@@ -249,9 +247,9 @@ static bool mmio_event_end(struct perf_evsel *evsel, struct perf_sample *sample,
 
 static void mmio_event_decode_key(struct perf_kvm_stat *kvm __maybe_unused,
 				  struct event_key *key,
-				  char decode[20])
+				  char *decode)
 {
-	scnprintf(decode, 20, "%#lx:%s", (unsigned long)key->key,
+	scnprintf(decode, DECODE_STR_LEN, "%#lx:%s", (unsigned long)key->key,
 				key->info == KVM_TRACE_MMIO_WRITE ? "W" : "R");
 }
 
@@ -292,9 +290,9 @@ static bool ioport_event_end(struct perf_evsel *evsel,
 
 static void ioport_event_decode_key(struct perf_kvm_stat *kvm __maybe_unused,
 				    struct event_key *key,
-				    char decode[20])
+				    char *decode)
 {
-	scnprintf(decode, 20, "%#llx:%s", (unsigned long long)key->key,
+	scnprintf(decode, DECODE_STR_LEN, "%#llx:%s", (unsigned long long)key->key,
 				key->info ? "POUT" : "PIN");
 }
 
@@ -524,7 +522,7 @@ static bool handle_end_event(struct perf_kvm_stat *kvm,
 	time_diff = sample->time - time_begin;
 
 	if (kvm->duration && time_diff > kvm->duration) {
-		char decode[32];
+		char decode[DECODE_STR_LEN];
 
 		kvm->events_ops->decode_key(kvm, &event->key, decode);
 		if (strcmp(decode, "HLT")) {
@@ -552,7 +550,7 @@ struct vcpu_event_record *per_vcpu_record(struct thread *thread,
 			return NULL;
 		}
 
-		vcpu_record->vcpu_id = perf_evsel__intval(evsel, sample, "vcpu_id");
+		vcpu_record->vcpu_id = perf_evsel__intval(evsel, sample, VCPU_ID);
 		thread->priv = vcpu_record;
 	}
 
@@ -739,7 +737,7 @@ static void show_timeofday(void)
 
 static void print_result(struct perf_kvm_stat *kvm)
 {
-	char decode[20];
+	char decode[DECODE_STR_LEN];
 	struct kvm_event *event;
 	int vcpu = kvm->trace_vcpu;
 
@@ -750,7 +748,7 @@ static void print_result(struct perf_kvm_stat *kvm)
 
 	pr_info("\n\n");
 	print_vcpu_info(kvm);
-	pr_info("%20s ", kvm->events_ops->name);
+	pr_info("%*s ", DECODE_STR_LEN, kvm->events_ops->name);
 	pr_info("%10s ", "Samples");
 	pr_info("%9s ", "Samples%");
 
@@ -769,7 +767,7 @@ static void print_result(struct perf_kvm_stat *kvm)
 		min = get_event_min(event, vcpu);
 
 		kvm->events_ops->decode_key(kvm, &event->key, decode);
-		pr_info("%20s ", decode);
+		pr_info("%*s ", DECODE_STR_LEN, decode);
 		pr_info("%10llu ", (unsigned long long)ecount);
 		pr_info("%8.2f%% ", (double)ecount / kvm->total_count * 100);
 		pr_info("%8.2f%% ", (double)etime / kvm->total_time * 100);
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH 2/4] perf kvm: Move arch specific code into arch/
  2014-07-03 14:29 [PATCH/RFC 0/4] perf kvm: add stat support for s390 Alexander Yarygin
  2014-07-03 14:29 ` [PATCH 1/4] perf kvm: Use defines of kvm events Alexander Yarygin
@ 2014-07-03 14:29 ` Alexander Yarygin
  2014-07-07 14:09   ` Christian Borntraeger
                     ` (2 more replies)
  2014-07-03 14:29 ` [PATCH 3/4] perf kvm: Add skip_event() for --duration option Alexander Yarygin
                   ` (3 subsequent siblings)
  5 siblings, 3 replies; 23+ messages in thread
From: Alexander Yarygin @ 2014-07-03 14:29 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: David Ahern, Peter Zijlstra, Paul Mackerras, Ingo Molnar,
	Arnaldo Carvalho de Melo, Christian Borntraeger, Cornelia Huck,
	linux-kernel, Alexander Yarygin

Parts of a 'perf kvm stat' code make sense only for x86.
Let's move this code into the arch/x86/kvm-stat.c file and add
util/kvm-stat.h for generic structure definitions.

Add a global array 'kvm_reg_events_ops' for accessing the
arch-specific 'kvm_events_ops' from generic code.

Since the several global arrays (i.e. 'kvm_events_tp') have been moved
to arch/*, we can not know their sizes and use them directly in
builtin-kvm.c. This patch fixes that problem by adding trimming
NULL element to each array and changing the behavior of their handlers
in generic code.

Signed-off-by: Alexander Yarygin <yarygin@linux.vnet.ibm.com>
Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
---
 tools/perf/Makefile.perf            |    1 +
 tools/perf/arch/x86/Makefile        |    1 +
 tools/perf/arch/x86/util/kvm-stat.c |  151 ++++++++++++++++++
 tools/perf/builtin-kvm.c            |  297 ++++-------------------------------
 tools/perf/util/kvm-stat.h          |  130 +++++++++++++++
 5 files changed, 317 insertions(+), 263 deletions(-)
 create mode 100644 tools/perf/arch/x86/util/kvm-stat.c
 create mode 100644 tools/perf/util/kvm-stat.h

diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index ae20edf..f1a590f 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -300,6 +300,7 @@ LIB_H += ui/progress.h
 LIB_H += ui/util.h
 LIB_H += ui/ui.h
 LIB_H += util/data.h
+LIB_H += util/kvm-stat.h
 
 LIB_OBJS += $(OUTPUT)util/abspath.o
 LIB_OBJS += $(OUTPUT)util/alias.o
diff --git a/tools/perf/arch/x86/Makefile b/tools/perf/arch/x86/Makefile
index d393901..9b21881 100644
--- a/tools/perf/arch/x86/Makefile
+++ b/tools/perf/arch/x86/Makefile
@@ -16,3 +16,4 @@ LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/header.o
 LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/tsc.o
 LIB_H += arch/$(ARCH)/util/tsc.h
 HAVE_KVM_STAT_SUPPORT := 1
+LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/kvm-stat.o
diff --git a/tools/perf/arch/x86/util/kvm-stat.c b/tools/perf/arch/x86/util/kvm-stat.c
new file mode 100644
index 0000000..2f8d2c1
--- /dev/null
+++ b/tools/perf/arch/x86/util/kvm-stat.c
@@ -0,0 +1,151 @@
+#include "../../util/kvm-stat.h"
+#include <asm/kvm_perf.h>
+
+define_exit_reasons_table(vmx_exit_reasons, VMX_EXIT_REASONS);
+define_exit_reasons_table(svm_exit_reasons, SVM_EXIT_REASONS);
+
+static struct kvm_events_ops exit_events = {
+	.is_begin_event = exit_event_begin,
+	.is_end_event = exit_event_end,
+	.decode_key = exit_event_decode_key,
+	.name = "VM-EXIT"
+};
+
+/*
+ * For the mmio events, we treat:
+ * the time of MMIO write: kvm_mmio(KVM_TRACE_MMIO_WRITE...) -> kvm_entry
+ * the time of MMIO read: kvm_exit -> kvm_mmio(KVM_TRACE_MMIO_READ...).
+ */
+static void mmio_event_get_key(struct perf_evsel *evsel, struct perf_sample *sample,
+			       struct event_key *key)
+{
+	key->key  = perf_evsel__intval(evsel, sample, "gpa");
+	key->info = perf_evsel__intval(evsel, sample, "type");
+}
+
+#define KVM_TRACE_MMIO_READ_UNSATISFIED 0
+#define KVM_TRACE_MMIO_READ 1
+#define KVM_TRACE_MMIO_WRITE 2
+
+static bool mmio_event_begin(struct perf_evsel *evsel,
+			     struct perf_sample *sample, struct event_key *key)
+{
+	/* MMIO read begin event in kernel. */
+	if (kvm_exit_event(evsel))
+		return true;
+
+	/* MMIO write begin event in kernel. */
+	if (!strcmp(evsel->name, "kvm:kvm_mmio") &&
+	    perf_evsel__intval(evsel, sample, "type") == KVM_TRACE_MMIO_WRITE) {
+		mmio_event_get_key(evsel, sample, key);
+		return true;
+	}
+
+	return false;
+}
+
+static bool mmio_event_end(struct perf_evsel *evsel, struct perf_sample *sample,
+			   struct event_key *key)
+{
+	/* MMIO write end event in kernel. */
+	if (kvm_entry_event(evsel))
+		return true;
+
+	/* MMIO read end event in kernel.*/
+	if (!strcmp(evsel->name, "kvm:kvm_mmio") &&
+	    perf_evsel__intval(evsel, sample, "type") == KVM_TRACE_MMIO_READ) {
+		mmio_event_get_key(evsel, sample, key);
+		return true;
+	}
+
+	return false;
+}
+
+static void mmio_event_decode_key(struct perf_kvm_stat *kvm __maybe_unused,
+				  struct event_key *key,
+				  char *decode)
+{
+	scnprintf(decode, DECODE_STR_LEN, "%#lx:%s",
+		  (unsigned long)key->key,
+		  key->info == KVM_TRACE_MMIO_WRITE ? "W" : "R");
+}
+
+static struct kvm_events_ops mmio_events = {
+	.is_begin_event = mmio_event_begin,
+	.is_end_event = mmio_event_end,
+	.decode_key = mmio_event_decode_key,
+	.name = "MMIO Access"
+};
+
+ /* The time of emulation pio access is from kvm_pio to kvm_entry. */
+static void ioport_event_get_key(struct perf_evsel *evsel,
+				 struct perf_sample *sample,
+				 struct event_key *key)
+{
+	key->key  = perf_evsel__intval(evsel, sample, "port");
+	key->info = perf_evsel__intval(evsel, sample, "rw");
+}
+
+static bool ioport_event_begin(struct perf_evsel *evsel,
+			       struct perf_sample *sample,
+			       struct event_key *key)
+{
+	if (!strcmp(evsel->name, "kvm:kvm_pio")) {
+		ioport_event_get_key(evsel, sample, key);
+		return true;
+	}
+
+	return false;
+}
+
+static bool ioport_event_end(struct perf_evsel *evsel,
+			     struct perf_sample *sample __maybe_unused,
+			     struct event_key *key __maybe_unused)
+{
+	return kvm_entry_event(evsel);
+}
+
+static void ioport_event_decode_key(struct perf_kvm_stat *kvm __maybe_unused,
+				    struct event_key *key,
+				    char *decode)
+{
+	scnprintf(decode, DECODE_STR_LEN, "%#llx:%s",
+		  (unsigned long long)key->key,
+		  key->info ? "POUT" : "PIN");
+}
+
+static struct kvm_events_ops ioport_events = {
+	.is_begin_event = ioport_event_begin,
+	.is_end_event = ioport_event_end,
+	.decode_key = ioport_event_decode_key,
+	.name = "IO Port Access"
+};
+
+const char * const kvm_events_tp[] = {
+	"kvm:kvm_entry",
+	"kvm:kvm_exit",
+	"kvm:kvm_mmio",
+	"kvm:kvm_pio",
+	NULL,
+};
+
+struct kvm_reg_events_ops kvm_reg_events_ops[] = {
+	{ .name = "vmexit", .ops = &exit_events },
+	{ .name = "mmio", .ops = &mmio_events },
+	{ .name = "ioport", .ops = &ioport_events },
+	{ NULL, NULL },
+};
+
+int cpu_isa_init(struct perf_kvm_stat *kvm, const char *cpuid)
+{
+	if (strstr(cpuid, "Intel")) {
+		kvm->exit_reasons = vmx_exit_reasons;
+		kvm->exit_reasons_isa = "VMX";
+	} else if (strstr(cpuid, "AMD")) {
+		kvm->exit_reasons = svm_exit_reasons;
+		kvm->exit_reasons_isa = "SVM";
+	} else
+		return -ENOTSUP;
+
+	return 0;
+}
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index 6d73346..75ee8c1 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -31,109 +31,23 @@
 
 #ifdef HAVE_KVM_STAT_SUPPORT
 #include <asm/kvm_perf.h>
+#include "util/kvm-stat.h"
 
-struct event_key {
-	#define INVALID_KEY     (~0ULL)
-	u64 key;
-	int info;
-};
-
-struct kvm_event_stats {
-	u64 time;
-	struct stats stats;
-};
-
-struct kvm_event {
-	struct list_head hash_entry;
-	struct rb_node rb;
-
-	struct event_key key;
-
-	struct kvm_event_stats total;
-
-	#define DEFAULT_VCPU_NUM 8
-	int max_vcpu;
-	struct kvm_event_stats *vcpu;
-};
-
-typedef int (*key_cmp_fun)(struct kvm_event*, struct kvm_event*, int);
-
-struct kvm_event_key {
-	const char *name;
-	key_cmp_fun key;
-};
-
-
-struct perf_kvm_stat;
-
-struct kvm_events_ops {
-	bool (*is_begin_event)(struct perf_evsel *evsel,
-			       struct perf_sample *sample,
-			       struct event_key *key);
-	bool (*is_end_event)(struct perf_evsel *evsel,
-			     struct perf_sample *sample, struct event_key *key);
-	void (*decode_key)(struct perf_kvm_stat *kvm, struct event_key *key,
-			   char *decode);
-	const char *name;
-};
-
-struct exit_reasons_table {
-	unsigned long exit_code;
-	const char *reason;
-};
-
-#define EVENTS_BITS		12
-#define EVENTS_CACHE_SIZE	(1UL << EVENTS_BITS)
-
-struct perf_kvm_stat {
-	struct perf_tool    tool;
-	struct record_opts  opts;
-	struct perf_evlist  *evlist;
-	struct perf_session *session;
-
-	const char *file_name;
-	const char *report_event;
-	const char *sort_key;
-	int trace_vcpu;
-
-	struct exit_reasons_table *exit_reasons;
-	const char *exit_reasons_isa;
-
-	struct kvm_events_ops *events_ops;
-	key_cmp_fun compare;
-	struct list_head kvm_events_cache[EVENTS_CACHE_SIZE];
-
-	u64 total_time;
-	u64 total_count;
-	u64 lost_events;
-	u64 duration;
-
-	const char *pid_str;
-	struct intlist *pid_list;
-
-	struct rb_root result;
-
-	int timerfd;
-	unsigned int display_time;
-	bool live;
-};
-
-
-static void exit_event_get_key(struct perf_evsel *evsel,
-			       struct perf_sample *sample,
-			       struct event_key *key)
+void exit_event_get_key(struct perf_evsel *evsel,
+			struct perf_sample *sample,
+			struct event_key *key)
 {
 	key->info = 0;
 	key->key = perf_evsel__intval(evsel, sample, KVM_EXIT_REASON);
 }
 
-static bool kvm_exit_event(struct perf_evsel *evsel)
+bool kvm_exit_event(struct perf_evsel *evsel)
 {
 	return !strcmp(evsel->name, KVM_EXIT_TRACE);
 }
 
-static bool exit_event_begin(struct perf_evsel *evsel,
-			     struct perf_sample *sample, struct event_key *key)
+bool exit_event_begin(struct perf_evsel *evsel,
+		      struct perf_sample *sample, struct event_key *key)
 {
 	if (kvm_exit_event(evsel)) {
 		exit_event_get_key(evsel, sample, key);
@@ -143,26 +57,18 @@ static bool exit_event_begin(struct perf_evsel *evsel,
 	return false;
 }
 
-static bool kvm_entry_event(struct perf_evsel *evsel)
+bool kvm_entry_event(struct perf_evsel *evsel)
 {
 	return !strcmp(evsel->name, KVM_ENTRY_TRACE);
 }
 
-static bool exit_event_end(struct perf_evsel *evsel,
-			   struct perf_sample *sample __maybe_unused,
-			   struct event_key *key __maybe_unused)
+bool exit_event_end(struct perf_evsel *evsel,
+		    struct perf_sample *sample __maybe_unused,
+		    struct event_key *key __maybe_unused)
 {
 	return kvm_entry_event(evsel);
 }
 
-#define define_exit_reasons_table(name, symbols)	\
-	static struct exit_reasons_table name[] = {	\
-		symbols, { -1, NULL }			\
-	}
-
-define_exit_reasons_table(vmx_exit_reasons, VMX_EXIT_REASONS);
-define_exit_reasons_table(svm_exit_reasons, SVM_EXIT_REASONS);
-
 static const char *get_exit_reason(struct perf_kvm_stat *kvm,
 				   struct exit_reasons_table *tbl,
 				   u64 exit_code)
@@ -178,9 +84,9 @@ static const char *get_exit_reason(struct perf_kvm_stat *kvm,
 	return "UNKNOWN";
 }
 
-static void exit_event_decode_key(struct perf_kvm_stat *kvm,
-				  struct event_key *key,
-				  char *decode)
+void exit_event_decode_key(struct perf_kvm_stat *kvm,
+			   struct event_key *key,
+			   char *decode)
 {
 	const char *exit_reason = get_exit_reason(kvm, kvm->exit_reasons,
 						  key->key);
@@ -188,139 +94,20 @@ static void exit_event_decode_key(struct perf_kvm_stat *kvm,
 	scnprintf(decode, DECODE_STR_LEN, "%s", exit_reason);
 }
 
-static struct kvm_events_ops exit_events = {
-	.is_begin_event = exit_event_begin,
-	.is_end_event = exit_event_end,
-	.decode_key = exit_event_decode_key,
-	.name = "VM-EXIT"
-};
-
-/*
- * For the mmio events, we treat:
- * the time of MMIO write: kvm_mmio(KVM_TRACE_MMIO_WRITE...) -> kvm_entry
- * the time of MMIO read: kvm_exit -> kvm_mmio(KVM_TRACE_MMIO_READ...).
- */
-static void mmio_event_get_key(struct perf_evsel *evsel, struct perf_sample *sample,
-			       struct event_key *key)
-{
-	key->key  = perf_evsel__intval(evsel, sample, "gpa");
-	key->info = perf_evsel__intval(evsel, sample, "type");
-}
-
-#define KVM_TRACE_MMIO_READ_UNSATISFIED 0
-#define KVM_TRACE_MMIO_READ 1
-#define KVM_TRACE_MMIO_WRITE 2
-
-static bool mmio_event_begin(struct perf_evsel *evsel,
-			     struct perf_sample *sample, struct event_key *key)
-{
-	/* MMIO read begin event in kernel. */
-	if (kvm_exit_event(evsel))
-		return true;
-
-	/* MMIO write begin event in kernel. */
-	if (!strcmp(evsel->name, "kvm:kvm_mmio") &&
-	    perf_evsel__intval(evsel, sample, "type") == KVM_TRACE_MMIO_WRITE) {
-		mmio_event_get_key(evsel, sample, key);
-		return true;
-	}
-
-	return false;
-}
-
-static bool mmio_event_end(struct perf_evsel *evsel, struct perf_sample *sample,
-			   struct event_key *key)
-{
-	/* MMIO write end event in kernel. */
-	if (kvm_entry_event(evsel))
-		return true;
-
-	/* MMIO read end event in kernel.*/
-	if (!strcmp(evsel->name, "kvm:kvm_mmio") &&
-	    perf_evsel__intval(evsel, sample, "type") == KVM_TRACE_MMIO_READ) {
-		mmio_event_get_key(evsel, sample, key);
-		return true;
-	}
-
-	return false;
-}
-
-static void mmio_event_decode_key(struct perf_kvm_stat *kvm __maybe_unused,
-				  struct event_key *key,
-				  char *decode)
-{
-	scnprintf(decode, DECODE_STR_LEN, "%#lx:%s", (unsigned long)key->key,
-				key->info == KVM_TRACE_MMIO_WRITE ? "W" : "R");
-}
-
-static struct kvm_events_ops mmio_events = {
-	.is_begin_event = mmio_event_begin,
-	.is_end_event = mmio_event_end,
-	.decode_key = mmio_event_decode_key,
-	.name = "MMIO Access"
-};
-
- /* The time of emulation pio access is from kvm_pio to kvm_entry. */
-static void ioport_event_get_key(struct perf_evsel *evsel,
-				 struct perf_sample *sample,
-				 struct event_key *key)
+static bool register_kvm_events_ops(struct perf_kvm_stat *kvm)
 {
-	key->key  = perf_evsel__intval(evsel, sample, "port");
-	key->info = perf_evsel__intval(evsel, sample, "rw");
-}
+	struct kvm_reg_events_ops *events_ops = kvm_reg_events_ops;
 
-static bool ioport_event_begin(struct perf_evsel *evsel,
-			       struct perf_sample *sample,
-			       struct event_key *key)
-{
-	if (!strcmp(evsel->name, "kvm:kvm_pio")) {
-		ioport_event_get_key(evsel, sample, key);
-		return true;
+	for (events_ops = kvm_reg_events_ops; events_ops->name; events_ops++) {
+		if (!strcmp(events_ops->name, kvm->report_event)) {
+			kvm->events_ops = events_ops->ops;
+			return true;
+		}
 	}
 
 	return false;
 }
 
-static bool ioport_event_end(struct perf_evsel *evsel,
-			     struct perf_sample *sample __maybe_unused,
-			     struct event_key *key __maybe_unused)
-{
-	return kvm_entry_event(evsel);
-}
-
-static void ioport_event_decode_key(struct perf_kvm_stat *kvm __maybe_unused,
-				    struct event_key *key,
-				    char *decode)
-{
-	scnprintf(decode, DECODE_STR_LEN, "%#llx:%s", (unsigned long long)key->key,
-				key->info ? "POUT" : "PIN");
-}
-
-static struct kvm_events_ops ioport_events = {
-	.is_begin_event = ioport_event_begin,
-	.is_end_event = ioport_event_end,
-	.decode_key = ioport_event_decode_key,
-	.name = "IO Port Access"
-};
-
-static bool register_kvm_events_ops(struct perf_kvm_stat *kvm)
-{
-	bool ret = true;
-
-	if (!strcmp(kvm->report_event, "vmexit"))
-		kvm->events_ops = &exit_events;
-	else if (!strcmp(kvm->report_event, "mmio"))
-		kvm->events_ops = &mmio_events;
-	else if (!strcmp(kvm->report_event, "ioport"))
-		kvm->events_ops = &ioport_events;
-	else {
-		pr_err("Unknown report event:%s\n", kvm->report_event);
-		ret = false;
-	}
-
-	return ret;
-}
-
 struct vcpu_event_record {
 	int vcpu_id;
 	u64 start_time;
@@ -833,20 +620,6 @@ static int process_sample_event(struct perf_tool *tool,
 	return 0;
 }
 
-static int cpu_isa_init(struct perf_kvm_stat *kvm, const char *cpuid)
-{
-	if (strstr(cpuid, "Intel")) {
-		kvm->exit_reasons = vmx_exit_reasons;
-		kvm->exit_reasons_isa = "VMX";
-	} else if (strstr(cpuid, "AMD")) {
-		kvm->exit_reasons = svm_exit_reasons;
-		kvm->exit_reasons_isa = "SVM";
-	} else
-		return -ENOTSUP;
-
-	return 0;
-}
-
 static int cpu_isa_config(struct perf_kvm_stat *kvm)
 {
 	char buf[64], *cpuid;
@@ -1305,13 +1078,6 @@ exit:
 	return ret;
 }
 
-static const char * const kvm_events_tp[] = {
-	"kvm:kvm_entry",
-	"kvm:kvm_exit",
-	"kvm:kvm_mmio",
-	"kvm:kvm_pio",
-};
-
 #define STRDUP_FAIL_EXIT(s)		\
 	({	char *_p;		\
 	_p = strdup(s);		\
@@ -1323,7 +1089,7 @@ static const char * const kvm_events_tp[] = {
 static int
 kvm_events_record(struct perf_kvm_stat *kvm, int argc, const char **argv)
 {
-	unsigned int rec_argc, i, j;
+	unsigned int rec_argc, i, j, events_tp_size;
 	const char **rec_argv;
 	const char * const record_args[] = {
 		"record",
@@ -1331,9 +1097,14 @@ kvm_events_record(struct perf_kvm_stat *kvm, int argc, const char **argv)
 		"-m", "1024",
 		"-c", "1",
 	};
+	const char * const *events_tp;
+	events_tp_size = 0;
+
+	for (events_tp = kvm_events_tp; *events_tp; events_tp++)
+		events_tp_size++;
 
 	rec_argc = ARRAY_SIZE(record_args) + argc + 2 +
-		   2 * ARRAY_SIZE(kvm_events_tp);
+		   2 * events_tp_size;
 	rec_argv = calloc(rec_argc + 1, sizeof(char *));
 
 	if (rec_argv == NULL)
@@ -1342,7 +1113,7 @@ kvm_events_record(struct perf_kvm_stat *kvm, int argc, const char **argv)
 	for (i = 0; i < ARRAY_SIZE(record_args); i++)
 		rec_argv[i] = STRDUP_FAIL_EXIT(record_args[i]);
 
-	for (j = 0; j < ARRAY_SIZE(kvm_events_tp); j++) {
+	for (j = 0; j < events_tp_size; j++) {
 		rec_argv[i++] = "-e";
 		rec_argv[i++] = STRDUP_FAIL_EXIT(kvm_events_tp[j]);
 	}
@@ -1396,16 +1167,16 @@ static struct perf_evlist *kvm_live_event_list(void)
 {
 	struct perf_evlist *evlist;
 	char *tp, *name, *sys;
-	unsigned int j;
 	int err = -1;
+	const char * const *events_tp;
 
 	evlist = perf_evlist__new();
 	if (evlist == NULL)
 		return NULL;
 
-	for (j = 0; j < ARRAY_SIZE(kvm_events_tp); j++) {
+	for (events_tp = kvm_events_tp; *events_tp; events_tp++) {
 
-		tp = strdup(kvm_events_tp[j]);
+		tp = strdup(*events_tp);
 		if (tp == NULL)
 			goto out;
 
@@ -1414,7 +1185,7 @@ static struct perf_evlist *kvm_live_event_list(void)
 		name = strchr(tp, ':');
 		if (name == NULL) {
 			pr_err("Error parsing %s tracepoint: subsystem delimiter not found\n",
-				kvm_events_tp[j]);
+			       *events_tp);
 			free(tp);
 			goto out;
 		}
@@ -1422,7 +1193,7 @@ static struct perf_evlist *kvm_live_event_list(void)
 		name++;
 
 		if (perf_evlist__add_newtp(evlist, sys, name, NULL)) {
-			pr_err("Failed to add %s tracepoint to the list\n", kvm_events_tp[j]);
+			pr_err("Failed to add %s tracepoint to the list\n", *events_tp);
 			free(tp);
 			goto out;
 		}
diff --git a/tools/perf/util/kvm-stat.h b/tools/perf/util/kvm-stat.h
new file mode 100644
index 0000000..d0d9fb1
--- /dev/null
+++ b/tools/perf/util/kvm-stat.h
@@ -0,0 +1,130 @@
+#ifndef __PERF_KVM_STAT_H
+#define __PERF_KVM_STAT_H
+
+#include "../perf.h"
+#include "evsel.h"
+#include "evlist.h"
+#include "session.h"
+#include "tool.h"
+#include "stat.h"
+
+struct event_key {
+	#define INVALID_KEY     (~0ULL)
+	u64 key;
+	int info;
+};
+
+struct kvm_event_stats {
+	u64 time;
+	struct stats stats;
+};
+
+struct kvm_event {
+	struct list_head hash_entry;
+	struct rb_node rb;
+
+	struct event_key key;
+
+	struct kvm_event_stats total;
+
+	#define DEFAULT_VCPU_NUM 8
+	int max_vcpu;
+	struct kvm_event_stats *vcpu;
+};
+
+typedef int (*key_cmp_fun)(struct kvm_event*, struct kvm_event*, int);
+
+struct kvm_event_key {
+	const char *name;
+	key_cmp_fun key;
+};
+
+struct perf_kvm_stat;
+
+struct kvm_events_ops {
+	bool (*is_begin_event)(struct perf_evsel *evsel,
+			       struct perf_sample *sample,
+			       struct event_key *key);
+	bool (*is_end_event)(struct perf_evsel *evsel,
+			     struct perf_sample *sample, struct event_key *key);
+	void (*decode_key)(struct perf_kvm_stat *kvm, struct event_key *key,
+			   char *decode);
+	const char *name;
+};
+
+struct exit_reasons_table {
+	unsigned long exit_code;
+	const char *reason;
+};
+
+#define EVENTS_BITS		12
+#define EVENTS_CACHE_SIZE	(1UL << EVENTS_BITS)
+
+struct perf_kvm_stat {
+	struct perf_tool    tool;
+	struct record_opts  opts;
+	struct perf_evlist  *evlist;
+	struct perf_session *session;
+
+	const char *file_name;
+	const char *report_event;
+	const char *sort_key;
+	int trace_vcpu;
+
+	struct exit_reasons_table *exit_reasons;
+	const char *exit_reasons_isa;
+
+	struct kvm_events_ops *events_ops;
+	key_cmp_fun compare;
+	struct list_head kvm_events_cache[EVENTS_CACHE_SIZE];
+
+	u64 total_time;
+	u64 total_count;
+	u64 lost_events;
+	u64 duration;
+
+	const char *pid_str;
+	struct intlist *pid_list;
+
+	struct rb_root result;
+
+	int timerfd;
+	unsigned int display_time;
+	bool live;
+};
+
+struct kvm_reg_events_ops {
+	const char *name;
+	struct kvm_events_ops *ops;
+};
+
+void exit_event_get_key(struct perf_evsel *evsel,
+			struct perf_sample *sample,
+			struct event_key *key);
+bool exit_event_begin(struct perf_evsel *evsel,
+		      struct perf_sample *sample,
+		      struct event_key *key);
+bool exit_event_end(struct perf_evsel *evsel,
+		    struct perf_sample *sample,
+		    struct event_key *key);
+void exit_event_decode_key(struct perf_kvm_stat *kvm,
+			   struct event_key *key,
+			   char *decode);
+
+bool kvm_exit_event(struct perf_evsel *evsel);
+bool kvm_entry_event(struct perf_evsel *evsel);
+
+#define define_exit_reasons_table(name, symbols)	\
+	static struct exit_reasons_table name[] = {	\
+		symbols, { -1, NULL }			\
+	}
+
+/*
+ * arch specific callbacks and data structures
+ */
+int cpu_isa_init(struct perf_kvm_stat *kvm, const char *cpuid);
+
+extern const char * const kvm_events_tp[];
+extern struct kvm_reg_events_ops kvm_reg_events_ops[];
+
+#endif /* __PERF_KVM_STAT_H */
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH 3/4] perf kvm: Add skip_event() for --duration option
  2014-07-03 14:29 [PATCH/RFC 0/4] perf kvm: add stat support for s390 Alexander Yarygin
  2014-07-03 14:29 ` [PATCH 1/4] perf kvm: Use defines of kvm events Alexander Yarygin
  2014-07-03 14:29 ` [PATCH 2/4] perf kvm: Move arch specific code into arch/ Alexander Yarygin
@ 2014-07-03 14:29 ` Alexander Yarygin
  2014-07-07 14:10   ` Christian Borntraeger
                     ` (2 more replies)
  2014-07-03 14:29 ` [PATCH 4/4] perf kvm: Add stat support on s390 Alexander Yarygin
                   ` (2 subsequent siblings)
  5 siblings, 3 replies; 23+ messages in thread
From: Alexander Yarygin @ 2014-07-03 14:29 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: David Ahern, Peter Zijlstra, Paul Mackerras, Ingo Molnar,
	Arnaldo Carvalho de Melo, Christian Borntraeger, Cornelia Huck,
	linux-kernel, Alexander Yarygin

Current code skips output of the x86 specific HLT event in order to
avoid flooding the output with enabled --duration option. The events to
be skipped should be architecture dependent, though.

Let's add an architecture specific array of events to be skipped and
introduce a skip_event() function checking against that array.

Signed-off-by: Alexander Yarygin <yarygin@linux.vnet.ibm.com>
Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
---
 tools/perf/arch/x86/util/kvm-stat.c |    5 +++++
 tools/perf/builtin-kvm.c            |   13 ++++++++++++-
 tools/perf/util/kvm-stat.h          |    1 +
 3 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/tools/perf/arch/x86/util/kvm-stat.c b/tools/perf/arch/x86/util/kvm-stat.c
index 2f8d2c1..14e4e66 100644
--- a/tools/perf/arch/x86/util/kvm-stat.c
+++ b/tools/perf/arch/x86/util/kvm-stat.c
@@ -136,6 +136,11 @@ struct kvm_reg_events_ops kvm_reg_events_ops[] = {
 	{ NULL, NULL },
 };
 
+const char * const kvm_skip_events[] = {
+	"HLT",
+	NULL,
+};
+
 int cpu_isa_init(struct perf_kvm_stat *kvm, const char *cpuid)
 {
 	if (strstr(cpuid, "Intel")) {
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index 75ee8c1..fc2d63d 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -261,6 +261,17 @@ static bool update_kvm_event(struct kvm_event *event, int vcpu_id,
 	return true;
 }
 
+static bool skip_event(const char *event)
+{
+	const char * const *skip_events;
+
+	for (skip_events = kvm_skip_events; *skip_events; skip_events++)
+		if (!strcmp(event, *skip_events))
+			return true;
+
+	return false;
+}
+
 static bool handle_end_event(struct perf_kvm_stat *kvm,
 			     struct vcpu_event_record *vcpu_record,
 			     struct event_key *key,
@@ -312,7 +323,7 @@ static bool handle_end_event(struct perf_kvm_stat *kvm,
 		char decode[DECODE_STR_LEN];
 
 		kvm->events_ops->decode_key(kvm, &event->key, decode);
-		if (strcmp(decode, "HLT")) {
+		if (!skip_event(decode)) {
 			pr_info("%" PRIu64 " VM %d, vcpu %d: %s event took %" PRIu64 "usec\n",
 				 sample->time, sample->pid, vcpu_record->vcpu_id,
 				 decode, time_diff/1000);
diff --git a/tools/perf/util/kvm-stat.h b/tools/perf/util/kvm-stat.h
index d0d9fb1..ba937ca 100644
--- a/tools/perf/util/kvm-stat.h
+++ b/tools/perf/util/kvm-stat.h
@@ -126,5 +126,6 @@ int cpu_isa_init(struct perf_kvm_stat *kvm, const char *cpuid);
 
 extern const char * const kvm_events_tp[];
 extern struct kvm_reg_events_ops kvm_reg_events_ops[];
+extern const char * const kvm_skip_events[];
 
 #endif /* __PERF_KVM_STAT_H */
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH 4/4] perf kvm: Add stat support on s390
  2014-07-03 14:29 [PATCH/RFC 0/4] perf kvm: add stat support for s390 Alexander Yarygin
                   ` (2 preceding siblings ...)
  2014-07-03 14:29 ` [PATCH 3/4] perf kvm: Add skip_event() for --duration option Alexander Yarygin
@ 2014-07-03 14:29 ` Alexander Yarygin
  2014-07-07 14:11   ` Christian Borntraeger
                     ` (3 more replies)
  2014-07-03 15:07 ` [PATCH/RFC 0/4] perf kvm: add stat support for s390 Christian Borntraeger
  2014-07-09 16:47 ` David Ahern
  5 siblings, 4 replies; 23+ messages in thread
From: Alexander Yarygin @ 2014-07-03 14:29 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: David Ahern, Peter Zijlstra, Paul Mackerras, Ingo Molnar,
	Arnaldo Carvalho de Melo, Christian Borntraeger, Cornelia Huck,
	linux-kernel, Alexander Yarygin

On s390, the vmexit event has a tree-like structure: between
exit_event_begin and exit_event_end several other events may happen
and with each of them refining the previous ones.

This patch adds a decoder for such events to the generic code
and also the files <asm/kvm_perf.h> and kvm-stat.c for s390.

Commands 'perf kvm stat record', 'report' and 'live' are supported.

Signed-off-by: Alexander Yarygin <yarygin@linux.vnet.ibm.com>
---
 arch/s390/include/uapi/asm/Kbuild     |    1 +
 arch/s390/include/uapi/asm/kvm_perf.h |   25 ++++++++
 tools/perf/Documentation/perf-kvm.txt |   10 ++--
 tools/perf/MANIFEST                   |    2 +
 tools/perf/arch/s390/Makefile         |    2 +
 tools/perf/arch/s390/util/kvm-stat.c  |  105 +++++++++++++++++++++++++++++++++
 tools/perf/builtin-kvm.c              |   52 ++++++++++++++--
 tools/perf/util/kvm-stat.h            |    9 +++
 8 files changed, 198 insertions(+), 8 deletions(-)
 create mode 100644 arch/s390/include/uapi/asm/kvm_perf.h
 create mode 100644 tools/perf/arch/s390/util/kvm-stat.c

diff --git a/arch/s390/include/uapi/asm/Kbuild b/arch/s390/include/uapi/asm/Kbuild
index 6a9a9eb..0e2b54d 100644
--- a/arch/s390/include/uapi/asm/Kbuild
+++ b/arch/s390/include/uapi/asm/Kbuild
@@ -16,6 +16,7 @@ header-y += ioctls.h
 header-y += ipcbuf.h
 header-y += kvm.h
 header-y += kvm_para.h
+header-y += kvm_perf.h
 header-y += kvm_virtio.h
 header-y += mman.h
 header-y += monwriter.h
diff --git a/arch/s390/include/uapi/asm/kvm_perf.h b/arch/s390/include/uapi/asm/kvm_perf.h
new file mode 100644
index 0000000..3972827
--- /dev/null
+++ b/arch/s390/include/uapi/asm/kvm_perf.h
@@ -0,0 +1,25 @@
+/*
+ * Definitions for perf-kvm on s390
+ *
+ * Copyright 2014 IBM Corp.
+ * Author(s): Alexander Yarygin <yarygin@linux.vnet.ibm.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License (version 2 only)
+ * as published by the Free Software Foundation.
+ */
+
+#ifndef __LINUX_KVM_PERF_S390_H
+#define __LINUX_KVM_PERF_S390_H
+
+#include <asm/sie.h>
+
+#define DECODE_STR_LEN 40
+
+#define VCPU_ID "id"
+
+#define KVM_ENTRY_TRACE "kvm:kvm_s390_sie_enter"
+#define KVM_EXIT_TRACE "kvm:kvm_s390_sie_exit"
+#define KVM_EXIT_REASON "icptcode"
+
+#endif
diff --git a/tools/perf/Documentation/perf-kvm.txt b/tools/perf/Documentation/perf-kvm.txt
index 52276a6..abf2925 100644
--- a/tools/perf/Documentation/perf-kvm.txt
+++ b/tools/perf/Documentation/perf-kvm.txt
@@ -103,8 +103,8 @@ STAT REPORT OPTIONS
        analyze events which occures on this vcpu. (default: all vcpus)
 
 --event=<value>::
-       event to be analyzed. Possible values: vmexit, mmio, ioport.
-       (default: vmexit)
+       event to be analyzed. Possible values: vmexit, mmio (x86 only),
+       ioport (x86 only). (default: vmexit)
 -k::
 --key=<value>::
        Sorting key. Possible values: sample (default, sort by samples
@@ -138,7 +138,8 @@ STAT LIVE OPTIONS
 
 
 --event=<value>::
-       event to be analyzed. Possible values: vmexit, mmio, ioport.
+       event to be analyzed. Possible values: vmexit,
+       mmio (x86 only), ioport (x86 only).
        (default: vmexit)
 
 -k::
@@ -147,7 +148,8 @@ STAT LIVE OPTIONS
        number), time (sort by average time).
 
 --duration=<value>::
-       Show events other than HLT that take longer than duration usecs.
+       Show events other than HLT (x86 only) or Wait state (s390 only)
+       that take longer than duration usecs.
 
 SEE ALSO
 --------
diff --git a/tools/perf/MANIFEST b/tools/perf/MANIFEST
index 02b485d..344c4d3 100644
--- a/tools/perf/MANIFEST
+++ b/tools/perf/MANIFEST
@@ -38,3 +38,5 @@ arch/x86/include/uapi/asm/svm.h
 arch/x86/include/uapi/asm/vmx.h
 arch/x86/include/uapi/asm/kvm.h
 arch/x86/include/uapi/asm/kvm_perf.h
+arch/s390/include/uapi/asm/sie.h
+arch/s390/include/uapi/asm/kvm_perf.h
diff --git a/tools/perf/arch/s390/Makefile b/tools/perf/arch/s390/Makefile
index 744e629..798ac73 100644
--- a/tools/perf/arch/s390/Makefile
+++ b/tools/perf/arch/s390/Makefile
@@ -3,3 +3,5 @@ PERF_HAVE_DWARF_REGS := 1
 LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/dwarf-regs.o
 endif
 LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/header.o
+HAVE_KVM_STAT_SUPPORT := 1
+LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/kvm-stat.o
diff --git a/tools/perf/arch/s390/util/kvm-stat.c b/tools/perf/arch/s390/util/kvm-stat.c
new file mode 100644
index 0000000..a5dbc07
--- /dev/null
+++ b/tools/perf/arch/s390/util/kvm-stat.c
@@ -0,0 +1,105 @@
+/*
+ * Arch specific functions for perf kvm stat.
+ *
+ * Copyright 2014 IBM Corp.
+ * Author(s): Alexander Yarygin <yarygin@linux.vnet.ibm.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License (version 2 only)
+ * as published by the Free Software Foundation.
+ */
+
+#include "../../util/kvm-stat.h"
+#include <asm/kvm_perf.h>
+
+define_exit_reasons_table(sie_exit_reasons, sie_intercept_code);
+define_exit_reasons_table(sie_icpt_insn_codes, icpt_insn_codes);
+define_exit_reasons_table(sie_sigp_order_codes, sigp_order_codes);
+define_exit_reasons_table(sie_diagnose_codes, diagnose_codes);
+define_exit_reasons_table(sie_icpt_prog_codes, icpt_prog_codes);
+
+static void event_icpt_insn_get_key(struct perf_evsel *evsel,
+				    struct perf_sample *sample,
+				    struct event_key *key)
+{
+	unsigned long insn;
+
+	insn = perf_evsel__intval(evsel, sample, "instruction");
+	key->key = icpt_insn_decoder(insn);
+	key->exit_reasons = sie_icpt_insn_codes;
+}
+
+static void event_sigp_get_key(struct perf_evsel *evsel,
+			       struct perf_sample *sample,
+			       struct event_key *key)
+{
+	key->key = perf_evsel__intval(evsel, sample, "order_code");
+	key->exit_reasons = sie_sigp_order_codes;
+}
+
+static void event_diag_get_key(struct perf_evsel *evsel,
+			       struct perf_sample *sample,
+			       struct event_key *key)
+{
+	key->key = perf_evsel__intval(evsel, sample, "code");
+	key->exit_reasons = sie_diagnose_codes;
+}
+
+static void event_icpt_prog_get_key(struct perf_evsel *evsel,
+				    struct perf_sample *sample,
+				    struct event_key *key)
+{
+	key->key = perf_evsel__intval(evsel, sample, "code");
+	key->exit_reasons = sie_icpt_prog_codes;
+}
+
+static struct child_event_ops child_events[] = {
+	{ .name = "kvm:kvm_s390_intercept_instruction",
+	  .get_key = event_icpt_insn_get_key },
+	{ .name = "kvm:kvm_s390_handle_sigp",
+	  .get_key = event_sigp_get_key },
+	{ .name = "kvm:kvm_s390_handle_diag",
+	  .get_key = event_diag_get_key },
+	{ .name = "kvm:kvm_s390_intercept_prog",
+	  .get_key = event_icpt_prog_get_key },
+	{ NULL, NULL },
+};
+
+static struct kvm_events_ops exit_events = {
+	.is_begin_event = exit_event_begin,
+	.is_end_event = exit_event_end,
+	.child_ops = child_events,
+	.decode_key = exit_event_decode_key,
+	.name = "VM-EXIT"
+};
+
+const char * const kvm_events_tp[] = {
+	"kvm:kvm_s390_sie_enter",
+	"kvm:kvm_s390_sie_exit",
+	"kvm:kvm_s390_intercept_instruction",
+	"kvm:kvm_s390_handle_sigp",
+	"kvm:kvm_s390_handle_diag",
+	"kvm:kvm_s390_intercept_prog",
+	NULL,
+};
+
+struct kvm_reg_events_ops kvm_reg_events_ops[] = {
+	{ .name = "vmexit", .ops = &exit_events },
+	{ NULL, NULL },
+};
+
+const char * const kvm_skip_events[] = {
+	"Wait state",
+	NULL,
+};
+
+int cpu_isa_init(struct perf_kvm_stat *kvm, const char *cpuid)
+{
+	if (strstr(cpuid, "IBM/S390")) {
+		kvm->exit_reasons = sie_exit_reasons;
+		kvm->exit_reasons_isa = "SIE";
+	} else
+		return -ENOTSUP;
+
+	return 0;
+}
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index fc2d63d..43367eb 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -88,7 +88,7 @@ void exit_event_decode_key(struct perf_kvm_stat *kvm,
 			   struct event_key *key,
 			   char *decode)
 {
-	const char *exit_reason = get_exit_reason(kvm, kvm->exit_reasons,
+	const char *exit_reason = get_exit_reason(kvm, key->exit_reasons,
 						  key->key);
 
 	scnprintf(decode, DECODE_STR_LEN, "%s", exit_reason);
@@ -261,6 +261,43 @@ static bool update_kvm_event(struct kvm_event *event, int vcpu_id,
 	return true;
 }
 
+static bool is_child_event(struct perf_kvm_stat *kvm,
+			   struct perf_evsel *evsel,
+			   struct perf_sample *sample,
+			   struct event_key *key)
+{
+	struct child_event_ops *child_ops;
+
+	child_ops = kvm->events_ops->child_ops;
+
+	if (!child_ops)
+		return false;
+
+	for (; child_ops->name; child_ops++) {
+		if (!strcmp(evsel->name, child_ops->name)) {
+			child_ops->get_key(evsel, sample, key);
+			return true;
+		}
+	}
+
+	return false;
+}
+
+static bool handle_child_event(struct perf_kvm_stat *kvm,
+			       struct vcpu_event_record *vcpu_record,
+			       struct event_key *key,
+			       struct perf_sample *sample __maybe_unused)
+{
+	struct kvm_event *event = NULL;
+
+	if (key->key != INVALID_KEY)
+		event = find_create_kvm_event(kvm, key);
+
+	vcpu_record->last_event = event;
+
+	return true;
+}
+
 static bool skip_event(const char *event)
 {
 	const char * const *skip_events;
@@ -361,7 +398,8 @@ static bool handle_kvm_event(struct perf_kvm_stat *kvm,
 			     struct perf_sample *sample)
 {
 	struct vcpu_event_record *vcpu_record;
-	struct event_key key = {.key = INVALID_KEY};
+	struct event_key key = { .key = INVALID_KEY,
+				 .exit_reasons = kvm->exit_reasons };
 
 	vcpu_record = per_vcpu_record(thread, evsel, sample);
 	if (!vcpu_record)
@@ -375,6 +413,9 @@ static bool handle_kvm_event(struct perf_kvm_stat *kvm,
 	if (kvm->events_ops->is_begin_event(evsel, sample, &key))
 		return handle_begin_event(kvm, vcpu_record, &key, sample->time);
 
+	if (is_child_event(kvm, evsel, sample, &key))
+		return handle_child_event(kvm, vcpu_record, &key, sample);
+
 	if (kvm->events_ops->is_end_event(evsel, sample, &key))
 		return handle_end_event(kvm, vcpu_record, &key, sample);
 
@@ -1143,7 +1184,8 @@ kvm_events_report(struct perf_kvm_stat *kvm, int argc, const char **argv)
 {
 	const struct option kvm_events_report_options[] = {
 		OPT_STRING(0, "event", &kvm->report_event, "report event",
-			    "event for reporting: vmexit, mmio, ioport"),
+			   "event for reporting: vmexit, "
+			   "mmio (x86 only), ioport (x86 only)"),
 		OPT_INTEGER(0, "vcpu", &kvm->trace_vcpu,
 			    "vcpu id to report"),
 		OPT_STRING('k', "key", &kvm->sort_key, "sort-key",
@@ -1249,7 +1291,9 @@ static int kvm_events_live(struct perf_kvm_stat *kvm,
 			"key for sorting: sample(sort by samples number)"
 			" time (sort by avg time)"),
 		OPT_U64(0, "duration", &kvm->duration,
-		    "show events other than HALT that take longer than duration usecs"),
+			"show events other than"
+			" HLT (x86 only) or Wait state (s390 only)"
+			" that take longer than duration usecs"),
 		OPT_END()
 	};
 	const char * const live_usage[] = {
diff --git a/tools/perf/util/kvm-stat.h b/tools/perf/util/kvm-stat.h
index ba937ca..0b5a8cd 100644
--- a/tools/perf/util/kvm-stat.h
+++ b/tools/perf/util/kvm-stat.h
@@ -12,6 +12,7 @@ struct event_key {
 	#define INVALID_KEY     (~0ULL)
 	u64 key;
 	int info;
+	struct exit_reasons_table *exit_reasons;
 };
 
 struct kvm_event_stats {
@@ -41,12 +42,20 @@ struct kvm_event_key {
 
 struct perf_kvm_stat;
 
+struct child_event_ops {
+	void (*get_key)(struct perf_evsel *evsel,
+			struct perf_sample *sample,
+			struct event_key *key);
+	const char *name;
+};
+
 struct kvm_events_ops {
 	bool (*is_begin_event)(struct perf_evsel *evsel,
 			       struct perf_sample *sample,
 			       struct event_key *key);
 	bool (*is_end_event)(struct perf_evsel *evsel,
 			     struct perf_sample *sample, struct event_key *key);
+	struct child_event_ops *child_ops;
 	void (*decode_key)(struct perf_kvm_stat *kvm, struct event_key *key,
 			   char *decode);
 	const char *name;
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* Re: [PATCH/RFC 0/4] perf kvm: add stat support for s390
  2014-07-03 14:29 [PATCH/RFC 0/4] perf kvm: add stat support for s390 Alexander Yarygin
                   ` (3 preceding siblings ...)
  2014-07-03 14:29 ` [PATCH 4/4] perf kvm: Add stat support on s390 Alexander Yarygin
@ 2014-07-03 15:07 ` Christian Borntraeger
  2014-07-09 16:47 ` David Ahern
  5 siblings, 0 replies; 23+ messages in thread
From: Christian Borntraeger @ 2014-07-03 15:07 UTC (permalink / raw)
  To: Alexander Yarygin, Jiri Olsa
  Cc: David Ahern, Peter Zijlstra, Paul Mackerras, Ingo Molnar,
	Arnaldo Carvalho de Melo, Cornelia Huck, linux-kernel,
	Paolo Bonzini

On 03/07/14 16:29, Alexander Yarygin wrote:
> Currently, a lot of code in buildin-kvm.c are x86 specific.
> In accordance with the proposal of David Ahern, we moved the code under
> #ifdefs from buildin-kvm.c into tools/perf/arch/*/kvm-stat.c. Architecture
> specific constants were added in arch/*/include/uapi/perf-kvm.h. Also,
> generic perf kvm stat structures were moved into the new file util/kvm-stat.h.
> 
> So, patches 1-3 reduce architecture dependency of buildin-kvm.c.
> Patch 4 implements s390 specific functions. Since some events on s390
> can have tree-like structure, the patch also adds functions to handle
> these events in generic code.
> 
> The patch set based on linux-3.16-rc1 including patches in
> "perf kvm: refactoring and small changes".
> 
> Link to the "perf kvm: refactoring and small changes" patch series:
> https://lkml.org/lkml/2014/7/3/461
> Link to the previous thread: https://lkml.org/lkml/2014/4/25/331
> 
> Alexander Yarygin (4):
>   perf kvm: Use defines of kvm events
>   perf kvm: Move arch specific code into arch/
>   perf kvm: Add skip_event() for --duration option
>   perf kvm: Add stat support on s390
> 
>  arch/s390/include/uapi/asm/Kbuild     |    1 +
>  arch/s390/include/uapi/asm/kvm_perf.h |   25 +++
>  arch/x86/include/uapi/asm/Kbuild      |    1 +
>  arch/x86/include/uapi/asm/kvm_perf.h  |   16 ++
>  tools/perf/Documentation/perf-kvm.txt |   10 +-
>  tools/perf/MANIFEST                   |    3 +
>  tools/perf/Makefile.perf              |    1 +
>  tools/perf/arch/s390/Makefile         |    2 +
>  tools/perf/arch/s390/util/kvm-stat.c  |  105 +++++++++
>  tools/perf/arch/x86/Makefile          |    1 +
>  tools/perf/arch/x86/util/kvm-stat.c   |  156 ++++++++++++++
>  tools/perf/builtin-kvm.c              |  384 +++++++++------------------------
>  tools/perf/util/kvm-stat.h            |  140 ++++++++++++
>  13 files changed, 561 insertions(+), 284 deletions(-)
>  create mode 100644 arch/s390/include/uapi/asm/kvm_perf.h
>  create mode 100644 arch/x86/include/uapi/asm/kvm_perf.h
>  create mode 100644 tools/perf/arch/s390/util/kvm-stat.c
>  create mode 100644 tools/perf/arch/x86/util/kvm-stat.c
>  create mode 100644 tools/perf/util/kvm-stat.h
> 
> --
> 1.7.9.5


CC Paolo,

All patches, look sane and
Acked-by; Christian Borntraeger <borntraeger@de.ibm.com>

Christian



^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH 1/4] perf kvm: Use defines of kvm events
  2014-07-03 14:29 ` [PATCH 1/4] perf kvm: Use defines of kvm events Alexander Yarygin
@ 2014-07-07 14:06   ` Christian Borntraeger
  2014-07-07 15:42     ` David Ahern
  2014-07-09 13:45   ` David Ahern
  2014-07-18  4:21   ` [tip:perf/core] " tip-bot for Alexander Yarygin
  2 siblings, 1 reply; 23+ messages in thread
From: Christian Borntraeger @ 2014-07-07 14:06 UTC (permalink / raw)
  To: Alexander Yarygin, Jiri Olsa
  Cc: David Ahern, Peter Zijlstra, Paul Mackerras, Ingo Molnar,
	Arnaldo Carvalho de Melo, Cornelia Huck, linux-kernel,
	Paolo Bonzini

On 03/07/14 16:29, Alexander Yarygin wrote:
> Currently perf-kvm uses string literals for kvm event names,
> but it works only for x86, because other architectures may have
> other names for those events.
> 
> To reduce dependence on architecture, we add <asm/kvm_perf.h> file with
> defines for:
> - kvm_entry and kvm_exit events,
> - exit reason field name in kvm_exit event,
> - length of exit reasons strings,
> - vcpu_id field name in kvm trace events,
> 
> and replace literals in perf-kvm.
> 
> Signed-off-by: Alexander Yarygin <yarygin@linux.vnet.ibm.com>
> Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>

Acked-by: Christian Borntraeger <borntraeger@de.ibm.com>
Would be good if Paolo and David could ack the KVM/perf parts. Then this should also go into next merge window.

> ---
>  arch/x86/include/uapi/asm/Kbuild     |    1 +
>  arch/x86/include/uapi/asm/kvm_perf.h |   16 ++++++++++++++++
>  tools/perf/MANIFEST                  |    1 +
>  tools/perf/builtin-kvm.c             |   34 ++++++++++++++++------------------
>  4 files changed, 34 insertions(+), 18 deletions(-)
>  create mode 100644 arch/x86/include/uapi/asm/kvm_perf.h
> 
> diff --git a/arch/x86/include/uapi/asm/Kbuild b/arch/x86/include/uapi/asm/Kbuild
> index 09409c4..3dec769 100644
> --- a/arch/x86/include/uapi/asm/Kbuild
> +++ b/arch/x86/include/uapi/asm/Kbuild
> @@ -22,6 +22,7 @@ header-y += ipcbuf.h
>  header-y += ist.h
>  header-y += kvm.h
>  header-y += kvm_para.h
> +header-y += kvm_perf.h
>  header-y += ldt.h
>  header-y += mce.h
>  header-y += mman.h
> diff --git a/arch/x86/include/uapi/asm/kvm_perf.h b/arch/x86/include/uapi/asm/kvm_perf.h
> new file mode 100644
> index 0000000..3bb964f
> --- /dev/null
> +++ b/arch/x86/include/uapi/asm/kvm_perf.h
> @@ -0,0 +1,16 @@
> +#ifndef _ASM_X86_KVM_PERF_H
> +#define _ASM_X86_KVM_PERF_H
> +
> +#include <asm/svm.h>
> +#include <asm/vmx.h>
> +#include <asm/kvm.h>
> +
> +#define DECODE_STR_LEN 20
> +
> +#define VCPU_ID "vcpu_id"
> +
> +#define KVM_ENTRY_TRACE "kvm:kvm_entry"
> +#define KVM_EXIT_TRACE "kvm:kvm_exit"
> +#define KVM_EXIT_REASON "exit_reason"
> +
> +#endif /* _ASM_X86_KVM_PERF_H */
> diff --git a/tools/perf/MANIFEST b/tools/perf/MANIFEST
> index 45da209..02b485d 100644
> --- a/tools/perf/MANIFEST
> +++ b/tools/perf/MANIFEST
> @@ -37,3 +37,4 @@ arch/x86/include/asm/kvm_host.h
>  arch/x86/include/uapi/asm/svm.h
>  arch/x86/include/uapi/asm/vmx.h
>  arch/x86/include/uapi/asm/kvm.h
> +arch/x86/include/uapi/asm/kvm_perf.h
> diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
> index 41dbeaf..6d73346 100644
> --- a/tools/perf/builtin-kvm.c
> +++ b/tools/perf/builtin-kvm.c
> @@ -30,9 +30,7 @@
>  #include <math.h>
> 
>  #ifdef HAVE_KVM_STAT_SUPPORT
> -#include <asm/svm.h>
> -#include <asm/vmx.h>
> -#include <asm/kvm.h>
> +#include <asm/kvm_perf.h>
> 
>  struct event_key {
>  	#define INVALID_KEY     (~0ULL)
> @@ -75,7 +73,7 @@ struct kvm_events_ops {
>  	bool (*is_end_event)(struct perf_evsel *evsel,
>  			     struct perf_sample *sample, struct event_key *key);
>  	void (*decode_key)(struct perf_kvm_stat *kvm, struct event_key *key,
> -			   char decode[20]);
> +			   char *decode);
>  	const char *name;
>  };
> 
> @@ -126,12 +124,12 @@ static void exit_event_get_key(struct perf_evsel *evsel,
>  			       struct event_key *key)
>  {
>  	key->info = 0;
> -	key->key = perf_evsel__intval(evsel, sample, "exit_reason");
> +	key->key = perf_evsel__intval(evsel, sample, KVM_EXIT_REASON);
>  }
> 
>  static bool kvm_exit_event(struct perf_evsel *evsel)
>  {
> -	return !strcmp(evsel->name, "kvm:kvm_exit");
> +	return !strcmp(evsel->name, KVM_EXIT_TRACE);
>  }
> 
>  static bool exit_event_begin(struct perf_evsel *evsel,
> @@ -147,7 +145,7 @@ static bool exit_event_begin(struct perf_evsel *evsel,
> 
>  static bool kvm_entry_event(struct perf_evsel *evsel)
>  {
> -	return !strcmp(evsel->name, "kvm:kvm_entry");
> +	return !strcmp(evsel->name, KVM_ENTRY_TRACE);
>  }
> 
>  static bool exit_event_end(struct perf_evsel *evsel,
> @@ -182,12 +180,12 @@ static const char *get_exit_reason(struct perf_kvm_stat *kvm,
> 
>  static void exit_event_decode_key(struct perf_kvm_stat *kvm,
>  				  struct event_key *key,
> -				  char decode[20])
> +				  char *decode)
>  {
>  	const char *exit_reason = get_exit_reason(kvm, kvm->exit_reasons,
>  						  key->key);
> 
> -	scnprintf(decode, 20, "%s", exit_reason);
> +	scnprintf(decode, DECODE_STR_LEN, "%s", exit_reason);
>  }
> 
>  static struct kvm_events_ops exit_events = {
> @@ -249,9 +247,9 @@ static bool mmio_event_end(struct perf_evsel *evsel, struct perf_sample *sample,
> 
>  static void mmio_event_decode_key(struct perf_kvm_stat *kvm __maybe_unused,
>  				  struct event_key *key,
> -				  char decode[20])
> +				  char *decode)
>  {
> -	scnprintf(decode, 20, "%#lx:%s", (unsigned long)key->key,
> +	scnprintf(decode, DECODE_STR_LEN, "%#lx:%s", (unsigned long)key->key,
>  				key->info == KVM_TRACE_MMIO_WRITE ? "W" : "R");
>  }
> 
> @@ -292,9 +290,9 @@ static bool ioport_event_end(struct perf_evsel *evsel,
> 
>  static void ioport_event_decode_key(struct perf_kvm_stat *kvm __maybe_unused,
>  				    struct event_key *key,
> -				    char decode[20])
> +				    char *decode)
>  {
> -	scnprintf(decode, 20, "%#llx:%s", (unsigned long long)key->key,
> +	scnprintf(decode, DECODE_STR_LEN, "%#llx:%s", (unsigned long long)key->key,
>  				key->info ? "POUT" : "PIN");
>  }
> 
> @@ -524,7 +522,7 @@ static bool handle_end_event(struct perf_kvm_stat *kvm,
>  	time_diff = sample->time - time_begin;
> 
>  	if (kvm->duration && time_diff > kvm->duration) {
> -		char decode[32];
> +		char decode[DECODE_STR_LEN];
> 
>  		kvm->events_ops->decode_key(kvm, &event->key, decode);
>  		if (strcmp(decode, "HLT")) {
> @@ -552,7 +550,7 @@ struct vcpu_event_record *per_vcpu_record(struct thread *thread,
>  			return NULL;
>  		}
> 
> -		vcpu_record->vcpu_id = perf_evsel__intval(evsel, sample, "vcpu_id");
> +		vcpu_record->vcpu_id = perf_evsel__intval(evsel, sample, VCPU_ID);
>  		thread->priv = vcpu_record;
>  	}
> 
> @@ -739,7 +737,7 @@ static void show_timeofday(void)
> 
>  static void print_result(struct perf_kvm_stat *kvm)
>  {
> -	char decode[20];
> +	char decode[DECODE_STR_LEN];
>  	struct kvm_event *event;
>  	int vcpu = kvm->trace_vcpu;
> 
> @@ -750,7 +748,7 @@ static void print_result(struct perf_kvm_stat *kvm)
> 
>  	pr_info("\n\n");
>  	print_vcpu_info(kvm);
> -	pr_info("%20s ", kvm->events_ops->name);
> +	pr_info("%*s ", DECODE_STR_LEN, kvm->events_ops->name);
>  	pr_info("%10s ", "Samples");
>  	pr_info("%9s ", "Samples%");
> 
> @@ -769,7 +767,7 @@ static void print_result(struct perf_kvm_stat *kvm)
>  		min = get_event_min(event, vcpu);
> 
>  		kvm->events_ops->decode_key(kvm, &event->key, decode);
> -		pr_info("%20s ", decode);
> +		pr_info("%*s ", DECODE_STR_LEN, decode);
>  		pr_info("%10llu ", (unsigned long long)ecount);
>  		pr_info("%8.2f%% ", (double)ecount / kvm->total_count * 100);
>  		pr_info("%8.2f%% ", (double)etime / kvm->total_time * 100);
> 


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH 2/4] perf kvm: Move arch specific code into arch/
  2014-07-03 14:29 ` [PATCH 2/4] perf kvm: Move arch specific code into arch/ Alexander Yarygin
@ 2014-07-07 14:09   ` Christian Borntraeger
  2014-07-09 13:45   ` David Ahern
  2014-07-18  4:21   ` [tip:perf/core] " tip-bot for Alexander Yarygin
  2 siblings, 0 replies; 23+ messages in thread
From: Christian Borntraeger @ 2014-07-07 14:09 UTC (permalink / raw)
  To: Alexander Yarygin, Jiri Olsa
  Cc: David Ahern, Peter Zijlstra, Paul Mackerras, Ingo Molnar,
	Arnaldo Carvalho de Melo, Cornelia Huck, linux-kernel,
	Paolo Bonzini

On 03/07/14 16:29, Alexander Yarygin wrote:
> Parts of a 'perf kvm stat' code make sense only for x86.
> Let's move this code into the arch/x86/kvm-stat.c file and add
> util/kvm-stat.h for generic structure definitions.
> 
> Add a global array 'kvm_reg_events_ops' for accessing the
> arch-specific 'kvm_events_ops' from generic code.
> 
> Since the several global arrays (i.e. 'kvm_events_tp') have been moved
> to arch/*, we can not know their sizes and use them directly in
> builtin-kvm.c. This patch fixes that problem by adding trimming
> NULL element to each array and changing the behavior of their handlers
> in generic code.
> 
> Signed-off-by: Alexander Yarygin <yarygin@linux.vnet.ibm.com>
> Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>

Acked-by: Christian Borntraeger <borntraeger@de.ibm.com>
Would be good if Paolo and David could ack the KVM/perf parts.

Then this should also go into next merge window.



> ---
>  tools/perf/Makefile.perf            |    1 +
>  tools/perf/arch/x86/Makefile        |    1 +
>  tools/perf/arch/x86/util/kvm-stat.c |  151 ++++++++++++++++++
>  tools/perf/builtin-kvm.c            |  297 ++++-------------------------------
>  tools/perf/util/kvm-stat.h          |  130 +++++++++++++++
>  5 files changed, 317 insertions(+), 263 deletions(-)
>  create mode 100644 tools/perf/arch/x86/util/kvm-stat.c
>  create mode 100644 tools/perf/util/kvm-stat.h
> 
> diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
> index ae20edf..f1a590f 100644
> --- a/tools/perf/Makefile.perf
> +++ b/tools/perf/Makefile.perf
> @@ -300,6 +300,7 @@ LIB_H += ui/progress.h
>  LIB_H += ui/util.h
>  LIB_H += ui/ui.h
>  LIB_H += util/data.h
> +LIB_H += util/kvm-stat.h
> 
>  LIB_OBJS += $(OUTPUT)util/abspath.o
>  LIB_OBJS += $(OUTPUT)util/alias.o
> diff --git a/tools/perf/arch/x86/Makefile b/tools/perf/arch/x86/Makefile
> index d393901..9b21881 100644
> --- a/tools/perf/arch/x86/Makefile
> +++ b/tools/perf/arch/x86/Makefile
> @@ -16,3 +16,4 @@ LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/header.o
>  LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/tsc.o
>  LIB_H += arch/$(ARCH)/util/tsc.h
>  HAVE_KVM_STAT_SUPPORT := 1
> +LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/kvm-stat.o
> diff --git a/tools/perf/arch/x86/util/kvm-stat.c b/tools/perf/arch/x86/util/kvm-stat.c
> new file mode 100644
> index 0000000..2f8d2c1
> --- /dev/null
> +++ b/tools/perf/arch/x86/util/kvm-stat.c
> @@ -0,0 +1,151 @@
> +#include "../../util/kvm-stat.h"
> +#include <asm/kvm_perf.h>
> +
> +define_exit_reasons_table(vmx_exit_reasons, VMX_EXIT_REASONS);
> +define_exit_reasons_table(svm_exit_reasons, SVM_EXIT_REASONS);
> +
> +static struct kvm_events_ops exit_events = {
> +	.is_begin_event = exit_event_begin,
> +	.is_end_event = exit_event_end,
> +	.decode_key = exit_event_decode_key,
> +	.name = "VM-EXIT"
> +};
> +
> +/*
> + * For the mmio events, we treat:
> + * the time of MMIO write: kvm_mmio(KVM_TRACE_MMIO_WRITE...) -> kvm_entry
> + * the time of MMIO read: kvm_exit -> kvm_mmio(KVM_TRACE_MMIO_READ...).
> + */
> +static void mmio_event_get_key(struct perf_evsel *evsel, struct perf_sample *sample,
> +			       struct event_key *key)
> +{
> +	key->key  = perf_evsel__intval(evsel, sample, "gpa");
> +	key->info = perf_evsel__intval(evsel, sample, "type");
> +}
> +
> +#define KVM_TRACE_MMIO_READ_UNSATISFIED 0
> +#define KVM_TRACE_MMIO_READ 1
> +#define KVM_TRACE_MMIO_WRITE 2
> +
> +static bool mmio_event_begin(struct perf_evsel *evsel,
> +			     struct perf_sample *sample, struct event_key *key)
> +{
> +	/* MMIO read begin event in kernel. */
> +	if (kvm_exit_event(evsel))
> +		return true;
> +
> +	/* MMIO write begin event in kernel. */
> +	if (!strcmp(evsel->name, "kvm:kvm_mmio") &&
> +	    perf_evsel__intval(evsel, sample, "type") == KVM_TRACE_MMIO_WRITE) {
> +		mmio_event_get_key(evsel, sample, key);
> +		return true;
> +	}
> +
> +	return false;
> +}
> +
> +static bool mmio_event_end(struct perf_evsel *evsel, struct perf_sample *sample,
> +			   struct event_key *key)
> +{
> +	/* MMIO write end event in kernel. */
> +	if (kvm_entry_event(evsel))
> +		return true;
> +
> +	/* MMIO read end event in kernel.*/
> +	if (!strcmp(evsel->name, "kvm:kvm_mmio") &&
> +	    perf_evsel__intval(evsel, sample, "type") == KVM_TRACE_MMIO_READ) {
> +		mmio_event_get_key(evsel, sample, key);
> +		return true;
> +	}
> +
> +	return false;
> +}
> +
> +static void mmio_event_decode_key(struct perf_kvm_stat *kvm __maybe_unused,
> +				  struct event_key *key,
> +				  char *decode)
> +{
> +	scnprintf(decode, DECODE_STR_LEN, "%#lx:%s",
> +		  (unsigned long)key->key,
> +		  key->info == KVM_TRACE_MMIO_WRITE ? "W" : "R");
> +}
> +
> +static struct kvm_events_ops mmio_events = {
> +	.is_begin_event = mmio_event_begin,
> +	.is_end_event = mmio_event_end,
> +	.decode_key = mmio_event_decode_key,
> +	.name = "MMIO Access"
> +};
> +
> + /* The time of emulation pio access is from kvm_pio to kvm_entry. */
> +static void ioport_event_get_key(struct perf_evsel *evsel,
> +				 struct perf_sample *sample,
> +				 struct event_key *key)
> +{
> +	key->key  = perf_evsel__intval(evsel, sample, "port");
> +	key->info = perf_evsel__intval(evsel, sample, "rw");
> +}
> +
> +static bool ioport_event_begin(struct perf_evsel *evsel,
> +			       struct perf_sample *sample,
> +			       struct event_key *key)
> +{
> +	if (!strcmp(evsel->name, "kvm:kvm_pio")) {
> +		ioport_event_get_key(evsel, sample, key);
> +		return true;
> +	}
> +
> +	return false;
> +}
> +
> +static bool ioport_event_end(struct perf_evsel *evsel,
> +			     struct perf_sample *sample __maybe_unused,
> +			     struct event_key *key __maybe_unused)
> +{
> +	return kvm_entry_event(evsel);
> +}
> +
> +static void ioport_event_decode_key(struct perf_kvm_stat *kvm __maybe_unused,
> +				    struct event_key *key,
> +				    char *decode)
> +{
> +	scnprintf(decode, DECODE_STR_LEN, "%#llx:%s",
> +		  (unsigned long long)key->key,
> +		  key->info ? "POUT" : "PIN");
> +}
> +
> +static struct kvm_events_ops ioport_events = {
> +	.is_begin_event = ioport_event_begin,
> +	.is_end_event = ioport_event_end,
> +	.decode_key = ioport_event_decode_key,
> +	.name = "IO Port Access"
> +};
> +
> +const char * const kvm_events_tp[] = {
> +	"kvm:kvm_entry",
> +	"kvm:kvm_exit",
> +	"kvm:kvm_mmio",
> +	"kvm:kvm_pio",
> +	NULL,
> +};
> +
> +struct kvm_reg_events_ops kvm_reg_events_ops[] = {
> +	{ .name = "vmexit", .ops = &exit_events },
> +	{ .name = "mmio", .ops = &mmio_events },
> +	{ .name = "ioport", .ops = &ioport_events },
> +	{ NULL, NULL },
> +};
> +
> +int cpu_isa_init(struct perf_kvm_stat *kvm, const char *cpuid)
> +{
> +	if (strstr(cpuid, "Intel")) {
> +		kvm->exit_reasons = vmx_exit_reasons;
> +		kvm->exit_reasons_isa = "VMX";
> +	} else if (strstr(cpuid, "AMD")) {
> +		kvm->exit_reasons = svm_exit_reasons;
> +		kvm->exit_reasons_isa = "SVM";
> +	} else
> +		return -ENOTSUP;
> +
> +	return 0;
> +}
> diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
> index 6d73346..75ee8c1 100644
> --- a/tools/perf/builtin-kvm.c
> +++ b/tools/perf/builtin-kvm.c
> @@ -31,109 +31,23 @@
> 
>  #ifdef HAVE_KVM_STAT_SUPPORT
>  #include <asm/kvm_perf.h>
> +#include "util/kvm-stat.h"
> 
> -struct event_key {
> -	#define INVALID_KEY     (~0ULL)
> -	u64 key;
> -	int info;
> -};
> -
> -struct kvm_event_stats {
> -	u64 time;
> -	struct stats stats;
> -};
> -
> -struct kvm_event {
> -	struct list_head hash_entry;
> -	struct rb_node rb;
> -
> -	struct event_key key;
> -
> -	struct kvm_event_stats total;
> -
> -	#define DEFAULT_VCPU_NUM 8
> -	int max_vcpu;
> -	struct kvm_event_stats *vcpu;
> -};
> -
> -typedef int (*key_cmp_fun)(struct kvm_event*, struct kvm_event*, int);
> -
> -struct kvm_event_key {
> -	const char *name;
> -	key_cmp_fun key;
> -};
> -
> -
> -struct perf_kvm_stat;
> -
> -struct kvm_events_ops {
> -	bool (*is_begin_event)(struct perf_evsel *evsel,
> -			       struct perf_sample *sample,
> -			       struct event_key *key);
> -	bool (*is_end_event)(struct perf_evsel *evsel,
> -			     struct perf_sample *sample, struct event_key *key);
> -	void (*decode_key)(struct perf_kvm_stat *kvm, struct event_key *key,
> -			   char *decode);
> -	const char *name;
> -};
> -
> -struct exit_reasons_table {
> -	unsigned long exit_code;
> -	const char *reason;
> -};
> -
> -#define EVENTS_BITS		12
> -#define EVENTS_CACHE_SIZE	(1UL << EVENTS_BITS)
> -
> -struct perf_kvm_stat {
> -	struct perf_tool    tool;
> -	struct record_opts  opts;
> -	struct perf_evlist  *evlist;
> -	struct perf_session *session;
> -
> -	const char *file_name;
> -	const char *report_event;
> -	const char *sort_key;
> -	int trace_vcpu;
> -
> -	struct exit_reasons_table *exit_reasons;
> -	const char *exit_reasons_isa;
> -
> -	struct kvm_events_ops *events_ops;
> -	key_cmp_fun compare;
> -	struct list_head kvm_events_cache[EVENTS_CACHE_SIZE];
> -
> -	u64 total_time;
> -	u64 total_count;
> -	u64 lost_events;
> -	u64 duration;
> -
> -	const char *pid_str;
> -	struct intlist *pid_list;
> -
> -	struct rb_root result;
> -
> -	int timerfd;
> -	unsigned int display_time;
> -	bool live;
> -};
> -
> -
> -static void exit_event_get_key(struct perf_evsel *evsel,
> -			       struct perf_sample *sample,
> -			       struct event_key *key)
> +void exit_event_get_key(struct perf_evsel *evsel,
> +			struct perf_sample *sample,
> +			struct event_key *key)
>  {
>  	key->info = 0;
>  	key->key = perf_evsel__intval(evsel, sample, KVM_EXIT_REASON);
>  }
> 
> -static bool kvm_exit_event(struct perf_evsel *evsel)
> +bool kvm_exit_event(struct perf_evsel *evsel)
>  {
>  	return !strcmp(evsel->name, KVM_EXIT_TRACE);
>  }
> 
> -static bool exit_event_begin(struct perf_evsel *evsel,
> -			     struct perf_sample *sample, struct event_key *key)
> +bool exit_event_begin(struct perf_evsel *evsel,
> +		      struct perf_sample *sample, struct event_key *key)
>  {
>  	if (kvm_exit_event(evsel)) {
>  		exit_event_get_key(evsel, sample, key);
> @@ -143,26 +57,18 @@ static bool exit_event_begin(struct perf_evsel *evsel,
>  	return false;
>  }
> 
> -static bool kvm_entry_event(struct perf_evsel *evsel)
> +bool kvm_entry_event(struct perf_evsel *evsel)
>  {
>  	return !strcmp(evsel->name, KVM_ENTRY_TRACE);
>  }
> 
> -static bool exit_event_end(struct perf_evsel *evsel,
> -			   struct perf_sample *sample __maybe_unused,
> -			   struct event_key *key __maybe_unused)
> +bool exit_event_end(struct perf_evsel *evsel,
> +		    struct perf_sample *sample __maybe_unused,
> +		    struct event_key *key __maybe_unused)
>  {
>  	return kvm_entry_event(evsel);
>  }
> 
> -#define define_exit_reasons_table(name, symbols)	\
> -	static struct exit_reasons_table name[] = {	\
> -		symbols, { -1, NULL }			\
> -	}
> -
> -define_exit_reasons_table(vmx_exit_reasons, VMX_EXIT_REASONS);
> -define_exit_reasons_table(svm_exit_reasons, SVM_EXIT_REASONS);
> -
>  static const char *get_exit_reason(struct perf_kvm_stat *kvm,
>  				   struct exit_reasons_table *tbl,
>  				   u64 exit_code)
> @@ -178,9 +84,9 @@ static const char *get_exit_reason(struct perf_kvm_stat *kvm,
>  	return "UNKNOWN";
>  }
> 
> -static void exit_event_decode_key(struct perf_kvm_stat *kvm,
> -				  struct event_key *key,
> -				  char *decode)
> +void exit_event_decode_key(struct perf_kvm_stat *kvm,
> +			   struct event_key *key,
> +			   char *decode)
>  {
>  	const char *exit_reason = get_exit_reason(kvm, kvm->exit_reasons,
>  						  key->key);
> @@ -188,139 +94,20 @@ static void exit_event_decode_key(struct perf_kvm_stat *kvm,
>  	scnprintf(decode, DECODE_STR_LEN, "%s", exit_reason);
>  }
> 
> -static struct kvm_events_ops exit_events = {
> -	.is_begin_event = exit_event_begin,
> -	.is_end_event = exit_event_end,
> -	.decode_key = exit_event_decode_key,
> -	.name = "VM-EXIT"
> -};
> -
> -/*
> - * For the mmio events, we treat:
> - * the time of MMIO write: kvm_mmio(KVM_TRACE_MMIO_WRITE...) -> kvm_entry
> - * the time of MMIO read: kvm_exit -> kvm_mmio(KVM_TRACE_MMIO_READ...).
> - */
> -static void mmio_event_get_key(struct perf_evsel *evsel, struct perf_sample *sample,
> -			       struct event_key *key)
> -{
> -	key->key  = perf_evsel__intval(evsel, sample, "gpa");
> -	key->info = perf_evsel__intval(evsel, sample, "type");
> -}
> -
> -#define KVM_TRACE_MMIO_READ_UNSATISFIED 0
> -#define KVM_TRACE_MMIO_READ 1
> -#define KVM_TRACE_MMIO_WRITE 2
> -
> -static bool mmio_event_begin(struct perf_evsel *evsel,
> -			     struct perf_sample *sample, struct event_key *key)
> -{
> -	/* MMIO read begin event in kernel. */
> -	if (kvm_exit_event(evsel))
> -		return true;
> -
> -	/* MMIO write begin event in kernel. */
> -	if (!strcmp(evsel->name, "kvm:kvm_mmio") &&
> -	    perf_evsel__intval(evsel, sample, "type") == KVM_TRACE_MMIO_WRITE) {
> -		mmio_event_get_key(evsel, sample, key);
> -		return true;
> -	}
> -
> -	return false;
> -}
> -
> -static bool mmio_event_end(struct perf_evsel *evsel, struct perf_sample *sample,
> -			   struct event_key *key)
> -{
> -	/* MMIO write end event in kernel. */
> -	if (kvm_entry_event(evsel))
> -		return true;
> -
> -	/* MMIO read end event in kernel.*/
> -	if (!strcmp(evsel->name, "kvm:kvm_mmio") &&
> -	    perf_evsel__intval(evsel, sample, "type") == KVM_TRACE_MMIO_READ) {
> -		mmio_event_get_key(evsel, sample, key);
> -		return true;
> -	}
> -
> -	return false;
> -}
> -
> -static void mmio_event_decode_key(struct perf_kvm_stat *kvm __maybe_unused,
> -				  struct event_key *key,
> -				  char *decode)
> -{
> -	scnprintf(decode, DECODE_STR_LEN, "%#lx:%s", (unsigned long)key->key,
> -				key->info == KVM_TRACE_MMIO_WRITE ? "W" : "R");
> -}
> -
> -static struct kvm_events_ops mmio_events = {
> -	.is_begin_event = mmio_event_begin,
> -	.is_end_event = mmio_event_end,
> -	.decode_key = mmio_event_decode_key,
> -	.name = "MMIO Access"
> -};
> -
> - /* The time of emulation pio access is from kvm_pio to kvm_entry. */
> -static void ioport_event_get_key(struct perf_evsel *evsel,
> -				 struct perf_sample *sample,
> -				 struct event_key *key)
> +static bool register_kvm_events_ops(struct perf_kvm_stat *kvm)
>  {
> -	key->key  = perf_evsel__intval(evsel, sample, "port");
> -	key->info = perf_evsel__intval(evsel, sample, "rw");
> -}
> +	struct kvm_reg_events_ops *events_ops = kvm_reg_events_ops;
> 
> -static bool ioport_event_begin(struct perf_evsel *evsel,
> -			       struct perf_sample *sample,
> -			       struct event_key *key)
> -{
> -	if (!strcmp(evsel->name, "kvm:kvm_pio")) {
> -		ioport_event_get_key(evsel, sample, key);
> -		return true;
> +	for (events_ops = kvm_reg_events_ops; events_ops->name; events_ops++) {
> +		if (!strcmp(events_ops->name, kvm->report_event)) {
> +			kvm->events_ops = events_ops->ops;
> +			return true;
> +		}
>  	}
> 
>  	return false;
>  }
> 
> -static bool ioport_event_end(struct perf_evsel *evsel,
> -			     struct perf_sample *sample __maybe_unused,
> -			     struct event_key *key __maybe_unused)
> -{
> -	return kvm_entry_event(evsel);
> -}
> -
> -static void ioport_event_decode_key(struct perf_kvm_stat *kvm __maybe_unused,
> -				    struct event_key *key,
> -				    char *decode)
> -{
> -	scnprintf(decode, DECODE_STR_LEN, "%#llx:%s", (unsigned long long)key->key,
> -				key->info ? "POUT" : "PIN");
> -}
> -
> -static struct kvm_events_ops ioport_events = {
> -	.is_begin_event = ioport_event_begin,
> -	.is_end_event = ioport_event_end,
> -	.decode_key = ioport_event_decode_key,
> -	.name = "IO Port Access"
> -};
> -
> -static bool register_kvm_events_ops(struct perf_kvm_stat *kvm)
> -{
> -	bool ret = true;
> -
> -	if (!strcmp(kvm->report_event, "vmexit"))
> -		kvm->events_ops = &exit_events;
> -	else if (!strcmp(kvm->report_event, "mmio"))
> -		kvm->events_ops = &mmio_events;
> -	else if (!strcmp(kvm->report_event, "ioport"))
> -		kvm->events_ops = &ioport_events;
> -	else {
> -		pr_err("Unknown report event:%s\n", kvm->report_event);
> -		ret = false;
> -	}
> -
> -	return ret;
> -}
> -
>  struct vcpu_event_record {
>  	int vcpu_id;
>  	u64 start_time;
> @@ -833,20 +620,6 @@ static int process_sample_event(struct perf_tool *tool,
>  	return 0;
>  }
> 
> -static int cpu_isa_init(struct perf_kvm_stat *kvm, const char *cpuid)
> -{
> -	if (strstr(cpuid, "Intel")) {
> -		kvm->exit_reasons = vmx_exit_reasons;
> -		kvm->exit_reasons_isa = "VMX";
> -	} else if (strstr(cpuid, "AMD")) {
> -		kvm->exit_reasons = svm_exit_reasons;
> -		kvm->exit_reasons_isa = "SVM";
> -	} else
> -		return -ENOTSUP;
> -
> -	return 0;
> -}
> -
>  static int cpu_isa_config(struct perf_kvm_stat *kvm)
>  {
>  	char buf[64], *cpuid;
> @@ -1305,13 +1078,6 @@ exit:
>  	return ret;
>  }
> 
> -static const char * const kvm_events_tp[] = {
> -	"kvm:kvm_entry",
> -	"kvm:kvm_exit",
> -	"kvm:kvm_mmio",
> -	"kvm:kvm_pio",
> -};
> -
>  #define STRDUP_FAIL_EXIT(s)		\
>  	({	char *_p;		\
>  	_p = strdup(s);		\
> @@ -1323,7 +1089,7 @@ static const char * const kvm_events_tp[] = {
>  static int
>  kvm_events_record(struct perf_kvm_stat *kvm, int argc, const char **argv)
>  {
> -	unsigned int rec_argc, i, j;
> +	unsigned int rec_argc, i, j, events_tp_size;
>  	const char **rec_argv;
>  	const char * const record_args[] = {
>  		"record",
> @@ -1331,9 +1097,14 @@ kvm_events_record(struct perf_kvm_stat *kvm, int argc, const char **argv)
>  		"-m", "1024",
>  		"-c", "1",
>  	};
> +	const char * const *events_tp;
> +	events_tp_size = 0;
> +
> +	for (events_tp = kvm_events_tp; *events_tp; events_tp++)
> +		events_tp_size++;
> 
>  	rec_argc = ARRAY_SIZE(record_args) + argc + 2 +
> -		   2 * ARRAY_SIZE(kvm_events_tp);
> +		   2 * events_tp_size;
>  	rec_argv = calloc(rec_argc + 1, sizeof(char *));
> 
>  	if (rec_argv == NULL)
> @@ -1342,7 +1113,7 @@ kvm_events_record(struct perf_kvm_stat *kvm, int argc, const char **argv)
>  	for (i = 0; i < ARRAY_SIZE(record_args); i++)
>  		rec_argv[i] = STRDUP_FAIL_EXIT(record_args[i]);
> 
> -	for (j = 0; j < ARRAY_SIZE(kvm_events_tp); j++) {
> +	for (j = 0; j < events_tp_size; j++) {
>  		rec_argv[i++] = "-e";
>  		rec_argv[i++] = STRDUP_FAIL_EXIT(kvm_events_tp[j]);
>  	}
> @@ -1396,16 +1167,16 @@ static struct perf_evlist *kvm_live_event_list(void)
>  {
>  	struct perf_evlist *evlist;
>  	char *tp, *name, *sys;
> -	unsigned int j;
>  	int err = -1;
> +	const char * const *events_tp;
> 
>  	evlist = perf_evlist__new();
>  	if (evlist == NULL)
>  		return NULL;
> 
> -	for (j = 0; j < ARRAY_SIZE(kvm_events_tp); j++) {
> +	for (events_tp = kvm_events_tp; *events_tp; events_tp++) {
> 
> -		tp = strdup(kvm_events_tp[j]);
> +		tp = strdup(*events_tp);
>  		if (tp == NULL)
>  			goto out;
> 
> @@ -1414,7 +1185,7 @@ static struct perf_evlist *kvm_live_event_list(void)
>  		name = strchr(tp, ':');
>  		if (name == NULL) {
>  			pr_err("Error parsing %s tracepoint: subsystem delimiter not found\n",
> -				kvm_events_tp[j]);
> +			       *events_tp);
>  			free(tp);
>  			goto out;
>  		}
> @@ -1422,7 +1193,7 @@ static struct perf_evlist *kvm_live_event_list(void)
>  		name++;
> 
>  		if (perf_evlist__add_newtp(evlist, sys, name, NULL)) {
> -			pr_err("Failed to add %s tracepoint to the list\n", kvm_events_tp[j]);
> +			pr_err("Failed to add %s tracepoint to the list\n", *events_tp);
>  			free(tp);
>  			goto out;
>  		}
> diff --git a/tools/perf/util/kvm-stat.h b/tools/perf/util/kvm-stat.h
> new file mode 100644
> index 0000000..d0d9fb1
> --- /dev/null
> +++ b/tools/perf/util/kvm-stat.h
> @@ -0,0 +1,130 @@
> +#ifndef __PERF_KVM_STAT_H
> +#define __PERF_KVM_STAT_H
> +
> +#include "../perf.h"
> +#include "evsel.h"
> +#include "evlist.h"
> +#include "session.h"
> +#include "tool.h"
> +#include "stat.h"
> +
> +struct event_key {
> +	#define INVALID_KEY     (~0ULL)
> +	u64 key;
> +	int info;
> +};
> +
> +struct kvm_event_stats {
> +	u64 time;
> +	struct stats stats;
> +};
> +
> +struct kvm_event {
> +	struct list_head hash_entry;
> +	struct rb_node rb;
> +
> +	struct event_key key;
> +
> +	struct kvm_event_stats total;
> +
> +	#define DEFAULT_VCPU_NUM 8
> +	int max_vcpu;
> +	struct kvm_event_stats *vcpu;
> +};
> +
> +typedef int (*key_cmp_fun)(struct kvm_event*, struct kvm_event*, int);
> +
> +struct kvm_event_key {
> +	const char *name;
> +	key_cmp_fun key;
> +};
> +
> +struct perf_kvm_stat;
> +
> +struct kvm_events_ops {
> +	bool (*is_begin_event)(struct perf_evsel *evsel,
> +			       struct perf_sample *sample,
> +			       struct event_key *key);
> +	bool (*is_end_event)(struct perf_evsel *evsel,
> +			     struct perf_sample *sample, struct event_key *key);
> +	void (*decode_key)(struct perf_kvm_stat *kvm, struct event_key *key,
> +			   char *decode);
> +	const char *name;
> +};
> +
> +struct exit_reasons_table {
> +	unsigned long exit_code;
> +	const char *reason;
> +};
> +
> +#define EVENTS_BITS		12
> +#define EVENTS_CACHE_SIZE	(1UL << EVENTS_BITS)
> +
> +struct perf_kvm_stat {
> +	struct perf_tool    tool;
> +	struct record_opts  opts;
> +	struct perf_evlist  *evlist;
> +	struct perf_session *session;
> +
> +	const char *file_name;
> +	const char *report_event;
> +	const char *sort_key;
> +	int trace_vcpu;
> +
> +	struct exit_reasons_table *exit_reasons;
> +	const char *exit_reasons_isa;
> +
> +	struct kvm_events_ops *events_ops;
> +	key_cmp_fun compare;
> +	struct list_head kvm_events_cache[EVENTS_CACHE_SIZE];
> +
> +	u64 total_time;
> +	u64 total_count;
> +	u64 lost_events;
> +	u64 duration;
> +
> +	const char *pid_str;
> +	struct intlist *pid_list;
> +
> +	struct rb_root result;
> +
> +	int timerfd;
> +	unsigned int display_time;
> +	bool live;
> +};
> +
> +struct kvm_reg_events_ops {
> +	const char *name;
> +	struct kvm_events_ops *ops;
> +};
> +
> +void exit_event_get_key(struct perf_evsel *evsel,
> +			struct perf_sample *sample,
> +			struct event_key *key);
> +bool exit_event_begin(struct perf_evsel *evsel,
> +		      struct perf_sample *sample,
> +		      struct event_key *key);
> +bool exit_event_end(struct perf_evsel *evsel,
> +		    struct perf_sample *sample,
> +		    struct event_key *key);
> +void exit_event_decode_key(struct perf_kvm_stat *kvm,
> +			   struct event_key *key,
> +			   char *decode);
> +
> +bool kvm_exit_event(struct perf_evsel *evsel);
> +bool kvm_entry_event(struct perf_evsel *evsel);
> +
> +#define define_exit_reasons_table(name, symbols)	\
> +	static struct exit_reasons_table name[] = {	\
> +		symbols, { -1, NULL }			\
> +	}
> +
> +/*
> + * arch specific callbacks and data structures
> + */
> +int cpu_isa_init(struct perf_kvm_stat *kvm, const char *cpuid);
> +
> +extern const char * const kvm_events_tp[];
> +extern struct kvm_reg_events_ops kvm_reg_events_ops[];
> +
> +#endif /* __PERF_KVM_STAT_H */
> 


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH 3/4] perf kvm: Add skip_event() for --duration option
  2014-07-03 14:29 ` [PATCH 3/4] perf kvm: Add skip_event() for --duration option Alexander Yarygin
@ 2014-07-07 14:10   ` Christian Borntraeger
  2014-07-09 13:45   ` David Ahern
  2014-07-18  4:22   ` [tip:perf/core] " tip-bot for Alexander Yarygin
  2 siblings, 0 replies; 23+ messages in thread
From: Christian Borntraeger @ 2014-07-07 14:10 UTC (permalink / raw)
  To: Alexander Yarygin, Jiri Olsa
  Cc: David Ahern, Peter Zijlstra, Paul Mackerras, Ingo Molnar,
	Arnaldo Carvalho de Melo, Cornelia Huck, linux-kernel,
	Paolo Bonzini

On 03/07/14 16:29, Alexander Yarygin wrote:
> Current code skips output of the x86 specific HLT event in order to
> avoid flooding the output with enabled --duration option. The events to
> be skipped should be architecture dependent, though.
> 
> Let's add an architecture specific array of events to be skipped and
> introduce a skip_event() function checking against that array.
> 
> Signed-off-by: Alexander Yarygin <yarygin@linux.vnet.ibm.com>
> Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>

Reviewed-by: Christian Borntraeger <borntraeger@de.ibm.com>

Would be good if Paolo and David could ack the KVM/perf parts.
Then this should also go into next merge window.

> ---
>  tools/perf/arch/x86/util/kvm-stat.c |    5 +++++
>  tools/perf/builtin-kvm.c            |   13 ++++++++++++-
>  tools/perf/util/kvm-stat.h          |    1 +
>  3 files changed, 18 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/perf/arch/x86/util/kvm-stat.c b/tools/perf/arch/x86/util/kvm-stat.c
> index 2f8d2c1..14e4e66 100644
> --- a/tools/perf/arch/x86/util/kvm-stat.c
> +++ b/tools/perf/arch/x86/util/kvm-stat.c
> @@ -136,6 +136,11 @@ struct kvm_reg_events_ops kvm_reg_events_ops[] = {
>  	{ NULL, NULL },
>  };
> 
> +const char * const kvm_skip_events[] = {
> +	"HLT",
> +	NULL,
> +};
> +
>  int cpu_isa_init(struct perf_kvm_stat *kvm, const char *cpuid)
>  {
>  	if (strstr(cpuid, "Intel")) {
> diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
> index 75ee8c1..fc2d63d 100644
> --- a/tools/perf/builtin-kvm.c
> +++ b/tools/perf/builtin-kvm.c
> @@ -261,6 +261,17 @@ static bool update_kvm_event(struct kvm_event *event, int vcpu_id,
>  	return true;
>  }
> 
> +static bool skip_event(const char *event)
> +{
> +	const char * const *skip_events;
> +
> +	for (skip_events = kvm_skip_events; *skip_events; skip_events++)
> +		if (!strcmp(event, *skip_events))
> +			return true;
> +
> +	return false;
> +}
> +
>  static bool handle_end_event(struct perf_kvm_stat *kvm,
>  			     struct vcpu_event_record *vcpu_record,
>  			     struct event_key *key,
> @@ -312,7 +323,7 @@ static bool handle_end_event(struct perf_kvm_stat *kvm,
>  		char decode[DECODE_STR_LEN];
> 
>  		kvm->events_ops->decode_key(kvm, &event->key, decode);
> -		if (strcmp(decode, "HLT")) {
> +		if (!skip_event(decode)) {
>  			pr_info("%" PRIu64 " VM %d, vcpu %d: %s event took %" PRIu64 "usec\n",
>  				 sample->time, sample->pid, vcpu_record->vcpu_id,
>  				 decode, time_diff/1000);
> diff --git a/tools/perf/util/kvm-stat.h b/tools/perf/util/kvm-stat.h
> index d0d9fb1..ba937ca 100644
> --- a/tools/perf/util/kvm-stat.h
> +++ b/tools/perf/util/kvm-stat.h
> @@ -126,5 +126,6 @@ int cpu_isa_init(struct perf_kvm_stat *kvm, const char *cpuid);
> 
>  extern const char * const kvm_events_tp[];
>  extern struct kvm_reg_events_ops kvm_reg_events_ops[];
> +extern const char * const kvm_skip_events[];
> 
>  #endif /* __PERF_KVM_STAT_H */
> 


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH 4/4] perf kvm: Add stat support on s390
  2014-07-03 14:29 ` [PATCH 4/4] perf kvm: Add stat support on s390 Alexander Yarygin
@ 2014-07-07 14:11   ` Christian Borntraeger
  2014-07-09 13:45   ` David Ahern
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 23+ messages in thread
From: Christian Borntraeger @ 2014-07-07 14:11 UTC (permalink / raw)
  To: Alexander Yarygin, Jiri Olsa
  Cc: David Ahern, Peter Zijlstra, Paul Mackerras, Ingo Molnar,
	Arnaldo Carvalho de Melo, Cornelia Huck, linux-kernel

On 03/07/14 16:29, Alexander Yarygin wrote:
> On s390, the vmexit event has a tree-like structure: between
> exit_event_begin and exit_event_end several other events may happen
> and with each of them refining the previous ones.
> 
> This patch adds a decoder for such events to the generic code
> and also the files <asm/kvm_perf.h> and kvm-stat.c for s390.
> 
> Commands 'perf kvm stat record', 'report' and 'live' are supported.
> 
> Signed-off-by: Alexander Yarygin <yarygin@linux.vnet.ibm.com>

Acked-by: Christian Borntraeger <borntraeger@de.ibm.com>
Would be good if Paolo and David could ack the KVM/perf parts.
Then this should also go into next merge window.

> ---
>  arch/s390/include/uapi/asm/Kbuild     |    1 +
>  arch/s390/include/uapi/asm/kvm_perf.h |   25 ++++++++
>  tools/perf/Documentation/perf-kvm.txt |   10 ++--
>  tools/perf/MANIFEST                   |    2 +
>  tools/perf/arch/s390/Makefile         |    2 +
>  tools/perf/arch/s390/util/kvm-stat.c  |  105 +++++++++++++++++++++++++++++++++
>  tools/perf/builtin-kvm.c              |   52 ++++++++++++++--
>  tools/perf/util/kvm-stat.h            |    9 +++
>  8 files changed, 198 insertions(+), 8 deletions(-)
>  create mode 100644 arch/s390/include/uapi/asm/kvm_perf.h
>  create mode 100644 tools/perf/arch/s390/util/kvm-stat.c
> 
> diff --git a/arch/s390/include/uapi/asm/Kbuild b/arch/s390/include/uapi/asm/Kbuild
> index 6a9a9eb..0e2b54d 100644
> --- a/arch/s390/include/uapi/asm/Kbuild
> +++ b/arch/s390/include/uapi/asm/Kbuild
> @@ -16,6 +16,7 @@ header-y += ioctls.h
>  header-y += ipcbuf.h
>  header-y += kvm.h
>  header-y += kvm_para.h
> +header-y += kvm_perf.h
>  header-y += kvm_virtio.h
>  header-y += mman.h
>  header-y += monwriter.h
> diff --git a/arch/s390/include/uapi/asm/kvm_perf.h b/arch/s390/include/uapi/asm/kvm_perf.h
> new file mode 100644
> index 0000000..3972827
> --- /dev/null
> +++ b/arch/s390/include/uapi/asm/kvm_perf.h
> @@ -0,0 +1,25 @@
> +/*
> + * Definitions for perf-kvm on s390
> + *
> + * Copyright 2014 IBM Corp.
> + * Author(s): Alexander Yarygin <yarygin@linux.vnet.ibm.com>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License (version 2 only)
> + * as published by the Free Software Foundation.
> + */
> +
> +#ifndef __LINUX_KVM_PERF_S390_H
> +#define __LINUX_KVM_PERF_S390_H
> +
> +#include <asm/sie.h>
> +
> +#define DECODE_STR_LEN 40
> +
> +#define VCPU_ID "id"
> +
> +#define KVM_ENTRY_TRACE "kvm:kvm_s390_sie_enter"
> +#define KVM_EXIT_TRACE "kvm:kvm_s390_sie_exit"
> +#define KVM_EXIT_REASON "icptcode"
> +
> +#endif
> diff --git a/tools/perf/Documentation/perf-kvm.txt b/tools/perf/Documentation/perf-kvm.txt
> index 52276a6..abf2925 100644
> --- a/tools/perf/Documentation/perf-kvm.txt
> +++ b/tools/perf/Documentation/perf-kvm.txt
> @@ -103,8 +103,8 @@ STAT REPORT OPTIONS
>         analyze events which occures on this vcpu. (default: all vcpus)
> 
>  --event=<value>::
> -       event to be analyzed. Possible values: vmexit, mmio, ioport.
> -       (default: vmexit)
> +       event to be analyzed. Possible values: vmexit, mmio (x86 only),
> +       ioport (x86 only). (default: vmexit)
>  -k::
>  --key=<value>::
>         Sorting key. Possible values: sample (default, sort by samples
> @@ -138,7 +138,8 @@ STAT LIVE OPTIONS
> 
> 
>  --event=<value>::
> -       event to be analyzed. Possible values: vmexit, mmio, ioport.
> +       event to be analyzed. Possible values: vmexit,
> +       mmio (x86 only), ioport (x86 only).
>         (default: vmexit)
> 
>  -k::
> @@ -147,7 +148,8 @@ STAT LIVE OPTIONS
>         number), time (sort by average time).
> 
>  --duration=<value>::
> -       Show events other than HLT that take longer than duration usecs.
> +       Show events other than HLT (x86 only) or Wait state (s390 only)
> +       that take longer than duration usecs.
> 
>  SEE ALSO
>  --------
> diff --git a/tools/perf/MANIFEST b/tools/perf/MANIFEST
> index 02b485d..344c4d3 100644
> --- a/tools/perf/MANIFEST
> +++ b/tools/perf/MANIFEST
> @@ -38,3 +38,5 @@ arch/x86/include/uapi/asm/svm.h
>  arch/x86/include/uapi/asm/vmx.h
>  arch/x86/include/uapi/asm/kvm.h
>  arch/x86/include/uapi/asm/kvm_perf.h
> +arch/s390/include/uapi/asm/sie.h
> +arch/s390/include/uapi/asm/kvm_perf.h
> diff --git a/tools/perf/arch/s390/Makefile b/tools/perf/arch/s390/Makefile
> index 744e629..798ac73 100644
> --- a/tools/perf/arch/s390/Makefile
> +++ b/tools/perf/arch/s390/Makefile
> @@ -3,3 +3,5 @@ PERF_HAVE_DWARF_REGS := 1
>  LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/dwarf-regs.o
>  endif
>  LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/header.o
> +HAVE_KVM_STAT_SUPPORT := 1
> +LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/kvm-stat.o
> diff --git a/tools/perf/arch/s390/util/kvm-stat.c b/tools/perf/arch/s390/util/kvm-stat.c
> new file mode 100644
> index 0000000..a5dbc07
> --- /dev/null
> +++ b/tools/perf/arch/s390/util/kvm-stat.c
> @@ -0,0 +1,105 @@
> +/*
> + * Arch specific functions for perf kvm stat.
> + *
> + * Copyright 2014 IBM Corp.
> + * Author(s): Alexander Yarygin <yarygin@linux.vnet.ibm.com>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License (version 2 only)
> + * as published by the Free Software Foundation.
> + */
> +
> +#include "../../util/kvm-stat.h"
> +#include <asm/kvm_perf.h>
> +
> +define_exit_reasons_table(sie_exit_reasons, sie_intercept_code);
> +define_exit_reasons_table(sie_icpt_insn_codes, icpt_insn_codes);
> +define_exit_reasons_table(sie_sigp_order_codes, sigp_order_codes);
> +define_exit_reasons_table(sie_diagnose_codes, diagnose_codes);
> +define_exit_reasons_table(sie_icpt_prog_codes, icpt_prog_codes);
> +
> +static void event_icpt_insn_get_key(struct perf_evsel *evsel,
> +				    struct perf_sample *sample,
> +				    struct event_key *key)
> +{
> +	unsigned long insn;
> +
> +	insn = perf_evsel__intval(evsel, sample, "instruction");
> +	key->key = icpt_insn_decoder(insn);
> +	key->exit_reasons = sie_icpt_insn_codes;
> +}
> +
> +static void event_sigp_get_key(struct perf_evsel *evsel,
> +			       struct perf_sample *sample,
> +			       struct event_key *key)
> +{
> +	key->key = perf_evsel__intval(evsel, sample, "order_code");
> +	key->exit_reasons = sie_sigp_order_codes;
> +}
> +
> +static void event_diag_get_key(struct perf_evsel *evsel,
> +			       struct perf_sample *sample,
> +			       struct event_key *key)
> +{
> +	key->key = perf_evsel__intval(evsel, sample, "code");
> +	key->exit_reasons = sie_diagnose_codes;
> +}
> +
> +static void event_icpt_prog_get_key(struct perf_evsel *evsel,
> +				    struct perf_sample *sample,
> +				    struct event_key *key)
> +{
> +	key->key = perf_evsel__intval(evsel, sample, "code");
> +	key->exit_reasons = sie_icpt_prog_codes;
> +}
> +
> +static struct child_event_ops child_events[] = {
> +	{ .name = "kvm:kvm_s390_intercept_instruction",
> +	  .get_key = event_icpt_insn_get_key },
> +	{ .name = "kvm:kvm_s390_handle_sigp",
> +	  .get_key = event_sigp_get_key },
> +	{ .name = "kvm:kvm_s390_handle_diag",
> +	  .get_key = event_diag_get_key },
> +	{ .name = "kvm:kvm_s390_intercept_prog",
> +	  .get_key = event_icpt_prog_get_key },
> +	{ NULL, NULL },
> +};
> +
> +static struct kvm_events_ops exit_events = {
> +	.is_begin_event = exit_event_begin,
> +	.is_end_event = exit_event_end,
> +	.child_ops = child_events,
> +	.decode_key = exit_event_decode_key,
> +	.name = "VM-EXIT"
> +};
> +
> +const char * const kvm_events_tp[] = {
> +	"kvm:kvm_s390_sie_enter",
> +	"kvm:kvm_s390_sie_exit",
> +	"kvm:kvm_s390_intercept_instruction",
> +	"kvm:kvm_s390_handle_sigp",
> +	"kvm:kvm_s390_handle_diag",
> +	"kvm:kvm_s390_intercept_prog",
> +	NULL,
> +};
> +
> +struct kvm_reg_events_ops kvm_reg_events_ops[] = {
> +	{ .name = "vmexit", .ops = &exit_events },
> +	{ NULL, NULL },
> +};
> +
> +const char * const kvm_skip_events[] = {
> +	"Wait state",
> +	NULL,
> +};
> +
> +int cpu_isa_init(struct perf_kvm_stat *kvm, const char *cpuid)
> +{
> +	if (strstr(cpuid, "IBM/S390")) {
> +		kvm->exit_reasons = sie_exit_reasons;
> +		kvm->exit_reasons_isa = "SIE";
> +	} else
> +		return -ENOTSUP;
> +
> +	return 0;
> +}
> diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
> index fc2d63d..43367eb 100644
> --- a/tools/perf/builtin-kvm.c
> +++ b/tools/perf/builtin-kvm.c
> @@ -88,7 +88,7 @@ void exit_event_decode_key(struct perf_kvm_stat *kvm,
>  			   struct event_key *key,
>  			   char *decode)
>  {
> -	const char *exit_reason = get_exit_reason(kvm, kvm->exit_reasons,
> +	const char *exit_reason = get_exit_reason(kvm, key->exit_reasons,
>  						  key->key);
> 
>  	scnprintf(decode, DECODE_STR_LEN, "%s", exit_reason);
> @@ -261,6 +261,43 @@ static bool update_kvm_event(struct kvm_event *event, int vcpu_id,
>  	return true;
>  }
> 
> +static bool is_child_event(struct perf_kvm_stat *kvm,
> +			   struct perf_evsel *evsel,
> +			   struct perf_sample *sample,
> +			   struct event_key *key)
> +{
> +	struct child_event_ops *child_ops;
> +
> +	child_ops = kvm->events_ops->child_ops;
> +
> +	if (!child_ops)
> +		return false;
> +
> +	for (; child_ops->name; child_ops++) {
> +		if (!strcmp(evsel->name, child_ops->name)) {
> +			child_ops->get_key(evsel, sample, key);
> +			return true;
> +		}
> +	}
> +
> +	return false;
> +}
> +
> +static bool handle_child_event(struct perf_kvm_stat *kvm,
> +			       struct vcpu_event_record *vcpu_record,
> +			       struct event_key *key,
> +			       struct perf_sample *sample __maybe_unused)
> +{
> +	struct kvm_event *event = NULL;
> +
> +	if (key->key != INVALID_KEY)
> +		event = find_create_kvm_event(kvm, key);
> +
> +	vcpu_record->last_event = event;
> +
> +	return true;
> +}
> +
>  static bool skip_event(const char *event)
>  {
>  	const char * const *skip_events;
> @@ -361,7 +398,8 @@ static bool handle_kvm_event(struct perf_kvm_stat *kvm,
>  			     struct perf_sample *sample)
>  {
>  	struct vcpu_event_record *vcpu_record;
> -	struct event_key key = {.key = INVALID_KEY};
> +	struct event_key key = { .key = INVALID_KEY,
> +				 .exit_reasons = kvm->exit_reasons };
> 
>  	vcpu_record = per_vcpu_record(thread, evsel, sample);
>  	if (!vcpu_record)
> @@ -375,6 +413,9 @@ static bool handle_kvm_event(struct perf_kvm_stat *kvm,
>  	if (kvm->events_ops->is_begin_event(evsel, sample, &key))
>  		return handle_begin_event(kvm, vcpu_record, &key, sample->time);
> 
> +	if (is_child_event(kvm, evsel, sample, &key))
> +		return handle_child_event(kvm, vcpu_record, &key, sample);
> +
>  	if (kvm->events_ops->is_end_event(evsel, sample, &key))
>  		return handle_end_event(kvm, vcpu_record, &key, sample);
> 
> @@ -1143,7 +1184,8 @@ kvm_events_report(struct perf_kvm_stat *kvm, int argc, const char **argv)
>  {
>  	const struct option kvm_events_report_options[] = {
>  		OPT_STRING(0, "event", &kvm->report_event, "report event",
> -			    "event for reporting: vmexit, mmio, ioport"),
> +			   "event for reporting: vmexit, "
> +			   "mmio (x86 only), ioport (x86 only)"),
>  		OPT_INTEGER(0, "vcpu", &kvm->trace_vcpu,
>  			    "vcpu id to report"),
>  		OPT_STRING('k', "key", &kvm->sort_key, "sort-key",
> @@ -1249,7 +1291,9 @@ static int kvm_events_live(struct perf_kvm_stat *kvm,
>  			"key for sorting: sample(sort by samples number)"
>  			" time (sort by avg time)"),
>  		OPT_U64(0, "duration", &kvm->duration,
> -		    "show events other than HALT that take longer than duration usecs"),
> +			"show events other than"
> +			" HLT (x86 only) or Wait state (s390 only)"
> +			" that take longer than duration usecs"),
>  		OPT_END()
>  	};
>  	const char * const live_usage[] = {
> diff --git a/tools/perf/util/kvm-stat.h b/tools/perf/util/kvm-stat.h
> index ba937ca..0b5a8cd 100644
> --- a/tools/perf/util/kvm-stat.h
> +++ b/tools/perf/util/kvm-stat.h
> @@ -12,6 +12,7 @@ struct event_key {
>  	#define INVALID_KEY     (~0ULL)
>  	u64 key;
>  	int info;
> +	struct exit_reasons_table *exit_reasons;
>  };
> 
>  struct kvm_event_stats {
> @@ -41,12 +42,20 @@ struct kvm_event_key {
> 
>  struct perf_kvm_stat;
> 
> +struct child_event_ops {
> +	void (*get_key)(struct perf_evsel *evsel,
> +			struct perf_sample *sample,
> +			struct event_key *key);
> +	const char *name;
> +};
> +
>  struct kvm_events_ops {
>  	bool (*is_begin_event)(struct perf_evsel *evsel,
>  			       struct perf_sample *sample,
>  			       struct event_key *key);
>  	bool (*is_end_event)(struct perf_evsel *evsel,
>  			     struct perf_sample *sample, struct event_key *key);
> +	struct child_event_ops *child_ops;
>  	void (*decode_key)(struct perf_kvm_stat *kvm, struct event_key *key,
>  			   char *decode);
>  	const char *name;
> 


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH 1/4] perf kvm: Use defines of kvm events
  2014-07-07 14:06   ` Christian Borntraeger
@ 2014-07-07 15:42     ` David Ahern
  0 siblings, 0 replies; 23+ messages in thread
From: David Ahern @ 2014-07-07 15:42 UTC (permalink / raw)
  To: Christian Borntraeger, Alexander Yarygin, Jiri Olsa
  Cc: Peter Zijlstra, Paul Mackerras, Ingo Molnar,
	Arnaldo Carvalho de Melo, Cornelia Huck, linux-kernel,
	Paolo Bonzini

On 7/7/14, 8:06 AM, Christian Borntraeger wrote:
> On 03/07/14 16:29, Alexander Yarygin wrote:
>> Currently perf-kvm uses string literals for kvm event names,
>> but it works only for x86, because other architectures may have
>> other names for those events.
>>
>> To reduce dependence on architecture, we add <asm/kvm_perf.h> file with
>> defines for:
>> - kvm_entry and kvm_exit events,
>> - exit reason field name in kvm_exit event,
>> - length of exit reasons strings,
>> - vcpu_id field name in kvm trace events,
>>
>> and replace literals in perf-kvm.
>>
>> Signed-off-by: Alexander Yarygin <yarygin@linux.vnet.ibm.com>
>> Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
>
> Acked-by: Christian Borntraeger <borntraeger@de.ibm.com>
> Would be good if Paolo and David could ack the KVM/perf parts. Then this should also go into next merge window.

I want to try out the patches on x86 and verify compiles on ppc; 
hopefully by end of day tomorrow.

David


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH 1/4] perf kvm: Use defines of kvm events
  2014-07-03 14:29 ` [PATCH 1/4] perf kvm: Use defines of kvm events Alexander Yarygin
  2014-07-07 14:06   ` Christian Borntraeger
@ 2014-07-09 13:45   ` David Ahern
  2014-07-18  4:21   ` [tip:perf/core] " tip-bot for Alexander Yarygin
  2 siblings, 0 replies; 23+ messages in thread
From: David Ahern @ 2014-07-09 13:45 UTC (permalink / raw)
  To: Alexander Yarygin, Jiri Olsa
  Cc: Peter Zijlstra, Paul Mackerras, Ingo Molnar,
	Arnaldo Carvalho de Melo, Christian Borntraeger, Cornelia Huck,
	linux-kernel

On 7/3/14, 8:29 AM, Alexander Yarygin wrote:
> Currently perf-kvm uses string literals for kvm event names,
> but it works only for x86, because other architectures may have
> other names for those events.
>
> To reduce dependence on architecture, we add <asm/kvm_perf.h> file with
> defines for:
> - kvm_entry and kvm_exit events,
> - exit reason field name in kvm_exit event,
> - length of exit reasons strings,
> - vcpu_id field name in kvm trace events,
>
> and replace literals in perf-kvm.
>
> Signed-off-by: Alexander Yarygin <yarygin@linux.vnet.ibm.com>
> Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>

For perf bits, Reviewed-by David Ahern <dsahern@gmail.com>

Compiled and Tested on x86


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH 2/4] perf kvm: Move arch specific code into arch/
  2014-07-03 14:29 ` [PATCH 2/4] perf kvm: Move arch specific code into arch/ Alexander Yarygin
  2014-07-07 14:09   ` Christian Borntraeger
@ 2014-07-09 13:45   ` David Ahern
  2014-07-18  4:21   ` [tip:perf/core] " tip-bot for Alexander Yarygin
  2 siblings, 0 replies; 23+ messages in thread
From: David Ahern @ 2014-07-09 13:45 UTC (permalink / raw)
  To: Alexander Yarygin, Jiri Olsa
  Cc: Peter Zijlstra, Paul Mackerras, Ingo Molnar,
	Arnaldo Carvalho de Melo, Christian Borntraeger, Cornelia Huck,
	linux-kernel

On 7/3/14, 8:29 AM, Alexander Yarygin wrote:
> Parts of a 'perf kvm stat' code make sense only for x86.
> Let's move this code into the arch/x86/kvm-stat.c file and add
> util/kvm-stat.h for generic structure definitions.
>
> Add a global array 'kvm_reg_events_ops' for accessing the
> arch-specific 'kvm_events_ops' from generic code.
>
> Since the several global arrays (i.e. 'kvm_events_tp') have been moved
> to arch/*, we can not know their sizes and use them directly in
> builtin-kvm.c. This patch fixes that problem by adding trimming
> NULL element to each array and changing the behavior of their handlers
> in generic code.
>
> Signed-off-by: Alexander Yarygin<yarygin@linux.vnet.ibm.com>
> Reviewed-by: Cornelia Huck<cornelia.huck@de.ibm.com>

Reviewed-by David Ahern <dsahern@gmail.com>

Compiled and Tested on x86


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH 3/4] perf kvm: Add skip_event() for --duration option
  2014-07-03 14:29 ` [PATCH 3/4] perf kvm: Add skip_event() for --duration option Alexander Yarygin
  2014-07-07 14:10   ` Christian Borntraeger
@ 2014-07-09 13:45   ` David Ahern
  2014-07-18  4:22   ` [tip:perf/core] " tip-bot for Alexander Yarygin
  2 siblings, 0 replies; 23+ messages in thread
From: David Ahern @ 2014-07-09 13:45 UTC (permalink / raw)
  To: Alexander Yarygin, Jiri Olsa
  Cc: Peter Zijlstra, Paul Mackerras, Ingo Molnar,
	Arnaldo Carvalho de Melo, Christian Borntraeger, Cornelia Huck,
	linux-kernel

On 7/3/14, 8:29 AM, Alexander Yarygin wrote:
> Current code skips output of the x86 specific HLT event in order to
> avoid flooding the output with enabled --duration option. The events to
> be skipped should be architecture dependent, though.
>
> Let's add an architecture specific array of events to be skipped and
> introduce a skip_event() function checking against that array.
>
> Signed-off-by: Alexander Yarygin <yarygin@linux.vnet.ibm.com>
> Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>

Reviewed-by David Ahern <dsahern@gmail.com>

Compiled and Tested on x86


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH 4/4] perf kvm: Add stat support on s390
  2014-07-03 14:29 ` [PATCH 4/4] perf kvm: Add stat support on s390 Alexander Yarygin
  2014-07-07 14:11   ` Christian Borntraeger
@ 2014-07-09 13:45   ` David Ahern
  2014-07-10 10:50   ` Alexander Yarygin
  2014-07-18  4:22   ` [tip:perf/core] " tip-bot for Alexander Yarygin
  3 siblings, 0 replies; 23+ messages in thread
From: David Ahern @ 2014-07-09 13:45 UTC (permalink / raw)
  To: Alexander Yarygin, Jiri Olsa
  Cc: Peter Zijlstra, Paul Mackerras, Ingo Molnar,
	Arnaldo Carvalho de Melo, Christian Borntraeger, Cornelia Huck,
	linux-kernel

On 7/3/14, 8:29 AM, Alexander Yarygin wrote:
> On s390, the vmexit event has a tree-like structure: between
> exit_event_begin and exit_event_end several other events may happen
> and with each of them refining the previous ones.
>
> This patch adds a decoder for such events to the generic code
> and also the files <asm/kvm_perf.h> and kvm-stat.c for s390.
>
> Commands 'perf kvm stat record', 'report' and 'live' are supported.
>
> Signed-off-by: Alexander Yarygin<yarygin@linux.vnet.ibm.com>

Reviewed-by David Ahern <dsahern@gmail.com>

Compiled and Tested on x86


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH/RFC 0/4] perf kvm: add stat support for s390
  2014-07-03 14:29 [PATCH/RFC 0/4] perf kvm: add stat support for s390 Alexander Yarygin
                   ` (4 preceding siblings ...)
  2014-07-03 15:07 ` [PATCH/RFC 0/4] perf kvm: add stat support for s390 Christian Borntraeger
@ 2014-07-09 16:47 ` David Ahern
  2014-07-09 18:58   ` Arnaldo Carvalho de Melo
  5 siblings, 1 reply; 23+ messages in thread
From: David Ahern @ 2014-07-09 16:47 UTC (permalink / raw)
  To: Alexander Yarygin, Jiri Olsa
  Cc: Peter Zijlstra, Paul Mackerras, Ingo Molnar,
	Arnaldo Carvalho de Melo, Christian Borntraeger, Cornelia Huck,
	linux-kernel

fixed Arnaldo's address so this patch set gets on his radar.


On 7/3/14, 8:29 AM, Alexander Yarygin wrote:
> Currently, a lot of code in buildin-kvm.c are x86 specific.
> In accordance with the proposal of David Ahern, we moved the code under
> #ifdefs from buildin-kvm.c into tools/perf/arch/*/kvm-stat.c. Architecture
> specific constants were added in arch/*/include/uapi/perf-kvm.h. Also,
> generic perf kvm stat structures were moved into the new file util/kvm-stat.h.
>
> So, patches 1-3 reduce architecture dependency of buildin-kvm.c.
> Patch 4 implements s390 specific functions. Since some events on s390
> can have tree-like structure, the patch also adds functions to handle
> these events in generic code.
>
> The patch set based on linux-3.16-rc1 including patches in
> "perf kvm: refactoring and small changes".
>
> Link to the "perf kvm: refactoring and small changes" patch series:
> https://lkml.org/lkml/2014/7/3/461
> Link to the previous thread: https://lkml.org/lkml/2014/4/25/331




^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH/RFC 0/4] perf kvm: add stat support for s390
  2014-07-09 16:47 ` David Ahern
@ 2014-07-09 18:58   ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 23+ messages in thread
From: Arnaldo Carvalho de Melo @ 2014-07-09 18:58 UTC (permalink / raw)
  To: David Ahern
  Cc: Alexander Yarygin, Jiri Olsa, Peter Zijlstra, Paul Mackerras,
	Ingo Molnar, Christian Borntraeger, Cornelia Huck, linux-kernel

Em Wed, Jul 09, 2014 at 10:47:11AM -0600, David Ahern escreveu:
> fixed Arnaldo's address so this patch set gets on his radar.

Thanks, applied to my perf/core branch, will be in the next pull req to
Ingo.

- Arnaldo
 
> 
> On 7/3/14, 8:29 AM, Alexander Yarygin wrote:
> >Currently, a lot of code in buildin-kvm.c are x86 specific.
> >In accordance with the proposal of David Ahern, we moved the code under
> >#ifdefs from buildin-kvm.c into tools/perf/arch/*/kvm-stat.c. Architecture
> >specific constants were added in arch/*/include/uapi/perf-kvm.h. Also,
> >generic perf kvm stat structures were moved into the new file util/kvm-stat.h.
> >
> >So, patches 1-3 reduce architecture dependency of buildin-kvm.c.
> >Patch 4 implements s390 specific functions. Since some events on s390
> >can have tree-like structure, the patch also adds functions to handle
> >these events in generic code.
> >
> >The patch set based on linux-3.16-rc1 including patches in
> >"perf kvm: refactoring and small changes".
> >
> >Link to the "perf kvm: refactoring and small changes" patch series:
> >https://lkml.org/lkml/2014/7/3/461
> >Link to the previous thread: https://lkml.org/lkml/2014/4/25/331
> 
> 
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH 4/4] perf kvm: Add stat support on s390
  2014-07-03 14:29 ` [PATCH 4/4] perf kvm: Add stat support on s390 Alexander Yarygin
  2014-07-07 14:11   ` Christian Borntraeger
  2014-07-09 13:45   ` David Ahern
@ 2014-07-10 10:50   ` Alexander Yarygin
  2014-07-10 13:40     ` Arnaldo Carvalho de Melo
  2014-07-18  4:22   ` [tip:perf/core] " tip-bot for Alexander Yarygin
  3 siblings, 1 reply; 23+ messages in thread
From: Alexander Yarygin @ 2014-07-10 10:50 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, David Ahern
  Cc: Jiri Olsa, Peter Zijlstra, Paul Mackerras, Ingo Molnar,
	Alexander Yarygin, Christian Borntraeger, Cornelia Huck,
	linux-kernel

At Thu,  3 Jul 2014 18:29:07 +0400,
Alexander Yarygin wrote:
> 

...

> diff --git a/tools/perf/Documentation/perf-kvm.txt b/tools/perf/Documentation/perf-kvm.txt
> index 52276a6..abf2925 100644
> --- a/tools/perf/Documentation/perf-kvm.txt
> +++ b/tools/perf/Documentation/perf-kvm.txt
> @@ -103,8 +103,8 @@ STAT REPORT OPTIONS
>         analyze events which occures on this vcpu. (default: all vcpus)
> 
>  --event=<value>::
> -       event to be analyzed. Possible values: vmexit, mmio, ioport.
> -       (default: vmexit)
> +       event to be analyzed. Possible values: vmexit, mmio (x86 only),
> +       ioport (x86 only). (default: vmexit)
>  -k::
>  --key=<value>::
>         Sorting key. Possible values: sample (default, sort by samples
> @@ -138,7 +138,8 @@ STAT LIVE OPTIONS
> 
> 
>  --event=<value>::
> -       event to be analyzed. Possible values: vmexit, mmio, ioport.
> +       event to be analyzed. Possible values: vmexit,
> +       mmio (x86 only), ioport (x86 only).
>         (default: vmexit)
> 
>  -k::
> @@ -147,7 +148,8 @@ STAT LIVE OPTIONS
>         number), time (sort by average time).
> 
>  --duration=<value>::
> -       Show events other than HLT that take longer than duration usecs.
> +       Show events other than HLT (x86 only) or Wait state (s390 only)
> +       that take longer than duration usecs.
> 
>  SEE ALSO
>  --------

fixup (mmio and ioport events are marked as x86 only):

--- a/tools/perf/Documentation/perf-kvm.txt
+++ b/tools/perf/Documentation/perf-kvm.txt
@@ -51,9 +51,9 @@ There are a couple of variants of perf kvm:
   'perf kvm stat <command>' to run a command and gather performance counter
   statistics.
   Especially, perf 'kvm stat record/report' generates a statistical analysis
-  of KVM events. Currently, vmexit, mmio and ioport events are supported.
-  'perf kvm stat record <command>' records kvm events and the events between
-  start and end <command>.
+  of KVM events. Currently, vmexit, mmio (x86 only) and ioport (x86 only)
+  events are supported. 'perf kvm stat record <command>' records kvm events
+  and the events between start and end <command>.
   And this command produces a file which contains tracing results of kvm
   events.

Arnaldo, could you please also merge this? Or should I resend the patch?

Thanks.


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH 4/4] perf kvm: Add stat support on s390
  2014-07-10 10:50   ` Alexander Yarygin
@ 2014-07-10 13:40     ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 23+ messages in thread
From: Arnaldo Carvalho de Melo @ 2014-07-10 13:40 UTC (permalink / raw)
  To: Alexander Yarygin
  Cc: David Ahern, Jiri Olsa, Peter Zijlstra, Paul Mackerras,
	Ingo Molnar, Christian Borntraeger, Cornelia Huck, linux-kernel

Em Thu, Jul 10, 2014 at 02:50:07PM +0400, Alexander Yarygin escreveu:
> Arnaldo, could you please also merge this? Or should I resend the patch?

Done, thanks.

- Arnaldo

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [tip:perf/core] perf kvm: Use defines of kvm events
  2014-07-03 14:29 ` [PATCH 1/4] perf kvm: Use defines of kvm events Alexander Yarygin
  2014-07-07 14:06   ` Christian Borntraeger
  2014-07-09 13:45   ` David Ahern
@ 2014-07-18  4:21   ` tip-bot for Alexander Yarygin
  2 siblings, 0 replies; 23+ messages in thread
From: tip-bot for Alexander Yarygin @ 2014-07-18  4:21 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: acme, linux-kernel, paulus, hpa, mingo, a.p.zijlstra,
	borntraeger, jolsa, cornelia.huck, yarygin, dsahern, tglx

Commit-ID:  44b3802122174ba499613bac3aab2e66e948ce1e
Gitweb:     http://git.kernel.org/tip/44b3802122174ba499613bac3aab2e66e948ce1e
Author:     Alexander Yarygin <yarygin@linux.vnet.ibm.com>
AuthorDate: Thu, 3 Jul 2014 18:29:04 +0400
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 16 Jul 2014 17:57:32 -0300

perf kvm: Use defines of kvm events

Currently perf-kvm uses string literals for kvm event names, but it
works only for x86, because other architectures may have other names for
those events.

To reduce dependence on architecture, we add <asm/kvm_perf.h> file with
defines for:

- kvm_entry and kvm_exit events,
- exit reason field name in kvm_exit event,
- length of exit reasons strings,
- vcpu_id field name in kvm trace events,

and replace literals in perf-kvm.

Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Reviewed-by David Ahern <dsahern@gmail.com>
Signed-off-by: Alexander Yarygin <yarygin@linux.vnet.ibm.com>
Acked-by: Christian Borntraeger <borntraeger@de.ibm.com>
Cc: Christian Borntraeger <borntraeger@de.ibm.com>
Cc: Cornelia Huck <cornelia.huck@de.ibm.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1404397747-20939-2-git-send-email-yarygin@linux.vnet.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 arch/x86/include/uapi/asm/Kbuild     |  1 +
 arch/x86/include/uapi/asm/kvm_perf.h | 16 ++++++++++++++++
 tools/perf/MANIFEST                  |  1 +
 tools/perf/builtin-kvm.c             | 34 ++++++++++++++++------------------
 4 files changed, 34 insertions(+), 18 deletions(-)

diff --git a/arch/x86/include/uapi/asm/Kbuild b/arch/x86/include/uapi/asm/Kbuild
index 09409c4..3dec769 100644
--- a/arch/x86/include/uapi/asm/Kbuild
+++ b/arch/x86/include/uapi/asm/Kbuild
@@ -22,6 +22,7 @@ header-y += ipcbuf.h
 header-y += ist.h
 header-y += kvm.h
 header-y += kvm_para.h
+header-y += kvm_perf.h
 header-y += ldt.h
 header-y += mce.h
 header-y += mman.h
diff --git a/arch/x86/include/uapi/asm/kvm_perf.h b/arch/x86/include/uapi/asm/kvm_perf.h
new file mode 100644
index 0000000..3bb964f
--- /dev/null
+++ b/arch/x86/include/uapi/asm/kvm_perf.h
@@ -0,0 +1,16 @@
+#ifndef _ASM_X86_KVM_PERF_H
+#define _ASM_X86_KVM_PERF_H
+
+#include <asm/svm.h>
+#include <asm/vmx.h>
+#include <asm/kvm.h>
+
+#define DECODE_STR_LEN 20
+
+#define VCPU_ID "vcpu_id"
+
+#define KVM_ENTRY_TRACE "kvm:kvm_entry"
+#define KVM_EXIT_TRACE "kvm:kvm_exit"
+#define KVM_EXIT_REASON "exit_reason"
+
+#endif /* _ASM_X86_KVM_PERF_H */
diff --git a/tools/perf/MANIFEST b/tools/perf/MANIFEST
index 45da209..02b485d 100644
--- a/tools/perf/MANIFEST
+++ b/tools/perf/MANIFEST
@@ -37,3 +37,4 @@ arch/x86/include/asm/kvm_host.h
 arch/x86/include/uapi/asm/svm.h
 arch/x86/include/uapi/asm/vmx.h
 arch/x86/include/uapi/asm/kvm.h
+arch/x86/include/uapi/asm/kvm_perf.h
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index 41dbeaf..6d73346 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -30,9 +30,7 @@
 #include <math.h>
 
 #ifdef HAVE_KVM_STAT_SUPPORT
-#include <asm/svm.h>
-#include <asm/vmx.h>
-#include <asm/kvm.h>
+#include <asm/kvm_perf.h>
 
 struct event_key {
 	#define INVALID_KEY     (~0ULL)
@@ -75,7 +73,7 @@ struct kvm_events_ops {
 	bool (*is_end_event)(struct perf_evsel *evsel,
 			     struct perf_sample *sample, struct event_key *key);
 	void (*decode_key)(struct perf_kvm_stat *kvm, struct event_key *key,
-			   char decode[20]);
+			   char *decode);
 	const char *name;
 };
 
@@ -126,12 +124,12 @@ static void exit_event_get_key(struct perf_evsel *evsel,
 			       struct event_key *key)
 {
 	key->info = 0;
-	key->key = perf_evsel__intval(evsel, sample, "exit_reason");
+	key->key = perf_evsel__intval(evsel, sample, KVM_EXIT_REASON);
 }
 
 static bool kvm_exit_event(struct perf_evsel *evsel)
 {
-	return !strcmp(evsel->name, "kvm:kvm_exit");
+	return !strcmp(evsel->name, KVM_EXIT_TRACE);
 }
 
 static bool exit_event_begin(struct perf_evsel *evsel,
@@ -147,7 +145,7 @@ static bool exit_event_begin(struct perf_evsel *evsel,
 
 static bool kvm_entry_event(struct perf_evsel *evsel)
 {
-	return !strcmp(evsel->name, "kvm:kvm_entry");
+	return !strcmp(evsel->name, KVM_ENTRY_TRACE);
 }
 
 static bool exit_event_end(struct perf_evsel *evsel,
@@ -182,12 +180,12 @@ static const char *get_exit_reason(struct perf_kvm_stat *kvm,
 
 static void exit_event_decode_key(struct perf_kvm_stat *kvm,
 				  struct event_key *key,
-				  char decode[20])
+				  char *decode)
 {
 	const char *exit_reason = get_exit_reason(kvm, kvm->exit_reasons,
 						  key->key);
 
-	scnprintf(decode, 20, "%s", exit_reason);
+	scnprintf(decode, DECODE_STR_LEN, "%s", exit_reason);
 }
 
 static struct kvm_events_ops exit_events = {
@@ -249,9 +247,9 @@ static bool mmio_event_end(struct perf_evsel *evsel, struct perf_sample *sample,
 
 static void mmio_event_decode_key(struct perf_kvm_stat *kvm __maybe_unused,
 				  struct event_key *key,
-				  char decode[20])
+				  char *decode)
 {
-	scnprintf(decode, 20, "%#lx:%s", (unsigned long)key->key,
+	scnprintf(decode, DECODE_STR_LEN, "%#lx:%s", (unsigned long)key->key,
 				key->info == KVM_TRACE_MMIO_WRITE ? "W" : "R");
 }
 
@@ -292,9 +290,9 @@ static bool ioport_event_end(struct perf_evsel *evsel,
 
 static void ioport_event_decode_key(struct perf_kvm_stat *kvm __maybe_unused,
 				    struct event_key *key,
-				    char decode[20])
+				    char *decode)
 {
-	scnprintf(decode, 20, "%#llx:%s", (unsigned long long)key->key,
+	scnprintf(decode, DECODE_STR_LEN, "%#llx:%s", (unsigned long long)key->key,
 				key->info ? "POUT" : "PIN");
 }
 
@@ -524,7 +522,7 @@ static bool handle_end_event(struct perf_kvm_stat *kvm,
 	time_diff = sample->time - time_begin;
 
 	if (kvm->duration && time_diff > kvm->duration) {
-		char decode[32];
+		char decode[DECODE_STR_LEN];
 
 		kvm->events_ops->decode_key(kvm, &event->key, decode);
 		if (strcmp(decode, "HLT")) {
@@ -552,7 +550,7 @@ struct vcpu_event_record *per_vcpu_record(struct thread *thread,
 			return NULL;
 		}
 
-		vcpu_record->vcpu_id = perf_evsel__intval(evsel, sample, "vcpu_id");
+		vcpu_record->vcpu_id = perf_evsel__intval(evsel, sample, VCPU_ID);
 		thread->priv = vcpu_record;
 	}
 
@@ -739,7 +737,7 @@ static void show_timeofday(void)
 
 static void print_result(struct perf_kvm_stat *kvm)
 {
-	char decode[20];
+	char decode[DECODE_STR_LEN];
 	struct kvm_event *event;
 	int vcpu = kvm->trace_vcpu;
 
@@ -750,7 +748,7 @@ static void print_result(struct perf_kvm_stat *kvm)
 
 	pr_info("\n\n");
 	print_vcpu_info(kvm);
-	pr_info("%20s ", kvm->events_ops->name);
+	pr_info("%*s ", DECODE_STR_LEN, kvm->events_ops->name);
 	pr_info("%10s ", "Samples");
 	pr_info("%9s ", "Samples%");
 
@@ -769,7 +767,7 @@ static void print_result(struct perf_kvm_stat *kvm)
 		min = get_event_min(event, vcpu);
 
 		kvm->events_ops->decode_key(kvm, &event->key, decode);
-		pr_info("%20s ", decode);
+		pr_info("%*s ", DECODE_STR_LEN, decode);
 		pr_info("%10llu ", (unsigned long long)ecount);
 		pr_info("%8.2f%% ", (double)ecount / kvm->total_count * 100);
 		pr_info("%8.2f%% ", (double)etime / kvm->total_time * 100);

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [tip:perf/core] perf kvm: Move arch specific code into arch/
  2014-07-03 14:29 ` [PATCH 2/4] perf kvm: Move arch specific code into arch/ Alexander Yarygin
  2014-07-07 14:09   ` Christian Borntraeger
  2014-07-09 13:45   ` David Ahern
@ 2014-07-18  4:21   ` tip-bot for Alexander Yarygin
  2 siblings, 0 replies; 23+ messages in thread
From: tip-bot for Alexander Yarygin @ 2014-07-18  4:21 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: acme, linux-kernel, paulus, hpa, mingo, a.p.zijlstra,
	borntraeger, jolsa, cornelia.huck, yarygin, dsahern, tglx

Commit-ID:  9daa81239e60c162153fb2a365b8492c9a9bf632
Gitweb:     http://git.kernel.org/tip/9daa81239e60c162153fb2a365b8492c9a9bf632
Author:     Alexander Yarygin <yarygin@linux.vnet.ibm.com>
AuthorDate: Thu, 3 Jul 2014 18:29:05 +0400
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 16 Jul 2014 17:57:32 -0300

perf kvm: Move arch specific code into arch/

Parts of a 'perf kvm stat' code make sense only for x86.

Let's move this code into the arch/x86/kvm-stat.c file and add
util/kvm-stat.h for generic structure definitions.

Add a global array 'kvm_reg_events_ops' for accessing the arch-specific
'kvm_events_ops' from generic code.

Since the several global arrays (i.e. 'kvm_events_tp') have been moved
to arch/*, we can not know their sizes and use them directly in
builtin-kvm.c. This patch fixes that problem by adding trimming NULL
element to each array and changing the behavior of their handlers in
generic code.

Reviewed-by: David Ahern <dsahern@gmail.com>
Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: Alexander Yarygin <yarygin@linux.vnet.ibm.com>
Acked-by: Christian Borntraeger <borntraeger@de.ibm.com>
Cc: Christian Borntraeger <borntraeger@de.ibm.com>
Cc: Cornelia Huck <cornelia.huck@de.ibm.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1404397747-20939-3-git-send-email-yarygin@linux.vnet.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/Makefile.perf            |   1 +
 tools/perf/arch/x86/Makefile        |   1 +
 tools/perf/arch/x86/util/kvm-stat.c | 151 ++++++++++++++++++
 tools/perf/builtin-kvm.c            | 297 +++++-------------------------------
 tools/perf/util/kvm-stat.h          | 130 ++++++++++++++++
 5 files changed, 317 insertions(+), 263 deletions(-)

diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 9670a16..90c4983 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -300,6 +300,7 @@ LIB_H += ui/progress.h
 LIB_H += ui/util.h
 LIB_H += ui/ui.h
 LIB_H += util/data.h
+LIB_H += util/kvm-stat.h
 
 LIB_OBJS += $(OUTPUT)util/abspath.o
 LIB_OBJS += $(OUTPUT)util/alias.o
diff --git a/tools/perf/arch/x86/Makefile b/tools/perf/arch/x86/Makefile
index d393901..9b21881 100644
--- a/tools/perf/arch/x86/Makefile
+++ b/tools/perf/arch/x86/Makefile
@@ -16,3 +16,4 @@ LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/header.o
 LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/tsc.o
 LIB_H += arch/$(ARCH)/util/tsc.h
 HAVE_KVM_STAT_SUPPORT := 1
+LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/kvm-stat.o
diff --git a/tools/perf/arch/x86/util/kvm-stat.c b/tools/perf/arch/x86/util/kvm-stat.c
new file mode 100644
index 0000000..2f8d2c1
--- /dev/null
+++ b/tools/perf/arch/x86/util/kvm-stat.c
@@ -0,0 +1,151 @@
+#include "../../util/kvm-stat.h"
+#include <asm/kvm_perf.h>
+
+define_exit_reasons_table(vmx_exit_reasons, VMX_EXIT_REASONS);
+define_exit_reasons_table(svm_exit_reasons, SVM_EXIT_REASONS);
+
+static struct kvm_events_ops exit_events = {
+	.is_begin_event = exit_event_begin,
+	.is_end_event = exit_event_end,
+	.decode_key = exit_event_decode_key,
+	.name = "VM-EXIT"
+};
+
+/*
+ * For the mmio events, we treat:
+ * the time of MMIO write: kvm_mmio(KVM_TRACE_MMIO_WRITE...) -> kvm_entry
+ * the time of MMIO read: kvm_exit -> kvm_mmio(KVM_TRACE_MMIO_READ...).
+ */
+static void mmio_event_get_key(struct perf_evsel *evsel, struct perf_sample *sample,
+			       struct event_key *key)
+{
+	key->key  = perf_evsel__intval(evsel, sample, "gpa");
+	key->info = perf_evsel__intval(evsel, sample, "type");
+}
+
+#define KVM_TRACE_MMIO_READ_UNSATISFIED 0
+#define KVM_TRACE_MMIO_READ 1
+#define KVM_TRACE_MMIO_WRITE 2
+
+static bool mmio_event_begin(struct perf_evsel *evsel,
+			     struct perf_sample *sample, struct event_key *key)
+{
+	/* MMIO read begin event in kernel. */
+	if (kvm_exit_event(evsel))
+		return true;
+
+	/* MMIO write begin event in kernel. */
+	if (!strcmp(evsel->name, "kvm:kvm_mmio") &&
+	    perf_evsel__intval(evsel, sample, "type") == KVM_TRACE_MMIO_WRITE) {
+		mmio_event_get_key(evsel, sample, key);
+		return true;
+	}
+
+	return false;
+}
+
+static bool mmio_event_end(struct perf_evsel *evsel, struct perf_sample *sample,
+			   struct event_key *key)
+{
+	/* MMIO write end event in kernel. */
+	if (kvm_entry_event(evsel))
+		return true;
+
+	/* MMIO read end event in kernel.*/
+	if (!strcmp(evsel->name, "kvm:kvm_mmio") &&
+	    perf_evsel__intval(evsel, sample, "type") == KVM_TRACE_MMIO_READ) {
+		mmio_event_get_key(evsel, sample, key);
+		return true;
+	}
+
+	return false;
+}
+
+static void mmio_event_decode_key(struct perf_kvm_stat *kvm __maybe_unused,
+				  struct event_key *key,
+				  char *decode)
+{
+	scnprintf(decode, DECODE_STR_LEN, "%#lx:%s",
+		  (unsigned long)key->key,
+		  key->info == KVM_TRACE_MMIO_WRITE ? "W" : "R");
+}
+
+static struct kvm_events_ops mmio_events = {
+	.is_begin_event = mmio_event_begin,
+	.is_end_event = mmio_event_end,
+	.decode_key = mmio_event_decode_key,
+	.name = "MMIO Access"
+};
+
+ /* The time of emulation pio access is from kvm_pio to kvm_entry. */
+static void ioport_event_get_key(struct perf_evsel *evsel,
+				 struct perf_sample *sample,
+				 struct event_key *key)
+{
+	key->key  = perf_evsel__intval(evsel, sample, "port");
+	key->info = perf_evsel__intval(evsel, sample, "rw");
+}
+
+static bool ioport_event_begin(struct perf_evsel *evsel,
+			       struct perf_sample *sample,
+			       struct event_key *key)
+{
+	if (!strcmp(evsel->name, "kvm:kvm_pio")) {
+		ioport_event_get_key(evsel, sample, key);
+		return true;
+	}
+
+	return false;
+}
+
+static bool ioport_event_end(struct perf_evsel *evsel,
+			     struct perf_sample *sample __maybe_unused,
+			     struct event_key *key __maybe_unused)
+{
+	return kvm_entry_event(evsel);
+}
+
+static void ioport_event_decode_key(struct perf_kvm_stat *kvm __maybe_unused,
+				    struct event_key *key,
+				    char *decode)
+{
+	scnprintf(decode, DECODE_STR_LEN, "%#llx:%s",
+		  (unsigned long long)key->key,
+		  key->info ? "POUT" : "PIN");
+}
+
+static struct kvm_events_ops ioport_events = {
+	.is_begin_event = ioport_event_begin,
+	.is_end_event = ioport_event_end,
+	.decode_key = ioport_event_decode_key,
+	.name = "IO Port Access"
+};
+
+const char * const kvm_events_tp[] = {
+	"kvm:kvm_entry",
+	"kvm:kvm_exit",
+	"kvm:kvm_mmio",
+	"kvm:kvm_pio",
+	NULL,
+};
+
+struct kvm_reg_events_ops kvm_reg_events_ops[] = {
+	{ .name = "vmexit", .ops = &exit_events },
+	{ .name = "mmio", .ops = &mmio_events },
+	{ .name = "ioport", .ops = &ioport_events },
+	{ NULL, NULL },
+};
+
+int cpu_isa_init(struct perf_kvm_stat *kvm, const char *cpuid)
+{
+	if (strstr(cpuid, "Intel")) {
+		kvm->exit_reasons = vmx_exit_reasons;
+		kvm->exit_reasons_isa = "VMX";
+	} else if (strstr(cpuid, "AMD")) {
+		kvm->exit_reasons = svm_exit_reasons;
+		kvm->exit_reasons_isa = "SVM";
+	} else
+		return -ENOTSUP;
+
+	return 0;
+}
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index 6d73346..75ee8c1 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -31,109 +31,23 @@
 
 #ifdef HAVE_KVM_STAT_SUPPORT
 #include <asm/kvm_perf.h>
+#include "util/kvm-stat.h"
 
-struct event_key {
-	#define INVALID_KEY     (~0ULL)
-	u64 key;
-	int info;
-};
-
-struct kvm_event_stats {
-	u64 time;
-	struct stats stats;
-};
-
-struct kvm_event {
-	struct list_head hash_entry;
-	struct rb_node rb;
-
-	struct event_key key;
-
-	struct kvm_event_stats total;
-
-	#define DEFAULT_VCPU_NUM 8
-	int max_vcpu;
-	struct kvm_event_stats *vcpu;
-};
-
-typedef int (*key_cmp_fun)(struct kvm_event*, struct kvm_event*, int);
-
-struct kvm_event_key {
-	const char *name;
-	key_cmp_fun key;
-};
-
-
-struct perf_kvm_stat;
-
-struct kvm_events_ops {
-	bool (*is_begin_event)(struct perf_evsel *evsel,
-			       struct perf_sample *sample,
-			       struct event_key *key);
-	bool (*is_end_event)(struct perf_evsel *evsel,
-			     struct perf_sample *sample, struct event_key *key);
-	void (*decode_key)(struct perf_kvm_stat *kvm, struct event_key *key,
-			   char *decode);
-	const char *name;
-};
-
-struct exit_reasons_table {
-	unsigned long exit_code;
-	const char *reason;
-};
-
-#define EVENTS_BITS		12
-#define EVENTS_CACHE_SIZE	(1UL << EVENTS_BITS)
-
-struct perf_kvm_stat {
-	struct perf_tool    tool;
-	struct record_opts  opts;
-	struct perf_evlist  *evlist;
-	struct perf_session *session;
-
-	const char *file_name;
-	const char *report_event;
-	const char *sort_key;
-	int trace_vcpu;
-
-	struct exit_reasons_table *exit_reasons;
-	const char *exit_reasons_isa;
-
-	struct kvm_events_ops *events_ops;
-	key_cmp_fun compare;
-	struct list_head kvm_events_cache[EVENTS_CACHE_SIZE];
-
-	u64 total_time;
-	u64 total_count;
-	u64 lost_events;
-	u64 duration;
-
-	const char *pid_str;
-	struct intlist *pid_list;
-
-	struct rb_root result;
-
-	int timerfd;
-	unsigned int display_time;
-	bool live;
-};
-
-
-static void exit_event_get_key(struct perf_evsel *evsel,
-			       struct perf_sample *sample,
-			       struct event_key *key)
+void exit_event_get_key(struct perf_evsel *evsel,
+			struct perf_sample *sample,
+			struct event_key *key)
 {
 	key->info = 0;
 	key->key = perf_evsel__intval(evsel, sample, KVM_EXIT_REASON);
 }
 
-static bool kvm_exit_event(struct perf_evsel *evsel)
+bool kvm_exit_event(struct perf_evsel *evsel)
 {
 	return !strcmp(evsel->name, KVM_EXIT_TRACE);
 }
 
-static bool exit_event_begin(struct perf_evsel *evsel,
-			     struct perf_sample *sample, struct event_key *key)
+bool exit_event_begin(struct perf_evsel *evsel,
+		      struct perf_sample *sample, struct event_key *key)
 {
 	if (kvm_exit_event(evsel)) {
 		exit_event_get_key(evsel, sample, key);
@@ -143,26 +57,18 @@ static bool exit_event_begin(struct perf_evsel *evsel,
 	return false;
 }
 
-static bool kvm_entry_event(struct perf_evsel *evsel)
+bool kvm_entry_event(struct perf_evsel *evsel)
 {
 	return !strcmp(evsel->name, KVM_ENTRY_TRACE);
 }
 
-static bool exit_event_end(struct perf_evsel *evsel,
-			   struct perf_sample *sample __maybe_unused,
-			   struct event_key *key __maybe_unused)
+bool exit_event_end(struct perf_evsel *evsel,
+		    struct perf_sample *sample __maybe_unused,
+		    struct event_key *key __maybe_unused)
 {
 	return kvm_entry_event(evsel);
 }
 
-#define define_exit_reasons_table(name, symbols)	\
-	static struct exit_reasons_table name[] = {	\
-		symbols, { -1, NULL }			\
-	}
-
-define_exit_reasons_table(vmx_exit_reasons, VMX_EXIT_REASONS);
-define_exit_reasons_table(svm_exit_reasons, SVM_EXIT_REASONS);
-
 static const char *get_exit_reason(struct perf_kvm_stat *kvm,
 				   struct exit_reasons_table *tbl,
 				   u64 exit_code)
@@ -178,9 +84,9 @@ static const char *get_exit_reason(struct perf_kvm_stat *kvm,
 	return "UNKNOWN";
 }
 
-static void exit_event_decode_key(struct perf_kvm_stat *kvm,
-				  struct event_key *key,
-				  char *decode)
+void exit_event_decode_key(struct perf_kvm_stat *kvm,
+			   struct event_key *key,
+			   char *decode)
 {
 	const char *exit_reason = get_exit_reason(kvm, kvm->exit_reasons,
 						  key->key);
@@ -188,139 +94,20 @@ static void exit_event_decode_key(struct perf_kvm_stat *kvm,
 	scnprintf(decode, DECODE_STR_LEN, "%s", exit_reason);
 }
 
-static struct kvm_events_ops exit_events = {
-	.is_begin_event = exit_event_begin,
-	.is_end_event = exit_event_end,
-	.decode_key = exit_event_decode_key,
-	.name = "VM-EXIT"
-};
-
-/*
- * For the mmio events, we treat:
- * the time of MMIO write: kvm_mmio(KVM_TRACE_MMIO_WRITE...) -> kvm_entry
- * the time of MMIO read: kvm_exit -> kvm_mmio(KVM_TRACE_MMIO_READ...).
- */
-static void mmio_event_get_key(struct perf_evsel *evsel, struct perf_sample *sample,
-			       struct event_key *key)
-{
-	key->key  = perf_evsel__intval(evsel, sample, "gpa");
-	key->info = perf_evsel__intval(evsel, sample, "type");
-}
-
-#define KVM_TRACE_MMIO_READ_UNSATISFIED 0
-#define KVM_TRACE_MMIO_READ 1
-#define KVM_TRACE_MMIO_WRITE 2
-
-static bool mmio_event_begin(struct perf_evsel *evsel,
-			     struct perf_sample *sample, struct event_key *key)
-{
-	/* MMIO read begin event in kernel. */
-	if (kvm_exit_event(evsel))
-		return true;
-
-	/* MMIO write begin event in kernel. */
-	if (!strcmp(evsel->name, "kvm:kvm_mmio") &&
-	    perf_evsel__intval(evsel, sample, "type") == KVM_TRACE_MMIO_WRITE) {
-		mmio_event_get_key(evsel, sample, key);
-		return true;
-	}
-
-	return false;
-}
-
-static bool mmio_event_end(struct perf_evsel *evsel, struct perf_sample *sample,
-			   struct event_key *key)
-{
-	/* MMIO write end event in kernel. */
-	if (kvm_entry_event(evsel))
-		return true;
-
-	/* MMIO read end event in kernel.*/
-	if (!strcmp(evsel->name, "kvm:kvm_mmio") &&
-	    perf_evsel__intval(evsel, sample, "type") == KVM_TRACE_MMIO_READ) {
-		mmio_event_get_key(evsel, sample, key);
-		return true;
-	}
-
-	return false;
-}
-
-static void mmio_event_decode_key(struct perf_kvm_stat *kvm __maybe_unused,
-				  struct event_key *key,
-				  char *decode)
-{
-	scnprintf(decode, DECODE_STR_LEN, "%#lx:%s", (unsigned long)key->key,
-				key->info == KVM_TRACE_MMIO_WRITE ? "W" : "R");
-}
-
-static struct kvm_events_ops mmio_events = {
-	.is_begin_event = mmio_event_begin,
-	.is_end_event = mmio_event_end,
-	.decode_key = mmio_event_decode_key,
-	.name = "MMIO Access"
-};
-
- /* The time of emulation pio access is from kvm_pio to kvm_entry. */
-static void ioport_event_get_key(struct perf_evsel *evsel,
-				 struct perf_sample *sample,
-				 struct event_key *key)
+static bool register_kvm_events_ops(struct perf_kvm_stat *kvm)
 {
-	key->key  = perf_evsel__intval(evsel, sample, "port");
-	key->info = perf_evsel__intval(evsel, sample, "rw");
-}
+	struct kvm_reg_events_ops *events_ops = kvm_reg_events_ops;
 
-static bool ioport_event_begin(struct perf_evsel *evsel,
-			       struct perf_sample *sample,
-			       struct event_key *key)
-{
-	if (!strcmp(evsel->name, "kvm:kvm_pio")) {
-		ioport_event_get_key(evsel, sample, key);
-		return true;
+	for (events_ops = kvm_reg_events_ops; events_ops->name; events_ops++) {
+		if (!strcmp(events_ops->name, kvm->report_event)) {
+			kvm->events_ops = events_ops->ops;
+			return true;
+		}
 	}
 
 	return false;
 }
 
-static bool ioport_event_end(struct perf_evsel *evsel,
-			     struct perf_sample *sample __maybe_unused,
-			     struct event_key *key __maybe_unused)
-{
-	return kvm_entry_event(evsel);
-}
-
-static void ioport_event_decode_key(struct perf_kvm_stat *kvm __maybe_unused,
-				    struct event_key *key,
-				    char *decode)
-{
-	scnprintf(decode, DECODE_STR_LEN, "%#llx:%s", (unsigned long long)key->key,
-				key->info ? "POUT" : "PIN");
-}
-
-static struct kvm_events_ops ioport_events = {
-	.is_begin_event = ioport_event_begin,
-	.is_end_event = ioport_event_end,
-	.decode_key = ioport_event_decode_key,
-	.name = "IO Port Access"
-};
-
-static bool register_kvm_events_ops(struct perf_kvm_stat *kvm)
-{
-	bool ret = true;
-
-	if (!strcmp(kvm->report_event, "vmexit"))
-		kvm->events_ops = &exit_events;
-	else if (!strcmp(kvm->report_event, "mmio"))
-		kvm->events_ops = &mmio_events;
-	else if (!strcmp(kvm->report_event, "ioport"))
-		kvm->events_ops = &ioport_events;
-	else {
-		pr_err("Unknown report event:%s\n", kvm->report_event);
-		ret = false;
-	}
-
-	return ret;
-}
-
 struct vcpu_event_record {
 	int vcpu_id;
 	u64 start_time;
@@ -833,20 +620,6 @@ static int process_sample_event(struct perf_tool *tool,
 	return 0;
 }
 
-static int cpu_isa_init(struct perf_kvm_stat *kvm, const char *cpuid)
-{
-	if (strstr(cpuid, "Intel")) {
-		kvm->exit_reasons = vmx_exit_reasons;
-		kvm->exit_reasons_isa = "VMX";
-	} else if (strstr(cpuid, "AMD")) {
-		kvm->exit_reasons = svm_exit_reasons;
-		kvm->exit_reasons_isa = "SVM";
-	} else
-		return -ENOTSUP;
-
-	return 0;
-}
-
 static int cpu_isa_config(struct perf_kvm_stat *kvm)
 {
 	char buf[64], *cpuid;
@@ -1305,13 +1078,6 @@ exit:
 	return ret;
 }
 
-static const char * const kvm_events_tp[] = {
-	"kvm:kvm_entry",
-	"kvm:kvm_exit",
-	"kvm:kvm_mmio",
-	"kvm:kvm_pio",
-};
-
 #define STRDUP_FAIL_EXIT(s)		\
 	({	char *_p;		\
 	_p = strdup(s);		\
@@ -1323,7 +1089,7 @@ static const char * const kvm_events_tp[] = {
 static int
 kvm_events_record(struct perf_kvm_stat *kvm, int argc, const char **argv)
 {
-	unsigned int rec_argc, i, j;
+	unsigned int rec_argc, i, j, events_tp_size;
 	const char **rec_argv;
 	const char * const record_args[] = {
 		"record",
@@ -1331,9 +1097,14 @@ kvm_events_record(struct perf_kvm_stat *kvm, int argc, const char **argv)
 		"-m", "1024",
 		"-c", "1",
 	};
+	const char * const *events_tp;
+	events_tp_size = 0;
+
+	for (events_tp = kvm_events_tp; *events_tp; events_tp++)
+		events_tp_size++;
 
 	rec_argc = ARRAY_SIZE(record_args) + argc + 2 +
-		   2 * ARRAY_SIZE(kvm_events_tp);
+		   2 * events_tp_size;
 	rec_argv = calloc(rec_argc + 1, sizeof(char *));
 
 	if (rec_argv == NULL)
@@ -1342,7 +1113,7 @@ kvm_events_record(struct perf_kvm_stat *kvm, int argc, const char **argv)
 	for (i = 0; i < ARRAY_SIZE(record_args); i++)
 		rec_argv[i] = STRDUP_FAIL_EXIT(record_args[i]);
 
-	for (j = 0; j < ARRAY_SIZE(kvm_events_tp); j++) {
+	for (j = 0; j < events_tp_size; j++) {
 		rec_argv[i++] = "-e";
 		rec_argv[i++] = STRDUP_FAIL_EXIT(kvm_events_tp[j]);
 	}
@@ -1396,16 +1167,16 @@ static struct perf_evlist *kvm_live_event_list(void)
 {
 	struct perf_evlist *evlist;
 	char *tp, *name, *sys;
-	unsigned int j;
 	int err = -1;
+	const char * const *events_tp;
 
 	evlist = perf_evlist__new();
 	if (evlist == NULL)
 		return NULL;
 
-	for (j = 0; j < ARRAY_SIZE(kvm_events_tp); j++) {
+	for (events_tp = kvm_events_tp; *events_tp; events_tp++) {
 
-		tp = strdup(kvm_events_tp[j]);
+		tp = strdup(*events_tp);
 		if (tp == NULL)
 			goto out;
 
@@ -1414,7 +1185,7 @@ static struct perf_evlist *kvm_live_event_list(void)
 		name = strchr(tp, ':');
 		if (name == NULL) {
 			pr_err("Error parsing %s tracepoint: subsystem delimiter not found\n",
-				kvm_events_tp[j]);
+			       *events_tp);
 			free(tp);
 			goto out;
 		}
@@ -1422,7 +1193,7 @@ static struct perf_evlist *kvm_live_event_list(void)
 		name++;
 
 		if (perf_evlist__add_newtp(evlist, sys, name, NULL)) {
-			pr_err("Failed to add %s tracepoint to the list\n", kvm_events_tp[j]);
+			pr_err("Failed to add %s tracepoint to the list\n", *events_tp);
 			free(tp);
 			goto out;
 		}
diff --git a/tools/perf/util/kvm-stat.h b/tools/perf/util/kvm-stat.h
new file mode 100644
index 0000000..d0d9fb1
--- /dev/null
+++ b/tools/perf/util/kvm-stat.h
@@ -0,0 +1,130 @@
+#ifndef __PERF_KVM_STAT_H
+#define __PERF_KVM_STAT_H
+
+#include "../perf.h"
+#include "evsel.h"
+#include "evlist.h"
+#include "session.h"
+#include "tool.h"
+#include "stat.h"
+
+struct event_key {
+	#define INVALID_KEY     (~0ULL)
+	u64 key;
+	int info;
+};
+
+struct kvm_event_stats {
+	u64 time;
+	struct stats stats;
+};
+
+struct kvm_event {
+	struct list_head hash_entry;
+	struct rb_node rb;
+
+	struct event_key key;
+
+	struct kvm_event_stats total;
+
+	#define DEFAULT_VCPU_NUM 8
+	int max_vcpu;
+	struct kvm_event_stats *vcpu;
+};
+
+typedef int (*key_cmp_fun)(struct kvm_event*, struct kvm_event*, int);
+
+struct kvm_event_key {
+	const char *name;
+	key_cmp_fun key;
+};
+
+struct perf_kvm_stat;
+
+struct kvm_events_ops {
+	bool (*is_begin_event)(struct perf_evsel *evsel,
+			       struct perf_sample *sample,
+			       struct event_key *key);
+	bool (*is_end_event)(struct perf_evsel *evsel,
+			     struct perf_sample *sample, struct event_key *key);
+	void (*decode_key)(struct perf_kvm_stat *kvm, struct event_key *key,
+			   char *decode);
+	const char *name;
+};
+
+struct exit_reasons_table {
+	unsigned long exit_code;
+	const char *reason;
+};
+
+#define EVENTS_BITS		12
+#define EVENTS_CACHE_SIZE	(1UL << EVENTS_BITS)
+
+struct perf_kvm_stat {
+	struct perf_tool    tool;
+	struct record_opts  opts;
+	struct perf_evlist  *evlist;
+	struct perf_session *session;
+
+	const char *file_name;
+	const char *report_event;
+	const char *sort_key;
+	int trace_vcpu;
+
+	struct exit_reasons_table *exit_reasons;
+	const char *exit_reasons_isa;
+
+	struct kvm_events_ops *events_ops;
+	key_cmp_fun compare;
+	struct list_head kvm_events_cache[EVENTS_CACHE_SIZE];
+
+	u64 total_time;
+	u64 total_count;
+	u64 lost_events;
+	u64 duration;
+
+	const char *pid_str;
+	struct intlist *pid_list;
+
+	struct rb_root result;
+
+	int timerfd;
+	unsigned int display_time;
+	bool live;
+};
+
+struct kvm_reg_events_ops {
+	const char *name;
+	struct kvm_events_ops *ops;
+};
+
+void exit_event_get_key(struct perf_evsel *evsel,
+			struct perf_sample *sample,
+			struct event_key *key);
+bool exit_event_begin(struct perf_evsel *evsel,
+		      struct perf_sample *sample,
+		      struct event_key *key);
+bool exit_event_end(struct perf_evsel *evsel,
+		    struct perf_sample *sample,
+		    struct event_key *key);
+void exit_event_decode_key(struct perf_kvm_stat *kvm,
+			   struct event_key *key,
+			   char *decode);
+
+bool kvm_exit_event(struct perf_evsel *evsel);
+bool kvm_entry_event(struct perf_evsel *evsel);
+
+#define define_exit_reasons_table(name, symbols)	\
+	static struct exit_reasons_table name[] = {	\
+		symbols, { -1, NULL }			\
+	}
+
+/*
+ * arch specific callbacks and data structures
+ */
+int cpu_isa_init(struct perf_kvm_stat *kvm, const char *cpuid);
+
+extern const char * const kvm_events_tp[];
+extern struct kvm_reg_events_ops kvm_reg_events_ops[];
+
+#endif /* __PERF_KVM_STAT_H */

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [tip:perf/core] perf kvm: Add skip_event() for --duration option
  2014-07-03 14:29 ` [PATCH 3/4] perf kvm: Add skip_event() for --duration option Alexander Yarygin
  2014-07-07 14:10   ` Christian Borntraeger
  2014-07-09 13:45   ` David Ahern
@ 2014-07-18  4:22   ` tip-bot for Alexander Yarygin
  2 siblings, 0 replies; 23+ messages in thread
From: tip-bot for Alexander Yarygin @ 2014-07-18  4:22 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: acme, linux-kernel, paulus, hpa, mingo, a.p.zijlstra,
	borntraeger, jolsa, cornelia.huck, yarygin, dsahern, tglx

Commit-ID:  54c801ff71ba9c9ae41871e226b9d846ff9c6bab
Gitweb:     http://git.kernel.org/tip/54c801ff71ba9c9ae41871e226b9d846ff9c6bab
Author:     Alexander Yarygin <yarygin@linux.vnet.ibm.com>
AuthorDate: Thu, 3 Jul 2014 18:29:06 +0400
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 16 Jul 2014 17:57:32 -0300

perf kvm: Add skip_event() for --duration option

Current code skips output of the x86 specific HLT event in order to
avoid flooding the output with enabled --duration option. The events to
be skipped should be architecture dependent, though.

Let's add an architecture specific array of events to be skipped and
introduce a skip_event() function checking against that array.

Reviewed-by: Christian Borntraeger <borntraeger@de.ibm.com>
Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Reviewed-by: David Ahern <dsahern@gmail.com>
Signed-off-by: Alexander Yarygin <yarygin@linux.vnet.ibm.com>
Cc: Christian Borntraeger <borntraeger@de.ibm.com>
Cc: Cornelia Huck <cornelia.huck@de.ibm.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1404397747-20939-4-git-send-email-yarygin@linux.vnet.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/arch/x86/util/kvm-stat.c |  5 +++++
 tools/perf/builtin-kvm.c            | 13 ++++++++++++-
 tools/perf/util/kvm-stat.h          |  1 +
 3 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/tools/perf/arch/x86/util/kvm-stat.c b/tools/perf/arch/x86/util/kvm-stat.c
index 2f8d2c1..14e4e66 100644
--- a/tools/perf/arch/x86/util/kvm-stat.c
+++ b/tools/perf/arch/x86/util/kvm-stat.c
@@ -136,6 +136,11 @@ struct kvm_reg_events_ops kvm_reg_events_ops[] = {
 	{ NULL, NULL },
 };
 
+const char * const kvm_skip_events[] = {
+	"HLT",
+	NULL,
+};
+
 int cpu_isa_init(struct perf_kvm_stat *kvm, const char *cpuid)
 {
 	if (strstr(cpuid, "Intel")) {
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index 75ee8c1..fc2d63d 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -261,6 +261,17 @@ static bool update_kvm_event(struct kvm_event *event, int vcpu_id,
 	return true;
 }
 
+static bool skip_event(const char *event)
+{
+	const char * const *skip_events;
+
+	for (skip_events = kvm_skip_events; *skip_events; skip_events++)
+		if (!strcmp(event, *skip_events))
+			return true;
+
+	return false;
+}
+
 static bool handle_end_event(struct perf_kvm_stat *kvm,
 			     struct vcpu_event_record *vcpu_record,
 			     struct event_key *key,
@@ -312,7 +323,7 @@ static bool handle_end_event(struct perf_kvm_stat *kvm,
 		char decode[DECODE_STR_LEN];
 
 		kvm->events_ops->decode_key(kvm, &event->key, decode);
-		if (strcmp(decode, "HLT")) {
+		if (!skip_event(decode)) {
 			pr_info("%" PRIu64 " VM %d, vcpu %d: %s event took %" PRIu64 "usec\n",
 				 sample->time, sample->pid, vcpu_record->vcpu_id,
 				 decode, time_diff/1000);
diff --git a/tools/perf/util/kvm-stat.h b/tools/perf/util/kvm-stat.h
index d0d9fb1..ba937ca 100644
--- a/tools/perf/util/kvm-stat.h
+++ b/tools/perf/util/kvm-stat.h
@@ -126,5 +126,6 @@ int cpu_isa_init(struct perf_kvm_stat *kvm, const char *cpuid);
 
 extern const char * const kvm_events_tp[];
 extern struct kvm_reg_events_ops kvm_reg_events_ops[];
+extern const char * const kvm_skip_events[];
 
 #endif /* __PERF_KVM_STAT_H */

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [tip:perf/core] perf kvm: Add stat support on s390
  2014-07-03 14:29 ` [PATCH 4/4] perf kvm: Add stat support on s390 Alexander Yarygin
                     ` (2 preceding siblings ...)
  2014-07-10 10:50   ` Alexander Yarygin
@ 2014-07-18  4:22   ` tip-bot for Alexander Yarygin
  3 siblings, 0 replies; 23+ messages in thread
From: tip-bot for Alexander Yarygin @ 2014-07-18  4:22 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: acme, linux-kernel, paulus, hpa, mingo, a.p.zijlstra,
	borntraeger, jolsa, cornelia.huck, yarygin, dsahern, tglx

Commit-ID:  3be8e2a0a53c3179a44a933614f6a893da0b5c19
Gitweb:     http://git.kernel.org/tip/3be8e2a0a53c3179a44a933614f6a893da0b5c19
Author:     Alexander Yarygin <yarygin@linux.vnet.ibm.com>
AuthorDate: Thu, 3 Jul 2014 18:29:07 +0400
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 16 Jul 2014 17:57:33 -0300

perf kvm: Add stat support on s390

On s390, the vmexit event has a tree-like structure: between
exit_event_begin and exit_event_end several other events may happen and
with each of them refining the previous ones.

This patch adds a decoder for such events to the generic code and also
the files <asm/kvm_perf.h> and kvm-stat.c for s390.

Commands 'perf kvm stat record', 'report' and 'live' are supported.

Reviewed-by: David Ahern <dsahern@gmail.com>
Signed-off-by: Alexander Yarygin <yarygin@linux.vnet.ibm.com>
Acked-by: Christian Borntraeger <borntraeger@de.ibm.com>
Cc: Christian Borntraeger <borntraeger@de.ibm.com>
Cc: Cornelia Huck <cornelia.huck@de.ibm.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1404397747-20939-5-git-send-email-yarygin@linux.vnet.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 arch/s390/include/uapi/asm/Kbuild     |   1 +
 arch/s390/include/uapi/asm/kvm_perf.h |  25 ++++++++
 tools/perf/Documentation/perf-kvm.txt |  16 +++---
 tools/perf/MANIFEST                   |   2 +
 tools/perf/arch/s390/Makefile         |   2 +
 tools/perf/arch/s390/util/kvm-stat.c  | 105 ++++++++++++++++++++++++++++++++++
 tools/perf/builtin-kvm.c              |  52 +++++++++++++++--
 tools/perf/util/kvm-stat.h            |   9 +++
 8 files changed, 201 insertions(+), 11 deletions(-)

diff --git a/arch/s390/include/uapi/asm/Kbuild b/arch/s390/include/uapi/asm/Kbuild
index 6a9a9eb..0e2b54d 100644
--- a/arch/s390/include/uapi/asm/Kbuild
+++ b/arch/s390/include/uapi/asm/Kbuild
@@ -16,6 +16,7 @@ header-y += ioctls.h
 header-y += ipcbuf.h
 header-y += kvm.h
 header-y += kvm_para.h
+header-y += kvm_perf.h
 header-y += kvm_virtio.h
 header-y += mman.h
 header-y += monwriter.h
diff --git a/arch/s390/include/uapi/asm/kvm_perf.h b/arch/s390/include/uapi/asm/kvm_perf.h
new file mode 100644
index 0000000..3972827
--- /dev/null
+++ b/arch/s390/include/uapi/asm/kvm_perf.h
@@ -0,0 +1,25 @@
+/*
+ * Definitions for perf-kvm on s390
+ *
+ * Copyright 2014 IBM Corp.
+ * Author(s): Alexander Yarygin <yarygin@linux.vnet.ibm.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License (version 2 only)
+ * as published by the Free Software Foundation.
+ */
+
+#ifndef __LINUX_KVM_PERF_S390_H
+#define __LINUX_KVM_PERF_S390_H
+
+#include <asm/sie.h>
+
+#define DECODE_STR_LEN 40
+
+#define VCPU_ID "id"
+
+#define KVM_ENTRY_TRACE "kvm:kvm_s390_sie_enter"
+#define KVM_EXIT_TRACE "kvm:kvm_s390_sie_exit"
+#define KVM_EXIT_REASON "icptcode"
+
+#endif
diff --git a/tools/perf/Documentation/perf-kvm.txt b/tools/perf/Documentation/perf-kvm.txt
index 52276a6..6e689dc 100644
--- a/tools/perf/Documentation/perf-kvm.txt
+++ b/tools/perf/Documentation/perf-kvm.txt
@@ -51,9 +51,9 @@ There are a couple of variants of perf kvm:
   'perf kvm stat <command>' to run a command and gather performance counter
   statistics.
   Especially, perf 'kvm stat record/report' generates a statistical analysis
-  of KVM events. Currently, vmexit, mmio and ioport events are supported.
-  'perf kvm stat record <command>' records kvm events and the events between
-  start and end <command>.
+  of KVM events. Currently, vmexit, mmio (x86 only) and ioport (x86 only)
+  events are supported. 'perf kvm stat record <command>' records kvm events
+  and the events between start and end <command>.
   And this command produces a file which contains tracing results of kvm
   events.
 
@@ -103,8 +103,8 @@ STAT REPORT OPTIONS
        analyze events which occures on this vcpu. (default: all vcpus)
 
 --event=<value>::
-       event to be analyzed. Possible values: vmexit, mmio, ioport.
-       (default: vmexit)
+       event to be analyzed. Possible values: vmexit, mmio (x86 only),
+       ioport (x86 only). (default: vmexit)
 -k::
 --key=<value>::
        Sorting key. Possible values: sample (default, sort by samples
@@ -138,7 +138,8 @@ STAT LIVE OPTIONS
 
 
 --event=<value>::
-       event to be analyzed. Possible values: vmexit, mmio, ioport.
+       event to be analyzed. Possible values: vmexit,
+       mmio (x86 only), ioport (x86 only).
        (default: vmexit)
 
 -k::
@@ -147,7 +148,8 @@ STAT LIVE OPTIONS
        number), time (sort by average time).
 
 --duration=<value>::
-       Show events other than HLT that take longer than duration usecs.
+       Show events other than HLT (x86 only) or Wait state (s390 only)
+       that take longer than duration usecs.
 
 SEE ALSO
 --------
diff --git a/tools/perf/MANIFEST b/tools/perf/MANIFEST
index 02b485d..344c4d3 100644
--- a/tools/perf/MANIFEST
+++ b/tools/perf/MANIFEST
@@ -38,3 +38,5 @@ arch/x86/include/uapi/asm/svm.h
 arch/x86/include/uapi/asm/vmx.h
 arch/x86/include/uapi/asm/kvm.h
 arch/x86/include/uapi/asm/kvm_perf.h
+arch/s390/include/uapi/asm/sie.h
+arch/s390/include/uapi/asm/kvm_perf.h
diff --git a/tools/perf/arch/s390/Makefile b/tools/perf/arch/s390/Makefile
index 744e629..798ac73 100644
--- a/tools/perf/arch/s390/Makefile
+++ b/tools/perf/arch/s390/Makefile
@@ -3,3 +3,5 @@ PERF_HAVE_DWARF_REGS := 1
 LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/dwarf-regs.o
 endif
 LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/header.o
+HAVE_KVM_STAT_SUPPORT := 1
+LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/kvm-stat.o
diff --git a/tools/perf/arch/s390/util/kvm-stat.c b/tools/perf/arch/s390/util/kvm-stat.c
new file mode 100644
index 0000000..a5dbc07
--- /dev/null
+++ b/tools/perf/arch/s390/util/kvm-stat.c
@@ -0,0 +1,105 @@
+/*
+ * Arch specific functions for perf kvm stat.
+ *
+ * Copyright 2014 IBM Corp.
+ * Author(s): Alexander Yarygin <yarygin@linux.vnet.ibm.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License (version 2 only)
+ * as published by the Free Software Foundation.
+ */
+
+#include "../../util/kvm-stat.h"
+#include <asm/kvm_perf.h>
+
+define_exit_reasons_table(sie_exit_reasons, sie_intercept_code);
+define_exit_reasons_table(sie_icpt_insn_codes, icpt_insn_codes);
+define_exit_reasons_table(sie_sigp_order_codes, sigp_order_codes);
+define_exit_reasons_table(sie_diagnose_codes, diagnose_codes);
+define_exit_reasons_table(sie_icpt_prog_codes, icpt_prog_codes);
+
+static void event_icpt_insn_get_key(struct perf_evsel *evsel,
+				    struct perf_sample *sample,
+				    struct event_key *key)
+{
+	unsigned long insn;
+
+	insn = perf_evsel__intval(evsel, sample, "instruction");
+	key->key = icpt_insn_decoder(insn);
+	key->exit_reasons = sie_icpt_insn_codes;
+}
+
+static void event_sigp_get_key(struct perf_evsel *evsel,
+			       struct perf_sample *sample,
+			       struct event_key *key)
+{
+	key->key = perf_evsel__intval(evsel, sample, "order_code");
+	key->exit_reasons = sie_sigp_order_codes;
+}
+
+static void event_diag_get_key(struct perf_evsel *evsel,
+			       struct perf_sample *sample,
+			       struct event_key *key)
+{
+	key->key = perf_evsel__intval(evsel, sample, "code");
+	key->exit_reasons = sie_diagnose_codes;
+}
+
+static void event_icpt_prog_get_key(struct perf_evsel *evsel,
+				    struct perf_sample *sample,
+				    struct event_key *key)
+{
+	key->key = perf_evsel__intval(evsel, sample, "code");
+	key->exit_reasons = sie_icpt_prog_codes;
+}
+
+static struct child_event_ops child_events[] = {
+	{ .name = "kvm:kvm_s390_intercept_instruction",
+	  .get_key = event_icpt_insn_get_key },
+	{ .name = "kvm:kvm_s390_handle_sigp",
+	  .get_key = event_sigp_get_key },
+	{ .name = "kvm:kvm_s390_handle_diag",
+	  .get_key = event_diag_get_key },
+	{ .name = "kvm:kvm_s390_intercept_prog",
+	  .get_key = event_icpt_prog_get_key },
+	{ NULL, NULL },
+};
+
+static struct kvm_events_ops exit_events = {
+	.is_begin_event = exit_event_begin,
+	.is_end_event = exit_event_end,
+	.child_ops = child_events,
+	.decode_key = exit_event_decode_key,
+	.name = "VM-EXIT"
+};
+
+const char * const kvm_events_tp[] = {
+	"kvm:kvm_s390_sie_enter",
+	"kvm:kvm_s390_sie_exit",
+	"kvm:kvm_s390_intercept_instruction",
+	"kvm:kvm_s390_handle_sigp",
+	"kvm:kvm_s390_handle_diag",
+	"kvm:kvm_s390_intercept_prog",
+	NULL,
+};
+
+struct kvm_reg_events_ops kvm_reg_events_ops[] = {
+	{ .name = "vmexit", .ops = &exit_events },
+	{ NULL, NULL },
+};
+
+const char * const kvm_skip_events[] = {
+	"Wait state",
+	NULL,
+};
+
+int cpu_isa_init(struct perf_kvm_stat *kvm, const char *cpuid)
+{
+	if (strstr(cpuid, "IBM/S390")) {
+		kvm->exit_reasons = sie_exit_reasons;
+		kvm->exit_reasons_isa = "SIE";
+	} else
+		return -ENOTSUP;
+
+	return 0;
+}
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index fc2d63d..43367eb 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -88,7 +88,7 @@ void exit_event_decode_key(struct perf_kvm_stat *kvm,
 			   struct event_key *key,
 			   char *decode)
 {
-	const char *exit_reason = get_exit_reason(kvm, kvm->exit_reasons,
+	const char *exit_reason = get_exit_reason(kvm, key->exit_reasons,
 						  key->key);
 
 	scnprintf(decode, DECODE_STR_LEN, "%s", exit_reason);
@@ -261,6 +261,43 @@ static bool update_kvm_event(struct kvm_event *event, int vcpu_id,
 	return true;
 }
 
+static bool is_child_event(struct perf_kvm_stat *kvm,
+			   struct perf_evsel *evsel,
+			   struct perf_sample *sample,
+			   struct event_key *key)
+{
+	struct child_event_ops *child_ops;
+
+	child_ops = kvm->events_ops->child_ops;
+
+	if (!child_ops)
+		return false;
+
+	for (; child_ops->name; child_ops++) {
+		if (!strcmp(evsel->name, child_ops->name)) {
+			child_ops->get_key(evsel, sample, key);
+			return true;
+		}
+	}
+
+	return false;
+}
+
+static bool handle_child_event(struct perf_kvm_stat *kvm,
+			       struct vcpu_event_record *vcpu_record,
+			       struct event_key *key,
+			       struct perf_sample *sample __maybe_unused)
+{
+	struct kvm_event *event = NULL;
+
+	if (key->key != INVALID_KEY)
+		event = find_create_kvm_event(kvm, key);
+
+	vcpu_record->last_event = event;
+
+	return true;
+}
+
 static bool skip_event(const char *event)
 {
 	const char * const *skip_events;
@@ -361,7 +398,8 @@ static bool handle_kvm_event(struct perf_kvm_stat *kvm,
 			     struct perf_sample *sample)
 {
 	struct vcpu_event_record *vcpu_record;
-	struct event_key key = {.key = INVALID_KEY};
+	struct event_key key = { .key = INVALID_KEY,
+				 .exit_reasons = kvm->exit_reasons };
 
 	vcpu_record = per_vcpu_record(thread, evsel, sample);
 	if (!vcpu_record)
@@ -375,6 +413,9 @@ static bool handle_kvm_event(struct perf_kvm_stat *kvm,
 	if (kvm->events_ops->is_begin_event(evsel, sample, &key))
 		return handle_begin_event(kvm, vcpu_record, &key, sample->time);
 
+	if (is_child_event(kvm, evsel, sample, &key))
+		return handle_child_event(kvm, vcpu_record, &key, sample);
+
 	if (kvm->events_ops->is_end_event(evsel, sample, &key))
 		return handle_end_event(kvm, vcpu_record, &key, sample);
 
@@ -1143,7 +1184,8 @@ kvm_events_report(struct perf_kvm_stat *kvm, int argc, const char **argv)
 {
 	const struct option kvm_events_report_options[] = {
 		OPT_STRING(0, "event", &kvm->report_event, "report event",
-			    "event for reporting: vmexit, mmio, ioport"),
+			   "event for reporting: vmexit, "
+			   "mmio (x86 only), ioport (x86 only)"),
 		OPT_INTEGER(0, "vcpu", &kvm->trace_vcpu,
 			    "vcpu id to report"),
 		OPT_STRING('k', "key", &kvm->sort_key, "sort-key",
@@ -1249,7 +1291,9 @@ static int kvm_events_live(struct perf_kvm_stat *kvm,
 			"key for sorting: sample(sort by samples number)"
 			" time (sort by avg time)"),
 		OPT_U64(0, "duration", &kvm->duration,
-		    "show events other than HALT that take longer than duration usecs"),
+			"show events other than"
+			" HLT (x86 only) or Wait state (s390 only)"
+			" that take longer than duration usecs"),
 		OPT_END()
 	};
 	const char * const live_usage[] = {
diff --git a/tools/perf/util/kvm-stat.h b/tools/perf/util/kvm-stat.h
index ba937ca..0b5a8cd 100644
--- a/tools/perf/util/kvm-stat.h
+++ b/tools/perf/util/kvm-stat.h
@@ -12,6 +12,7 @@ struct event_key {
 	#define INVALID_KEY     (~0ULL)
 	u64 key;
 	int info;
+	struct exit_reasons_table *exit_reasons;
 };
 
 struct kvm_event_stats {
@@ -41,12 +42,20 @@ struct kvm_event_key {
 
 struct perf_kvm_stat;
 
+struct child_event_ops {
+	void (*get_key)(struct perf_evsel *evsel,
+			struct perf_sample *sample,
+			struct event_key *key);
+	const char *name;
+};
+
 struct kvm_events_ops {
 	bool (*is_begin_event)(struct perf_evsel *evsel,
 			       struct perf_sample *sample,
 			       struct event_key *key);
 	bool (*is_end_event)(struct perf_evsel *evsel,
 			     struct perf_sample *sample, struct event_key *key);
+	struct child_event_ops *child_ops;
 	void (*decode_key)(struct perf_kvm_stat *kvm, struct event_key *key,
 			   char *decode);
 	const char *name;

^ permalink raw reply related	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2014-07-18  4:24 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-03 14:29 [PATCH/RFC 0/4] perf kvm: add stat support for s390 Alexander Yarygin
2014-07-03 14:29 ` [PATCH 1/4] perf kvm: Use defines of kvm events Alexander Yarygin
2014-07-07 14:06   ` Christian Borntraeger
2014-07-07 15:42     ` David Ahern
2014-07-09 13:45   ` David Ahern
2014-07-18  4:21   ` [tip:perf/core] " tip-bot for Alexander Yarygin
2014-07-03 14:29 ` [PATCH 2/4] perf kvm: Move arch specific code into arch/ Alexander Yarygin
2014-07-07 14:09   ` Christian Borntraeger
2014-07-09 13:45   ` David Ahern
2014-07-18  4:21   ` [tip:perf/core] " tip-bot for Alexander Yarygin
2014-07-03 14:29 ` [PATCH 3/4] perf kvm: Add skip_event() for --duration option Alexander Yarygin
2014-07-07 14:10   ` Christian Borntraeger
2014-07-09 13:45   ` David Ahern
2014-07-18  4:22   ` [tip:perf/core] " tip-bot for Alexander Yarygin
2014-07-03 14:29 ` [PATCH 4/4] perf kvm: Add stat support on s390 Alexander Yarygin
2014-07-07 14:11   ` Christian Borntraeger
2014-07-09 13:45   ` David Ahern
2014-07-10 10:50   ` Alexander Yarygin
2014-07-10 13:40     ` Arnaldo Carvalho de Melo
2014-07-18  4:22   ` [tip:perf/core] " tip-bot for Alexander Yarygin
2014-07-03 15:07 ` [PATCH/RFC 0/4] perf kvm: add stat support for s390 Christian Borntraeger
2014-07-09 16:47 ` David Ahern
2014-07-09 18:58   ` Arnaldo Carvalho de Melo

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.