linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] perf tools: Don't sort the task scan result from /proc
@ 2022-07-01 20:54 Namhyung Kim
  2022-07-01 20:54 ` [PATCH 2/2] perf tools: Ignore dead threads during event synthesis Namhyung Kim
  2022-07-01 23:06 ` [PATCH 1/2] perf tools: Don't sort the task scan result from /proc Ian Rogers
  0 siblings, 2 replies; 4+ messages in thread
From: Namhyung Kim @ 2022-07-01 20:54 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Jiri Olsa
  Cc: Ingo Molnar, Peter Zijlstra, LKML, Ian Rogers, linux-perf-users

It should not sort the result as procfs already returns a proper
ordering of tasks.  Actually sorting the order caused problems that it
doesn't guararantee to process the main thread first.

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

diff --git a/tools/perf/util/synthetic-events.c b/tools/perf/util/synthetic-events.c
index 27acdc5e5723..a068f42833c3 100644
--- a/tools/perf/util/synthetic-events.c
+++ b/tools/perf/util/synthetic-events.c
@@ -754,7 +754,7 @@ static int __event__synthesize_thread(union perf_event *comm_event,
 	snprintf(filename, sizeof(filename), "%s/proc/%d/task",
 		 machine->root_dir, pid);
 
-	n = scandir(filename, &dirent, filter_task, alphasort);
+	n = scandir(filename, &dirent, filter_task, NULL);
 	if (n < 0)
 		return n;
 
@@ -987,7 +987,7 @@ int perf_event__synthesize_threads(struct perf_tool *tool,
 		return 0;
 
 	snprintf(proc_path, sizeof(proc_path), "%s/proc", machine->root_dir);
-	n = scandir(proc_path, &dirent, filter_task, alphasort);
+	n = scandir(proc_path, &dirent, filter_task, NULL);
 	if (n < 0)
 		return err;
 
-- 
2.37.0.rc0.161.g10f37bed90-goog


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

* [PATCH 2/2] perf tools: Ignore dead threads during event synthesis
  2022-07-01 20:54 [PATCH 1/2] perf tools: Don't sort the task scan result from /proc Namhyung Kim
@ 2022-07-01 20:54 ` Namhyung Kim
  2022-07-01 23:06   ` Ian Rogers
  2022-07-01 23:06 ` [PATCH 1/2] perf tools: Don't sort the task scan result from /proc Ian Rogers
  1 sibling, 1 reply; 4+ messages in thread
From: Namhyung Kim @ 2022-07-01 20:54 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Jiri Olsa
  Cc: Ingo Molnar, Peter Zijlstra, LKML, Ian Rogers, linux-perf-users

When it synthesize various task events, it scans the list of task
first and then accesses later.  There's a window threads can die
between the two and proc entries may not be available.

Instead of bailing out, we can ignore that thread and move on.

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

diff --git a/tools/perf/util/synthetic-events.c b/tools/perf/util/synthetic-events.c
index a068f42833c3..84d17bd4efae 100644
--- a/tools/perf/util/synthetic-events.c
+++ b/tools/perf/util/synthetic-events.c
@@ -767,11 +767,12 @@ static int __event__synthesize_thread(union perf_event *comm_event,
 		if (*end)
 			continue;
 
-		rc = -1;
+		/* some threads may exit just after scan, ignore it */
 		if (perf_event__prepare_comm(comm_event, pid, _pid, machine,
 					     &tgid, &ppid, &kernel_thread) != 0)
-			break;
+			continue;
 
+		rc = -1;
 		if (perf_event__synthesize_fork(tool, fork_event, _pid, tgid,
 						ppid, process, machine) < 0)
 			break;
-- 
2.37.0.rc0.161.g10f37bed90-goog


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

* Re: [PATCH 1/2] perf tools: Don't sort the task scan result from /proc
  2022-07-01 20:54 [PATCH 1/2] perf tools: Don't sort the task scan result from /proc Namhyung Kim
  2022-07-01 20:54 ` [PATCH 2/2] perf tools: Ignore dead threads during event synthesis Namhyung Kim
@ 2022-07-01 23:06 ` Ian Rogers
  1 sibling, 0 replies; 4+ messages in thread
From: Ian Rogers @ 2022-07-01 23:06 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: Arnaldo Carvalho de Melo, Jiri Olsa, Ingo Molnar, Peter Zijlstra,
	LKML, linux-perf-users

On Fri, Jul 1, 2022 at 1:55 PM Namhyung Kim <namhyung@kernel.org> wrote:
>
> It should not sort the result as procfs already returns a proper
> ordering of tasks.  Actually sorting the order caused problems that it
> doesn't guararantee to process the main thread first.
>
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>

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

Thanks,
Ian

> ---
>  tools/perf/util/synthetic-events.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/tools/perf/util/synthetic-events.c b/tools/perf/util/synthetic-events.c
> index 27acdc5e5723..a068f42833c3 100644
> --- a/tools/perf/util/synthetic-events.c
> +++ b/tools/perf/util/synthetic-events.c
> @@ -754,7 +754,7 @@ static int __event__synthesize_thread(union perf_event *comm_event,
>         snprintf(filename, sizeof(filename), "%s/proc/%d/task",
>                  machine->root_dir, pid);
>
> -       n = scandir(filename, &dirent, filter_task, alphasort);
> +       n = scandir(filename, &dirent, filter_task, NULL);
>         if (n < 0)
>                 return n;
>
> @@ -987,7 +987,7 @@ int perf_event__synthesize_threads(struct perf_tool *tool,
>                 return 0;
>
>         snprintf(proc_path, sizeof(proc_path), "%s/proc", machine->root_dir);
> -       n = scandir(proc_path, &dirent, filter_task, alphasort);
> +       n = scandir(proc_path, &dirent, filter_task, NULL);
>         if (n < 0)
>                 return err;
>
> --
> 2.37.0.rc0.161.g10f37bed90-goog
>

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

* Re: [PATCH 2/2] perf tools: Ignore dead threads during event synthesis
  2022-07-01 20:54 ` [PATCH 2/2] perf tools: Ignore dead threads during event synthesis Namhyung Kim
@ 2022-07-01 23:06   ` Ian Rogers
  0 siblings, 0 replies; 4+ messages in thread
From: Ian Rogers @ 2022-07-01 23:06 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: Arnaldo Carvalho de Melo, Jiri Olsa, Ingo Molnar, Peter Zijlstra,
	LKML, linux-perf-users

On Fri, Jul 1, 2022 at 1:55 PM Namhyung Kim <namhyung@kernel.org> wrote:
>
> When it synthesize various task events, it scans the list of task
> first and then accesses later.  There's a window threads can die
> between the two and proc entries may not be available.
>
> Instead of bailing out, we can ignore that thread and move on.
>
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>

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

Thanks,
Ian

> ---
>  tools/perf/util/synthetic-events.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/tools/perf/util/synthetic-events.c b/tools/perf/util/synthetic-events.c
> index a068f42833c3..84d17bd4efae 100644
> --- a/tools/perf/util/synthetic-events.c
> +++ b/tools/perf/util/synthetic-events.c
> @@ -767,11 +767,12 @@ static int __event__synthesize_thread(union perf_event *comm_event,
>                 if (*end)
>                         continue;
>
> -               rc = -1;
> +               /* some threads may exit just after scan, ignore it */
>                 if (perf_event__prepare_comm(comm_event, pid, _pid, machine,
>                                              &tgid, &ppid, &kernel_thread) != 0)
> -                       break;
> +                       continue;
>
> +               rc = -1;
>                 if (perf_event__synthesize_fork(tool, fork_event, _pid, tgid,
>                                                 ppid, process, machine) < 0)
>                         break;
> --
> 2.37.0.rc0.161.g10f37bed90-goog
>

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

end of thread, other threads:[~2022-07-01 23:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-01 20:54 [PATCH 1/2] perf tools: Don't sort the task scan result from /proc Namhyung Kim
2022-07-01 20:54 ` [PATCH 2/2] perf tools: Ignore dead threads during event synthesis Namhyung Kim
2022-07-01 23:06   ` Ian Rogers
2022-07-01 23:06 ` [PATCH 1/2] perf tools: Don't sort the task scan result from /proc 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).