]> git.karo-electronics.de Git - linux-beck.git/commitdiff
perf tools: Add cpumode to struct perf_sample
authorArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 22 Mar 2016 21:23:43 +0000 (18:23 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 23 Mar 2016 15:03:07 +0000 (12:03 -0300)
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.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
16 files changed:
tools/perf/builtin-inject.c
tools/perf/builtin-script.c
tools/perf/builtin-top.c
tools/perf/builtin-trace.c
tools/perf/tests/code-reading.c
tools/perf/tests/hists_common.c
tools/perf/tests/hists_cumulate.c
tools/perf/tests/hists_filter.c
tools/perf/tests/hists_link.c
tools/perf/tests/hists_output.c
tools/perf/util/build-id.c
tools/perf/util/event.c
tools/perf/util/event.h
tools/perf/util/evsel.c
tools/perf/util/machine.c
tools/perf/util/session.c

index b33b42c009ed18bae2d813bc0ad2a1da542485cb..d1a2d104f2bc19153159f83c3bf4941896c5ccad 100644 (file)
@@ -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) {
index d04c8e7a9507fc39fad124446a51edcbf11e2c27..928a4411e0235cf6fbe9647e65ef2c9c145211df 100644 (file)
@@ -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);
 
index 94af190f6843d2c92e68b2dfef8dc51017c42079..a287800bc4950ab3ca052b041889c7d4448e0d67 100644 (file)
@@ -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)
index 8dc98c598b1aed734ab6a6695c7308f3c16e0910..93ac724fb635ce71236615aa80014b67a740fa08 100644 (file)
@@ -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)
index afc9ad0a0515c5db77745d0d0c6964d950fa3bfc..abd3f0ec0c0b8e61c6371df1077e1fb2240e068e 100644 (file)
@@ -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;
 }
index 071a8b5f5232fa394d4baa88a611f48e3ef2687d..f55f4bd47932dbaaf325a6732d0daa7a12a2358b 100644 (file)
@@ -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++) {
index ecf136c385d5ff2f21111e813a9ce1e30c03365a..cf7eef73fbe64bf12c51358d087126aa79ccd444 100644 (file)
@@ -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;
index 34b945a55d4d2864cc561f36275191f57f84210a..1c9e19352cb6029966cc18d2fce187583f7e26e6 100644 (file)
@@ -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;
index 64b257d8d557679f71a56458067f5324e6a6f62c..7885b1d324e49750cbd7c632b4e11dc7240bdede 100644 (file)
@@ -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;
index 23cce67c7e48902b86c00cc6e56df22ef16386e4..03e4e9c47a553d1f6b212591bd11bb5c61aa21d5 100644 (file)
@@ -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;
index f1479eeef7daf9ae2c386abcef7d079a0370c836..0573c2ec861d9de0a04dbb71862e0ed85e255ff1 100644 (file)
@@ -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;
index 7bad5c3fa7b7175862f5e3bdf38ffca0e1b14ee1..f679caac12d0ff1994cdd6235d2c3a407f4517d2 100644 (file)
@@ -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;
index b7ffb7ee9971f020f1b2320baa478ed1421a01e9..f5a2e67c86aae385576f1ae224fe207d76fe46c5 100644 (file)
@@ -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;
index 0902fe418754ec0c3149d3daeafc122fee65e243..738ce226002b8a0e88093fefaf74e9fe6093a13a 100644 (file)
@@ -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)
index ad79297c76c87533fb961ac5f8e3daee58f2fda6..80b9b6a87990b29e4722a956e62814130c1290de 100644 (file)
@@ -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 *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;
index 60b3593d210dbc3b52997a693bcc8f9645687f08..4abd85c6346dd5d8193108d8c72668dfe2ef2948 100644 (file)
@@ -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