Skip to contentSkip to conversation

perf/core improvements and fixes

GIT PULL New Jiri Olsa 1 participant 10 messages Jun 19, 2014 perf events

lore
Share & tools
lore

Jiri Olsa

author reviewer
#0 lore raw

hi Ingo,
please consider pulling

thanks,
jirka

The following changes since commit 4ba96195051be30160af6d5f5f83f9a055ab1f23:

Merge tag 'perf-core-for-mingo' of git://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf into perf/core (2014-06-13 08:19:06 +0200)

are available in the git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git tags/perf-core-for-mingo

for you to fetch changes up to 26d664a30d08002ac0a4dbd09217ea084da07bc9:

perf symbols: Get kernel start address by symbol name (2014-06-19 18:18:38 +0200)

----------------------------------------------------------------
perf/core improvements and fixes:

. Updates from trace-cmd for traceevent plugin_kvm plus args cleanup (Steven Rostedt)

. Fix kernel start address lookup in report code (Simon Que)

. Fix segfault in cumulative.callchain report (Jiri Olsa)

----------------------------------------------------------------
Jan Kiszka (3):
tools lib traceevent: Report unknown VMX exit reasons with code tools lib traceevent: Factor out print_exit_reason in kvm plugin tools lib traceevent: Fix and cleanup kvm_nested_vmexit tracepoints

Jiri Olsa (1):
perf tools: Fix segfault in cumulative.callchain report

Simon Que (1):
perf symbols: Get kernel start address by symbol name

Steven Rostedt (3):
tools lib traceevent: Fix format in plugin_kvm
tools lib traceevent: Clean up format of args in cfg80211 plugin tools lib traceevent: Clean up format of args in jbd2 plugin

Steven Rostedt (Red Hat) (1):
tools lib traceevent: Add back in kvm plugins nested_vmexit events

 tools/lib/traceevent/plugin_cfg80211.c |  3 +-
 tools/lib/traceevent/plugin_jbd2.c     |  6 ++--
 tools/lib/traceevent/plugin_kvm.c      | 64 +++++++++++++++++++++++++++++-----
 tools/perf/ui/browsers/hists.c         | 21 ++++++++---
 tools/perf/util/machine.c              | 54 ++++++++++++----------------
 5 files changed, 97 insertions(+), 51 deletions(-)
author reviewer
#1 lore raw

PATCH 1/9 tools lib traceevent: Report unknown VMX exit reasons with code

From: Jan Kiszka <[email protected]>

Allows to parse the result even if the KVM plugin does not yet understand a specific exit code.

---
 tools/lib/traceevent/plugin_kvm.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
tools/lib/traceevent/plugin_kvm.c +8 -4
index 9e0e8c6..3e61220 100644
@@ -240,9 +240,8 @@ static const char *find_exit_reason(unsigned isa, int val)
 	for (i = 0; strings[i].val >= 0; i++)
 		if (strings[i].val == val)
 			break;
