perf tools: Don't sort the task scan result from /proc
Namhyung Kim
maintainerPATCH 1/2 perf tools: Don't sort the task scan result from /proc
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.
--- tools/perf/util/synthetic-events.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/util/synthetic-events.c +2 -2
@@ -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;
Signature · 1 line
2.37.0.rc0.161.g10f37bed90-goog
Namhyung Kim
maintainerPATCH 2/2 perf tools: Ignore dead threads during event synthesis
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.
--- tools/perf/util/synthetic-events.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
tools/perf/util/synthetic-events.c +3 -2
@@ -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 ;
Signature · 1 line
2.37.0.rc0.161.g10f37bed90-goog
Re: [PATCH 2/2] perf tools: Ignore dead threads during event synthesis
Quoted 8 lines · Namhyung Kim
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 <[email protected]>
Thanks,
Ian
Quoted 26 lines
--- tools/perf/util/synthetic-events.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)tools/perf/util/synthetic-events.c +3
-3@@ -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
Quoted 6 lines · Namhyung Kim
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 <[email protected]>
Thanks,
Ian
Quoted 29 lines
--- tools/perf/util/synthetic-events.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)tools/perf/util/synthetic-events.c +2
-3@@ -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