From owner-freebsd-current@FreeBSD.ORG Mon Oct 18 17:54:24 2010 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 183EC106566B for ; Mon, 18 Oct 2010 17:54:24 +0000 (UTC) (envelope-from emaste@freebsd.org) Received: from mail1.sandvine.com (Mail1.sandvine.com [64.7.137.134]) by mx1.freebsd.org (Postfix) with ESMTP id BA1D68FC22 for ; Mon, 18 Oct 2010 17:54:23 +0000 (UTC) Received: from labgw2.phaedrus.sandvine.com (192.168.222.22) by WTL-EXCH-1.sandvine.com (192.168.196.31) with Microsoft SMTP Server id 14.0.694.0; Mon, 18 Oct 2010 13:43:31 -0400 Received: by labgw2.phaedrus.sandvine.com (Postfix, from userid 10332) id 3C94A33C00; Mon, 18 Oct 2010 13:43:31 -0400 (EDT) Date: Mon, 18 Oct 2010 13:43:31 -0400 From: Ed Maste To: Message-ID: <20101018174331.GA80017@sandvine.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline User-Agent: Mutt/1.4.2.1i Subject: CPU report in first line of "vmstat 1" is meaningless X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 18 Oct 2010 17:54:24 -0000 The us/sy/id CPU usage numbers in the first line of vmstat are not useful, because they're calculated based on kern.cp_times since boot, and not a delta as are all subsequent lines. If the system has been up long enough wrapping may come in to play, giving negative results. For example, on one machine I see: $ vmstat 1 procs memory page disks faults cpu r b w avm fre flt re pi po fr sr da0 pa0 in sy cs us sy id 1 0 2 1097M 227M 101 0 0 0 195 45 0 0 483 40 243 -24 -33 157 1 0 2 1102M 222M 1396 0 0 0 0 0 0 0 159 2170 826 25 2 74 1 0 2 1107M 218M 1124 0 0 0 0 0 0 0 146 2217 789 24 2 74 Should we wait for one interval before displaying the first line, or display nothing (or a placeholder like '-')? Below is a quick patch that illustrates the issue, and implements the "display nothing" option. With the patch the output looks like: $ vmstat 1 procs memory page disk faults cpu r b w avm fre flt re pi po fr sr ad0 in sy cs us sy id 3 0 0 1971M 85M 326 0 0 0 334 5 0 457 3674 1495 2 0 0 1971M 85M 23 0 0 0 0 0 0 301 3634 1209 5 7 88 1 0 0 1971M 85M 74 0 0 0 0 0 0 510 4655 1619 7 3 90 And the patch: Index: usr.bin/vmstat/vmstat.c =================================================================== --- usr.bin/vmstat/vmstat.c (revision 214019) +++ usr.bin/vmstat/vmstat.c (working copy) @@ -658,6 +658,7 @@ int ncpus, maxid; u_long cpumask; int rate_adj; + int have_prev_cp_times = 0; uptime = getuptime(); halfuptime = uptime / 2; @@ -803,10 +804,13 @@ (unsigned long)rate(sum.v_intr - osum.v_intr), (unsigned long)rate(sum.v_syscall - osum.v_syscall), (unsigned long)rate(sum.v_swtch - osum.v_swtch)); - if (Pflag) - pcpustats(ncpus, cpumask, maxid); - else - cpustats(); + if (have_prev_cp_times) { + if (Pflag) + pcpustats(ncpus, cpumask, maxid); + else + cpustats(); + } else + have_prev_cp_times = 1; (void)printf("\n"); (void)fflush(stdout); if (reps >= 0 && --reps <= 0) -Ed