perf tools: Add cpumode to struct perf_sample
tip-bot for Arnaldo Carvalho de Melo
merge botCommit-ID: 473398a21d28c089555117a8db4ea04e371dd03c Gitweb: http://git.kernel.org/tip/473398a21d28c089555117a8db4ea04e371dd03c Author: Arnaldo Carvalho de Melo <[email protected]> AuthorDate: Tue, 22 Mar 2016 18:23:43 -0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 23 Mar 2016 12:03:07 -0300
perf tools: Add cpumode to struct perf_sample
To avoid parsing event->header.misc in many locations.
This will also allow setting perf.sample.{ip,cpumode} in a single place, from tracepoint fields, as needed by 'perf kvm' with PPC guests, where the guest hardware counters is not available at the host.
Cc Adrian Hunter <[email protected]>
Cc Hemant Kumar <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Naveen N. Rao <[email protected]>
Cc Ravi Bangoria <[email protected]>
Cc Wang Nan <[email protected]>
Signed-off-by Arnaldo Carvalho de Melo <[email protected]>
--- tools/perf/builtin-inject.c | 5 +---- tools/perf/builtin-script.c | 7 +++---- tools/perf/builtin-top.c | 5 +---- tools/perf/builtin-trace.c | 9 ++++----- tools/perf/tests/code-reading.c | 5 +---- tools/perf/tests/hists_common.c | 6 ++++-- tools/perf/tests/hists_cumulate.c | 1 + tools/perf/tests/hists_filter.c | 1 + tools/perf/tests/hists_link.c | 1 + tools/perf/tests/hists_output.c | 1 + tools/perf/util/build-id.c | 3 +-- tools/perf/util/event.c | 15 ++++++--------- tools/perf/util/event.h | 1 + tools/perf/util/evsel.c | 1 + tools/perf/util/machine.c | 14 ++++++-------- tools/perf/util/session.c | 5 ++--- 16 files changed, 35 insertions(+), 45 deletions(-)
tools/perf/builtin-inject.c +1 -4
@@ -416,9 +416,6 @@ static int perf_event__inject_buildid(struct perf_tool *tool, {struct addr_location al;struct thread *thread; -u8 cpumode; - - cpumode = event->header.misc &PERF_RECORD_MISC_CPUMODE_MASK ; thread =machine__findnew_thread (machine, sample->pid, sample->tid);if (thread ==NULL ) {
@@ -427,7 +424,7 @@ static int perf_event__inject_buildid(struct perf_tool *tool, goto repipe; } -thread__find_addr_map (thread, cpumode,MAP__FUNCTION , sample->ip, &al); +thread__find_addr_map (thread, sample->cpumode,MAP__FUNCTION , sample->ip, &al);if (al.map !=NULL ) {if (!al.map->dso->hit) {
tools/perf/builtin-script.c +3 -4
@@ -498,14 +498,13 @@ static void print_sample_brstack(union perf_event *event __maybe_unused, } } -static void print_sample_brstacksym (union perf_event *event, +static void print_sample_brstacksym (union perf_event *event__maybe_unused ,struct perf_sample *sample,struct thread *thread__maybe_unused ,struct perf_event_attr *attr__maybe_unused ) {struct branch_stack *br = sample->branch_stack;struct addr_location alf, alt; -u8 cpumode = event->header.misc &PERF_RECORD_MISC_CPUMODE_MASK ;u64 i, from, to;if (!(br && br->nr))
@@ -518,11 +517,11 @@ static void print_sample_brstacksym(union perf_event *event, from = br->entries[i].from; to = br->entries[i].to; -thread__find_addr_map (thread, cpumode,MAP__FUNCTION , from, &alf); +thread__find_addr_map (thread, sample->cpumode,MAP__FUNCTION , from, &alf);if (alf.map) alf.sym =map__find_symbol (alf.map, alf.addr,NULL ); -thread__find_addr_map (thread, cpumode,MAP__FUNCTION , to, &alt); +thread__find_addr_map (thread, sample->cpumode,MAP__FUNCTION , to, &alt);if (alt.map) alt.sym =map__find_symbol (alt.map, alt.addr,NULL );
tools/perf/builtin-top.c +1 -4
@@ -809,7 +809,6 @@ static void perf_top__mmap_read_idx(struct perf_top *top, int idx)struct perf_session *session = top->session;union perf_event *event;struct machine *machine; -u8 origin;int ret;while ((event =perf_evlist__mmap_read (top->evlist, idx)) !=NULL ) {
@@ -822,12 +821,10 @@ static void perf_top__mmap_read_idx(struct perf_top *top, int idx) evsel =perf_evlist__id2evsel (session->evlist, sample.id);assert (evsel !=NULL ); - origin = event->header.misc &PERF_RECORD_MISC_CPUMODE_MASK ; -if (event->header.type ==PERF_RECORD_SAMPLE ) ++top->samples; -switch (origin) { +switch (sample.cpumode) {case PERF_RECORD_MISC_USER : ++top->us_samples;if (top->hide_user_symbols)
tools/perf/builtin-trace.c +4 -5
@@ -2256,11 +2256,10 @@ static void print_location(FILE *f, struct perf_sample *sample,static int trace__pgfault (struct trace *trace,struct perf_evsel *evsel, -union perf_event *event, +union perf_event *event__maybe_unused ,struct perf_sample *sample) {struct thread *thread; -u8 cpumode = event->header.misc &PERF_RECORD_MISC_CPUMODE_MASK ;struct addr_location al;char map_type ='d' ;struct thread_trace *ttrace;
@@ -2279,7 +2278,7 @@ static int trace__pgfault(struct trace *trace,if (trace->summary_only) goto out; -thread__find_addr_location (thread, cpumode,MAP__FUNCTION , +thread__find_addr_location (thread, sample->cpumode,MAP__FUNCTION , sample->ip, &al);trace__fprintf_entry_head (trace, thread,0 , sample->time, trace->output);
@@ -2292,11 +2291,11 @@ static int trace__pgfault(struct trace *trace,fprintf (trace->output,"] => " ); -thread__find_addr_location (thread, cpumode,MAP__VARIABLE , +thread__find_addr_location (thread, sample->cpumode,MAP__VARIABLE , sample->addr, &al);if (!al.map) { -thread__find_addr_location (thread, cpumode, +thread__find_addr_location (thread, sample->cpumode,MAP__FUNCTION , sample->addr, &al);if (al.map)
tools/perf/tests/code-reading.c +1 -4
@@ -293,7 +293,6 @@ static int process_sample_event(struct machine *machine, {struct perf_sample sample;struct thread *thread; -u8 cpumode;int ret;if (perf_evlist__parse_sample (evlist, event, &sample)) {
@@ -307,9 +306,7 @@ static int process_sample_event(struct machine *machine,return -1 ; } - cpumode = event->header.misc &PERF_RECORD_MISC_CPUMODE_MASK ; - - ret =read_object_code (sample.ip,READLEN , cpumode, thread, state); + ret =read_object_code (sample.ip,READLEN , sample.cpumode, thread, state);thread__put (thread);return ret; }
tools/perf/tests/hists_common.c +4 -2
@@ -100,9 +100,11 @@ struct machine *setup_fake_machine(struct machines *machines) }for (i =0 ; i <ARRAY_SIZE (fake_mmap_info); i++) { +struct perf_sample sample = { + .cpumode =PERF_RECORD_MISC_USER , + };union perf_event fake_mmap_event = { .mmap = { - .header = { .misc =PERF_RECORD_MISC_USER , }, .pid = fake_mmap_info[i].pid, .tid = fake_mmap_info[i].pid, .start = fake_mmap_info[i].start,
@@ -114,7 +116,7 @@ struct machine *setup_fake_machine(struct machines *machines)strcpy (fake_mmap_event.mmap.filename, fake_mmap_info[i].filename); -machine__process_mmap_event (machine, &fake_mmap_event,NULL ); +machine__process_mmap_event (machine, &fake_mmap_event, &sample); }for (i =0 ; i <ARRAY_SIZE (fake_symbols); i++) {
tools/perf/tests/hists_cumulate.c +1 -0
@@ -97,6 +97,7 @@ static int add_hist_entries(struct hists *hists, struct machine *machine)else iter.ops = &hist_iter_normal; + sample.cpumode =PERF_RECORD_MISC_USER ; sample.pid = fake_samples[i].pid; sample.tid = fake_samples[i].pid; sample.ip = fake_samples[i].ip;
tools/perf/tests/hists_filter.c +1 -0
@@ -76,6 +76,7 @@ static int add_hist_entries(struct perf_evlist *evlist, hists->dso_filter =NULL ; hists->symbol_filter_str =NULL ; + sample.cpumode =PERF_RECORD_MISC_USER ; sample.pid = fake_samples[i].pid; sample.tid = fake_samples[i].pid; sample.ip = fake_samples[i].ip;
tools/perf/tests/hists_link.c +1 -0
@@ -82,6 +82,7 @@ static int add_hist_entries(struct perf_evlist *evlist, struct machine *machine) }, }; + sample.cpumode =PERF_RECORD_MISC_USER ; sample.pid = fake_common_samples[k].pid; sample.tid = fake_common_samples[k].pid; sample.ip = fake_common_samples[k].ip;
tools/perf/tests/hists_output.c +1 -0
@@ -63,6 +63,7 @@ static int add_hist_entries(struct hists *hists, struct machine *machine) .hide_unresolved = false, }; + sample.cpumode =PERF_RECORD_MISC_USER ; sample.cpu = fake_samples[i].cpu; sample.pid = fake_samples[i].pid; sample.tid = fake_samples[i].pid;
tools/perf/util/build-id.c +1 -2
@@ -28,7 +28,6 @@ int build_id__mark_dso_hit(struct perf_tool *tool __maybe_unused, struct machine *machine) {struct addr_location al; -u8 cpumode = event->header.misc &PERF_RECORD_MISC_CPUMODE_MASK ;struct thread *thread =machine__findnew_thread (machine, sample->pid, sample->tid);
@@ -38,7 +37,7 @@ int build_id__mark_dso_hit(struct perf_tool *tool __maybe_unused,return -1 ; } -thread__find_addr_map (thread, cpumode,MAP__FUNCTION , sample->ip, &al); +thread__find_addr_map (thread, sample->cpumode,MAP__FUNCTION , sample->ip, &al);if (al.map !=NULL ) al.map->dso->hit =1 ;
tools/perf/util/event.c +6 -9
@@ -1295,12 +1295,11 @@ void thread__find_addr_location(struct thread *thread,* Callers need to drop the reference to al->thread, obtained in * machine__findnew_thread() */ -int perf_event__preprocess_sample (const union perf_event *event, +int perf_event__preprocess_sample (const union perf_event *event__maybe_unused ,struct machine *machine,struct addr_location *al,struct perf_sample *sample) { -u8 cpumode = event->header.misc &PERF_RECORD_MISC_CPUMODE_MASK ;struct thread *thread =machine__findnew_thread (machine, sample->pid, sample->tid);
@@ -1315,11 +1314,11 @@ int perf_event__preprocess_sample(const union perf_event *event,* events, but for older perf.data files there was no such thing, so do * it now. */ -if (cpumode ==PERF_RECORD_MISC_KERNEL && +if (sample->cpumode ==PERF_RECORD_MISC_KERNEL &&machine__kernel_map (machine) ==NULL )machine__create_kernel_maps (machine); -thread__find_addr_map (thread, cpumode,MAP__FUNCTION , sample->ip, al); +thread__find_addr_map (thread, sample->cpumode,MAP__FUNCTION , sample->ip, al);dump_printf (" ...... dso: %s\n" , al->map ? al->map->dso->long_name : al->level =='H' ?"[hypervisor]" :"<not found>" );
@@ -1395,16 +1394,14 @@ bool sample_addr_correlates_sym(struct perf_event_attr *attr)return false; } -void perf_event__preprocess_sample_addr (union perf_event *event, +void perf_event__preprocess_sample_addr (union perf_event *event__maybe_unused ,struct perf_sample *sample,struct thread *thread,struct addr_location *al) { -u8 cpumode = event->header.misc &PERF_RECORD_MISC_CPUMODE_MASK ; - -thread__find_addr_map (thread, cpumode,MAP__FUNCTION , sample->addr, al); +thread__find_addr_map (thread, sample->cpumode,MAP__FUNCTION , sample->addr, al);if (!al->map) -thread__find_addr_map (thread, cpumode,MAP__VARIABLE , +thread__find_addr_map (thread, sample->cpumode,MAP__VARIABLE , sample->addr, al); al->cpu = sample->cpu;
tools/perf/util/event.h +1 -0
@@ -192,6 +192,7 @@ struct perf_sample {u64 data_src;u32 flags;u16 insn_len; +u8 cpumode;void *raw_data;struct ip_callchain *callchain;struct branch_stack *branch_stack;
tools/perf/util/evsel.c +1 -0
@@ -1643,6 +1643,7 @@ int perf_evsel__parse_sample(struct perf_evsel *evsel, union perf_event *event, data->stream_id = data->id = data->time =-1ULL ; data->period = evsel->attr.sample_period; data->weight =0 ; + data->cpumode = event->header.misc &PERF_RECORD_MISC_CPUMODE_MASK ;if (event->header.type !=PERF_RECORD_SAMPLE ) {if (!evsel->attr.sample_id_all)
tools/perf/util/machine.c +6 -8
@@ -1301,9 +1301,8 @@ out_problem:int machine__process_mmap2_event (struct machine *machine,union perf_event *event, -struct perf_sample *sample__maybe_unused ) +struct perf_sample *sample) { -u8 cpumode = event->header.misc &PERF_RECORD_MISC_CPUMODE_MASK ;struct thread *thread;struct map *map;enum map_type type;
@@ -1312,8 +1311,8 @@ int machine__process_mmap2_event(struct machine *machine,if (dump_trace)perf_event__fprintf_mmap2 (event, stdout); -if (cpumode ==PERF_RECORD_MISC_GUEST_KERNEL || - cpumode ==PERF_RECORD_MISC_KERNEL ) { +if (sample->cpumode ==PERF_RECORD_MISC_GUEST_KERNEL || + sample->cpumode ==PERF_RECORD_MISC_KERNEL ) { ret =machine__process_kernel_mmap_event (machine, event);if (ret <0 ) goto out_problem;
@@ -1355,9 +1354,8 @@ out_problem: }int machine__process_mmap_event (struct machine *machine,union perf_event *event, -struct perf_sample *sample__maybe_unused ) +struct perf_sample *sample) { -u8 cpumode = event->header.misc &PERF_RECORD_MISC_CPUMODE_MASK ;struct thread *thread;struct map *map;enum map_type type;
@@ -1366,8 +1364,8 @@ int machine__process_mmap_event(struct machine *machine, union perf_event *eventif (dump_trace)perf_event__fprintf_mmap (event, stdout); -if (cpumode ==PERF_RECORD_MISC_GUEST_KERNEL || - cpumode ==PERF_RECORD_MISC_KERNEL ) { +if (sample->cpumode ==PERF_RECORD_MISC_GUEST_KERNEL || + sample->cpumode ==PERF_RECORD_MISC_KERNEL ) { ret =machine__process_kernel_mmap_event (machine, event);if (ret <0 ) goto out_problem;
tools/perf/util/session.c +2 -3
@@ -1107,12 +1107,11 @@ static struct machine *machines__find_for_cpumode(struct machines *machines,union perf_event *event, struct perf_sample *sample) { - const u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK; struct machine *machine;if (perf_guest && - ((cpumode ==PERF_RECORD_MISC_GUEST_KERNEL ) || - (cpumode ==PERF_RECORD_MISC_GUEST_USER ))) { + ((sample->cpumode ==PERF_RECORD_MISC_GUEST_KERNEL ) || + (sample->cpumode ==PERF_RECORD_MISC_GUEST_USER ))) {u32 pid; if (event->header.type == PERF_RECORD_MMAP