Skip to contentSkip to conversation

support PERF_SAMPLE_PHYS_ADDR (user)

PATCH In review [email protected] 4 participants 16 messages Aug 29, 2017 – Sep 5, 2017 perf events

lore
Share & tools
lore
#0 lore raw

v2 cover support PERF_SAMPLE_PHYS_ADDR (user)

From: Kan Liang <[email protected]>

The patch series is to support PERF_SAMPLE_PHYS_ADDR in user perf tool. The kernel patch has been merged, which commit ID is fc7ce9c74c3a ("perf/core, x86: Add PERF_SAMPLE_PHYS_ADDR").

Changes since V1:
- Don't mandate SAMPLE_ADDR when SAMPLE_PHYS_ADDR
- Update change log

Kan Liang (5):
perf tools: support new sample type for physical address perf tools: add sort option for physical address perf mem: support physical address
perf script: support physical address
perf test: add test case for PERF_SAMPLE_PHYS_ADDR

 tools/include/uapi/linux/perf_event.h    |  4 +-
 tools/perf/Documentation/perf-mem.txt    |  4 ++
 tools/perf/Documentation/perf-record.txt |  5 +-
 tools/perf/Documentation/perf-report.txt |  1 +
 tools/perf/Documentation/perf-script.txt |  2 +-
 tools/perf/builtin-mem.c                 | 97 +++++++++++++++++++++++---------
 tools/perf/builtin-record.c              |  2 +
 tools/perf/builtin-script.c              | 15 ++++-
 tools/perf/perf.h                        |  1 +
 tools/perf/tests/sample-parsing.c        |  6 +-
 tools/perf/util/event.h                  |  1 +
 tools/perf/util/evsel.c                  | 17 ++++++
 tools/perf/util/hist.c                   |  4 ++
 tools/perf/util/hist.h                   |  1 +
 tools/perf/util/machine.c                |  8 ++-
 tools/perf/util/session.c                |  3 +
 tools/perf/util/sort.c                   | 42 ++++++++++++++
 tools/perf/util/sort.h                   |  1 +
 tools/perf/util/symbol.h                 |  1 +
 19 files changed, 181 insertions(+), 34 deletions(-)
Signature · 1 line
2.4.3
#1 lore raw

PATCH v2 1/5 perf tools: support new sample type for physical address

From: Kan Liang <[email protected]>

Support new sample type PERF_SAMPLE_PHYS_ADDR for physical address.

Add new option --phys-data to record sample physical address.

---
 tools/include/uapi/linux/perf_event.h    |  4 +++-
 tools/perf/Documentation/perf-record.txt |  5 ++++-
 tools/perf/builtin-record.c              |  2 ++
 tools/perf/perf.h                        |  1 +
 tools/perf/util/event.h                  |  1 +
 tools/perf/util/evsel.c                  | 17 +++++++++++++++++
 6 files changed, 28 insertions(+), 2 deletions(-)
tools/include/uapi/linux/perf_event.h +3 -1
index 2a37ae9..140ae63 100644
@@ -139,8 +139,9 @@ enum perf_event_sample_format {
 	PERF_SAMPLE_IDENTIFIER			= 1U << 16,
 	PERF_SAMPLE_TRANSACTION			= 1U << 17,
 	PERF_SAMPLE_REGS_INTR			= 1U << 18,
+	PERF_SAMPLE_PHYS_ADDR			= 1U << 19,
 
-	PERF_SAMPLE_MAX = 1U << 19,		/* non-ABI */
+	PERF_SAMPLE_MAX = 1U << 20,		/* non-ABI */
 };
 
 /*
@@ -814,6 +815,7 @@ enum perf_event_type {
 	 *	{ u64			transaction; } && PERF_SAMPLE_TRANSACTION
 	 *	{ u64			abi; # enum perf_sample_regs_abi
 	 *	  u64			regs[weight(mask)]; } && PERF_SAMPLE_REGS_INTR
+	 *	{ u64			phys_addr;} && PERF_SAMPLE_PHYS_ADDR
 	 * };
 	 */
 	PERF_RECORD_SAMPLE			= 9,
tools/perf/Documentation/perf-record.txt +4 -1
index 9bdea04..e397453 100644
@@ -249,7 +249,10 @@ OPTIONS
 
 -d::
 --data::
-	Record the sample addresses.
+	Record the sample virtual addresses.
+
+--phys-data::
+	Record the sample physical addresses.
 
 -T::
 --timestamp::
tools/perf/builtin-record.c +2 -0
index 36d7117..56f8142 100644
@@ -1604,6 +1604,8 @@ static struct option __record_options[] = {
 	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(0, "phys-data", &record.opts.sample_phys_addr,
+		    "Record the sample physical addresses"),
 	OPT_BOOLEAN(0, "sample-cpu", &record.opts.sample_cpu, "Record the sample cpu"),
 	OPT_BOOLEAN_SET('T', "timestamp", &record.opts.sample_time,
 			&record.opts.sample_time_set,
tools/perf/perf.h +1 -0
index 2c010dd..dc442ba 100644
@@ -43,6 +43,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;
tools/perf/util/event.h +1 -0
index 423ac82..ee7bcc8 100644
@@ -200,6 +200,7 @@ struct perf_sample {
 	u32 cpu;
 	u32 raw_size;
 	u64 data_src;
+	u64 phys_addr;
 	u32 flags;
 	u16 insn_len;
 	u8  cpumode;
tools/perf/util/evsel.c +17 -0
index a5888c7..228a78d 100644
@@ -950,6 +950,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;
@@ -2201,6 +2204,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;
 }
 
@@ -2306,6 +2315,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;
 }
 
@@ -2495,6 +2507,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;
 }
 
Signature · 1 line
2.4.3
#2 lore raw

Re: [PATCH V2 1/5] perf tools: support new sample type for physical address

On Tue, Aug 29, 2017 at 01:11:08PM -0400, [email protected] wrote:

SNIP

Quoted 39 lines
tools/perf/util/evsel.c +12 -0
index a5888c7..228a78d 100644
@@ -950,6 +950,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;
@@ -2201,6 +2204,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;
 }
 
@@ -2306,6 +2315,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;
 }
 
@@ -2495,6 +2507,11 @@ int perf_event__synthesize_sample(union perf_event *event, u64 type,
 		}

tools/perf/util/evsel.c int perf_event__synthesize_sample(union perf_event *event, u64 type, · line 2517

Quoted 10 lines
tools/perf/util/evsel.c +5 -0
 	}
 
+	if (type & PERF_SAMPLE_PHYS_ADDR) {
+		*array = sample->phys_addr;
+		array++;
+	}
+
 	return 0;
 }
 

missing the printing bits

jirka

tools/perf/util/evsel.c +1 -1
index e705c0d59a69..4bb89373eb52 100644
@@ -1467,7 +1467,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
#3 lore raw

Re: [PATCH V2 1/5] perf tools: support new sample type for physical address

Em Fri, Sep 01, 2017 at 05:28:27PM +0200, Jiri Olsa escreveu:

Quoted 45 lines · On Tue, Aug 29, 2017 at 01:11:08PM -0400, [email protected] wrote:

SNIP

Quoted 41 lines
tools/perf/util/evsel.c +12 -0
index a5888c7..228a78d 100644
@@ -950,6 +950,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;
@@ -2201,6 +2204,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;
 }
 
@@ -2306,6 +2315,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;
 }
 
@@ -2495,6 +2507,11 @@ int perf_event__synthesize_sample(union perf_event *event, u64 type,
 		}
 	}
 
Quoted 10 lines

tools/perf/util/evsel.c int perf_event__synthesize_sample(union perf_event *event, u64 type, · line 2517

Quoted 8 lines
tools/perf/util/evsel.c +5 -0
+	if (type & PERF_SAMPLE_PHYS_ADDR) {
+		*array = sample->phys_addr;
+		array++;
+	}
+
 	return 0;
 }
 

missing the printing bits

I'm folding this one there then,

- Arnaldo

Quoted 16 lines

jirka

tools/perf/util/evsel.c +1 -1
index e705c0d59a69..4bb89373eb52 100644
@@ -1467,7 +1467,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
#4 lore raw

[tip:perf/urgent] perf tools: Support new sample type for physical address

In reply to [email protected]
perf tools: Support new sample type for physical address
Commit-ID:  3b0a5daa061076b2b75ffc294e74483ad9bf241a
Gitweb:     http://git.kernel.org/tip/3b0a5daa061076b2b75ffc294e74483ad9bf241a
Author:     Kan Liang <[email protected]>
AuthorDate: Tue, 29 Aug 2017 13:11:08 -0400
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Fri, 1 Sep 2017 14:46:00 -0300

perf tools: Support new sample type for physical address

Support new sample type PERF_SAMPLE_PHYS_ADDR for physical address.

Add new option --phys-data to record sample physical address.

