From owner-freebsd-bugs@FreeBSD.ORG Wed Dec 1 11:00:23 2010 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id CEA331065695 for ; Wed, 1 Dec 2010 11:00:23 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 529CD8FC1D for ; Wed, 1 Dec 2010 11:00:22 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.4/8.14.4) with ESMTP id oB1B0MLN008418 for ; Wed, 1 Dec 2010 11:00:22 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.4/8.14.4/Submit) id oB1B0MGT008396; Wed, 1 Dec 2010 11:00:22 GMT (envelope-from gnats) Resent-Date: Wed, 1 Dec 2010 11:00:22 GMT Resent-Message-Id: <201012011100.oB1B0MGT008396@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Hiro Aki Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id DDFEC106566C for ; Wed, 1 Dec 2010 10:55:58 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from red.freebsd.org (unknown [IPv6:2001:4f8:fff6::22]) by mx1.freebsd.org (Postfix) with ESMTP id CB7B48FC08 for ; Wed, 1 Dec 2010 10:55:58 +0000 (UTC) Received: from red.freebsd.org (localhost [127.0.0.1]) by red.freebsd.org (8.14.4/8.14.4) with ESMTP id oB1Atw7q037276 for ; Wed, 1 Dec 2010 10:55:58 GMT (envelope-from nobody@red.freebsd.org) Received: (from nobody@localhost) by red.freebsd.org (8.14.4/8.14.4/Submit) id oB1AtwxM037275; Wed, 1 Dec 2010 10:55:58 GMT (envelope-from nobody) Message-Id: <201012011055.oB1AtwxM037275@red.freebsd.org> Date: Wed, 1 Dec 2010 10:55:58 GMT From: Hiro Aki To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Cc: Subject: bin/152738: vmstat, printhdr() doesn't work correctly with -p option under multiple CPUs X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 01 Dec 2010 11:00:23 -0000 >Number: 152738 >Category: bin >Synopsis: vmstat, printhdr() doesn't work correctly with -p option under multiple CPUs >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Wed Dec 01 11:00:21 UTC 2010 >Closed-Date: >Last-Modified: >Originator: Hiro Aki >Release: 8.1.0 >Organization: Any Command Reading Club >Environment: >Description: vmstat with -P option under multi-CPU environment doesn't display the header correctly if it has a cpu unavailable. the reason is below: in the function "printhdr()", ncpus is the number of CPUs available, not the number of all CPUs. so it might have the case that printf() is not called enough times for the number of all CPUs. 842: for (i = 0; i < ncpus; i++) { 843: if (cpumask & (1ul << i)) 844: printf("cpu%-2d ", i); 845: } on the other hand, "pcpustats()", which display the state of multiple CPUs, this works fine, using maxid which is the number of all CPUs. 1122: for (i = 0; i <= maxid; i++) { 1123: if ((cpumask & (1ul << i)) == 0) 1124: continue; 1125: for (state = 0; state < CPUSTATES; ++state) { 1126: tmp = cur_cp_times[i * CPUSTATES + state]; 1127: cur_cp_times[i * CPUSTATES + state] -= last_cp_times[i * CPUSTATES + state]; 1128: last_cp_times[i * CPUSTATES + state] = tmp; 1129: } 1130: } >How-To-Repeat: did the code inspection and haven't actually run the problem. don't have multi-cpu machine for the first place lol. >Fix: this is a patch for vmstat.c at revision 1.109 http://www.freebsd.org/cgi/cvsweb.cgi/~checkout~/src/usr.bin/vmstat/vmstat.c *** vmstat.c 2010-11-29 23:18:40.000000000 +0900 --- vmstatCorrected.c 2010-11-29 23:20:21.000000000 +0900 *************** *** 169,175 **** static void needhdr(int); static void needresize(int); static void doresize(void); ! static void printhdr(int, u_long); static void usage(void); static long pct(long, long); --- 169,175 ---- static void needhdr(int); static void needresize(int); static void doresize(void); ! static void printhdr(int, u_long, int); static void usage(void); static long pct(long, long); *************** *** 707,713 **** } for (hdrcnt = 1;;) { if (!--hdrcnt) ! printhdr(ncpus, cpumask); if (kd != NULL) { if (kvm_getcptime(kd, cur.cp_time) < 0) errx(1, "kvm_getcptime: %s", kvm_geterr(kd)); --- 707,713 ---- } for (hdrcnt = 1;;) { if (!--hdrcnt) ! printhdr(ncpus, cpumask, maxid); if (kd != NULL) { if (kvm_getcptime(kd, cur.cp_time) < 0) errx(1, "kvm_getcptime: %s", kvm_geterr(kd)); *************** *** 758,764 **** errx(1, "%s", devstat_errbuf); break; case 1: ! printhdr(ncpus, cpumask); break; default: break; --- 758,764 ---- errx(1, "%s", devstat_errbuf); break; case 1: ! printhdr(ncpus, cpumask, maxid); break; default: break; *************** *** 827,833 **** } static void ! printhdr(int ncpus, u_long cpumask) { int i, num_shown; --- 827,833 ---- } static void ! printhdr(int ncpus, u_long cpumask, int maxid) { int i, num_shown; *************** *** 839,845 **** (void)printf("disk"); (void)printf(" faults "); if (Pflag) { ! for (i = 0; i < ncpus; i++) { if (cpumask & (1ul << i)) printf("cpu%-2d ", i); } --- 839,845 ---- (void)printf("disk"); (void)printf(" faults "); if (Pflag) { ! for (i = 0; i <= maxid; i++) { if (cpumask & (1ul << i)) printf("cpu%-2d ", i); } >Release-Note: >Audit-Trail: >Unformatted: