Skip to content

Commit 7669ad8

Browse files
committed
exit: get rid of PROC_SLOCK when checking a process to report, take #2
The suspension counter needs synchronisation through slock, but we don't need it to check if inspecting the counter is necessary to begin with. In the common case it is not, thus avoid the lock if possible. Reviewed by: kib Tested by: pho
1 parent 4f1d7ae commit 7669ad8

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

sys/kern/kern_exit.c

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,6 +1174,7 @@ kern_wait6(struct thread *td, idtype_t idtype, id_t id, int *status,
11741174
struct proc *p, *q;
11751175
pid_t pid;
11761176
int error, nfound, ret;
1177+
bool report;
11771178

11781179
AUDIT_ARG_VALUE((int)idtype); /* XXX - This is likely wrong! */
11791180
AUDIT_ARG_PID((pid_t)id); /* XXX - This may be wrong! */
@@ -1225,36 +1226,38 @@ kern_wait6(struct thread *td, idtype_t idtype, id_t id, int *status,
12251226
nfound++;
12261227
PROC_LOCK_ASSERT(p, MA_OWNED);
12271228

1228-
if ((options & (WTRAPPED | WUNTRACED)) != 0)
1229-
PROC_SLOCK(p);
1230-
12311229
if ((options & WTRAPPED) != 0 &&
1232-
(p->p_flag & P_TRACED) != 0 &&
1233-
(p->p_flag & (P_STOPPED_TRACE | P_STOPPED_SIG)) != 0 &&
1234-
p->p_suspcount == p->p_numthreads &&
1235-
(p->p_flag & P_WAITED) == 0) {
1230+
(p->p_flag & P_TRACED) != 0) {
1231+
PROC_SLOCK(p);
1232+
report =
1233+
((p->p_flag & (P_STOPPED_TRACE | P_STOPPED_SIG)) &&
1234+
p->p_suspcount == p->p_numthreads &&
1235+
(p->p_flag & P_WAITED) == 0);
12361236
PROC_SUNLOCK(p);
1237+
if (report) {
12371238
CTR4(KTR_PTRACE,
12381239
"wait: returning trapped pid %d status %#x "
12391240
"(xstat %d) xthread %d",
12401241
p->p_pid, W_STOPCODE(p->p_xsig), p->p_xsig,
12411242
p->p_xthread != NULL ?
12421243
p->p_xthread->td_tid : -1);
1243-
report_alive_proc(td, p, siginfo, status, options,
1244-
CLD_TRAPPED);
1245-
return (0);
1244+
report_alive_proc(td, p, siginfo, status,
1245+
options, CLD_TRAPPED);
1246+
return (0);
1247+
}
12461248
}
12471249
if ((options & WUNTRACED) != 0 &&
1248-
(p->p_flag & P_STOPPED_SIG) != 0 &&
1249-
p->p_suspcount == p->p_numthreads &&
1250-
(p->p_flag & P_WAITED) == 0) {
1250+
(p->p_flag & P_STOPPED_SIG) != 0) {
1251+
PROC_SLOCK(p);
1252+
report = (p->p_suspcount == p->p_numthreads &&
1253+
((p->p_flag & P_WAITED) == 0));
12511254
PROC_SUNLOCK(p);
1252-
report_alive_proc(td, p, siginfo, status, options,
1253-
CLD_STOPPED);
1254-
return (0);
1255+
if (report) {
1256+
report_alive_proc(td, p, siginfo, status,
1257+
options, CLD_STOPPED);
1258+
return (0);
1259+
}
12551260
}
1256-
if ((options & (WTRAPPED | WUNTRACED)) != 0)
1257-
PROC_SUNLOCK(p);
12581261
if ((options & WCONTINUED) != 0 &&
12591262
(p->p_flag & P_CONTINUED) != 0) {
12601263
report_alive_proc(td, p, siginfo, status, options,

0 commit comments

Comments
 (0)