History log of /freebsd-current/usr.bin/systat/vmstat.c
Revision Date Author Comments
# bdcbfde3 23-Nov-2023 Warner Losh <imp@FreeBSD.org>

usr.bin: Remove ancient SCCS tags.

Remove ancient SCCS tags from the tree, automated scripting, with two
minor fixup to keep things compiling. All the common forms in the tree
were removed with a perl script.

Sponsored by: Netflix


# e5d258c9 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

Remove $FreeBSD$: two-line .c pattern

Remove /^#include\s+<sys/cdefs.h>.*$\n\s+__FBSDID\("\$FreeBSD\$"\);\n/


# c9d1fa70 29-Jan-2022 Peter Jeremy <peterj@FreeBSD.org>

systat: Display seconds in vmstat mode

Providing a timestamp with seconds granularity helps make it obvious
that the display is updating.

Reviewed by: mckusick
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D29181


# a115a4aa 01-Jan-2022 Kirk McKusick <mckusick@FreeBSD.org>

systat -vm: Humanize output for ease of reading.

Using 8 width is too wide for large numbers like 1379991K;
1330M is easier to read.

Submitted by: ota_j.email.ne.jp
Reviewed by: mckusick
MFC after: 2 weeks
Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D33495


# 6d88f9fe 01-Nov-2021 Mateusz Guzik <mjg@FreeBSD.org>

systat: mostly clean up warns

Sponsored by: Rubicon Communications, LLC ("Netgate")


# dbb25cbe 24-Dec-2020 Stefan Eßer <se@FreeBSD.org>

Adjust to display more than 999 sleeping threads


# 2717b998 21-Nov-2020 Michael Reifenberger <mr@FreeBSD.org>

Improve number reading by rounding up to a next unit earlier for memory display.

Submitted by: ota@j.email.ne.jp
Differential Revision: https://reviews.freebsd.org/D26503


# 9a8fc6bb 15-May-2020 Michael Reifenberger <mr@FreeBSD.org>

Introduce sysputpage() to display large page size with human readable format.
Using UI units allows to fit larger numbers in columns.
Stop calling v_page_size - this is a value that doesn't change at runtime.
Renamed WINDOW *wnd to *wd to avoid conflict with global *wnd variable.
Use bit-shift to convert page size to byte.

PR: 246458
Submitted by: ota@j.email.ne.jp
MFC after: 2 weeks
Differential Revision: D24834


# 5452c16c 12-Jan-2020 Cy Schubert <cy@FreeBSD.org>

Sync with r356645. desiredvnodes is now maxvnodes.


# a4b840be 12-Jan-2020 Cy Schubert <cy@FreeBSD.org>

As of r356642 desiredvnodes is u_long.


# 45518845 02-Apr-2019 Michael Reifenberger <mr@FreeBSD.org>

systat -zarc to display disk activities like -vm

PR: 213310
Submitted by: ota
MFH: 4 weeks
Differential Revision: https://reviews.freebsd.org/D18726


# 1b7a3d1f 22-Nov-2017 Konstantin Belousov <kib@FreeBSD.org>

Order declarations alphabetically.
Match signess of the format and the value.

Noted by: bde
Sponsored by: The FreeBSD Foundation


# 90dd3e79 21-Nov-2017 Konstantin Belousov <kib@FreeBSD.org>

systat: use and correctly display 64bit counters.

Following struct vmtotal changes, make systat use and correctly
display 64-bit counters. Switch to humanize_number(3) to overcome
homegrown arithmetics limits in pretty printing large numbers. Use
1024 as a divisor for memory fields to make it consistent with other
tools and users expectations.

Submitted by: Pawel Biernacki <pawel.biernacki@gmail.com>
Sponsored by: Mysterious Code Ltd.
PR: 2137
Differential revision: https://reviews.freebsd.org/D13105


# 8a16b7a1 20-Nov-2017 Pedro F. Giffuni <pfg@FreeBSD.org>

General further adoption of SPDX licensing ID tags.

Mainly focus on files that use BSD 3-Clause license.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.

Special thanks to Wind River for providing access to "The Duke of
Highlander" tool: an older (2014) run over FreeBSD tree was useful as a
starting point.


# 795cd431 20-Apr-2017 Jung-uk Kim <jkim@FreeBSD.org>

Fix systat(1) regression. It was broken by r317061.


# fbbd9655 28-Feb-2017 Warner Losh <imp@FreeBSD.org>

Renumber copyright clause 4

Renumber cluase 4 to 3, per what everybody else did when BSD granted
them permission to remove clause 3. My insistance on keeping the same
numbering for legal reasons is too pedantic, so give up on that point.

Submitted by: Jan Schaumann <jschauma@stevens.edu>
Pull Request: https://github.com/freebsd/freebsd/pull/96


# cc59e3a7 10-Nov-2016 Mark Johnston <markj@FreeBSD.org>

Add the laundry page count to the displays of systat, top, and vmstat.

Reviewed by: alc, kib
Differential Revision: https://reviews.freebsd.org/D8467


# 18b14b44 27-Dec-2015 Marcelo Araujo <araujo@FreeBSD.org>

Add on systat -vm the ability to display the physical and kernel memory
percent usage.

PR: bin/203917
Submitted by: ota <ota@j.email.ne.jp>
Approved by: bapt (mentor)
Differential Revision: https://reviews.freebsd.org/D4281


# 1e902b3b 10-Sep-2015 Xin LI <delphij@FreeBSD.org>

- Avoid accessing window properties directly, instead, use accessors.
This should be no-op for now, but allows the code to work if we
move to NCURSES_OPAQUE.
- Use calloc() instead of malloc+bzero.

MFC after: 2 weeks


# 8d2419b5 23-Mar-2013 Alexander Motin <mav@FreeBSD.org>

Make `systat -vmstat` to use suffixes to display big floating point numbers
that are not fitting into the specified field width, same as done for ints.
In particular that allows to properly display disk tps above 100k, that are
reachable with modern SSDs.


# 9c02dc33 27-Jan-2013 Andrey Zonov <zont@FreeBSD.org>

- Show page faults requiring I/O on vmstat display.

Reviewed by: alc
MFC after: 2 weeks


# 2bd338d6 15-Oct-2011 Ed Schouten <ed@FreeBSD.org>

Fix whitespace inconsistencies in systat(1).

According to md5(1), the resulting binary is the same.


# da52b4ca 11-Dec-2010 Joel Dahl <joel@FreeBSD.org>

Remove the advertising clause from UCB copyrighted files in usr.bin. This
is in accordance with the information provided at
ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change

Also add $FreeBSD$ to a few files to keep svn happy.

Discussed with: imp, rwatson


# a7d5f7eb 19-Oct-2010 Jamie Gritton <jamie@FreeBSD.org>

A new jail(8) with a configuration file, to replace the work currently done
by /etc/rc.d/jail.


# 4b06d651 08-Sep-2010 Alexander Motin <mav@FreeBSD.org>

For total interrupt count on -vm screen count all interrupts, but not only
those which fit the screen.


# f91b7a25 18-Jul-2010 Alexander Motin <mav@FreeBSD.org>

Partially revert r209312, restoring ability to fit "stray irqX" names into
into available 10 characters by dropping "irq" in the middle of string.


# cb9c9783 18-Jun-2010 Alexander Motin <mav@FreeBSD.org>

Do not print first digits of IRQ number if whole number doesn't fit.


# fe0506d7 09-Mar-2010 Marcel Moolenaar <marcel@FreeBSD.org>

Create the altix project branch. The altix project will add support
for the SGI Altix 350 to FreeBSD/ia64. The hardware used for porting
is a two-module system, consisting of a base compute module and a
CPU expansion module. SGI's NUMAFlex architecture can be an excellent
platform to test CPU affinity and NUMA-aware features in FreeBSD.


# ab90a4d1 13-Jan-2010 Ed Schouten <ed@FreeBSD.org>

Perform all trivial ports to utmpx for usr.bin/.

They were already converted to use libulog, so it's easy to convert them
to utmpx.


# 821df508 12-Dec-2009 Xin LI <delphij@FreeBSD.org>

Revert most part of 200420 as requested, as more review and polish is
needed.


# 6f2d3221 11-Dec-2009 Xin LI <delphij@FreeBSD.org>

Remove unneeded header includes from usr.bin/ except contributed code.

Tested with: make universe


# 3487b134 05-Dec-2009 Ed Schouten <ed@FreeBSD.org>

Let systat's vmstat use utmpx.


# a0b9e7e3 10-Mar-2009 John Baldwin <jhb@FreeBSD.org>

Update top and systat for vfs.bufcache now being a long rather than an int.


# d7f03759 19-Oct-2008 Ulf Lilleengen <lulf@FreeBSD.org>

- Import the HEAD csup code which is the basis for the cvsmode work.


# 93b9f504 16-Jan-2008 Xin LI <delphij@FreeBSD.org>

ANSIfy and remove register.

Resulting binary verified with strip(1)+md5(1).


# bad4d172 27-Nov-2006 Ruslan Ermilov <ru@FreeBSD.org>

- Revert signedness type changes to "struct vmtotal"; by making
them unsigned I made the possible overflows hard to detect,
and it only saved 1 bit which isn't principal, even less now
that the underlying issue with the total of virtual memory has
been fixed. (For the record, it will overflow with >=2T of
VM total, with 32-bit ints used to keep counters in pages.)

- While here, fix printing of other "struct vmtotal" members
such as t_rq, t_dw, t_pw, and t_sw as they are also signed.

Reviewed by: bde
MFC after: 3 days


