Patch "perf evsel: Enable ignore_missing_thread for pid option" has been added to the 4.14-stable tree
Subsystems (2)
This is a note to let you know that I've just added the patch titled
perf evsel: Enable ignore_missing_thread for pid option
to the 4.14-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
perf-evsel-enable-ignore_missing_thread-for-pid-option.patch
and it can be found in the queue-4.14 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
Quoted 1 line
From foo@baz Mon Apr 9 13:58:16 CEST 2018
From: Mengting Zhang <[email protected]>
Date: Wed, 13 Dec 2017 15:01:53 +0800
Subject: perf evsel: Enable ignore_missing_thread for pid option
From: Mengting Zhang <[email protected]>
[ Upstream commit ca8000684ec4e66f965e1f9547a3c6cb834154ca ]
While monitoring a multithread process with pid option, perf sometimes may return sys_perf_event_open failure with 3(No such process) if any of the process's threads die before we open the event. However, we want perf continue monitoring the remaining threads and do not exit with error.
Here, the patch enables perf_evsel::ignore_missing_thread for -p option to ignore complete failure if any of threads die before we open the event. But it may still return sys_perf_event_open failure with 22(Invalid) if we monitors several event groups.
sys_perf_event_open: pid 28960 cpu 40 group_fd 118202 flags 0x8
sys_perf_event_open: pid 28961 cpu 40 group_fd 118203 flags 0x8 WARNING: Ignored open failure for pid 28962
sys_perf_event_open: pid 28962 cpu 40 group_fd [118203] flags 0x8 sys_perf_event_open failed, error -22
That is because when we ignore a missing thread, we change the thread_idx without dealing with its fds, FD(evsel, cpu, thread). Then get_group_fd() may return a wrong group_fd for the next thread and sys_perf_event_open() return with 22.
sys_perf_event_open(){
...
if (group_fd != -1)
perf_fget_light()//to get corresponding group_leader by group_fd
...
if (group_leader)
if (group_leader->ctx->task != ctx->task)//should on the same task
goto err_context
...
}This patch also fixes this bug by introducing perf_evsel__remove_fd() and update_fds to allow removing fds for the missing thread.
Changes since v1:
- Change group_fd__remove() into a more genetic way without changing code logic
- Remove redundant condition
Changes since v2:
- Use a proper function name and add some comment.
- Multiline comment style fixes.
Committer testing:
Before this patch the recently added 'perf stat --per-thread' for system wide counting would race while enumerating all threads using /proc:
[root@jouet ~]# perf stat --per-thread failed to parse CPUs map: No such file or directory
Usage: perf stat [<options>] [<command>]
-C, --cpu <cpu> list of cpus to monitor in system-wide
-a, --all-cpus system-wide collection from all CPUs
[root@jouet ~]# perf stat --per-thread failed to parse CPUs map: No such file or directory
Usage: perf stat [<options>] [<command>]
-C, --cpu <cpu> list of cpus to monitor in system-wide
-a, --all-cpus system-wide collection from all CPUs
[root@jouet ~]#
When, say, the kernel was being built, so lots of shortlived threads, after this patch this doesn't happen.
--- tools/perf/builtin-record.c | 4 +-- tools/perf/util/evsel.c | 47 ++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 47 insertions(+), 4 deletions(-)
tools/perf/builtin-record.c +2 -2
@@ -1856,8 +1856,8 @@ int cmd_record(int argc, const char **ar goto out; } -/* Enable ignoring missing threads when -u option is defined. */ - rec->opts.ignore_missing_thread = rec->opts.target.uid !=UINT_MAX ; +/* Enable ignoring missing threads when -u/-p option is defined. */ + rec->opts.ignore_missing_thread = rec->opts.target.uid !=UINT_MAX || rec->opts.target.pid; err = -ENOMEM ;if (perf_evlist__create_maps (rec->evlist, &rec->opts.target) <0 )
tools/perf/util/evsel.c +45 -2
73 lines not on this page · raw message
Patches currently in stable-queue which might be from [email protected] are
queue-4.14/perf-evsel-enable-ignore_missing_thread-for-pid-option.patch