* [PATCH V2 2/8] perf tools: add option to record sample physical address
2016-01-07 13:30 [PATCH V2 1/8] perf: Add PERF_SAMPLE_PHYS_ADDR kan.liang
@ 2016-01-07 13:30 ` kan.liang
2016-01-07 13:30 ` [PATCH V2 3/8] perf tools: add sort option phys_daddr kan.liang
` (8 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: kan.liang @ 2016-01-07 13:30 UTC (permalink / raw)
To: peterz, acme; +Cc: eranian, ak, jolsa, namhyung, linux-kernel, Kan Liang
From: Kan Liang <kan.liang@intel.com>
Add new option --phys-data for perf record to record sample physical
address. Once the option is applied, it implies that --data option is
also applied to record sample virtual address.
Signed-off-by: Kan Liang <kan.liang@intel.com>
---
Changes since V1:
- Display PHYS_ADDR in perf evlist if applicable
- Order the PHYS_ADDR according to the order defined in the header file
tools/perf/Documentation/perf-record.txt | 6 +++++-
tools/perf/builtin-record.c | 10 +++++++++-
tools/perf/perf.h | 1 +
tools/perf/util/event.h | 1 +
tools/perf/util/evsel.c | 19 ++++++++++++++++++-
tools/perf/util/session.c | 3 +++
6 files changed, 37 insertions(+), 3 deletions(-)
diff --git a/tools/perf/Documentation/perf-record.txt b/tools/perf/Documentation/perf-record.txt
index 3a1a32f..e40c9df 100644
--- a/tools/perf/Documentation/perf-record.txt
+++ b/tools/perf/Documentation/perf-record.txt
@@ -181,7 +181,11 @@ OPTIONS
-d::
--data::
- Record the sample addresses.
+ Record the sample virtual addresses.
+
+--phys-data::
+ Record the sample physical addresses which implies
+ the virtual address is also recorded.
-T::
--timestamp::
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 9c5cdc2c4..b552f50 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -1082,7 +1082,8 @@ struct option __record_options[] = {
OPT_BOOLEAN('q', "quiet", &quiet, "don't print any message"),
OPT_BOOLEAN('s', "stat", &record.opts.inherit_stat,
"per thread counts"),
- OPT_BOOLEAN('d', "data", &record.opts.sample_address, "Record the sample addresses"),
+ OPT_BOOLEAN('d', "data", &record.opts.sample_address, "Record the sample virtual addresses"),
+ OPT_BOOLEAN(0, "phys-data", &record.opts.sample_phys_addr, "Record the sample physical addresses"),
OPT_BOOLEAN_SET('T', "timestamp", &record.opts.sample_time,
&record.opts.sample_time_set,
"Record the sample timestamps"),
@@ -1223,6 +1224,13 @@ int cmd_record(int argc, const char **argv, const char *prefix __maybe_unused)
goto out_symbol_exit;
}
+ /*
+ * Record the sample physical addr which also implies
+ * the virtual addr is recorded.
+ */
+ if (rec->opts.sample_phys_addr)
+ rec->opts.sample_address = true;
+
if (rec->opts.target.tid && !rec->opts.no_inherit_set)
rec->opts.no_inherit = true;
diff --git a/tools/perf/perf.h b/tools/perf/perf.h
index 90129ac..edfb938 100644
--- a/tools/perf/perf.h
+++ b/tools/perf/perf.h
@@ -49,6 +49,7 @@ struct record_opts {
bool no_samples;
bool raw_samples;
bool sample_address;
+ bool sample_phys_addr;
bool sample_weight;
bool sample_time;
bool sample_time_set;
diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h
index b7ffb7e..0715883 100644
--- a/tools/perf/util/event.h
+++ b/tools/perf/util/event.h
@@ -190,6 +190,7 @@ struct perf_sample {
u32 cpu;
u32 raw_size;
u64 data_src;
+ u64 phys_addr;
u32 flags;
u16 insn_len;
void *raw_data;
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 544e440..4be7533 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -838,6 +838,9 @@ void perf_evsel__config(struct perf_evsel *evsel, struct record_opts *opts)
if (opts->sample_address)
perf_evsel__set_sample_bit(evsel, DATA_SRC);
+ if (opts->sample_phys_addr)
+ perf_evsel__set_sample_bit(evsel, PHYS_ADDR);
+
if (opts->no_buffering) {
attr->watermark = 0;
attr->wakeup_events = 1;
@@ -1208,7 +1211,7 @@ static void __p_sample_type(char *buf, size_t size, u64 value)
bit_name(PERIOD), bit_name(STREAM_ID), bit_name(RAW),
bit_name(BRANCH_STACK), bit_name(REGS_USER), bit_name(STACK_USER),
bit_name(IDENTIFIER), bit_name(REGS_INTR), bit_name(DATA_SRC),
- bit_name(WEIGHT),
+ bit_name(WEIGHT), bit_name(PHYS_ADDR),
{ .name = NULL, }
};
#undef bit_name
@@ -1871,6 +1874,12 @@ int perf_evsel__parse_sample(struct perf_evsel *evsel, union perf_event *event,
}
}
+ data->phys_addr = 0;
+ if (type & PERF_SAMPLE_PHYS_ADDR) {
+ data->phys_addr = *array;
+ array++;
+ }
+
return 0;
}
@@ -1976,6 +1985,9 @@ size_t perf_event__sample_event_size(const struct perf_sample *sample, u64 type,
}
}
+ if (type & PERF_SAMPLE_PHYS_ADDR)
+ result += sizeof(u64);
+
return result;
}
@@ -2165,6 +2177,11 @@ int perf_event__synthesize_sample(union perf_event *event, u64 type,
}
}
+ if (type & PERF_SAMPLE_PHYS_ADDR) {
+ *array = sample->phys_addr;
+ array++;
+ }
+
return 0;
}
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index d5636ba..670ff4f 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -1122,6 +1122,9 @@ static void dump_sample(struct perf_evsel *evsel, union perf_event *event,
if (sample_type & PERF_SAMPLE_DATA_SRC)
printf(" . data_src: 0x%"PRIx64"\n", sample->data_src);
+ if (sample_type & PERF_SAMPLE_PHYS_ADDR)
+ printf(" .. phys_addr: 0x%"PRIx64"\n", sample->phys_addr);
+
if (sample_type & PERF_SAMPLE_TRANSACTION)
printf("... transaction: %" PRIx64 "\n", sample->transaction);
--
1.8.3.1
^ permalink raw reply [flat|nested] 11+ messages in thread* [PATCH V2 3/8] perf tools: add sort option phys_daddr
2016-01-07 13:30 [PATCH V2 1/8] perf: Add PERF_SAMPLE_PHYS_ADDR kan.liang
2016-01-07 13:30 ` [PATCH V2 2/8] perf tools: add option to record sample physical address kan.liang
@ 2016-01-07 13:30 ` kan.liang
2016-01-07 13:30 ` [PATCH V2 4/8] perf mem: add option phys-data to record physical address kan.liang
` (7 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: kan.liang @ 2016-01-07 13:30 UTC (permalink / raw)
To: peterz, acme; +Cc: eranian, ak, jolsa, namhyung, linux-kernel, Kan Liang
From: Kan Liang <kan.liang@intel.com>
Add a new sort option phys_daddr for --mem-mode sort. With this option
applied, perf can sort and report by sample's physical address.
Signed-off-by: Kan Liang <kan.liang@intel.com>
---
tools/perf/Documentation/perf-report.txt | 1 +
tools/perf/util/hist.c | 3 +++
tools/perf/util/hist.h | 1 +
tools/perf/util/machine.c | 7 ++++--
tools/perf/util/sort.c | 42 ++++++++++++++++++++++++++++++++
tools/perf/util/sort.h | 1 +
tools/perf/util/symbol.h | 1 +
7 files changed, 54 insertions(+), 2 deletions(-)
diff --git a/tools/perf/Documentation/perf-report.txt b/tools/perf/Documentation/perf-report.txt
index 8a301f6..91c387e 100644
--- a/tools/perf/Documentation/perf-report.txt
+++ b/tools/perf/Documentation/perf-report.txt
@@ -163,6 +163,7 @@ OPTIONS
- mem: type of memory access for the data at the time of sample
- snoop: type of snoop (if any) for the data at the time of sample
- dcacheline: the cacheline the data address is on at the time of sample
+ - phys_daddr: physical address of data being executed on at the time of sample
And default sort keys are changed to local_weight, mem, sym, dso,
symbol_daddr, dso_daddr, snoop, tlb, locked, see '--mem-mode'.
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index afc9b8f..3051f15 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -152,6 +152,9 @@ void hists__calc_col_len(struct hists *hists, struct hist_entry *h)
symlen = unresolved_col_width + 4 + 2;
hists__set_unres_dso_col_len(hists, HISTC_MEM_DADDR_DSO);
}
+
+ hists__new_col_len(hists, HISTC_MEM_PHYS_DADDR, unresolved_col_width + 4 + 2);
+
} else {
symlen = unresolved_col_width + 4 + 2;
hists__new_col_len(hists, HISTC_MEM_DADDR_SYMBOL, symlen);
diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h
index cb8f373..3bb574a 100644
--- a/tools/perf/util/hist.h
+++ b/tools/perf/util/hist.h
@@ -44,6 +44,7 @@ enum hist_column {
HISTC_GLOBAL_WEIGHT,
HISTC_MEM_DADDR_SYMBOL,
HISTC_MEM_DADDR_DSO,
+ HISTC_MEM_PHYS_DADDR,
HISTC_MEM_LOCKED,
HISTC_MEM_TLB,
HISTC_MEM_LVL,
diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index ad79297..6a516cc 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -1560,10 +1560,12 @@ static void ip__resolve_ams(struct thread *thread,
ams->al_addr = al.addr;
ams->sym = al.sym;
ams->map = al.map;
+ ams->phys_addr = 0;
}
static void ip__resolve_data(struct thread *thread,
- u8 m, struct addr_map_symbol *ams, u64 addr)
+ u8 m, struct addr_map_symbol *ams,
+ u64 addr, u64 phys_addr)
{
struct addr_location al;
@@ -1583,6 +1585,7 @@ static void ip__resolve_data(struct thread *thread,
ams->al_addr = al.addr;
ams->sym = al.sym;
ams->map = al.map;
+ ams->phys_addr = phys_addr;
}
struct mem_info *sample__resolve_mem(struct perf_sample *sample,
@@ -1594,7 +1597,7 @@ struct mem_info *sample__resolve_mem(struct perf_sample *sample,
return NULL;
ip__resolve_ams(al->thread, &mi->iaddr, sample->ip);
- ip__resolve_data(al->thread, al->cpumode, &mi->daddr, sample->addr);
+ ip__resolve_data(al->thread, al->cpumode, &mi->daddr, sample->addr, sample->phys_addr);
mi->data_src.val = sample->data_src;
return mi;
diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c
index a8a9588..4ce6827 100644
--- a/tools/perf/util/sort.c
+++ b/tools/perf/util/sort.c
@@ -832,6 +832,40 @@ sort__tlb_cmp(struct hist_entry *left, struct hist_entry *right)
return (int64_t)(data_src_r.mem_dtlb - data_src_l.mem_dtlb);
}
+static int64_t
+sort__phys_daddr_cmp(struct hist_entry *left, struct hist_entry *right)
+{
+ uint64_t l = 0, r = 0;
+
+ if (left->mem_info)
+ l = left->mem_info->daddr.phys_addr;
+ if (right->mem_info)
+ r = right->mem_info->daddr.phys_addr;
+
+ return (int64_t)(r - l);
+}
+
+static int hist_entry__phys_daddr_snprintf(struct hist_entry *he, char *bf,
+ size_t size, unsigned int width)
+{
+ uint64_t addr = 0;
+ size_t ret = 0;
+ size_t len = BITS_PER_LONG / 4;
+
+ addr = he->mem_info->daddr.phys_addr;
+
+ ret += repsep_snprintf(bf + ret, size - ret, "[%c] ", he->level);
+
+ ret += repsep_snprintf(bf + ret, size - ret, "%-#.*llx", len, addr);
+
+ ret += repsep_snprintf(bf + ret, size - ret, "%-*s", width - ret, "");
+
+ if (ret > width)
+ bf[width] = '\0';
+
+ return width;
+}
+
static const char * const tlb_access[] = {
"N/A",
"HIT",
@@ -1222,6 +1256,13 @@ struct sort_entry sort_mem_dcacheline = {
.se_width_idx = HISTC_MEM_DCACHELINE,
};
+struct sort_entry sort_mem_phys_daddr = {
+ .se_header = "Data Physical Address",
+ .se_cmp = sort__phys_daddr_cmp,
+ .se_snprintf = hist_entry__phys_daddr_snprintf,
+ .se_width_idx = HISTC_MEM_PHYS_DADDR,
+};
+
static int64_t
sort__abort_cmp(struct hist_entry *left, struct hist_entry *right)
{
@@ -1410,6 +1451,7 @@ static struct sort_dimension memory_sort_dimensions[] = {
DIM(SORT_MEM_LVL, "mem", sort_mem_lvl),
DIM(SORT_MEM_SNOOP, "snoop", sort_mem_snoop),
DIM(SORT_MEM_DCACHELINE, "dcacheline", sort_mem_dcacheline),
+ DIM(SORT_MEM_PHYS_DADDR, "phys_daddr", sort_mem_phys_daddr),
};
#undef DIM
diff --git a/tools/perf/util/sort.h b/tools/perf/util/sort.h
index dec536b..f6e1781 100644
--- a/tools/perf/util/sort.h
+++ b/tools/perf/util/sort.h
@@ -207,6 +207,7 @@ enum sort_type {
SORT_MEM_SNOOP,
SORT_MEM_DCACHELINE,
SORT_MEM_IADDR_SYMBOL,
+ SORT_MEM_PHYS_DADDR,
};
/*
diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h
index ccd1caa..c35c3f0 100644
--- a/tools/perf/util/symbol.h
+++ b/tools/perf/util/symbol.h
@@ -170,6 +170,7 @@ struct addr_map_symbol {
struct symbol *sym;
u64 addr;
u64 al_addr;
+ u64 phys_addr;
};
struct branch_info {
--
1.8.3.1
^ permalink raw reply [flat|nested] 11+ messages in thread* [PATCH V2 4/8] perf mem: add option phys-data to record physical address
2016-01-07 13:30 [PATCH V2 1/8] perf: Add PERF_SAMPLE_PHYS_ADDR kan.liang
2016-01-07 13:30 ` [PATCH V2 2/8] perf tools: add option to record sample physical address kan.liang
2016-01-07 13:30 ` [PATCH V2 3/8] perf tools: add sort option phys_daddr kan.liang
@ 2016-01-07 13:30 ` kan.liang
2016-01-07 13:30 ` [PATCH V2 5/8] perf mem: report physical addresses kan.liang
` (6 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: kan.liang @ 2016-01-07 13:30 UTC (permalink / raw)
To: peterz, acme; +Cc: eranian, ak, jolsa, namhyung, linux-kernel, Kan Liang
From: Kan Liang <kan.liang@intel.com>
Add option phys-data in perf mem to record physical address
Signed-off-by: Kan Liang <kan.liang@intel.com>
---
tools/perf/builtin-mem.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/tools/perf/builtin-mem.c b/tools/perf/builtin-mem.c
index 3901700..7d5ff3a 100644
--- a/tools/perf/builtin-mem.c
+++ b/tools/perf/builtin-mem.c
@@ -16,6 +16,7 @@ struct perf_mem {
bool hide_unresolved;
bool dump_raw;
bool force;
+ bool phys_addr;
int operation;
const char *cpu_list;
DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);
@@ -39,6 +40,9 @@ static int __cmd_record(int argc, const char **argv, struct perf_mem *mem)
rec_argv[i++] = "-d";
+ if (mem->phys_addr)
+ rec_argv[i++] = "--phys-data";
+
if (mem->operation & MEM_OPERATION_LOAD) {
rec_argv[i++] = "-e";
rec_argv[i++] = "cpu/mem-loads/pp";
@@ -290,6 +294,7 @@ int cmd_mem(int argc, const char **argv, const char *prefix __maybe_unused)
"separator for columns, no spaces will be added"
" between columns '.' is reserved."),
OPT_BOOLEAN('f', "force", &mem.force, "don't complain, do it"),
+ OPT_BOOLEAN('p', "phys-data", &mem.phys_addr, "Record sample physical addresses"),
OPT_END()
};
const char *const mem_subcommands[] = { "record", "report", NULL };
--
1.8.3.1
^ permalink raw reply [flat|nested] 11+ messages in thread* [PATCH V2 5/8] perf mem: report physical addresses
2016-01-07 13:30 [PATCH V2 1/8] perf: Add PERF_SAMPLE_PHYS_ADDR kan.liang
` (2 preceding siblings ...)
2016-01-07 13:30 ` [PATCH V2 4/8] perf mem: add option phys-data to record physical address kan.liang
@ 2016-01-07 13:30 ` kan.liang
2016-01-07 13:30 ` [PATCH V2 6/8] perf mem: dump " kan.liang
` (5 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: kan.liang @ 2016-01-07 13:30 UTC (permalink / raw)
To: peterz, acme; +Cc: eranian, ak, jolsa, namhyung, linux-kernel, Kan Liang
From: Kan Liang <kan.liang@intel.com>
perf mem report should support physical addresses by applying -p or
--phys-data.
Signed-off-by: Kan Liang <kan.liang@intel.com>
---
Changes since V1:
- Remove default_phys_mem_sort_order. Use a consistent format "--sort="
tools/perf/builtin-mem.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/tools/perf/builtin-mem.c b/tools/perf/builtin-mem.c
index 7d5ff3a..f8b77a3 100644
--- a/tools/perf/builtin-mem.c
+++ b/tools/perf/builtin-mem.c
@@ -176,9 +176,16 @@ static int report_events(int argc, const char **argv, struct perf_mem *mem)
* there is no weight (cost) associated with stores, so don't print
* the column
*/
- if (!(mem->operation & MEM_OPERATION_LOAD))
- rep_argv[i++] = "--sort=mem,sym,dso,symbol_daddr,"
- "dso_daddr,tlb,locked";
+ if (!(mem->operation & MEM_OPERATION_LOAD)) {
+ if (mem->phys_addr)
+ rep_argv[i++] = "--sort=mem,sym,dso,symbol_daddr,"
+ "dso_daddr,tlb,locked,phys_daddr";
+ else
+ rep_argv[i++] = "--sort=mem,sym,dso,symbol_daddr,"
+ "dso_daddr,tlb,locked";
+ } else if (mem->phys_addr)
+ rep_argv[i++] = "--sort=local_weight,mem,sym,dso,symbol_daddr,"
+ "dso_daddr,snoop,tlb,locked,phys_daddr";
for (j = 1; j < argc; j++, i++)
rep_argv[i] = argv[j];
@@ -294,7 +301,7 @@ int cmd_mem(int argc, const char **argv, const char *prefix __maybe_unused)
"separator for columns, no spaces will be added"
" between columns '.' is reserved."),
OPT_BOOLEAN('f', "force", &mem.force, "don't complain, do it"),
- OPT_BOOLEAN('p', "phys-data", &mem.phys_addr, "Record sample physical addresses"),
+ OPT_BOOLEAN('p', "phys-data", &mem.phys_addr, "Record/Report sample physical addresses"),
OPT_END()
};
const char *const mem_subcommands[] = { "record", "report", NULL };
--
1.8.3.1
^ permalink raw reply [flat|nested] 11+ messages in thread* [PATCH V2 6/8] perf mem: dump physical addresses
2016-01-07 13:30 [PATCH V2 1/8] perf: Add PERF_SAMPLE_PHYS_ADDR kan.liang
` (3 preceding siblings ...)
2016-01-07 13:30 ` [PATCH V2 5/8] perf mem: report physical addresses kan.liang
@ 2016-01-07 13:30 ` kan.liang
2016-01-07 13:30 ` [PATCH V2 7/8] perf script: support physical addresses in script kan.liang
` (4 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: kan.liang @ 2016-01-07 13:30 UTC (permalink / raw)
To: peterz, acme; +Cc: eranian, ak, jolsa, namhyung, linux-kernel, Kan Liang
From: Kan Liang <kan.liang@intel.com>
perf mem report should support dumping physical addresses by applying -p
or --phys-data.
Signed-off-by: Kan Liang <kan.liang@intel.com>
---
tools/perf/Documentation/perf-mem.txt | 4 ++
tools/perf/builtin-mem.c | 81 ++++++++++++++++++++++++-----------
2 files changed, 61 insertions(+), 24 deletions(-)
diff --git a/tools/perf/Documentation/perf-mem.txt b/tools/perf/Documentation/perf-mem.txt
index 43310d8..929575a 100644
--- a/tools/perf/Documentation/perf-mem.txt
+++ b/tools/perf/Documentation/perf-mem.txt
@@ -48,6 +48,10 @@ OPTIONS
option can be passed in record mode. It will be interpreted the same way as perf
record.
+-p::
+--phys-data::
+ Record/Report/Dump sample physical addresses
+
SEE ALSO
--------
linkperf:perf-record[1], linkperf:perf-report[1]
diff --git a/tools/perf/builtin-mem.c b/tools/perf/builtin-mem.c
index f8b77a3..192e25e 100644
--- a/tools/perf/builtin-mem.c
+++ b/tools/perf/builtin-mem.c
@@ -83,30 +83,60 @@ dump_raw_samples(struct perf_tool *tool,
if (al.map != NULL)
al.map->dso->hit = 1;
- if (symbol_conf.field_sep) {
- fmt = "%d%s%d%s0x%"PRIx64"%s0x%"PRIx64"%s%"PRIu64
- "%s0x%"PRIx64"%s%s:%s\n";
+ if (mem->phys_addr) {
+ if (symbol_conf.field_sep) {
+ fmt = "%d%s%d%s0x%"PRIx64"%s0x%"PRIx64"%s0x%016"PRIx64
+ "%s%"PRIu64"%s0x%"PRIx64"%s%s:%s\n";
+ } else {
+ fmt = "%5d%s%5d%s0x%016"PRIx64"%s0x016%"PRIx64
+ "%s0x%016"PRIx64"%s%5"PRIu64"%s0x%06"PRIx64
+ "%s%s:%s\n";
+ symbol_conf.field_sep = " ";
+ }
+
+ printf(fmt,
+ sample->pid,
+ symbol_conf.field_sep,
+ sample->tid,
+ symbol_conf.field_sep,
+ sample->ip,
+ symbol_conf.field_sep,
+ sample->addr,
+ symbol_conf.field_sep,
+ sample->phys_addr,
+ symbol_conf.field_sep,
+ sample->weight,
+ symbol_conf.field_sep,
+ sample->data_src,
+ symbol_conf.field_sep,
+ al.map ? (al.map->dso ? al.map->dso->long_name : "???") : "???",
+ al.sym ? al.sym->name : "???");
} else {
- fmt = "%5d%s%5d%s0x%016"PRIx64"%s0x016%"PRIx64
- "%s%5"PRIu64"%s0x%06"PRIx64"%s%s:%s\n";
- symbol_conf.field_sep = " ";
- }
+ if (symbol_conf.field_sep) {
+ fmt = "%d%s%d%s0x%"PRIx64"%s0x%"PRIx64"%s%"PRIu64
+ "%s0x%"PRIx64"%s%s:%s\n";
+ } else {
+ fmt = "%5d%s%5d%s0x%016"PRIx64"%s0x016%"PRIx64
+ "%s%5"PRIu64"%s0x%06"PRIx64"%s%s:%s\n";
+ symbol_conf.field_sep = " ";
+ }
- printf(fmt,
- sample->pid,
- symbol_conf.field_sep,
- sample->tid,
- symbol_conf.field_sep,
- sample->ip,
- symbol_conf.field_sep,
- sample->addr,
- symbol_conf.field_sep,
- sample->weight,
- symbol_conf.field_sep,
- sample->data_src,
- symbol_conf.field_sep,
- al.map ? (al.map->dso ? al.map->dso->long_name : "???") : "???",
- al.sym ? al.sym->name : "???");
+ printf(fmt,
+ sample->pid,
+ symbol_conf.field_sep,
+ sample->tid,
+ symbol_conf.field_sep,
+ sample->ip,
+ symbol_conf.field_sep,
+ sample->addr,
+ symbol_conf.field_sep,
+ sample->weight,
+ symbol_conf.field_sep,
+ sample->data_src,
+ symbol_conf.field_sep,
+ al.map ? (al.map->dso ? al.map->dso->long_name : "???") : "???",
+ al.sym ? al.sym->name : "???");
+ }
out_put:
addr_location__put(&al);
return 0;
@@ -146,7 +176,10 @@ static int report_raw_events(struct perf_mem *mem)
if (ret < 0)
goto out_delete;
- printf("# PID, TID, IP, ADDR, LOCAL WEIGHT, DSRC, SYMBOL\n");
+ if (mem->phys_addr)
+ printf("# PID, TID, IP, ADDR, PHYS ADDR, LOCAL WEIGHT, DSRC, SYMBOL\n");
+ else
+ printf("# PID, TID, IP, ADDR, LOCAL WEIGHT, DSRC, SYMBOL\n");
ret = perf_session__process_events(session);
@@ -301,7 +334,7 @@ int cmd_mem(int argc, const char **argv, const char *prefix __maybe_unused)
"separator for columns, no spaces will be added"
" between columns '.' is reserved."),
OPT_BOOLEAN('f', "force", &mem.force, "don't complain, do it"),
- OPT_BOOLEAN('p', "phys-data", &mem.phys_addr, "Record/Report sample physical addresses"),
+ OPT_BOOLEAN('p', "phys-data", &mem.phys_addr, "Record/Report/Dump sample physical addresses"),
OPT_END()
};
const char *const mem_subcommands[] = { "record", "report", NULL };
--
1.8.3.1
^ permalink raw reply [flat|nested] 11+ messages in thread* [PATCH V2 7/8] perf script: support physical addresses in script
2016-01-07 13:30 [PATCH V2 1/8] perf: Add PERF_SAMPLE_PHYS_ADDR kan.liang
` (4 preceding siblings ...)
2016-01-07 13:30 ` [PATCH V2 6/8] perf mem: dump " kan.liang
@ 2016-01-07 13:30 ` kan.liang
2016-01-07 13:30 ` [PATCH V2 8/8] perf test: add test case for PERF_SAMPLE_PHYS_ADDR kan.liang
` (3 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: kan.liang @ 2016-01-07 13:30 UTC (permalink / raw)
To: peterz, acme; +Cc: eranian, ak, jolsa, namhyung, linux-kernel, Kan Liang
From: Kan Liang <kan.liang@intel.com>
perf script print out physical addresses by applying phys_addr.
Signed-off-by: Kan Liang <kan.liang@intel.com>
---
Changes since V1:
- PHYS_ADDR already stored in perf.data. Remove the requirement for ADDR.
tools/perf/builtin-script.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index c298cdc..ad19eec 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -58,6 +58,7 @@ enum perf_output_field {
PERF_OUTPUT_IREGS = 1U << 14,
PERF_OUTPUT_BRSTACK = 1U << 15,
PERF_OUTPUT_BRSTACKSYM = 1U << 16,
+ PERF_OUTPUT_PHYS_ADDR = 1U << 17,
};
struct output_option {
@@ -81,6 +82,7 @@ struct output_option {
{.str = "iregs", .field = PERF_OUTPUT_IREGS},
{.str = "brstack", .field = PERF_OUTPUT_BRSTACK},
{.str = "brstacksym", .field = PERF_OUTPUT_BRSTACKSYM},
+ {.str = "phys_addr", .field = PERF_OUTPUT_PHYS_ADDR},
};
/* default set to maintain compatibility with current format */
@@ -290,6 +292,11 @@ static int perf_evsel__check_attr(struct perf_evsel *evsel,
PERF_OUTPUT_IREGS))
return -EINVAL;
+ if (PRINT_FIELD(PHYS_ADDR) &&
+ perf_evsel__do_check_stype(evsel, PERF_SAMPLE_PHYS_ADDR, "PHYS_ADDR",
+ PERF_OUTPUT_PHYS_ADDR, allow_user_set))
+ return -EINVAL;
+
return 0;
}
@@ -653,6 +660,9 @@ static void process_event(struct perf_script *script __maybe_unused, union perf_
if (PRINT_FIELD(ADDR))
print_sample_addr(event, sample, thread, attr);
+ if (PRINT_FIELD(PHYS_ADDR))
+ printf("%16" PRIx64, sample->phys_addr);
+
if (PRINT_FIELD(IP)) {
if (!symbol_conf.use_callchain)
printf(" ");
@@ -1893,7 +1903,8 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
"comma separated output fields prepend with 'type:'. "
"Valid types: hw,sw,trace,raw. "
"Fields: comm,tid,pid,time,cpu,event,trace,ip,sym,dso,"
- "addr,symoff,period,iregs,brstack,brstacksym,flags", parse_output_fields),
+ "addr,symoff,period,iregs,brstack,brstacksym,flags,phys_addr",
+ parse_output_fields),
OPT_BOOLEAN('a', "all-cpus", &system_wide,
"system-wide collection from all CPUs"),
OPT_STRING('S', "symbols", &symbol_conf.sym_list_str, "symbol[,symbol...]",
--
1.8.3.1
^ permalink raw reply [flat|nested] 11+ messages in thread* [PATCH V2 8/8] perf test: add test case for PERF_SAMPLE_PHYS_ADDR
2016-01-07 13:30 [PATCH V2 1/8] perf: Add PERF_SAMPLE_PHYS_ADDR kan.liang
` (5 preceding siblings ...)
2016-01-07 13:30 ` [PATCH V2 7/8] perf script: support physical addresses in script kan.liang
@ 2016-01-07 13:30 ` kan.liang
2016-01-07 21:08 ` [PATCH V2 1/8] perf: Add PERF_SAMPLE_PHYS_ADDR kbuild test robot
` (2 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: kan.liang @ 2016-01-07 13:30 UTC (permalink / raw)
To: peterz, acme; +Cc: eranian, ak, jolsa, namhyung, linux-kernel, Kan Liang
From: Kan Liang <kan.liang@intel.com>
Extend sample-parsing test cases to support new sample type
PERF_SAMPLE_PHYS_ADDR.
Signed-off-by: Kan Liang <kan.liang@intel.com>
---
tools/perf/tests/sample-parsing.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/tools/perf/tests/sample-parsing.c b/tools/perf/tests/sample-parsing.c
index 5f23710..8813fa1 100644
--- a/tools/perf/tests/sample-parsing.c
+++ b/tools/perf/tests/sample-parsing.c
@@ -45,6 +45,9 @@ static bool samples_same(const struct perf_sample *s1,
if (type & PERF_SAMPLE_ADDR)
COMP(addr);
+ if (type & PERF_SAMPLE_PHYS_ADDR)
+ COMP(phys_addr);
+
if (type & PERF_SAMPLE_ID)
COMP(id);
@@ -303,7 +306,7 @@ int test__sample_parsing(int subtest __maybe_unused)
* were added. Please actually update the test rather than just change
* the condition below.
*/
- if (PERF_SAMPLE_MAX > PERF_SAMPLE_REGS_INTR << 1) {
+ if (PERF_SAMPLE_MAX > PERF_SAMPLE_PHYS_ADDR << 1) {
pr_debug("sample format has changed, some new PERF_SAMPLE_ bit was introduced - test needs updating\n");
return -1;
}
--
1.8.3.1
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH V2 1/8] perf: Add PERF_SAMPLE_PHYS_ADDR
2016-01-07 13:30 [PATCH V2 1/8] perf: Add PERF_SAMPLE_PHYS_ADDR kan.liang
` (6 preceding siblings ...)
2016-01-07 13:30 ` [PATCH V2 8/8] perf test: add test case for PERF_SAMPLE_PHYS_ADDR kan.liang
@ 2016-01-07 21:08 ` kbuild test robot
2016-01-07 21:22 ` kbuild test robot
2016-01-19 16:30 ` Peter Zijlstra
9 siblings, 0 replies; 11+ messages in thread
From: kbuild test robot @ 2016-01-07 21:08 UTC (permalink / raw)
To: kan.liang
Cc: kbuild-all, peterz, acme, eranian, ak, jolsa, namhyung,
linux-kernel, Kan Liang
[-- Attachment #1: Type: text/plain, Size: 2115 bytes --]
Hi Kan,
[auto build test WARNING on tip/perf/core]
[also build test WARNING on v4.4-rc8 next-20160107]
[if your patch is applied to the wrong git tree, please drop us a note to help improving the system]
url: https://github.com/0day-ci/linux/commits/kan-liang-intel-com/perf-Add-PERF_SAMPLE_PHYS_ADDR/20160108-045715
config: i386-tinyconfig (attached as .config)
reproduce:
# save the attached .config to linux build tree
make ARCH=i386
All warnings (new ones prefixed by >>):
arch/x86/kernel/cpu/perf_event_intel_ds.c: In function 'setup_pebs_sample_data':
>> arch/x86/kernel/cpu/perf_event_intel_ds.c:1087:41: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
data->phys_addr = (u64)virt_to_phys((void *)data->addr);
^
vim +1087 arch/x86/kernel/cpu/perf_event_intel_ds.c
1071 regs->ip = pebs->real_ip;
1072 regs->flags |= PERF_EFLAGS_EXACT;
1073 } else if (event->attr.precise_ip > 1 && intel_pmu_pebs_fixup_ip(regs))
1074 regs->flags |= PERF_EFLAGS_EXACT;
1075 else
1076 regs->flags &= ~PERF_EFLAGS_EXACT;
1077
1078 if ((sample_type & PERF_SAMPLE_ADDR) &&
1079 x86_pmu.intel_cap.pebs_format >= 1)
1080 data->addr = pebs->dla;
1081
1082 if ((sample_type & PERF_SAMPLE_PHYS_ADDR) && (data->addr != 0)) {
1083 if (data->addr >= TASK_SIZE) {
1084 /* If it's vmalloc()d memory, leave phys_addr as 0 */
1085 if (virt_addr_valid(data->addr) &&
1086 !(data->addr >= VMALLOC_START && data->addr < VMALLOC_END))
> 1087 data->phys_addr = (u64)virt_to_phys((void *)data->addr);
1088 } else {
1089 /*
1090 * Walking the pages tables for user address.
1091 * Interrupts are disabled, so it prevents any tear down
1092 * of the page tables.
1093 * Try IRQ-safe __get_user_pages_fast first.
1094 * If failed, leave phys_addr as 0.
1095 */
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
[-- Attachment #2: .config.gz --]
[-- Type: application/octet-stream, Size: 6098 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH V2 1/8] perf: Add PERF_SAMPLE_PHYS_ADDR
2016-01-07 13:30 [PATCH V2 1/8] perf: Add PERF_SAMPLE_PHYS_ADDR kan.liang
` (7 preceding siblings ...)
2016-01-07 21:08 ` [PATCH V2 1/8] perf: Add PERF_SAMPLE_PHYS_ADDR kbuild test robot
@ 2016-01-07 21:22 ` kbuild test robot
2016-01-19 16:30 ` Peter Zijlstra
9 siblings, 0 replies; 11+ messages in thread
From: kbuild test robot @ 2016-01-07 21:22 UTC (permalink / raw)
To: kan.liang
Cc: kbuild-all, peterz, acme, eranian, ak, jolsa, namhyung,
linux-kernel, Kan Liang
[-- Attachment #1: Type: text/plain, Size: 2265 bytes --]
Hi Kan,
[auto build test ERROR on tip/perf/core]
[also build test ERROR on v4.4-rc8 next-20160107]
[if your patch is applied to the wrong git tree, please drop us a note to help improving the system]
url: https://github.com/0day-ci/linux/commits/kan-liang-intel-com/perf-Add-PERF_SAMPLE_PHYS_ADDR/20160108-045715
config: x86_64-randconfig-x006-01060743 (attached as .config)
reproduce:
# save the attached .config to linux build tree
make ARCH=x86_64
All errors (new ones prefixed by >>):
arch/x86/kernel/cpu/perf_event_intel_ds.c: In function 'setup_pebs_sample_data':
>> arch/x86/kernel/cpu/perf_event_intel_ds.c:1087:28: error: implicit declaration of function 'virt_to_phys' [-Werror=implicit-function-declaration]
data->phys_addr = (u64)virt_to_phys((void *)data->addr);
^
>> arch/x86/kernel/cpu/perf_event_intel_ds.c:1098:23: error: implicit declaration of function 'page_to_phys' [-Werror=implicit-function-declaration]
data->phys_addr = page_to_phys(p) + data->addr % PAGE_SIZE;
^
cc1: some warnings being treated as errors
vim +/virt_to_phys +1087 arch/x86/kernel/cpu/perf_event_intel_ds.c
1081
1082 if ((sample_type & PERF_SAMPLE_PHYS_ADDR) && (data->addr != 0)) {
1083 if (data->addr >= TASK_SIZE) {
1084 /* If it's vmalloc()d memory, leave phys_addr as 0 */
1085 if (virt_addr_valid(data->addr) &&
1086 !(data->addr >= VMALLOC_START && data->addr < VMALLOC_END))
> 1087 data->phys_addr = (u64)virt_to_phys((void *)data->addr);
1088 } else {
1089 /*
1090 * Walking the pages tables for user address.
1091 * Interrupts are disabled, so it prevents any tear down
1092 * of the page tables.
1093 * Try IRQ-safe __get_user_pages_fast first.
1094 * If failed, leave phys_addr as 0.
1095 */
1096 if ((current->mm != NULL) &&
1097 (__get_user_pages_fast(data->addr, 1, 0, &p) == 1))
> 1098 data->phys_addr = page_to_phys(p) + data->addr % PAGE_SIZE;
1099
1100 if (p)
1101 put_page(p);
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
[-- Attachment #2: .config.gz --]
[-- Type: application/octet-stream, Size: 20341 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH V2 1/8] perf: Add PERF_SAMPLE_PHYS_ADDR
2016-01-07 13:30 [PATCH V2 1/8] perf: Add PERF_SAMPLE_PHYS_ADDR kan.liang
` (8 preceding siblings ...)
2016-01-07 21:22 ` kbuild test robot
@ 2016-01-19 16:30 ` Peter Zijlstra
9 siblings, 0 replies; 11+ messages in thread
From: Peter Zijlstra @ 2016-01-19 16:30 UTC (permalink / raw)
To: kan.liang; +Cc: acme, eranian, ak, jolsa, namhyung, linux-kernel
On Thu, Jan 07, 2016 at 08:30:33AM -0500, kan.liang@intel.com wrote:
> From: Kan Liang <kan.liang@intel.com>
>
> For understanding how the workload maps to memory channels and hardware
> behavior, it's useful to collect address maps with physical addresses.
> This is not intended for detecting page sharing (which can be already
> done using the mmap inode), but for lower level hardware behavior
> studies.
This patch set completely lacks any useful example for why we should
entertain this.
> @@ -8269,6 +8275,11 @@ SYSCALL_DEFINE5(perf_event_open,
> return -EINVAL;
> }
>
> + /* Only privileged users can get kernel addresses */
> + if ((attr.sample_type & PERF_SAMPLE_PHYS_ADDR) &&
> + !capable(CAP_SYS_ADMIN))
> + return -EACCES;
> +
should that not also include a perf_paranoid_kernel() test?
^ permalink raw reply [flat|nested] 11+ messages in thread