# 20739dfa 23-Nov-2006 Ruslan Ermilov <ru@FreeBSD.org>

Fix the format specifier suitable for uintmax_t.


# 5c88a11e 20-Nov-2006 Ruslan Ermilov <ru@FreeBSD.org>

- Fix types of "struct vmmeter" members so they are unsigned.

- Fix overflow bugs in sysctl(8), systat(1), and vmstat(8)
when printing values of "struct vmmeter" in kilobytes as
they don't necessarily fit into 32 bits. (Fix sysctl(8)
reporting of a total virtual memory; it's in pages too.)


# 04984aac 01-May-2006 Bruce Evans <bde@FreeBSD.org>

For the vmstat sub-display:

vmstat.c:
Move totfr to be under daefr and prcfr since it logically belongs there.

Move all the count fields (wire, act, inact, cache and free) to near
the bottom of the sub-display (after all the rate fields) to reduce
competition with adjoining sub-displays.

systat.1:
Move things as above.

Attempt to improve missing and poor wording in the description of the
fields. The long sentence was hard to parse and didn't say anything
about the different units.

Increment .Dd.


# 74a2149c 30-Apr-2006 Bruce Evans <bde@FreeBSD.org>

Unbreak the support for 24-row terminals in the vmstat display. The
part that handled the 17th and 18th rows of the vmstat-proper subdisplay
was deleted in rev.1.10 when these rows stopped being used and was not
restored when the 17th row was used again. For such terminals, we now
lose the `buf' field instead of making a mess with it. Terminals with
fewer than 24 rows have never been supported.

The problem is not avoided by using curses since we use the last line
for data entry and don't use a separate subwindow for this line.
Some other things in the vmstat display could be handled better using
subwindows.


# 1247d9c6 30-Apr-2006 Bruce Evans <bde@FreeBSD.org>

Sort the ex-extended vmstat fields into their documented order in the
output too.

Fine tune all coordinates and most field widths in the vmstat (sub)display
for this and previous changes now that we have to change almost all of them
just to move the ex-extended fields:
- change VMSTATROW back to 7. It was 6 due to a hack in the extended vm
stats changes.
- reduce the maximum field width that we try for from 9 to 8. 4 or 5 is
enough for most fields but we try to use the same width for all fields.
8 is enough to display everything without changing units memory sizes
exceed 100GB.

Fix some unrelated coordinates and field widths in comments.


# de9a857e 30-Apr-2006 Bruce Evans <bde@FreeBSD.org>

Eliminate the "extended" vm stats. Move all fields in the extended
vm stats to the normal vm stats. Sort them into the normal stats
according to the man page only in the source code so that diffs are
almost readable. Reduce style bugs in printing the value of %ozfod.


# 9177eda6 30-Apr-2006 Bruce Evans <bde@FreeBSD.org>

Reduce the namei (sub)display by 5 columns to make enough space for a
new vnstat display to the right of the namei display.

Move the non-vmstat fields {des,num,fre}vn from the vmstat display to a
new vnstat display. Move the dtbuf field there too. The buf and dtbuf
fields are non-vmstat and non-vnstat, so there is no good place to
display them. I need to move at least 1 of them out of the vm stats
for further cleanups of the vm stats, and there is only space for 1
of them in the vn stats. (The best place for the current buf field
is actually /dev/null, since it has been completely broken for about
10 years and broken for longer. It gives an uninteresting virtual
memory count where an interesting real memory count is wanted.)


# 3bccedcd 30-Apr-2006 Bruce Evans <bde@FreeBSD.org>

Don't redraw the disk names on every update. This was apparently done
to handle changes to the set of disks selected, but it is unnecessary
for that since the whole screen is redrawn when this set is changed.
It was also buggy:
- MAXDRIVES*6 = 42 was hard-coded as only 30 spaces in a string literal,
the last 2 disk names were not cleared as intended
- when the extended vmstats are active, clearing of even 30 columns
overruns the ozfod value field by 3 columns. This was harmless because
the field is much wider than necessary.


# 6e977072 30-Apr-2006 Bruce Evans <bde@FreeBSD.org>

Fix "slow (on-the-fly) zero fills percentage (`%slo-z')" some more. The
value printed is actually the optimized (i.e., the non-slow, not-on-the-fly
zero fills percentage) except in overflow cases. Describe it as %ozfod
in the display. Move the field descriptor 1 to the left so that there
is space for 5 characters after the % sign (this leaves no space between
the number and the descriptor but the % character serves well as a
separator).

Fixed integer overflow at z.ozfod = UINT_MAX/100 in the calculation of
%ozfod. This value can be reached just a few hours or minutes after
booting, so %ozfod was usually garbage in boot mode. Now %ozfod is
correct in boot mode for a few days or hours.

Print a non-dummy %ozfod when the division for it isn't division by 0
instead of when the result will be less than 100%. A result of 100%
may be correct, though a result of more than 100% indicates overflow
of one or both counters.


