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
This commit is contained in:
Mateusz Guzik 2017-11-03 19:21:36 +00:00
parent 5399c35fcc
commit a2c36a24b6
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=325368

View file

@ -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);