perf evlist: Clarify sterror_mmap variable names
[firefly-linux-kernel-4.4.55.git] / tools / perf / util / evlist.c
index 3c9e77d6b4c2bf97b863d3ff75e2cc8f88a68e04..d661f252b8914b7b4ebebfe561fa6e4cd01b9cd7 100644 (file)
@@ -8,6 +8,7 @@
  */
 #include "util.h"
 #include <api/fs/debugfs.h>
+#include <api/fs/fs.h>
 #include <poll.h>
 #include "cpumap.h"
 #include "thread_map.h"
@@ -413,7 +414,7 @@ int perf_evlist__alloc_pollfd(struct perf_evlist *evlist)
        int nfds = 0;
        struct perf_evsel *evsel;
 
-       list_for_each_entry(evsel, &evlist->entries, node) {
+       evlist__for_each(evlist, evsel) {
                if (evsel->system_wide)
                        nfds += nr_cpus;
                else
@@ -527,6 +528,22 @@ static int perf_evlist__id_add_fd(struct perf_evlist *evlist,
        return 0;
 }
 
+static void perf_evlist__set_sid_idx(struct perf_evlist *evlist,
+                                    struct perf_evsel *evsel, int idx, int cpu,
+                                    int thread)
+{
+       struct perf_sample_id *sid = SID(evsel, cpu, thread);
+       sid->idx = idx;
+       if (evlist->cpus && cpu >= 0)
+               sid->cpu = evlist->cpus->map[cpu];
+       else
+               sid->cpu = -1;
+       if (!evsel->system_wide && evlist->threads && thread >= 0)
+               sid->tid = evlist->threads->map[thread];
+       else
+               sid->tid = -1;
+}
+
 struct perf_sample_id *perf_evlist__id2sid(struct perf_evlist *evlist, u64 id)
 {
        struct hlist_head *head;
@@ -800,14 +817,26 @@ static int perf_evlist__mmap_per_evsel(struct perf_evlist *evlist, int idx,
                        perf_evlist__mmap_get(evlist, idx);
                }
 
-               if (__perf_evlist__add_pollfd(evlist, fd, idx) < 0) {
+               /*
+                * The system_wide flag causes a selected event to be opened
+                * always without a pid.  Consequently it will never get a
+                * POLLHUP, but it is used for tracking in combination with
+                * other events, so it should not need to be polled anyway.
+                * Therefore don't add it for polling.
+                */
+               if (!evsel->system_wide &&
+                   __perf_evlist__add_pollfd(evlist, fd, idx) < 0) {
                        perf_evlist__mmap_put(evlist, idx);
                        return -1;
                }
 
-               if ((evsel->attr.read_format & PERF_FORMAT_ID) &&
-                   perf_evlist__id_add_fd(evlist, evsel, cpu, thread, fd) < 0)
-                       return -1;
+               if (evsel->attr.read_format & PERF_FORMAT_ID) {
+                       if (perf_evlist__id_add_fd(evlist, evsel, cpu, thread,
+                                                  fd) < 0)
+                               return -1;
+                       perf_evlist__set_sid_idx(evlist, evsel, idx, cpu,
+                                                thread);
+               }
        }
 
        return 0;
@@ -1455,6 +1484,28 @@ int perf_evlist__strerror_open(struct perf_evlist *evlist __maybe_unused,
        return 0;
 }
 
+int perf_evlist__strerror_mmap(struct perf_evlist *evlist, int err, char *buf, size_t size)
+{
+       char sbuf[STRERR_BUFSIZE], *emsg = strerror_r(err, sbuf, sizeof(sbuf));
+       int pages_attempted = evlist->mmap_len / 1024, pages_max_per_user;
+
+       switch (err) {
+       case EPERM:
+               sysctl__read_int("kernel/perf_event_mlock_kb", &pages_max_per_user);
+               scnprintf(buf, size, "Error:\t%s.\n"
+                                    "Hint:\tCheck /proc/sys/kernel/perf_event_mlock_kb (%d kB) setting.\n"
+                                    "Hint:\tTried using %zd kB.\n"
+                                    "Hint:\tTry using a smaller -m/--mmap-pages value.",
+                                    emsg, pages_max_per_user, pages_attempted);
+               break;
+       default:
+               scnprintf(buf, size, "%s", emsg);
+               break;
+       }
+
+       return 0;
+}
+
 void perf_evlist__to_front(struct perf_evlist *evlist,
                           struct perf_evsel *move_evsel)
 {