# 43f2757a 29-Apr-2006 Bruce Evans <bde@FreeBSD.org>

If DEBUG is defined, then fill numeric fields with asterisks instead of
spaces and numbers for temporary(?) debugging.


# 4545c625 29-Apr-2006 Bruce Evans <bde@FreeBSD.org>

Edit the interrupt name strings to shorten them. This is believed to
only affect amd64 and i386. alpha uses "intr N" instead of "irqN" and
mostly has no device names. ia64 uses only device names.

- Edit interrupt names once after they are read from the kernel and not
every time they are displayed.
- Discard bogus trailing spaces so that the next step doesn't move things
to oblivion.
- If an interrupt name starts with "irqN:" (as it usually does in on
amd64 and i386), then move "irqN" to the end and strip ":", since we
have no space for the ":" and don't want to start descriptions with
"N" after stripping "irq" in the next step (since "N" would look like
a count). This step may need reworking for interrupt names containing
several device names -- then moving the irq number to the end would
lose it instead of losing some device names.
- Remove "irq" from an interrupt name if and only if the original name is
too long to display.


# 18d3a03e 29-Apr-2006 Bruce Evans <bde@FreeBSD.org>

Backed out rev.1.49 since it had buffer overruns and only worked
accidentally.

Read buffer overruns:
The size of the target array (TSOTTA == 10) is a wrong limit to use for
scanning the source string.

Write buffer overruns:
TSOTTA is also a wrong limit to use for copying to the target buffer,
since we want to add a NUL terminator afterwards. TSOTTA was also 1
too small for holding both the desired number of visible characters
and the NUL.

Worked accidentally:
There is error in the algorithm that tends to result in the space saved
by stripping "irq" not actually being used, but some cases worked
accidentally provided "irqN" is near the end of the source string and
"N" is only 1 digit.

Starting with 5.mumble-CURRENT, "irqN" is at the beginning of the
string on all (?) arches that have it and the accidents don't happen.
E.g. on i386's, the keyboard irq is now named
"irq1: atkbd0<bogus blank padding>" by the kernel, and this name was
converted to "1: atkb" -- not only the device number but part of the
device name has been lost --, while before 5.mumble the kernel name
was "atkbd0 irq1" and systat accidentally preserved the irq number to
give "atkbd0 1". The ":" in the string wastes precious space, and
stripping "irq" results in descriptions starting with numbers which
makes them look too much like counts. This commit just fixes the last
problem.


# e76bdda0 29-Apr-2006 Bruce Evans <bde@FreeBSD.org>

Abbreviate long field descriptors at write time so that they don't get
clobbered at runtime:
dirtybuf -> dtbuf
desiredvnodes -> desvn
numvnodes -> numvn
freevnodes -> frevn
The vmstats column has only 5 characters available for descriptors, but up
to 13 were used. The extras get clobbered at runtime by interrupt values
and/or descriptors on systems with more than 12 interrupt sources.
%slo-z -> %sloz
This one is in the "extended" vmstats area and doesn't get clobbered now.

Removed stale documentation of desvn.

Changed a descriptor:
tfree -> totfr
so that it is consistent with the abbreviations for other free counts
(daefr and prcfr) and thus almost decodeable.

Fixed missing documentation of tfree/totfr. This and everything else
in the extended vmstats area is misdocumented as being in a certain
place in the vmstats column.


# 244bb595 17-Mar-2006 John-Mark Gurney <jmg@FreeBSD.org>

fix spelling of ozfod... I've been wondering why we'd need to fill a page
w/ non-zero data, and it turns out we don't... This is really optimized
zero filled on demand, or pages that were already zero'd for us...

MFC after: 3 days


# 8d40843a 14-Feb-2006 Bruce Evans <bde@FreeBSD.org>

Move the "r p d s w" fields to the left to create space for expansion.
3 columns were wasted at the left, except these columns were used to
make the header line up. Now there is no space on the same line for
the "Proc:" part of the header. Try putting this on the line above
although it clutters that line (there is already similar clutter for
the "Interrupts" header). Leave 1 column between these fields. With
the above and a previous change there is enough of space for this.

Use 5 columns instead of 3 for the number of users since 3 is not quite
enough and there was space to spare. This also fixes an off-by-2 error
in a previous fix forthe column count in the comment on STATROW.

Move all the pager fields 1 to the right so that the "count" and "pages"
descriptors more clearly apply to the pager fields and not the memory
fields. There was space to space.

Waste some of the spare space at the right of the pager fields to expand
all the pager field widths to their old values (but now with a column
between the fields). There are fields more in need of expansion but most
of them are not in places near spare space.


# cd8ad406 13-Feb-2006 Bruce Evans <bde@FreeBSD.org>

