linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 1/9] perf thread_map: Skip exited threads when scanning /proc
@ 2023-12-01 23:50 Ian Rogers
  2023-12-01 23:50 ` [PATCH v1 2/9] perf list: Add scandirat compatibility function Ian Rogers
                   ` (7 more replies)
  0 siblings, 8 replies; 13+ messages in thread
From: Ian Rogers @ 2023-12-01 23:50 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	Ian Rogers, Adrian Hunter, Nathan Chancellor, Nick Desaulniers,
	Tom Rix, Ravi Bangoria, James Clark, Kan Liang, John Garry,
	linux-kernel, linux-perf-users, llvm

Scanning /proc is inherently racy. Scanning /proc/pid/task within that
is also racy as the pid can terminate. Rather than failing in
__thread_map__new_all_cpus, skip pids for such failures.

Signed-off-by: Ian Rogers <irogers@google.com>
---
 tools/perf/util/thread_map.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/tools/perf/util/thread_map.c b/tools/perf/util/thread_map.c
index e848579e61a8..18fbc41d09f3 100644
--- a/tools/perf/util/thread_map.c
+++ b/tools/perf/util/thread_map.c
@@ -109,9 +109,10 @@ static struct perf_thread_map *__thread_map__new_all_cpus(uid_t uid)
 
 		snprintf(path, sizeof(path), "/proc/%d/task", pid);
 		items = scandir(path, &namelist, filter, NULL);
-		if (items <= 0)
-			goto out_free_closedir;
-
+		if (items <= 0) {
+			pr_debug("scandir for %d returned empty, skipping\n", pid);
+			continue;
+		}
 		while (threads->nr + items >= max_threads) {
 			max_threads *= 2;
 			grow = true;
@@ -152,8 +153,6 @@ static struct perf_thread_map *__thread_map__new_all_cpus(uid_t uid)
 	for (i = 0; i < items; i++)
 		zfree(&namelist[i]);
 	free(namelist);
-
-out_free_closedir:
 	zfree(&threads);
 	goto out_closedir;
 }
-- 
2.43.0.rc2.451.g8631bc7472-goog


^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2023-12-04 21:14 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-01 23:50 [PATCH v1 1/9] perf thread_map: Skip exited threads when scanning /proc Ian Rogers
2023-12-01 23:50 ` [PATCH v1 2/9] perf list: Add scandirat compatibility function Ian Rogers
2023-12-01 23:50 ` [PATCH v1 3/9] perf tests: Avoid fork in perf_has_symbol test Ian Rogers
2023-12-04  6:54   ` Adrian Hunter
2023-12-01 23:50 ` [PATCH v1 4/9] tools subcmd: Add a no exec function call option Ian Rogers
2023-12-01 23:50 ` [PATCH v1 5/9] perf test: Rename builtin-test-list and add missed header guard Ian Rogers
2023-12-01 23:50 ` [PATCH v1 6/9] perf tests: Use scandirat for shell script finding Ian Rogers
2023-12-01 23:50 ` [PATCH v1 7/9] perf tests: Run time generate shell test suites Ian Rogers
2023-12-01 23:50 ` [PATCH v1 8/9] perf srcline: Add missed addr2line closes Ian Rogers
2023-12-01 23:50 ` [PATCH v1 9/9] perf tests: Add option to run tests in parallel Ian Rogers
2023-12-02  2:06   ` Ian Rogers
2023-12-04 20:30     ` Arnaldo Carvalho de Melo
2023-12-04 21:14       ` Ian Rogers

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).