linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: linux-kernel@vger.kernel.org, Jiri Olsa <jolsa@redhat.com>,
	Jiri Olsa <jolsa@kernel.org>, David Ahern <dsahern@gmail.com>,
	Namhyung Kim <namhyung@kernel.org>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH 20/22] perf evsel: Allow to ignore missing pid
Date: Tue, 13 Dec 2016 12:09:26 -0300	[thread overview]
Message-ID: <20161213150928.13144-21-acme@kernel.org> (raw)
In-Reply-To: <20161213150928.13144-1-acme@kernel.org>

From: Jiri Olsa <jolsa@redhat.com>

Adding perf_evsel::ignore_missing_cpu_thread bool.

When set true, it allows perf to ignore error of missing pid of perf
event syscall.

We remove missing thread id from the thread_map, so the rest of the
processing like ioctl and mmap won't get disturbed with -1 fd.

The reason for supporting this is to ease up monitoring group of pids,
that 'disappear' before perf opens their event. This currently leads
perf to report error and exit and makes perf record's -u option unusable
under certain setup.

With this change we will allow this race and ignore such failure with
following warning:

  WARNING: Ignored open failure for pid 8605

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/20161213074622.GA3084@krava
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/perf.h       |  1 +
 tools/perf/util/evsel.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
 tools/perf/util/evsel.h |  1 +
 3 files changed, 46 insertions(+)

diff --git a/tools/perf/perf.h b/tools/perf/perf.h
index 9a0236a4cf95..1c27d947c2fe 100644
--- a/tools/perf/perf.h
+++ b/tools/perf/perf.h
@@ -55,6 +55,7 @@ struct record_opts {
 	bool	     all_user;
 	bool	     tail_synthesize;
 	bool	     overwrite;
+	bool	     ignore_missing_thread;
 	unsigned int freq;
 	unsigned int mmap_pages;
 	unsigned int auxtrace_mmap_pages;
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index fd61ebd77c26..04e536ae4d88 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -990,6 +990,8 @@ void perf_evsel__config(struct perf_evsel *evsel, struct record_opts *opts,
 	 * it overloads any global configuration.
 	 */
 	apply_config_terms(evsel, opts);
+
+	evsel->ignore_missing_thread = opts->ignore_missing_thread;
 }
 
 static int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads)
@@ -1419,6 +1421,33 @@ static int __open_attr__fprintf(FILE *fp, const char *name, const char *val,
 	return fprintf(fp, "  %-32s %s\n", name, val);
 }
 
