Skip to content

Commit

Permalink
perf tools: Add cpumode to struct perf_sample
Browse files Browse the repository at this point in the history
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]>
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
  • Loading branch information
acmel committed Mar 23, 2016
1 parent eb9f032 commit 473398a
Show file tree
Hide file tree
Showing 16 changed files with 35 additions and 45 deletions.
5 changes: 1 addition & 4 deletions tools/perf/builtin-inject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
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 @@ -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))
Expand All @@ -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);

Expand Down
5 changes: 1 addition & 4 deletions tools/perf/builtin-top.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
Expand Down
9 changes: 4 additions & 5 deletions tools/perf/builtin-trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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)
Expand Down
5 changes: 1 addition & 4 deletions tools/perf/tests/code-reading.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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;
}
Expand Down
6 changes: 4 additions & 2 deletions tools/perf/tests/hists_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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++) {
Expand Down
1 change: 1 addition & 0 deletions tools/perf/tests/hists_cumulate.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions tools/perf/tests/hists_filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions tools/perf/tests/hists_link.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions tools/perf/tests/hists_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
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 @@ -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);

Expand All @@ -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;
Expand Down
15 changes: 6 additions & 9 deletions tools/perf/util/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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>");
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions tools/perf/util/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions tools/perf/util/evsel.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 6 additions & 8 deletions tools/perf/util/machine.c
Original file line number Diff line number Diff line change
Expand Up @@ -1301,9 +1301,8 @@ static int machine__process_kernel_mmap_event(struct machine *machine,

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;
Expand All @@ -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;
Expand Down Expand Up @@ -1355,9 +1354,8 @@ int machine__process_mmap2_event(struct machine *machine,
}

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;
Expand All @@ -1366,8 +1364,8 @@ int machine__process_mmap_event(struct machine *machine, union perf_event *event
if (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;
Expand Down
5 changes: 2 additions & 3 deletions tools/perf/util/session.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 473398a

Please sign in to comment.