Date: Sun, 17 May 2009 12:30:25 +0000 (UTC) From: Ed Schouten <ed@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r192250 - head/sys/kern Message-ID: <200905171230.n4HCUQfP027932@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: ed Date: Sun May 17 12:30:25 2009 New Revision: 192250 URL: http://svn.freebsd.org/changeset/base/192250 Log: Several cleanups to tty_info(), better known as Ctrl-T. - Only pick up PROC_LOCK once, which means we can drop the PGRP_LOCK right after picking up PROC_LOCK for the first time. - Print the process real time, making it consistent with tools like time(1). - Use `p' and `td' to reference the process/thread we are going to print. Only use pick-variables inside the loops. We already did this for the threads, but not the processes. Modified: head/sys/kern/tty_info.c Modified: head/sys/kern/tty_info.c ============================================================================== --- head/sys/kern/tty_info.c Sun May 17 12:21:11 2009 (r192249) +++ head/sys/kern/tty_info.c Sun May 17 12:30:25 2009 (r192250) @@ -213,9 +213,9 @@ proc_compare(struct proc *p1, struct pro void tty_info(struct tty *tp) { - struct timeval utime, stime; - struct proc *p, *pick; - struct thread *td, *picktd; + struct timeval rtime, utime, stime; + struct proc *p, *ppick; + struct thread *td, *tdpick; const char *stateprefix, *state; long rss; int load, pctcpu; @@ -254,17 +254,17 @@ tty_info(struct tty *tp) * whole list. However, we're guaranteed not to reference an exited * thread or proc since we hold the tty locked. */ - pick = NULL; - LIST_FOREACH(p, &tp->t_pgrp->pg_members, p_pglist) - if (proc_compare(pick, p)) - pick = p; - - PROC_LOCK(pick); - picktd = NULL; - FOREACH_THREAD_IN_PROC(pick, td) - if (thread_compare(picktd, td)) - picktd = td; - td = picktd; + p = NULL; + LIST_FOREACH(ppick, &tp->t_pgrp->pg_members, p_pglist) + if (proc_compare(p, ppick)) + p = ppick; + + PROC_LOCK(p); + PGRP_UNLOCK(tp->t_pgrp); + td = NULL; + FOREACH_THREAD_IN_PROC(p, tdpick) + if (thread_compare(td, tdpick)) + td = tdpick; stateprefix = ""; thread_lock(td); if (TD_IS_RUNNING(td)) @@ -284,28 +284,28 @@ tty_info(struct tty *tp) state = "suspended"; else if (TD_AWAITING_INTR(td)) state = "intrwait"; - else if (pick->p_state == PRS_ZOMBIE) + else if (p->p_state == PRS_ZOMBIE) state = "zombie"; else state = "unknown"; pctcpu = (sched_pctcpu(td) * 10000 + FSCALE / 2) >> FSHIFT; thread_unlock(td); - if (pick->p_state == PRS_NEW || pick->p_state == PRS_ZOMBIE) + if (p->p_state == PRS_NEW || p->p_state == PRS_ZOMBIE) rss = 0; else - rss = pgtok(vmspace_resident_count(pick->p_vmspace)); - PROC_UNLOCK(pick); - PROC_LOCK(pick); - PGRP_UNLOCK(tp->t_pgrp); - rufetchcalc(pick, &ru, &utime, &stime); - pid = pick->p_pid; - strlcpy(comm, pick->p_comm, sizeof comm); - PROC_UNLOCK(pick); + rss = pgtok(vmspace_resident_count(p->p_vmspace)); + microuptime(&rtime); + timevalsub(&rtime, &p->p_stats->p_start); + rufetchcalc(p, &ru, &utime, &stime); + pid = p->p_pid; + strlcpy(comm, p->p_comm, sizeof comm); + PROC_UNLOCK(p); - /* Print command, pid, state, utime, stime, %cpu, and rss. */ + /* Print command, pid, state, rtime, utime, stime, %cpu, and rss. */ ttyprintf(tp, - " cmd: %s %d [%s%s] %ld.%02ldu %ld.%02lds %d%% %ldk\n", + " cmd: %s %d [%s%s] %ld.%02ldr %ld.%02ldu %ld.%02lds %d%% %ldk\n", comm, pid, stateprefix, state, + (long)rtime.tv_sec, rtime.tv_usec / 10000, (long)utime.tv_sec, utime.tv_usec / 10000, (long)stime.tv_sec, stime.tv_usec / 10000, pctcpu / 100, rss);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200905171230.n4HCUQfP027932>