Merge branch 'linus' into x86/urgent
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / tools / perf / util / evlist.c
index 95b21fece2cefe1ac7c513a7351f37dbb0abd4be..d852cefa20def5ff48665e7ef44bc842093f6f49 100644 (file)
@@ -19,7 +19,7 @@
 #include <linux/hash.h>
 
 #define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y))
-#define SID(e, x, y) xyarray__entry(e->id, x, y)
+#define SID(e, x, y) xyarray__entry(e->sample_id, x, y)
 
 void perf_evlist__init(struct perf_evlist *evlist, struct cpu_map *cpus,
                       struct thread_map *threads)
@@ -106,12 +106,32 @@ void perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd)
        evlist->nr_fds++;
 }
 
-static int perf_evlist__id_hash(struct perf_evlist *evlist, struct perf_evsel *evsel,
-                              int cpu, int thread, int fd)
+static void perf_evlist__id_hash(struct perf_evlist *evlist,
+                                struct perf_evsel *evsel,
+                                int cpu, int thread, u64 id)
+{
+       int hash;
+       struct perf_sample_id *sid = SID(evsel, cpu, thread);
+
+       sid->id = id;
+       sid->evsel = evsel;
+       hash = hash_64(sid->id, PERF_EVLIST__HLIST_BITS);
+       hlist_add_head(&sid->node, &evlist->heads[hash]);
+}
+
+void perf_evlist__id_add(struct perf_evlist *evlist, struct perf_evsel *evsel,
+                        int cpu, int thread, u64 id)
+{
+       perf_evlist__id_hash(evlist, evsel, cpu, thread, id);
+       evsel->id[evsel->ids++] = id;
+}
+
+static int perf_evlist__id_add_fd(struct perf_evlist *evlist,
+                                 struct perf_evsel *evsel,
+                                 int cpu, int thread, int fd)
 {
-       struct perf_sample_id *sid;
        u64 read_data[4] = { 0, };
-       int hash, id_idx = 1; /* The first entry is the counter value */
+       int id_idx = 1; /* The first entry is the counter value */
 
        if (!(evsel->attr.read_format & PERF_FORMAT_ID) ||
            read(fd, &read_data, sizeof(read_data)) == -1)
@@ -122,11 +142,7 @@ static int perf_evlist__id_hash(struct perf_evlist *evlist, struct perf_evsel *e
        if (evsel->attr.read_format & PERF_FORMAT_TOTAL_TIME_RUNNING)
                ++id_idx;
 
-       sid = SID(evsel, cpu, thread);
-       sid->id = read_data[id_idx];
-       sid->evsel = evsel;
-       hash = hash_64(sid->id, PERF_EVLIST__HLIST_BITS);
-       hlist_add_head(&sid->node, &evlist->heads[hash]);
+       perf_evlist__id_add(evlist, evsel, cpu, thread, read_data[id_idx]);
        return 0;
 }
 
@@ -284,7 +300,7 @@ int perf_evlist__mmap(struct perf_evlist *evlist, int pages, bool overwrite)
 
        list_for_each_entry(evsel, &evlist->entries, node) {
                if ((evsel->attr.read_format & PERF_FORMAT_ID) &&
-                   evsel->id == NULL &&
+                   evsel->sample_id == NULL &&
                    perf_evsel__alloc_id(evsel, cpus->nr, threads->nr) < 0)
                        return -ENOMEM;
 
@@ -300,7 +316,7 @@ int perf_evlist__mmap(struct perf_evlist *evlist, int pages, bool overwrite)
                                        goto out_unmap;
 
                                if ((evsel->attr.read_format & PERF_FORMAT_ID) &&
-                                   perf_evlist__id_hash(evlist, evsel, cpu, thread, fd) < 0)
+                                   perf_evlist__id_add_fd(evlist, evsel, cpu, thread, fd) < 0)
                                        goto out_unmap;
                        }
                }
@@ -348,3 +364,31 @@ void perf_evlist__delete_maps(struct perf_evlist *evlist)
        evlist->cpus    = NULL;
        evlist->threads = NULL;
 }
+
+int perf_evlist__set_filters(struct perf_evlist *evlist)
+{
+       const struct thread_map *threads = evlist->threads;
+       const struct cpu_map *cpus = evlist->cpus;
+       struct perf_evsel *evsel;
+       char *filter;
+       int thread;
+       int cpu;
+       int err;
+       int fd;
+
+       list_for_each_entry(evsel, &evlist->entries, node) {
+               filter = evsel->filter;
+               if (!filter)
+                       continue;
+               for (cpu = 0; cpu < cpus->nr; cpu++) {
+                       for (thread = 0; thread < threads->nr; thread++) {
+                               fd = FD(evsel, cpu, thread);
+                               err = ioctl(fd, PERF_EVENT_IOC_SET_FILTER, filter);
+                               if (err)
+                                       return err;
+                       }
+               }
+       }
+
+       return 0;
+}