FreeBSD/sys/kern/kern_proc.c
/*
 * Fill in information that is thread specific.  Must be called with
 * target process locked.  If 'preferthread' is set, overwrite certain
 * process-related fields that are maintained for both threads and
 * processes.
 */
Fill in information that is thread specific.  Must be called with
target process locked.  If 'preferthread' is set, overwrite certain
process-related fields that are maintained for both threads and
processes.
Fill in information that is thread specific . Must be called with target process locked . If ' preferthread ' is set overwrite certain process - related fields that are maintained for both threads and processes .
static void
fill_kinfo_thread(struct thread *td, struct kinfo_proc *kp, int preferthread)
{
	struct proc *p;
	p = td->td_proc;
	kp->ki_tdaddr = td;
	PROC_LOCK_ASSERT(p, MA_OWNED);
	if (preferthread)
		PROC_STATLOCK(p);
	thread_lock(td);
	if (td->td_wmesg != NULL)
		strlcpy(kp->ki_wmesg, td->td_wmesg, sizeof(kp->ki_wmesg));
	else
		bzero(kp->ki_wmesg, sizeof(kp->ki_wmesg));
	strlcpy(kp->ki_tdname, td->td_name, sizeof(kp->ki_tdname));
	if (TD_ON_LOCK(td)) {
		kp->ki_kiflag |= KI_LOCKBLOCK;
		strlcpy(kp->ki_lockname, td->td_lockname,
		    sizeof(kp->ki_lockname));
	} else {
		kp->ki_kiflag &= ~KI_LOCKBLOCK;
		bzero(kp->ki_lockname, sizeof(kp->ki_lockname));
	}
	if (p->p_state == PRS_NORMAL) { 
		if (TD_ON_RUNQ(td) ||
		    TD_CAN_RUN(td) ||
		    TD_IS_RUNNING(td)) {
			kp->ki_stat = SRUN;
		} else if (P_SHOULDSTOP(p)) {
			kp->ki_stat = SSTOP;
		} else if (TD_IS_SLEEPING(td)) {
			kp->ki_stat = SSLEEP;
		} else if (TD_ON_LOCK(td)) {
			kp->ki_stat = SLOCK;
		} else {
			kp->ki_stat = SWAIT;
		}
	} else if (p->p_state == PRS_ZOMBIE) {
		kp->ki_stat = SZOMB;
	} else {
		kp->ki_stat = SIDL;
	}
	kp->ki_wchan = td->td_wchan;
	kp->ki_pri.pri_level = td->td_priority;
	kp->ki_pri.pri_native = td->td_base_pri;
	if (td->td_lastcpu == NOCPU)
		kp->ki_lastcpu_old = NOCPU_OLD;
	else if (td->td_lastcpu > MAXCPU_OLD)
		kp->ki_lastcpu_old = MAXCPU_OLD;
	else
		kp->ki_lastcpu_old = td->td_lastcpu;
	if (td->td_oncpu == NOCPU)
		kp->ki_oncpu_old = NOCPU_OLD;
	else if (td->td_oncpu > MAXCPU_OLD)
		kp->ki_oncpu_old = MAXCPU_OLD;
	else
		kp->ki_oncpu_old = td->td_oncpu;
	kp->ki_lastcpu = td->td_lastcpu;
	kp->ki_oncpu = td->td_oncpu;
	kp->ki_tdflags = td->td_flags;
	kp->ki_tid = td->td_tid;
	kp->ki_numthreads = p->p_numthreads;
	kp->ki_pcb = td->td_pcb;
	kp->ki_kstack = (void *)td->td_kstack;
	kp->ki_slptime = (ticks - td->td_slptick) / hz;
	kp->ki_pri.pri_class = td->td_pri_class;
	kp->ki_pri.pri_user = td->td_user_pri;
	if (preferthread) {
		rufetchtd(td, &kp->ki_rusage);
		kp->ki_runtime = cputick2usec(td->td_rux.rux_runtime);
		kp->ki_pctcpu = sched_pctcpu(td);
		kp->ki_estcpu = sched_estcpu(td);
		kp->ki_cow = td->td_cow;
	}
	kp->ki_rqindex = 0;
	if (preferthread)
		kp->ki_siglist = td->td_siglist;
	kp->ki_sigmask = td->td_sigmask;
	thread_unlock(td);
	if (preferthread)
		PROC_STATUNLOCK(p);
}
static void fill_kinfo_thread ( struct thread * td , struct kinfo_proc * kp , int preferthread ) { struct proc * p ; p = td -> td_proc ; kp -> ki_tdaddr = td ; PROC_LOCK_ASSERT ( p , MA_OWNED ) ; if ( preferthread ) PROC_STATLOCK ( p ) ; thread_lock ( td ) ; if ( td -> td_wmesg != NULL ) strlcpy ( kp -> ki_wmesg , td -> td_wmesg , sizeof ( kp -> ki_wmesg ) ) ; else bzero ( kp -> ki_wmesg , sizeof ( kp -> ki_wmesg ) ) ; strlcpy ( kp -> ki_tdname , td -> td_name , sizeof ( kp -> ki_tdname ) ) ; if ( TD_ON_LOCK ( td ) ) { kp -> ki_kiflag |= KI_LOCKBLOCK ; strlcpy ( kp -> ki_lockname , td -> td_lockname , sizeof ( kp -> ki_lockname ) ) ; } else { kp -> ki_kiflag &= ~ KI_LOCKBLOCK ; bzero ( kp -> ki_lockname , sizeof ( kp -> ki_lockname ) ) ; } if ( p -> p_state == PRS_NORMAL ) { if ( TD_ON_RUNQ ( td ) || TD_CAN_RUN ( td ) || TD_IS_RUNNING ( td ) ) { kp -> ki_stat = SRUN ; } else if ( P_SHOULDSTOP ( p ) ) { kp -> ki_stat = SSTOP ; } else if ( TD_IS_SLEEPING ( td ) ) { kp -> ki_stat = SSLEEP ; } else if ( TD_ON_LOCK ( td ) ) { kp -> ki_stat = SLOCK ; } else { kp -> ki_stat = SWAIT ; } } else if ( p -> p_state == PRS_ZOMBIE ) { kp -> ki_stat = SZOMB ; } else { kp -> ki_stat = SIDL ; } kp -> ki_wchan = td -> td_wchan ; kp -> ki_pri . pri_level = td -> td_priority ; kp -> ki_pri . pri_native = td -> td_base_pri ; if ( td -> td_lastcpu == NOCPU ) kp -> ki_lastcpu_old = NOCPU_OLD ; else if ( td -> td_lastcpu > MAXCPU_OLD ) kp -> ki_lastcpu_old = MAXCPU_OLD ; else kp -> ki_lastcpu_old = td -> td_lastcpu ; if ( td -> td_oncpu == NOCPU ) kp -> ki_oncpu_old = NOCPU_OLD ; else if ( td -> td_oncpu > MAXCPU_OLD ) kp -> ki_oncpu_old = MAXCPU_OLD ; else kp -> ki_oncpu_old = td -> td_oncpu ; kp -> ki_lastcpu = td -> td_lastcpu ; kp -> ki_oncpu = td -> td_oncpu ; kp -> ki_tdflags = td -> td_flags ; kp -> ki_tid = td -> td_tid ; kp -> ki_numthreads = p -> p_numthreads ; kp -> ki_pcb = td -> td_pcb ; kp -> ki_kstack = ( void * ) td -> td_kstack ; kp -> ki_slptime = ( ticks - td -> td_slptick ) / hz ; kp -> ki_pri . pri_class = td -> td_pri_class ; kp -> ki_pri . pri_user = td -> td_user_pri ; if ( preferthread ) { rufetchtd ( td , & kp -> ki_rusage ) ; kp -> ki_runtime = cputick2usec ( td -> td_rux . rux_runtime ) ; kp -> ki_pctcpu = sched_pctcpu ( td ) ; kp -> ki_estcpu = sched_estcpu ( td ) ; kp -> ki_cow = td -> td_cow ; } kp -> ki_rqindex = 0 ; if ( preferthread ) kp -> ki_siglist = td -> td_siglist ; kp -> ki_sigmask = td -> td_sigmask ; thread_unlock ( td ) ; if ( preferthread ) PROC_STATUNLOCK ( p ) ; }
Fill in information that is thread specific.
Fill in information that is thread specific .
/* approximate. */ /* Things in the thread */ /*
	 * Note: legacy fields; clamp at the old NOCPU value and/or
	 * the maximum u_char CPU value.
	 */ /* We can't get this anymore but ps etc never used it anyway. */