From owner-svn-src-all@FreeBSD.ORG Sun May 17 12:30:26 2009 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3F031106568F; Sun, 17 May 2009 12:30:26 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 212308FC22; Sun, 17 May 2009 12:30:26 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n4HCUQ5Y027933; Sun, 17 May 2009 12:30:26 GMT (envelope-from ed@svn.freebsd.org) Received: (from ed@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n4HCUQfP027932; Sun, 17 May 2009 12:30:26 GMT (envelope-from ed@svn.freebsd.org) Message-Id: <200905171230.n4HCUQfP027932@svn.freebsd.org> From: Ed Schouten Date: Sun, 17 May 2009 12:30:25 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r192250 - head/sys/kern X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 17 May 2009 12:30:26 -0000 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);