-	if (strings[i].str)
-		return strings[i].str;
-	return "UNKNOWN";
+
+	return strings[i].str;
 }
 
 static int kvm_exit_handler(struct trace_seq *s, struct pevent_record *record,
@@ -251,6 +250,7 @@ static int kvm_exit_handler(struct trace_seq *s, struct pevent_record *record,
 	unsigned long long isa;
 	unsigned long long val;
 	unsigned long long info1 = 0, info2 = 0;
+	const char *reason;
 
 	if (pevent_get_field_val(s, event, "exit_reason", record, &val, 1) < 0)
 		return -1;
@@ -258,7 +258,11 @@ static int kvm_exit_handler(struct trace_seq *s, struct pevent_record *record,
 	if (pevent_get_field_val(s, event, "isa", record, &isa, 0) < 0)
 		isa = 1;
 
-	trace_seq_printf(s, "reason %s", find_exit_reason(isa, val));
+	reason = find_exit_reason(isa, val);
+	if (reason)
+		trace_seq_printf(s, "reason %s", reason);
+	else
+		trace_seq_printf(s, "reason UNKNOWN (%llu)", val);
 
 	pevent_print_num_field(s, " rip 0x%lx", event, "guest_rip", record, 1);
 
Signature · 1 line
1.8.3.1
author reviewer
#2 lore raw

PATCH 2/9 tools lib traceevent: Factor out print_exit_reason in kvm plugin

In reply to Jiri Olsa

From: Jan Kiszka <[email protected]>

We will reuse it for nested vmexit tracepoints.

---
 tools/lib/traceevent/plugin_kvm.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
tools/lib/traceevent/plugin_kvm.c +13 -4
index 3e61220..2d7d1d7 100644
@@ -244,15 +244,14 @@ static const char *find_exit_reason(unsigned isa, int val)
 	return strings[i].str;
 }
 
-static int kvm_exit_handler(struct trace_seq *s, struct pevent_record *record,
-			    struct event_format *event, void *context)
+static int print_exit_reason(struct trace_seq *s, struct pevent_record *record,
+			     struct event_format *event, const char *field)
 {
 	unsigned long long isa;
 	unsigned long long val;
-	unsigned long long info1 = 0, info2 = 0;
 	const char *reason;
 
-	if (pevent_get_field_val(s, event, "exit_reason", record, &val, 1) < 0)
+	if (pevent_get_field_val(s, event, field, record, &val, 1) < 0)
 		return -1;
 
 	if (pevent_get_field_val(s, event, "isa", record, &isa, 0) < 0)
@@ -263,6 +262,16 @@ static int kvm_exit_handler(struct trace_seq *s, struct pevent_record *record,
 		trace_seq_printf(s, "reason %s", reason);
 	else
 		trace_seq_printf(s, "reason UNKNOWN (%llu)", val);
+	return 0;
+}
+
+static int kvm_exit_handler(struct trace_seq *s, struct pevent_record *record,
+			    struct event_format *event, void *context)
+{
+	unsigned long long info1 = 0, info2 = 0;
+
+	if (print_exit_reason(s, record, event, "exit_reason") < 0)
+		return -1;
 
 	pevent_print_num_field(s, " rip 0x%lx", event, "guest_rip", record, 1);
 
Signature · 1 line
1.8.3.1
author reviewer
#3 lore raw

PATCH 3/9 tools lib traceevent: Add back in kvm plugins nested_vmexit events

In reply to Jiri Olsa

From: "Steven Rostedt (Red Hat)" <[email protected]>

The nested vmexit events were removed from the backport from trace-cmd because they were considered buggy. They have since been updated in trace-cmd but are still missing from the traceevent library. Add back in the buggy version to be able to backport the fixes.

---
 tools/lib/traceevent/plugin_kvm.c | 41 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)
tools/lib/traceevent/plugin_kvm.c +41 -0
index 2d7d1d7..0d43783 100644
@@ -326,6 +326,35 @@ static int kvm_emulate_insn_handler(struct trace_seq *s,
 	return 0;
 }
 
+
+static int kvm_nested_vmexit_inject_handler(struct trace_seq *s, struct pevent_record *record,
+					    struct event_format *event, void *context)
+{
+	unsigned long long val;
+
+	pevent_print_num_field(s, " rip %0x016llx", event, "rip", record, 1);
+
+	if (pevent_get_field_val(s, event, "exit_code", record, &val, 1) < 0)
+		return -1;
+
+	trace_seq_printf(s, "reason %s", find_exit_reason(2, val));
+
+	pevent_print_num_field(s, " ext_inf1: %0x016llx", event, "exit_info1", record, 1);
+	pevent_print_num_field(s, " ext_inf2: %0x016llx", event, "exit_info2", record, 1);
+	pevent_print_num_field(s, " ext_int: %0x016llx", event, "exit_int_info", record, 1);
+	pevent_print_num_field(s, " ext_int_err: %0x016llx", event, "exit_int_info_err", record, 1);
+
+	return 0;
+}
+
+static int kvm_nested_vmexit_handler(struct trace_seq *s, struct pevent_record *record,
+				     struct event_format *event, void *context)
+{
+	pevent_print_num_field(s, " rip %0x016llx", event, "rip", record, 1);
+
+	return kvm_nested_vmexit_inject_handler(s, record, event, context);
+}
+
 union kvm_mmu_page_role {
 	unsigned word;
 	struct {
@@ -422,6 +451,12 @@ int PEVENT_PLUGIN_LOADER(struct pevent *pevent)
 	pevent_register_event_handler(pevent, -1, "kvm", "kvm_emulate_insn",
 				      kvm_emulate_insn_handler, NULL);
 
+	pevent_register_event_handler(pevent, -1, "kvm", "kvm_nested_vmexit",
+				      kvm_nested_vmexit_handler, NULL);
+
+	pevent_register_event_handler(pevent, -1, "kvm", "kvm_nested_vmexit_inject",
+				      kvm_nested_vmexit_inject_handler, NULL);
+
 	pevent_register_event_handler(pevent, -1, "kvmmmu", "kvm_mmu_get_page",
 				      kvm_mmu_get_page_handler, NULL);
 
@@ -456,6 +491,12 @@ void PEVENT_PLUGIN_UNLOADER(struct pevent *pevent)
 	pevent_unregister_event_handler(pevent, -1, "kvm", "kvm_emulate_insn",
 					kvm_emulate_insn_handler, NULL);
 
+	pevent_unregister_event_handler(pevent, -1, "kvm", "kvm_nested_vmexit",
+					kvm_nested_vmexit_handler, NULL);
+
+	pevent_unregister_event_handler(pevent, -1, "kvm", "kvm_nested_vmexit_inject",
+					kvm_nested_vmexit_inject_handler, NULL);
+
 	pevent_unregister_event_handler(pevent, -1, "kvmmmu", "kvm_mmu_get_page",
 					kvm_mmu_get_page_handler, NULL);
 
Signature · 1 line
1.8.3.1
author reviewer
#4 lore raw

PATCH 4/9 tools lib traceevent: Fix and cleanup kvm_nested_vmexit tracepoints

In reply to Jiri Olsa

From: Jan Kiszka <[email protected]>

Fix several issues of kvm_nested_vmexit[_inject]: field width aren't supported with pevent_print, rip was printed twice/incorrectly, SVM ISA was hard-coded, we don't use ':' to separate field names.

---
 tools/lib/traceevent/plugin_kvm.c | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)
tools/lib/traceevent/plugin_kvm.c +6 -12
index 0d43783..0575e59 100644
@@ -330,19 +330,13 @@ static int kvm_emulate_insn_handler(struct trace_seq *s,
 static int kvm_nested_vmexit_inject_handler(struct trace_seq *s, struct pevent_record *record,
 					    struct event_format *event, void *context)
 {
-	unsigned long long val;
-
-	pevent_print_num_field(s, " rip %0x016llx", event, "rip", record, 1);
-
-	if (pevent_get_field_val(s, event, "exit_code", record, &val, 1) < 0)
+	if (print_exit_reason(s, record, event, "exit_code") < 0)
 		return -1;
 
-	trace_seq_printf(s, "reason %s", find_exit_reason(2, val));
-
-	pevent_print_num_field(s, " ext_inf1: %0x016llx", event, "exit_info1", record, 1);
-	pevent_print_num_field(s, " ext_inf2: %0x016llx", event, "exit_info2", record, 1);
-	pevent_print_num_field(s, " ext_int: %0x016llx", event, "exit_int_info", record, 1);
-	pevent_print_num_field(s, " ext_int_err: %0x016llx", event, "exit_int_info_err", record, 1);
+	pevent_print_num_field(s, " info1 %llx", event, "exit_info1", record, 1);
+	pevent_print_num_field(s, " info2 %llx", event, "exit_info2", record, 1);
+	pevent_print_num_field(s, " int_info %llx", event, "exit_int_info", record, 1);
+	pevent_print_num_field(s, " int_info_err %llx", event, "exit_int_info_err", record, 1);
 
 	return 0;
 }
@@ -350,7 +344,7 @@ static int kvm_nested_vmexit_inject_handler(struct trace_seq *s, struct pevent_r
 static int kvm_nested_vmexit_handler(struct trace_seq *s, struct pevent_record *record,
 				     struct event_format *event, void *context)
 {
-	pevent_print_num_field(s, " rip %0x016llx", event, "rip", record, 1);
+	pevent_print_num_field(s, "rip %lx ", event, "rip", record, 1);
 
 	return kvm_nested_vmexit_inject_handler(s, record, event, context);
 }
Signature · 1 line
1.8.3.1
author reviewer
#5 lore raw

PATCH 5/9 tools lib traceevent: Fix format in plugin_kvm

In reply to Jiri Olsa

From: Steven Rostedt <[email protected]>

The format field argument passed to the format
in pevent_print_num_field() will be of type long long. That means that %ll must be used instead of %l.

---
 tools/lib/traceevent/plugin_kvm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/lib/traceevent/plugin_kvm.c +1 -1
index 0575e59..88fe83d 100644
@@ -344,7 +344,7 @@ static int kvm_nested_vmexit_inject_handler(struct trace_seq *s, struct pevent_r
 static int kvm_nested_vmexit_handler(struct trace_seq *s, struct pevent_record *record,
 				     struct event_format *event, void *context)
 {
-	pevent_print_num_field(s, "rip %lx ", event, "rip", record, 1);
+	pevent_print_num_field(s, "rip %llx ", event, "rip", record, 1);
 
 	return kvm_nested_vmexit_inject_handler(s, record, event, context);
 }
Signature · 1 line
1.8.3.1
author reviewer
#6 lore raw

PATCH 6/9 tools lib traceevent: Clean up format of args in cfg80211 plugin

In reply to Jiri Olsa

From: Steven Rostedt <[email protected]>

While synchronizing what's in trace-cmd vs what's in perf, I came across a change that was made when entering the cfg80211 plugin into the tools/lib/traceevent directory. The function prototype went from:

static unsigned long long process___le16_to_cpup(struct trace_seq *s,
unsigned long long *args)

to:

static unsigned long long
process___le16_to_cpup(struct trace_seq *s,
unsigned long long *args)

I can understand the line break after the long long, but there's no reason to keep args on a separate line.

---
 tools/lib/traceevent/plugin_cfg80211.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
tools/lib/traceevent/plugin_cfg80211.c +1 -2
index c066b25..4592d84 100644
@@ -5,8 +5,7 @@
 #include "event-parse.h"
 
 static unsigned long long
-process___le16_to_cpup(struct trace_seq *s,
-		       unsigned long long *args)
+process___le16_to_cpup(struct trace_seq *s, unsigned long long *args)
 {
 	uint16_t *val = (uint16_t *) (unsigned long) args[0];
 	return val ? (long long) le16toh(*val) : 0;
Signature · 1 line
1.8.3.1
author reviewer
#7 lore raw

PATCH 7/9 tools lib traceevent: Clean up format of args in jbd2 plugin

In reply to Jiri Olsa

From: Steven Rostedt <[email protected]>

While synchronizing what's in trace-cmd vs what's in perf, I came across a change that was made when entering the jbd2 plugin into the tools/lib/traceevent directory. For example, one of the function prototypes went from:

unsigned long long process_jbd2_dev_to_name(struct trace_seq *s,
unsigned long long *args)

to:

static unsigned long long process_jbd2_dev_to_name(struct trace_seq *s,
unsigned long long *args)

I can understand the line break after the long long, but there's no reason to keep args on a separate line.

---
 tools/lib/traceevent/plugin_jbd2.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
tools/lib/traceevent/plugin_jbd2.c +2 -4
index 0db714c..5c23d5b 100644
@@ -30,8 +30,7 @@
 #define MINOR(dev)	((unsigned int) ((dev) & MINORMASK))
 
 static unsigned long long
-process_jbd2_dev_to_name(struct trace_seq *s,
-			 unsigned long long *args)
+process_jbd2_dev_to_name(struct trace_seq *s, unsigned long long *args)
 {
 	unsigned int dev = args[0];
 
@@ -40,8 +39,7 @@ process_jbd2_dev_to_name(struct trace_seq *s,
 }
 
 static unsigned long long
-process_jiffies_to_msecs(struct trace_seq *s,
-			 unsigned long long *args)
+process_jiffies_to_msecs(struct trace_seq *s, unsigned long long *args)
 {
 	unsigned long long jiffies = args[0];
 
Signature · 1 line
1.8.3.1
author reviewer
#8 lore raw

PATCH 8/9 perf tools: Fix segfault in cumulative.callchain report

In reply to Jiri Olsa

When cumulative callchain mode is on, we could get samples with with no actual hits. This breaks the assumption of the annotation code, that each sample has annotation counts allocated and leads to segfault.

Fixing this by additional checks for annotation stats.

Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Corey Ashford <[email protected]>
Cc David Ahern <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
---
 tools/perf/ui/browsers/hists.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)
tools/perf/ui/browsers/hists.c +16 -5
index 52c03fb..04a229a 100644
@@ -17,6 +17,7 @@
 #include "../util.h"
 #include "../ui.h"
 #include "map.h"
+#include "annotate.h"
 
 struct hist_browser {
 	struct ui_browser   b;
@@ -1593,13 +1594,18 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,
 					 bi->to.sym->name) > 0)
 				annotate_t = nr_options++;
 		} else {
-
 			if (browser->selection != NULL &&
 			    browser->selection->sym != NULL &&
-			    !browser->selection->map->dso->annotate_warned &&
-				asprintf(&options[nr_options], "Annotate %s",
-					 browser->selection->sym->name) > 0)
-				annotate = nr_options++;
+			    !browser->selection->map->dso->annotate_warned) {
+				struct annotation *notes;
+
+				notes = symbol__annotation(browser->selection->sym);
+
+				if (notes->src &&
+				    asprintf(&options[nr_options], "Annotate %s",
+						 browser->selection->sym->name) > 0)
+					annotate = nr_options++;
+			}
 		}
 
 		if (thread != NULL &&
@@ -1656,6 +1662,7 @@ retry_popup_menu:
 
 		if (choice == annotate || choice == annotate_t || choice == annotate_f) {
 			struct hist_entry *he;
+			struct annotation *notes;
 			int err;
 do_annotate:
 			if (!objdump_path && perf_session_env__lookup_objdump(env))
@@ -1679,6 +1686,10 @@ do_annotate:
 				he->ms.map = he->branch_info->to.map;
 			}
 
+			notes = symbol__annotation(he->ms.sym);
+			if (!notes->src)
+				continue;
+
 			/*
 			 * Don't let this be freed, say, by hists__decay_entry.
 			 */
Signature · 1 line
1.8.3.1
author reviewer
#9 lore raw

PATCH 9/9 perf symbols: Get kernel start address by symbol name

In reply to Jiri Olsa

From: Simon Que <[email protected]>

The function machine__get_kernel_start_addr() was taking the first symbol of kallsyms as the start address. This is incorrect in certain cases where the first symbol is something at 0, while the actual kernel functions begin at a later point (e.g. 0x80200000).

This patch fixes machine__get_kernel_start_addr() to search for the symbol "_text" or "_stext", which marks the beginning of kernel mapping. This was already being done in machine__create_kernel_maps(). Thus, this patch is just a refactor, to move that code into machine__get_kernel_start_addr().

---
 tools/perf/util/machine.c | 54 +++++++++++++++++++----------------------------
 1 file changed, 22 insertions(+), 32 deletions(-)
tools/perf/util/machine.c +22 -32
index 0e5fea9..c73e1fc 100644
@@ -496,18 +496,6 @@ struct process_args {
 	u64 start;
 };
 
-static int symbol__in_kernel(void *arg, const char *name,
-			     char type __maybe_unused, u64 start)
-{
-	struct process_args *args = arg;
-
-	if (strchr(name, '['))
-		return 0;
-
-	args->start = start;
-	return 1;
-}
-
 static void machine__get_kallsyms_filename(struct machine *machine, char *buf,
 					   size_t bufsz)
 {
@@ -517,27 +505,41 @@ static void machine__get_kallsyms_filename(struct machine *machine, char *buf,
 		scnprintf(buf, bufsz, "%s/proc/kallsyms", machine->root_dir);
 }
 
-/* Figure out the start address of kernel map from /proc/kallsyms */
-static u64 machine__get_kernel_start_addr(struct machine *machine)
+const char *ref_reloc_sym_names[] = {"_text", "_stext", NULL};
+
+/* Figure out the start address of kernel map from /proc/kallsyms.
+ * Returns the name of the start symbol in *symbol_name. Pass in NULL as
+ * symbol_name if it's not that important.
+ */
+static u64 machine__get_kernel_start_addr(struct machine *machine,
+					  const char **symbol_name)
 {
 	char filename[PATH_MAX];
-	struct process_args args;
+	int i;
+	const char *name;
+	u64 addr = 0;
 
 	machine__get_kallsyms_filename(machine, filename, PATH_MAX);
 
 	if (symbol__restricted_filename(filename, "/proc/kallsyms"))
 		return 0;
 
-	if (kallsyms__parse(filename, &args, symbol__in_kernel) <= 0)
-		return 0;
+	for (i = 0; (name = ref_reloc_sym_names[i]) != NULL; i++) {
+		addr = kallsyms__get_function_start(filename, name);
+		if (addr)
+			break;
+	}
+
+	if (symbol_name)
+		*symbol_name = name;
 
-	return args.start;
+	return addr;
 }
 
 int __machine__create_kernel_maps(struct machine *machine, struct dso *kernel)
 {
 	enum map_type type;
-	u64 start = machine__get_kernel_start_addr(machine);
+	u64 start = machine__get_kernel_start_addr(machine, NULL);
 
 	for (type = 0; type < MAP__NR_TYPES; ++type) {
 		struct kmap *kmap;
@@ -852,23 +854,11 @@ static int machine__create_modules(struct machine *machine)
 	return 0;
 }
 
-const char *ref_reloc_sym_names[] = {"_text", "_stext", NULL};
-
 int machine__create_kernel_maps(struct machine *machine)
 {
 	struct dso *kernel = machine__get_kernel(machine);
-	char filename[PATH_MAX];
 	const char *name;
-	u64 addr = 0;
-	int i;
-
-	machine__get_kallsyms_filename(machine, filename, PATH_MAX);
-
-	for (i = 0; (name = ref_reloc_sym_names[i]) != NULL; i++) {
-		addr = kallsyms__get_function_start(filename, name);
-		if (addr)
-			break;
-	}
+	u64 addr = machine__get_kernel_start_addr(machine, &name);
 	if (!addr)
 		return -1;
 
Signature · 1 line
1.8.3.1