From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751823AbeAPNGU (ORCPT + 1 other); Tue, 16 Jan 2018 08:06:20 -0500 Received: from mga09.intel.com ([134.134.136.24]:28794 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751131AbeAPNGT (ORCPT ); Tue, 16 Jan 2018 08:06:19 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,368,1511856000"; d="scan'208";a="11341882" Subject: Re: [PATCH] perf stat: Ignore error thread when enabling system-wide --per-thread To: Jiri Olsa Cc: acme@kernel.org, jolsa@kernel.org, peterz@infradead.org, mingo@redhat.com, alexander.shishkin@linux.intel.com, Linux-kernel@vger.kernel.org, ak@linux.intel.com, kan.liang@intel.com, yao.jin@intel.com References: <1516117388-10120-1-git-send-email-yao.jin@linux.intel.com> <20180116125132.GD26643@krava> From: "Jin, Yao" Message-ID: <1189ec53-0d3b-c59c-63f0-4c4ad0d72405@linux.intel.com> Date: Tue, 16 Jan 2018 21:06:09 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 In-Reply-To: <20180116125132.GD26643@krava> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: Just tested. But looks it's not OK for '--per-thread' case. jinyao@skl:~/$ ./perf stat --per-thread WARNING: Ignored open failure for pid 1 WARNING: Ignored open failure for pid 2 WARNING: Ignored open failure for pid 4 WARNING: Ignored open failure for pid 6 WARNING: Ignored open failure for pid 7 WARNING: Ignored open failure for pid 8 WARNING: Ignored open failure for pid 9 WARNING: Ignored open failure for pid 10 ...... WARNING: Ignored open failure for pid 11783 WARNING: Ignored open failure for pid 12275 WARNING: Ignored open failure for pid 31733 WARNING: Ignored open failure for pid 31737 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 Thanks Jin Yao On 1/16/2018 8:51 PM, Jiri Olsa wrote: > On Tue, Jan 16, 2018 at 11:43:08PM +0800, Jin Yao wrote: >> 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 > > could we use the existing code like in attached patch? > > we might also swap following warning for some generic one: > WARNING: Ignored open failure for pid 28392 > > jirka > > > --- > diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c > index 98bf9d32f222..f9d4d3ad6fc5 100644 > --- a/tools/perf/builtin-stat.c > +++ b/tools/perf/builtin-stat.c > @@ -276,6 +276,9 @@ static int create_perf_stat_counter(struct perf_evsel *evsel) > attr->enable_on_exec = 1; > } > > + if (stat_config.aggr_mode == AGGR_THREAD) > + evsel->ignore_missing_thread = true; > + > if (target__has_cpu(&target) && !target__has_per_thread(&target)) > return perf_evsel__open_per_cpu(evsel, perf_evsel__cpus(evsel)); > > diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c > index 8f971a2301d1..509ee175bc97 100644 > --- a/tools/perf/util/evsel.c > +++ b/tools/perf/util/evsel.c > @@ -1656,7 +1656,7 @@ static bool ignore_missing_thread(struct perf_evsel *evsel, > return false; > > /* The -ESRCH is perf event syscall errno for pid's not found. */ > - if (err != -ESRCH) > + if (err != -ESRCH && err != -EACCES) > return false; > > /* If there's only one thread, let it fail. */ >