Changeset View
Changeset View
Standalone View
Standalone View
sys/kern/kern_proc.c
Show First 20 Lines • Show All 187 Lines • ▼ Show 20 Lines | procinit(void) | ||||
LIST_INIT(&zombproc); | LIST_INIT(&zombproc); | ||||
pidhashtbl = hashinit(maxproc / 4, M_PROC, &pidhash); | pidhashtbl = hashinit(maxproc / 4, M_PROC, &pidhash); | ||||
pidhashlock = (pidhash + 1) / 64; | pidhashlock = (pidhash + 1) / 64; | ||||
if (pidhashlock > 0) | if (pidhashlock > 0) | ||||
pidhashlock--; | pidhashlock--; | ||||
pidhashtbl_lock = malloc(sizeof(*pidhashtbl_lock) * (pidhashlock + 1), | pidhashtbl_lock = malloc(sizeof(*pidhashtbl_lock) * (pidhashlock + 1), | ||||
M_PROC, M_WAITOK | M_ZERO); | M_PROC, M_WAITOK | M_ZERO); | ||||
for (i = 0; i < pidhashlock + 1; i++) | for (i = 0; i < pidhashlock + 1; i++) | ||||
sx_init(&pidhashtbl_lock[i], "pidhash"); | sx_init_flags(&pidhashtbl_lock[i], "pidhash", SX_DUPOK); | ||||
pgrphashtbl = hashinit(maxproc / 4, M_PROC, &pgrphash); | pgrphashtbl = hashinit(maxproc / 4, M_PROC, &pgrphash); | ||||
proc_zone = uma_zcreate("PROC", sched_sizeof_proc(), | proc_zone = uma_zcreate("PROC", sched_sizeof_proc(), | ||||
mjg: If this is to appease WITNESS you can add SX_DUPOK instead. No opinion one way or the other… | |||||
Done Inline ActionsI don't have a strong opinion either, but this way broken code that rmacklem: I don't have a strong opinion either, but this way broken code that
does acquire the same lock… | |||||
proc_ctor, proc_dtor, proc_init, proc_fini, | proc_ctor, proc_dtor, proc_init, proc_fini, | ||||
UMA_ALIGN_PTR, UMA_ZONE_NOFREE); | UMA_ALIGN_PTR, UMA_ZONE_NOFREE); | ||||
uihashinit(); | uihashinit(); | ||||
} | } | ||||
/* | /* | ||||
* Prepare a proc for use. | * Prepare a proc for use. | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 153 Lines • ▼ Show 20 Lines | inferior(struct proc *p) | ||||
sx_assert(&proctree_lock, SX_LOCKED); | sx_assert(&proctree_lock, SX_LOCKED); | ||||
PROC_LOCK_ASSERT(p, MA_OWNED); | PROC_LOCK_ASSERT(p, MA_OWNED); | ||||
for (; p != curproc; p = proc_realparent(p)) { | for (; p != curproc; p = proc_realparent(p)) { | ||||
if (p->p_pid == 0) | if (p->p_pid == 0) | ||||
return (0); | return (0); | ||||
} | } | ||||
return (1); | return (1); | ||||
} | |||||
/* | |||||
* Shared lock all the pid hash lists. | |||||
*/ | |||||
void | |||||
pidhash_slockall(void) | |||||
{ | |||||
u_long i; | |||||
for (i = 0; i < pidhashlock + 1; i++) | |||||
Not Done Inline ActionsThe condition can be written as i <= pidhashlock kib: The condition can be written as `i <= pidhashlock` | |||||
Done Inline ActionsI just copied the line in procinit() that initializes them, so that the code is rmacklem: I just copied the line in procinit() that initializes them, so that the code is
consistent with… | |||||
sx_slock(&pidhashtbl_lock[i]); | |||||
} | |||||
/* | |||||
* Shared unlock all the pid hash lists. | |||||
*/ | |||||
void | |||||
pidhash_sunlockall(void) | |||||
{ | |||||
u_long i; | |||||
for (i = 0; i < pidhashlock + 1; i++) | |||||
sx_sunlock(&pidhashtbl_lock[i]); | |||||
} | |||||
/* | |||||
* Similar to pfind_any(), this function finds zombies. | |||||
Done Inline ActionsBut now pfind and pfind_locked have different semantics with the latter not returning zombies. At the very least this needs a comment. Or you can rename this to pfind_any_locked and you are set. mjg: But now pfind and pfind_locked have different semantics with the latter not returning zombies. | |||||
*/ | |||||
struct proc * | |||||
pfind_any_locked(pid_t pid) | |||||
{ | |||||
struct proc *p; | |||||
sx_assert(PIDHASHLOCK(pid), SX_LOCKED); | |||||
LIST_FOREACH(p, PIDHASH(pid), p_hash) { | |||||
if (p->p_pid == pid) { | |||||
PROC_LOCK(p); | |||||
if (p->p_state == PRS_NEW) { | |||||
PROC_UNLOCK(p); | |||||
p = NULL; | |||||
} | |||||
break; | |||||
} | |||||
} | |||||
return (p); | |||||
} | } | ||||
/* | /* | ||||
* Locate a process by number. | * Locate a process by number. | ||||
* | * | ||||
* By not returning processes in the PRS_NEW state, we allow callers to avoid | * By not returning processes in the PRS_NEW state, we allow callers to avoid | ||||
* testing for that condition to avoid dereferencing p_ucred, et al. | * testing for that condition to avoid dereferencing p_ucred, et al. | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 2,830 Lines • Show Last 20 Lines |
If this is to appease WITNESS you can add SX_DUPOK instead. No opinion one way or the other, but most of the time these kind of locks are not numbered.