linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: linux-kernel@vger.kernel.org,
	Alexander Yarygin <yarygin@linux.vnet.ibm.com>,
	Christian Borntraeger <borntraeger@de.ibm.com>,
	Cornelia Huck <cornelia.huck@de.ibm.com>,
	David Ahern <dsahern@gmail.com>, Jiri Olsa <jolsa@redhat.com>,
	Paul Mackerras <paulus@samba.org>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH 01/33] perf kvm: Use defines of kvm events
Date: Thu, 17 Jul 2014 13:12:03 -0300	[thread overview]
Message-ID: <1405613555-23380-2-git-send-email-acme@kernel.org> (raw)
In-Reply-To: <1405613555-23380-1-git-send-email-acme@kernel.org>

From: Alexander Yarygin <yarygin@linux.vnet.ibm.com>

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>

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(-)
 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 09409c44f9a5..3dec769cadf7 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 000000000000..3bb964f88aa1
--- /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 45da209b6ed3..02b485d619cd 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 41dbeaf8cc11..6d73346ef2a6 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.9.3


  reply	other threads:[~2014-07-17 16:12 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-17 16:12 [GIT PULL 00/33] perf/core improvements and fixes Arnaldo Carvalho de Melo
2014-07-17 16:12 ` Arnaldo Carvalho de Melo [this message]
2014-07-17 16:12 ` [PATCH 02/33] perf kvm: Move arch specific code into arch/ Arnaldo Carvalho de Melo
2014-07-17 16:12 ` [PATCH 03/33] perf kvm: Add skip_event() for --duration option Arnaldo Carvalho de Melo
2014-07-17 16:12 ` [PATCH 04/33] perf kvm: Add stat support on s390 Arnaldo Carvalho de Melo
2014-07-17 16:12 ` [PATCH 05/33] perf script: Add missing calls to Py_DECREF for return values Arnaldo Carvalho de Melo
2014-07-17 16:12 ` [PATCH 06/33] perf script: Add callchain to generic and tracepoint events Arnaldo Carvalho de Melo
2014-07-17 16:12 ` [PATCH 07/33] perf script: Provide additional sample information on generic events Arnaldo Carvalho de Melo
2014-07-17 16:12 ` [PATCH 08/33] perf machine: Fix the value used for unknown pids Arnaldo Carvalho de Melo
2014-07-17 16:12 ` [PATCH 09/33] perf script: Display PERF_RECORD_MISC_COMM_EXEC flag Arnaldo Carvalho de Melo
2014-07-17 16:12 ` [PATCH 10/33] perf record: Select comm_exec flag if supported Arnaldo Carvalho de Melo
2014-07-17 16:12 ` [PATCH 11/33] perf tools: Fix missing kernel map load Arnaldo Carvalho de Melo
2014-07-17 16:12 ` [PATCH 12/33] perf symbols: Fix missing GNU IFUNC symbols Arnaldo Carvalho de Melo
2014-07-17 16:12 ` [PATCH 13/33] perf inject: Fix build id injection Arnaldo Carvalho de Melo
2014-07-17 16:12 ` [PATCH 14/33] perf callchain: Fix appending a callchain from a previous sample Arnaldo Carvalho de Melo
2014-07-17 16:12 ` [PATCH 15/33] perf buildid-cache: Apply force option to copying kcore Arnaldo Carvalho de Melo
2014-07-17 16:12 ` [PATCH 16/33] perf symbols: Record whether a dso is 64-bit Arnaldo Carvalho de Melo
2014-07-17 16:12 ` [PATCH 17/33] perf symbols: Do not attempt to read data from kallsyms Arnaldo Carvalho de Melo
2014-07-17 16:12 ` [PATCH 18/33] perf symbols: Add ability to iterate over a dso's symbols Arnaldo Carvalho de Melo
2014-07-17 16:12 ` [PATCH 19/33] perf session: Flag if the event stream is entirely in memory Arnaldo Carvalho de Melo
2014-07-17 16:12 ` [PATCH 20/33] perf evlist: Pass mmap parameters in a struct Arnaldo Carvalho de Melo
2014-07-17 16:12 ` [PATCH 21/33] perf tools: Add feature test for __sync_val_compare_and_swap Arnaldo Carvalho de Melo
2014-07-17 16:12 ` [PATCH 22/33] perf tools: Add option macro OPT_CALLBACK_OPTARG Arnaldo Carvalho de Melo
2014-07-17 16:12 ` [PATCH 23/33] perf evsel: Add 'no_aux_samples' option Arnaldo Carvalho de Melo
2014-07-17 16:12 ` [PATCH 24/33] perf evsel: Add 'immediate' option Arnaldo Carvalho de Melo
2014-07-17 16:12 ` [PATCH 25/33] perf machine: Fix map groups of threads with unknown pids Arnaldo Carvalho de Melo
2014-07-17 16:12 ` [PATCH 26/33] perf thread: Allow deletion of a thread with no map groups Arnaldo Carvalho de Melo
2014-07-17 16:12 ` [PATCH 27/33] perf machine: Fix leak of 'struct thread' on error path Arnaldo Carvalho de Melo
2014-07-17 16:12 ` [PATCH 28/33] perf tools: Remove verbose from functions prototypes Arnaldo Carvalho de Melo
2014-07-17 16:12 ` [PATCH 29/33] perf tools: Move pr_* debug macros into debug object Arnaldo Carvalho de Melo
2014-07-17 16:12 ` [PATCH 30/33] perf tools: Factor eprintf to allow different debug variables Arnaldo Carvalho de Melo
2014-07-17 16:12 ` [PATCH 31/33] perf tools: Add --debug optionto set debug variable Arnaldo Carvalho de Melo
2014-07-17 16:12 ` [PATCH 32/33] perf tools: Remove needless getopt.h includes Arnaldo Carvalho de Melo
2014-07-17 16:12 ` [PATCH 33/33] perf tools: Allow TSC conversion on any arch Arnaldo Carvalho de Melo
2014-07-18  4:17 ` [GIT PULL 00/33] perf/core improvements and fixes Ingo Molnar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1405613555-23380-2-git-send-email-acme@kernel.org \
    --to=acme@kernel.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@redhat.com \
    --cc=borntraeger@de.ibm.com \
    --cc=cornelia.huck@de.ibm.com \
    --cc=dsahern@gmail.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=paulus@samba.org \
    --cc=yarygin@linux.vnet.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).