From: Andi Kleen <andi@firstfloor.org>
To: acme@kernel.org
Cc: jolsa@redhat.com, linux-kernel@vger.kernel.org,
namhyung@kernel.org, eranian@google.com,
Andi Kleen <ak@linux.intel.com>
Subject: [PATCH 01/10] perf, tools: Add tools support for cycles, weight branch_info field
Date: Sun, 10 May 2015 06:51:57 -0700 [thread overview]
Message-ID: <1431265926-4766-2-git-send-email-andi@firstfloor.org> (raw)
In-Reply-To: <1431265926-4766-1-git-send-email-andi@firstfloor.org>
From: Andi Kleen <ak@linux.intel.com>
cycles is a new branch_info field available on some CPUs
that indicates the time deltas between branches in the LBR.
Add a sort key and output code for the cycles
to allow to display the basic block cycles individually in perf report.
We also pass in the cycles for weight when LBRs are processed,
which allows to get global and local weight, to get an estimate
of the total cost.
And also print the cycles information for perf report -D.
I also added printing for the previously missing LBR flags
(mispredict etc.)
Signed-off-by: Andi Kleen <ak@linux.intel.com>
---
tools/perf/Documentation/perf-report.txt | 1 +
tools/perf/util/event.h | 3 ++-
tools/perf/util/hist.c | 3 ++-
tools/perf/util/hist.h | 1 +
tools/perf/util/session.c | 16 ++++++++++++----
tools/perf/util/sort.c | 24 ++++++++++++++++++++++++
tools/perf/util/sort.h | 1 +
7 files changed, 43 insertions(+), 6 deletions(-)
diff --git a/tools/perf/Documentation/perf-report.txt b/tools/perf/Documentation/perf-report.txt
index 27190ed..034a2b4 100644
--- a/tools/perf/Documentation/perf-report.txt
+++ b/tools/perf/Documentation/perf-report.txt
@@ -108,6 +108,7 @@ OPTIONS
- mispredict: "N" for predicted branch, "Y" for mispredicted branch
- in_tx: branch in TSX transaction
- abort: TSX transaction abort.
+ - cycles: Cycles in basic block
And default sort keys are changed to comm, dso_from, symbol_from, dso_to
and symbol_to, see '--branch-stack'.
diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h
index 7eecd5e..f028a3c 100644
--- a/tools/perf/util/event.h
+++ b/tools/perf/util/event.h
@@ -129,7 +129,8 @@ struct branch_flags {
u64 predicted:1;
u64 in_tx:1;
u64 abort:1;
- u64 reserved:60;
+ u64 cycles:16;
+ u64 reserved:44;
};
struct branch_entry {
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index 3387706..302fc05 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -623,7 +623,8 @@ iter_add_next_branch_entry(struct hist_entry_iter *iter, struct addr_location *a
* and not events sampled. Thus we use a pseudo period of 1.
*/
he = __hists__add_entry(hists, al, iter->parent, &bi[i], NULL,
- 1, 1, 0, true);
+ 1, bi->flags.cycles ? bi->flags.cycles : 1,
+ 0, true);
if (he == NULL)
return -ENOMEM;
diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h
index 9f31b89..b55c904 100644
--- a/tools/perf/util/hist.h
+++ b/tools/perf/util/hist.h
@@ -47,6 +47,7 @@ enum hist_column {
HISTC_MEM_SNOOP,
HISTC_MEM_DCACHELINE,
HISTC_TRANSACTION,
+ HISTC_CYCLES,
HISTC_NR_COLS, /* Last entry */
};
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index e722107..484b974 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -738,10 +738,18 @@ static void branch_stack__printf(struct perf_sample *sample)
printf("... branch stack: nr:%" PRIu64 "\n", sample->branch_stack->nr);
- for (i = 0; i < sample->branch_stack->nr; i++)
- printf("..... %2"PRIu64": %016" PRIx64 " -> %016" PRIx64 "\n",
- i, sample->branch_stack->entries[i].from,
- sample->branch_stack->entries[i].to);
+ for (i = 0; i < sample->branch_stack->nr; i++) {
+ struct branch_entry *e = &sample->branch_stack->entries[i];
+
+ printf("..... %2"PRIu64": %016" PRIx64 " -> %016" PRIx64 " %hu cycles %s%s%s%s %x\n",
+ i, e->from, e->to,
+ e->flags.cycles,
+ e->flags.mispred ? "M" : " ",
+ e->flags.predicted ? "P" : " ",
+ e->flags.abort ? "A" : " ",
+ e->flags.in_tx ? "T" : " ",
+ (unsigned)e->flags.reserved);
+ }
}
static void regs_dump__printf(u64 mask, u64 *regs)
diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c
index 4593f36..03d8e6e 100644
--- a/tools/perf/util/sort.c
+++ b/tools/perf/util/sort.c
@@ -528,6 +528,29 @@ static int hist_entry__mispredict_snprintf(struct hist_entry *he, char *bf,
return repsep_snprintf(bf, size, "%-*.*s", width, width, out);
}
+static int64_t
+sort__cycles_cmp(struct hist_entry *left, struct hist_entry *right)
+{
+ return left->branch_info->flags.cycles -
+ right->branch_info->flags.cycles;
+}
+
+static int hist_entry__cycles_snprintf(struct hist_entry *he, char *bf,
+ size_t size, unsigned int width)
+{
+ if (he->branch_info->flags.cycles == 0)
+ return repsep_snprintf(bf, size, "%-*s", width, "-");
+ return repsep_snprintf(bf, size, "%-*hd", width,
+ he->branch_info->flags.cycles);
+}
+
+struct sort_entry sort_cycles = {
+ .se_header = "Basic Block Cycles",
+ .se_cmp = sort__cycles_cmp,
+ .se_snprintf = hist_entry__cycles_snprintf,
+ .se_width_idx = HISTC_CYCLES,
+};
+
/* --sort daddr_sym */
static int64_t
sort__daddr_cmp(struct hist_entry *left, struct hist_entry *right)
@@ -1192,6 +1215,7 @@ static struct sort_dimension bstack_sort_dimensions[] = {
DIM(SORT_MISPREDICT, "mispredict", sort_mispredict),
DIM(SORT_IN_TX, "in_tx", sort_in_tx),
DIM(SORT_ABORT, "abort", sort_abort),
+ DIM(SORT_CYCLES, "cycles", sort_cycles),
};
#undef DIM
diff --git a/tools/perf/util/sort.h b/tools/perf/util/sort.h
index e97cd47..bc6c87a 100644
--- a/tools/perf/util/sort.h
+++ b/tools/perf/util/sort.h
@@ -185,6 +185,7 @@ enum sort_type {
SORT_MISPREDICT,
SORT_ABORT,
SORT_IN_TX,
+ SORT_CYCLES,
/* memory mode specific sort keys */
__SORT_MEMORY_MODE,
--
1.9.3
next prev parent reply other threads:[~2015-05-10 13:54 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-10 13:51 Cycles annotation support for perf tools Andi Kleen
2015-05-10 13:51 ` Andi Kleen [this message]
2015-05-10 13:51 ` [PATCH 02/10] perf, tools, report: Add flag for non ANY branch mode Andi Kleen
2015-05-10 13:51 ` [PATCH 03/10] perf, tools, report: Add infrastructure for a cycles histogram Andi Kleen
2015-05-10 13:52 ` [PATCH 04/10] perf, tools, report: Add processing for cycle histograms Andi Kleen
2015-05-26 10:09 ` Jiri Olsa
2015-05-26 17:37 ` Andi Kleen
2015-06-01 13:02 ` Jiri Olsa
2015-06-01 13:07 ` Andi Kleen
2015-05-10 13:52 ` [PATCH 05/10] perf, tools: Compute IPC and basic block cycles for annotate Andi Kleen
2015-05-10 13:52 ` [PATCH 06/10] perf, tools, annotate: Finally display IPC and cycle accounting Andi Kleen
2015-05-10 13:52 ` [PATCH 07/10] perf, tools, report: Move branch option parsing to own file Andi Kleen
2015-05-26 10:09 ` Jiri Olsa
2015-05-10 13:52 ` [PATCH 08/10] perf, tools, top: Add branch annotation code to top Andi Kleen
2015-05-10 13:52 ` [PATCH 09/10] perf, tools, report: Display cycles in branch sort mode Andi Kleen
2015-05-10 13:52 ` [PATCH 10/10] test patch: Add fake branch cycles to input data in report/top Andi Kleen
2015-05-18 19:06 ` Cycles annotation support for perf tools Andi Kleen
2015-05-19 9:55 ` Jiri Olsa
2015-05-24 18:55 ` Jiri Olsa
2015-05-24 19:19 ` Andi Kleen
2015-05-26 10:08 ` Jiri Olsa
2015-05-26 16:56 ` Andi Kleen
2015-05-26 21:40 ` Andi Kleen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1431265926-4766-2-git-send-email-andi@firstfloor.org \
--to=andi@firstfloor.org \
--cc=acme@kernel.org \
--cc=ak@linux.intel.com \
--cc=eranian@google.com \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=namhyung@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox