Skip to content

Commit 8780fb2

Browse files
kliang2acmel
authored andcommitted
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. Signed-off-by: Kan Liang <[email protected]> Tested-by: Jiri Olsa <[email protected]> Acked-by: Stephane Eranian <[email protected]> Cc: Andi Kleen <[email protected]> Cc: Madhavan Srinivasan <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 3b0a5da commit 8780fb2

File tree

8 files changed

+59
-2
lines changed

8 files changed

+59
-2
lines changed

tools/perf/Documentation/perf-report.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ OPTIONS
137137
- mem: type of memory access for the data at the time of the sample
138138
- snoop: type of snoop (if any) for the data at the time of the sample
139139
- dcacheline: the cacheline the data address is on at the time of the sample
140+
- phys_daddr: physical address of data being executed on at the time of sample
140141

141142
And the default sort keys are changed to local_weight, mem, sym, dso,
142143
symbol_daddr, dso_daddr, snoop, tlb, locked, see '--mem-mode'.

tools/perf/util/hist.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,10 @@ void hists__calc_col_len(struct hists *hists, struct hist_entry *h)
167167
symlen = unresolved_col_width + 4 + 2;
168168
hists__set_unres_dso_col_len(hists, HISTC_MEM_DADDR_DSO);
169169
}
170+
171+
hists__new_col_len(hists, HISTC_MEM_PHYS_DADDR,
172+
unresolved_col_width + 4 + 2);
173+
170174
} else {
171175
symlen = unresolved_col_width + 4 + 2;
172176
hists__new_col_len(hists, HISTC_MEM_DADDR_SYMBOL, symlen);

tools/perf/util/hist.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ enum hist_column {
4747
HISTC_GLOBAL_WEIGHT,
4848
HISTC_MEM_DADDR_SYMBOL,
4949
HISTC_MEM_DADDR_DSO,
50+
HISTC_MEM_PHYS_DADDR,
5051
HISTC_MEM_LOCKED,
5152
HISTC_MEM_TLB,
5253
HISTC_MEM_LVL,

tools/perf/util/machine.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1635,10 +1635,12 @@ static void ip__resolve_ams(struct thread *thread,
16351635
ams->al_addr = al.addr;
16361636
ams->sym = al.sym;
16371637
ams->map = al.map;
1638+
ams->phys_addr = 0;
16381639
}
16391640

16401641
static void ip__resolve_data(struct thread *thread,
1641-
u8 m, struct addr_map_symbol *ams, u64 addr)
1642+
u8 m, struct addr_map_symbol *ams,
1643+
u64 addr, u64 phys_addr)
16421644
{
16431645
struct addr_location al;
16441646

@@ -1658,6 +1660,7 @@ static void ip__resolve_data(struct thread *thread,
16581660
ams->al_addr = al.addr;
16591661
ams->sym = al.sym;
16601662
ams->map = al.map;
1663+
ams->phys_addr = phys_addr;
16611664
}
16621665

16631666
struct mem_info *sample__resolve_mem(struct perf_sample *sample,
@@ -1669,7 +1672,8 @@ struct mem_info *sample__resolve_mem(struct perf_sample *sample,
16691672
return NULL;
16701673

16711674
ip__resolve_ams(al->thread, &mi->iaddr, sample->ip);
1672-
ip__resolve_data(al->thread, al->cpumode, &mi->daddr, sample->addr);
1675+
ip__resolve_data(al->thread, al->cpumode, &mi->daddr,
1676+
sample->addr, sample->phys_addr);
16731677
mi->data_src.val = sample->data_src;
16741678

16751679
return mi;

tools/perf/util/session.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,6 +1120,9 @@ static void dump_sample(struct perf_evsel *evsel, union perf_event *event,
11201120
if (sample_type & PERF_SAMPLE_DATA_SRC)
11211121
printf(" . data_src: 0x%"PRIx64"\n", sample->data_src);
11221122

1123+
if (sample_type & PERF_SAMPLE_PHYS_ADDR)
1124+
printf(" .. phys_addr: 0x%"PRIx64"\n", sample->phys_addr);
1125+
11231126
if (sample_type & PERF_SAMPLE_TRANSACTION)
11241127
printf("... transaction: %" PRIx64 "\n", sample->transaction);
11251128

tools/perf/util/sort.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,6 +1315,47 @@ struct sort_entry sort_mem_dcacheline = {
13151315
.se_width_idx = HISTC_MEM_DCACHELINE,
13161316
};
13171317

1318+
static int64_t
1319+
sort__phys_daddr_cmp(struct hist_entry *left, struct hist_entry *right)
1320+
{
1321+
uint64_t l = 0, r = 0;
1322+
1323+
if (left->mem_info)
1324+
l = left->mem_info->daddr.phys_addr;
1325+
if (right->mem_info)
1326+
r = right->mem_info->daddr.phys_addr;
1327+
1328+
return (int64_t)(r - l);
1329+
}
1330+
1331+
static int hist_entry__phys_daddr_snprintf(struct hist_entry *he, char *bf,
1332+
size_t size, unsigned int width)
1333+
{
1334+
uint64_t addr = 0;
1335+
size_t ret = 0;
1336+
size_t len = BITS_PER_LONG / 4;
1337+
1338+
addr = he->mem_info->daddr.phys_addr;
1339+
1340+
ret += repsep_snprintf(bf + ret, size - ret, "[%c] ", he->level);
1341+
1342+
ret += repsep_snprintf(bf + ret, size - ret, "%-#.*llx", len, addr);
1343+
1344+
ret += repsep_snprintf(bf + ret, size - ret, "%-*s", width - ret, "");
1345+
1346+
if (ret > width)
1347+
bf[width] = '\0';
1348+
1349+
return width;
1350+
}
1351+
1352+
struct sort_entry sort_mem_phys_daddr = {
1353+
.se_header = "Data Physical Address",
1354+
.se_cmp = sort__phys_daddr_cmp,
1355+
.se_snprintf = hist_entry__phys_daddr_snprintf,
1356+
.se_width_idx = HISTC_MEM_PHYS_DADDR,
1357+
};
1358+
13181359
static int64_t
13191360
sort__abort_cmp(struct hist_entry *left, struct hist_entry *right)
13201361
{
@@ -1547,6 +1588,7 @@ static struct sort_dimension memory_sort_dimensions[] = {
15471588
DIM(SORT_MEM_LVL, "mem", sort_mem_lvl),
15481589
DIM(SORT_MEM_SNOOP, "snoop", sort_mem_snoop),
15491590
DIM(SORT_MEM_DCACHELINE, "dcacheline", sort_mem_dcacheline),
1591+
DIM(SORT_MEM_PHYS_DADDR, "phys_daddr", sort_mem_phys_daddr),
15501592
};
15511593

15521594
#undef DIM

tools/perf/util/sort.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ enum sort_type {
245245
SORT_MEM_SNOOP,
246246
SORT_MEM_DCACHELINE,
247247
SORT_MEM_IADDR_SYMBOL,
248+
SORT_MEM_PHYS_DADDR,
248249
};
249250

250251
/*

tools/perf/util/symbol.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ struct addr_map_symbol {
186186
struct symbol *sym;
187187
u64 addr;
188188
u64 al_addr;
189+
u64 phys_addr;
189190
};
190191

191192
struct branch_info {

0 commit comments

Comments
 (0)