Linux Perf Users
 help / color / mirror / Atom feed
* [PATCH] perf record: Do not fail with an exiting thread
@ 2026-11-11 19:23 Namhyung Kim
  2026-11-11 19:54 ` sashiko-bot
  2026-11-12  0:40 ` Ian Rogers
  0 siblings, 2 replies; 3+ messages in thread
From: Namhyung Kim @ 2026-11-11 19:23 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Ian Rogers, Jiri Olsa, Adrian Hunter, James Clark, Peter Zijlstra,
	Ingo Molnar, LKML, linux-perf-users

When a thread in the target process exits during the synthesize, it
can fail due to the missing /proc entry.  So __perf_event__synthesize_
thread() ignores the return value of __event__synthesize_thread().

Do the same in the perf_event__synthesize_thread_map() too.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/util/synthetic-events.c | 26 ++++++++++++++++----------
 1 file changed, 16 insertions(+), 10 deletions(-)

diff --git a/tools/perf/util/synthetic-events.c b/tools/perf/util/synthetic-events.c
index b9dbd105cdc37f38..3c8d29f27fd91a2c 100644
--- a/tools/perf/util/synthetic-events.c
+++ b/tools/perf/util/synthetic-events.c
@@ -991,6 +991,7 @@ int perf_event__synthesize_thread_map(const struct perf_tool *tool,
 	union perf_event *comm_event, *mmap_event, *fork_event;
 	union perf_event *namespaces_event;
 	int err = -1, thread, j;
+	int synthesized = 0;
 
 	comm_event = malloc(sizeof(comm_event->comm) + machine->id_hdr_size);
 	if (comm_event == NULL)
@@ -1010,16 +1011,19 @@ int perf_event__synthesize_thread_map(const struct perf_tool *tool,
 	if (namespaces_event == NULL)
 		goto out_free_fork;
 
-	err = 0;
 	for (thread = 0; thread < threads->nr; ++thread) {
+		/*
+		 * We may race with exiting thread, so don't stop just because
+		 * one thread couldn't be synthesized.
+		 */
 		if (__event__synthesize_thread(comm_event, mmap_event,
 					       fork_event, namespaces_event,
 					       perf_thread_map__pid(threads, thread), 0,
 					       process, tool, machine,
-					       needs_mmap, mmap_data)) {
-			err = -1;
-			break;
-		}
+					       needs_mmap, mmap_data))
+			continue;
+
+		synthesized++;
 
 		/*
 		 * comm.pid is set to thread group id by
@@ -1037,17 +1041,19 @@ int perf_event__synthesize_thread_map(const struct perf_tool *tool,
 			}
 
 			/* if not, generate events for it */
-			if (need_leader &&
-			    __event__synthesize_thread(comm_event, mmap_event,
+			if (need_leader) {
+				__event__synthesize_thread(comm_event, mmap_event,
 						       fork_event, namespaces_event,
 						       comm_event->comm.pid, 0,
 						       process, tool, machine,
-						       needs_mmap, mmap_data)) {
-				err = -1;
-				break;
+						       needs_mmap, mmap_data);
 			}
 		}
 	}
+
+	if (synthesized)
+		err = 0;
+
 	free(namespaces_event);
 out_free_fork:
 	free(fork_event);
-- 
2.56.0.567.gdb80ae8cd5-goog


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

* Re: [PATCH] perf record: Do not fail with an exiting thread
  2026-11-11 19:23 [PATCH] perf record: Do not fail with an exiting thread Namhyung Kim
@ 2026-11-11 19:54 ` sashiko-bot
  2026-11-12  0:40 ` Ian Rogers
  1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-11-11 19:54 UTC (permalink / raw)
  To: Namhyung Kim; +Cc: linux-perf-users

> When a thread in the target process exits during the synthesize, it
> can fail due to the missing /proc entry.  So __perf_event__synthesize_
> thread() ignores the return value of __event__synthesize_thread().
> 
> Do the same in the perf_event__synthesize_thread_map() too.
> 
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261111192328.3917311-1-namhyung@kernel.org?part=1


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

* Re: [PATCH] perf record: Do not fail with an exiting thread
  2026-11-11 19:23 [PATCH] perf record: Do not fail with an exiting thread Namhyung Kim
  2026-11-11 19:54 ` sashiko-bot
@ 2026-11-12  0:40 ` Ian Rogers
  1 sibling, 0 replies; 3+ messages in thread
From: Ian Rogers @ 2026-11-12  0:40 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: Arnaldo Carvalho de Melo, Jiri Olsa, Adrian Hunter, James Clark,
	Peter Zijlstra, Ingo Molnar, LKML, linux-perf-users

On Wed, Nov 11, 2026 at 11:23 AM Namhyung Kim <namhyung@kernel.org> wrote:
>
> When a thread in the target process exits during the synthesize, it
> can fail due to the missing /proc entry.  So __perf_event__synthesize_
> thread() ignores the return value of __event__synthesize_thread().
>
> Do the same in the perf_event__synthesize_thread_map() too.
>
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>

Reviewed-by: Ian Rogers <irogers@google.com>

Thanks,
Ian

> ---
>  tools/perf/util/synthetic-events.c | 26 ++++++++++++++++----------
>  1 file changed, 16 insertions(+), 10 deletions(-)
>
> diff --git a/tools/perf/util/synthetic-events.c b/tools/perf/util/synthetic-events.c
> index b9dbd105cdc37f38..3c8d29f27fd91a2c 100644
> --- a/tools/perf/util/synthetic-events.c
> +++ b/tools/perf/util/synthetic-events.c
> @@ -991,6 +991,7 @@ int perf_event__synthesize_thread_map(const struct perf_tool *tool,
>         union perf_event *comm_event, *mmap_event, *fork_event;
>         union perf_event *namespaces_event;
>         int err = -1, thread, j;
> +       int synthesized = 0;
>
>         comm_event = malloc(sizeof(comm_event->comm) + machine->id_hdr_size);
>         if (comm_event == NULL)
> @@ -1010,16 +1011,19 @@ int perf_event__synthesize_thread_map(const struct perf_tool *tool,
>         if (namespaces_event == NULL)
>                 goto out_free_fork;
>
> -       err = 0;
>         for (thread = 0; thread < threads->nr; ++thread) {
> +               /*
> +                * We may race with exiting thread, so don't stop just because
> +                * one thread couldn't be synthesized.
> +                */
>                 if (__event__synthesize_thread(comm_event, mmap_event,
>                                                fork_event, namespaces_event,
>                                                perf_thread_map__pid(threads, thread), 0,
>                                                process, tool, machine,
> -                                              needs_mmap, mmap_data)) {
> -                       err = -1;
> -                       break;
> -               }
> +                                              needs_mmap, mmap_data))
> +                       continue;
> +
> +               synthesized++;
>
>                 /*
>                  * comm.pid is set to thread group id by
> @@ -1037,17 +1041,19 @@ int perf_event__synthesize_thread_map(const struct perf_tool *tool,
>                         }
>
>                         /* if not, generate events for it */
> -                       if (need_leader &&
> -                           __event__synthesize_thread(comm_event, mmap_event,
> +                       if (need_leader) {
> +                               __event__synthesize_thread(comm_event, mmap_event,
>                                                        fork_event, namespaces_event,
>                                                        comm_event->comm.pid, 0,
>                                                        process, tool, machine,
> -                                                      needs_mmap, mmap_data)) {
> -                               err = -1;
> -                               break;
> +                                                      needs_mmap, mmap_data);
>                         }
>                 }
>         }
> +
> +       if (synthesized)
> +               err = 0;
> +
>         free(namespaces_event);
>  out_free_fork:
>         free(fork_event);
> --
> 2.56.0.567.gdb80ae8cd5-goog
>

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

end of thread, other threads:[~2026-11-12  0:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-11 19:23 [PATCH] perf record: Do not fail with an exiting thread Namhyung Kim
2026-11-11 19:54 ` sashiko-bot
2026-11-12  0:40 ` Ian Rogers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox