From owner-freebsd-sparc64@FreeBSD.ORG Mon Mar 4 19:49:05 2013 Return-Path: Delivered-To: freebsd-sparc64@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 372432FB for ; Mon, 4 Mar 2013 19:49:05 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from bigwig.baldwin.cx (bigknife-pt.tunnel.tserv9.chi1.ipv6.he.net [IPv6:2001:470:1f10:75::2]) by mx1.freebsd.org (Postfix) with ESMTP id 10E281076 for ; Mon, 4 Mar 2013 19:49:05 +0000 (UTC) Received: from jhbbsd.localnet (unknown [209.249.190.124]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id 5D0FBB944; Mon, 4 Mar 2013 14:49:04 -0500 (EST) From: John Baldwin To: freebsd-sparc64@freebsd.org Subject: Re: top's CPUn vs C column Date: Mon, 4 Mar 2013 11:37:44 -0500 User-Agent: KMail/1.13.5 (FreeBSD/8.2-CBSD-20110714-p25; KDE/4.5.5; amd64; ; ) References: In-Reply-To: MIME-Version: 1.0 Content-Type: Text/Plain; charset="windows-1252" Content-Transfer-Encoding: 7bit Message-Id: <201303041137.44337.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.7 (bigwig.baldwin.cx); Mon, 04 Mar 2013 14:49:04 -0500 (EST) X-BeenThere: freebsd-sparc64@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Porting FreeBSD to the Sparc List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 04 Mar 2013 19:49:05 -0000 On Friday, March 01, 2013 1:17:41 pm Chris Ross wrote: > > So, I was looking at a v240 I have running stable/9 (9.1-STABLE), and noticed something odd. The per-CPU information displayed by top seems inconsistent. To simplify things, while I'm running a "make release" in /usr/src/release, I just started running the following command over and over (by hand): > > cross: top | grep " CPU" > cross: top | grep " CPU" > 1044 cross 1 72 0 17128K 4464K CPU1 0 0:01 1.27% zsh > 22528 root 1 77 5 11672K 2592K CPU1 1 0:00 0.00% sh > cross: top | grep " CPU" > cross: top | grep " CPU" > 22634 cross 1 72 0 12808K 2872K CPU1 1 0:00 0.00% top > 22633 root 1 77 5 6272K 880K CPU0 1 0:00 0.00% make > cross: top | grep " CPU" > 22637 root 1 77 5 6272K 1656K CPU0 0 0:00 0.00% make > cross: top | grep " CPU" > cross: top | grep " CPU" > 22684 root 1 77 5 11672K 2592K CPU0 0 0:00 0.00% sh > cross: > > This displayed what I had earlier seen in the full-screen top. There doesn't appear to be any specific binding between the "n" in the "CPUn" state value, and the number in the "C" column, which is according to the man page, should mean the same thing. No, they are different things. The man page is a bit stale. The 'C' column is the CPU that the process last ran on. Hmm, it's actually easiest to fix the code I think. Try this (untested) change: Index: usr.bin/top/machine.c =================================================================== --- machine.c (revision 247792) +++ machine.c (working copy) @@ -797,7 +797,7 @@ format_next_process(caddr_t handle, char *(*get_us 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]; @@ -997,6 +997,13 @@ format_next_process(caddr_t handle, char *(*get_us } /* 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'; @@ -1014,7 +1021,7 @@ format_next_process(caddr_t handle, char *(*get_us 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, -- John Baldwin