]> asedeno.scripts.mit.edu Git - linux.git/blobdiff - tools/perf/util/evlist.c
libperf: Add 'overwrite' to 'struct perf_mmap'
[linux.git] / tools / perf / util / evlist.c
index f2b86f49ab8d257c812fba56131f6266e3347cfc..16d47a420bc2cde71068619ec0df2f56f0cbfdac 100644 (file)
 #include <inttypes.h>
 #include <poll.h>
 #include "cpumap.h"
+#include "util/mmap.h"
 #include "thread_map.h"
 #include "target.h"
 #include "evlist.h"
 #include "evsel.h"
 #include "debug.h"
 #include "units.h"
+#include "util.h" // page_size
+#include "../perf.h"
 #include "asm/bug.h"
 #include "bpf-event.h"
 #include <signal.h>
 #include <unistd.h>
+#include <sched.h>
+#include <stdlib.h>
 
 #include "parse-events.h"
 #include <subcmd/parse-options.h>
 #include <linux/hash.h>
 #include <linux/log2.h>
 #include <linux/err.h>
+#include <linux/string.h>
 #include <linux/zalloc.h>
 #include <perf/evlist.h>
+#include <perf/evsel.h>
+#include <perf/cpumap.h>
+
+#include <internal/xyarray.h>
 
 #ifdef LACKS_SIGQUEUE_PROTOTYPE
 int sigqueue(pid_t pid, int sig, const union sigval value);
 #endif
 
-#define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y))
+#define FD(e, x, y) (*(int *)xyarray__entry(e->core.fd, x, y))
 #define SID(e, x, y) xyarray__entry(e->sample_id, x, y)
 
 void evlist__init(struct evlist *evlist, struct perf_cpu_map *cpus,
@@ -50,7 +60,7 @@ void evlist__init(struct evlist *evlist, struct perf_cpu_map *cpus,
        for (i = 0; i < PERF_EVLIST__HLIST_SIZE; ++i)
                INIT_HLIST_HEAD(&evlist->heads[i]);
        perf_evlist__init(&evlist->core);
-       perf_evlist__set_maps(evlist, cpus, threads);
+       perf_evlist__set_maps(&evlist->core, cpus, threads);
        fdarray__init(&evlist->pollfd, 64);
        evlist->workload.pid = -1;
        evlist->bkw_mmap_state = BKW_MMAP_NOTREADY;
@@ -115,7 +125,7 @@ static void perf_evlist__update_id_pos(struct evlist *evlist)
        perf_evlist__set_id_pos(evlist);
 }
 
-static void perf_evlist__purge(struct evlist *evlist)
+static void evlist__purge(struct evlist *evlist)
 {
        struct evsel *pos, *n;
 
@@ -125,10 +135,10 @@ static void perf_evlist__purge(struct evlist *evlist)
                evsel__delete(pos);
        }
 
-       evlist->nr_entries = 0;
+       evlist->core.nr_entries = 0;
 }
 
-void perf_evlist__exit(struct evlist *evlist)
+void evlist__exit(struct evlist *evlist)
 {
        zfree(&evlist->mmap);
        zfree(&evlist->overwrite_mmap);
@@ -140,62 +150,33 @@ void evlist__delete(struct evlist *evlist)
        if (evlist == NULL)
                return;
 
-       perf_evlist__munmap(evlist);
+       evlist__munmap(evlist);
        evlist__close(evlist);
-       perf_cpu_map__put(evlist->cpus);
-       perf_thread_map__put(evlist->threads);
-       evlist->cpus = NULL;
-       evlist->threads = NULL;
-       perf_evlist__purge(evlist);
-       perf_evlist__exit(evlist);
+       perf_cpu_map__put(evlist->core.cpus);
+       perf_thread_map__put(evlist->core.threads);
+       evlist->core.cpus = NULL;
+       evlist->core.threads = NULL;
+       evlist__purge(evlist);
+       evlist__exit(evlist);
        free(evlist);
 }
 
