Skip to contentSkip to conversation

exit: move trace_sched_process_exit earlier in do_exit()

PATCH Superseded [email protected] 3 participants 4 messages Mar 10, 2024 – Mar 23, 2024

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 exit: move trace_sched_process_exit earlier in do_exit()

From: Wen Yang <[email protected]>

Currently coredump_task_exit() takes some time to wait for the generation of the dump file. But if the user-space wants to receive a notification as soon as possible it maybe inconvenient.

Move trace_sched_process_exit() earlier in do_exit(). This way a user-space monitor could detect the exits and potentially make some preparations in advance.

Oleg initially proposed this suggestion, and Steven further provided some detailed suggestions, and Mathieu carefully checked the historical code and said:
: I've checked with Matthew Khouzam (maintainer of Trace Compass) : which care about this tracepoint, and we have not identified any : significant impact of moving it on its model of the scheduler, other : than slightly changing its timing.
: I've also checked quickly in lttng-analyses and have not found : any code that care about its specific placement.
: So I would say go ahead and move it earlier in do_exit(), it's : fine by me.

Cc Masami Hiramatsu <[email protected]>
Cc Mathieu Desnoyers <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Christian Brauner <[email protected]>
Cc Mel Gorman <[email protected]>
Cc Peter Zijlstra <[email protected]>
---
 kernel/exit.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/exit.c +1 -1
index 493647fd7c07..2cff6533cb39 100644
@@ -826,6 +826,7 @@ void __noreturn do_exit(long code)
 
 	WARN_ON(tsk->plug);
 
+	trace_sched_process_exit(tsk);
 	kcov_task_exit(tsk);
 	kmsan_task_exit(tsk);
 
@@ -866,7 +867,6 @@ void __noreturn do_exit(long code)
 
 	if (group_dead)
 		acct_process();
-	trace_sched_process_exit(tsk);
 
 	exit_sem(tsk);
 	exit_shm(tsk);
Signature · 1 line
2.25.1
#1 lore raw
Quoted 10 lines · On Sun, 10 Mar 2024 13:25:29 +0800 [email protected] wrote:

From: Wen Yang <[email protected]>

Currently coredump_task_exit() takes some time to wait for the generation of the dump file. But if the user-space wants to receive a notification as soon as possible it maybe inconvenient.

Move trace_sched_process_exit() earlier in do_exit(). This way a user-space monitor could detect the exits and potentially make some preparations in advance.

Quoted 12 lines

Oleg initially proposed this suggestion, and Steven further provided some detailed suggestions, and Mathieu carefully checked the historical code and said:
: I've checked with Matthew Khouzam (maintainer of Trace Compass) : which care about this tracepoint, and we have not identified any : significant impact of moving it on its model of the scheduler, other : than slightly changing its timing.
: I've also checked quickly in lttng-analyses and have not found : any code that care about its specific placement.
: So I would say go ahead and move it earlier in do_exit(), it's : fine by me.

I'm putting together last minute minor patches for this merge window. I can take this if nobody has any objections.

-- Steve

Quoted 36 lines
Cc Masami Hiramatsu <[email protected]>
Cc Mathieu Desnoyers <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Christian Brauner <[email protected]>
Cc Mel Gorman <[email protected]>
Cc Peter Zijlstra <[email protected]>
---
 kernel/exit.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/exit.c +1 -1
index 493647fd7c07..2cff6533cb39 100644
@@ -826,6 +826,7 @@ void __noreturn do_exit(long code)
 
 	WARN_ON(tsk->plug);
 
+	trace_sched_process_exit(tsk);
 	kcov_task_exit(tsk);
 	kmsan_task_exit(tsk);
 
@@ -866,7 +867,6 @@ void __noreturn do_exit(long code)
 
 	if (group_dead)
 		acct_process();
-	trace_sched_process_exit(tsk);
 
 	exit_sem(tsk);
 	exit_shm(tsk);
#2 lore raw
In reply to [email protected]
Quoted 5 lines · On Sun, 10 Mar 2024 13:25:29 +0800 [email protected] wrote:

From: Wen Yang <[email protected]>

Currently coredump_task_exit() takes some time to wait for the generation of the dump file. But if the user-space wants to receive a notification as soon as possible it maybe inconvenient.

If userspace is awaiting this notification to say "it's now OK to read the dump file" then it could break things?

Quoted 4 lines

Move trace_sched_process_exit() earlier in do_exit(). This way a user-space monitor could detect the exits and potentially make some preparations in advance.

Quoted 11 lines

Oleg initially proposed this suggestion, and Steven further provided some detailed suggestions, and Mathieu carefully checked the historical code and said:
: I've checked with Matthew Khouzam (maintainer of Trace Compass) : which care about this tracepoint, and we have not identified any : significant impact of moving it on its model of the scheduler, other : than slightly changing its timing.
: I've also checked quickly in lttng-analyses and have not found : any code that care about its specific placement.
: So I would say go ahead and move it earlier in do_exit(), it's : fine by me.

I'm not seeing a clear need for this change. "maybe inconveniant" is quite thin. Please fully describe what motivated you to work on this?

author
#3 lore raw
Quoted 11 lines · Andrew Morton
Quoted 5 lines · On Sun, 10 Mar 2024 13:25:29 +0800 [email protected] wrote:

From: Wen Yang <[email protected]>

Currently coredump_task_exit() takes some time to wait for the generation of the dump file. But if the user-space wants to receive a notification as soon as possible it maybe inconvenient.

If userspace is awaiting this notification to say "it's now OK to read the dump file" then it could break things?

Thanks for your comments.

This could also be achieved in the nearby proc_exit_connector().

In addition, this issue has been discussed in detail in the following link:
https://lkml.org/lkml/2024/2/23/1018

Quoted 16 lines
Quoted 4 lines

Move trace_sched_process_exit() earlier in do_exit(). This way a user-space monitor could detect the exits and potentially make some preparations in advance.

Quoted 11 lines

Oleg initially proposed this suggestion, and Steven further provided some detailed suggestions, and Mathieu carefully checked the historical code and said:
: I've checked with Matthew Khouzam (maintainer of Trace Compass) : which care about this tracepoint, and we have not identified any : significant impact of moving it on its model of the scheduler, other : than slightly changing its timing.
: I've also checked quickly in lttng-analyses and have not found : any code that care about its specific placement.
: So I would say go ahead and move it earlier in do_exit(), it's : fine by me.

Quoted 3 lines

I'm not seeing a clear need for this change. "maybe inconveniant" is quite thin. Please fully describe what motivated you to work on this?

Thanks.
We hope to address this issue in our Advanced Driver Assistance System:
When certain critical processes exit abnormally, prompt information can be reported to the monitoring program as soon as possible.

We have also attempted to add a new TP, as follows:
https://lkml.org/lkml/2024/2/23/5

But after some discussion, it is still considered more reasonable to move trace_sched_process_exit() earlier.

We also look forward to your suggestions, thanks again.

--
Best wishes,
Wen