aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMateusz Guzik <mjg@FreeBSD.org>2017-11-03 19:21:36 +0000
committerMateusz Guzik <mjg@FreeBSD.org>2017-11-03 19:21:36 +0000
commita2c36a24b6c86cc389e6cff5301b1730c394bed2 (patch)
treeaf101873dbfa380243b91d5d590a6346e4aa4538
parent5399c35fccefb2eb83ce58d90848a056eca961a1 (diff)
downloadsrc-a2c36a24b6c86cc389e6cff5301b1730c394bed2.tar.gz
src-a2c36a24b6c86cc389e6cff5301b1730c394bed2.zip
Special-case pget lookups where pid == curproc->pid
Saves on allproc_lock acquires during buildworld, poudriere etc. Submitted by: Pawel Biernacki <pawel.biernacki@gmail.com> Sponsored by: Mysterious Code Ltd. Differential Revision: D12929
Notes
Notes: svn path=/head/; revision=325368
-rw-r--r--sys/kern/kern_proc.c37
1 files changed, 21 insertions, 16 deletions
diff --git a/sys/kern/kern_proc.c b/sys/kern/kern_proc.c
index de829228b1d4..53c08f1b8aa2 100644
--- a/sys/kern/kern_proc.c
+++ b/sys/kern/kern_proc.c
@@ -389,23 +389,28 @@ pget(pid_t pid, int flags, struct proc **pp)
struct proc *p;
int error;
- sx_slock(&allproc_lock);
- if (pid <= PID_MAX) {
- p = pfind_locked(pid);
- if (p == NULL && (flags & PGET_NOTWEXIT) == 0)
- p = zpfind_locked(pid);
- } else if ((flags & PGET_NOTID) == 0) {
- p = pfind_tid_locked(pid);
+ p = curproc;
+ if (p->p_pid == pid) {
+ PROC_LOCK(p);
} else {
- p = NULL;
- }
- sx_sunlock(&allproc_lock);
- if (p == NULL)
- return (ESRCH);
- if ((flags & PGET_CANSEE) != 0) {
- error = p_cansee(curthread, p);
- if (error != 0)
- goto errout;
+ sx_slock(&allproc_lock);
+ if (pid <= PID_MAX) {
+ p = pfind_locked(pid);
+ if (p == NULL && (flags & PGET_NOTWEXIT) == 0)
+ p = zpfind_locked(pid);
+ } else if ((flags & PGET_NOTID) == 0) {
+ p = pfind_tid_locked(pid);
+ } else {
+ p = NULL;
+ }
+ sx_sunlock(&allproc_lock);
+ if (p == NULL)
+ return (ESRCH);
+ if ((flags & PGET_CANSEE) != 0) {
+ error = p_cansee(curthread, p);
+ if (error != 0)
+ goto errout;
+ }
}
if ((flags & PGET_CANDEBUG) != 0) {
error = p_candebug(curthread, p);