thread: use tdfind in sysctl_kern_proc_kstack
This treads linear scans for locked lookup, but more importantly removes the only consumer of thread_find.
This commit is contained in:
parent
94275e3e69
commit
f837888a3e
@ -2748,6 +2748,7 @@ sysctl_kern_proc_kstack(SYSCTL_HANDLER_ARGS)
|
||||
struct stack *st;
|
||||
struct sbuf sb;
|
||||
struct proc *p;
|
||||
bool locked;
|
||||
|
||||
name = (int *)arg1;
|
||||
error = pget((pid_t)name[0], PGET_NOTINEXEC | PGET_WANTREAD, &p);
|
||||
@ -2787,12 +2788,15 @@ sysctl_kern_proc_kstack(SYSCTL_HANDLER_ARGS)
|
||||
lwpidarray[i] = td->td_tid;
|
||||
i++;
|
||||
}
|
||||
PROC_UNLOCK(p);
|
||||
locked = false;
|
||||
numthreads = i;
|
||||
for (i = 0; i < numthreads; i++) {
|
||||
td = thread_find(p, lwpidarray[i]);
|
||||
td = tdfind(lwpidarray[i], p->p_pid);
|
||||
if (td == NULL) {
|
||||
continue;
|
||||
}
|
||||
locked = true;
|
||||
bzero(kkstp, sizeof(*kkstp));
|
||||
(void)sbuf_new(&sb, kkstp->kkst_trace,
|
||||
sizeof(kkstp->kkst_trace), SBUF_FIXEDLEN);
|
||||
@ -2806,14 +2810,16 @@ sysctl_kern_proc_kstack(SYSCTL_HANDLER_ARGS)
|
||||
kkstp->kkst_state = KKST_STATE_RUNNING;
|
||||
thread_unlock(td);
|
||||
PROC_UNLOCK(p);
|
||||
locked = false;
|
||||
stack_sbuf_print(&sb, st);
|
||||
sbuf_finish(&sb);
|
||||
sbuf_delete(&sb);
|
||||
error = SYSCTL_OUT(req, kkstp, sizeof(*kkstp));
|
||||
PROC_LOCK(p);
|
||||
if (error)
|
||||
break;
|
||||
}
|
||||
if (!locked)
|
||||
PROC_LOCK(p);
|
||||
_PRELE(p);
|
||||
PROC_UNLOCK(p);
|
||||
if (lwpidarray != NULL)
|
||||
|
Loading…
Reference in New Issue
Block a user