Skip to content

Commit 98a3b32

Browse files
Stephane Eranianacmel
authored andcommitted
perf tools: Add mem access sampling core support
This patch adds the sorting and histogram support functions to enable profiling of memory accesses. The following sorting orders are added: - symbol_daddr: data address symbol (or raw address) - dso_daddr: data address shared object - locked: access uses locked transaction - tlb : TLB access - mem : memory level of the access (L1, L2, L3, RAM, ...) - snoop: access snoop mode Signed-off-by: Stephane Eranian <eranian@google.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: Ingo Molnar <mingo@elte.hu> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Namhyung Kim <namhyung.kim@lge.com> Cc: Peter Zijlstra <peterz@infradead.org> Link: http://lkml.kernel.org/r/1359040242-8269-12-git-send-email-eranian@google.com [ committer note: changed to cope with fc5871e, the move of methods to machine.[ch], and the rename of dsrc to data_src, to match the change made in the PERF_SAMPLE_DSRC in a previous patch. ] Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 0548429 commit 98a3b32

10 files changed

Lines changed: 525 additions & 10 deletions

File tree

‎tools/perf/util/event.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,21 @@ struct perf_sample {
9191
u64 weight;
9292
u32 cpu;
9393
u32 raw_size;
94+
u64 data_src;
9495
void *raw_data;
9596
struct ip_callchain *callchain;
9697
struct branch_stack *branch_stack;
9798
struct regs_dump user_regs;
9899
struct stack_dump user_stack;
99100
};
100101

102+
#define PERF_MEM_DATA_SRC_NONE \
103+
(PERF_MEM_S(OP, NA) |\
104+
PERF_MEM_S(LVL, NA) |\
105+
PERF_MEM_S(SNOOP, NA) |\
106+
PERF_MEM_S(LOCK, NA) |\
107+
PERF_MEM_S(TLB, NA))
108+
101109
struct build_id_event {
102110
struct perf_event_header header;
103111
pid_t pid;

‎tools/perf/util/evsel.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,6 +1177,12 @@ int perf_evsel__parse_sample(struct perf_evsel *evsel, union perf_event *event,
11771177
array++;
11781178
}
11791179

1180+
data->data_src = PERF_MEM_DATA_SRC_NONE;
1181+
if (type & PERF_SAMPLE_DATA_SRC) {
1182+
data->data_src = *array;
1183+
array++;
1184+
}
1185+
11801186
return 0;
11811187
}
11821188

‎tools/perf/util/hist.c‎

Lines changed: 83 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,16 @@ static void hists__set_unres_dso_col_len(struct hists *hists, int dso)
6767
void hists__calc_col_len(struct hists *hists, struct hist_entry *h)
6868
{
6969
const unsigned int unresolved_col_width = BITS_PER_LONG / 4;
70+
int symlen;
7071
u16 len;
7172

7273
if (h->ms.sym)
7374
hists__new_col_len(hists, HISTC_SYMBOL, h->ms.sym->namelen + 4);
74-
else
75+
else {
76+
symlen = unresolved_col_width + 4 + 2;
77+
hists__new_col_len(hists, HISTC_SYMBOL, symlen);
7578
hists__set_unres_dso_col_len(hists, HISTC_DSO);
79+
}
7680

7781
len = thread__comm_len(h->thread);
7882
if (hists__new_col_len(hists, HISTC_COMM, len))
@@ -87,7 +91,6 @@ void hists__calc_col_len(struct hists *hists, struct hist_entry *h)
8791
hists__new_col_len(hists, HISTC_PARENT, h->parent->namelen);
8892

8993
if (h->branch_info) {
90-
int symlen;
9194
/*
9295
* +4 accounts for '[x] ' priv level info
9396
* +2 account of 0x prefix on raw addresses
@@ -116,6 +119,42 @@ void hists__calc_col_len(struct hists *hists, struct hist_entry *h)
116119
hists__set_unres_dso_col_len(hists, HISTC_DSO_TO);
117120
}
118121
}
122+
123+
if (h->mem_info) {
124+
/*
125+
* +4 accounts for '[x] ' priv level info
126+
* +2 account of 0x prefix on raw addresses
127+
*/
128+
if (h->mem_info->daddr.sym) {
129+
symlen = (int)h->mem_info->daddr.sym->namelen + 4
130+
+ unresolved_col_width + 2;
131+
hists__new_col_len(hists, HISTC_MEM_DADDR_SYMBOL,
132+
symlen);
133+
} else {
134+
symlen = unresolved_col_width + 4 + 2;
135+
hists__new_col_len(hists, HISTC_MEM_DADDR_SYMBOL,
136+
symlen);
137+
}
138+
if (h->mem_info->daddr.map) {
139+
symlen = dso__name_len(h->mem_info->daddr.map->dso);
140+
hists__new_col_len(hists, HISTC_MEM_DADDR_DSO,
141+
symlen);
142+
} else {
143+
symlen = unresolved_col_width + 4 + 2;
144+
hists__set_unres_dso_col_len(hists, HISTC_MEM_DADDR_DSO);
145+
}
146+
} else {
147+
symlen = unresolved_col_width + 4 + 2;
148+
hists__new_col_len(hists, HISTC_MEM_DADDR_SYMBOL, symlen);
149+
hists__set_unres_dso_col_len(hists, HISTC_MEM_DADDR_DSO);
150+
}
151+
152+
hists__new_col_len(hists, HISTC_MEM_LOCKED, 6);
153+
hists__new_col_len(hists, HISTC_MEM_TLB, 22);
154+
hists__new_col_len(hists, HISTC_MEM_SNOOP, 12);
155+
hists__new_col_len(hists, HISTC_MEM_LVL, 21 + 3);
156+
hists__new_col_len(hists, HISTC_LOCAL_WEIGHT, 12);
157+
hists__new_col_len(hists, HISTC_GLOBAL_WEIGHT, 12);
119158
}
120159