Removed the frobbing of CPU percentages from > 99.9 to 99.9. Rev.1.35
made it unnecessary. (Rev.1.6 had to reduce the field width to 4, and
changed 100.0 and preposterous larger values down to 99.9 since 100.0
wouldn't have fitted. Rev.1.35 handles precentages > 99.9 well enough by
changing the format to %.0f when the string given by the initial format
is too wide.)

Even with this change, during short testing I've never seen a percentage
of 100 being displayed by systat -v, although top(1) displays percentages
of 100 user or 100 idle for similar loads.


# 4bb97cfa 14-Feb-2006 Bruce Evans <bde@FreeBSD.org>

Fix some minor bugs:

Always use snprintf()'s return value, since discarding it is a style
bug at best and using it here gives slightly simpler code and better
error checking. Use snprintf() in putlongdouble() the same as in
putfloat(). (1.25 changed most sprintf()'s to snprintf()'s to fix
non-bugs without changing the logic to use the result of snprintf();
1.27 restored one of the sprintf()s by cloning a stale version of
putfloat().)

Don't print a too-long field in the unlikely case that the fallback
to M units in putint() leaves the field still too long. (The fallback
to printing stars was lost in rev.1.58 when the fallback to M units
was added.)


# 991d33c3 14-Feb-2006 Bruce Evans <bde@FreeBSD.org>

Reduce the field width by 1 for many numeric fields so that most fields
cannot run into other fields or field descriptors. If the value is
too large to fit in the field width, then the output format is adjusted
so that the value (usually) fits, but with fields running together
externally this adjustment usually didn't help. Mostly it doesn't
matter to lose 1 digit of precision, but switching the output format
is bad if it happens often or gives bogus units. The loss of width
is most serious for fields near "Csw" (which are also the ones which
must often ran together) since these have a high variance and large
values relative to the possible field widths so the switch occurs more
often now, and for the memory size fields where the switch gives the
bogus units kKB or MKB.

Now only the fields for r, p, d, s and w can run into each other.
These fields have width 3, and 3 cannot be reduced to 2 without losing
all precision when the value is between 100 and 999.

Trim "pdwake" to "pdwak" at think time now that it doesn't get clobbered
at runtime. The manpage doesn't need to be changed for this because
it documents the clobbered descriptor, unlike for 4 other too-long
descriptors which only get clobbered if there are lots of interrupt
sources.

Trim "% busy" to "%busy" since most other descriptors for percentages
are spelled without the space and this change makes changing the widths
of the %busy fields unnecessary.


# e3c53cce 14-Feb-2006 Bruce Evans <bde@FreeBSD.org>

Oops, the "excessive" {} removed in the previous commit was needed
around PUTRATE() because PUTRATE() only looked like a function -- it was
multiple statements. Use "do {...} while(0)" as usual in PUTRATE() so
that it is a single statement that can be used like a function.


# 123fa099 14-Feb-2006 Bruce Evans <bde@FreeBSD.org>

Fixed all (?) bitrot in the comments about the number of columns used by
various groups of fields.


# dc8ccdf0 14-Feb-2006 Bruce Evans <bde@FreeBSD.org>