+static bool ignore_missing_thread(struct perf_evsel *evsel,
+				  struct thread_map *threads,
+				  int thread, int err)
+{
+	if (!evsel->ignore_missing_thread)
+		return false;
+
+	/* The system wide setup does not work with threads. */
+	if (evsel->system_wide)
+		return false;
+
+	/* The -ESRCH is perf event syscall errno for pid's not found. */
+	if (err != -ESRCH)
+		return false;
+
+	/* If there's only one thread, let it fail. */
+	if (threads->nr == 1)
+		return false;
+
+	if (thread_map__remove(threads, thread))
+		return false;
+
+	pr_warning("WARNING: Ignored open failure for pid %d\n",
+		   thread_map__pid(threads, thread));
+	return true;
+}
+
 static int __perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus,
 			      struct thread_map *threads)
 {
@@ -1491,6 +1520,21 @@ static int __perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus,
 
 			if (fd < 0) {
 				err = -errno;
+
+				if (ignore_missing_thread(evsel, threads, thread, err)) {
+					/*
+					 * We just removed 1 thread, so take a step
+					 * back on thread index and lower the upper
+					 * nthreads limit.
+					 */
+					nthreads--;
+					thread--;
+
+					/* ... and pretend like nothing have happened. */
+					err = 0;
+					continue;
+				}
+
 				pr_debug2("\nsys_perf_event_open failed, error %d\n",
 					  err);
 				goto try_fallback;
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index 6abb89cd27f9..06ef6f29efa1 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -120,6 +120,7 @@ struct perf_evsel {
 	bool			tracking;
 	bool			per_pkg;
 	bool			precise_max;
+	bool			ignore_missing_thread;
 	/* parse modifier helper */
 	int			exclude_GH;
 	int			nr_members;
-- 
2.9.3

  parent reply	other threads:[~2016-12-13 15:13 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-13 15:09 [GIT PULL 00/22] perf/core improvements and fixes Arnaldo Carvalho de Melo
2016-12-13 15:09 ` [PATCH 01/22] perf tools: Move headers check into bash script Arnaldo Carvalho de Melo
2016-12-13 15:09 ` [PATCH 02/22] perf sched timehist: Split is_idle_sample() Arnaldo Carvalho de Melo
2016-12-13 15:09 ` [PATCH 03/22] perf sched timehist: Introduce struct idle_time_data Arnaldo Carvalho de Melo
2016-12-13 15:09 ` [PATCH 04/22] perf sched timehist: Save callchain when entering idle Arnaldo Carvalho de Melo
2016-12-13 15:09 ` [PATCH 05/22] perf sched timehist: Skip non-idle events when necessary Arnaldo Carvalho de Melo
2016-12-13 15:09 ` [PATCH 06/22] perf sched timehist: Add -I/--idle-hist option Arnaldo Carvalho de Melo
2016-12-13 15:09 ` [PATCH 07/22] perf sched timehist: Show callchains for idle stat Arnaldo Carvalho de Melo
2016-12-13 15:09 ` [PATCH 08/22] tools lib bpf: Sync {tools,}/include/uapi/linux/bpf.h Arnaldo Carvalho de Melo
2016-12-13 15:09 ` [PATCH 09/22] tools lib bpf: use __u32 from linux/types.h Arnaldo Carvalho de Melo
2016-12-13 15:09 ` [PATCH 10/22] tools lib bpf: Add flags to bpf_create_map() Arnaldo Carvalho de Melo
2016-12-13 15:09 ` [PATCH 11/22] samples/bpf: Make samples more libbpf-centric Arnaldo Carvalho de Melo
2016-12-13 15:09 ` [PATCH 12/22] samples/bpf: Switch over to libbpf Arnaldo Carvalho de Melo
2016-12-13 15:09 ` [PATCH 13/22] samples/bpf: Remove perf_event_open() declaration Arnaldo Carvalho de Melo
2016-12-13 15:09 ` [PATCH 14/22] samples/bpf: Move open_raw_sock to separate header Arnaldo Carvalho de Melo
2016-12-13 15:09 ` [PATCH 15/22] perf sdt: Add scanning of sdt probles arguments Arnaldo Carvalho de Melo
2016-12-13 15:09 ` [PATCH 16/22] perf tools: Remove some needless __maybe_unused Arnaldo Carvalho de Melo
2016-12-13 15:09 ` [PATCH 17/22] perf mem: Fix --all-user/--all-kernel options Arnaldo Carvalho de Melo
2016-12-13 15:09 ` [PATCH 18/22] perf evsel: Use variable instead of repeating lengthy FD macro Arnaldo Carvalho de Melo
2016-12-13 15:09 ` [PATCH 19/22] perf thread_map: Add thread_map__remove function Arnaldo Carvalho de Melo
2016-12-13 15:09 ` Arnaldo Carvalho de Melo [this message]
2016-12-13 15:09 ` [PATCH 21/22] perf record: Force ignore_missing_thread for uid option Arnaldo Carvalho de Melo
2016-12-13 15:09 ` [PATCH 22/22] samples/bpf: Drop unnecessary build targets Arnaldo Carvalho de Melo

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=20161213150928.13144-21-acme@kernel.org \
    --to=acme@kernel.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@redhat.com \
    --cc=dsahern@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    /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).