From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
Jin Yao <yao.jin@linux.intel.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Andi Kleen <ak@linux.intel.com>, Kan Liang <kan.liang@intel.com>,
Peter Zijlstra <peterz@infradead.org>,
Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH 05/28] perf stat: Ignore error thread when enabling system-wide --per-thread
Date: Mon, 5 Mar 2018 11:29:09 -0300 [thread overview]
Message-ID: <20180305142932.16921-6-acme@kernel.org> (raw)
In-Reply-To: <20180305142932.16921-1-acme@kernel.org>
From: Jin Yao <yao.jin@linux.intel.com>
If we execute 'perf stat --per-thread' with non-root account (even set
kernel.perf_event_paranoid = -1 yet), it reports the error:
jinyao@skl:~$ perf stat --per-thread
Error:
You may not have permission to collect system-wide stats.
Consider tweaking /proc/sys/kernel/perf_event_paranoid,
which controls use of the performance events system by
unprivileged users (without CAP_SYS_ADMIN).
The current value is 2:
-1: Allow use of (almost) all events by all users
Ignore mlock limit after perf_event_mlock_kb without CAP_IPC_LOCK
>= 0: Disallow ftrace function tracepoint by users without CAP_SYS_ADMIN
Disallow raw tracepoint access by users without CAP_SYS_ADMIN
>= 1: Disallow CPU event access by users without CAP_SYS_ADMIN
>= 2: Disallow kernel profiling by users without CAP_SYS_ADMIN
To make this setting permanent, edit /etc/sysctl.conf too, e.g.:
kernel.perf_event_paranoid = -1
Perhaps the ptrace rule doesn't allow to trace some processes. But anyway
the global --per-thread mode had better ignore such errors and continue
working on other threads.
This patch will record the index of error thread in perf_evsel__open()
and remove this thread before retrying.
For example (run with non-root, kernel.perf_event_paranoid isn't set):
jinyao@skl:~$ perf stat --per-thread
^C
Performance counter stats for 'system wide':
vmstat-3458 6.171984 cpu-clock:u (msec) # 0.000 CPUs utilized
perf-3670 0.515599 cpu-clock:u (msec) # 0.000 CPUs utilized
vmstat-3458 1,163,643 cycles:u # 0.189 GHz
perf-3670 40,881 cycles:u # 0.079 GHz
vmstat-3458 1,410,238 instructions:u # 1.21 insn per cycle
perf-3670 3,536 instructions:u # 0.09 insn per cycle
vmstat-3458 288,937 branches:u # 46.814 M/sec
perf-3670 936 branches:u # 1.815 M/sec
vmstat-3458 15,195 branch-misses:u # 5.26% of all branches
perf-3670 76 branch-misses:u # 8.12% of all branches
12.651675247 seconds time elapsed
Signed-off-by: Jin Yao <yao.jin@linux.intel.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Kan Liang <kan.liang@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/1516117388-10120-1-git-send-email-yao.jin@linux.intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/builtin-stat.c | 14 +++++++++++++-
tools/perf/util/evsel.c | 3 +++
tools/perf/util/thread_map.c | 1 +
tools/perf/util/thread_map.h | 1 +
4 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index fadcff52cd09..6214d2b220b2 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -637,7 +637,19 @@ static int __run_perf_stat(int argc, const char **argv)
if (verbose > 0)
ui__warning("%s\n", msg);
goto try_again;
- }
+ } else if (target__has_per_thread(&target) &&
+ evsel_list->threads &&
+ evsel_list->threads->err_thread != -1) {
+ /*
+ * For global --per-thread case, skip current
+ * error thread.
+ */
+ if (!thread_map__remove(evsel_list->threads,
+ evsel_list->threads->err_thread)) {
+ evsel_list->threads->err_thread = -1;
+ goto try_again;
+ }
+ }
perf_evsel__open_strerror(counter, &target,
errno, msg, sizeof(msg));
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index ef351688b797..b56e1c2ddaee 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -1915,6 +1915,9 @@ int perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus,
goto fallback_missing_features;
}
out_close:
+ if (err)
+ threads->err_thread = thread;
+
do {
while (--thread >= 0) {
close(FD(evsel, cpu, thread));
diff --git a/tools/perf/util/thread_map.c b/tools/perf/util/thread_map.c
index 729dad8f412d..5d467d8ae9ab 100644
--- a/tools/perf/util/thread_map.c
+++ b/tools/perf/util/thread_map.c
@@ -32,6 +32,7 @@ static void thread_map__reset(struct thread_map *map, int start, int nr)
size_t size = (nr - start) * sizeof(map->map[0]);
memset(&map->map[start], 0, size);
+ map->err_thread = -1;
}
static struct thread_map *thread_map__realloc(struct thread_map *map, int nr)
diff --git a/tools/perf/util/thread_map.h b/tools/perf/util/thread_map.h
index 5ec91cfd1869..2f689c90a8c6 100644
--- a/tools/perf/util/thread_map.h
+++ b/tools/perf/util/thread_map.h
@@ -14,6 +14,7 @@ struct thread_map_data {
struct thread_map {
refcount_t refcnt;
int nr;
+ int err_thread;
struct thread_map_data map[];
};
--
2.14.3
next prev parent reply other threads:[~2018-03-05 14:29 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-05 14:29 [GIT PULL 00/28] perf/core improvements and fixes Arnaldo Carvalho de Melo
2018-03-05 14:29 ` [PATCH 01/28] perf kallsyms: Fix the usage on the man page Arnaldo Carvalho de Melo
2018-03-05 14:29 ` [PATCH 02/28] perf stat: Use xyarray dimensions to iterate fds Arnaldo Carvalho de Melo
2018-03-05 14:29 ` [PATCH 03/28] perf cgroup: Simplify arguments when tracking multiple events Arnaldo Carvalho de Melo
2018-03-05 14:29 ` [PATCH 04/28] perf top: Fix annoying fallback message on older kernels Arnaldo Carvalho de Melo
2018-03-05 14:29 ` Arnaldo Carvalho de Melo [this message]
2018-03-05 14:29 ` [PATCH 06/28] perf annotate browser: Be more robust when drawing jump arrows Arnaldo Carvalho de Melo
2018-03-05 14:29 ` [PATCH 07/28] perf tests: Switch trace+probe_libc_inet_pton to use record Arnaldo Carvalho de Melo
2018-03-05 14:29 ` [PATCH 08/28] perf tests: Rename trace+probe_libc_inet_pton to record+probe_libc_inet_pton Arnaldo Carvalho de Melo
2018-03-05 14:29 ` [PATCH 09/28] perf record: Allow asking for the maximum allowed sample rate Arnaldo Carvalho de Melo
2018-03-05 14:29 ` [PATCH 10/28] perf top browser: Show sample_freq in browser title line Arnaldo Carvalho de Melo
2018-03-05 14:29 ` [PATCH 11/28] perf top: Allow asking for the maximum allowed sample rate Arnaldo Carvalho de Melo
2018-03-05 14:29 ` [PATCH 12/28] perf record: Throttle user defined frequencies to the maximum allowed Arnaldo Carvalho de Melo
2018-03-05 14:29 ` [PATCH 13/28] perf annotate: Find 'call' instruction target symbol at parsing time Arnaldo Carvalho de Melo
2018-03-05 14:29 ` [PATCH 14/28] perf record: Fix crash in pipe mode Arnaldo Carvalho de Melo
2018-03-05 14:29 ` [PATCH 15/28] perf kvm: Switch to new perf_mmap__read_event() interface Arnaldo Carvalho de Melo
2018-03-05 14:29 ` [PATCH 16/28] perf trace: " Arnaldo Carvalho de Melo
2018-03-05 14:29 ` [PATCH 17/28] perf python: " Arnaldo Carvalho de Melo
2018-03-05 14:29 ` [PATCH 18/28] perf test: Switch to new perf_mmap__read_event() interface for bpf Arnaldo Carvalho de Melo
2018-03-05 14:29 ` [PATCH 19/28] perf test: Switch to new perf_mmap__read_event() interface for 'code reading' test Arnaldo Carvalho de Melo
2018-03-05 14:29 ` [PATCH 20/28] perf test: Switch to new perf_mmap__read_event() interface for "keep tracking" test Arnaldo Carvalho de Melo
2018-03-05 14:29 ` [PATCH 21/28] perf test: Switch to new perf_mmap__read_event() interface for mmap-basic Arnaldo Carvalho de Melo
2018-03-05 14:29 ` [PATCH 22/28] perf test: Switch to new perf_mmap__read_event() interface for tp fields Arnaldo Carvalho de Melo
2018-03-05 14:29 ` [PATCH 23/28] perf test: Switch to new perf_mmap__read_event() interface for perf-record Arnaldo Carvalho de Melo
2018-03-05 14:29 ` [PATCH 24/28] perf test: Switch to new perf_mmap__read_event() interface for time-to-tsc Arnaldo Carvalho de Melo
2018-03-05 14:29 ` [PATCH 25/28] perf test: Switch to new perf_mmap__read_event() interface for sw-clock Arnaldo Carvalho de Melo
2018-03-05 14:29 ` [PATCH 26/28] perf test: Switch to new perf_mmap__read_event() interface for switch-tracking Arnaldo Carvalho de Melo
2018-03-05 14:29 ` [PATCH 27/28] perf test: Switch to new perf_mmap__read_event() interface for task-exit Arnaldo Carvalho de Melo
2018-03-05 14:29 ` [PATCH 28/28] perf mmap: Discard legacy interfaces for mmap read forward Arnaldo Carvalho de Melo
2018-03-06 6:35 ` [GIT PULL 00/28] perf/core improvements and fixes Ingo Molnar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180305142932.16921-6-acme@kernel.org \
--to=acme@kernel.org \
--cc=acme@redhat.com \
--cc=ak@linux.intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=kan.liang@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=yao.jin@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).