[PATCH V2 2/8] perf tools: add option to record sample physical address

From: kan . liang
Date: Thu Jan 07 2016 - 15:53:10 EST


From: Kan Liang <kan.liang@xxxxxxxxx>

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@xxxxxxxxx>
---

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