From 26dc5750ed936bca8b2128365657e4d55e4ac56d Mon Sep 17 00:00:00 2001 From: jhb Date: Mon, 3 Jun 2013 17:07:57 +0000 Subject: [PATCH] MFC 248167: Fix the 'C' field for a running thread to match the behavior described in the manpage by having it display the current CPU (ki_oncpu) rather than the previously used CPU (ki_lastcpu). ki_lastcpu is still used for all other thread states. git-svn-id: svn://svn.freebsd.org/base/stable/8@251312 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- usr.bin/top/machine.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/usr.bin/top/machine.c b/usr.bin/top/machine.c index 70b15ff1b..15eee4caa 100644 --- a/usr.bin/top/machine.c +++ b/usr.bin/top/machine.c @@ -796,7 +796,7 @@ format_next_process(caddr_t handle, char *(*get_userid)(int), int flags) double pct; struct handle *hp; char status[16]; - int state; + int cpu, state; struct rusage ru, *rup; long p_tot, s_tot; char *proc_fmt, thr_buf[6], jid_buf[6]; @@ -995,6 +995,13 @@ format_next_process(caddr_t handle, char *(*get_userid)(int), int flags) } /* format this entry */ + if (smpmode) { + if (state == SRUN && pp->ki_oncpu != 0xff) + cpu = pp->ki_oncpu; + else + cpu = pp->ki_lastcpu; + } else + cpu = 0; proc_fmt = smpmode ? smp_Proc_format : up_Proc_format; if (ps.thread != 0) thr_buf[0] = '\0'; @@ -1012,7 +1019,7 @@ format_next_process(caddr_t handle, char *(*get_userid)(int), int flags) format_k2(PROCSIZE(pp)), format_k2(pagetok(pp->ki_rssize)), status, - smpmode ? pp->ki_lastcpu : 0, + cpu, format_time(cputime), ps.wcpu ? 100.0 * weighted_cpu(pct, pp) : 100.0 * pct, screen_width > cmdlengthdelta ? screen_width - cmdlengthdelta : 0, -- 2.45.0