Cc Andi Kleen <[email protected]>
Cc Madhavan Srinivasan <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>
[ Added missing printing in evsel.c patch sent by Jiri Olsa ]
---
 tools/include/uapi/linux/perf_event.h    |  4 +++-
 tools/perf/Documentation/perf-record.txt |  5 ++++-
 tools/perf/builtin-record.c              |  2 ++
 tools/perf/perf.h                        |  1 +
 tools/perf/util/event.h                  |  1 +
 tools/perf/util/evsel.c                  | 19 ++++++++++++++++++-
 6 files changed, 29 insertions(+), 3 deletions(-)
tools/include/uapi/linux/perf_event.h +3 -1
index 2a37ae9..140ae63 100644
@@ -139,8 +139,9 @@ enum perf_event_sample_format {
 	PERF_SAMPLE_IDENTIFIER			= 1U << 16,
 	PERF_SAMPLE_TRANSACTION			= 1U << 17,
 	PERF_SAMPLE_REGS_INTR			= 1U << 18,
+	PERF_SAMPLE_PHYS_ADDR			= 1U << 19,
 
-	PERF_SAMPLE_MAX = 1U << 19,		/* non-ABI */
+	PERF_SAMPLE_MAX = 1U << 20,		/* non-ABI */
 };
 
 /*
@@ -814,6 +815,7 @@ enum perf_event_type {
 	 *	{ u64			transaction; } && PERF_SAMPLE_TRANSACTION
 	 *	{ u64			abi; # enum perf_sample_regs_abi
 	 *	  u64			regs[weight(mask)]; } && PERF_SAMPLE_REGS_INTR
+	 *	{ u64			phys_addr;} && PERF_SAMPLE_PHYS_ADDR
 	 * };
 	 */
 	PERF_RECORD_SAMPLE			= 9,
tools/perf/Documentation/perf-record.txt +4 -1
index 9bdea04..e397453 100644
@@ -249,7 +249,10 @@ OPTIONS
 
 -d::
 --data::
-	Record the sample addresses.
+	Record the sample virtual addresses.
+
+--phys-data::
+	Record the sample physical addresses.
 
 -T::
 --timestamp::
tools/perf/builtin-record.c +2 -0
index 36d7117..56f8142 100644
@@ -1604,6 +1604,8 @@ static struct option __record_options[] = {
 	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(0, "phys-data", &record.opts.sample_phys_addr,
+		    "Record the sample physical addresses"),
 	OPT_BOOLEAN(0, "sample-cpu", &record.opts.sample_cpu, "Record the sample cpu"),
 	OPT_BOOLEAN_SET('T', "timestamp", &record.opts.sample_time,
 			&record.opts.sample_time_set,
tools/perf/perf.h +1 -0
index 2c010dd..dc442ba 100644
@@ -43,6 +43,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;
tools/perf/util/event.h +1 -0
index 423ac82..ee7bcc8 100644
@@ -200,6 +200,7 @@ struct perf_sample {
 	u32 cpu;
 	u32 raw_size;
 	u64 data_src;
+	u64 phys_addr;
 	u32 flags;
 	u16 insn_len;
 	u8  cpumode;
tools/perf/util/evsel.c +18 -1
index d9bd632..4bb8937 100644
@@ -955,6 +955,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;
@@ -1464,7 +1467,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
@@ -2206,6 +2209,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;
 }
 
@@ -2311,6 +2320,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;
 }
 
@@ -2500,6 +2512,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;
 }
 
#5 lore raw

PATCH v2 2/5 perf tools: add sort option for physical address

In reply to [email protected]

From: Kan Liang <[email protected]>

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.

---
 tools/perf/Documentation/perf-report.txt |  1 +
 tools/perf/util/hist.c                   |  4 +++
 tools/perf/util/hist.h                   |  1 +
 tools/perf/util/machine.c                |  8 ++++--
 tools/perf/util/session.c                |  3 +++
 tools/perf/util/sort.c                   | 42 ++++++++++++++++++++++++++++++++
 tools/perf/util/sort.h                   |  1 +
 tools/perf/util/symbol.h                 |  1 +
 8 files changed, 59 insertions(+), 2 deletions(-)
tools/perf/Documentation/perf-report.txt +1 -0
index 9fa8461..383a98d 100644
@@ -137,6 +137,7 @@ OPTIONS
 	- mem: type of memory access for the data at the time of the sample
 	- snoop: type of snoop (if any) for the data at the time of the sample
 	- dcacheline: the cacheline the data address is on at the time of the sample
+	- phys_daddr: physical address of data being executed on at the time of sample
 
 	And the default sort keys are changed to local_weight, mem, sym, dso,
 	symbol_daddr, dso_daddr, snoop, tlb, locked, see '--mem-mode'.
tools/perf/util/hist.c +4 -0
index 9453b2e..e60d8d8 100644
@@ -167,6 +167,10 @@ 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);
tools/perf/util/hist.h +1 -0
index ee3670a..e60dda2 100644
@@ -47,6 +47,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,
tools/perf/util/machine.c +6 -2
index 5c8eaca..879e64e 100644
@@ -1635,10 +1635,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;
 
@@ -1658,6 +1660,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,
@@ -1669,7 +1672,8 @@ 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;
tools/perf/util/session.c +3 -0
index dc453f8..5348d5c 100644
@@ -1120,6 +1120,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);
 
tools/perf/util/sort.c +42 -0

54 lines not on this page · raw message

tools/perf/util/sort.h +1 -0
index b7c7559..f36dc49 100644
@@ -245,6 +245,7 @@ enum sort_type {
 	SORT_MEM_SNOOP,
 	SORT_MEM_DCACHELINE,
 	SORT_MEM_IADDR_SYMBOL,
+	SORT_MEM_PHYS_DADDR,
 };
 
 /*
tools/perf/util/symbol.h +1 -0
index d00a012..2bd6a1f 100644
@@ -186,6 +186,7 @@ struct addr_map_symbol {
 	struct symbol *sym;
 	u64	      addr;
 	u64	      al_addr;
+	u64	      phys_addr;
 };
 
 struct branch_info {
Signature · 1 line
2.4.3
#6 lore raw

[tip:perf/urgent] perf sort: Add sort option for physical address

perf sort: Add sort option for physical address
Commit-ID:  8780fb25ab060bafa5a8149e79b703e0fc7ee847
Gitweb:     http://git.kernel.org/tip/8780fb25ab060bafa5a8149e79b703e0fc7ee847
Author:     Kan Liang <[email protected]>
AuthorDate: Tue, 29 Aug 2017 13:11:09 -0400
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Fri, 1 Sep 2017 14:46:11 -0300

perf sort: Add sort option for physical address

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.

---
 tools/perf/Documentation/perf-report.txt |  1 +
 tools/perf/util/hist.c                   |  4 +++
 tools/perf/util/hist.h                   |  1 +
 tools/perf/util/machine.c                |  8 ++++--
 tools/perf/util/session.c                |  3 +++
 tools/perf/util/sort.c                   | 42 ++++++++++++++++++++++++++++++++
 tools/perf/util/sort.h                   |  1 +
 tools/perf/util/symbol.h                 |  1 +
 8 files changed, 59 insertions(+), 2 deletions(-)
tools/perf/Documentation/perf-report.txt +1 -0
index 9fa8461..383a98d 100644
@@ -137,6 +137,7 @@ OPTIONS
 	- mem: type of memory access for the data at the time of the sample
 	- snoop: type of snoop (if any) for the data at the time of the sample
 	- dcacheline: the cacheline the data address is on at the time of the sample
+	- phys_daddr: physical address of data being executed on at the time of sample
 
 	And the default sort keys are changed to local_weight, mem, sym, dso,
 	symbol_daddr, dso_daddr, snoop, tlb, locked, see '--mem-mode'.
tools/perf/util/hist.c +4 -0
index 9453b2e..e60d8d8 100644
@@ -167,6 +167,10 @@ 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);
tools/perf/util/hist.h +1 -0
index ee3670a..e60dda2 100644
@@ -47,6 +47,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,
tools/perf/util/machine.c +6 -2
index 9eaa953..df70936 100644
@@ -1635,10 +1635,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;
 
@@ -1658,6 +1660,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,
@@ -1669,7 +1672,8 @@ 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;
tools/perf/util/session.c +3 -0
index ac86369..a7ebd9f 100644
@@ -1120,6 +1120,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);
 
tools/perf/util/sort.c +42 -0

54 lines not on this page · raw message

tools/perf/util/sort.h +1 -0
index b7c7559..f36dc49 100644
@@ -245,6 +245,7 @@ enum sort_type {
 	SORT_MEM_SNOOP,
 	SORT_MEM_DCACHELINE,
 	SORT_MEM_IADDR_SYMBOL,
+	SORT_MEM_PHYS_DADDR,
 };
 
 /*
tools/perf/util/symbol.h +1 -0
index d00a012..2bd6a1f 100644
@@ -186,6 +186,7 @@ struct addr_map_symbol {
 	struct symbol *sym;
 	u64	      addr;
 	u64	      al_addr;
+	u64	      phys_addr;
 };
 
 struct branch_info {
#7 lore raw

PATCH v2 3/5 perf mem: support physical address

In reply to [email protected]

From: Kan Liang <[email protected]>

Add option phys-data in perf mem to record/report physical address. The default mem sort order for physical address is changed accordingly.

---
 tools/perf/Documentation/perf-mem.txt |  4 ++
 tools/perf/builtin-mem.c              | 97 +++++++++++++++++++++++++----------
 2 files changed, 75 insertions(+), 26 deletions(-)
tools/perf/Documentation/perf-mem.txt +4 -0
index 7349632..4be08a1 100644
@@ -59,6 +59,10 @@ OPTIONS
 --ldload::
 	Specify desired latency for loads event.
 
+-p::
+--phys-data::
+	Record/Report sample physical addresses
+
 SEE ALSO
 --------
 linkperf:perf-record[1], linkperf:perf-report[1]
tools/perf/builtin-mem.c +71 -26

135 lines not on this page · raw message

Signature · 1 line
2.4.3
#8 lore raw

[tip:perf/urgent] perf mem: Support physical address

perf mem: Support physical address
Commit-ID:  c35aeb9dfe512422ca9ea28aae692c8f1d052b2d
Gitweb:     http://git.kernel.org/tip/c35aeb9dfe512422ca9ea28aae692c8f1d052b2d
Author:     Kan Liang <[email protected]>
AuthorDate: Tue, 29 Aug 2017 13:11:10 -0400
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Fri, 1 Sep 2017 14:46:23 -0300

perf mem: Support physical address

Add option phys-data in "perf mem" to record/report physical address. The default mem sort order for physical address is changed accordingly.

---
 tools/perf/Documentation/perf-mem.txt |  4 ++
 tools/perf/builtin-mem.c              | 97 +++++++++++++++++++++++++----------
 2 files changed, 75 insertions(+), 26 deletions(-)
tools/perf/Documentation/perf-mem.txt +4 -0
index 7349632..4be08a1 100644
@@ -59,6 +59,10 @@ OPTIONS
 --ldload::
 	Specify desired latency for loads event.
 
+-p::
+--phys-data::
+	Record/Report sample physical addresses
+
 SEE ALSO
 --------
 linkperf:perf-record[1], linkperf:perf-report[1]
tools/perf/builtin-mem.c +71 -26

135 lines not on this page · raw message

#9 lore raw

PATCH v2 4/5 perf script: support physical address

In reply to [email protected]

From: Kan Liang <[email protected]>

Display the physical address at the tail if it is available.

---
 tools/perf/Documentation/perf-script.txt |  2 +-
 tools/perf/builtin-script.c              | 15 +++++++++++++--
 2 files changed, 14 insertions(+), 3 deletions(-)
tools/perf/Documentation/perf-script.txt +1 -1
index 5ee8796..18dfcfa 100644
@@ -117,7 +117,7 @@ OPTIONS
         Comma separated list of fields to print. Options are:
         comm, tid, pid, time, cpu, event, trace, ip, sym, dso, addr, symoff,
         srcline, period, iregs, brstack, brstacksym, flags, bpf-output, brstackinsn, brstackoff,
-        callindent, insn, insnlen, synth.
+        callindent, insn, insnlen, synth, phys_addr.
         Field list can be prepended with the type, trace, sw or hw,
         to indicate to which event type the field list applies.
         e.g., -F sw:comm,tid,time,ip,sym  and -F trace:time,cpu,trace
tools/perf/builtin-script.c +13 -2
index 378f76c..3d4c3b5 100644
@@ -87,6 +87,7 @@ enum perf_output_field {
 	PERF_OUTPUT_BRSTACKINSN	    = 1U << 23,
 	PERF_OUTPUT_BRSTACKOFF	    = 1U << 24,
 	PERF_OUTPUT_SYNTH           = 1U << 25,
+	PERF_OUTPUT_PHYS_ADDR       = 1U << 26,
 };
 
 struct output_option {
@@ -119,6 +120,7 @@ struct output_option {
 	{.str = "brstackinsn", .field = PERF_OUTPUT_BRSTACKINSN},
 	{.str = "brstackoff", .field = PERF_OUTPUT_BRSTACKOFF},
 	{.str = "synth", .field = PERF_OUTPUT_SYNTH},
+	{.str = "phys_addr", .field = PERF_OUTPUT_PHYS_ADDR},
 };
 
 enum {
@@ -175,7 +177,8 @@ static struct {
 			      PERF_OUTPUT_EVNAME | PERF_OUTPUT_IP |
 			      PERF_OUTPUT_SYM | PERF_OUTPUT_DSO |
 			      PERF_OUTPUT_PERIOD |  PERF_OUTPUT_ADDR |
-			      PERF_OUTPUT_DATA_SRC | PERF_OUTPUT_WEIGHT,
+			      PERF_OUTPUT_DATA_SRC | PERF_OUTPUT_WEIGHT |
+			      PERF_OUTPUT_PHYS_ADDR,
 
 		.invalid_fields = PERF_OUTPUT_TRACE | PERF_OUTPUT_BPF_OUTPUT,
 	},
@@ -382,6 +385,11 @@ static int perf_evsel__check_attr(struct perf_evsel *evsel,
 					PERF_OUTPUT_IREGS))
 		return -EINVAL;
 
+	if (PRINT_FIELD(PHYS_ADDR) &&
+		perf_evsel__check_stype(evsel, PERF_SAMPLE_PHYS_ADDR, "PHYS_ADDR",
+					PERF_OUTPUT_PHYS_ADDR))
+		return -EINVAL;
+
 	return 0;
 }
 
@@ -1446,6 +1454,9 @@ static void process_event(struct perf_script *script,
 	if (perf_evsel__is_bpf_output(evsel) && PRINT_FIELD(BPF_OUTPUT))
 		print_sample_bpf_output(sample);
 	print_insn(sample, attr, thread, machine);
+
+	if (PRINT_FIELD(PHYS_ADDR))
+		printf("%16" PRIx64, sample->phys_addr);
 	printf("\n");
 }
 
@@ -2729,7 +2740,7 @@ int cmd_script(int argc, const char **argv)
 		     "Valid types: hw,sw,trace,raw,synth. "
 		     "Fields: comm,tid,pid,time,cpu,event,trace,ip,sym,dso,"
 		     "addr,symoff,period,iregs,brstack,brstacksym,flags,"
-		     "bpf-output,callindent,insn,insnlen,brstackinsn,synth",
+		     "bpf-output,callindent,insn,insnlen,brstackinsn,synth,phys_addr",
 		     parse_output_fields),
 	OPT_BOOLEAN('a', "all-cpus", &system_wide,
 		    "system-wide collection from all CPUs"),
Signature · 1 line
2.4.3
#10 lore raw

[tip:perf/urgent] perf script: Support physical address

perf script: Support physical address
Commit-ID:  49d58f04eb6cdc18b3747fc4243a7114364f5420
Gitweb:     http://git.kernel.org/tip/49d58f04eb6cdc18b3747fc4243a7114364f5420
Author:     Kan Liang <[email protected]>
AuthorDate: Tue, 29 Aug 2017 13:11:11 -0400
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Fri, 1 Sep 2017 14:46:29 -0300

perf script: Support physical address

Display the physical address at the tail if it is available.

---
 tools/perf/Documentation/perf-script.txt |  2 +-
 tools/perf/builtin-script.c              | 15 +++++++++++++--
 2 files changed, 14 insertions(+), 3 deletions(-)
tools/perf/Documentation/perf-script.txt +1 -1
index 5ee8796..18dfcfa 100644
@@ -117,7 +117,7 @@ OPTIONS
         Comma separated list of fields to print. Options are:
         comm, tid, pid, time, cpu, event, trace, ip, sym, dso, addr, symoff,
         srcline, period, iregs, brstack, brstacksym, flags, bpf-output, brstackinsn, brstackoff,
-        callindent, insn, insnlen, synth.
+        callindent, insn, insnlen, synth, phys_addr.
         Field list can be prepended with the type, trace, sw or hw,
         to indicate to which event type the field list applies.
         e.g., -F sw:comm,tid,time,ip,sym  and -F trace:time,cpu,trace
tools/perf/builtin-script.c +13 -2
index 378f76c..3d4c3b5 100644
@@ -87,6 +87,7 @@ enum perf_output_field {
 	PERF_OUTPUT_BRSTACKINSN	    = 1U << 23,
 	PERF_OUTPUT_BRSTACKOFF	    = 1U << 24,
 	PERF_OUTPUT_SYNTH           = 1U << 25,
+	PERF_OUTPUT_PHYS_ADDR       = 1U << 26,
 };
 
 struct output_option {
@@ -119,6 +120,7 @@ struct output_option {
 	{.str = "brstackinsn", .field = PERF_OUTPUT_BRSTACKINSN},
 	{.str = "brstackoff", .field = PERF_OUTPUT_BRSTACKOFF},
 	{.str = "synth", .field = PERF_OUTPUT_SYNTH},
+	{.str = "phys_addr", .field = PERF_OUTPUT_PHYS_ADDR},
 };
 
 enum {
@@ -175,7 +177,8 @@ static struct {
 			      PERF_OUTPUT_EVNAME | PERF_OUTPUT_IP |
 			      PERF_OUTPUT_SYM | PERF_OUTPUT_DSO |
 			      PERF_OUTPUT_PERIOD |  PERF_OUTPUT_ADDR |
-			      PERF_OUTPUT_DATA_SRC | PERF_OUTPUT_WEIGHT,
+			      PERF_OUTPUT_DATA_SRC | PERF_OUTPUT_WEIGHT |
+			      PERF_OUTPUT_PHYS_ADDR,
 
 		.invalid_fields = PERF_OUTPUT_TRACE | PERF_OUTPUT_BPF_OUTPUT,
 	},
@@ -382,6 +385,11 @@ static int perf_evsel__check_attr(struct perf_evsel *evsel,
 					PERF_OUTPUT_IREGS))
 		return -EINVAL;
 
+	if (PRINT_FIELD(PHYS_ADDR) &&
+		perf_evsel__check_stype(evsel, PERF_SAMPLE_PHYS_ADDR, "PHYS_ADDR",
+					PERF_OUTPUT_PHYS_ADDR))
+		return -EINVAL;
+
 	return 0;
 }
 
@@ -1446,6 +1454,9 @@ static void process_event(struct perf_script *script,
 	if (perf_evsel__is_bpf_output(evsel) && PRINT_FIELD(BPF_OUTPUT))
 		print_sample_bpf_output(sample);
 	print_insn(sample, attr, thread, machine);
+
+	if (PRINT_FIELD(PHYS_ADDR))
+		printf("%16" PRIx64, sample->phys_addr);
 	printf("\n");
 }
 
@@ -2729,7 +2740,7 @@ int cmd_script(int argc, const char **argv)
 		     "Valid types: hw,sw,trace,raw,synth. "
 		     "Fields: comm,tid,pid,time,cpu,event,trace,ip,sym,dso,"
 		     "addr,symoff,period,iregs,brstack,brstacksym,flags,"
-		     "bpf-output,callindent,insn,insnlen,brstackinsn,synth",
+		     "bpf-output,callindent,insn,insnlen,brstackinsn,synth,phys_addr",
 		     parse_output_fields),
 	OPT_BOOLEAN('a', "all-cpus", &system_wide,
 		    "system-wide collection from all CPUs"),
#11 lore raw

PATCH v2 5/5 perf test: add test case for PERF_SAMPLE_PHYS_ADDR

In reply to [email protected]

From: Kan Liang <[email protected]>

Extend sample-parsing test cases to support new sample type PERF_SAMPLE_PHYS_ADDR.

---
 tools/perf/tests/sample-parsing.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
tools/perf/tests/sample-parsing.c +5 -1
index 6d028f4..c385848 100644
@@ -141,6 +141,9 @@ static bool samples_same(const struct perf_sample *s1,
 		}
 	}
 
+	if (type & PERF_SAMPLE_PHYS_ADDR)
+		COMP(phys_addr);
+
 	return true;
 }
 
@@ -206,6 +209,7 @@ static int do_test(u64 sample_type, u64 sample_regs, u64 read_format)
 			.mask	= sample_regs,
 			.regs	= regs,
 		},
+		.phys_addr	= 113,
 	};
 	struct sample_read_value values[] = {{1, 5}, {9, 3}, {2, 7}, {6, 4},};
 	struct perf_sample sample_out;
@@ -305,7 +309,7 @@ int test__sample_parsing(struct test *test __maybe_unused, int subtest __maybe_u
 	 * 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;
 	}
Signature · 1 line
2.4.3
#12 lore raw

[tip:perf/urgent] perf test: Add test case for PERF_SAMPLE_PHYS_ADDR

perf test: Add test case for PERF_SAMPLE_PHYS_ADDR
Commit-ID:  fc33dccba39584e403436b9cda3edc9c34b62bce
Gitweb:     http://git.kernel.org/tip/fc33dccba39584e403436b9cda3edc9c34b62bce
Author:     Kan Liang <[email protected]>
AuthorDate: Tue, 29 Aug 2017 13:11:12 -0400
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Fri, 1 Sep 2017 14:46:34 -0300

perf test: Add test case for PERF_SAMPLE_PHYS_ADDR

Extend sample-parsing test cases to support new sample type PERF_SAMPLE_PHYS_ADDR.

---
 tools/perf/tests/sample-parsing.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
tools/perf/tests/sample-parsing.c +5 -1
index 6d028f4..c385848 100644
@@ -141,6 +141,9 @@ static bool samples_same(const struct perf_sample *s1,
 		}
 	}
 
+	if (type & PERF_SAMPLE_PHYS_ADDR)
+		COMP(phys_addr);
+
 	return true;
 }
 
@@ -206,6 +209,7 @@ static int do_test(u64 sample_type, u64 sample_regs, u64 read_format)
 			.mask	= sample_regs,
 			.regs	= regs,
 		},
+		.phys_addr	= 113,
 	};
 	struct sample_read_value values[] = {{1, 5}, {9, 3}, {2, 7}, {6, 4},};
 	struct perf_sample sample_out;
@@ -305,7 +309,7 @@ int test__sample_parsing(struct test *test __maybe_unused, int subtest __maybe_u
 	 * 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;
 	}
#13 lore raw
In reply to [email protected]
Quoted 10 lines · On Tue, Aug 29, 2017 at 01:11:07PM -0400, [email protected] wrote:

From: Kan Liang <[email protected]>

The patch series is to support PERF_SAMPLE_PHYS_ADDR in user perf tool. The kernel patch has been merged, which commit ID is fc7ce9c74c3a ("perf/core, x86: Add PERF_SAMPLE_PHYS_ADDR").

Changes since V1:
- Don't mandate SAMPLE_ADDR when SAMPLE_PHYS_ADDR
- Update change log

Quoted 6 lines

Kan Liang (5):
perf tools: support new sample type for physical address perf tools: add sort option for physical address perf mem: support physical address
perf script: support physical address
perf test: add test case for PERF_SAMPLE_PHYS_ADDR

apart from the nit in patch 1

Tested/Acked-by: Jiri Olsa <[email protected]>

thanks,
jirka

maintainer Tested-by Jiri Olsa
#14 lore raw

Em Fri, Sep 01, 2017 at 05:45:02PM +0200, Jiri Olsa escreveu:

Quoted 11 lines · On Tue, Aug 29, 2017 at 01:11:07PM -0400, [email protected] wrote:
Quoted 10 lines

From: Kan Liang <[email protected]>

The patch series is to support PERF_SAMPLE_PHYS_ADDR in user perf tool. The kernel patch has been merged, which commit ID is fc7ce9c74c3a ("perf/core, x86: Add PERF_SAMPLE_PHYS_ADDR").

Changes since V1:
- Don't mandate SAMPLE_ADDR when SAMPLE_PHYS_ADDR
- Update change log

Quoted 8 lines
Quoted 6 lines

Kan Liang (5):
perf tools: support new sample type for physical address perf tools: add sort option for physical address perf mem: support physical address
perf script: support physical address
perf test: add test case for PERF_SAMPLE_PHYS_ADDR

apart from the nit in patch 1

Which I folded your patch into

Quoted 1 line

Tested/Acked-by: Jiri Olsa <[email protected]>

I think in this case a Tested-by: is a super ack, right?

So I'll leave it as:

Ok?

- Arnaldo

#15 lore raw
Quoted 25 lines · Arnaldo Carvalho de Melo

Em Fri, Sep 01, 2017 at 05:45:02PM +0200, Jiri Olsa escreveu:

Quoted 11 lines · On Tue, Aug 29, 2017 at 01:11:07PM -0400, [email protected] wrote:
Quoted 10 lines

From: Kan Liang <[email protected]>

The patch series is to support PERF_SAMPLE_PHYS_ADDR in user perf tool. The kernel patch has been merged, which commit ID is fc7ce9c74c3a ("perf/core, x86: Add PERF_SAMPLE_PHYS_ADDR").

Changes since V1:
- Don't mandate SAMPLE_ADDR when SAMPLE_PHYS_ADDR
- Update change log

Quoted 8 lines
Quoted 6 lines

Kan Liang (5):
perf tools: support new sample type for physical address perf tools: add sort option for physical address perf mem: support physical address
perf script: support physical address
perf test: add test case for PERF_SAMPLE_PHYS_ADDR

apart from the nit in patch 1

Which I folded your patch into

Quoted 1 line

Tested/Acked-by: Jiri Olsa <[email protected]>

Quoted 7 lines

I think in this case a Tested-by: is a super ack, right?

So I'll leave it as:

Ok?

ook ;-)

jirka