[tip:perf/core] perf tools: Parse tracepoints with '-' in system name

2014-05-01 Thread tip-bot for Alexander Yarygin
Commit-ID:  2b9032e0ecb57de819bcf40b440e7cbd2d8f3a8c
Gitweb: http://git.kernel.org/tip/2b9032e0ecb57de819bcf40b440e7cbd2d8f3a8c
Author: Alexander Yarygin yary...@linux.vnet.ibm.com
AuthorDate: Fri, 25 Apr 2014 17:34:05 +0200
Committer:  Jiri Olsa jo...@kernel.org
CommitDate: Tue, 29 Apr 2014 14:27:23 +0200

perf tools: Parse tracepoints with '-' in system name

Trace events potentially can have a '-' in their trace system name,
e.g. kvm on s390 defines kvm-s390:* tracepoints.
We could not parse them, because there was no rule for this:
  $ sudo ./perf top -e kvm-s390:*
  invalid or unsupported event: 'kvm-s390:*'

This patch adds an extra rule to event_legacy_tracepoint which handles
those cases. Without the patch, perf will not accept such tracepoints in
the -e option.

Signed-off-by: Alexander Yarygin yary...@linux.vnet.ibm.com
Tested-by: Christian Borntraeger borntrae...@de.ibm.com
Acked-by: Christian Borntraeger borntrae...@de.ibm.com
Link: 
http://lkml.kernel.org/r/1398440047-6641-2-git-send-email-yary...@linux.vnet.ibm.com
Signed-off-by: Jiri Olsa jo...@kernel.org
---
 tools/perf/util/parse-events.y | 12 
 1 file changed, 12 insertions(+)

diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y
index 4eb67ec..ac9db9f 100644
--- a/tools/perf/util/parse-events.y
+++ b/tools/perf/util/parse-events.y
@@ -299,6 +299,18 @@ PE_PREFIX_MEM PE_VALUE sep_dc
 }
 
 event_legacy_tracepoint:
+PE_NAME '-' PE_NAME ':' PE_NAME
+{
+   struct parse_events_evlist *data = _data;
+   struct list_head *list;
+   char sys_name[128];
+   snprintf(sys_name, 128, %s-%s, $1, $3);
+
+   ALLOC_LIST(list);
+   ABORT_ON(parse_events_add_tracepoint(list, data-idx, sys_name, $5));
+   $$ = list;
+}
+|
 PE_NAME ':' PE_NAME
 {
struct parse_events_evlist *data = _data;
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:perf/core] perf tests: Add numeric identifier to evlist_test

2014-05-01 Thread tip-bot for Alexander Yarygin
Commit-ID:  615b8f99f755f8e2701f08cef9c56bd3033891a5
Gitweb: http://git.kernel.org/tip/615b8f99f755f8e2701f08cef9c56bd3033891a5
Author: Alexander Yarygin yary...@linux.vnet.ibm.com
AuthorDate: Fri, 25 Apr 2014 17:34:06 +0200
Committer:  Jiri Olsa jo...@kernel.org
CommitDate: Tue, 29 Apr 2014 14:29:48 +0200

perf tests: Add numeric identifier to evlist_test

In tests/parse-events.c test cases are declared in evlist_test[]
arrays. Elements of arrays are initialized in following pattern:
[i] = {
.name  = ...,
.check = ...,
},

When perf-test is running with '-v' option, 'i' variable will be
printed for every existing test.

However, we can't add any arch specific tests inside #ifdefs, because it
will create collision between the element number inside #ifdef and the
next one outside.

This patch adds 'id' field in evlist_test, uses it as a test
identifier and removes explicit numbering of array elements. This helps
to number tests with gaps.

Signed-off-by: Alexander Yarygin yary...@linux.vnet.ibm.com
Link: 
http://lkml.kernel.org/r/1398440047-6641-3-git-send-email-yary...@linux.vnet.ibm.com
Signed-off-by: Jiri Olsa jo...@kernel.org
---
 tools/perf/tests/parse-events.c | 135 ++--
 1 file changed, 90 insertions(+), 45 deletions(-)

diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-events.c
index 8605ff5..81dbd5a 100644
--- a/tools/perf/tests/parse-events.c
+++ b/tools/perf/tests/parse-events.c
@@ -1174,188 +1174,233 @@ static int test__all_tracepoints(struct perf_evlist 
*evlist)
 struct evlist_test {
const char *name;
__u32 type;
+   const int id;
int (*check)(struct perf_evlist *evlist);
 };
 
 static struct evlist_test test__events[] = {
-   [0] = {
+   {
.name  = syscalls:sys_enter_open,
.check = test__checkevent_tracepoint,
+   .id= 0,
},
-   [1] = {
+   {
.name  = syscalls:*,
.check = test__checkevent_tracepoint_multi,
+   .id= 1,
},
-   [2] = {
+   {
.name  = r1a,
.check = test__checkevent_raw,
+   .id= 2,
},
-   [3] = {
+   {
.name  = 1:1,
.check = test__checkevent_numeric,
+   .id= 3,
},
-   [4] = {
+   {
.name  = instructions,
.check = test__checkevent_symbolic_name,
+   .id= 4,
},
-   [5] = {
+   {
.name  = cycles/period=10,config2/,
.check = test__checkevent_symbolic_name_config,
+   .id= 5,
},
-   [6] = {
+   {
.name  = faults,
.check = test__checkevent_symbolic_alias,
+   .id= 6,
},
-   [7] = {
+   {
.name  = L1-dcache-load-miss,
.check = test__checkevent_genhw,
+   .id= 7,
},
-   [8] = {
+   {
.name  = mem:0,
.check = test__checkevent_breakpoint,
+   .id= 8,
},
-   [9] = {
+   {
.name  = mem:0:x,
.check = test__checkevent_breakpoint_x,
+   .id= 9,
},
-   [10] = {
+   {
.name  = mem:0:r,
.check = test__checkevent_breakpoint_r,
+   .id= 10,
},
-   [11] = {
+   {
.name  = mem:0:w,
.check = test__checkevent_breakpoint_w,
+   .id= 11,
},
-   [12] = {
+   {
.name  = syscalls:sys_enter_open:k,
.check = test__checkevent_tracepoint_modifier,
+   .id= 12,
},
-   [13] = {
+   {
.name  = syscalls:*:u,
.check = test__checkevent_tracepoint_multi_modifier,
+   .id= 13,
},
-   [14] = {
+   {
.name  = r1a:kp,
.check = test__checkevent_raw_modifier,
+   .id= 14,
},
-   [15] = {
+   {
.name  = 1:1:hp,
.check = test__checkevent_numeric_modifier,
+   .id= 15,
},
-   [16] = {
+   {
.name  = instructions:h,
.check = test__checkevent_symbolic_name_modifier,
+   .id= 16,
},
-   [17] = {
+   {
.name  = faults:u,
.check = test__checkevent_symbolic_alias_modifier,
+   .id= 17,
},
-   [18] = {
+   {
.name  = L1-dcache-load-miss:kp,
.check = test__checkevent_genhw_modifier,
+   .id= 18,
},
-   [19] = {
+   {
.name  = mem:0:u,
.check = 

[tip:perf/core] perf tests: Add a test of kvm-390: trace event

2014-05-01 Thread tip-bot for Alexander Yarygin
Commit-ID:  c0bc8c6d4a2e18e54ef7854a86bc5a47a8e3d04e
Gitweb: http://git.kernel.org/tip/c0bc8c6d4a2e18e54ef7854a86bc5a47a8e3d04e
Author: Alexander Yarygin yary...@linux.vnet.ibm.com
AuthorDate: Fri, 25 Apr 2014 17:34:07 +0200
Committer:  Jiri Olsa jo...@kernel.org
CommitDate: Tue, 29 Apr 2014 14:30:43 +0200

perf tests: Add a test of kvm-390: trace event

Add a s390 specific test of a hardcoded trace event with '-'
in the name.

Signed-off-by: Alexander Yarygin yary...@linux.vnet.ibm.com
Link: 
http://lkml.kernel.org/r/1398440047-6641-4-git-send-email-yary...@linux.vnet.ibm.com
Signed-off-by: Jiri Olsa jo...@kernel.org
---
 tools/perf/tests/parse-events.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-events.c
index 81dbd5a..deba669 100644
--- a/tools/perf/tests/parse-events.c
+++ b/tools/perf/tests/parse-events.c
@@ -1389,6 +1389,13 @@ static struct evlist_test test__events[] = {
.check = test__pinned_group,
.id= 41,
},
+#if defined(__s390x__)
+   {
+   .name  = kvm-s390:kvm_s390_create_vm,
+   .check = test__checkevent_tracepoint,
+   .id= 100,
+   },
+#endif
 };
 
 static struct evlist_test test__events_pmu[] = {
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:perf/urgent] perf kvm: Fix 'Min time' counting in report command

2014-04-20 Thread tip-bot for Alexander Yarygin
Commit-ID:  acb61fc8ed73eb477a9044272d7a1b1f5a572f91
Gitweb: http://git.kernel.org/tip/acb61fc8ed73eb477a9044272d7a1b1f5a572f91
Author: Alexander Yarygin yary...@linux.vnet.ibm.com
AuthorDate: Wed, 9 Apr 2014 16:21:59 +0200
Committer:  Jiri Olsa jo...@redhat.com
CommitDate: Sun, 20 Apr 2014 00:14:08 +0200

perf kvm: Fix 'Min time' counting in report command

Every event in the perf-kvm has a 'stats' structure, which contains
max/min/average/etc times of handling this event.
The problem is that the 'perf-kvm stat report' command always shows
that 'min time' is 0us for every event. Example:

 # perf kvm stat report

 Analyze events for all VCPUs:

VM-EXITSamples  Samples% Time%   Min Time   Max Time Avg time
  [..]
  0xB2 MSCH 12 0.07% 0.00%0us8us 7.31us ( +-   
2.11% )
  0xB2 CHSC 12 0.07% 0.00%0us   18us 9.39us ( +-   
9.49% )
  0xB2 STPX  8 0.05% 0.00%0us2us 1.88us ( +-   
7.18% )
  0xB2 STSI  7 0.04% 0.00%0us   44us 16.49us ( +-  
38.20% )
  [..]

This happens because the 'stats' structure is not initialized and
stats-min equals to 0. Lets initialize the structure for every
event after its allocation using init_stats() function. This initializes
stats-min to -1 and makes 'Min time' statistics counting work:

 # perf kvm stat report

 Analyze events for all VCPUs:

VM-EXITSamples  Samples% Time%   Min Time   Max Time Avg time
  [..]
  0xB2 MSCH 12 0.07% 0.00%6us8us 7.31us ( +-   
2.11% )
  0xB2 CHSC 12 0.07% 0.00%7us   18us 9.39us ( +-   
9.49% )
  0xB2 STPX  8 0.05% 0.00%1us2us 1.88us ( +-   
7.18% )
  0xB2 STSI  7 0.04% 0.00%1us   44us 16.49us ( +-  
38.20% )
  [..]

Signed-off-by: Alexander Yarygin yary...@linux.vnet.ibm.com
Signed-off-by: Christian Borntraeger borntrae...@de.ibm.com
Reviewed-by: David Ahern dsah...@gmail.com
Link: 
http://lkml.kernel.org/r/1397053319-2130-3-git-send-email-borntrae...@de.ibm.com
[ Fixing the perf examples changelog output ]
Signed-off-by: Jiri Olsa jo...@redhat.com
---
 tools/perf/builtin-kvm.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index 21c164b..0f1e5a2 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -404,6 +404,7 @@ static struct kvm_event *kvm_alloc_init_event(struct 
event_key *key)
}
 
event-key = *key;
+   init_stats(event-total.stats);
return event;
 }
 
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:perf/core] perf kvm: Refactoring of cpu_isa_config()

2014-07-16 Thread tip-bot for Alexander Yarygin
Commit-ID:  65c647a65c155e69bd5765d5e454982566ac1c62
Gitweb: http://git.kernel.org/tip/65c647a65c155e69bd5765d5e454982566ac1c62
Author: Alexander Yarygin yary...@linux.vnet.ibm.com
AuthorDate: Thu, 3 Jul 2014 17:59:51 +0400
Committer:  Arnaldo Carvalho de Melo a...@redhat.com
CommitDate: Mon, 7 Jul 2014 16:55:24 -0300

perf kvm: Refactoring of cpu_isa_config()

cpu_isa_config() does two different things: searching for cpuid and
initializing perf_kvm_stat struct with proper parameters.

Let's move initialization to a separate function cpu_isa_init(), which
is used to initialize all possible ISAs and can be used to init
arch-depended things.

Reviewed-by: Cornelia Huck cornelia.h...@de.ibm.com
Reviewed-by: David Ahern dsah...@gmail.com
Signed-off-by: Alexander Yarygin yary...@linux.vnet.ibm.com
Acked-by: Christian Borntraeger borntrae...@de.ibm.com
Cc: Christian Borntraeger borntrae...@de.ibm.com
Cc: Cornelia Huck cornelia.h...@de.ibm.com
Cc: David Ahern dsah...@gmail.com
Cc: Jiri Olsa jo...@redhat.com
Cc: Paul Mackerras pau...@samba.org
Cc: Peter Zijlstra a.p.zijls...@chello.nl
Link: 
http://lkml.kernel.org/r/1404395992-17095-4-git-send-email-yary...@linux.vnet.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo a...@redhat.com
---
 tools/perf/builtin-kvm.c | 39 +++
 1 file changed, 23 insertions(+), 16 deletions(-)

diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index 75f3544..41dbeaf 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -835,36 +835,45 @@ 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;
-   int err, isa;
+   int err;
 
if (kvm-live) {
err = get_cpuid(buf, sizeof(buf));
if (err != 0) {
-   pr_err(Failed to look up CPU type (Intel or AMD)\n);
+   pr_err(Failed to look up CPU type\n);
return err;
}
cpuid = buf;
} else
cpuid = kvm-session-header.env.cpuid;
 
-   if (strstr(cpuid, Intel))
-   isa = 1;
-   else if (strstr(cpuid, AMD))
-   isa = 0;
-   else {
-   pr_err(CPU %s is not supported.\n, cpuid);
-   return -ENOTSUP;
+   if (!cpuid) {
+   pr_err(Failed to look up CPU type\n);
+   return -EINVAL;
}
 
-   if (isa == 1) {
-   kvm-exit_reasons = vmx_exit_reasons;
-   kvm-exit_reasons_isa = VMX;
-   }
+   err = cpu_isa_init(kvm, cpuid);
+   if (err == -ENOTSUP)
+   pr_err(CPU %s is not supported.\n, cpuid);
 
-   return 0;
+   return err;
 }
 
 static bool verify_vcpu(int vcpu)
@@ -1583,8 +1592,6 @@ static int kvm_cmd_stat(const char *file_name, int argc, 
const char **argv)
.report_event   = vmexit,
.sort_key   = sample,
 
-   .exit_reasons = svm_exit_reasons,
-   .exit_reasons_isa = SVM,
};
 
if (argc == 1) {
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:perf/core] perf kvm: Simplify exit reasons tables definitions

2014-07-16 Thread tip-bot for Alexander Yarygin
Commit-ID:  df74c13b6c53c97576652f7b2840764ad7d5f949
Gitweb: http://git.kernel.org/tip/df74c13b6c53c97576652f7b2840764ad7d5f949
Author: Alexander Yarygin yary...@linux.vnet.ibm.com
AuthorDate: Thu, 3 Jul 2014 17:59:50 +0400
Committer:  Arnaldo Carvalho de Melo a...@redhat.com
CommitDate: Mon, 7 Jul 2014 16:55:24 -0300

perf kvm: Simplify exit reasons tables definitions

The perf_kvm_stat struct keeps the size of a table of exit reasons in
the field 'exit_reasons_size'.

The field is initialized and then used by get_exit_reason() for serial
access to the table, so that the calling function does not actually need
to know table size.

Usage of tables with 'end of sequence' marker simplifies the
get_exit_reason() function.

Also the patch introduces a define_exit_reasons_table, which makes it
easier to define new tables.

Reviewed-by: Cornelia Huck cornelia.h...@de.ibm.com
Reviewed-by: David Ahern dsah...@gmail.com
Signed-off-by: Alexander Yarygin yary...@linux.vnet.ibm.com
Acked-by: Christian Borntraeger borntrae...@de.ibm.com
Cc: Christian Borntraeger borntrae...@de.ibm.com
Cc: Cornelia Huck cornelia.h...@de.ibm.com
Cc: David Ahern dsah...@gmail.com
Cc: Jiri Olsa jo...@redhat.com
Cc: Paul Mackerras pau...@samba.org
Cc: Peter Zijlstra a.p.zijls...@chello.nl
Link: 
http://lkml.kernel.org/r/1404395992-17095-3-git-send-email-yary...@linux.vnet.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo a...@redhat.com
---
 tools/perf/builtin-kvm.c | 27 ---
 1 file changed, 12 insertions(+), 15 deletions(-)

diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index 214ec0e..75f3544 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -99,7 +99,6 @@ struct perf_kvm_stat {
int trace_vcpu;
 
struct exit_reasons_table *exit_reasons;
-   int exit_reasons_size;
const char *exit_reasons_isa;
 
struct kvm_events_ops *events_ops;
@@ -158,20 +157,19 @@ static bool exit_event_end(struct perf_evsel *evsel,
return kvm_entry_event(evsel);
 }
 
-static struct exit_reasons_table vmx_exit_reasons[] = {
-   VMX_EXIT_REASONS
-};
+#define define_exit_reasons_table(name, symbols)   \
+   static struct exit_reasons_table name[] = { \
+   symbols, { -1, NULL }   \
+   }
 
-static struct exit_reasons_table svm_exit_reasons[] = {
-   SVM_EXIT_REASONS
-};
+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, u64 exit_code)
+static const char *get_exit_reason(struct perf_kvm_stat *kvm,
+  struct exit_reasons_table *tbl,
+  u64 exit_code)
 {
-   int i = kvm-exit_reasons_size;
-   struct exit_reasons_table *tbl = kvm-exit_reasons;
-
-   while (i--) {
+   while (tbl-reason != NULL) {
if (tbl-exit_code == exit_code)
return tbl-reason;
tbl++;
@@ -186,7 +184,8 @@ static void exit_event_decode_key(struct perf_kvm_stat *kvm,
  struct event_key *key,
  char decode[20])
 {
-   const char *exit_reason = get_exit_reason(kvm, key-key);
+   const char *exit_reason = get_exit_reason(kvm, kvm-exit_reasons,
+ key-key);
 
scnprintf(decode, 20, %s, exit_reason);
 }
@@ -862,7 +861,6 @@ static int cpu_isa_config(struct perf_kvm_stat *kvm)
 
if (isa == 1) {
kvm-exit_reasons = vmx_exit_reasons;
-   kvm-exit_reasons_size = ARRAY_SIZE(vmx_exit_reasons);
kvm-exit_reasons_isa = VMX;
}
 
@@ -1586,7 +1584,6 @@ static int kvm_cmd_stat(const char *file_name, int argc, 
const char **argv)
.sort_key   = sample,
 
.exit_reasons = svm_exit_reasons,
-   .exit_reasons_size = ARRAY_SIZE(svm_exit_reasons),
.exit_reasons_isa = SVM,
};
 
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:perf/core] perf tools: Allow to use cpuinfo on s390

2014-07-16 Thread tip-bot for Alexander Yarygin
Commit-ID:  f8d9ccde2be4c24bfb8787af36a59a981b00a02d
Gitweb: http://git.kernel.org/tip/f8d9ccde2be4c24bfb8787af36a59a981b00a02d
Author: Alexander Yarygin yary...@linux.vnet.ibm.com
AuthorDate: Thu, 3 Jul 2014 18:08:22 +0400
Committer:  Arnaldo Carvalho de Melo a...@redhat.com
CommitDate: Mon, 7 Jul 2014 16:55:24 -0300

perf tools: Allow to use cpuinfo on s390

This patch defines CPUINFO_PROC for s390 and implements get_cpuid().

Reviewed-by: Cornelia Huck cornelia.h...@de.ibm.com
Reviewed-by: David Ahern dsah...@gmail.com
Signed-off-by: Alexander Yarygin yary...@linux.vnet.ibm.com
Acked-by: Christian Borntraeger borntrae...@de.ibm.com
Cc: Christian Borntraeger borntrae...@de.ibm.com
Cc: Cornelia Huck cornelia.h...@de.ibm.com
Cc: David Ahern dsah...@gmail.com
Cc: Jiri Olsa jo...@redhat.com
Cc: Paul Mackerras pau...@samba.org
Cc: Peter Zijlstra a.p.zijls...@chello.nl
Link: http://lkml.kernel.org/r/87ioneo7qh.wl%yary...@linux.vnet.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo a...@redhat.com
---
 tools/perf/arch/s390/Makefile  |  1 +
 tools/perf/arch/s390/util/header.c | 28 
 tools/perf/perf-sys.h  |  1 +
 3 files changed, 30 insertions(+)

diff --git a/tools/perf/arch/s390/Makefile b/tools/perf/arch/s390/Makefile
index 15130b5..744e629 100644
--- a/tools/perf/arch/s390/Makefile
+++ b/tools/perf/arch/s390/Makefile
@@ -2,3 +2,4 @@ ifndef NO_DWARF
 PERF_HAVE_DWARF_REGS := 1
 LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/dwarf-regs.o
 endif
+LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/header.o
diff --git a/tools/perf/arch/s390/util/header.c 
b/tools/perf/arch/s390/util/header.c
new file mode 100644
index 000..9fa6c3e
--- /dev/null
+++ b/tools/perf/arch/s390/util/header.c
@@ -0,0 +1,28 @@
+/*
+ * Implementation of get_cpuid().
+ *
+ * Copyright 2014 IBM Corp.
+ * Author(s): Alexander Yarygin yary...@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 sys/types.h
+#include unistd.h
+#include stdio.h
+#include string.h
+
+#include ../../util/header.h
+
+int get_cpuid(char *buffer, size_t sz)
+{
+   const char *cpuid = IBM/S390;
+
+   if (strlen(cpuid) + 1  sz)
+   return -1;
+
+   strcpy(buffer, cpuid);
+   return 0;
+}
diff --git a/tools/perf/perf-sys.h b/tools/perf/perf-sys.h
index 5268a14..937e432 100644
--- a/tools/perf/perf-sys.h
+++ b/tools/perf/perf-sys.h
@@ -54,6 +54,7 @@
 #define mb()   asm volatile(bcr 15,0 ::: memory)
 #define wmb()  asm volatile(bcr 15,0 ::: memory)
 #define rmb()  asm volatile(bcr 15,0 ::: memory)
+#define CPUINFO_PROC   vendor_id
 #endif
 
 #ifdef __sh__
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:perf/core] perf kvm: Introduce HAVE_KVM_STAT_SUPPORT flag

2014-07-16 Thread tip-bot for Alexander Yarygin
Commit-ID:  da50ad69723111e0292f1943dad77b41bb9a25b0
Gitweb: http://git.kernel.org/tip/da50ad69723111e0292f1943dad77b41bb9a25b0
Author: Alexander Yarygin yary...@linux.vnet.ibm.com
AuthorDate: Thu, 3 Jul 2014 17:59:49 +0400
Committer:  Arnaldo Carvalho de Melo a...@redhat.com
CommitDate: Mon, 7 Jul 2014 16:55:23 -0300

perf kvm: Introduce HAVE_KVM_STAT_SUPPORT flag

kvm stat support is currently conditional on i386/x86_64. Let's abstract
this into a HAVE_KVM_STAT_SUPPORT flag, so that other architectures can
support kvm stat as well.

Reviewed-by: Cornelia Huck cornelia.h...@de.ibm.com
Reviewed-by: David Ahern dsah...@gmail.com
Signed-off-by: Alexander Yarygin yary...@linux.vnet.ibm.com
Acked-by: Christian Borntraeger borntrae...@de.ibm.com
Cc: Christian Borntraeger borntrae...@de.ibm.com
Cc: Cornelia Huck cornelia.h...@de.ibm.com
Cc: David Ahern dsah...@gmail.com
Cc: Jiri Olsa jo...@redhat.com
Cc: Paul Mackerras pau...@samba.org
Cc: Peter Zijlstra a.p.zijls...@chello.nl
Link: 
http://lkml.kernel.org/r/1404395992-17095-2-git-send-email-yary...@linux.vnet.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo a...@redhat.com
---
 tools/perf/arch/x86/Makefile | 1 +
 tools/perf/builtin-kvm.c | 6 +++---
 tools/perf/config/Makefile   | 4 
 3 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/tools/perf/arch/x86/Makefile b/tools/perf/arch/x86/Makefile
index 1641542..d393901 100644
--- a/tools/perf/arch/x86/Makefile
+++ b/tools/perf/arch/x86/Makefile
@@ -15,3 +15,4 @@ endif
 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
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index 0f1e5a2..214ec0e 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -29,7 +29,7 @@
 #include pthread.h
 #include math.h
 
-#if defined(__i386__) || defined(__x86_64__)
+#ifdef HAVE_KVM_STAT_SUPPORT
 #include asm/svm.h
 #include asm/vmx.h
 #include asm/kvm.h
@@ -1609,7 +1609,7 @@ static int kvm_cmd_stat(const char *file_name, int argc, 
const char **argv)
 perf_stat:
return cmd_stat(argc, argv, NULL);
 }
-#endif
+#endif /* HAVE_KVM_STAT_SUPPORT */
 
 static int __cmd_record(const char *file_name, int argc, const char **argv)
 {
@@ -1726,7 +1726,7 @@ int cmd_kvm(int argc, const char **argv, const char 
*prefix __maybe_unused)
return cmd_top(argc, argv, NULL);
else if (!strncmp(argv[0], buildid-list, 12))
return __cmd_buildid_list(file_name, argc, argv);
-#if defined(__i386__) || defined(__x86_64__)
+#ifdef HAVE_KVM_STAT_SUPPORT
else if (!strncmp(argv[0], stat, 4))
return kvm_cmd_stat(file_name, argc, argv);
 #endif
diff --git a/tools/perf/config/Makefile b/tools/perf/config/Makefile
index 346bdb6..b7f42d5 100644
--- a/tools/perf/config/Makefile
+++ b/tools/perf/config/Makefile
@@ -594,6 +594,10 @@ ifndef NO_LIBNUMA
   endif
 endif
 
+ifdef HAVE_KVM_STAT_SUPPORT
+CFLAGS += -DHAVE_KVM_STAT_SUPPORT
+endif
+
 # Among the variables below, these:
 #   perfexecdir
 #   template_dir
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:perf/core] perf kvm: Add skip_event() for --duration option

2014-07-17 Thread tip-bot for Alexander Yarygin
Commit-ID:  54c801ff71ba9c9ae41871e226b9d846ff9c6bab
Gitweb: http://git.kernel.org/tip/54c801ff71ba9c9ae41871e226b9d846ff9c6bab
Author: Alexander Yarygin yary...@linux.vnet.ibm.com
AuthorDate: Thu, 3 Jul 2014 18:29:06 +0400
Committer:  Arnaldo Carvalho de Melo a...@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 borntrae...@de.ibm.com
Reviewed-by: Cornelia Huck cornelia.h...@de.ibm.com
Reviewed-by: David Ahern dsah...@gmail.com
Signed-off-by: Alexander Yarygin yary...@linux.vnet.ibm.com
Cc: Christian Borntraeger borntrae...@de.ibm.com
Cc: Cornelia Huck cornelia.h...@de.ibm.com
Cc: David Ahern dsah...@gmail.com
Cc: Ingo Molnar mi...@kernel.org
Cc: Jiri Olsa jo...@redhat.com
Cc: Paul Mackerras pau...@samba.org
Cc: Peter Zijlstra a.p.zijls...@chello.nl
Link: 
http://lkml.kernel.org/r/1404397747-20939-4-git-send-email-yary...@linux.vnet.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo a...@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 */
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:perf/core] perf kvm: Add stat support on s390

2014-07-17 Thread tip-bot for Alexander Yarygin
Commit-ID:  3be8e2a0a53c3179a44a933614f6a893da0b5c19
Gitweb: http://git.kernel.org/tip/3be8e2a0a53c3179a44a933614f6a893da0b5c19
Author: Alexander Yarygin yary...@linux.vnet.ibm.com
AuthorDate: Thu, 3 Jul 2014 18:29:07 +0400
Committer:  Arnaldo Carvalho de Melo a...@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 dsah...@gmail.com
Signed-off-by: Alexander Yarygin yary...@linux.vnet.ibm.com
Acked-by: Christian Borntraeger borntrae...@de.ibm.com
Cc: Christian Borntraeger borntrae...@de.ibm.com
Cc: Cornelia Huck cornelia.h...@de.ibm.com
Cc: David Ahern dsah...@gmail.com
Cc: Ingo Molnar mi...@kernel.org
Cc: Jiri Olsa jo...@redhat.com
Cc: Paul Mackerras pau...@samba.org
Cc: Peter Zijlstra a.p.zijls...@chello.nl
Link: 
http://lkml.kernel.org/r/1404397747-20939-5-git-send-email-yary...@linux.vnet.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo a...@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 000..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 yary...@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 

[tip:perf/core] perf kvm: Use defines of kvm events

2014-07-17 Thread tip-bot for Alexander Yarygin
Commit-ID:  44b3802122174ba499613bac3aab2e66e948ce1e
Gitweb: http://git.kernel.org/tip/44b3802122174ba499613bac3aab2e66e948ce1e
Author: Alexander Yarygin yary...@linux.vnet.ibm.com
AuthorDate: Thu, 3 Jul 2014 18:29:04 +0400
Committer:  Arnaldo Carvalho de Melo a...@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.h...@de.ibm.com
Reviewed-by David Ahern dsah...@gmail.com
Signed-off-by: Alexander Yarygin yary...@linux.vnet.ibm.com
Acked-by: Christian Borntraeger borntrae...@de.ibm.com
Cc: Christian Borntraeger borntrae...@de.ibm.com
Cc: Cornelia Huck cornelia.h...@de.ibm.com
Cc: David Ahern dsah...@gmail.com
Cc: Ingo Molnar mi...@kernel.org
Cc: Jiri Olsa jo...@redhat.com
Cc: Paul Mackerras pau...@samba.org
Cc: Peter Zijlstra a.p.zijls...@chello.nl
Link: 
http://lkml.kernel.org/r/1404397747-20939-2-git-send-email-yary...@linux.vnet.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo a...@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 000..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);
+   

[tip:perf/core] perf kvm: Move arch specific code into arch/

2014-07-17 Thread tip-bot for Alexander Yarygin
Commit-ID:  9daa81239e60c162153fb2a365b8492c9a9bf632
Gitweb: http://git.kernel.org/tip/9daa81239e60c162153fb2a365b8492c9a9bf632
Author: Alexander Yarygin yary...@linux.vnet.ibm.com
AuthorDate: Thu, 3 Jul 2014 18:29:05 +0400
Committer:  Arnaldo Carvalho de Melo a...@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 dsah...@gmail.com
Reviewed-by: Cornelia Huck cornelia.h...@de.ibm.com
Signed-off-by: Alexander Yarygin yary...@linux.vnet.ibm.com
Acked-by: Christian Borntraeger borntrae...@de.ibm.com
Cc: Christian Borntraeger borntrae...@de.ibm.com
Cc: Cornelia Huck cornelia.h...@de.ibm.com
Cc: David Ahern dsah...@gmail.com
Cc: Ingo Molnar mi...@kernel.org
Cc: Jiri Olsa jo...@redhat.com
Cc: Paul Mackerras pau...@samba.org
Cc: Peter Zijlstra a.p.zijls...@chello.nl
Link: 
http://lkml.kernel.org/r/1404397747-20939-3-git-send-email-yary...@linux.vnet.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo a...@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 000..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 

[tip:perf/urgent] perf kvm stat live: Enable events copying

2014-10-15 Thread tip-bot for Alexander Yarygin
Commit-ID:  673d659f5c5918b7ddbafebf1f129c9eb82973b4
Gitweb: http://git.kernel.org/tip/673d659f5c5918b7ddbafebf1f129c9eb82973b4
Author: Alexander Yarygin yary...@linux.vnet.ibm.com
AuthorDate: Fri, 3 Oct 2014 18:40:12 +0400
Committer:  Arnaldo Carvalho de Melo a...@redhat.com
CommitDate: Wed, 15 Oct 2014 17:39:03 -0300

perf kvm stat live: Enable events copying

Process of analyzing events caused by 2 functions: mmap_read() and
finished_round().

During mmap_read(), perf receives events from shared memory, queues
their pointers for further processing in finished_round() and notifies
the kernel that the events have been processed.

By the time when finished_round() is invoked, queued events can be
overwritten by the kernel, so the finished_round() occurs on potentially
corrupted memory.

Since there is no place where the event can be safely consumed, let's
copy events when queueing.

Signed-off-by: Alexander Yarygin yary...@linux.vnet.ibm.com
Cc: Christian Borntraeger borntrae...@de.ibm.com
Cc: David Ahern dsah...@gmail.com
Cc: Frederic Weisbecker fweis...@gmail.com
Cc: Ingo Molnar mi...@kernel.org
Cc: Jiri Olsa jo...@redhat.com
Cc: Mike Galbraith efa...@gmx.de
Cc: Namhyung Kim namhyung@lge.com
Cc: Paul Mackerras pau...@samba.org
Cc: Peter Zijlstra a.p.zijls...@chello.nl
Cc: Stephane Eranian eran...@google.com
Link: 
http://lkml.kernel.org/r/1412347212-28237-3-git-send-email-yary...@linux.vnet.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo a...@redhat.com
---
 tools/perf/builtin-kvm.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index ef9fc15..b65eb050 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -1358,6 +1358,7 @@ static int kvm_events_live(struct perf_kvm_stat *kvm,
}
kvm-session-evlist = kvm-evlist;
perf_session__set_id_hdr_size(kvm-session);
+   ordered_events__set_copy_on_queue(kvm-session-ordered_events, true);
machine__synthesize_threads(kvm-session-machines.host, 
kvm-opts.target,
kvm-evlist-threads, false);
err = kvm_live_open_events(kvm);
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:perf/urgent] perf session: Add option to copy events when queueing

2014-10-15 Thread tip-bot for Alexander Yarygin
Commit-ID:  54bf53b1cb9150b894213a705c562d52388376ef
Gitweb: http://git.kernel.org/tip/54bf53b1cb9150b894213a705c562d52388376ef
Author: Alexander Yarygin yary...@linux.vnet.ibm.com
AuthorDate: Fri, 3 Oct 2014 18:40:11 +0400
Committer:  Arnaldo Carvalho de Melo a...@redhat.com
CommitDate: Wed, 15 Oct 2014 17:39:03 -0300

perf session: Add option to copy events when queueing

When processing events the session code has an ordered samples queue
which is used to time-sort events coming in across multiple mmaps. At a
later point in time samples on the queue are flushed up to some
timestamp at which point the event is actually processed.

When analyzing events live (ie., record/analysis path in the same
command) there is a race that leads to corrupted events and parse errors
which cause perf to terminate. The problem is that when the event is
placed in the ordered samples queue it is only a reference to the event
which is really sitting in the mmap buffer. Even though the event is
queued for later processing the mmap tail pointer is updated which
indicates to the kernel that the event has been processed. The race is
flushing the event from the queue before it gets overwritten by some
other event. For commands trying to process events live (versus just
writing to a file) and processing a high rate of events this leads to
parse failures and perf terminates.

Examples hitting this problem are 'perf kvm stat live', especially with
nested VMs which generate 100,000+ traces per second, and a command
processing scheduling events with a high rate of context switching --
e.g., running 'perf bench sched pipe'.

This patch offers live commands an option to copy the event when it is
placed in the ordered samples queue.

Based on a patch from David Ahern dsah...@gmail.com

Signed-off-by: Alexander Yarygin yary...@linux.vnet.ibm.com
Acked-by: Jiri Olsa jo...@kernel.org
Cc: Christian Borntraeger borntrae...@de.ibm.com
Cc: David Ahern dsah...@gmail.com
Cc: Frederic Weisbecker fweis...@gmail.com
Cc: Ingo Molnar mi...@kernel.org
Cc: Jiri Olsa jo...@redhat.com
Cc: Mike Galbraith efa...@gmx.de
Cc: Namhyung Kim namhyung@lge.com
Cc: Paul Mackerras pau...@samba.org
Cc: Peter Zijlstra a.p.zijls...@chello.nl
Cc: Stephane Eranian eran...@google.com
Link: 
http://lkml.kernel.org/r/1412347212-28237-2-git-send-email-yary...@linux.vnet.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo a...@redhat.com
---
 tools/perf/util/ordered-events.c | 49 
 tools/perf/util/ordered-events.h | 10 +++-
 tools/perf/util/session.c|  5 ++--
 3 files changed, 56 insertions(+), 8 deletions(-)

diff --git a/tools/perf/util/ordered-events.c b/tools/perf/util/ordered-events.c
index 706ce1a..fd4be94 100644
--- a/tools/perf/util/ordered-events.c
+++ b/tools/perf/util/ordered-events.c
@@ -1,5 +1,6 @@
 #include linux/list.h
 #include linux/compiler.h
+#include linux/string.h
 #include ordered-events.h
 #include evlist.h
 #include session.h
@@ -57,11 +58,45 @@ static void queue_event(struct ordered_events *oe, struct 
ordered_event *new)
}
 }
 
+static union perf_event *__dup_event(struct ordered_events *oe,
+union perf_event *event)
+{
+   union perf_event *new_event = NULL;
+
+   if (oe-cur_alloc_size  oe-max_alloc_size) {
+   new_event = memdup(event, event-header.size);
+   if (new_event)
+   oe-cur_alloc_size += event-header.size;
+   }
+
+   return new_event;
+}
+
+static union perf_event *dup_event(struct ordered_events *oe,
+  union perf_event *event)
+{
+   return oe-copy_on_queue ? __dup_event(oe, event) : event;
+}
+
+static void free_dup_event(struct ordered_events *oe, union perf_event *event)
+{
+   if (oe-copy_on_queue) {
+   oe-cur_alloc_size -= event-header.size;
+   free(event);
+   }
+}
+
 #define MAX_SAMPLE_BUFFER  (64 * 1024 / sizeof(struct ordered_event))
-static struct ordered_event *alloc_event(struct ordered_events *oe)
+static struct ordered_event *alloc_event(struct ordered_events *oe,
+union perf_event *event)
 {
struct list_head *cache = oe-cache;
struct ordered_event *new = NULL;
+   union perf_event *new_event;
+
+   new_event = dup_event(oe, event);
+   if (!new_event)
+   return NULL;
 
if (!list_empty(cache)) {
new = list_entry(cache-next, struct ordered_event, list);
@@ -74,8 +109,10 @@ static struct ordered_event *alloc_event(struct 
ordered_events *oe)
size_t size = MAX_SAMPLE_BUFFER * sizeof(*new);
 
oe-buffer = malloc(size);
-   if (!oe-buffer)
+   if (!oe-buffer) {
+   free_dup_event(oe, new_event);
return NULL;
+   }
 
pr(alloc size % PRIu64 B (+%zu), max % PRIu64 

[tip:perf/core] perf kvm stat report: Save pid string in opts.target.pid

2014-09-18 Thread tip-bot for Alexander Yarygin
Commit-ID:  3ae4a76ac840021294c091884e04af7c92e481ae
Gitweb: http://git.kernel.org/tip/3ae4a76ac840021294c091884e04af7c92e481ae
Author: Alexander Yarygin yary...@linux.vnet.ibm.com
AuthorDate: Mon, 1 Sep 2014 17:44:53 +0400
Committer:  Arnaldo Carvalho de Melo a...@redhat.com
CommitDate: Wed, 17 Sep 2014 17:08:07 -0300

perf kvm stat report: Save pid string in opts.target.pid

The 'perf kvm stat report' command uses the kvm-pid_str field to keep
the value of the --pid option. Let's use kvm-opts.target.pid instead.

Signed-off-by: Alexander Yarygin yary...@linux.vnet.ibm.com
Acked-by: David Ahern dsah...@gmail.com
Cc: Christian Borntraeger borntrae...@de.ibm.com
Cc: David Ahern dsah...@gmail.com
Cc: Ingo Molnar mi...@kernel.org
Cc: Jiri Olsa jo...@kernel.org
Cc: Paul Mackerras pau...@samba.org
Cc: Peter Zijlstra a.p.zijls...@chello.nl
Link: 
http://lkml.kernel.org/r/1409579095-12963-2-git-send-email-yary...@linux.vnet.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo a...@redhat.com
---
 tools/perf/builtin-kvm.c   | 6 +++---
 tools/perf/util/kvm-stat.h | 1 -
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index 1a4ef9c..646ec5d 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -1085,8 +1085,8 @@ static int read_events(struct perf_kvm_stat *kvm)
 
 static int parse_target_str(struct perf_kvm_stat *kvm)
 {
-   if (kvm-pid_str) {
-   kvm-pid_list = intlist__new(kvm-pid_str);
+   if (kvm-opts.target.pid) {
+   kvm-pid_list = intlist__new(kvm-opts.target.pid);
if (kvm-pid_list == NULL) {
pr_err(Error parsing process id string\n);
return -EINVAL;
@@ -1188,7 +1188,7 @@ kvm_events_report(struct perf_kvm_stat *kvm, int argc, 
const char **argv)
OPT_STRING('k', key, kvm-sort_key, sort-key,
key for sorting: sample(sort by samples number)
 time (sort by avg time)),
-   OPT_STRING('p', pid, kvm-pid_str, pid,
+   OPT_STRING('p', pid, kvm-opts.target.pid, pid,
   analyze events only for given process id(s)),
OPT_END()
};
diff --git a/tools/perf/util/kvm-stat.h b/tools/perf/util/kvm-stat.h
index 0b5a8cd..cf1d7913 100644
--- a/tools/perf/util/kvm-stat.h
+++ b/tools/perf/util/kvm-stat.h
@@ -92,7 +92,6 @@ struct perf_kvm_stat {
u64 lost_events;
u64 duration;
 
-   const char *pid_str;
struct intlist *pid_list;
 
struct rb_root result;
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:perf/core] perf kvm stat report: Unify the title bar output

2014-09-18 Thread tip-bot for Alexander Yarygin
Commit-ID:  1f3e5b55035549311e42c3f84007e6c799ed991f
Gitweb: http://git.kernel.org/tip/1f3e5b55035549311e42c3f84007e6c799ed991f
Author: Alexander Yarygin yary...@linux.vnet.ibm.com
AuthorDate: Mon, 1 Sep 2014 17:44:55 +0400
Committer:  Arnaldo Carvalho de Melo a...@redhat.com
CommitDate: Wed, 17 Sep 2014 17:08:08 -0300

perf kvm stat report: Unify the title bar output

The 'live' command prints additional information to the Analyze events
for  title bar about the current target.  Let's print the same title
for the 'report' command.

Signed-off-by: Alexander Yarygin yary...@linux.vnet.ibm.com
Acked-by: David Ahern dsah...@gmail.com
Cc: Christian Borntraeger borntrae...@de.ibm.com
Cc: David Ahern dsah...@gmail.com
Cc: Ingo Molnar mi...@kernel.org
Cc: Jiri Olsa jo...@kernel.org
Cc: Paul Mackerras pau...@samba.org
Cc: Peter Zijlstra a.p.zijls...@chello.nl
Link: 
http://lkml.kernel.org/r/1409579095-12963-4-git-send-email-yary...@linux.vnet.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo a...@redhat.com
---
 tools/perf/builtin-kvm.c | 14 ++
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index 84295ab..f5d3ae4 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -543,14 +543,12 @@ static void print_vcpu_info(struct perf_kvm_stat *kvm)
 
pr_info(Analyze events for );
 
-   if (kvm-live) {
-   if (kvm-opts.target.system_wide)
-   pr_info(all VMs, );
-   else if (kvm-opts.target.pid)
-   pr_info(pid(s) %s, , kvm-opts.target.pid);
-   else
-   pr_info(dazed and confused on what is monitored, );
-   }
+   if (kvm-opts.target.system_wide)
+   pr_info(all VMs, );
+   else if (kvm-opts.target.pid)
+   pr_info(pid(s) %s, , kvm-opts.target.pid);
+   else
+   pr_info(dazed and confused on what is monitored, );
 
if (vcpu == -1)
pr_info(all VCPUs:\n\n);
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:perf/core] perf kvm stat report: Enable the target.system_wide flag

2014-09-18 Thread tip-bot for Alexander Yarygin
Commit-ID:  f181957c2849478fc963a8ac3c7dacf0a87c6b05
Gitweb: http://git.kernel.org/tip/f181957c2849478fc963a8ac3c7dacf0a87c6b05
Author: Alexander Yarygin yary...@linux.vnet.ibm.com
AuthorDate: Mon, 1 Sep 2014 17:44:54 +0400
Committer:  Arnaldo Carvalho de Melo a...@redhat.com
CommitDate: Wed, 17 Sep 2014 17:08:07 -0300

perf kvm stat report: Enable the target.system_wide flag

The 'perf kvm stat report' command can be used to analyze events either
for system wide or for specific pids.

Let's enable kvm-opts.target.system_wide flag when 'report' command is
running for system-wide analyzing. This helps to sync kvm-opts.target
values in 'report' and 'live' commands.

Signed-off-by: Alexander Yarygin yary...@linux.vnet.ibm.com
Acked-by: David Ahern dsah...@gmail.com
Cc: Christian Borntraeger borntrae...@de.ibm.com
Cc: David Ahern dsah...@gmail.com
Cc: Ingo Molnar mi...@kernel.org
Cc: Jiri Olsa jo...@kernel.org
Cc: Paul Mackerras pau...@samba.org
Cc: Peter Zijlstra a.p.zijls...@chello.nl
Link: 
http://lkml.kernel.org/r/1409579095-12963-3-git-send-email-yary...@linux.vnet.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo a...@redhat.com
---
 tools/perf/builtin-kvm.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index 646ec5d..84295ab 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -1207,6 +1207,9 @@ kvm_events_report(struct perf_kvm_stat *kvm, int argc, 
const char **argv)
   kvm_events_report_options);
}
 
+   if (!kvm-opts.target.pid)
+   kvm-opts.target.system_wide = true;
+
return kvm_events_report_vcpu(kvm);
 }
 
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:perf/urgent] perf kvm stat live: Mark events as (x86 only) in help output

2014-12-12 Thread tip-bot for Alexander Yarygin
Commit-ID:  99d348a84c2118ed04c9b72168787f55e2fe33a5
Gitweb: http://git.kernel.org/tip/99d348a84c2118ed04c9b72168787f55e2fe33a5
Author: Alexander Yarygin yary...@linux.vnet.ibm.com
AuthorDate: Wed, 10 Dec 2014 14:28:10 +0100
Committer:  Arnaldo Carvalho de Melo a...@redhat.com
CommitDate: Wed, 10 Dec 2014 12:08:59 -0300

perf kvm stat live: Mark events as (x86 only) in help output

The mmio and ioport events are useful only on x86.

Signed-off-by: Alexander Yarygin yary...@linux.vnet.ibm.com
Acked-by: David Ahern dsah...@gmail.com
Cc: Christian Borntraeger borntrae...@de.ibm.com
Cc: Jiri Olsa jo...@kernel.org
Link: 
http://lkml.kernel.org/r/1418218090-20718-1-git-send-email-borntrae...@de.ibm.com
Signed-off-by: Christian Borntraeger borntrae...@de.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo a...@redhat.com
---
 tools/perf/builtin-kvm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index 3c0f3d4..0894a81 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -1293,7 +1293,8 @@ static int kvm_events_live(struct perf_kvm_stat *kvm,
OPT_UINTEGER('d', display, kvm-display_time,
time in seconds between display updates),
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,
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:perf/urgent] perf kvm: Fix 'Min time' counting in report command

2014-04-20 Thread tip-bot for Alexander Yarygin
Commit-ID:  acb61fc8ed73eb477a9044272d7a1b1f5a572f91
Gitweb: http://git.kernel.org/tip/acb61fc8ed73eb477a9044272d7a1b1f5a572f91
Author: Alexander Yarygin 
AuthorDate: Wed, 9 Apr 2014 16:21:59 +0200
Committer:  Jiri Olsa 
CommitDate: Sun, 20 Apr 2014 00:14:08 +0200

perf kvm: Fix 'Min time' counting in report command

Every event in the perf-kvm has a 'stats' structure, which contains
max/min/average/etc times of handling this event.
The problem is that the 'perf-kvm stat report' command always shows
that 'min time' is 0us for every event. Example:

 # perf kvm stat report

 Analyze events for all VCPUs:

VM-EXITSamples  Samples% Time%   Min Time   Max Time Avg time
  [..]
  0xB2 MSCH 12 0.07% 0.00%0us8us 7.31us ( +-   
2.11% )
  0xB2 CHSC 12 0.07% 0.00%0us   18us 9.39us ( +-   
9.49% )
  0xB2 STPX  8 0.05% 0.00%0us2us 1.88us ( +-   
7.18% )
  0xB2 STSI  7 0.04% 0.00%0us   44us 16.49us ( +-  
38.20% )
  [..]

This happens because the 'stats' structure is not initialized and
stats->min equals to 0. Lets initialize the structure for every
event after its allocation using init_stats() function. This initializes
stats->min to -1 and makes 'Min time' statistics counting work:

 # perf kvm stat report

 Analyze events for all VCPUs:

VM-EXITSamples  Samples% Time%   Min Time   Max Time Avg time
  [..]
  0xB2 MSCH 12 0.07% 0.00%6us8us 7.31us ( +-   
2.11% )
  0xB2 CHSC 12 0.07% 0.00%7us   18us 9.39us ( +-   
9.49% )
  0xB2 STPX  8 0.05% 0.00%1us2us 1.88us ( +-   
7.18% )
  0xB2 STSI  7 0.04% 0.00%1us   44us 16.49us ( +-  
38.20% )
  [..]

Signed-off-by: Alexander Yarygin 
Signed-off-by: Christian Borntraeger 
Reviewed-by: David Ahern 
Link: 
http://lkml.kernel.org/r/1397053319-2130-3-git-send-email-borntrae...@de.ibm.com
[ Fixing the perf examples changelog output ]
Signed-off-by: Jiri Olsa 
---
 tools/perf/builtin-kvm.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index 21c164b..0f1e5a2 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -404,6 +404,7 @@ static struct kvm_event *kvm_alloc_init_event(struct 
event_key *key)
}
 
event->key = *key;
+   init_stats(>total.stats);
return event;
 }
 
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:perf/core] perf kvm: Refactoring of cpu_isa_config()

2014-07-16 Thread tip-bot for Alexander Yarygin
Commit-ID:  65c647a65c155e69bd5765d5e454982566ac1c62
Gitweb: http://git.kernel.org/tip/65c647a65c155e69bd5765d5e454982566ac1c62
Author: Alexander Yarygin 
AuthorDate: Thu, 3 Jul 2014 17:59:51 +0400
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 7 Jul 2014 16:55:24 -0300

perf kvm: Refactoring of cpu_isa_config()

cpu_isa_config() does two different things: searching for cpuid and
initializing perf_kvm_stat struct with proper parameters.

Let's move initialization to a separate function cpu_isa_init(), which
is used to initialize all possible ISAs and can be used to init
arch-depended things.

Reviewed-by: Cornelia Huck 
Reviewed-by: David Ahern 
Signed-off-by: Alexander Yarygin 
Acked-by: Christian Borntraeger 
Cc: Christian Borntraeger 
Cc: Cornelia Huck 
Cc: David Ahern 
Cc: Jiri Olsa 
Cc: Paul Mackerras 
Cc: Peter Zijlstra 
Link: 
http://lkml.kernel.org/r/1404395992-17095-4-git-send-email-yary...@linux.vnet.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-kvm.c | 39 +++
 1 file changed, 23 insertions(+), 16 deletions(-)

diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index 75f3544..41dbeaf 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -835,36 +835,45 @@ 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;
-   int err, isa;
+   int err;
 
if (kvm->live) {
err = get_cpuid(buf, sizeof(buf));
if (err != 0) {
-   pr_err("Failed to look up CPU type (Intel or AMD)\n");
+   pr_err("Failed to look up CPU type\n");
return err;
}
cpuid = buf;
} else
cpuid = kvm->session->header.env.cpuid;
 
-   if (strstr(cpuid, "Intel"))
-   isa = 1;
-   else if (strstr(cpuid, "AMD"))
-   isa = 0;
-   else {
-   pr_err("CPU %s is not supported.\n", cpuid);
-   return -ENOTSUP;
+   if (!cpuid) {
+   pr_err("Failed to look up CPU type\n");
+   return -EINVAL;
}
 
-   if (isa == 1) {
-   kvm->exit_reasons = vmx_exit_reasons;
-   kvm->exit_reasons_isa = "VMX";
-   }
+   err = cpu_isa_init(kvm, cpuid);
+   if (err == -ENOTSUP)
+   pr_err("CPU %s is not supported.\n", cpuid);
 
-   return 0;
+   return err;
 }
 
 static bool verify_vcpu(int vcpu)
@@ -1583,8 +1592,6 @@ static int kvm_cmd_stat(const char *file_name, int argc, 
const char **argv)
.report_event   = "vmexit",
.sort_key   = "sample",
 
-   .exit_reasons = svm_exit_reasons,
-   .exit_reasons_isa = "SVM",
};
 
if (argc == 1) {
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:perf/core] perf kvm: Simplify exit reasons tables definitions

2014-07-16 Thread tip-bot for Alexander Yarygin
Commit-ID:  df74c13b6c53c97576652f7b2840764ad7d5f949
Gitweb: http://git.kernel.org/tip/df74c13b6c53c97576652f7b2840764ad7d5f949
Author: Alexander Yarygin 
AuthorDate: Thu, 3 Jul 2014 17:59:50 +0400
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 7 Jul 2014 16:55:24 -0300

perf kvm: Simplify exit reasons tables definitions

The perf_kvm_stat struct keeps the size of a table of exit reasons in
the field 'exit_reasons_size'.

The field is initialized and then used by get_exit_reason() for serial
access to the table, so that the calling function does not actually need
to know table size.

Usage of tables with 'end of sequence' marker simplifies the
get_exit_reason() function.

Also the patch introduces a define_exit_reasons_table, which makes it
easier to define new tables.

Reviewed-by: Cornelia Huck 
Reviewed-by: David Ahern 
Signed-off-by: Alexander Yarygin 
Acked-by: Christian Borntraeger 
Cc: Christian Borntraeger 
Cc: Cornelia Huck 
Cc: David Ahern 
Cc: Jiri Olsa 
Cc: Paul Mackerras 
Cc: Peter Zijlstra 
Link: 
http://lkml.kernel.org/r/1404395992-17095-3-git-send-email-yary...@linux.vnet.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-kvm.c | 27 ---
 1 file changed, 12 insertions(+), 15 deletions(-)

diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index 214ec0e..75f3544 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -99,7 +99,6 @@ struct perf_kvm_stat {
int trace_vcpu;
 
struct exit_reasons_table *exit_reasons;
-   int exit_reasons_size;
const char *exit_reasons_isa;
 
struct kvm_events_ops *events_ops;
@@ -158,20 +157,19 @@ static bool exit_event_end(struct perf_evsel *evsel,
return kvm_entry_event(evsel);
 }
 
-static struct exit_reasons_table vmx_exit_reasons[] = {
-   VMX_EXIT_REASONS
-};
+#define define_exit_reasons_table(name, symbols)   \
+   static struct exit_reasons_table name[] = { \
+   symbols, { -1, NULL }   \
+   }
 
-static struct exit_reasons_table svm_exit_reasons[] = {
-   SVM_EXIT_REASONS
-};
+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, u64 exit_code)
+static const char *get_exit_reason(struct perf_kvm_stat *kvm,
+  struct exit_reasons_table *tbl,
+  u64 exit_code)
 {
-   int i = kvm->exit_reasons_size;
-   struct exit_reasons_table *tbl = kvm->exit_reasons;
-
-   while (i--) {
+   while (tbl->reason != NULL) {
if (tbl->exit_code == exit_code)
return tbl->reason;
tbl++;
@@ -186,7 +184,8 @@ static void exit_event_decode_key(struct perf_kvm_stat *kvm,
  struct event_key *key,
  char decode[20])
 {
-   const char *exit_reason = get_exit_reason(kvm, key->key);
+   const char *exit_reason = get_exit_reason(kvm, kvm->exit_reasons,
+ key->key);
 
scnprintf(decode, 20, "%s", exit_reason);
 }
@@ -862,7 +861,6 @@ static int cpu_isa_config(struct perf_kvm_stat *kvm)
 
if (isa == 1) {
kvm->exit_reasons = vmx_exit_reasons;
-   kvm->exit_reasons_size = ARRAY_SIZE(vmx_exit_reasons);
kvm->exit_reasons_isa = "VMX";
}
 
@@ -1586,7 +1584,6 @@ static int kvm_cmd_stat(const char *file_name, int argc, 
const char **argv)
.sort_key   = "sample",
 
.exit_reasons = svm_exit_reasons,
-   .exit_reasons_size = ARRAY_SIZE(svm_exit_reasons),
.exit_reasons_isa = "SVM",
};
 
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:perf/core] perf tools: Allow to use cpuinfo on s390

2014-07-16 Thread tip-bot for Alexander Yarygin
Commit-ID:  f8d9ccde2be4c24bfb8787af36a59a981b00a02d
Gitweb: http://git.kernel.org/tip/f8d9ccde2be4c24bfb8787af36a59a981b00a02d
Author: Alexander Yarygin 
AuthorDate: Thu, 3 Jul 2014 18:08:22 +0400
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 7 Jul 2014 16:55:24 -0300

perf tools: Allow to use cpuinfo on s390

This patch defines CPUINFO_PROC for s390 and implements get_cpuid().

Reviewed-by: Cornelia Huck 
Reviewed-by: David Ahern 
Signed-off-by: Alexander Yarygin 
Acked-by: Christian Borntraeger 
Cc: Christian Borntraeger 
Cc: Cornelia Huck 
Cc: David Ahern 
Cc: Jiri Olsa 
Cc: Paul Mackerras 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/87ioneo7qh.wl%yary...@linux.vnet.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/arch/s390/Makefile  |  1 +
 tools/perf/arch/s390/util/header.c | 28 
 tools/perf/perf-sys.h  |  1 +
 3 files changed, 30 insertions(+)

diff --git a/tools/perf/arch/s390/Makefile b/tools/perf/arch/s390/Makefile
index 15130b5..744e629 100644
--- a/tools/perf/arch/s390/Makefile
+++ b/tools/perf/arch/s390/Makefile
@@ -2,3 +2,4 @@ ifndef NO_DWARF
 PERF_HAVE_DWARF_REGS := 1
 LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/dwarf-regs.o
 endif
+LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/header.o
diff --git a/tools/perf/arch/s390/util/header.c 
b/tools/perf/arch/s390/util/header.c
new file mode 100644
index 000..9fa6c3e
--- /dev/null
+++ b/tools/perf/arch/s390/util/header.c
@@ -0,0 +1,28 @@
+/*
+ * Implementation of get_cpuid().
+ *
+ * Copyright 2014 IBM Corp.
+ * Author(s): Alexander Yarygin 
+ *
+ * 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 
+#include 
+#include 
+#include 
+
+#include "../../util/header.h"
+
+int get_cpuid(char *buffer, size_t sz)
+{
+   const char *cpuid = "IBM/S390";
+
+   if (strlen(cpuid) + 1 > sz)
+   return -1;
+
+   strcpy(buffer, cpuid);
+   return 0;
+}
diff --git a/tools/perf/perf-sys.h b/tools/perf/perf-sys.h
index 5268a14..937e432 100644
--- a/tools/perf/perf-sys.h
+++ b/tools/perf/perf-sys.h
@@ -54,6 +54,7 @@
 #define mb()   asm volatile("bcr 15,0" ::: "memory")
 #define wmb()  asm volatile("bcr 15,0" ::: "memory")
 #define rmb()  asm volatile("bcr 15,0" ::: "memory")
+#define CPUINFO_PROC   "vendor_id"
 #endif
 
 #ifdef __sh__
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:perf/core] perf kvm: Introduce HAVE_KVM_STAT_SUPPORT flag

2014-07-16 Thread tip-bot for Alexander Yarygin
Commit-ID:  da50ad69723111e0292f1943dad77b41bb9a25b0
Gitweb: http://git.kernel.org/tip/da50ad69723111e0292f1943dad77b41bb9a25b0
Author: Alexander Yarygin 
AuthorDate: Thu, 3 Jul 2014 17:59:49 +0400
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 7 Jul 2014 16:55:23 -0300

perf kvm: Introduce HAVE_KVM_STAT_SUPPORT flag

kvm stat support is currently conditional on i386/x86_64. Let's abstract
this into a HAVE_KVM_STAT_SUPPORT flag, so that other architectures can
support kvm stat as well.

Reviewed-by: Cornelia Huck 
Reviewed-by: David Ahern 
Signed-off-by: Alexander Yarygin 
Acked-by: Christian Borntraeger 
Cc: Christian Borntraeger 
Cc: Cornelia Huck 
Cc: David Ahern 
Cc: Jiri Olsa 
Cc: Paul Mackerras 
Cc: Peter Zijlstra 
Link: 
http://lkml.kernel.org/r/1404395992-17095-2-git-send-email-yary...@linux.vnet.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/arch/x86/Makefile | 1 +
 tools/perf/builtin-kvm.c | 6 +++---
 tools/perf/config/Makefile   | 4 
 3 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/tools/perf/arch/x86/Makefile b/tools/perf/arch/x86/Makefile
index 1641542..d393901 100644
--- a/tools/perf/arch/x86/Makefile
+++ b/tools/perf/arch/x86/Makefile
@@ -15,3 +15,4 @@ endif
 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
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index 0f1e5a2..214ec0e 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -29,7 +29,7 @@
 #include 
 #include 
 
-#if defined(__i386__) || defined(__x86_64__)
+#ifdef HAVE_KVM_STAT_SUPPORT
 #include 
 #include 
 #include 
@@ -1609,7 +1609,7 @@ static int kvm_cmd_stat(const char *file_name, int argc, 
const char **argv)
 perf_stat:
return cmd_stat(argc, argv, NULL);
 }
-#endif
+#endif /* HAVE_KVM_STAT_SUPPORT */
 
 static int __cmd_record(const char *file_name, int argc, const char **argv)
 {
@@ -1726,7 +1726,7 @@ int cmd_kvm(int argc, const char **argv, const char 
*prefix __maybe_unused)
return cmd_top(argc, argv, NULL);
else if (!strncmp(argv[0], "buildid-list", 12))
return __cmd_buildid_list(file_name, argc, argv);
-#if defined(__i386__) || defined(__x86_64__)
+#ifdef HAVE_KVM_STAT_SUPPORT
else if (!strncmp(argv[0], "stat", 4))
return kvm_cmd_stat(file_name, argc, argv);
 #endif
diff --git a/tools/perf/config/Makefile b/tools/perf/config/Makefile
index 346bdb6..b7f42d5 100644
--- a/tools/perf/config/Makefile
+++ b/tools/perf/config/Makefile
@@ -594,6 +594,10 @@ ifndef NO_LIBNUMA
   endif
 endif
 
+ifdef HAVE_KVM_STAT_SUPPORT
+CFLAGS += -DHAVE_KVM_STAT_SUPPORT
+endif
+
 # Among the variables below, these:
 #   perfexecdir
 #   template_dir
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:perf/core] perf kvm: Add skip_event() for --duration option

2014-07-17 Thread tip-bot for Alexander Yarygin
Commit-ID:  54c801ff71ba9c9ae41871e226b9d846ff9c6bab
Gitweb: http://git.kernel.org/tip/54c801ff71ba9c9ae41871e226b9d846ff9c6bab
Author: Alexander Yarygin 
AuthorDate: Thu, 3 Jul 2014 18:29:06 +0400
Committer:  Arnaldo Carvalho de Melo 
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 
Reviewed-by: Cornelia Huck 
Reviewed-by: David Ahern 
Signed-off-by: Alexander Yarygin 
Cc: Christian Borntraeger 
Cc: Cornelia Huck 
Cc: David Ahern 
Cc: Ingo Molnar 
Cc: Jiri Olsa 
Cc: Paul Mackerras 
Cc: Peter Zijlstra 
Link: 
http://lkml.kernel.org/r/1404397747-20939-4-git-send-email-yary...@linux.vnet.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 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, >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 */
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:perf/core] perf kvm: Add stat support on s390

2014-07-17 Thread tip-bot for Alexander Yarygin
Commit-ID:  3be8e2a0a53c3179a44a933614f6a893da0b5c19
Gitweb: http://git.kernel.org/tip/3be8e2a0a53c3179a44a933614f6a893da0b5c19
Author: Alexander Yarygin 
AuthorDate: Thu, 3 Jul 2014 18:29:07 +0400
Committer:  Arnaldo Carvalho de Melo 
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  and kvm-stat.c for s390.

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

Reviewed-by: David Ahern 
Signed-off-by: Alexander Yarygin 
Acked-by: Christian Borntraeger 
Cc: Christian Borntraeger 
Cc: Cornelia Huck 
Cc: David Ahern 
Cc: Ingo Molnar 
Cc: Jiri Olsa 
Cc: Paul Mackerras 
Cc: Peter Zijlstra 
Link: 
http://lkml.kernel.org/r/1404397747-20939-5-git-send-email-yary...@linux.vnet.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 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 000..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 
+ *
+ * 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 
+
+#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 ' 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 ' records kvm events and the events between
-  start and end .
+  of KVM events. Currently, vmexit, mmio (x86 only) and ioport (x86 only)
+  events are supported. 'perf kvm stat record ' records kvm events
+  and the events between start and end .
   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=::
-   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=::
Sorting key. Possible values: sample (default, sort by samples
@@ -138,7 +138,8 @@ STAT LIVE OPTIONS
 
 
 --event=::
-   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=::
-   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 

[tip:perf/core] perf kvm: Use defines of kvm events

2014-07-17 Thread tip-bot for Alexander Yarygin
Commit-ID:  44b3802122174ba499613bac3aab2e66e948ce1e
Gitweb: http://git.kernel.org/tip/44b3802122174ba499613bac3aab2e66e948ce1e
Author: Alexander Yarygin 
AuthorDate: Thu, 3 Jul 2014 18:29:04 +0400
Committer:  Arnaldo Carvalho de Melo 
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  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 
Reviewed-by David Ahern 
Signed-off-by: Alexander Yarygin 
Acked-by: Christian Borntraeger 
Cc: Christian Borntraeger 
Cc: Cornelia Huck 
Cc: David Ahern 
Cc: Ingo Molnar 
Cc: Jiri Olsa 
Cc: Paul Mackerras 
Cc: Peter Zijlstra 
Link: 
http://lkml.kernel.org/r/1404397747-20939-2-git-send-email-yary...@linux.vnet.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 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 000..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 
+#include 
+#include 
+
+#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 
 
 #ifdef HAVE_KVM_STAT_SUPPORT
-#include 
-#include 
-#include 
+#include 
 
 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 

[tip:perf/core] perf kvm: Move arch specific code into arch/

2014-07-17 Thread tip-bot for Alexander Yarygin
Commit-ID:  9daa81239e60c162153fb2a365b8492c9a9bf632
Gitweb: http://git.kernel.org/tip/9daa81239e60c162153fb2a365b8492c9a9bf632
Author: Alexander Yarygin 
AuthorDate: Thu, 3 Jul 2014 18:29:05 +0400
Committer:  Arnaldo Carvalho de Melo 
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 
Reviewed-by: Cornelia Huck 
Signed-off-by: Alexander Yarygin 
Acked-by: Christian Borntraeger 
Cc: Christian Borntraeger 
Cc: Cornelia Huck 
Cc: David Ahern 
Cc: Ingo Molnar 
Cc: Jiri Olsa 
Cc: Paul Mackerras 
Cc: Peter Zijlstra 
Link: 
http://lkml.kernel.org/r/1404397747-20939-3-git-send-email-yary...@linux.vnet.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 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 000..2f8d2c1
--- /dev/null
+++ b/tools/perf/arch/x86/util/kvm-stat.c
@@ -0,0 +1,151 @@
+#include "../../util/kvm-stat.h"
+#include 
+
+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 == 

[tip:perf/urgent] perf kvm stat live: Mark events as (x86 only) in help output

2014-12-12 Thread tip-bot for Alexander Yarygin
Commit-ID:  99d348a84c2118ed04c9b72168787f55e2fe33a5
Gitweb: http://git.kernel.org/tip/99d348a84c2118ed04c9b72168787f55e2fe33a5
Author: Alexander Yarygin 
AuthorDate: Wed, 10 Dec 2014 14:28:10 +0100
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Wed, 10 Dec 2014 12:08:59 -0300

perf kvm stat live: Mark events as (x86 only) in help output

The mmio and ioport events are useful only on x86.

Signed-off-by: Alexander Yarygin 
Acked-by: David Ahern 
Cc: Christian Borntraeger 
Cc: Jiri Olsa 
Link: 
http://lkml.kernel.org/r/1418218090-20718-1-git-send-email-borntrae...@de.ibm.com
Signed-off-by: Christian Borntraeger 
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-kvm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index 3c0f3d4..0894a81 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -1293,7 +1293,8 @@ static int kvm_events_live(struct perf_kvm_stat *kvm,
OPT_UINTEGER('d', "display", >display_time,
"time in seconds between display updates"),
OPT_STRING(0, "event", >report_event, "report event",
-   "event for reporting: vmexit, mmio, ioport"),
+   "event for reporting: "
+   "vmexit, mmio (x86 only), ioport (x86 only)"),
OPT_INTEGER(0, "vcpu", >trace_vcpu,
"vcpu id to report"),
OPT_STRING('k', "key", >sort_key, "sort-key",
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:perf/core] perf kvm stat report: Save pid string in opts.target.pid

2014-09-18 Thread tip-bot for Alexander Yarygin
Commit-ID:  3ae4a76ac840021294c091884e04af7c92e481ae
Gitweb: http://git.kernel.org/tip/3ae4a76ac840021294c091884e04af7c92e481ae
Author: Alexander Yarygin 
AuthorDate: Mon, 1 Sep 2014 17:44:53 +0400
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Wed, 17 Sep 2014 17:08:07 -0300

perf kvm stat report: Save pid string in opts.target.pid

The 'perf kvm stat report' command uses the kvm->pid_str field to keep
the value of the --pid option. Let's use kvm->opts.target.pid instead.

Signed-off-by: Alexander Yarygin 
Acked-by: David Ahern 
Cc: Christian Borntraeger 
Cc: David Ahern 
Cc: Ingo Molnar 
Cc: Jiri Olsa 
Cc: Paul Mackerras 
Cc: Peter Zijlstra 
Link: 
http://lkml.kernel.org/r/1409579095-12963-2-git-send-email-yary...@linux.vnet.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-kvm.c   | 6 +++---
 tools/perf/util/kvm-stat.h | 1 -
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index 1a4ef9c..646ec5d 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -1085,8 +1085,8 @@ static int read_events(struct perf_kvm_stat *kvm)
 
 static int parse_target_str(struct perf_kvm_stat *kvm)
 {
-   if (kvm->pid_str) {
-   kvm->pid_list = intlist__new(kvm->pid_str);
+   if (kvm->opts.target.pid) {
+   kvm->pid_list = intlist__new(kvm->opts.target.pid);
if (kvm->pid_list == NULL) {
pr_err("Error parsing process id string\n");
return -EINVAL;
@@ -1188,7 +1188,7 @@ kvm_events_report(struct perf_kvm_stat *kvm, int argc, 
const char **argv)
OPT_STRING('k', "key", >sort_key, "sort-key",
"key for sorting: sample(sort by samples number)"
" time (sort by avg time)"),
-   OPT_STRING('p', "pid", >pid_str, "pid",
+   OPT_STRING('p', "pid", >opts.target.pid, "pid",
   "analyze events only for given process id(s)"),
OPT_END()
};
diff --git a/tools/perf/util/kvm-stat.h b/tools/perf/util/kvm-stat.h
index 0b5a8cd..cf1d7913 100644
--- a/tools/perf/util/kvm-stat.h
+++ b/tools/perf/util/kvm-stat.h
@@ -92,7 +92,6 @@ struct perf_kvm_stat {
u64 lost_events;
u64 duration;
 
-   const char *pid_str;
struct intlist *pid_list;
 
struct rb_root result;
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:perf/core] perf kvm stat report: Unify the title bar output

2014-09-18 Thread tip-bot for Alexander Yarygin
Commit-ID:  1f3e5b55035549311e42c3f84007e6c799ed991f
Gitweb: http://git.kernel.org/tip/1f3e5b55035549311e42c3f84007e6c799ed991f
Author: Alexander Yarygin 
AuthorDate: Mon, 1 Sep 2014 17:44:55 +0400
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Wed, 17 Sep 2014 17:08:08 -0300

perf kvm stat report: Unify the title bar output

The 'live' command prints additional information to the "Analyze events
for " title bar about the current target.  Let's print the same title
for the 'report' command.

Signed-off-by: Alexander Yarygin 
Acked-by: David Ahern 
Cc: Christian Borntraeger 
Cc: David Ahern 
Cc: Ingo Molnar 
Cc: Jiri Olsa 
Cc: Paul Mackerras 
Cc: Peter Zijlstra 
Link: 
http://lkml.kernel.org/r/1409579095-12963-4-git-send-email-yary...@linux.vnet.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-kvm.c | 14 ++
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index 84295ab..f5d3ae4 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -543,14 +543,12 @@ static void print_vcpu_info(struct perf_kvm_stat *kvm)
 
pr_info("Analyze events for ");
 
-   if (kvm->live) {
-   if (kvm->opts.target.system_wide)
-   pr_info("all VMs, ");
-   else if (kvm->opts.target.pid)
-   pr_info("pid(s) %s, ", kvm->opts.target.pid);
-   else
-   pr_info("dazed and confused on what is monitored, ");
-   }
+   if (kvm->opts.target.system_wide)
+   pr_info("all VMs, ");
+   else if (kvm->opts.target.pid)
+   pr_info("pid(s) %s, ", kvm->opts.target.pid);
+   else
+   pr_info("dazed and confused on what is monitored, ");
 
if (vcpu == -1)
pr_info("all VCPUs:\n\n");
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:perf/core] perf kvm stat report: Enable the target.system_wide flag

2014-09-18 Thread tip-bot for Alexander Yarygin
Commit-ID:  f181957c2849478fc963a8ac3c7dacf0a87c6b05
Gitweb: http://git.kernel.org/tip/f181957c2849478fc963a8ac3c7dacf0a87c6b05
Author: Alexander Yarygin 
AuthorDate: Mon, 1 Sep 2014 17:44:54 +0400
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Wed, 17 Sep 2014 17:08:07 -0300

perf kvm stat report: Enable the target.system_wide flag

The 'perf kvm stat report' command can be used to analyze events either
for system wide or for specific pids.

Let's enable kvm->opts.target.system_wide flag when 'report' command is
running for system-wide analyzing. This helps to sync kvm->opts.target
values in 'report' and 'live' commands.

Signed-off-by: Alexander Yarygin 
Acked-by: David Ahern 
Cc: Christian Borntraeger 
Cc: David Ahern 
Cc: Ingo Molnar 
Cc: Jiri Olsa 
Cc: Paul Mackerras 
Cc: Peter Zijlstra 
Link: 
http://lkml.kernel.org/r/1409579095-12963-3-git-send-email-yary...@linux.vnet.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-kvm.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index 646ec5d..84295ab 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -1207,6 +1207,9 @@ kvm_events_report(struct perf_kvm_stat *kvm, int argc, 
const char **argv)
   kvm_events_report_options);
}
 
+   if (!kvm->opts.target.pid)
+   kvm->opts.target.system_wide = true;
+
return kvm_events_report_vcpu(kvm);
 }
 
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:perf/urgent] perf kvm stat live: Enable events copying

2014-10-15 Thread tip-bot for Alexander Yarygin
Commit-ID:  673d659f5c5918b7ddbafebf1f129c9eb82973b4
Gitweb: http://git.kernel.org/tip/673d659f5c5918b7ddbafebf1f129c9eb82973b4
Author: Alexander Yarygin 
AuthorDate: Fri, 3 Oct 2014 18:40:12 +0400
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Wed, 15 Oct 2014 17:39:03 -0300

perf kvm stat live: Enable events copying

Process of analyzing events caused by 2 functions: mmap_read() and
finished_round().

During mmap_read(), perf receives events from shared memory, queues
their pointers for further processing in finished_round() and notifies
the kernel that the events have been processed.

By the time when finished_round() is invoked, queued events can be
overwritten by the kernel, so the finished_round() occurs on potentially
corrupted memory.

Since there is no place where the event can be safely consumed, let's
copy events when queueing.

Signed-off-by: Alexander Yarygin 
Cc: Christian Borntraeger 
Cc: David Ahern 
Cc: Frederic Weisbecker 
Cc: Ingo Molnar 
Cc: Jiri Olsa 
Cc: Mike Galbraith 
Cc: Namhyung Kim 
Cc: Paul Mackerras 
Cc: Peter Zijlstra 
Cc: Stephane Eranian 
Link: 
http://lkml.kernel.org/r/1412347212-28237-3-git-send-email-yary...@linux.vnet.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-kvm.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index ef9fc15..b65eb050 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -1358,6 +1358,7 @@ static int kvm_events_live(struct perf_kvm_stat *kvm,
}
kvm->session->evlist = kvm->evlist;
perf_session__set_id_hdr_size(kvm->session);
+   ordered_events__set_copy_on_queue(>session->ordered_events, true);
machine__synthesize_threads(>session->machines.host, 
>opts.target,
kvm->evlist->threads, false);
err = kvm_live_open_events(kvm);
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:perf/urgent] perf session: Add option to copy events when queueing

2014-10-15 Thread tip-bot for Alexander Yarygin
Commit-ID:  54bf53b1cb9150b894213a705c562d52388376ef
Gitweb: http://git.kernel.org/tip/54bf53b1cb9150b894213a705c562d52388376ef
Author: Alexander Yarygin 
AuthorDate: Fri, 3 Oct 2014 18:40:11 +0400
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Wed, 15 Oct 2014 17:39:03 -0300

perf session: Add option to copy events when queueing

When processing events the session code has an ordered samples queue
which is used to time-sort events coming in across multiple mmaps. At a
later point in time samples on the queue are flushed up to some
timestamp at which point the event is actually processed.

When analyzing events live (ie., record/analysis path in the same
command) there is a race that leads to corrupted events and parse errors
which cause perf to terminate. The problem is that when the event is
placed in the ordered samples queue it is only a reference to the event
which is really sitting in the mmap buffer. Even though the event is
queued for later processing the mmap tail pointer is updated which
indicates to the kernel that the event has been processed. The race is
flushing the event from the queue before it gets overwritten by some
other event. For commands trying to process events live (versus just
writing to a file) and processing a high rate of events this leads to
parse failures and perf terminates.

Examples hitting this problem are 'perf kvm stat live', especially with
nested VMs which generate 100,000+ traces per second, and a command
processing scheduling events with a high rate of context switching --
e.g., running 'perf bench sched pipe'.

This patch offers live commands an option to copy the event when it is
placed in the ordered samples queue.

Based on a patch from David Ahern 

Signed-off-by: Alexander Yarygin 
Acked-by: Jiri Olsa 
Cc: Christian Borntraeger 
Cc: David Ahern 
Cc: Frederic Weisbecker 
Cc: Ingo Molnar 
Cc: Jiri Olsa 
Cc: Mike Galbraith 
Cc: Namhyung Kim 
Cc: Paul Mackerras 
Cc: Peter Zijlstra 
Cc: Stephane Eranian 
Link: 
http://lkml.kernel.org/r/1412347212-28237-2-git-send-email-yary...@linux.vnet.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/ordered-events.c | 49 
 tools/perf/util/ordered-events.h | 10 +++-
 tools/perf/util/session.c|  5 ++--
 3 files changed, 56 insertions(+), 8 deletions(-)

diff --git a/tools/perf/util/ordered-events.c b/tools/perf/util/ordered-events.c
index 706ce1a..fd4be94 100644
--- a/tools/perf/util/ordered-events.c
+++ b/tools/perf/util/ordered-events.c
@@ -1,5 +1,6 @@
 #include 
 #include 
+#include 
 #include "ordered-events.h"
 #include "evlist.h"
 #include "session.h"
@@ -57,11 +58,45 @@ static void queue_event(struct ordered_events *oe, struct 
ordered_event *new)
}
 }
 
+static union perf_event *__dup_event(struct ordered_events *oe,
+union perf_event *event)
+{
+   union perf_event *new_event = NULL;
+
+   if (oe->cur_alloc_size < oe->max_alloc_size) {
+   new_event = memdup(event, event->header.size);
+   if (new_event)
+   oe->cur_alloc_size += event->header.size;
+   }
+
+   return new_event;
+}
+
+static union perf_event *dup_event(struct ordered_events *oe,
+  union perf_event *event)
+{
+   return oe->copy_on_queue ? __dup_event(oe, event) : event;
+}
+
+static void free_dup_event(struct ordered_events *oe, union perf_event *event)
+{
+   if (oe->copy_on_queue) {
+   oe->cur_alloc_size -= event->header.size;
+   free(event);
+   }
+}
+
 #define MAX_SAMPLE_BUFFER  (64 * 1024 / sizeof(struct ordered_event))
-static struct ordered_event *alloc_event(struct ordered_events *oe)
+static struct ordered_event *alloc_event(struct ordered_events *oe,
+union perf_event *event)
 {
struct list_head *cache = >cache;
struct ordered_event *new = NULL;
+   union perf_event *new_event;
+
+   new_event = dup_event(oe, event);
+   if (!new_event)
+   return NULL;
 
if (!list_empty(cache)) {
new = list_entry(cache->next, struct ordered_event, list);
@@ -74,8 +109,10 @@ static struct ordered_event *alloc_event(struct 
ordered_events *oe)
size_t size = MAX_SAMPLE_BUFFER * sizeof(*new);
 
oe->buffer = malloc(size);
-   if (!oe->buffer)
+   if (!oe->buffer) {
+   free_dup_event(oe, new_event);
return NULL;
+   }
 
pr("alloc size %" PRIu64 "B (+%zu), max %" PRIu64 "B\n",
   oe->cur_alloc_size, size, oe->max_alloc_size);
@@ -90,15 +127,17 @@ static struct ordered_event *alloc_event(struct 
ordered_events *oe)
pr("allocation limit reached %" PRIu64 "B\n", 
oe->max_alloc_size);
}
 
+   new->event = new_event;
return new;
 }
 
 

[tip:perf/core] perf tools: Parse tracepoints with '-' in system name

2014-05-01 Thread tip-bot for Alexander Yarygin
Commit-ID:  2b9032e0ecb57de819bcf40b440e7cbd2d8f3a8c
Gitweb: http://git.kernel.org/tip/2b9032e0ecb57de819bcf40b440e7cbd2d8f3a8c
Author: Alexander Yarygin 
AuthorDate: Fri, 25 Apr 2014 17:34:05 +0200
Committer:  Jiri Olsa 
CommitDate: Tue, 29 Apr 2014 14:27:23 +0200

perf tools: Parse tracepoints with '-' in system name

Trace events potentially can have a '-' in their trace system name,
e.g. kvm on s390 defines kvm-s390:* tracepoints.
We could not parse them, because there was no rule for this:
  $ sudo ./perf top -e "kvm-s390:*"
  invalid or unsupported event: 'kvm-s390:*'

This patch adds an extra rule to event_legacy_tracepoint which handles
those cases. Without the patch, perf will not accept such tracepoints in
the -e option.

Signed-off-by: Alexander Yarygin 
Tested-by: Christian Borntraeger 
Acked-by: Christian Borntraeger 
Link: 
http://lkml.kernel.org/r/1398440047-6641-2-git-send-email-yary...@linux.vnet.ibm.com
Signed-off-by: Jiri Olsa 
---
 tools/perf/util/parse-events.y | 12 
 1 file changed, 12 insertions(+)

diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y
index 4eb67ec..ac9db9f 100644
--- a/tools/perf/util/parse-events.y
+++ b/tools/perf/util/parse-events.y
@@ -299,6 +299,18 @@ PE_PREFIX_MEM PE_VALUE sep_dc
 }
 
 event_legacy_tracepoint:
+PE_NAME '-' PE_NAME ':' PE_NAME
+{
+   struct parse_events_evlist *data = _data;
+   struct list_head *list;
+   char sys_name[128];
+   snprintf(_name, 128, "%s-%s", $1, $3);
+
+   ALLOC_LIST(list);
+   ABORT_ON(parse_events_add_tracepoint(list, >idx, _name, $5));
+   $$ = list;
+}
+|
 PE_NAME ':' PE_NAME
 {
struct parse_events_evlist *data = _data;
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:perf/core] perf tests: Add numeric identifier to evlist_test

2014-05-01 Thread tip-bot for Alexander Yarygin
Commit-ID:  615b8f99f755f8e2701f08cef9c56bd3033891a5
Gitweb: http://git.kernel.org/tip/615b8f99f755f8e2701f08cef9c56bd3033891a5
Author: Alexander Yarygin 
AuthorDate: Fri, 25 Apr 2014 17:34:06 +0200
Committer:  Jiri Olsa 
CommitDate: Tue, 29 Apr 2014 14:29:48 +0200

perf tests: Add numeric identifier to evlist_test

In tests/parse-events.c test cases are declared in evlist_test[]
arrays. Elements of arrays are initialized in following pattern:
[i] = {
.name  = ...,
.check = ...,
},

When perf-test is running with '-v' option, 'i' variable will be
printed for every existing test.

However, we can't add any arch specific tests inside #ifdefs, because it
will create collision between the element number inside #ifdef and the
next one outside.

This patch adds 'id' field in evlist_test, uses it as a test
identifier and removes explicit numbering of array elements. This helps
to number tests with gaps.

Signed-off-by: Alexander Yarygin 
Link: 
http://lkml.kernel.org/r/1398440047-6641-3-git-send-email-yary...@linux.vnet.ibm.com
Signed-off-by: Jiri Olsa 
---
 tools/perf/tests/parse-events.c | 135 ++--
 1 file changed, 90 insertions(+), 45 deletions(-)

diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-events.c
index 8605ff5..81dbd5a 100644
--- a/tools/perf/tests/parse-events.c
+++ b/tools/perf/tests/parse-events.c
@@ -1174,188 +1174,233 @@ static int test__all_tracepoints(struct perf_evlist 
*evlist)
 struct evlist_test {
const char *name;
__u32 type;
+   const int id;
int (*check)(struct perf_evlist *evlist);
 };
 
 static struct evlist_test test__events[] = {
-   [0] = {
+   {
.name  = "syscalls:sys_enter_open",
.check = test__checkevent_tracepoint,
+   .id= 0,
},
-   [1] = {
+   {
.name  = "syscalls:*",
.check = test__checkevent_tracepoint_multi,
+   .id= 1,
},
-   [2] = {
+   {
.name  = "r1a",
.check = test__checkevent_raw,
+   .id= 2,
},
-   [3] = {
+   {
.name  = "1:1",
.check = test__checkevent_numeric,
+   .id= 3,
},
-   [4] = {
+   {
.name  = "instructions",
.check = test__checkevent_symbolic_name,
+   .id= 4,
},
-   [5] = {
+   {
.name  = "cycles/period=10,config2/",
.check = test__checkevent_symbolic_name_config,
+   .id= 5,
},
-   [6] = {
+   {
.name  = "faults",
.check = test__checkevent_symbolic_alias,
+   .id= 6,
},
-   [7] = {
+   {
.name  = "L1-dcache-load-miss",
.check = test__checkevent_genhw,
+   .id= 7,
},
-   [8] = {
+   {
.name  = "mem:0",
.check = test__checkevent_breakpoint,
+   .id= 8,
},
-   [9] = {
+   {
.name  = "mem:0:x",
.check = test__checkevent_breakpoint_x,
+   .id= 9,
},
-   [10] = {
+   {
.name  = "mem:0:r",
.check = test__checkevent_breakpoint_r,
+   .id= 10,
},
-   [11] = {
+   {
.name  = "mem:0:w",
.check = test__checkevent_breakpoint_w,
+   .id= 11,
},
-   [12] = {
+   {
.name  = "syscalls:sys_enter_open:k",
.check = test__checkevent_tracepoint_modifier,
+   .id= 12,
},
-   [13] = {
+   {
.name  = "syscalls:*:u",
.check = test__checkevent_tracepoint_multi_modifier,
+   .id= 13,
},
-   [14] = {
+   {
.name  = "r1a:kp",
.check = test__checkevent_raw_modifier,
+   .id= 14,
},
-   [15] = {
+   {
.name  = "1:1:hp",
.check = test__checkevent_numeric_modifier,
+   .id= 15,
},
-   [16] = {
+   {
.name  = "instructions:h",
.check = test__checkevent_symbolic_name_modifier,
+   .id= 16,
},
-   [17] = {
+   {
.name  = "faults:u",
.check = test__checkevent_symbolic_alias_modifier,
+   .id= 17,
},
-   [18] = {
+   {
.name  = "L1-dcache-load-miss:kp",
.check = test__checkevent_genhw_modifier,
+   .id= 18,
},
-   [19] = {
+   {
.name  = "mem:0:u",
.check = test__checkevent_breakpoint_modifier,
+   .id

[tip:perf/core] perf tests: Add a test of kvm-390: trace event

2014-05-01 Thread tip-bot for Alexander Yarygin
Commit-ID:  c0bc8c6d4a2e18e54ef7854a86bc5a47a8e3d04e
Gitweb: http://git.kernel.org/tip/c0bc8c6d4a2e18e54ef7854a86bc5a47a8e3d04e
Author: Alexander Yarygin 
AuthorDate: Fri, 25 Apr 2014 17:34:07 +0200
Committer:  Jiri Olsa 
CommitDate: Tue, 29 Apr 2014 14:30:43 +0200

perf tests: Add a test of kvm-390: trace event

Add a s390 specific test of a hardcoded trace event with '-'
in the name.

Signed-off-by: Alexander Yarygin 
Link: 
http://lkml.kernel.org/r/1398440047-6641-4-git-send-email-yary...@linux.vnet.ibm.com
Signed-off-by: Jiri Olsa 
---
 tools/perf/tests/parse-events.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-events.c
index 81dbd5a..deba669 100644
--- a/tools/perf/tests/parse-events.c
+++ b/tools/perf/tests/parse-events.c
@@ -1389,6 +1389,13 @@ static struct evlist_test test__events[] = {
.check = test__pinned_group,
.id= 41,
},
+#if defined(__s390x__)
+   {
+   .name  = "kvm-s390:kvm_s390_create_vm",
+   .check = test__checkevent_tracepoint,
+   .id= 100,
+   },
+#endif
 };
 
 static struct evlist_test test__events_pmu[] = {
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/