From: Ravi Bangoria <ravi.bangoria@linux.ibm.com>
To: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org
Cc: eranian@google.com, peterz@infradead.org, mpe@ellerman.id.au,
paulus@samba.org, mingo@redhat.com, acme@kernel.org,
mark.rutland@arm.com, alexander.shishkin@linux.intel.com,
jolsa@redhat.com, namhyung@kernel.org, adrian.hunter@intel.com,
ak@linux.intel.com, kan.liang@linux.intel.com,
alexey.budankov@linux.intel.com, yao.jin@linux.intel.com,
robert.richter@amd.com, kim.phillips@amd.com,
maddy@linux.ibm.com, ravi.bangoria@linux.ibm.com
Subject: [RFC 10/11] perf annotate: Preparation for hazard
Date: Mon, 2 Mar 2020 10:53:54 +0530 [thread overview]
Message-ID: <20200302052355.36365-11-ravi.bangoria@linux.ibm.com> (raw)
In-Reply-To: <20200302052355.36365-1-ravi.bangoria@linux.ibm.com>
Introduce 'struct hazard_hist' that will contain hazard specific
information for annotate. Add Array of list of 'struct hazard_hist'
into 'struct annotated_source' where array length = symbol size and
each member of list contain hazard info from associated perf sample.
This information is prepared while parsing samples in perf report.
Also, this is just a preparation step for annotate and followup
patch does actual annotate ui changes.
Signed-off-by: Ravi Bangoria <ravi.bangoria@linux.ibm.com>
---
tools/perf/builtin-report.c | 1 +
tools/perf/util/annotate.c | 75 +++++++++++++++++++++++++++++++++++++
tools/perf/util/annotate.h | 14 +++++++
tools/perf/util/hist.c | 13 +++++++
tools/perf/util/hist.h | 4 ++
tools/perf/util/machine.c | 6 +++
tools/perf/util/machine.h | 3 ++
7 files changed, 116 insertions(+)
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index a47542a12da1..ff950ff8dd51 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -301,6 +301,7 @@ static int process_sample_event(struct perf_tool *tool,
hist__account_cycles(sample->branch_stack, &al, sample,
rep->nonany_branch_mode,
&rep->total_cycles);
+ hist__capture_haz_info(&al, sample, evsel);
}
ret = hist_entry_iter__add(&iter, &al, rep->max_stack, rep);
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 8aef60a6ffea..766934b0f36d 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -36,6 +36,7 @@
#include "string2.h"
#include "util/event.h"
#include "arch/common.h"
+#include "hazard.h"
#include <regex.h>
#include <pthread.h>
#include <linux/bitops.h>
@@ -800,6 +801,21 @@ static int symbol__alloc_hist_cycles(struct symbol *sym)
return 0;
}
+static int symbol__alloc_hist_hazard(struct symbol *sym)
+{
+ struct annotation *notes = symbol__annotation(sym);
+ const size_t size = symbol__size(sym);
+ size_t i;
+
+ notes->src->haz_hist = calloc(size, sizeof(struct hazard_hist));
+ if (notes->src->haz_hist == NULL)
+ return -1;
+
+ for (i = 0; i < size; i++)
+ INIT_LIST_HEAD(¬es->src->haz_hist[i].list);
+ return 0;
+}
+
void symbol__annotate_zero_histograms(struct symbol *sym)
{
struct annotation *notes = symbol__annotation(sym);
@@ -920,6 +936,25 @@ static struct cyc_hist *symbol__cycles_hist(struct symbol *sym)
return notes->src->cycles_hist;
}
+static struct hazard_hist *symbol__hazard_hist(struct symbol *sym)
+{
+ struct annotation *notes = symbol__annotation(sym);
+
+ if (notes->src == NULL) {
+ notes->src = annotated_source__new();
+ if (notes->src == NULL)
+ return NULL;
+ goto alloc_haz_hist;
+ }
+
+ if (!notes->src->haz_hist) {
+alloc_haz_hist:
+ symbol__alloc_hist_hazard(sym);
+ }
+
+ return notes->src->haz_hist;
+}
+
struct annotated_source *symbol__hists(struct symbol *sym, int nr_hists)
{
struct annotation *notes = symbol__annotation(sym);
@@ -1014,6 +1049,46 @@ int addr_map_symbol__account_cycles(struct addr_map_symbol *ams,
return err;
}
+int symbol__capture_haz_info(struct addr_map_symbol *ams,
+ struct perf_sample *sample,
+ struct evsel *evsel)
+{
+ struct hazard_hist *hh, *tmp;
+ u64 offset;
+ const char *arch = perf_env__arch(perf_evsel__env(evsel));
+
+ if (ams->ms.sym == NULL)
+ return 0;
+
+ hh = symbol__hazard_hist(ams->ms.sym);
+ if (!hh)
+ return -ENOMEM;
+
+ if (ams->al_addr < ams->ms.sym->start || ams->al_addr >= ams->ms.sym->end)
+ return -ERANGE;
+
+ offset = ams->al_addr - ams->ms.sym->start;
+
+ tmp = zalloc(sizeof(*tmp));
+ if (!tmp)
+ return -ENOMEM;
+
+ tmp->icache = perf_haz__icache_str(sample->pipeline_haz->icache, arch);
+ tmp->haz_stage = perf_haz__hstage_str(sample->pipeline_haz->hazard_stage,
+ arch);
+ tmp->haz_reason = perf_haz__hreason_str(sample->pipeline_haz->hazard_stage,
+ sample->pipeline_haz->hazard_reason,
+ arch);
+ tmp->stall_stage = perf_haz__sstage_str(sample->pipeline_haz->stall_stage,
+ arch);
+ tmp->stall_reason = perf_haz__sreason_str(sample->pipeline_haz->stall_stage,
+ sample->pipeline_haz->stall_reason,
+ arch);
+
+ list_add(&tmp->list, &hh[offset].list);
+ return 0;
+}
+
static unsigned annotation__count_insn(struct annotation *notes, u64 start, u64 end)
{
unsigned n_insn = 0;
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
index 89839713d242..a3803f89b8fc 100644
--- a/tools/perf/util/annotate.h
+++ b/tools/perf/util/annotate.h
@@ -249,6 +249,15 @@ struct cyc_hist {
u16 reset;
};
+struct hazard_hist {
+ struct list_head list;
+ const char *icache;
+ const char *haz_stage;
+ const char *haz_reason;
+ const char *stall_stage;
+ const char *stall_reason;
+};
+
/** struct annotated_source - symbols with hits have this attached as in sannotation
*
* @histograms: Array of addr hit histograms per event being monitored
@@ -271,6 +280,7 @@ struct annotated_source {
int nr_histograms;
size_t sizeof_sym_hist;
struct cyc_hist *cycles_hist;
+ struct hazard_hist *haz_hist; /* Array of list. Array length = symbol size */
struct sym_hist *histograms;
};
@@ -343,6 +353,10 @@ int addr_map_symbol__account_cycles(struct addr_map_symbol *ams,
struct addr_map_symbol *start,
unsigned cycles);
+int symbol__capture_haz_info(struct addr_map_symbol *ams,
+ struct perf_sample *sample,
+ struct evsel *evsel);
+
int hist_entry__inc_addr_samples(struct hist_entry *he, struct perf_sample *sample,
struct evsel *evsel, u64 addr);
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index d690d08b0f64..3cbfebb80f68 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -2702,6 +2702,19 @@ void hist__account_cycles(struct branch_stack *bs, struct addr_location *al,
}
}
+void hist__capture_haz_info(struct addr_location *al,
+ struct perf_sample *sample,
+ struct evsel *evsel)
+{
+ struct addr_map_symbol ams;
+
+ if (!sample->pipeline_haz)
+ return;
+
+ sample__resolve_haz(al, &ams, sample);
+ symbol__capture_haz_info(&ams, sample, evsel);
+}
+
size_t perf_evlist__fprintf_nr_events(struct evlist *evlist, FILE *fp)
{
struct evsel *pos;
diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h
index 063d65985a11..086c1dfde21f 100644
--- a/tools/perf/util/hist.h
+++ b/tools/perf/util/hist.h
@@ -554,6 +554,10 @@ void hist__account_cycles(struct branch_stack *bs, struct addr_location *al,
struct perf_sample *sample, bool nonany_branch_mode,
u64 *total_cycles);
+void hist__capture_haz_info(struct addr_location *al,
+ struct perf_sample *sample,
+ struct evsel *evsel);
+
struct option;
int parse_filter_percentage(const struct option *opt, const char *arg, int unset);
int perf_hist_config(const char *var, const char *value);
diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index fb5c2cd44d30..e575488a1390 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -2094,6 +2094,12 @@ struct branch_info *sample__resolve_bstack(struct perf_sample *sample,
return bi;
}
+void sample__resolve_haz(struct addr_location *al, struct addr_map_symbol *ams,
+ struct perf_sample *sample)
+{
+ ip__resolve_ams(al->thread, ams, sample->ip);
+}
+
static void save_iterations(struct iterations *iter,
struct branch_entry *be, int nr)
{
diff --git a/tools/perf/util/machine.h b/tools/perf/util/machine.h
index be0a930eca89..e9a298b5430c 100644
--- a/tools/perf/util/machine.h
+++ b/tools/perf/util/machine.h
@@ -173,6 +173,9 @@ struct branch_info *sample__resolve_bstack(struct perf_sample *sample,
struct mem_info *sample__resolve_mem(struct perf_sample *sample,
struct addr_location *al);
+void sample__resolve_haz(struct addr_location *al, struct addr_map_symbol *ams,
+ struct perf_sample *sample);
+
struct callchain_cursor;
int thread__resolve_callchain(struct thread *thread,
--
2.21.1
next prev parent reply other threads:[~2020-03-02 5:25 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-02 5:23 [RFC 00/11] perf: Enhancing perf to export processor hazard information Ravi Bangoria
2020-03-02 5:23 ` [RFC 01/11] powerpc/perf: Simplify ISA207_SIER macros Ravi Bangoria
2020-03-02 5:23 ` [RFC 02/11] perf/core: Data structure to present hazard data Ravi Bangoria
2020-03-02 9:55 ` Peter Zijlstra
2020-03-02 14:23 ` maddy
2020-03-02 14:48 ` Mark Rutland
2020-03-03 14:32 ` Ravi Bangoria
2020-03-02 14:54 ` Mark Rutland
2020-03-03 14:31 ` Ravi Bangoria
2020-03-02 5:23 ` [RFC 03/11] powerpc/perf: Arch specific definitions for pipeline Ravi Bangoria
2020-03-02 5:23 ` [RFC 04/11] powerpc/perf: Arch support to expose Hazard data Ravi Bangoria
2020-03-02 5:23 ` [RFC 05/11] perf tools: Enable record and script to record and show hazard data Ravi Bangoria
2020-03-02 5:23 ` [RFC 06/11] perf hists: Make a room for hazard info in struct hist_entry Ravi Bangoria
2020-03-02 5:23 ` [RFC 07/11] perf hazard: Functions to convert generic hazard data to arch specific string Ravi Bangoria
2020-03-02 5:23 ` [RFC 08/11] perf report: Enable hazard mode Ravi Bangoria
2020-03-02 5:23 ` [RFC 09/11] perf annotate: Introduce type for annotation_line Ravi Bangoria
2020-03-02 5:23 ` Ravi Bangoria [this message]
2020-03-02 5:23 ` [RFC 11/11] perf annotate: Show hazard data in tui mode Ravi Bangoria
2020-03-02 10:13 ` [RFC 00/11] perf: Enhancing perf to export processor hazard information Peter Zijlstra
2020-03-02 20:21 ` Stephane Eranian
2020-03-02 22:25 ` Kim Phillips
2020-03-05 4:46 ` Ravi Bangoria
2020-03-05 22:06 ` Kim Phillips
2020-03-11 16:00 ` Ravi Bangoria
2020-03-12 22:38 ` Kim Phillips
2020-03-17 6:50 ` maddy
2020-03-18 17:35 ` Kim Phillips
2020-03-19 11:22 ` Michael Ellerman
2020-03-26 10:19 ` maddy
2020-03-26 19:48 ` Kim Phillips
2020-04-20 7:09 ` Madhavan Srinivasan
2020-04-27 7:18 ` Madhavan Srinivasan
2020-03-05 4:28 ` maddy
2020-03-03 1:33 ` Andi Kleen
2020-03-05 5:06 ` Ravi Bangoria
2020-03-02 21:08 ` Paul Clarke
2020-03-05 5:06 ` Ravi Bangoria
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=20200302052355.36365-11-ravi.bangoria@linux.ibm.com \
--to=ravi.bangoria@linux.ibm.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=ak@linux.intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=alexey.budankov@linux.intel.com \
--cc=eranian@google.com \
--cc=jolsa@redhat.com \
--cc=kan.liang@linux.intel.com \
--cc=kim.phillips@amd.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=maddy@linux.ibm.com \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=mpe@ellerman.id.au \
--cc=namhyung@kernel.org \
--cc=paulus@samba.org \
--cc=peterz@infradead.org \
--cc=robert.richter@amd.com \
--cc=yao.jin@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).