121160
void hists__output_recalc_col_len(struct hists *hists, int max_rows)
@@ -158,6 +197,7 @@ static void hist_entry__add_cpumode_period(struct hist_entry *he,
158197
static void he_stat__add_period(struct he_stat *he_stat, u64 period,
159198
u64 weight)
160199
{
200+
161201
he_stat->period += period;
162202
he_stat->weight += weight;
163203
he_stat->nr_events += 1;
@@ -243,7 +283,7 @@ void hists__decay_entries_threaded(struct hists *hists,
243283
static struct hist_entry *hist_entry__new(struct hist_entry *template)
244284
{
245285
size_t callchain_size = symbol_conf.use_callchain ? sizeof(struct callchain_root) : 0;
246-
struct hist_entry *he = malloc(sizeof(*he) + callchain_size);
286+
struct hist_entry *he = zalloc(sizeof(*he) + callchain_size);
247287

248288
if (he != NULL) {
249289
*he = *template;
@@ -258,6 +298,13 @@ static struct hist_entry *hist_entry__new(struct hist_entry *template)
258298
he->branch_info->to.map->referenced = true;
259299
}
260300

301+
if (he->mem_info) {
302+
if (he->mem_info->iaddr.map)
303+
he->mem_info->iaddr.map->referenced = true;
304+
if (he->mem_info->daddr.map)
305+
he->mem_info->daddr.map->referenced = true;
306+
}
307+
261308
if (symbol_conf.use_callchain)
262309
callchain_init(he->callchain);
263310

@@ -346,6 +393,36 @@ static struct hist_entry *add_hist_entry(struct hists *hists,
346393
return he;
347394
}
348395

396+
struct hist_entry *__hists__add_mem_entry(struct hists *self,
397+
struct addr_location *al,
398+
struct symbol *sym_parent,
399+
struct mem_info *mi,
400+
u64 period,
401+
u64 weight)
402+
{
403+
struct hist_entry entry = {
404+
.thread = al->thread,
405+
.ms = {
406+
.map = al->map,
407+
.sym = al->sym,
408+
},
409+
.stat = {
410+
.period = period,
411+
.weight = weight,
412+
.nr_events = 1,
413+
},
414+
.cpu = al->cpu,
415+
.ip = al->addr,
416+
.level = al->level,
417+
.parent = sym_parent,
418+
.filtered = symbol__parent_filter(sym_parent),
419+
.hists = self,
420+
.mem_info = mi,
421+
.branch_info = NULL,
422+
};
423+
return add_hist_entry(self, &entry, al, period, weight);
424+
}
425+
349426
struct hist_entry *__hists__add_branch_entry(struct hists *self,
350427
struct addr_location *al,
351428
struct symbol *sym_parent,
@@ -371,6 +448,7 @@ struct hist_entry *__hists__add_branch_entry(struct hists *self,
371448
.filtered = symbol__parent_filter(sym_parent),
372449
.branch_info = bi,
373450
.hists = self,
451+
.mem_info = NULL,
374452
};
375453

376454
return add_hist_entry(self, &entry, al, period, weight);
@@ -398,6 +476,8 @@ struct hist_entry *__hists__add_entry(struct hists *self,
398476
.parent = sym_parent,
399477
.filtered = symbol__parent_filter(sym_parent),
400478
.hists = self,
479+
.branch_info = NULL,
480+
.mem_info = NULL,
401481
};
402482

403483
return add_hist_entry(self, &entry, al, period, weight);

‎tools/perf/util/hist.h‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ enum hist_column {
5151
HISTC_SRCLINE,
5252
HISTC_LOCAL_WEIGHT,
5353
HISTC_GLOBAL_WEIGHT,
54+
HISTC_MEM_DADDR_SYMBOL,
55+
HISTC_MEM_DADDR_DSO,
56+
HISTC_MEM_LOCKED,
57+
HISTC_MEM_TLB,
58+
HISTC_MEM_LVL,
59+
HISTC_MEM_SNOOP,
5460
HISTC_NR_COLS, /* Last entry */
5561
};
5662

@@ -90,6 +96,13 @@ struct hist_entry *__hists__add_branch_entry(struct hists *self,
9096
u64 period,
9197
u64 weight);
9298

99+
struct hist_entry *__hists__add_mem_entry(struct hists *self,
100+
struct addr_location *al,
101+
struct symbol *sym_parent,
102+
struct mem_info *mi,
103+
u64 period,
104+
u64 weight);
105+
93106
void hists__output_resort(struct hists *self);
94107
void hists__output_resort_threaded(struct hists *hists);
95108
void hists__collapse_resort(struct hists *self);

‎tools/perf/util/machine.c‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,6 +1097,38 @@ static void ip__resolve_ams(struct machine *machine, struct thread *thread,
10971097
ams->map = al.map;
10981098
}
10991099

1100+
static void ip__resolve_data(struct machine *machine, struct thread *thread,
1101+
u8 m, struct addr_map_symbol *ams, u64 addr)
1102+
{
1103+
struct addr_location al;
1104+
1105+
memset(&al, 0, sizeof(al));
1106+
1107+
thread__find_addr_location(thread, machine, m, MAP__VARIABLE, addr, &al,
1108+
NULL);
1109+
ams->addr = addr;
1110+
ams->al_addr = al.addr;
1111+
ams->sym = al.sym;
1112+
ams->map = al.map;
1113+
}
1114+
1115+
struct mem_info *machine__resolve_mem(struct machine *machine,
1116+
struct thread *thr,
1117+
struct perf_sample *sample,
1118+
u8 cpumode)
1119+
{
1120+
struct mem_info *mi = zalloc(sizeof(*mi));
1121+
1122+
if (!mi)
1123+
return NULL;
1124+
1125+
ip__resolve_ams(machine, thr, &mi->iaddr, sample->ip);
1126+
ip__resolve_data(machine, thr, cpumode, &mi->daddr, sample->addr);
1127+
mi->data_src.val = sample->data_src;
1128+
1129+
return mi;
1130+
}
1131+
11001132
struct branch_info *machine__resolve_bstack(struct machine *machine,
11011133
struct thread *thr,
11021134
struct branch_stack *bs)

‎tools/perf/util/machine.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ void machine__delete(struct machine *machine);
7676
struct branch_info *machine__resolve_bstack(struct machine *machine,
7777
struct thread *thread,
7878
struct branch_stack *bs);
79+
struct mem_info *machine__resolve_mem(struct machine *machine,
80+
struct thread *thread,
81+
struct perf_sample *sample, u8 cpumode);
7982
int machine__resolve_callchain(struct machine *machine,
8083
struct perf_evsel *evsel,
8184
struct thread *thread,

‎tools/perf/util/session.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,9 @@ static void dump_sample(struct perf_evsel *evsel, union perf_event *event,
801801

802802
if (sample_type & PERF_SAMPLE_WEIGHT)
803803
printf("... weight: %" PRIu64 "\n", sample->weight);
804+
805+
if (sample_type & PERF_SAMPLE_DATA_SRC)
806+
printf(" . data_src: 0x%"PRIx64"\n", sample->data_src);
804807
}
805808

806809
static struct machine *

0 commit comments

Comments
 (0)