Skip to content

Commit

Permalink
perf tools: A thread's machine can be found via thread->mg->machine
Browse files Browse the repository at this point in the history
So stop passing both machine and thread to several thread methods,
reducing function signature length.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: David Ahern <dsahern@gmail.com>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jean Pihet <jean.pihet@linaro.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-ckcy19dcp1jfkmdihdjcqdn1@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
  • Loading branch information
Arnaldo Carvalho de Melo committed Oct 29, 2014
1 parent 11246c7 commit bb871a9
Show file tree
Hide file tree
Showing 16 changed files with 48 additions and 70 deletions.
5 changes: 2 additions & 3 deletions tools/perf/arch/powerpc/util/skip-callchain-idx.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,7 @@ static int check_return_addr(struct dso *dso, Dwarf_Addr pc)
* index: of callchain entry that needs to be ignored (if any)
* -1 if no entry needs to be ignored or in case of errors
*/
int arch_skip_callchain_idx(struct machine *machine, struct thread *thread,
struct ip_callchain *chain)
int arch_skip_callchain_idx(struct thread *thread, struct ip_callchain *chain)
{
struct addr_location al;
struct dso *dso = NULL;
Expand All @@ -246,7 +245,7 @@ int arch_skip_callchain_idx(struct machine *machine, struct thread *thread,

ip = chain->ips[2];

thread__find_addr_location(thread, machine, PERF_RECORD_MISC_USER,
thread__find_addr_location(thread, PERF_RECORD_MISC_USER,
MAP__FUNCTION, ip, &al);

if (al.map)
Expand Down
3 changes: 1 addition & 2 deletions tools/perf/builtin-inject.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,7 @@ static int perf_event__inject_buildid(struct perf_tool *tool,
goto repipe;
}

thread__find_addr_map(thread, machine, cpumode, MAP__FUNCTION,
sample->ip, &al);
thread__find_addr_map(thread, cpumode, MAP__FUNCTION, sample->ip, &al);

if (al.map != NULL) {
if (!al.map->dso->hit) {
Expand Down
7 changes: 3 additions & 4 deletions tools/perf/builtin-script.c
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,6 @@ static void print_sample_start(struct perf_sample *sample,

static void print_sample_addr(union perf_event *event,
struct perf_sample *sample,
struct machine *machine,
struct thread *thread,
struct perf_event_attr *attr)
{
Expand All @@ -390,7 +389,7 @@ static void print_sample_addr(union perf_event *event,
if (!sample_addr_correlates_sym(attr))
return;

perf_event__preprocess_sample_addr(event, sample, machine, thread, &al);
perf_event__preprocess_sample_addr(event, sample, thread, &al);

if (PRINT_FIELD(SYM)) {
printf(" ");
Expand Down Expand Up @@ -438,7 +437,7 @@ static void print_sample_bts(union perf_event *event,
((evsel->attr.sample_type & PERF_SAMPLE_ADDR) &&
!output[attr->type].user_set)) {
printf(" => ");
print_sample_addr(event, sample, al->machine, thread, attr);
print_sample_addr(event, sample, thread, attr);
}

if (print_srcline_last)
Expand Down Expand Up @@ -475,7 +474,7 @@ static void process_event(union perf_event *event, struct perf_sample *sample,
event_format__print(evsel->tp_format, sample->cpu,
sample->raw_data, sample->raw_size);
if (PRINT_FIELD(ADDR))
print_sample_addr(event, sample, al->machine, thread, attr);
print_sample_addr(event, sample, thread, attr);

if (PRINT_FIELD(IP)) {
if (!symbol_conf.use_callchain)
Expand Down
2 changes: 1 addition & 1 deletion tools/perf/builtin-timechart.c
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ static const char *cat_backtrace(union perf_event *event,
}

tal.filtered = 0;
thread__find_addr_location(al.thread, machine, cpumode,
thread__find_addr_location(al.thread, cpumode,
MAP__FUNCTION, ip, &tal);

if (tal.sym)
Expand Down
6 changes: 3 additions & 3 deletions tools/perf/builtin-trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -1846,7 +1846,7 @@ static int trace__pgfault(struct trace *trace,
if (trace->summary_only)
return 0;

thread__find_addr_location(thread, trace->host, cpumode, MAP__FUNCTION,
thread__find_addr_location(thread, cpumode, MAP__FUNCTION,
sample->ip, &al);

trace__fprintf_entry_head(trace, thread, 0, sample->time, trace->output);
Expand All @@ -1859,11 +1859,11 @@ static int trace__pgfault(struct trace *trace,

fprintf(trace->output, "] => ");

thread__find_addr_location(thread, trace->host, cpumode, MAP__VARIABLE,
thread__find_addr_location(thread, cpumode, MAP__VARIABLE,
sample->addr, &al);

if (!al.map) {
thread__find_addr_location(thread, trace->host, cpumode,
thread__find_addr_location(thread, cpumode,
MAP__FUNCTION, sample->addr, &al);

if (al.map)
Expand Down
3 changes: 1 addition & 2 deletions tools/perf/tests/code-reading.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,7 @@ static int read_object_code(u64 addr, size_t len, u8 cpumode,

pr_debug("Reading object code for memory address: %#"PRIx64"\n", addr);

thread__find_addr_map(thread, machine, cpumode, MAP__FUNCTION, addr,
&al);
thread__find_addr_map(thread, cpumode, MAP__FUNCTION, addr, &al);
if (!al.map || !al.map->dso) {
pr_debug("thread__find_addr_map failed\n");
return -1;
Expand Down
2 changes: 1 addition & 1 deletion tools/perf/tests/mmap-thread-lookup.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ static int mmap_events(synth_cb synth)

pr_debug("looking for map %p\n", td->map);

thread__find_addr_map(thread, machine,
thread__find_addr_map(thread,
PERF_RECORD_MISC_USER, MAP__FUNCTION,
(unsigned long) (td->map + 1), &al);

Expand Down
3 changes: 1 addition & 2 deletions tools/perf/util/build-id.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ int build_id__mark_dso_hit(struct perf_tool *tool __maybe_unused,
return -1;
}

thread__find_addr_map(thread, machine, cpumode, MAP__FUNCTION,
sample->ip, &al);
thread__find_addr_map(thread, cpumode, MAP__FUNCTION, sample->ip, &al);

if (al.map != NULL)
al.map->dso->hit = 1;
Expand Down
6 changes: 2 additions & 4 deletions tools/perf/util/callchain.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,9 @@ static inline void callchain_cursor_snapshot(struct callchain_cursor *dest,
}

#ifdef HAVE_SKIP_CALLCHAIN_IDX
extern int arch_skip_callchain_idx(struct machine *machine,
struct thread *thread, struct ip_callchain *chain);
extern int arch_skip_callchain_idx(struct thread *thread, struct ip_callchain *chain);
#else
static inline int arch_skip_callchain_idx(struct machine *machine __maybe_unused,
struct thread *thread __maybe_unused,
static inline int arch_skip_callchain_idx(struct thread *thread __maybe_unused,
struct ip_callchain *chain __maybe_unused)
{
return -1;
Expand Down
19 changes: 8 additions & 11 deletions tools/perf/util/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -730,12 +730,12 @@ int perf_event__process(struct perf_tool *tool __maybe_unused,
return machine__process_event(machine, event, sample);
}

void thread__find_addr_map(struct thread *thread,
struct machine *machine, u8 cpumode,
void thread__find_addr_map(struct thread *thread, u8 cpumode,
enum map_type type, u64 addr,
struct addr_location *al)
{
struct map_groups *mg = thread->mg;
struct machine *machine = mg->machine;
bool load_map = false;

al->machine = machine;
Expand Down Expand Up @@ -806,14 +806,14 @@ void thread__find_addr_map(struct thread *thread,
}
}

void thread__find_addr_location(struct thread *thread, struct machine *machine,
void thread__find_addr_location(struct thread *thread,
u8 cpumode, enum map_type type, u64 addr,
struct addr_location *al)
{
thread__find_addr_map(thread, machine, cpumode, type, addr, al);
thread__find_addr_map(thread, cpumode, type, addr, al);
if (al->map != NULL)
al->sym = map__find_symbol(al->map, al->addr,
machine->symbol_filter);
thread->mg->machine->symbol_filter);
else
al->sym = NULL;
}
Expand Down Expand Up @@ -842,8 +842,7 @@ int perf_event__preprocess_sample(const union perf_event *event,
machine->vmlinux_maps[MAP__FUNCTION] == NULL)
machine__create_kernel_maps(machine);

thread__find_addr_map(thread, machine, cpumode, MAP__FUNCTION,
sample->ip, al);
thread__find_addr_map(thread, cpumode, MAP__FUNCTION, sample->ip, al);
dump_printf(" ...... dso: %s\n",
al->map ? al->map->dso->long_name :
al->level == 'H' ? "[hypervisor]" : "<not found>");
Expand Down Expand Up @@ -902,16 +901,14 @@ bool sample_addr_correlates_sym(struct perf_event_attr *attr)

void perf_event__preprocess_sample_addr(union perf_event *event,
struct perf_sample *sample,
struct machine *machine,
struct thread *thread,
struct addr_location *al)
{
u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;

thread__find_addr_map(thread, machine, cpumode, MAP__FUNCTION,
sample->addr, al);
thread__find_addr_map(thread, cpumode, MAP__FUNCTION, sample->addr, al);
if (!al->map)
thread__find_addr_map(thread, machine, cpumode, MAP__VARIABLE,
thread__find_addr_map(thread, cpumode, MAP__VARIABLE,
sample->addr, al);

al->cpu = sample->cpu;
Expand Down
1 change: 0 additions & 1 deletion tools/perf/util/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,6 @@ bool is_bts_event(struct perf_event_attr *attr);
bool sample_addr_correlates_sym(struct perf_event_attr *attr);
void perf_event__preprocess_sample_addr(union perf_event *event,
struct perf_sample *sample,
struct machine *machine,
struct thread *thread,
struct addr_location *al);

Expand Down
35 changes: 14 additions & 21 deletions tools/perf/util/machine.c
Original file line number Diff line number Diff line change
Expand Up @@ -1289,7 +1289,7 @@ static bool symbol__match_regex(struct symbol *sym, regex_t *regex)
return 0;
}

static void ip__resolve_ams(struct machine *machine, struct thread *thread,
static void ip__resolve_ams(struct thread *thread,
struct addr_map_symbol *ams,
u64 ip)
{
Expand All @@ -1303,31 +1303,29 @@ static void ip__resolve_ams(struct machine *machine, struct thread *thread,
* Thus, we have to try consecutively until we find a match
* or else, the symbol is unknown
*/
thread__find_cpumode_addr_location(thread, machine, MAP__FUNCTION, ip, &al);
thread__find_cpumode_addr_location(thread, MAP__FUNCTION, ip, &al);

ams->addr = ip;
ams->al_addr = al.addr;
ams->sym = al.sym;
ams->map = al.map;
}

static void ip__resolve_data(struct machine *machine, struct thread *thread,
static void ip__resolve_data(struct thread *thread,
u8 m, struct addr_map_symbol *ams, u64 addr)
{
struct addr_location al;

memset(&al, 0, sizeof(al));

thread__find_addr_location(thread, machine, m, MAP__VARIABLE, addr,
&al);
thread__find_addr_location(thread, m, MAP__VARIABLE, addr, &al);
if (al.map == NULL) {
/*
* some shared data regions have execute bit set which puts
* their mapping in the MAP__FUNCTION type array.
* Check there as a fallback option before dropping the sample.
*/
thread__find_addr_location(thread, machine, m, MAP__FUNCTION, addr,
&al);
thread__find_addr_location(thread, m, MAP__FUNCTION, addr, &al);
}

ams->addr = addr;
Expand All @@ -1344,9 +1342,8 @@ struct mem_info *sample__resolve_mem(struct perf_sample *sample,
if (!mi)
return NULL;

ip__resolve_ams(al->machine, al->thread, &mi->iaddr, sample->ip);
ip__resolve_data(al->machine, al->thread, al->cpumode,
&mi->daddr, sample->addr);
ip__resolve_ams(al->thread, &mi->iaddr, sample->ip);
ip__resolve_data(al->thread, al->cpumode, &mi->daddr, sample->addr);
mi->data_src.val = sample->data_src;

return mi;
Expand All @@ -1363,15 +1360,14 @@ struct branch_info *sample__resolve_bstack(struct perf_sample *sample,
return NULL;

for (i = 0; i < bs->nr; i++) {
ip__resolve_ams(al->machine, al->thread, &bi[i].to, bs->entries[i].to);
ip__resolve_ams(al->machine, al->thread, &bi[i].from, bs->entries[i].from);
ip__resolve_ams(al->thread, &bi[i].to, bs->entries[i].to);
ip__resolve_ams(al->thread, &bi[i].from, bs->entries[i].from);
bi[i].flags = bs->entries[i].flags;
}
return bi;
}

static int machine__resolve_callchain_sample(struct machine *machine,
struct thread *thread,
static int thread__resolve_callchain_sample(struct thread *thread,
struct ip_callchain *chain,
struct symbol **parent,
struct addr_location *root_al,
Expand All @@ -1395,7 +1391,7 @@ static int machine__resolve_callchain_sample(struct machine *machine,
* Based on DWARF debug information, some architectures skip
* a callchain entry saved by the kernel.
*/
skip_idx = arch_skip_callchain_idx(machine, thread, chain);
skip_idx = arch_skip_callchain_idx(thread, chain);

for (i = 0; i < chain_nr; i++) {
u64 ip;
Expand Down Expand Up @@ -1437,7 +1433,7 @@ static int machine__resolve_callchain_sample(struct machine *machine,
}

al.filtered = 0;
thread__find_addr_location(thread, machine, cpumode,
thread__find_addr_location(thread, cpumode,
MAP__FUNCTION, ip, &al);
if (al.sym != NULL) {
if (sort__has_parent && !*parent &&
Expand Down Expand Up @@ -1476,11 +1472,8 @@ int machine__resolve_callchain(struct machine *machine,
struct addr_location *root_al,
int max_stack)
{
int ret;

ret = machine__resolve_callchain_sample(machine, thread,
sample->callchain, parent,
root_al, max_stack);
int ret = thread__resolve_callchain_sample(thread, sample->callchain,
parent, root_al, max_stack);
if (ret)
return ret;

Expand Down
4 changes: 1 addition & 3 deletions tools/perf/util/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ int thread__fork(struct thread *thread, struct thread *parent, u64 timestamp)
}

void thread__find_cpumode_addr_location(struct thread *thread,
struct machine *machine,
enum map_type type, u64 addr,
struct addr_location *al)
{
Expand All @@ -211,8 +210,7 @@ void thread__find_cpumode_addr_location(struct thread *thread,
};

for (i = 0; i < ARRAY_SIZE(cpumodes); i++) {
thread__find_addr_location(thread, machine, cpumodes[i], type,
addr, al);
thread__find_addr_location(thread, cpumodes[i], type, addr, al);
if (al->map)
break;
}
Expand Down
5 changes: 2 additions & 3 deletions tools/perf/util/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,15 @@ void thread__insert_map(struct thread *thread, struct map *map);
int thread__fork(struct thread *thread, struct thread *parent, u64 timestamp);
size_t thread__fprintf(struct thread *thread, FILE *fp);

void thread__find_addr_map(struct thread *thread, struct machine *machine,
void thread__find_addr_map(struct thread *thread,
u8 cpumode, enum map_type type, u64 addr,
struct addr_location *al);

void thread__find_addr_location(struct thread *thread, struct machine *machine,
void thread__find_addr_location(struct thread *thread,
u8 cpumode, enum map_type type, u64 addr,
struct addr_location *al);

void thread__find_cpumode_addr_location(struct thread *thread,
struct machine *machine,
enum map_type type, u64 addr,
struct addr_location *al);

Expand Down
4 changes: 2 additions & 2 deletions tools/perf/util/unwind-libdw.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ static int __report_module(struct addr_location *al, u64 ip,
Dwfl_Module *mod;
struct dso *dso = NULL;

thread__find_addr_location(ui->thread, ui->machine,
thread__find_addr_location(ui->thread,
PERF_RECORD_MISC_USER,
MAP__FUNCTION, ip, al);

Expand Down Expand Up @@ -89,7 +89,7 @@ static int access_dso_mem(struct unwind_info *ui, Dwarf_Addr addr,
struct addr_location al;
ssize_t size;

thread__find_addr_map(ui->thread, ui->machine, PERF_RECORD_MISC_USER,
thread__find_addr_map(ui->thread, PERF_RECORD_MISC_USER,
MAP__FUNCTION, addr, &al);
if (!al.map) {
pr_debug("unwind: no map for %lx\n", (unsigned long)addr);
Expand Down
Loading

0 comments on commit bb871a9

Please sign in to comment.