git: 80cf427b8dc1 - main - proc: shave a lock trip on exit if possible

From: Mateusz Guzik <mjg_at_FreeBSD.org>
Date: Wed, 29 Mar 2023 09:19:09 UTC
The branch main has been updated by mjg:

URL: https://cgit.FreeBSD.org/src/commit/?id=80cf427b8dc18bc5c26fed6d07bc5c5eda4545b0

commit 80cf427b8dc18bc5c26fed6d07bc5c5eda4545b0
Author:     Mateusz Guzik <mjg@FreeBSD.org>
AuthorDate: 2023-03-29 08:45:46 +0000
Commit:     Mateusz Guzik <mjg@FreeBSD.org>
CommitDate: 2023-03-29 09:19:03 +0000

    proc: shave a lock trip on exit if possible
    
    ... which happens to be vast majority of the time
---
 sys/kern/kern_exit.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/sys/kern/kern_exit.c b/sys/kern/kern_exit.c
index 3f64343aea0e..a92d5cc0f642 100644
--- a/sys/kern/kern_exit.c
+++ b/sys/kern/kern_exit.c
@@ -477,9 +477,11 @@ exit1(struct thread *td, int rval, int signo)
 	sx_xunlock(&allproc_lock);
 
 	sx_xlock(&proctree_lock);
-	PROC_LOCK(p);
-	p->p_flag &= ~(P_TRACED | P_PPWAIT | P_PPTRACE);
-	PROC_UNLOCK(p);
+	if ((p->p_flag & (P_TRACED | P_PPWAIT | P_PPTRACE)) != 0) {
+		PROC_LOCK(p);
+		p->p_flag &= ~(P_TRACED | P_PPWAIT | P_PPTRACE);
+		PROC_UNLOCK(p);
+	}
 
 	/*
 	 * killjobc() might drop and re-acquire proctree_lock to