Fix all (?) cases where the field width of a numeric field was far too
large. In most cases it is still 1 too large, so fields tend to run
together, but in the following cases it was more than 1 too large, and
the starting column was too small too, so the field started inside the
previous field or descriptor and clobbered that:
- "wire": the number for this overwrote 2 characters of the number for
"Flt". Reduce the field width by 3 (2 to avoid the overwrite and 1
so that the fields don't run together). This was already done for
the preceding number for "cow".
- "inact": the number for this overwrote 1 character of the descriptor
"Idle". Reducing the field width by 2 is enough.
- "cache:" the number for this overwrote 3 characters of the scale
"...| |". The field width should be reduced by 4 to keep things
from running together, but that is a lot and not so necessary here
since the final "|" in the scale serves as a delimiter. Only reduce
it by 3.
- "free": the number for this overwrote 2 characters of the bar graph.
The character position under the final "|" in the scale is apparently
not used, so reducing the field width by 3 is enough.

When "zfod" is in the main vmstat display:
- use the normal field width of 9 (not 5) for it since there is no shortage
of space. Fix style bugs (excessive {}) in the statement that
conditionally writes it.

Write all reduced field widths for vmstat fields as "9 - <reduction>" as
a hint that we don't want to reduce them.


# 10a84fd9 13-Feb-2006 Bruce Evans <bde@FreeBSD.org>

Fixed style bugs in rev.1.12. Rev.1.12 arranged to display the interrupt
number in more cases by stealing 2 characters from the count field to
give more space in the descriptor field, but it did the column adjustments
for this strangely using an off-by-2 error in the base column and
compensating off-by-2 errors in 6 offsets from the base column (4 new
errors and 2 from not changing the offsets that actually changed).

Print the "Interrupts" header directly at its offset from the base column
instead of spacing it half using the offset and half by printing a space
character.


# 043da612 21-Feb-2005 Paul Saab <ps@FreeBSD.org>

Fix an overflow when calculating the number of kilobytes from the
number of pages.

Obtained from: Yahoo!


# 84b4ac51 24-Oct-2003 Poul-Henning Kamp <phk@FreeBSD.org>

Use 'k' as suffix for Kilo

Pointed out by: several.


# f46a0535 20-Oct-2003 Poul-Henning Kamp <phk@FreeBSD.org>

When a numeric field overflows its width, try formatting the number in
'kilo' or 'mega' with appropriate suffix instead of filling the field
with stars.


# 1e3f260a 09-Apr-2003 Poul-Henning Kamp <phk@FreeBSD.org>

Let libdevstat calculate the device-busy % instead of home-rolling.


# 7194d335 15-Mar-2003 Poul-Henning Kamp <phk@FreeBSD.org>

Run a revision of the devstat interface:

Kernel:

Change statistics to use the *uptime() timescale (ie: relative to
boottime) rather than the UTC aligned timescale. This makes the
device statistics code oblivious to clock steps.

Change timestamps to bintime format, they are cheaper.

Remove the "busy_count", and replace it with two counter fields:
"start_count" and "end_count", which are updated in the down and
up paths respectively. This removes the locking constraint on
devstat.

Add a timestamp argument to devstat_start_transaction(), this will
normally be a timestamp set by the *_bio() function in bp->bio_t0.
Use this field to calculate duration of I/O operations.

Add two timestamp arguments to devstat_end_transaction(), one is
the current time, a NULL pointer means "take timestamp yourself",
the other is the timestamp of when this transaction started (see
above).

Change calculation of busy_time to operate on "the salami principle":
Only when we are idle, which we can determine by the start+end
counts being identical, do we update the "busy_from" field in the
down path. In the up path we accumulate the timeslice in busy_time
and update busy_from.

Change the byte_* and num_* fields into two arrays: bytes[] and
operations[].

Userland:

Change the misleading "busy_time" name to be called "snap_time" and
make the time long double since that is what most users need anyway,
fill it using clock_gettime(CLOCK_MONOTONIC) to put it on the same
timescale as the kernel fields.

Change devstat_compute_etime() to operate on struct bintime.

Remove the version 2 legacy interface: the change to bintime makes
compatibility far too expensive.

Fix a bug in systat's "vm" page where boot relative busy times would
be bogus.

Bump __FreeBSD_version to 500107

Review & Collaboration by: ken


# 3bd41074 16-Feb-2003 Poul-Henning Kamp <phk@FreeBSD.org>

Add #include <sys/resource.h>


# f341ca98 16-Feb-2003 Poul-Henning Kamp <phk@FreeBSD.org>

Remove #include <sys/dkstat.h>


# f7550ecf 11-Jan-2003 Matthew Dillon <dillon@FreeBSD.org>

Make 'sysctl vm.vmtotal' work properly using updated patch from Hiten.
(the patch in the PR was stale).

PR: kern/5689
Submitted by: Hiten Pandya <hiten@unixdaemons.com>


# a5426997 06-Jun-2002 Dag-Erling Smørgrav <des@FreeBSD.org>

debug.{numvnodes,freevnodes} moved to vfs.


# 3f330d7d 21-Mar-2002 Warner Losh <imp@FreeBSD.org>

remove __P


# 9ff712b0 11-Dec-2001 Mark Murray <markm@FreeBSD.org>

WARNS=2 fixes with NO_WERROR set, as there are some header issues
with namelists. use __FBSDID().


# 4b0ef38d 01-Dec-2001 Mark Murray <markm@FreeBSD.org>

Remove the 'irq' string from the irqN part of the "interrupts" display.
This allows us to see the irq number when device names ate too long.


# 8f29de8b 05-Sep-2001 Kenneth D. Merry <ken@FreeBSD.org>

Convert systat(1) to use the new devstat interface.

Submitted by: "Sergey A. Osokin" <osa@freebsd.org.ru>


# d62de5c4 01-Jun-2001 Thomas Moestl <tmm@FreeBSD.org>

Replace a use of the hw.nintr sysctl as it has just gone away, cast
size_t variables when passing them to a printf-like function, and some
minor cleanups.


# 0b8b714f 28-Mar-2001 Andrew Gallatin <gallatin@FreeBSD.org>

numdirtybuffers is an int, not a long.


# 342e2faa 22-Mar-2001 Thomas Moestl <tmm@FreeBSD.org>

Get rid of setgid kmem for systat, and while being there, fix some bugs
and compiler warnings.
The data for network statistics are still obtained via the kvm interface
if systat was started with the needed privileges, otherwise sysctls are
used. The reason for this is that with really many open sockets, the
sysctl method is probably slower, but it systat -netstat is probably not
really usable in either mode under these conditions.

Approved by: rwatson


# 6ab83137 21-Mar-2001 Andrey A. Chernov <ache@FreeBSD.org>

Don't attempt to parse %c


# 19f08522 02-Dec-2000 Andrew Gallatin <gallatin@FreeBSD.org>

Correct int/long type mismatch in the proper place this time. freevnodes
and numvnodes are longs in the kernel. They should remain longs in systat,
what really needs to change is that they should be using SYSCTL_LONG rather
than SYSCTL_INT. I also changed wantfreevnodes to SYSCTL_LONG because I
happened to notice it.

I wish there was a way to find all of these automatically..

Pointed out by: bde


# d468ee6f 01-Dec-2000 Andrew Gallatin <gallatin@FreeBSD.org>

fix int/long type mismatches found on alpha


# c3a27203 24-Nov-2000 Robert Watson <rwatson@FreeBSD.org>

o Make systat/vmstat.c use sysctl() to retrieve cp_time, bufspace,
maxvnodes, numvnodes, freevnodes, nchstats, and numdirtybuffers.
o Make the hw.ncpu error checking code a little more rigorous by
sanity checking the returned data size.
o Didn't fix machine-dependent non-sysctl-exported variables:
intrnames, eintrnames, intrcnt, eintrcnt, as these variables are
defined and exported from machine-dependent kernel code in
assembly. This should probably be fixed somehow.


# 9df46d4a 05-May-2000 Poul-Henning Kamp <phk@FreeBSD.org>

Don't include <sys/buf.h>


# 0e7f0658 14-Apr-2000 Warner Losh <imp@FreeBSD.org>

#include <errno.h> where needed. Kill extern int errno;.

Minor warnings in tip corrected.


# 2b543de8 19-Sep-1999 Brian Feldman <green@FreeBSD.org>

"Disks" is more correct than "Disks" could be.


# c3aac50f 27-Aug-1999 Peter Wemm <peter@FreeBSD.org>

$Id$ -> $FreeBSD$


# a4a026b4 30-Jul-1999 Dag-Erling Smørgrav <des@FreeBSD.org>

Show dirty buffers and the percentage of time a disk was busy.

PR: 12858
Submitted by: Arjan de Vet <Arjan.deVet@adv.iae.nl>


# 0af0a4b0 21-Mar-1999 Bruce Evans <bde@FreeBSD.org>

Display floats with format %*.0f instead of as "*****" if there is
enough space for this but not enough space for the normal %*.*f
format. Similarly for long doubles.


# 2d7142ca 07-Feb-1999 Matthew Dillon <dillon@FreeBSD.org>

Include discrete ozfod as well as ozfod/zfod percentage.


# 8b4c04d3 07-Feb-1999 Matthew Dillon <dillon@FreeBSD.org>

If there are 4 or fewer disk devices, we have room to display additional
VM statistics. zfod is moved and %slo-z ( percentage of zero-fills that
were slow, i.e. not pre-zero'd ), and number of pages freed per second.


# 154a13b5 08-Jan-1999 David E. O'Brien <obrien@FreeBSD.org>

revert to rev 1.29. (floppy drives will be gotten rid of another way)


# 4ae16510 27-Dec-1998 David E. O'Brien <obrien@FreeBSD.org>

Turn the compile time option into a run-time option.
You can now use the `want_fd' command in the vmstat display.

Suggested by: grog


# 5647c79d 27-Dec-1998 David E. O'Brien <obrien@FreeBSD.org>

Don't waste precious space on showing the performance of fdX.
(can get old behavior with -DWANT_FD)


# d22889b8 08-Oct-1998 David E. O'Brien <obrien@FreeBSD.org>

Quiet many compiler warnings.


# 2459ccb4 04-Oct-1998 Kenneth D. Merry <ken@FreeBSD.org>

Fix a core-dump situation in ":boot" mode in the vmstat display.

Reported by: bde


# 8d2fbde5 15-Sep-1998 Justin T. Gibbs <gibbs@FreeBSD.org>

Update system to new device statistics code.

Submitted by: "Kenneth D. Merry" <ken@plutotech.com>


# 81a4459b 06-Jul-1998 Bruce Evans <bde@FreeBSD.org>

Fixed type mismatches which were fatal when sizeof(long) > sizeof(int).


# 448b84a0 08-Jun-1998 Warner Losh <imp@FreeBSD.org>

o Use snprintf rather than sprintf
o Add more checks for buffer overflows
o Use snprintf rather than strcat/cpy and have better checks for max
length exceeded.

Most of these changes are not exploitable buffer overruns, but it never
hurts to be safe.

Inspired by and obtained from: OpenBSD


# 73cdb7fd 27-May-1998 John Hay <jhay@FreeBSD.org>

Correctly display the interrupt counts.
Reviewed with optimizations by: Tor Egge <tegge>


# 39253d4c 24-Sep-1997 Peter Wemm <peter@FreeBSD.org>

Show size of vnode pool in vmstat mode.


# d8793dfa 13-Aug-1997 Philippe Charnier <charnier@FreeBSD.org>

Use err(3). /sys/dkstat.h -> /usr/include/sys/dkstat.h


# b2ff494a 12-Nov-1996 Jordan K. Hubbard <jkh@FreeBSD.org>

Now that systat's working again, bring the vmstat cleanup over from
-stable.


# adb844d5 10-Nov-1996 Bruce Evans <bde@FreeBSD.org>

Initialize interrupt counters. The boot time values were displayed as ***.

Should be in 2.2.

Pointed out by: /etc/malloc.conf -> AJ


# 94591e17 11-Jun-1996 Jordan K. Hubbard <jkh@FreeBSD.org>

Cosmetic fixes for drive names which are 4 chars long.
Submitted-By: Joe Greco <jgreco@ns.sol.net>


# daab8558 31-Mar-1996 Andrey A. Chernov <ache@FreeBSD.org>

Localize time


# 0e08ab6f 29-Mar-1996 Bruce Evans <bde@FreeBSD.org>

Renamed Proc-cache to Dir-cache for the same reasons as in vmstat.
Tweaked screen positions to match.


# d376015e 13-Dec-1995 Bruce Evans <bde@FreeBSD.org>

Reduced vm dependencies. Only `struct vmmeter.h' is required.
Unfortunately, the sysctl number for reading this struct is
bogusly placed in <vm/vm_param.h> instead of with the declaration
of the struct.


# 0fe1bab6 13-Dec-1995 Peter Wemm <peter@FreeBSD.org>

Add explicit #include of <sys/vmmeter.h> after the last round of <vm/vm.h>
changes.


# 926e94cd 12-Jul-1995 Bruce Evans <bde@FreeBSD.org>

Don't attempt to read the variable `total' from the kernel. `total'
isn't used in systat or in the kernel (it was replaced by a sysctl()
call involving VM_METER) and will go away when I clean up bogus
common variables in the kernel.


# 7799f52a 30-May-1995 Rodney W. Grimes <rgrimes@FreeBSD.org>

Remove trailing whitespace.


# 90fef96d 28-Mar-1995 David Greenman <dg@FreeBSD.org>

From Mark Murray:

I got irritated with not seeing the interrupt numbers in a (crowded)
"systat -vmstat" display, so I fixed it. Here is a patch to please be
applied in src/usr.bin/systat


# ff93e578 25-Mar-1995 David Greenman <dg@FreeBSD.org>

Removed object lookup/hit count and changed the order of things a little.


# 1d93250f 24-Mar-1995 David Greenman <dg@FreeBSD.org>

Removed cnt.v_nzfod...we don't support it in the kernel.


# 475e2a7d 18-Mar-1995 Poul-Henning Kamp <phk@FreeBSD.org>

Fix the Name-cache counters. I didn't realign the negative hits.


# dc0b7482 11-Mar-1995 Poul-Henning Kamp <phk@FreeBSD.org>

Report the negative hits in the Namei section.


# 8950c014 10-Mar-1995 David Greenman <dg@FreeBSD.org>

Changes to support printing stats for the 'cached pages'.

Submitted by: John Dyson


# 3544ae54 03-Dec-1994 Bruce Evans <bde@FreeBSD.org>

extern.h, iostat.c, main.c, vmstat.c:
Use the correct value of hz (stathz if it is nonzero) for
interpretion of dk_time[] and cp_time[] in iostat.c. Avoid
multiple conversions of this value in iostat.c and vmstat.c

iostat.c:
Implement the display of cp_time[CP_INTR]. Fix the display
of cp_time[CP_IDLE] (the display was always null because
cp_time[CP_INTR] == 0 was displayed instead).

systat.1:
Document the display of cp_time[CP_INTR].

vmstat.c:
Implement the display of cp_time[CP_INTR].


# 293df9d6 24-Nov-1994 David Greenman <dg@FreeBSD.org>

Moved "VMSTAT" column up by one row so that it displays properly on 24
row displays.


# c58c4cd7 18-Oct-1994 David Greenman <dg@FreeBSD.org>

Updated to changes in struct vmmeter.


# 99e15595 15-Oct-1994 David Greenman <dg@FreeBSD.org>

Updated to changes in struct vmmeter.


# 104a0547 06-Aug-1994 Garrett Wollman <wollman@FreeBSD.org>

Make the %zfod display make more sense by comparing zfod versus the total
zfod + nzfod, rather than zfod / nzfod, which doesn't make a whole lot of sense.


# 9b50d902 26-May-1994 Rodney W. Grimes <rgrimes@FreeBSD.org>

BSD 4.4 Lite Usr.bin Sources