Bug 152738 - [patch] vmstat(8), printhdr() doesn't work correctly with -p option under multiple CPUs
Summary: [patch] vmstat(8), printhdr() doesn't work correctly with -p option under mul...
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: Unspecified
Hardware: Any Any
: Normal Affects Only Me
Assignee: Hiroki Sato
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-12-01 11:00 UTC by Hiro Aki
Modified: 2014-09-10 22:38 UTC (History)
1 user (show)

See Also:


Attachments
file.diff (2.21 KB, patch)
2010-12-01 11:00 UTC, Hiro Aki
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Hiro Aki 2010-12-01 11:00:21 UTC
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:	}

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

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.
Comment 1 commit-hook freebsd_committer freebsd_triage 2014-09-10 22:34:31 UTC
A commit references this bug:

Author: hrs
Date: Wed Sep 10 22:34:08 UTC 2014
New revision: 271410
URL: http://svnweb.freebsd.org/changeset/base/271410

Log:
  Fix header output when -P is specified and (ncpus - 1) != maxid.

  Reported by:	Hiroaki Shimizu
  PR:		152738

Changes:
  head/usr.bin/vmstat/vmstat.c
Comment 2 Hiroki Sato freebsd_committer freebsd_triage 2014-09-10 22:38:17 UTC
Committed with a minor modification.  Thank you for your report.