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 <adrian.hunter@intel.com>
Cc: Hemant Kumar <hemant@linux.vnet.ibm.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
Cc: Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-qp3yradhyt6q3wl895b1aat0@git.kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent eb9f0323
...@@ -416,9 +416,6 @@ static int perf_event__inject_buildid(struct perf_tool *tool, ...@@ -416,9 +416,6 @@ static int perf_event__inject_buildid(struct perf_tool *tool,
{ {
struct addr_location al; struct addr_location al;
struct thread *thread; struct thread *thread;
u8 cpumode;
cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
thread = machine__findnew_thread(machine, sample->pid, sample->tid); thread = machine__findnew_thread(machine, sample->pid, sample->tid);
if (thread == NULL) { if (thread == NULL) {
...@@ -427,7 +424,7 @@ static int perf_event__inject_buildid(struct perf_tool *tool, ...@@ -427,7 +424,7 @@ static int perf_event__inject_buildid(struct perf_tool *tool,
goto repipe; 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 != NULL) {
if (!al.map->dso->hit) { if (!al.map->dso->hit) {
......
...@@ -498,14 +498,13 @@ static void print_sample_brstack(union perf_event *event __maybe_unused, ...@@ -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 perf_sample *sample,
struct thread *thread __maybe_unused, struct thread *thread __maybe_unused,
struct perf_event_attr *attr __maybe_unused) struct perf_event_attr *attr __maybe_unused)
{ {
struct branch_stack *br = sample->branch_stack; struct branch_stack *br = sample->branch_stack;
struct addr_location alf, alt; struct addr_location alf, alt;
u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
u64 i, from, to; u64 i, from, to;
if (!(br && br->nr)) if (!(br && br->nr))
...@@ -518,11 +517,11 @@ static void print_sample_brstacksym(union perf_event *event, ...@@ -518,11 +517,11 @@ static void print_sample_brstacksym(union perf_event *event,
from = br->entries[i].from; from = br->entries[i].from;
to = br->entries[i].to; 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) if (alf.map)
alf.sym = map__find_symbol(alf.map, alf.addr, NULL); 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) if (alt.map)
alt.sym = map__find_symbol(alt.map, alt.addr, NULL); alt.sym = map__find_symbol(alt.map, alt.addr, NULL);
......
...@@ -809,7 +809,6 @@ static void perf_top__mmap_read_idx(struct perf_top *top, int idx) ...@@ -809,7 +809,6 @@ static void perf_top__mmap_read_idx(struct perf_top *top, int idx)
struct perf_session *session = top->session; struct perf_session *session = top->session;
union perf_event *event; union perf_event *event;
struct machine *machine; struct machine *machine;
u8 origin;
int ret; int ret;
while ((event = perf_evlist__mmap_read(top->evlist, idx)) != NULL) { 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) ...@@ -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); evsel = perf_evlist__id2evsel(session->evlist, sample.id);
assert(evsel != NULL); assert(evsel != NULL);
origin = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
if (event->header.type == PERF_RECORD_SAMPLE) if (event->header.type == PERF_RECORD_SAMPLE)
++top->samples; ++top->samples;
switch (origin) { switch (sample.cpumode) {
case PERF_RECORD_MISC_USER: case PERF_RECORD_MISC_USER:
++top->us_samples; ++top->us_samples;
if (top->hide_user_symbols) if (top->hide_user_symbols)
......
...@@ -2256,11 +2256,10 @@ static void print_location(FILE *f, struct perf_sample *sample, ...@@ -2256,11 +2256,10 @@ static void print_location(FILE *f, struct perf_sample *sample,
static int trace__pgfault(struct trace *trace, static int trace__pgfault(struct trace *trace,
struct perf_evsel *evsel, struct perf_evsel *evsel,
union perf_event *event, union perf_event *event __maybe_unused,
struct perf_sample *sample) struct perf_sample *sample)
{ {
struct thread *thread; struct thread *thread;
u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
struct addr_location al; struct addr_location al;
char map_type = 'd'; char map_type = 'd';
struct thread_trace *ttrace; struct thread_trace *ttrace;
...@@ -2279,7 +2278,7 @@ static int trace__pgfault(struct trace *trace, ...@@ -2279,7 +2278,7 @@ static int trace__pgfault(struct trace *trace,
if (trace->summary_only) if (trace->summary_only)
goto out; goto out;
thread__find_addr_location(thread, cpumode, MAP__FUNCTION, thread__find_addr_location(thread, sample->cpumode, MAP__FUNCTION,
sample->ip, &al); sample->ip, &al);
trace__fprintf_entry_head(trace, thread, 0, sample->time, trace->output); trace__fprintf_entry_head(trace, thread, 0, sample->time, trace->output);
...@@ -2292,11 +2291,11 @@ static int trace__pgfault(struct trace *trace, ...@@ -2292,11 +2291,11 @@ static int trace__pgfault(struct trace *trace,
fprintf(trace->output, "] => "); fprintf(trace->output, "] => ");
thread__find_addr_location(thread, cpumode, MAP__VARIABLE, thread__find_addr_location(thread, sample->cpumode, MAP__VARIABLE,
sample->addr, &al); sample->addr, &al);
if (!al.map) { if (!al.map) {
thread__find_addr_location(thread, cpumode, thread__find_addr_location(thread, sample->cpumode,
MAP__FUNCTION, sample->addr, &al); MAP__FUNCTION, sample->addr, &al);
if (al.map) if (al.map)
......
...@@ -293,7 +293,6 @@ static int process_sample_event(struct machine *machine, ...@@ -293,7 +293,6 @@ static int process_sample_event(struct machine *machine,
{ {
struct perf_sample sample; struct perf_sample sample;
struct thread *thread; struct thread *thread;
u8 cpumode;
int ret; int ret;
if (perf_evlist__parse_sample(evlist, event, &sample)) { if (perf_evlist__parse_sample(evlist, event, &sample)) {
...@@ -307,9 +306,7 @@ static int process_sample_event(struct machine *machine, ...@@ -307,9 +306,7 @@ static int process_sample_event(struct machine *machine,
return -1; return -1;
} }
cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK; ret = read_object_code(sample.ip, READLEN, sample.cpumode, thread, state);
ret = read_object_code(sample.ip, READLEN, cpumode, thread, state);
thread__put(thread); thread__put(thread);
return ret; return ret;
} }
......
...@@ -100,9 +100,11 @@ struct machine *setup_fake_machine(struct machines *machines) ...@@ -100,9 +100,11 @@ struct machine *setup_fake_machine(struct machines *machines)
} }
for (i = 0; i < ARRAY_SIZE(fake_mmap_info); i++) { 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 = { union perf_event fake_mmap_event = {
.mmap = { .mmap = {
.header = { .misc = PERF_RECORD_MISC_USER, },
.pid = fake_mmap_info[i].pid, .pid = fake_mmap_info[i].pid,
.tid = fake_mmap_info[i].pid, .tid = fake_mmap_info[i].pid,
.start = fake_mmap_info[i].start, .start = fake_mmap_info[i].start,
...@@ -114,7 +116,7 @@ struct machine *setup_fake_machine(struct machines *machines) ...@@ -114,7 +116,7 @@ struct machine *setup_fake_machine(struct machines *machines)
strcpy(fake_mmap_event.mmap.filename, strcpy(fake_mmap_event.mmap.filename,
fake_mmap_info[i].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++) { for (i = 0; i < ARRAY_SIZE(fake_symbols); i++) {
......
...@@ -97,6 +97,7 @@ static int add_hist_entries(struct hists *hists, struct machine *machine) ...@@ -97,6 +97,7 @@ static int add_hist_entries(struct hists *hists, struct machine *machine)
else else
iter.ops = &hist_iter_normal; iter.ops = &hist_iter_normal;
sample.cpumode = PERF_RECORD_MISC_USER;
sample.pid = fake_samples[i].pid; sample.pid = fake_samples[i].pid;
sample.tid = fake_samples[i].pid; sample.tid = fake_samples[i].pid;
sample.ip = fake_samples[i].ip; sample.ip = fake_samples[i].ip;
......
...@@ -76,6 +76,7 @@ static int add_hist_entries(struct perf_evlist *evlist, ...@@ -76,6 +76,7 @@ static int add_hist_entries(struct perf_evlist *evlist,
hists->dso_filter = NULL; hists->dso_filter = NULL;
hists->symbol_filter_str = NULL; hists->symbol_filter_str = NULL;
sample.cpumode = PERF_RECORD_MISC_USER;
sample.pid = fake_samples[i].pid; sample.pid = fake_samples[i].pid;
sample.tid = fake_samples[i].pid; sample.tid = fake_samples[i].pid;
sample.ip = fake_samples[i].ip; sample.ip = fake_samples[i].ip;
......
...@@ -82,6 +82,7 @@ static int add_hist_entries(struct perf_evlist *evlist, struct machine *machine) ...@@ -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.pid = fake_common_samples[k].pid;
sample.tid = fake_common_samples[k].pid; sample.tid = fake_common_samples[k].pid;
sample.ip = fake_common_samples[k].ip; sample.ip = fake_common_samples[k].ip;
......
...@@ -63,6 +63,7 @@ static int add_hist_entries(struct hists *hists, struct machine *machine) ...@@ -63,6 +63,7 @@ static int add_hist_entries(struct hists *hists, struct machine *machine)
.hide_unresolved = false, .hide_unresolved = false,
}; };
sample.cpumode = PERF_RECORD_MISC_USER;
sample.cpu = fake_samples[i].cpu; sample.cpu = fake_samples[i].cpu;
sample.pid = fake_samples[i].pid; sample.pid = fake_samples[i].pid;
sample.tid = fake_samples[i].pid; sample.tid = fake_samples[i].pid;
......
...@@ -28,7 +28,6 @@ int build_id__mark_dso_hit(struct perf_tool *tool __maybe_unused, ...@@ -28,7 +28,6 @@ int build_id__mark_dso_hit(struct perf_tool *tool __maybe_unused,
struct machine *machine) struct machine *machine)
{ {
struct addr_location al; struct addr_location al;
u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
struct thread *thread = machine__findnew_thread(machine, sample->pid, struct thread *thread = machine__findnew_thread(machine, sample->pid,
sample->tid); sample->tid);
...@@ -38,7 +37,7 @@ int build_id__mark_dso_hit(struct perf_tool *tool __maybe_unused, ...@@ -38,7 +37,7 @@ int build_id__mark_dso_hit(struct perf_tool *tool __maybe_unused,
return -1; 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) if (al.map != NULL)
al.map->dso->hit = 1; al.map->dso->hit = 1;
......
...@@ -1295,12 +1295,11 @@ void thread__find_addr_location(struct thread *thread, ...@@ -1295,12 +1295,11 @@ void thread__find_addr_location(struct thread *thread,
* Callers need to drop the reference to al->thread, obtained in * Callers need to drop the reference to al->thread, obtained in
* machine__findnew_thread() * 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 machine *machine,
struct addr_location *al, struct addr_location *al,
struct perf_sample *sample) struct perf_sample *sample)
{ {
u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
struct thread *thread = machine__findnew_thread(machine, sample->pid, struct thread *thread = machine__findnew_thread(machine, sample->pid,
sample->tid); sample->tid);
...@@ -1315,11 +1314,11 @@ int perf_event__preprocess_sample(const union perf_event *event, ...@@ -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 * events, but for older perf.data files there was no such thing, so do
* it now. * it now.
*/ */
if (cpumode == PERF_RECORD_MISC_KERNEL && if (sample->cpumode == PERF_RECORD_MISC_KERNEL &&
machine__kernel_map(machine) == NULL) machine__kernel_map(machine) == NULL)
machine__create_kernel_maps(machine); 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", dump_printf(" ...... dso: %s\n",
al->map ? al->map->dso->long_name : al->map ? al->map->dso->long_name :
al->level == 'H' ? "[hypervisor]" : "<not found>"); al->level == 'H' ? "[hypervisor]" : "<not found>");
...@@ -1395,16 +1394,14 @@ bool sample_addr_correlates_sym(struct perf_event_attr *attr) ...@@ -1395,16 +1394,14 @@ bool sample_addr_correlates_sym(struct perf_event_attr *attr)
return false; 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 perf_sample *sample,
struct thread *thread, struct thread *thread,
struct addr_location *al) struct addr_location *al)
{ {
u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK; thread__find_addr_map(thread, sample->cpumode, MAP__FUNCTION, sample->addr, al);
thread__find_addr_map(thread, cpumode, MAP__FUNCTION, sample->addr, al);
if (!al->map) if (!al->map)
thread__find_addr_map(thread, cpumode, MAP__VARIABLE, thread__find_addr_map(thread, sample->cpumode, MAP__VARIABLE,
sample->addr, al); sample->addr, al);
al->cpu = sample->cpu; al->cpu = sample->cpu;
......
...@@ -192,6 +192,7 @@ struct perf_sample { ...@@ -192,6 +192,7 @@ struct perf_sample {
u64 data_src; u64 data_src;
u32 flags; u32 flags;
u16 insn_len; u16 insn_len;
u8 cpumode;
void *raw_data; void *raw_data;
struct ip_callchain *callchain; struct ip_callchain *callchain;
struct branch_stack *branch_stack; struct branch_stack *branch_stack;
......
...@@ -1643,6 +1643,7 @@ int perf_evsel__parse_sample(struct perf_evsel *evsel, union perf_event *event, ...@@ -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->stream_id = data->id = data->time = -1ULL;
data->period = evsel->attr.sample_period; data->period = evsel->attr.sample_period;
data->weight = 0; data->weight = 0;
data->cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
if (event->header.type != PERF_RECORD_SAMPLE) { if (event->header.type != PERF_RECORD_SAMPLE) {
if (!evsel->attr.sample_id_all) if (!evsel->attr.sample_id_all)
......
...@@ -1301,9 +1301,8 @@ static int machine__process_kernel_mmap_event(struct machine *machine, ...@@ -1301,9 +1301,8 @@ static int machine__process_kernel_mmap_event(struct machine *machine,
int machine__process_mmap2_event(struct machine *machine, int machine__process_mmap2_event(struct machine *machine,
union perf_event *event, 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 thread *thread;
struct map *map; struct map *map;
enum map_type type; enum map_type type;
...@@ -1312,8 +1311,8 @@ int machine__process_mmap2_event(struct machine *machine, ...@@ -1312,8 +1311,8 @@ int machine__process_mmap2_event(struct machine *machine,
if (dump_trace) if (dump_trace)
perf_event__fprintf_mmap2(event, stdout); perf_event__fprintf_mmap2(event, stdout);
if (cpumode == PERF_RECORD_MISC_GUEST_KERNEL || if (sample->cpumode == PERF_RECORD_MISC_GUEST_KERNEL ||
cpumode == PERF_RECORD_MISC_KERNEL) { sample->cpumode == PERF_RECORD_MISC_KERNEL) {
ret = machine__process_kernel_mmap_event(machine, event); ret = machine__process_kernel_mmap_event(machine, event);
if (ret < 0) if (ret < 0)
goto out_problem; goto out_problem;
...@@ -1355,9 +1354,8 @@ int machine__process_mmap2_event(struct machine *machine, ...@@ -1355,9 +1354,8 @@ int machine__process_mmap2_event(struct machine *machine,
} }
int machine__process_mmap_event(struct machine *machine, union perf_event *event, 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 thread *thread;
struct map *map; struct map *map;
enum map_type type; enum map_type type;
...@@ -1366,8 +1364,8 @@ int machine__process_mmap_event(struct machine *machine, union perf_event *event ...@@ -1366,8 +1364,8 @@ int machine__process_mmap_event(struct machine *machine, union perf_event *event
if (dump_trace) if (dump_trace)
perf_event__fprintf_mmap(event, stdout); perf_event__fprintf_mmap(event, stdout);
if (cpumode == PERF_RECORD_MISC_GUEST_KERNEL || if (sample->cpumode == PERF_RECORD_MISC_GUEST_KERNEL ||
cpumode == PERF_RECORD_MISC_KERNEL) { sample->cpumode == PERF_RECORD_MISC_KERNEL) {
ret = machine__process_kernel_mmap_event(machine, event); ret = machine__process_kernel_mmap_event(machine, event);
if (ret < 0) if (ret < 0)
goto out_problem; goto out_problem;
......
...@@ -1107,12 +1107,11 @@ static struct machine *machines__find_for_cpumode(struct machines *machines, ...@@ -1107,12 +1107,11 @@ static struct machine *machines__find_for_cpumode(struct machines *machines,
union perf_event *event, union perf_event *event,
struct perf_sample *sample) struct perf_sample *sample)
{ {
const u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
struct machine *machine; struct machine *machine;
if (perf_guest && if (perf_guest &&
((cpumode == PERF_RECORD_MISC_GUEST_KERNEL) || ((sample->cpumode == PERF_RECORD_MISC_GUEST_KERNEL) ||
(cpumode == PERF_RECORD_MISC_GUEST_USER))) { (sample->cpumode == PERF_RECORD_MISC_GUEST_USER))) {
u32 pid; u32 pid;
if (event->header.type == PERF_RECORD_MMAP if (event->header.type == PERF_RECORD_MMAP
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment