Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1625895 > unrolled thread
| Started by | Jin Yao <yao.jin@linux.intel.com> |
|---|---|
| First post | 2017-04-19 10:00 +0200 |
| Last post | 2017-04-19 10:00 +0200 |
| Articles | 11 — 3 participants |
Back to article view | Back to linux.kernel
[PATCH v5 0/7] perf report: Show branch type Jin Yao <yao.jin@linux.intel.com> - 2017-04-19 10:00 +0200
[PATCH v5 5/7] perf util: Create branch.c/.h for common branch functions Jin Yao <yao.jin@linux.intel.com> - 2017-04-19 10:00 +0200
[PATCH v5 7/7] perf report: Show branch type in callchain entry Jin Yao <yao.jin@linux.intel.com> - 2017-04-19 10:00 +0200
Re: [PATCH v5 7/7] perf report: Show branch type in callchain entry Jiri Olsa <jolsa@redhat.com> - 2017-04-19 16:20 +0200
Re: [PATCH v5 7/7] perf report: Show branch type in callchain entry Jiri Olsa <jolsa@redhat.com> - 2017-04-19 16:20 +0200
Re: [PATCH v5 7/7] perf report: Show branch type in callchain entry "Jin, Yao" <yao.jin@linux.intel.com> - 2017-04-20 02:40 +0200
[PATCH v5 3/7] perf record: Create a new option save_type in --branch-filter Jin Yao <yao.jin@linux.intel.com> - 2017-04-19 10:00 +0200
[PATCH v5 6/7] perf report: Show branch type statistics for stdio mode Jin Yao <yao.jin@linux.intel.com> - 2017-04-19 10:00 +0200
Re: [PATCH v5 6/7] perf report: Show branch type statistics for stdio mode Jiri Olsa <jolsa@redhat.com> - 2017-04-19 16:20 +0200
Re: [PATCH v5 6/7] perf report: Show branch type statistics for stdio mode Jiri Olsa <jolsa@redhat.com> - 2017-04-19 16:20 +0200
[PATCH v5 2/7] perf/x86/intel: Record branch type Jin Yao <yao.jin@linux.intel.com> - 2017-04-19 10:00 +0200
| From | Jin Yao <yao.jin@linux.intel.com> |
|---|---|
| Date | 2017-04-19 10:00 +0200 |
| Subject | [PATCH v5 0/7] perf report: Show branch type |
| Message-ID | <txSGR-FS-7@gated-at.bofh.it> |
v5: --- Mainly the v5 patch series are updated according to comments from Jiri Olsa <jolsa@redhat.com>. The kernel part doesn't have functional change. It just solve the merge issue. In userspace, the functions of branch type counting and branch type name resolving are moved to the new files: util/branch.c, util/branch.h. And refactor the branch info printing code for better maintenance. Not changed (or just fix merge issue): perf/core: Define the common branch type classification perf/x86/intel: Record branch type perf record: Create a new option save_type in --branch-filter New patches: perf report: Refactor the branch info printing code perf util: Create branch.c/.h for common branch functions Changed: perf report: Show branch type statistics for stdio mode perf report: Show branch type in callchain entry v4: --- 1. Describe the major changes in patch description. Thanks for Peter Zijlstra's reminding. 2. Initialize branch type to 0 in intel_pmu_lbr_read_32 and intel_pmu_lbr_read_64. Remove the invalid else code in intel_pmu_lbr_filter. v3: --- 1. Move the JCC forward/backward and cross page computing from kernel to userspace. 2. Use lookup table to replace original switch/case processing. Changed: perf/core: Define the common branch type classification perf/x86/intel: Record branch type perf report: Show branch type statistics for stdio mode perf report: Show branch type in callchain entry Not changed: perf record: Create a new option save_type in --branch-filter v2: --- 1. Use 4 bits in perf_branch_entry to record branch type. 2. Pull out some common branch types from FAR_BRANCH. Now the branch types defined in perf_event.h: Jin Yao (7): perf/core: Define the common branch type classification perf/x86/intel: Record branch type perf record: Create a new option save_type in --branch-filter perf report: Refactor the branch info printing code perf util: Create branch.c/.h for common branch functions perf report: Show branch type statistics for stdio mode perf report: Show branch type in callchain entry arch/x86/events/intel/lbr.c | 53 ++++++++- include/uapi/linux/perf_event.h | 29 ++++- tools/include/uapi/linux/perf_event.h | 29 ++++- tools/perf/Documentation/perf-record.txt | 1 + tools/perf/builtin-report.c | 69 +++++++++++ tools/perf/util/Build | 1 + tools/perf/util/branch.c | 63 ++++++++++ tools/perf/util/branch.h | 23 ++++ tools/perf/util/callchain.c | 194 ++++++++++++++++++++----------- tools/perf/util/callchain.h | 5 +- tools/perf/util/event.h | 3 +- tools/perf/util/hist.c | 5 +- tools/perf/util/machine.c | 26 +++-- tools/perf/util/parse-branch-options.c | 1 + 14 files changed, 415 insertions(+), 87 deletions(-) create mode 100644 tools/perf/util/branch.c create mode 100644 tools/perf/util/branch.h -- 2.7.4
[toc] | [next] | [standalone]
| From | Jin Yao <yao.jin@linux.intel.com> |
|---|---|
| Date | 2017-04-19 10:00 +0200 |
| Subject | [PATCH v5 5/7] perf util: Create branch.c/.h for common branch functions |
| Message-ID | <txSGU-FS-101@gated-at.bofh.it> |
| In reply to | #1625895 |
Create new util/branch.c and util/branch.h to contain the common
branch functions. Such as:
branch_type_count(): Count the numbers of branch types
branch_type_name() : Return the name of branch type
The branch type is saved in branch_flags.
Change log
----------
v5: It's a new patch in v5 patch series.
Signed-off-by: Jin Yao <yao.jin@linux.intel.com>
---
tools/perf/util/Build | 1 +
tools/perf/util/branch.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++
tools/perf/util/branch.h | 23 ++++++++++++++++++
tools/perf/util/event.h | 3 ++-
4 files changed, 89 insertions(+), 1 deletion(-)
create mode 100644 tools/perf/util/branch.c
create mode 100644 tools/perf/util/branch.h
diff --git a/tools/perf/util/Build b/tools/perf/util/Build
index 5c0ea11..40e318c 100644
--- a/tools/perf/util/Build
+++ b/tools/perf/util/Build
@@ -90,6 +90,7 @@ libperf-y += vsprintf.o
libperf-y += drv_configs.o
libperf-y += time-utils.o
libperf-y += expr-bison.o
+libperf-y += branch.o
libperf-$(CONFIG_LIBBPF) += bpf-loader.o
libperf-$(CONFIG_BPF_PROLOGUE) += bpf-prologue.o
diff --git a/tools/perf/util/branch.c b/tools/perf/util/branch.c
new file mode 100644
index 0000000..702e376
--- /dev/null
+++ b/tools/perf/util/branch.c
@@ -0,0 +1,63 @@
+#include "perf.h"
+#include "util/util.h"
+#include "util/debug.h"
+#include "util/branch.h"
+
+static bool cross_area(u64 addr1, u64 addr2, int size)
+{
+ u64 align1, align2;
+
+ align1 = addr1 & ~(size - 1);
+ align2 = addr2 & ~(size - 1);
+
+ return (align1 != align2) ? true : false;
+}
+
+#define AREA_4K 4096
+#define AREA_2M (2 * 1024 * 1024)
+
+void branch_type_count(struct branch_type_stat *stat,
+ struct branch_flags *flags,
+ u64 from, u64 to)
+{
+ if (flags->type == PERF_BR_NONE || from == 0)
+ return;
+
+ stat->counts[flags->type]++;
+
+ if (flags->type == PERF_BR_JCC) {
+ if (to > from)
+ stat->jcc_fwd++;
+ else
+ stat->jcc_bwd++;
+ }
+
+ if (cross_area(from, to, AREA_2M))
+ stat->cross_2m++;
+ else if (cross_area(from, to, AREA_4K))
+ stat->cross_4k++;
+}
+
+const char *branch_type_name(int type)
+{
+ const char *branch_names[PERF_BR_MAX] = {
+ "N/A",
+ "JCC",
+ "JMP",
+ "IND_JMP",
+ "CALL",
+ "IND_CALL",
+ "RET",
+ "SYSCALL",
+ "SYSRET",
+ "IRQ",
+ "INT",
+ "IRET",
+ "FAR_BRANCH",
+ };
+
+ if (type >= 0 && type < PERF_BR_MAX)
+ return branch_names[type];
+
+ return NULL;
+}
diff --git a/tools/perf/util/branch.h b/tools/perf/util/branch.h
new file mode 100644
index 0000000..26c8da6
--- /dev/null
+++ b/tools/perf/util/branch.h
@@ -0,0 +1,23 @@
+#ifndef _PERF_BRANCH_H
+#define _PERF_BRANCH_H 1
+
+#include <stdint.h>
+#include "../perf.h"
+
+struct branch_type_stat {
+ u64 counts[PERF_BR_MAX];
+ u64 jcc_fwd;
+ u64 jcc_bwd;
+ u64 cross_4k;
+ u64 cross_2m;
+};
+
+struct branch_flags;
+
+void branch_type_count(struct branch_type_stat *stat,
+ struct branch_flags *flags,
+ u64 from, u64 to);
+
+const char *branch_type_name(int type);
+
+#endif /* _PERF_BRANCH_H */
diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h
index eb7a7b2..26b4c2e 100644
--- a/tools/perf/util/event.h
+++ b/tools/perf/util/event.h
@@ -142,7 +142,8 @@ struct branch_flags {
u64 in_tx:1;
u64 abort:1;
u64 cycles:16;
- u64 reserved:44;
+ u64 type:4;
+ u64 reserved:40;
};
struct branch_entry {
--
2.7.4
[toc] | [prev] | [next] | [standalone]
| From | Jin Yao <yao.jin@linux.intel.com> |
|---|---|
| Date | 2017-04-19 10:00 +0200 |
| Subject | [PATCH v5 7/7] perf report: Show branch type in callchain entry |
| Message-ID | <txSGV-FS-119@gated-at.bofh.it> |
| In reply to | #1625895 |
Show branch type in callchain entry. The branch type is printed
with other LBR information (such as cycles/abort/...).
For example:
perf report --branch-history --stdio --no-children
--23.56%--main div.c:42 (RET CROSS_2M cycles:2)
compute_flag div.c:28 (cycles:2)
compute_flag div.c:27 (RET CROSS_2M cycles:1)
rand rand.c:28 (cycles:1)
rand rand.c:28 (RET CROSS_2M cycles:1)
__random random.c:298 (cycles:1)
__random random.c:297 (JCC backward CROSS_2M cycles:1)
__random random.c:295 (cycles:1)
__random random.c:295 (JCC backward CROSS_2M cycles:1)
__random random.c:295 (cycles:1)
__random random.c:295 (RET CROSS_2M cycles:9)
Change log
----------
v5: Rewrite the branch info print code in util/callchain.c.
v4: Comparing to previous version, the major changes are:
Since we have to compute the JCC forward/JCC backward and cross
page checking in user space by from and to addresses, while each
callchain entry only contains one ip (either from or to), so
this patch will append a branch from address to the callchain
entry which just contains the to ip.
Signed-off-by: Jin Yao <yao.jin@linux.intel.com>
---
tools/perf/util/callchain.c | 88 ++++++++++++++++++++++++++++++++++++++++-----
tools/perf/util/callchain.h | 5 ++-
tools/perf/util/machine.c | 26 +++++++++-----
3 files changed, 101 insertions(+), 18 deletions(-)
diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c
index 8cae8a6..0cf17ae 100644
--- a/tools/perf/util/callchain.c
+++ b/tools/perf/util/callchain.c
@@ -22,6 +22,7 @@
#include "sort.h"
#include "machine.h"
#include "callchain.h"
+#include "branch.h"
__thread struct callchain_cursor callchain_cursor;
@@ -467,6 +468,11 @@ fill_node(struct callchain_node *node, struct callchain_cursor *cursor)
call->cycles_count = cursor_node->branch_flags.cycles;
call->iter_count = cursor_node->nr_loop_iter;
call->samples_count = cursor_node->samples;
+
+ branch_type_count(&call->brtype_stat,
+ &cursor_node->branch_flags,
+ cursor_node->branch_from,
+ cursor_node->ip);
}
list_add_tail(&call->list, &node->val);
@@ -579,6 +585,11 @@ static enum match_result match_chain(struct callchain_cursor_node *node,
cnode->cycles_count += node->branch_flags.cycles;
cnode->iter_count += node->nr_loop_iter;
cnode->samples_count += node->samples;
+
+ branch_type_count(&cnode->brtype_stat,
+ &node->branch_flags,
+ node->branch_from,
+ node->ip);
}
return MATCH_EQ;
@@ -813,7 +824,7 @@ merge_chain_branch(struct callchain_cursor *cursor,
list_for_each_entry_safe(list, next_list, &src->val, list) {
callchain_cursor_append(cursor, list->ip,
list->ms.map, list->ms.sym,
- false, NULL, 0, 0);
+ false, NULL, 0, 0, 0);
list_del(&list->list);
map__zput(list->ms.map);
free(list);
@@ -853,7 +864,7 @@ int callchain_merge(struct callchain_cursor *cursor,
int callchain_cursor_append(struct callchain_cursor *cursor,
u64 ip, struct map *map, struct symbol *sym,
bool branch, struct branch_flags *flags,
- int nr_loop_iter, int samples)
+ int nr_loop_iter, int samples, u64 branch_from)
{
struct callchain_cursor_node *node = *cursor->last;
@@ -877,6 +888,7 @@ int callchain_cursor_append(struct callchain_cursor *cursor,
memcpy(&node->branch_flags, flags,
sizeof(struct branch_flags));
+ node->branch_from = branch_from;
cursor->nr++;
cursor->last = &node->next;
@@ -1129,10 +1141,63 @@ static int count_float_printf(int index, const char *str, float value,
return printed;
}
+static int count_str_printf(int index, const char *str,
+ char *bf, int bfsize)
+{
+ int printed;
+
+ printed = scnprintf(bf, bfsize,
+ "%s%s",
+ (index) ? " " : " (", str);
+
+ return printed;
+}
+
+static int branch_type_str(struct branch_type_stat *stat,
+ char *bf, int bfsize)
+{
+ int i, j = 0, printed = 0;
+ u64 total = 0;
+
+ for (i = 0; i < PERF_BR_MAX; i++)
+ total += stat->counts[i];
+
+ if (total == 0)
+ return 0;
+
+ if (stat->jcc_fwd > 0)
+ printed += count_str_printf(j++, "JCC forward",
+ bf + printed, bfsize - printed);
+
+ if (stat->jcc_bwd > 0)
+ printed += count_str_printf(j++, "JCC backward",
+ bf + printed, bfsize - printed);
+
+ for (i = 0; i < PERF_BR_MAX; i++) {
+ if (i == PERF_BR_JCC)
+ continue;
+
+ if (stat->counts[i] > 0)
+ printed += count_str_printf(j++, branch_type_name(i),
+ bf + printed, bfsize - printed);
+ }
+
+ if (stat->cross_4k > 0)
+ printed += count_str_printf(j++, "CROSS_4K",
+ bf + printed, bfsize - printed);
+
+ if (stat->cross_2m > 0)
+ printed += count_str_printf(j++, "CROSS_2M",
+ bf + printed, bfsize - printed);
+
+ return printed;
+}
+
static int counts_str_build(char *bf, int bfsize,
u64 branch_count, u64 predicted_count,
u64 abort_count, u64 cycles_count,
- u64 iter_count, u64 samples_count)
+ u64 iter_count, u64 samples_count,
+ struct branch_type_stat *brtype_stat)
{
u64 cycles;
int printed = 0, i = 0;
@@ -1140,6 +1205,10 @@ static int counts_str_build(char *bf, int bfsize,
if (branch_count == 0)
return scnprintf(bf, bfsize, " (calltrace)");
+ printed = branch_type_str(brtype_stat, bf, bfsize);
+ if (printed)
+ i++;
+
cycles = cycles_count / branch_count;
if (cycles)
printed += count_pri64_printf(i++, "cycles",
@@ -1171,13 +1240,14 @@ static int counts_str_build(char *bf, int bfsize,
static int callchain_counts_printf(FILE *fp, char *bf, int bfsize,
u64 branch_count, u64 predicted_count,
u64 abort_count, u64 cycles_count,
- u64 iter_count, u64 samples_count)
+ u64 iter_count, u64 samples_count,
+ struct branch_type_stat *brtype_stat)
{
- char str[128];
+ char str[256];
counts_str_build(str, sizeof(str), branch_count,
predicted_count, abort_count, cycles_count,
- iter_count, samples_count);
+ iter_count, samples_count, brtype_stat);
if (fp)
return fprintf(fp, "%s", str);
@@ -1209,7 +1279,8 @@ int callchain_list_counts__printf_value(struct callchain_node *node,
return callchain_counts_printf(fp, bf, bfsize, branch_count,
predicted_count, abort_count,
- cycles_count, iter_count, samples_count);
+ cycles_count, iter_count, samples_count,
+ &clist->brtype_stat);
}
static void free_callchain_node(struct callchain_node *node)
@@ -1334,7 +1405,8 @@ int callchain_cursor__copy(struct callchain_cursor *dst,
rc = callchain_cursor_append(dst, node->ip, node->map, node->sym,
node->branch, &node->branch_flags,
- node->nr_loop_iter, node->samples);
+ node->nr_loop_iter, node->samples,
+ node->branch_from);
if (rc)
break;
diff --git a/tools/perf/util/callchain.h b/tools/perf/util/callchain.h
index c56c23d..9773820 100644
--- a/tools/perf/util/callchain.h
+++ b/tools/perf/util/callchain.h
@@ -7,6 +7,7 @@
#include "event.h"
#include "map.h"
#include "symbol.h"
+#include "branch.h"
#define HELP_PAD "\t\t\t\t"
@@ -119,6 +120,7 @@ struct callchain_list {
u64 cycles_count;
u64 iter_count;
u64 samples_count;
+ struct branch_type_stat brtype_stat;
char *srcline;
struct list_head list;
};
@@ -135,6 +137,7 @@ struct callchain_cursor_node {
struct symbol *sym;
bool branch;
struct branch_flags branch_flags;
+ u64 branch_from;
int nr_loop_iter;
int samples;
struct callchain_cursor_node *next;
@@ -198,7 +201,7 @@ static inline void callchain_cursor_reset(struct callchain_cursor *cursor)
int callchain_cursor_append(struct callchain_cursor *cursor, u64 ip,
struct map *map, struct symbol *sym,
bool branch, struct branch_flags *flags,
- int nr_loop_iter, int samples);
+ int nr_loop_iter, int samples, u64 branch_from);
/* Close a cursor writing session. Initialize for the reader */
static inline void callchain_cursor_commit(struct callchain_cursor *cursor)
diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index dfc6004..2309614 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -1673,7 +1673,8 @@ static int add_callchain_ip(struct thread *thread,
bool branch,
struct branch_flags *flags,
int nr_loop_iter,
- int samples)
+ int samples,
+ u64 branch_from)
{
struct addr_location al;
@@ -1726,7 +1727,8 @@ static int add_callchain_ip(struct thread *thread,
if (symbol_conf.hide_unresolved && al.sym == NULL)
return 0;
return callchain_cursor_append(cursor, al.addr, al.map, al.sym,
- branch, flags, nr_loop_iter, samples);
+ branch, flags, nr_loop_iter, samples,
+ branch_from);
}
struct branch_info *sample__resolve_bstack(struct perf_sample *sample,
@@ -1805,7 +1807,7 @@ static int resolve_lbr_callchain_sample(struct thread *thread,
struct ip_callchain *chain = sample->callchain;
int chain_nr = min(max_stack, (int)chain->nr), i;
u8 cpumode = PERF_RECORD_MISC_USER;
- u64 ip;
+ u64 ip, branch_from = 0;
for (i = 0; i < chain_nr; i++) {
if (chain->ips[i] == PERF_CONTEXT_USER)
@@ -1847,6 +1849,8 @@ static int resolve_lbr_callchain_sample(struct thread *thread,
ip = lbr_stack->entries[0].to;
branch = true;
flags = &lbr_stack->entries[0].flags;
+ branch_from =
+ lbr_stack->entries[0].from;
}
} else {
if (j < lbr_nr) {
@@ -1861,12 +1865,15 @@ static int resolve_lbr_callchain_sample(struct thread *thread,
ip = lbr_stack->entries[0].to;
branch = true;
flags = &lbr_stack->entries[0].flags;
+ branch_from =
+ lbr_stack->entries[0].from;
}
}
err = add_callchain_ip(thread, cursor, parent,
root_al, &cpumode, ip,
- branch, flags, 0, 0);
+ branch, flags, 0, 0,
+ branch_from);
if (err)
return (err < 0) ? err : 0;
}
@@ -1965,19 +1972,20 @@ static int thread__resolve_callchain_sample(struct thread *thread,
root_al,
NULL, be[i].to,
true, &be[i].flags,
- nr_loop_iter, 1);
+ nr_loop_iter, 1,
+ be[i].from);
else
err = add_callchain_ip(thread, cursor, parent,
root_al,
NULL, be[i].to,
true, &be[i].flags,
- 0, 0);
+ 0, 0, be[i].from);
if (!err)
err = add_callchain_ip(thread, cursor, parent, root_al,
NULL, be[i].from,
true, &be[i].flags,
- 0, 0);
+ 0, 0, 0);
if (err == -EINVAL)
break;
if (err)
@@ -2007,7 +2015,7 @@ static int thread__resolve_callchain_sample(struct thread *thread,
err = add_callchain_ip(thread, cursor, parent,
root_al, &cpumode, ip,
- false, NULL, 0, 0);
+ false, NULL, 0, 0, 0);
if (err)
return (err < 0) ? err : 0;
@@ -2024,7 +2032,7 @@ static int unwind_entry(struct unwind_entry *entry, void *arg)
return 0;
return callchain_cursor_append(cursor, entry->ip,
entry->map, entry->sym,
- false, NULL, 0, 0);
+ false, NULL, 0, 0, 0);
}
static int thread__resolve_callchain_unwind(struct thread *thread,
--
2.7.4
[toc] | [prev] | [next] | [standalone]
| From | Jiri Olsa <jolsa@redhat.com> |
|---|---|
| Date | 2017-04-19 16:20 +0200 |
| Subject | Re: [PATCH v5 7/7] perf report: Show branch type in callchain entry |
| Message-ID | <txYCB-4sd-13@gated-at.bofh.it> |
| In reply to | #1625898 |
On Wed, Apr 19, 2017 at 11:48:14PM +0800, Jin Yao wrote:
SNIP
> +static int count_str_printf(int index, const char *str,
> + char *bf, int bfsize)
> +{
> + int printed;
> +
> + printed = scnprintf(bf, bfsize,
> + "%s%s",
> + (index) ? " " : " (", str);
> +
> + return printed;
> +}
> +
> +static int branch_type_str(struct branch_type_stat *stat,
> + char *bf, int bfsize)
> +{
> + int i, j = 0, printed = 0;
> + u64 total = 0;
> +
> + for (i = 0; i < PERF_BR_MAX; i++)
> + total += stat->counts[i];
> +
> + if (total == 0)
> + return 0;
> +
> + if (stat->jcc_fwd > 0)
> + printed += count_str_printf(j++, "JCC forward",
> + bf + printed, bfsize - printed);
> +
> + if (stat->jcc_bwd > 0)
> + printed += count_str_printf(j++, "JCC backward",
> + bf + printed, bfsize - printed);
> +
> + for (i = 0; i < PERF_BR_MAX; i++) {
> + if (i == PERF_BR_JCC)
> + continue;
> +
> + if (stat->counts[i] > 0)
> + printed += count_str_printf(j++, branch_type_name(i),
> + bf + printed, bfsize - printed);
> + }
> +
> + if (stat->cross_4k > 0)
> + printed += count_str_printf(j++, "CROSS_4K",
> + bf + printed, bfsize - printed);
> +
> + if (stat->cross_2m > 0)
> + printed += count_str_printf(j++, "CROSS_2M",
> + bf + printed, bfsize - printed);
> +
> + return printed;
> +}
could you please also move this one to that new branch.c file
thanks,
jirka
[toc] | [prev] | [next] | [standalone]
| From | Jiri Olsa <jolsa@redhat.com> |
|---|---|
| Date | 2017-04-19 16:20 +0200 |
| Subject | Re: [PATCH v5 7/7] perf report: Show branch type in callchain entry |
| Message-ID | <txYCB-4sd-17@gated-at.bofh.it> |
| In reply to | #1625898 |
On Wed, Apr 19, 2017 at 11:48:14PM +0800, Jin Yao wrote:
SNIP
> +static int branch_type_str(struct branch_type_stat *stat,
> + char *bf, int bfsize)
> +{
> + int i, j = 0, printed = 0;
> + u64 total = 0;
> +
> + for (i = 0; i < PERF_BR_MAX; i++)
> + total += stat->counts[i];
> +
> + if (total == 0)
> + return 0;
> +
> + if (stat->jcc_fwd > 0)
> + printed += count_str_printf(j++, "JCC forward",
> + bf + printed, bfsize - printed);
> +
> + if (stat->jcc_bwd > 0)
> + printed += count_str_printf(j++, "JCC backward",
> + bf + printed, bfsize - printed);
please move that multiline conditional code inside {} brackets
thanks,
jirka
[toc] | [prev] | [next] | [standalone]
| From | "Jin, Yao" <yao.jin@linux.intel.com> |
|---|---|
| Date | 2017-04-20 02:40 +0200 |
| Subject | Re: [PATCH v5 7/7] perf report: Show branch type in callchain entry |
| Message-ID | <ty8iB-1OD-5@gated-at.bofh.it> |
| In reply to | #1626145 |
On 4/19/2017 10:15 PM, Jiri Olsa wrote:
> On Wed, Apr 19, 2017 at 11:48:14PM +0800, Jin Yao wrote:
>
> SNIP
>
>> +static int branch_type_str(struct branch_type_stat *stat,
>> + char *bf, int bfsize)
>> +{
>> + int i, j = 0, printed = 0;
>> + u64 total = 0;
>> +
>> + for (i = 0; i < PERF_BR_MAX; i++)
>> + total += stat->counts[i];
>> +
>> + if (total == 0)
>> + return 0;
>> +
>> + if (stat->jcc_fwd > 0)
>> + printed += count_str_printf(j++, "JCC forward",
>> + bf + printed, bfsize - printed);
>> +
>> + if (stat->jcc_bwd > 0)
>> + printed += count_str_printf(j++, "JCC backward",
>> + bf + printed, bfsize - printed);
> please move that multiline conditional code inside {} brackets
>
> thanks,
> jirka
Thanks so much for all of your review comments. I will add the fix to v6.
Thanks
Jin Yao
[toc] | [prev] | [next] | [standalone]
| From | Jin Yao <yao.jin@linux.intel.com> |
|---|---|
| Date | 2017-04-19 10:00 +0200 |
| Subject | [PATCH v5 3/7] perf record: Create a new option save_type in --branch-filter |
| Message-ID | <txSGW-FS-139@gated-at.bofh.it> |
| In reply to | #1625895 |
The option indicates the kernel to save branch type during sampling.
One example:
perf record -g --branch-filter any,save_type <command>
Change log
----------
v5: Not changed.
Signed-off-by: Jin Yao <yao.jin@linux.intel.com>
---
tools/perf/Documentation/perf-record.txt | 1 +
tools/perf/util/parse-branch-options.c | 1 +
2 files changed, 2 insertions(+)
diff --git a/tools/perf/Documentation/perf-record.txt b/tools/perf/Documentation/perf-record.txt
index ea3789d..e2f5a4f 100644
--- a/tools/perf/Documentation/perf-record.txt
+++ b/tools/perf/Documentation/perf-record.txt
@@ -332,6 +332,7 @@ following filters are defined:
- no_tx: only when the target is not in a hardware transaction
- abort_tx: only when the target is a hardware transaction abort
- cond: conditional branches
+ - save_type: save branch type during sampling in case binary is not available later
+
The option requires at least one branch type among any, any_call, any_ret, ind_call, cond.
diff --git a/tools/perf/util/parse-branch-options.c b/tools/perf/util/parse-branch-options.c
index 38fd115..e71fb5f 100644
--- a/tools/perf/util/parse-branch-options.c
+++ b/tools/perf/util/parse-branch-options.c
@@ -28,6 +28,7 @@ static const struct branch_mode branch_modes[] = {
BRANCH_OPT("cond", PERF_SAMPLE_BRANCH_COND),
BRANCH_OPT("ind_jmp", PERF_SAMPLE_BRANCH_IND_JUMP),
BRANCH_OPT("call", PERF_SAMPLE_BRANCH_CALL),
+ BRANCH_OPT("save_type", PERF_SAMPLE_BRANCH_TYPE_SAVE),
BRANCH_END
};
--
2.7.4
[toc] | [prev] | [next] | [standalone]
| From | Jin Yao <yao.jin@linux.intel.com> |
|---|---|
| Date | 2017-04-19 10:00 +0200 |
| Subject | [PATCH v5 6/7] perf report: Show branch type statistics for stdio mode |
| Message-ID | <txSGW-FS-147@gated-at.bofh.it> |
| In reply to | #1625895 |
Show the branch type statistics at the end of perf report --stdio.
For example:
perf report --stdio
JCC forward: 27.6%
JCC backward: 10.0%
CROSS_4K: 0.0%
CROSS_2M: 14.3%
JCC: 37.6%
JMP: 0.0%
IND_JMP: 6.5%
CALL: 26.6%
IND_CALL: 0.0%
RET: 29.3%
The branch types are:
---------------------
JCC forward: Conditional forward jump
JCC backward: Conditional backward jump
JMP: Jump imm
IND_JMP: Jump reg/mem
CALL: Call imm
IND_CALL: Call reg/mem
RET: Ret
SYSCALL: Syscall
SYSRET: Syscall return
IRQ: HW interrupt/trap/fault
INT: SW interrupt
IRET: Return from interrupt
FAR_BRANCH: Others not generic branch type
CROSS_4K and CROSS_2M:
----------------------
They are the metrics checking for branches cross 4K or 2MB pages.
It's an approximate computing. We don't know if the area is 4K or
2MB, so always compute both.
To make the output simple, if a branch crosses 2M area, CROSS_4K
will not be incremented.
Change log
----------
v5: Remove the unnecessary sort__mode checking in
hist_iter__branch_callback().
v4: Comparing to previous version, the major changes are:
Add the computing of JCC forward/JCC backward and cross page checking
by using the from and to addresses.
Signed-off-by: Jin Yao <yao.jin@linux.intel.com>
---
tools/perf/builtin-report.c | 69 +++++++++++++++++++++++++++++++++++++++++++++
tools/perf/util/hist.c | 5 +---
2 files changed, 70 insertions(+), 4 deletions(-)
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index c18158b..0050b13 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -38,6 +38,7 @@
#include "arch/common.h"
#include "util/time-utils.h"
#include "util/auxtrace.h"
+#include "util/branch.h"
#include <dlfcn.h>
#include <linux/bitmap.h>
@@ -66,6 +67,7 @@ struct report {
u64 queue_size;
int socket_filter;
DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);
+ struct branch_type_stat brtype_stat;
};
static int report__config(const char *var, const char *value, void *cb)
@@ -144,6 +146,22 @@ static int hist_iter__report_callback(struct hist_entry_iter *iter,
return err;
}
+static int hist_iter__branch_callback(struct hist_entry_iter *iter,
+ struct addr_location *al __maybe_unused,
+ bool single __maybe_unused,
+ void *arg)
+{
+ struct hist_entry *he = iter->he;
+ struct report *rep = arg;
+ struct branch_info *bi;
+
+ bi = he->branch_info;
+ branch_type_count(&rep->brtype_stat, &bi->flags,
+ bi->from.addr, bi->to.addr);
+
+ return 0;
+}
+
static int process_sample_event(struct perf_tool *tool,
union perf_event *event,
struct perf_sample *sample,
@@ -182,6 +200,8 @@ static int process_sample_event(struct perf_tool *tool,
*/
if (!sample->branch_stack)
goto out_put;
+
+ iter.add_entry_cb = hist_iter__branch_callback;
iter.ops = &hist_iter_branch;
} else if (rep->mem_mode) {
iter.ops = &hist_iter_mem;
@@ -369,6 +389,50 @@ static size_t hists__fprintf_nr_sample_events(struct hists *hists, struct report
return ret + fprintf(fp, "\n#\n");
}
+static void branch_type_stat_display(FILE *fp, struct branch_type_stat *stat)
+{
+ u64 total = 0;
+ int i;
+
+ for (i = 0; i < PERF_BR_MAX; i++)
+ total += stat->counts[i];
+
+ if (total == 0)
+ return;
+
+ fprintf(fp, "\n#");
+ fprintf(fp, "\n# Branch Statistics:");
+ fprintf(fp, "\n#");
+
+ if (stat->jcc_fwd > 0)
+ fprintf(fp, "\n%12s: %5.1f%%",
+ "JCC forward",
+ 100.0 * (double)stat->jcc_fwd / (double)total);
+
+ if (stat->jcc_bwd > 0)
+ fprintf(fp, "\n%12s: %5.1f%%",
+ "JCC backward",
+ 100.0 * (double)stat->jcc_bwd / (double)total);
+
+ if (stat->cross_4k > 0)
+ fprintf(fp, "\n%12s: %5.1f%%",
+ "CROSS_4K",
+ 100.0 * (double)stat->cross_4k / (double)total);
+
+ if (stat->cross_2m > 0)
+ fprintf(fp, "\n%12s: %5.1f%%",
+ "CROSS_2M",
+ 100.0 * (double)stat->cross_2m / (double)total);
+
+ for (i = 0; i < PERF_BR_MAX; i++) {
+ if (stat->counts[i] > 0)
+ fprintf(fp, "\n%12s: %5.1f%%",
+ branch_type_name(i),
+ 100.0 *
+ (double)stat->counts[i] / (double)total);
+ }
+}
+
static int perf_evlist__tty_browse_hists(struct perf_evlist *evlist,
struct report *rep,
const char *help)
@@ -404,6 +468,9 @@ static int perf_evlist__tty_browse_hists(struct perf_evlist *evlist,
perf_read_values_destroy(&rep->show_threads_values);
}
+ if (sort__mode == SORT_MODE__BRANCH)
+ branch_type_stat_display(stdout, &rep->brtype_stat);
+
return 0;
}
@@ -936,6 +1003,8 @@ int cmd_report(int argc, const char **argv)
if (has_br_stack && branch_call_mode)
symbol_conf.show_branchflag_count = true;
+ memset(&report.brtype_stat, 0, sizeof(struct branch_type_stat));
+
/*
* Branch mode is a tristate:
* -1 means default, so decide based on the file having branch data.
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index 61bf304..c8aee25 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -745,12 +745,9 @@ iter_prepare_branch_entry(struct hist_entry_iter *iter, struct addr_location *al
}
static int
-iter_add_single_branch_entry(struct hist_entry_iter *iter,
+iter_add_single_branch_entry(struct hist_entry_iter *iter __maybe_unused,
struct addr_location *al __maybe_unused)
{
- /* to avoid calling callback function */
- iter->he = NULL;
-
return 0;
}
--
2.7.4
[toc] | [prev] | [next] | [standalone]
| From | Jiri Olsa <jolsa@redhat.com> |
|---|---|
| Date | 2017-04-19 16:20 +0200 |
| Subject | Re: [PATCH v5 6/7] perf report: Show branch type statistics for stdio mode |
| Message-ID | <txYCB-4sd-1@gated-at.bofh.it> |
| In reply to | #1625900 |
On Wed, Apr 19, 2017 at 11:48:13PM +0800, Jin Yao wrote:
SNIP
> +static void branch_type_stat_display(FILE *fp, struct branch_type_stat *stat)
> +{
> + u64 total = 0;
> + int i;
> +
> + for (i = 0; i < PERF_BR_MAX; i++)
> + total += stat->counts[i];
> +
> + if (total == 0)
> + return;
> +
> + fprintf(fp, "\n#");
> + fprintf(fp, "\n# Branch Statistics:");
> + fprintf(fp, "\n#");
> +
> + if (stat->jcc_fwd > 0)
> + fprintf(fp, "\n%12s: %5.1f%%",
> + "JCC forward",
> + 100.0 * (double)stat->jcc_fwd / (double)total);
> +
> + if (stat->jcc_bwd > 0)
> + fprintf(fp, "\n%12s: %5.1f%%",
> + "JCC backward",
> + 100.0 * (double)stat->jcc_bwd / (double)total);
> +
> + if (stat->cross_4k > 0)
> + fprintf(fp, "\n%12s: %5.1f%%",
> + "CROSS_4K",
> + 100.0 * (double)stat->cross_4k / (double)total);
> +
> + if (stat->cross_2m > 0)
> + fprintf(fp, "\n%12s: %5.1f%%",
> + "CROSS_2M",
> + 100.0 * (double)stat->cross_2m / (double)total);
> +
> + for (i = 0; i < PERF_BR_MAX; i++) {
> + if (stat->counts[i] > 0)
> + fprintf(fp, "\n%12s: %5.1f%%",
> + branch_type_name(i),
> + 100.0 *
> + (double)stat->counts[i] / (double)total);
> + }
> +}
could you please also move this one to that new branch.c file
thanks,
jirka
[toc] | [prev] | [next] | [standalone]
| From | Jiri Olsa <jolsa@redhat.com> |
|---|---|
| Date | 2017-04-19 16:20 +0200 |
| Subject | Re: [PATCH v5 6/7] perf report: Show branch type statistics for stdio mode |
| Message-ID | <txYCC-4sd-29@gated-at.bofh.it> |
| In reply to | #1625900 |
On Wed, Apr 19, 2017 at 11:48:13PM +0800, Jin Yao wrote:
SNIP
> +static void branch_type_stat_display(FILE *fp, struct branch_type_stat *stat)
> +{
> + u64 total = 0;
> + int i;
> +
> + for (i = 0; i < PERF_BR_MAX; i++)
> + total += stat->counts[i];
> +
> + if (total == 0)
> + return;
> +
> + fprintf(fp, "\n#");
> + fprintf(fp, "\n# Branch Statistics:");
> + fprintf(fp, "\n#");
> +
> + if (stat->jcc_fwd > 0)
> + fprintf(fp, "\n%12s: %5.1f%%",
> + "JCC forward",
> + 100.0 * (double)stat->jcc_fwd / (double)total);
> +
> + if (stat->jcc_bwd > 0)
> + fprintf(fp, "\n%12s: %5.1f%%",
> + "JCC backward",
> + 100.0 * (double)stat->jcc_bwd / (double)total);
> +
> + if (stat->cross_4k > 0)
> + fprintf(fp, "\n%12s: %5.1f%%",
> + "CROSS_4K",
> + 100.0 * (double)stat->cross_4k / (double)total);
> +
> + if (stat->cross_2m > 0)
> + fprintf(fp, "\n%12s: %5.1f%%",
> + "CROSS_2M",
> + 100.0 * (double)stat->cross_2m / (double)total);
{} brackets here as well
thanks,
jirka
[toc] | [prev] | [next] | [standalone]
| From | Jin Yao <yao.jin@linux.intel.com> |
|---|---|
| Date | 2017-04-19 10:00 +0200 |
| Subject | [PATCH v5 2/7] perf/x86/intel: Record branch type |
| Message-ID | <txSGX-FS-157@gated-at.bofh.it> |
| In reply to | #1625895 |
Perf already has support for disassembling the branch instruction
and using the branch type for filtering. The patch just records
the branch type in perf_branch_entry.
Before recording, the patch converts the x86 branch type to
common branch type.
Change log
----------
v5: Just fix the merge error. No other update.
v4: Comparing to previous version, the major changes are:
1. Uses a lookup table to convert x86 branch type to common branch
type.
2. Move the JCC forward/JCC backward and cross page computing to
user space.
3. Initialize branch type to 0 in intel_pmu_lbr_read_32 and
intel_pmu_lbr_read_64
Signed-off-by: Jin Yao <yao.jin@linux.intel.com>
---
arch/x86/events/intel/lbr.c | 53 ++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 52 insertions(+), 1 deletion(-)
diff --git a/arch/x86/events/intel/lbr.c b/arch/x86/events/intel/lbr.c
index f924629..f10a7ed 100644
--- a/arch/x86/events/intel/lbr.c
+++ b/arch/x86/events/intel/lbr.c
@@ -109,6 +109,9 @@ enum {
X86_BR_ZERO_CALL = 1 << 15,/* zero length call */
X86_BR_CALL_STACK = 1 << 16,/* call stack */
X86_BR_IND_JMP = 1 << 17,/* indirect jump */
+
+ X86_BR_TYPE_SAVE = 1 << 18,/* indicate to save branch type */
+
};
#define X86_BR_PLM (X86_BR_USER | X86_BR_KERNEL)
@@ -510,6 +513,7 @@ static void intel_pmu_lbr_read_32(struct cpu_hw_events *cpuc)
cpuc->lbr_entries[i].in_tx = 0;
cpuc->lbr_entries[i].abort = 0;
cpuc->lbr_entries[i].cycles = 0;
+ cpuc->lbr_entries[i].type = 0;
cpuc->lbr_entries[i].reserved = 0;
}
cpuc->lbr_stack.nr = i;
@@ -596,6 +600,7 @@ static void intel_pmu_lbr_read_64(struct cpu_hw_events *cpuc)
cpuc->lbr_entries[out].in_tx = in_tx;
cpuc->lbr_entries[out].abort = abort;
cpuc->lbr_entries[out].cycles = cycles;
+ cpuc->lbr_entries[out].type = 0;
cpuc->lbr_entries[out].reserved = 0;
out++;
}
@@ -673,6 +678,10 @@ static int intel_pmu_setup_sw_lbr_filter(struct perf_event *event)
if (br_type & PERF_SAMPLE_BRANCH_CALL)
mask |= X86_BR_CALL | X86_BR_ZERO_CALL;
+
+ if (br_type & PERF_SAMPLE_BRANCH_TYPE_SAVE)
+ mask |= X86_BR_TYPE_SAVE;
+
/*
* stash actual user request into reg, it may
* be used by fixup code for some CPU
@@ -926,6 +935,44 @@ static int branch_type(unsigned long from, unsigned long to, int abort)
return ret;
}
+#define X86_BR_TYPE_MAP_MAX 16
+
+static int
+common_branch_type(int type)
+{
+ int i, mask;
+ const int branch_map[X86_BR_TYPE_MAP_MAX] = {
+ PERF_BR_CALL, /* X86_BR_CALL */
+ PERF_BR_RET, /* X86_BR_RET */
+ PERF_BR_SYSCALL, /* X86_BR_SYSCALL */
+ PERF_BR_SYSRET, /* X86_BR_SYSRET */
+ PERF_BR_INT, /* X86_BR_INT */
+ PERF_BR_IRET, /* X86_BR_IRET */
+ PERF_BR_JCC, /* X86_BR_JCC */
+ PERF_BR_JMP, /* X86_BR_JMP */
+ PERF_BR_IRQ, /* X86_BR_IRQ */
+ PERF_BR_IND_CALL, /* X86_BR_IND_CALL */
+ PERF_BR_NONE, /* X86_BR_ABORT */
+ PERF_BR_NONE, /* X86_BR_IN_TX */
+ PERF_BR_NONE, /* X86_BR_NO_TX */
+ PERF_BR_CALL, /* X86_BR_ZERO_CALL */
+ PERF_BR_NONE, /* X86_BR_CALL_STACK */
+ PERF_BR_IND_JMP, /* X86_BR_IND_JMP */
+ };
+
+ type >>= 2; /* skip X86_BR_USER and X86_BR_KERNEL */
+ mask = ~(~0 << 1);
+
+ for (i = 0; i < X86_BR_TYPE_MAP_MAX; i++) {
+ if (type & mask)
+ return branch_map[i];
+
+ type >>= 1;
+ }
+
+ return PERF_BR_NONE;
+}
+
/*
* implement actual branch filter based on user demand.
* Hardware may not exactly satisfy that request, thus
@@ -942,7 +989,8 @@ intel_pmu_lbr_filter(struct cpu_hw_events *cpuc)
bool compress = false;
/* if sampling all branches, then nothing to filter */
- if ((br_sel & X86_BR_ALL) == X86_BR_ALL)
+ if (((br_sel & X86_BR_ALL) == X86_BR_ALL) &&
+ ((br_sel & X86_BR_TYPE_SAVE) != X86_BR_TYPE_SAVE))
return;
for (i = 0; i < cpuc->lbr_stack.nr; i++) {
@@ -963,6 +1011,9 @@ intel_pmu_lbr_filter(struct cpu_hw_events *cpuc)
cpuc->lbr_entries[i].from = 0;
compress = true;
}
+
+ if ((br_sel & X86_BR_TYPE_SAVE) == X86_BR_TYPE_SAVE)
+ cpuc->lbr_entries[i].type = common_branch_type(type);
}
if (!compress)
--
2.7.4
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web