-static void __perf_evlist__propagate_maps(struct evlist *evlist,
-                                         struct evsel *evsel)
-{
-       /*
-        * We already have cpus for evsel (via PMU sysfs) so
-        * keep it, if there's no target cpu list defined.
-        */
-       if (!evsel->own_cpus || evlist->has_user_cpus) {
-               perf_cpu_map__put(evsel->cpus);
-               evsel->cpus = perf_cpu_map__get(evlist->cpus);
-       } else if (evsel->cpus != evsel->own_cpus) {
-               perf_cpu_map__put(evsel->cpus);
-               evsel->cpus = perf_cpu_map__get(evsel->own_cpus);
-       }
-
-       perf_thread_map__put(evsel->threads);
-       evsel->threads = perf_thread_map__get(evlist->threads);
-}
-
-static void perf_evlist__propagate_maps(struct evlist *evlist)
-{
-       struct evsel *evsel;
-
-       evlist__for_each_entry(evlist, evsel)
-               __perf_evlist__propagate_maps(evlist, evsel);
-}
-
 void evlist__add(struct evlist *evlist, struct evsel *entry)
 {
-       perf_evlist__add(&evlist->core, &entry->core);
        entry->evlist = evlist;
-       entry->idx = evlist->nr_entries;
+       entry->idx = evlist->core.nr_entries;
        entry->tracking = !entry->idx;
 
-       if (!evlist->nr_entries++)
-               perf_evlist__set_id_pos(evlist);
+       perf_evlist__add(&evlist->core, &entry->core);
 
-       __perf_evlist__propagate_maps(evlist, entry);
+       if (evlist->core.nr_entries == 1)
+               perf_evlist__set_id_pos(evlist);
 }
 
 void evlist__remove(struct evlist *evlist, struct evsel *evsel)
 {
        evsel->evlist = NULL;
-       list_del_init(&evsel->core.node);
-       evlist->nr_entries -= 1;
+       perf_evlist__remove(&evlist->core, &evsel->core);
 }
 
 void perf_evlist__splice_list_tail(struct evlist *evlist,
@@ -216,7 +197,7 @@ void __perf_evlist__set_leader(struct list_head *list)
        leader = list_entry(list->next, struct evsel, core.node);
        evsel = list_entry(list->prev, struct evsel, core.node);
 
-       leader->nr_members = evsel->idx - leader->idx + 1;
+       leader->core.nr_members = evsel->idx - leader->idx + 1;
 
        __evlist__for_each_entry(list, evsel) {
                evsel->leader = leader;
@@ -225,8 +206,8 @@ void __perf_evlist__set_leader(struct list_head *list)
 
 void perf_evlist__set_leader(struct evlist *evlist)
 {
-       if (evlist->nr_entries) {
-               evlist->nr_groups = evlist->nr_entries > 1 ? 1 : 0;
+       if (evlist->core.nr_entries) {
+               evlist->nr_groups = evlist->core.nr_entries > 1 ? 1 : 0;
                __perf_evlist__set_leader(&evlist->core.entries);
        }
 }
@@ -249,7 +230,7 @@ int perf_evlist__add_dummy(struct evlist *evlist)
                .config = PERF_COUNT_SW_DUMMY,
                .size   = sizeof(attr), /* to capture ABI version */
        };
-       struct evsel *evsel = perf_evsel__new_idx(&attr, evlist->nr_entries);
+       struct evsel *evsel = perf_evsel__new_idx(&attr, evlist->core.nr_entries);
 
        if (evsel == NULL)
                return -ENOMEM;
@@ -266,7 +247,7 @@ static int evlist__add_attrs(struct evlist *evlist,
        size_t i;
 
        for (i = 0; i < nr_attrs; i++) {
-               evsel = perf_evsel__new_idx(attrs + i, evlist->nr_entries + i);
+               evsel = perf_evsel__new_idx(attrs + i, evlist->core.nr_entries + i);
                if (evsel == NULL)
                        goto out_delete_partial_list;
                list_add_tail(&evsel->core.node, &head);
@@ -299,8 +280,8 @@ perf_evlist__find_tracepoint_by_id(struct evlist *evlist, int id)
        struct evsel *evsel;
 
        evlist__for_each_entry(evlist, evsel) {
-               if (evsel->attr.type   == PERF_TYPE_TRACEPOINT &&
-                   (int)evsel->attr.config == id)
+               if (evsel->core.attr.type   == PERF_TYPE_TRACEPOINT &&
+                   (int)evsel->core.attr.config == id)
                        return evsel;
        }
 
@@ -314,7 +295,7 @@ perf_evlist__find_tracepoint_by_name(struct evlist *evlist,
        struct evsel *evsel;
 
        evlist__for_each_entry(evlist, evsel) {
-               if ((evsel->attr.type == PERF_TYPE_TRACEPOINT) &&
+               if ((evsel->core.attr.type == PERF_TYPE_TRACEPOINT) &&
                    (strcmp(evsel->name, name) == 0))
                        return evsel;
        }
@@ -341,7 +322,7 @@ static int perf_evlist__nr_threads(struct evlist *evlist,
        if (evsel->system_wide)
                return 1;
        else
-               return thread_map__nr(evlist->threads);
+               return perf_thread_map__nr(evlist->core.threads);
 }
 
 void evlist__disable(struct evlist *evlist)
@@ -349,7 +330,7 @@ void evlist__disable(struct evlist *evlist)
        struct evsel *pos;
 
        evlist__for_each_entry(evlist, pos) {
-               if (pos->disabled || !perf_evsel__is_group_leader(pos) || !pos->fd)
+               if (pos->disabled || !perf_evsel__is_group_leader(pos) || !pos->core.fd)
                        continue;
                evsel__disable(pos);
        }
@@ -362,7 +343,7 @@ void evlist__enable(struct evlist *evlist)
        struct evsel *pos;
 
        evlist__for_each_entry(evlist, pos) {
-               if (!perf_evsel__is_group_leader(pos) || !pos->fd)
+               if (!perf_evsel__is_group_leader(pos) || !pos->core.fd)
                        continue;
                evsel__enable(pos);
        }
@@ -381,7 +362,7 @@ static int perf_evlist__enable_event_cpu(struct evlist *evlist,
        int thread;
        int nr_threads = perf_evlist__nr_threads(evlist, evsel);
 
-       if (!evsel->fd)
+       if (!evsel->core.fd)
                return -EINVAL;
 
        for (thread = 0; thread < nr_threads; thread++) {
@@ -397,9 +378,9 @@ static int perf_evlist__enable_event_thread(struct evlist *evlist,
                                            int thread)
 {
        int cpu;
-       int nr_cpus = cpu_map__nr(evlist->cpus);
+       int nr_cpus = perf_cpu_map__nr(evlist->core.cpus);
 
-       if (!evsel->fd)
+       if (!evsel->core.fd)
                return -EINVAL;
 
        for (cpu = 0; cpu < nr_cpus; cpu++) {
@@ -413,7 +394,7 @@ static int perf_evlist__enable_event_thread(struct evlist *evlist,
 int perf_evlist__enable_event_idx(struct evlist *evlist,
                                  struct evsel *evsel, int idx)
 {
-       bool per_cpu_mmaps = !cpu_map__empty(evlist->cpus);
+       bool per_cpu_mmaps = !perf_cpu_map__empty(evlist->core.cpus);
 
        if (per_cpu_mmaps)
                return perf_evlist__enable_event_cpu(evlist, evsel, idx);
@@ -423,8 +404,8 @@ int perf_evlist__enable_event_idx(struct evlist *evlist,
 
 int perf_evlist__alloc_pollfd(struct evlist *evlist)
 {
-       int nr_cpus = cpu_map__nr(evlist->cpus);
-       int nr_threads = thread_map__nr(evlist->threads);
+       int nr_cpus = perf_cpu_map__nr(evlist->core.cpus);
+       int nr_threads = perf_thread_map__nr(evlist->core.threads);
        int nfds = 0;
        struct evsel *evsel;
 
@@ -443,7 +424,7 @@ int perf_evlist__alloc_pollfd(struct evlist *evlist)
 }
 
 static int __perf_evlist__add_pollfd(struct evlist *evlist, int fd,
-                                    struct perf_mmap *map, short revent)
+                                    struct mmap *map, short revent)
 {
        int pos = fdarray__add(&evlist->pollfd, fd, revent | POLLERR | POLLHUP);
        /*
@@ -467,7 +448,7 @@ int perf_evlist__add_pollfd(struct evlist *evlist, int fd)
 static void perf_evlist__munmap_filtered(struct fdarray *fda, int fd,
                                         void *arg __maybe_unused)
 {
-       struct perf_mmap *map = fda->priv[fd].ptr;
+       struct mmap *map = fda->priv[fd].ptr;
 
        if (map)
                perf_mmap__put(map);
@@ -529,13 +510,13 @@ int perf_evlist__id_add_fd(struct evlist *evlist,
        if (perf_evlist__read_format(evlist) & PERF_FORMAT_GROUP)
                return -1;
 
-       if (!(evsel->attr.read_format & PERF_FORMAT_ID) ||
+       if (!(evsel->core.attr.read_format & PERF_FORMAT_ID) ||
            read(fd, &read_data, sizeof(read_data)) == -1)
                return -1;
 
-       if (evsel->attr.read_format & PERF_FORMAT_TOTAL_TIME_ENABLED)
+       if (evsel->core.attr.read_format & PERF_FORMAT_TOTAL_TIME_ENABLED)
                ++id_idx;
-       if (evsel->attr.read_format & PERF_FORMAT_TOTAL_TIME_RUNNING)
+       if (evsel->core.attr.read_format & PERF_FORMAT_TOTAL_TIME_RUNNING)
                ++id_idx;
 
        id = read_data[id_idx];
@@ -551,12 +532,12 @@ static void perf_evlist__set_sid_idx(struct evlist *evlist,
 {
        struct perf_sample_id *sid = SID(evsel, cpu, thread);
        sid->idx = idx;
-       if (evlist->cpus && cpu >= 0)
-               sid->cpu = evlist->cpus->map[cpu];
+       if (evlist->core.cpus && cpu >= 0)
+               sid->cpu = evlist->core.cpus->map[cpu];
        else
                sid->cpu = -1;
-       if (!evsel->system_wide && evlist->threads && thread >= 0)
-               sid->tid = thread_map__pid(evlist->threads, thread);
+       if (!evsel->system_wide && evlist->core.threads && thread >= 0)
+               sid->tid = perf_thread_map__pid(evlist->core.threads, thread);
        else
                sid->tid = -1;
 }
@@ -581,7 +562,7 @@ struct evsel *perf_evlist__id2evsel(struct evlist *evlist, u64 id)
 {
        struct perf_sample_id *sid;
 
-       if (evlist->nr_entries == 1 || !id)
+       if (evlist->core.nr_entries == 1 || !id)
                return perf_evlist__first(evlist);
 
        sid = perf_evlist__id2sid(evlist, id);
@@ -612,7 +593,7 @@ struct evsel *perf_evlist__id2evsel_strict(struct evlist *evlist,
 static int perf_evlist__event2id(struct evlist *evlist,
                                 union perf_event *event, u64 *id)
 {
-       const u64 *array = event->sample.array;
+       const __u64 *array = event->sample.array;
        ssize_t n;
 
        n = (event->header.size - sizeof(event->header)) >> 3;
@@ -639,10 +620,10 @@ struct evsel *perf_evlist__event2evsel(struct evlist *evlist,
        int hash;
        u64 id;
 
-       if (evlist->nr_entries == 1)
+       if (evlist->core.nr_entries == 1)
                return first;
 
-       if (!first->attr.sample_id_all &&
+       if (!first->core.attr.sample_id_all &&
            event->header.type != PERF_RECORD_SAMPLE)
                return first;
 
@@ -671,7 +652,7 @@ static int perf_evlist__set_paused(struct evlist *evlist, bool value)
                return 0;
 
        for (i = 0; i < evlist->nr_mmaps; i++) {
-               int fd = evlist->overwrite_mmap[i].fd;
+               int fd = evlist->overwrite_mmap[i].core.fd;
                int err;
 
                if (fd < 0)
@@ -693,7 +674,7 @@ static int perf_evlist__resume(struct evlist *evlist)
        return perf_evlist__set_paused(evlist, false);
 }
 
-static void perf_evlist__munmap_nofree(struct evlist *evlist)
+static void evlist__munmap_nofree(struct evlist *evlist)
 {
        int i;
 
@@ -706,29 +687,29 @@ static void perf_evlist__munmap_nofree(struct evlist *evlist)
                        perf_mmap__munmap(&evlist->overwrite_mmap[i]);
 }
 
-void perf_evlist__munmap(struct evlist *evlist)
+void evlist__munmap(struct evlist *evlist)
 {
-       perf_evlist__munmap_nofree(evlist);
+       evlist__munmap_nofree(evlist);
        zfree(&evlist->mmap);
        zfree(&evlist->overwrite_mmap);
 }
 
-static struct perf_mmap *perf_evlist__alloc_mmap(struct evlist *evlist,
-                                                bool overwrite)
+static struct mmap *evlist__alloc_mmap(struct evlist *evlist,
+                                      bool overwrite)
 {
        int i;
-       struct perf_mmap *map;
+       struct mmap *map;
 
-       evlist->nr_mmaps = cpu_map__nr(evlist->cpus);
-       if (cpu_map__empty(evlist->cpus))
-               evlist->nr_mmaps = thread_map__nr(evlist->threads);
-       map = zalloc(evlist->nr_mmaps * sizeof(struct perf_mmap));
+       evlist->nr_mmaps = perf_cpu_map__nr(evlist->core.cpus);
+       if (perf_cpu_map__empty(evlist->core.cpus))
+               evlist->nr_mmaps = perf_thread_map__nr(evlist->core.threads);
+       map = zalloc(evlist->nr_mmaps * sizeof(struct mmap));
        if (!map)
                return NULL;
 
        for (i = 0; i < evlist->nr_mmaps; i++) {
-               map[i].fd = -1;
-               map[i].overwrite = overwrite;
+               map[i].core.fd = -1;
+               map[i].core.overwrite = overwrite;
                /*
                 * When the perf_mmap() call is made we grab one refcount, plus
                 * one extra to let perf_mmap__consume() get the last
@@ -738,7 +719,7 @@ static struct perf_mmap *perf_evlist__alloc_mmap(struct evlist *evlist,
                 * Each PERF_EVENT_IOC_SET_OUTPUT points to this mmap and
                 * thus does perf_mmap__get() on it.
                 */
-               refcount_set(&map[i].refcnt, 0);
+               refcount_set(&map[i].core.refcnt, 0);
        }
        return map;
 }
@@ -747,32 +728,32 @@ static bool
 perf_evlist__should_poll(struct evlist *evlist __maybe_unused,
                         struct evsel *evsel)
 {
-       if (evsel->attr.write_backward)
+       if (evsel->core.attr.write_backward)
                return false;
        return true;
 }
 
-static int perf_evlist__mmap_per_evsel(struct evlist *evlist, int idx,
+static int evlist__mmap_per_evsel(struct evlist *evlist, int idx,
                                       struct mmap_params *mp, int cpu_idx,
                                       int thread, int *_output, int *_output_overwrite)
 {
        struct evsel *evsel;
        int revent;
-       int evlist_cpu = cpu_map__cpu(evlist->cpus, cpu_idx);
+       int evlist_cpu = cpu_map__cpu(evlist->core.cpus, cpu_idx);
 
        evlist__for_each_entry(evlist, evsel) {
-               struct perf_mmap *maps = evlist->mmap;
+               struct mmap *maps = evlist->mmap;
                int *output = _output;
                int fd;
                int cpu;
 
                mp->prot = PROT_READ | PROT_WRITE;
-               if (evsel->attr.write_backward) {
+               if (evsel->core.attr.write_backward) {
                        output = _output_overwrite;
                        maps = evlist->overwrite_mmap;
 
                        if (!maps) {
-                               maps = perf_evlist__alloc_mmap(evlist, true);
+                               maps = evlist__alloc_mmap(evlist, true);
                                if (!maps)
                                        return -1;
                                evlist->overwrite_mmap = maps;
@@ -785,7 +766,7 @@ static int perf_evlist__mmap_per_evsel(struct evlist *evlist, int idx,
                if (evsel->system_wide && thread)
                        continue;
 
-               cpu = cpu_map__idx(evsel->cpus, evlist_cpu);
+               cpu = perf_cpu_map__idx(evsel->core.cpus, evlist_cpu);
                if (cpu == -1)
                        continue;
 
@@ -818,7 +799,7 @@ static int perf_evlist__mmap_per_evsel(struct evlist *evlist, int idx,
                        return -1;
                }
 
-               if (evsel->attr.read_format & PERF_FORMAT_ID) {
+               if (evsel->core.attr.read_format & PERF_FORMAT_ID) {
                        if (perf_evlist__id_add_fd(evlist, evsel, cpu, thread,
                                                   fd) < 0)
                                return -1;
@@ -830,12 +811,12 @@ static int perf_evlist__mmap_per_evsel(struct evlist *evlist, int idx,
        return 0;
 }
 
-static int perf_evlist__mmap_per_cpu(struct evlist *evlist,
+static int evlist__mmap_per_cpu(struct evlist *evlist,
                                     struct mmap_params *mp)
 {
        int cpu, thread;
-       int nr_cpus = cpu_map__nr(evlist->cpus);
-       int nr_threads = thread_map__nr(evlist->threads);
+       int nr_cpus = perf_cpu_map__nr(evlist->core.cpus);
+       int nr_threads = perf_thread_map__nr(evlist->core.threads);
 
        pr_debug2("perf event ring buffer mmapped per cpu\n");
        for (cpu = 0; cpu < nr_cpus; cpu++) {
@@ -846,7 +827,7 @@ static int perf_evlist__mmap_per_cpu(struct evlist *evlist,
                                              true);
 
                for (thread = 0; thread < nr_threads; thread++) {
-                       if (perf_evlist__mmap_per_evsel(evlist, cpu, mp, cpu,
+                       if (evlist__mmap_per_evsel(evlist, cpu, mp, cpu,
                                                        thread, &output, &output_overwrite))
                                goto out_unmap;
                }
@@ -855,15 +836,15 @@ static int perf_evlist__mmap_per_cpu(struct evlist *evlist,
        return 0;
 
 out_unmap:
-       perf_evlist__munmap_nofree(evlist);
+       evlist__munmap_nofree(evlist);
        return -1;
 }
 
-static int perf_evlist__mmap_per_thread(struct evlist *evlist,
+static int evlist__mmap_per_thread(struct evlist *evlist,
                                        struct mmap_params *mp)
 {
        int thread;
-       int nr_threads = thread_map__nr(evlist->threads);
+       int nr_threads = perf_thread_map__nr(evlist->core.threads);
 
        pr_debug2("perf event ring buffer mmapped per thread\n");
        for (thread = 0; thread < nr_threads; thread++) {
@@ -873,7 +854,7 @@ static int perf_evlist__mmap_per_thread(struct evlist *evlist,
                auxtrace_mmap_params__set_idx(&mp->auxtrace_mp, evlist, thread,
                                              false);
 
-               if (perf_evlist__mmap_per_evsel(evlist, thread, mp, 0, thread,
+               if (evlist__mmap_per_evsel(evlist, thread, mp, 0, thread,
                                                &output, &output_overwrite))
                        goto out_unmap;
        }
@@ -881,7 +862,7 @@ static int perf_evlist__mmap_per_thread(struct evlist *evlist,
        return 0;
 
 out_unmap:
-       perf_evlist__munmap_nofree(evlist);
+       evlist__munmap_nofree(evlist);
        return -1;
 }
 
@@ -908,7 +889,7 @@ unsigned long perf_event_mlock_kb_in_pages(void)
        return pages;
 }
 
-size_t perf_evlist__mmap_size(unsigned long pages)
+size_t evlist__mmap_size(unsigned long pages)
 {
        if (pages == UINT_MAX)
                pages = perf_event_mlock_kb_in_pages();
@@ -991,7 +972,7 @@ int perf_evlist__parse_mmap_pages(const struct option *opt, const char *str,
 }
 
 /**
- * perf_evlist__mmap_ex - Create mmaps to receive events.
+ * evlist__mmap_ex - Create mmaps to receive events.
  * @evlist: list of events
  * @pages: map length in pages
  * @overwrite: overwrite older events?
@@ -999,7 +980,7 @@ int perf_evlist__parse_mmap_pages(const struct option *opt, const char *str,
  * @auxtrace_overwrite - overwrite older auxtrace data?
  *
  * If @overwrite is %false the user needs to signal event consumption using
- * perf_mmap__write_tail().  Using perf_evlist__mmap_read() does this
+ * perf_mmap__write_tail().  Using evlist__mmap_read() does this
  * automatically.
  *
  * Similarly, if @auxtrace_overwrite is %false the user needs to signal data
@@ -1007,14 +988,14 @@ int perf_evlist__parse_mmap_pages(const struct option *opt, const char *str,
  *
  * Return: %0 on success, negative error code otherwise.
  */
-int perf_evlist__mmap_ex(struct evlist *evlist, unsigned int pages,
+int evlist__mmap_ex(struct evlist *evlist, unsigned int pages,
                         unsigned int auxtrace_pages,
                         bool auxtrace_overwrite, int nr_cblocks, int affinity, int flush,
                         int comp_level)
 {
        struct evsel *evsel;
-       const struct perf_cpu_map *cpus = evlist->cpus;
-       const struct perf_thread_map *threads = evlist->threads;
+       const struct perf_cpu_map *cpus = evlist->core.cpus;
+       const struct perf_thread_map *threads = evlist->core.threads;
        /*
         * Delay setting mp.prot: set it before calling perf_mmap__mmap.
         * Its value is decided by evsel's write_backward.
@@ -1024,14 +1005,14 @@ int perf_evlist__mmap_ex(struct evlist *evlist, unsigned int pages,
                                  .comp_level = comp_level };
 
        if (!evlist->mmap)
-               evlist->mmap = perf_evlist__alloc_mmap(evlist, false);
+               evlist->mmap = evlist__alloc_mmap(evlist, false);
        if (!evlist->mmap)
                return -ENOMEM;
 
        if (evlist->pollfd.entries == NULL && perf_evlist__alloc_pollfd(evlist) < 0)
                return -ENOMEM;
 
-       evlist->mmap_len = perf_evlist__mmap_size(pages);
+       evlist->mmap_len = evlist__mmap_size(pages);
        pr_debug("mmap size %zuB\n", evlist->mmap_len);
        mp.mask = evlist->mmap_len - page_size - 1;
 
@@ -1039,21 +1020,21 @@ int perf_evlist__mmap_ex(struct evlist *evlist, unsigned int pages,
                                   auxtrace_pages, auxtrace_overwrite);
 
        evlist__for_each_entry(evlist, evsel) {
-               if ((evsel->attr.read_format & PERF_FORMAT_ID) &&
+               if ((evsel->core.attr.read_format & PERF_FORMAT_ID) &&
                    evsel->sample_id == NULL &&
-                   perf_evsel__alloc_id(evsel, cpu_map__nr(cpus), threads->nr) < 0)
+                   perf_evsel__alloc_id(evsel, perf_cpu_map__nr(cpus), threads->nr) < 0)
                        return -ENOMEM;
        }
 
-       if (cpu_map__empty(cpus))
-               return perf_evlist__mmap_per_thread(evlist, &mp);
+       if (perf_cpu_map__empty(cpus))
+               return evlist__mmap_per_thread(evlist, &mp);
 
-       return perf_evlist__mmap_per_cpu(evlist, &mp);
+       return evlist__mmap_per_cpu(evlist, &mp);
 }
 
-int perf_evlist__mmap(struct evlist *evlist, unsigned int pages)
+int evlist__mmap(struct evlist *evlist, unsigned int pages)
 {
-       return perf_evlist__mmap_ex(evlist, pages, 0, false, 0, PERF_AFFINITY_SYS, 1, 0);
+       return evlist__mmap_ex(evlist, pages, 0, false, 0, PERF_AFFINITY_SYS, 1, 0);
 }
 
 int perf_evlist__create_maps(struct evlist *evlist, struct target *target)
@@ -1089,14 +1070,14 @@ int perf_evlist__create_maps(struct evlist *evlist, struct target *target)
        if (target__uses_dummy_map(target))
                cpus = perf_cpu_map__dummy_new();
        else
-               cpus = cpu_map__new(target->cpu_list);
+               cpus = perf_cpu_map__new(target->cpu_list);
 
        if (!cpus)
                goto out_delete_threads;
 
-       evlist->has_user_cpus = !!target->cpu_list;
+       evlist->core.has_user_cpus = !!target->cpu_list;
 
-       perf_evlist__set_maps(evlist, cpus, threads);
+       perf_evlist__set_maps(&evlist->core, cpus, threads);
 
        return 0;
 
@@ -1105,29 +1086,6 @@ int perf_evlist__create_maps(struct evlist *evlist, struct target *target)
        return -1;
 }
 
-void perf_evlist__set_maps(struct evlist *evlist, struct perf_cpu_map *cpus,
-                          struct perf_thread_map *threads)
-{
-       /*
-        * Allow for the possibility that one or another of the maps isn't being
-        * changed i.e. don't put it.  Note we are assuming the maps that are
-        * being applied are brand new and evlist is taking ownership of the
-        * original reference count of 1.  If that is not the case it is up to
-        * the caller to increase the reference count.
-        */
-       if (cpus != evlist->cpus) {
-               perf_cpu_map__put(evlist->cpus);
-               evlist->cpus = perf_cpu_map__get(cpus);
-       }
-
-       if (threads != evlist->threads) {
-               perf_thread_map__put(evlist->threads);
-               evlist->threads = perf_thread_map__get(threads);
-       }
-
-       perf_evlist__propagate_maps(evlist);
-}
-
 void __perf_evlist__set_sample_bit(struct evlist *evlist,
                                   enum perf_event_sample_format bit)
 {
@@ -1159,7 +1117,7 @@ int perf_evlist__apply_filters(struct evlist *evlist, struct evsel **err_evsel)
                 * filters only work for tracepoint event, which doesn't have cpu limit.
                 * So evlist and evsel should always be same.
                 */
-               err = evsel__apply_filter(evsel, evsel->filter);
+               err = perf_evsel__apply_filter(&evsel->core, evsel->filter);
                if (err) {
                        *err_evsel = evsel;
                        break;
@@ -1175,7 +1133,7 @@ int perf_evlist__set_tp_filter(struct evlist *evlist, const char *filter)
        int err = 0;
 
        evlist__for_each_entry(evlist, evsel) {
-               if (evsel->attr.type != PERF_TYPE_TRACEPOINT)
+               if (evsel->core.attr.type != PERF_TYPE_TRACEPOINT)
                        continue;
 
                err = perf_evsel__set_filter(evsel, filter);
@@ -1222,7 +1180,7 @@ bool perf_evlist__valid_sample_type(struct evlist *evlist)
 {
        struct evsel *pos;
 
-       if (evlist->nr_entries == 1)
+       if (evlist->core.nr_entries == 1)
                return true;
 
        if (evlist->id_pos < 0 || evlist->is_pos < 0)
@@ -1245,7 +1203,7 @@ u64 __perf_evlist__combined_sample_type(struct evlist *evlist)
                return evlist->combined_sample_type;
 
        evlist__for_each_entry(evlist, evsel)
-               evlist->combined_sample_type |= evsel->attr.sample_type;
+               evlist->combined_sample_type |= evsel->core.attr.sample_type;
 
        return evlist->combined_sample_type;
 }
@@ -1262,18 +1220,18 @@ u64 perf_evlist__combined_branch_type(struct evlist *evlist)
        u64 branch_type = 0;
 
        evlist__for_each_entry(evlist, evsel)
-               branch_type |= evsel->attr.branch_sample_type;
+               branch_type |= evsel->core.attr.branch_sample_type;
        return branch_type;
 }
 
 bool perf_evlist__valid_read_format(struct evlist *evlist)
 {
        struct evsel *first = perf_evlist__first(evlist), *pos = first;
-       u64 read_format = first->attr.read_format;
-       u64 sample_type = first->attr.sample_type;
+       u64 read_format = first->core.attr.read_format;
+       u64 sample_type = first->core.attr.sample_type;
 
        evlist__for_each_entry(evlist, pos) {
-               if (read_format != pos->attr.read_format)
+               if (read_format != pos->core.attr.read_format)
                        return false;
        }
 
@@ -1289,7 +1247,7 @@ bool perf_evlist__valid_read_format(struct evlist *evlist)
 u64 perf_evlist__read_format(struct evlist *evlist)
 {
        struct evsel *first = perf_evlist__first(evlist);
-       return first->attr.read_format;
+       return first->core.attr.read_format;
 }
 
 u16 perf_evlist__id_hdr_size(struct evlist *evlist)
@@ -1299,10 +1257,10 @@ u16 perf_evlist__id_hdr_size(struct evlist *evlist)
        u64 sample_type;
        u16 size = 0;
 
-       if (!first->attr.sample_id_all)
+       if (!first->core.attr.sample_id_all)
                goto out;
 
-       sample_type = first->attr.sample_type;
+       sample_type = first->core.attr.sample_type;
 
        if (sample_type & PERF_SAMPLE_TID)
                size += sizeof(data->tid) * 2;
@@ -1330,7 +1288,7 @@ bool perf_evlist__valid_sample_id_all(struct evlist *evlist)
        struct evsel *first = perf_evlist__first(evlist), *pos = first;
 
        evlist__for_each_entry_continue(evlist, pos) {
-               if (first->attr.sample_id_all != pos->attr.sample_id_all)
+               if (first->core.attr.sample_id_all != pos->core.attr.sample_id_all)
                        return false;
        }
 
@@ -1340,7 +1298,7 @@ bool perf_evlist__valid_sample_id_all(struct evlist *evlist)
 bool perf_evlist__sample_id_all(struct evlist *evlist)
 {
        struct evsel *first = perf_evlist__first(evlist);
-       return first->attr.sample_id_all;
+       return first->core.attr.sample_id_all;
 }
 
 void perf_evlist__set_selected(struct evlist *evlist,
@@ -1354,7 +1312,7 @@ void evlist__close(struct evlist *evlist)
        struct evsel *evsel;
 
        evlist__for_each_entry_reverse(evlist, evsel)
-               perf_evsel__close(evsel);
+               evsel__close(evsel);
 }
 
 static int perf_evlist__create_syswide_maps(struct evlist *evlist)
@@ -1372,7 +1330,7 @@ static int perf_evlist__create_syswide_maps(struct evlist *evlist)
         * error, and we may not want to do that fallback to a
         * default cpu identity map :-\
         */
-       cpus = cpu_map__new(NULL);
+       cpus = perf_cpu_map__new(NULL);
        if (!cpus)
                goto out;
 
@@ -1380,7 +1338,7 @@ static int perf_evlist__create_syswide_maps(struct evlist *evlist)
        if (!threads)
                goto out_put;
 
-       perf_evlist__set_maps(evlist, cpus, threads);
+       perf_evlist__set_maps(&evlist->core, cpus, threads);
 out:
        return err;
 out_put:
@@ -1397,7 +1355,7 @@ int evlist__open(struct evlist *evlist)
         * Default: one fd per CPU, all threads, aka systemwide
         * as sys_perf_event_open(cpu = -1, thread = -1) is EINVAL
         */
-       if (evlist->threads == NULL && evlist->cpus == NULL) {
+       if (evlist->core.threads == NULL && evlist->core.cpus == NULL) {
                err = perf_evlist__create_syswide_maps(evlist);
                if (err < 0)
                        goto out_err;
@@ -1406,7 +1364,7 @@ int evlist__open(struct evlist *evlist)
        perf_evlist__update_id_pos(evlist);
 
        evlist__for_each_entry(evlist, evsel) {
-               err = evsel__open(evsel, evsel->cpus, evsel->threads);
+               err = evsel__open(evsel, evsel->core.cpus, evsel->core.threads);
                if (err < 0)
                        goto out_err;
        }
@@ -1500,12 +1458,12 @@ int perf_evlist__prepare_workload(struct evlist *evlist, struct target *target,
        }
 
        if (target__none(target)) {
-               if (evlist->threads == NULL) {
+               if (evlist->core.threads == NULL) {
                        fprintf(stderr, "FATAL: evlist->threads need to be set at this point (%s:%d).\n",
                                __func__, __LINE__);
                        goto out_close_pipes;
                }
-               perf_thread_map__set_pid(evlist->threads, 0, evlist->workload.pid);
+               perf_thread_map__set_pid(evlist->core.threads, 0, evlist->workload.pid);
        }
 
        close(child_ready_pipe[1]);
@@ -1620,14 +1578,14 @@ int perf_evlist__strerror_open(struct evlist *evlist,
                if (sysctl__read_int("kernel/perf_event_max_sample_rate", &max_freq) < 0)
                        goto out_default;
 
-               if (first->attr.sample_freq < (u64)max_freq)
+               if (first->core.attr.sample_freq < (u64)max_freq)
                        goto out_default;
 
                printed = scnprintf(buf, size,
                                    "Error:\t%s.\n"
                                    "Hint:\tCheck /proc/sys/kernel/perf_event_max_sample_rate.\n"
                                    "Hint:\tThe current value is %d and %" PRIu64 " is being requested.",
-                                   emsg, max_freq, first->attr.sample_freq);
+                                   emsg, max_freq, first->core.attr.sample_freq);
                break;
        }
        default:
@@ -1782,7 +1740,7 @@ bool perf_evlist__exclude_kernel(struct evlist *evlist)
        struct evsel *evsel;
 
        evlist__for_each_entry(evlist, evsel) {
-               if (!evsel->attr.exclude_kernel)
+               if (!evsel->core.attr.exclude_kernel)
                        return false;
        }
 
@@ -1812,7 +1770,7 @@ struct evsel *perf_evlist__reset_weak_group(struct evlist *evsel_list,
 
        leader = evsel->leader;
        pr_debug("Weak group for %s/%d failed\n",
-                       leader->name, leader->nr_members);
+                       leader->name, leader->core.nr_members);
 
        /*
         * for_each_group_member doesn't work here because it doesn't
@@ -1823,9 +1781,9 @@ struct evsel *perf_evlist__reset_weak_group(struct evlist *evsel_list,
                        is_open = false;
                if (c2->leader == leader) {
                        if (is_open)
-                               perf_evsel__close(c2);
+                               evsel__close(c2);
                        c2->leader = c2;
-                       c2->nr_members = 0;
+                       c2->core.nr_members = 0;
                }
        }
        return leader;
@@ -1849,7 +1807,7 @@ int perf_evlist__add_sb_event(struct evlist **evlist,
                attr->sample_id_all = 1;
        }
 
-       evsel = perf_evsel__new_idx(attr, (*evlist)->nr_entries);
+       evsel = perf_evsel__new_idx(attr, (*evlist)->core.nr_entries);
        if (!evsel)
                goto out_err;
 
@@ -1871,6 +1829,14 @@ static void *perf_evlist__poll_thread(void *arg)
        struct evlist *evlist = arg;
        bool draining = false;
        int i, done = 0;
+       /*
+        * In order to read symbols from other namespaces perf to needs to call
+        * setns(2).  This isn't permitted if the struct_fs has multiple users.
+        * unshare(2) the fs so that we may continue to setns into namespaces
+        * that we're observing when, for instance, reading the build-ids at
+        * the end of a 'perf record' session.
+        */
+       unshare(CLONE_FS);
 
        while (!done) {
                bool got_data = false;
@@ -1882,7 +1848,7 @@ static void *perf_evlist__poll_thread(void *arg)
                        perf_evlist__poll(evlist, 1000);
 
                for (i = 0; i < evlist->nr_mmaps; i++) {
-                       struct perf_mmap *map = &evlist->mmap[i];
+                       struct mmap *map = &evlist->mmap[i];
                        union perf_event *event;
 
                        if (perf_mmap__read_init(map))
@@ -1919,12 +1885,12 @@ int perf_evlist__start_sb_thread(struct evlist *evlist,
                goto out_delete_evlist;
 
        evlist__for_each_entry(evlist, counter) {
-               if (evsel__open(counter, evlist->cpus,
-                                    evlist->threads) < 0)
+               if (evsel__open(counter, evlist->core.cpus,
+                                    evlist->core.threads) < 0)
                        goto out_delete_evlist;
        }
 
-       if (perf_evlist__mmap(evlist, UINT_MAX))
+       if (evlist__mmap(evlist, UINT_MAX))
                goto out_delete_evlist;
 
        evlist__for_each_entry(evlist, counter) {