History log of /openbsd-current/usr.bin/systat/vmstat.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.96 28-Dec-2022 cheloha

systat(1): vmstat: dinfo(): compute rates using real elapsed time

The "naptime" value is not the real elapsed time. But showkre() has
the real elapsed time, "etime", so pass that as argument to dinfo().

Link: https://marc.info/?l=openbsd-tech&m=167095169115427&w=2

ok millert@


# 1.95 04-Dec-2022 cheloha

systat(1): vmstat: measure elapsed time with clock_gettime(2) instead of ticks

The vmstat view in systat(1) should not use statclock() ticks to count
elapsed time. First, ticks are low resolution. Second, the statclock
is sometimes randomized, so each tick is not necessarily of equal
length. Third, we're counting ticks from every CPU on the system, so
every rate in the view is divided by the number of CPUs. For example,
on an amd64 system with 8 CPUs you currently see:

200 clock

... when the true clock interrupt rate on that system is 1600.

Instead, measure elapsed time with clock_gettime(2). Use CLOCK_UPTIME
here so we exclude time when the system is suspended. With this
change we no longer need "stathz" or "hertz". We can also get rid of
the anachronistic secondary clock failure test.

Prompted by dlg@ and jmatthew@. deraadt@ says this has been in snaps
since 2022-11-21; no complaints.

Link: https://marc.info/?l=openbsd-tech&m=166898960831136&w=2

ok dlg@ deraadt@


Revision tags: OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.94 22-Feb-2022 deraadt

MAXCOMLEN is no longer needed in these programs, so remove the annotation
from sys/param.h include lines, or remove the include lines entirely if
it this was the least requirement.
ok millert


# 1.93 22-Feb-2022 deraadt

need a local nitems() definition


# 1.92 20-Feb-2022 deraadt

sys/proc.h requires sys/signal.h (will become visible when sys/param.h
is removed)


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.91 28-Jun-2019 deraadt

When system calls indicate an error they return -1, not some arbitrary
value < 0. errno is only updated in this case. Change all (most?)
callers of syscalls to follow this better, and let's see if this strictness
helps us in the future.


Revision tags: OPENBSD_6_5_BASE
# 1.90 20-Jan-2019 tedu

don't reuse global between functions; the value is wrong.
reported by Bryan Linton


# 1.89 17-Nov-2018 cheloha

Add new KERN_CPUSTATS sysctl(2) so we can identify offline CPUs.

Because of hw.smt we need a way to determine whether a given CPU is "online"
or "offline" from userspace. KERN_CPTIME2 is an array, and so cannot be
cleanly extended for this purpose, so add a new sysctl(2) KERN_CPUSTATS
with an extensible struct. At the moment it's just KERN_CPTIME2 with a
flags member, but it can grow as needed.

KERN_CPUSTATS appears to have been defined by BSDi long ago, but there are
few (if any) packages in the wild still using the symbol so breakage in ports
should be near zero. No other system inherited the symbol from BSDi, either.

Then, use the new sysctl(2) in systat(1) and top(1):

- systat(1) draws placeholder marks ('-') instead of percentages for
offline CPUs in the cpu view.

- systat(1) omits offline CPU ticks when drawing the "big bar" in
the vmstat view. The upshot is that the bar isn't half idle when
half your logical CPUs are disabled.

- top(1) does not draw lines for offline CPUs; if CPUs toggle on or
offline in interactive mode we redraw the display to expand/reduce
space for the new/missing CPUs. This is consistent with what some
top(1) implementations do on Linux.

- top(1) omits offline CPUs from the totals when CPU totals are
combined into a single line (the '-1' flag).

Originally prompted by deraadt@. Discussed endlessly with deraadt@,
ketennis@, and sthen@. Tested by jmc@ and jca@. Earlier versions also
discussed with jca@. Earlier versions tested by jmc@, tb@, and many
others.

docs ok jmc@, kernel bits ok ketennis@, everything ok sthen@,
"Is your stuff in yet?" deraadt@


Revision tags: OPENBSD_6_4_BASE
# 1.88 05-Oct-2018 cheloha

Revert KERN_CPTIME2 ENODEV changes in kernel and userspace.

ok kettenis deraadt


# 1.87 26-Sep-2018 cheloha

KERN_CPTIME2: set ENODEV if the CPU is offline.

This lets userspace distinguish between idle CPUs and those that are
not schedulable because hw.smt=0.

A subsequent commit probably needs to add documentation for this
to sysctl.2 (and perhaps elsewhere) after the dust settles.

Also included here are changes to systat(1) and top(1) that account
for the ENODEV case and adjust behavior accordingly:

- systat(1)'s cpu view prints placeholder marks ('-') instead of
percentages for each state if the given CPU is offline.

- systat(1)'s vmstat view checks for offline CPUs when computing the
machine state total and excludes them, so the CPU usage graph
only represents the states for online CPUs.

- top(1) does not draw CPU rows for offline CPUs when the view is
redrawn. If CPUs "go offline", percentages for each state are
replaced by placeholder marks ('-'); the view will need to be
redrawn to remove these rows. If CPUs "go online" the view will
need to be redrawn to show these new CPUs. In "combined CPU" mode,
the count and the state totals only represent online CPUs.

Ports using KERN_CPTIME2 will need to be updated. The changes
described above to make systat(1) and top(1) aware of the ENODEV
case *and* gracefully handle a changing HW_NCPUONLINE while the
application is running are not necessarily appropriate for each
and every port.

The changes described above are so extensive in part to demonstrate
one way a program *might* be made robust to changing CPU availability.
In particular, changing hw.smt after boot is an extremely rare event,
and this needs to be weighed when updating ports.

The logic needed to account for the KERN_CPTIME2 ENODEV case is
very roughly:

if (sysctl(...) == -1) {
if (errno != ENODEV) {
/* Actual error occurred. */
} else {
/* CPU is offline. */
}
} else {
/* CPU is online and CPU states were set by sysctl(2). */
}

Prompted by deraadt@. Basic idea for ENODEV from kettenis@. Discussed at
length with kettenis@. Additional testing by tb@.

No complaints from hackers@ after a week.

ok kettenis@, "I think you should commit [now]" deraadt@


# 1.86 22-Jun-2018 krw

Constrain IPKTS/OPKTS from floating down beyond the rest of the
displayed lines. Makes vmstat view in tall windows easier to read.

ok sthen@


# 1.85 19-May-2018 bluhm

Do not ignore nice time in systat(1). The sum would not be 100%,
a busy machine would look idle. As %Nic does not fit in the columns,
add it to %Usr. Introduce @ for spinning time to keep the characters
people are used to. Put %Spn between %Int and %Sys like in top.
OK visa@ mpi@


# 1.84 14-May-2018 mpi

Stopping counting and reporting CPU time spent spinning on a lock as
system time.

Introduce a new CP_SPIN "scheduler state" and modify userland tools
to display the % of timer a CPU spents spinning.

Based on a diff from jmatthew@, ok pirofti@, bluhm@, visa@, deraadt@


# 1.83 03-May-2018 otto

test for failing allocation using the standard idiom; prompted by Nan Xiao
ok tb@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.82 18-Dec-2016 krw

Remove statements that have no effect from X(), Y() and Z() #define's.
Leftovers from the re-engining of systat eight years ago. Makes gcc
quieter.

ok otto@ deraadt@


# 1.81 24-Aug-2016 guenther

Convert quad_t to int64_t and %q to %ll
Convert bzero() to memset() and bcopy() to memcpy()

ok natano@ millert@


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.80 20-Aug-2015 deraadt

Do not cast result of malloc/calloc/realloc* if stdlib.h is in scope
ok krw millert


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.79 16-Jan-2015 deraadt

first batch of programs adapting to the namespace cleanup
(pfvar.h nameser.h proc.h ucred.h)
ok guenther millert, and some review from doug as well.


# 1.78 23-Nov-2014 guenther

<sys/buf.h> isn't actually needed here

ok tedu@


# 1.77 15-Sep-2014 miod

Remove non-standard <sys/dkstat.h> header. It has not contained anything
related to disk stastics for almost 17 years, and the remaining
userland-visible defines duplicate those found in <sys/sched.h>.

Move the remaining _KERNEL defines to <sys/tty.h> where they belong, and
update all users to cope with this.

ok kettenis@


Revision tags: OPENBSD_5_6_BASE
# 1.76 08-Apr-2014 mpi

Use VM_UVMEXP instead of VM_METER for memory usages and directly
include <sys/vmmeter.h> where it is needed instead of relying on
it being included by <uvm/uvm_extern.h>.

miod@ likes it, ok guenther@


Revision tags: OPENBSD_5_5_BASE
# 1.75 31-Oct-2013 deraadt

sometimes we find .h we no longer need


Revision tags: OPENBSD_5_4_BASE
# 1.74 14-May-2013 miod

Don't display swapin/swapout uvmexp fields


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.73 19-Nov-2010 mikeb

Make KERN_CPTIME return an avarage number of ticks across all CPUs
tedu agreed with an idea, tested by Luis Useche and me; ok deraadt


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE
# 1.72 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


# 1.71 14-Aug-2009 deraadt

tie IPKTS/OPKTS to bottom corner for smaller screens


# 1.70 13-Aug-2009 deraadt

there are louder and louder moans about the inability to see packet
rates at the same time as interrupt counts, so sneak them into the
bottom corner of the vmstat screen
ok dlg


Revision tags: OPENBSD_4_6_BASE
# 1.69 03-May-2009 drahn

Hinge at the natural rollover point 9999x instead of 1024x when switching to
the next unit K->M->G. ok deraadt@


# 1.68 30-Mar-2009 deraadt

allow the disk transfer speed numbers to show useable numbers when disks
get really fast; ok canacar


Revision tags: OPENBSD_4_5_BASE
# 1.67 07-Dec-2008 canacar

Warning cleanup including unused variables and shadowed names


# 1.66 01-Nov-2008 canacar

Improve reporting of cache misses in the vmstat view. Previously
the misses field may report negative values. The hit/miss numbers
does not exactly reflect the statistics collected by the kernel
but this is close enough.

Report & patch from Bjorn Anderss, input from beck@ and thib@


Revision tags: OPENBSD_4_4_BASE
# 1.65 13-Jun-2008 deraadt

compile on older gcc; no decl after code


# 1.64 12-Jun-2008 canacar

New display engine for systat, based on pftop. Adds new views for pf
(status, state, rule, queue). While all displays work, some keyboard
comands are not implemented yet. Other features include better handling
of display resize and scrolling for long views. Committing now to fix
the remaining issues in the tree.
Testing and comments by otto@ and harding@, ok deraadt@


Revision tags: OPENBSD_4_3_BASE
# 1.63 01-Sep-2007 deraadt

malloc(n * m) -> calloc(n, m); from zinovik


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.62 25-Feb-2007 deraadt

use the 1 line load line from 'systat vm' on all the other displays, giving
them more room. much cleaner, and it is less code too; ok deanna


# 1.61 13-Nov-2006 otto

fix macro abuse leading to stray numbers in the vm display.
ok a whole lot of devs@


Revision tags: OPENBSD_4_0_BASE
# 1.60 14-Apr-2006 dlg

remove comments that says we dont count intr time and remove some code that
fudges the output to stay clean when intr time wasnt shown. not needed
since we show it now.


# 1.59 14-Apr-2006 dlg

show cpu time spent in interrupts. ive been wanting this for years.

tweaks by deraadt@ ok by many


# 1.58 31-Mar-2006 deraadt

spacing


# 1.57 31-Mar-2006 deraadt

fairly simple cleanup, lots of testing done


# 1.56 28-Mar-2006 mickey

give more space to the memory columns in vm page; deraadt@ ok


Revision tags: OPENBSD_3_9_BASE
# 1.55 28-Sep-2005 pedro

- when we run out of static kernel map entries, grab a fresh page using
the uvm_km_page allocator and use it instead of calling panic()
- add a counter to uvmexp so we can keep track of how many map entries
we have in use

idea from tedu@, long ago, okay deraadt@


Revision tags: OPENBSD_3_8_BASE
# 1.54 04-Apr-2005 deraadt

nlist.h not needed


Revision tags: OPENBSD_3_7_BASE
# 1.53 23-Sep-2004 deraadt

adapt to KERN_INTRCNT_CNT returning a quad, from danh (imported now to
avoid tree breakage)


Revision tags: OPENBSD_3_6_BASE
# 1.52 09-Jul-2004 deraadt

remove post-mortem stuff (sysctl only here)


# 1.51 28-Jun-2004 aaron

Remove special #if defined(__i386__) code from systat and vmstat. We now use
sysctl to fetch interrupt counters on all architectures. Also add new '-z'
flag to vmstat which means show all devices, even those that have not yet
generated an interrupt. deraadt@ tholo@ drahn@ millert@ ok


# 1.50 11-Jun-2004 deraadt

divide etime by ncpu


# 1.49 11-Jun-2004 deraadt

oops


# 1.48 11-Jun-2004 deraadt

on i386 machines, attempt to peek inside apic_intrhand[] as well, so that
MP machines get interrupt counters. will be replaced by a MI subsystem
one day. most code from drahn, few final bugs fixed by me


# 1.47 22-May-2004 henning

with modern disks data transfers rates above 10000 kByte/s are seen
regularily, make the disk columns a little wider so it doesn't run into
the neighboring column, theo ok


# 1.46 23-Apr-2004 tedu

don't print stats until they're stable, prevents seeing weird stuff in
disk columns. tested by jolan@. from pedro martelletto


Revision tags: OPENBSD_3_5_BASE
# 1.45 15-Feb-2004 tedu

'split' command for iostat mode
from Pedro Martelletto <pbastos@rdc.puc-rio.br>


# 1.44 15-Feb-2004 tedu

new arg to disk_unbusy, to record separate read/write statistics.
looked at by various, testing henning@ mcbride@ dan weeks
mostly from netbsd via Pedro Martelletto <pbastos@rdc.puc-rio.br>


# 1.43 16-Oct-2003 mickey

duh


# 1.42 15-Oct-2003 mickey

also print the uvmexp.zeropages if there is space in vm screen


Revision tags: OPENBSD_3_4_BASE
# 1.41 03-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


# 1.40 14-Apr-2003 deraadt

remove old comment


# 1.39 08-Apr-2003 deraadt

string cleaning; ok tdeval


Revision tags: OPENBSD_3_3_BASE
# 1.38 28-Feb-2003 jason

intrcnt's are ints not longs (at least according to the new kern.intrcnt stuff)


# 1.37 16-Dec-2002 tdeval

Make systat(1), iostat(8) and vmstat(8) automatically update their disk
statistics when a device is added/removed. ok deraadt@


Revision tags: OPENBSD_3_2_BASE
# 1.36 19-Jun-2002 deraadt

mark which nlist[] kmem entries are not needed in the sysctl case, and which are


# 1.35 18-Jun-2002 deraadt

ANSI


# 1.34 29-Apr-2002 millert

Fix 32bit int oflow when there is > 2GB vm; peters AT telia DOT net


Revision tags: OPENBSD_3_1_BASE
# 1.33 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


# 1.32 16-Feb-2002 tdeval

Some disk names are longer than 4. Cope with that.
ok deraadt@


# 1.31 07-Dec-2001 deraadt

move back. pvalchev -- the bug was quite obscure


# 1.30 07-Dec-2001 pvalchev

back out latest changes which cause problems on alpha/sparc64 until
they are fixed


# 1.29 23-Nov-2001 deraadt

fix signal races. use sysctl() instead of kvm where possible, and then KNF
the hell out of it; checked by miod


# 1.28 19-Nov-2001 mpech

kill more registers

millert@ ok


# 1.27 18-Nov-2001 deraadt

slightly expand the Csw/Trp/Sys/Int/Sof spacing


# 1.26 06-Nov-2001 art

New vm includes.


Revision tags: OPENBSD_3_0_BASE
# 1.25 28-Aug-2001 weingart

Add information on number/percentage of namei calls missed the cache.
millert@ ok.


# 1.24 27-Jun-2001 art

UVM is no longer an option


# 1.23 22-Jun-2001 lebel

use strlcpy vs strncpy+a[len-1]='\0'


# 1.22 04-May-2001 ericj

handle kvm_nlist() failing, from pr#1798.
Patch similar to the one submitted by <peterw@documenta.com.au>


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.21 22-Feb-2000 deraadt

_total is no longer a symbol in the kernel


# 1.20 26-Oct-1999 art

Fix printing of interrupts with UVM.


# 1.19 26-Oct-1999 art

support UVM. (much code from NetBSD)


Revision tags: OPENBSD_2_6_BASE
# 1.18 16-Jun-1999 espie

Fixed i386 -> __i386__


Revision tags: OPENBSD_2_5_BASE
# 1.17 19-Dec-1998 deraadt

move Act Free field over one


Revision tags: OPENBSD_2_4_BASE
# 1.16 13-Jul-1998 millert

ftpd: sleep for an indeterminate amount for non-existant logins
to simulate a crypt, like login does.
Use SEEK_* not L_* and kill some 0L's used in lseek while we're there.


# 1.15 12-Jun-1998 marc

fix vm load display


Revision tags: OPENBSD_2_3_BASE
# 1.14 19-Dec-1997 deraadt

comment this strncpy is safe


# 1.13 19-Dec-1997 deraadt

proactive buffer blocks


# 1.12 19-Dec-1997 deraadt

bye bye sprintf


# 1.11 24-Nov-1997 kstailey

Deal with the fact that PUTRATE() is a macro that contains braces by
surrounding it with braces after an ``if ()''.


# 1.10 22-Nov-1997 mickey

remove unused kernel vars


# 1.9 22-Nov-1997 kstailey

back out 1.8, will fix in another way.


# 1.8 22-Nov-1997 kstailey

Make vmstat mode display actually fit in 80x24.
Exploits fact that swap display is always blank.


Revision tags: OPENBSD_2_2_BASE
# 1.7 29-Jul-1997 flipk

delete accidental #if 0


# 1.6 29-Jul-1997 flipk

1) display full time string in 'vmstat' display so you can tell
the difference between an inactive display and a hung machine.
2) Update the man page for 'vmstat' to reflect reality (and actually
explain all those vm abbreviations).

netbsd PR bin/2756 (Jonathan Stone <jonathan@DSG.Stanford.EDU>


Revision tags: OPENBSD_2_1_BASE
# 1.5 20-Dec-1996 downsj

support four letter device names


Revision tags: OPENBSD_2_0_BASE
# 1.4 26-Jun-1996 deraadt

rcsid


# 1.3 25-Jun-1996 tholo

Show interrupt counts on i386.


# 1.2 22-May-1996 deraadt

libutil


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.95 04-Dec-2022 cheloha

systat(1): vmstat: measure elapsed time with clock_gettime(2) instead of ticks

The vmstat view in systat(1) should not use statclock() ticks to count
elapsed time. First, ticks are low resolution. Second, the statclock
is sometimes randomized, so each tick is not necessarily of equal
length. Third, we're counting ticks from every CPU on the system, so
every rate in the view is divided by the number of CPUs. For example,
on an amd64 system with 8 CPUs you currently see:

200 clock

... when the true clock interrupt rate on that system is 1600.

Instead, measure elapsed time with clock_gettime(2). Use CLOCK_UPTIME
here so we exclude time when the system is suspended. With this
change we no longer need "stathz" or "hertz". We can also get rid of
the anachronistic secondary clock failure test.

Prompted by dlg@ and jmatthew@. deraadt@ says this has been in snaps
since 2022-11-21; no complaints.

Link: https://marc.info/?l=openbsd-tech&m=166898960831136&w=2

ok dlg@ deraadt@


Revision tags: OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.94 22-Feb-2022 deraadt

MAXCOMLEN is no longer needed in these programs, so remove the annotation
from sys/param.h include lines, or remove the include lines entirely if
it this was the least requirement.
ok millert


# 1.93 22-Feb-2022 deraadt

need a local nitems() definition


# 1.92 20-Feb-2022 deraadt

sys/proc.h requires sys/signal.h (will become visible when sys/param.h
is removed)


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.91 28-Jun-2019 deraadt

When system calls indicate an error they return -1, not some arbitrary
value < 0. errno is only updated in this case. Change all (most?)
callers of syscalls to follow this better, and let's see if this strictness
helps us in the future.


Revision tags: OPENBSD_6_5_BASE
# 1.90 20-Jan-2019 tedu

don't reuse global between functions; the value is wrong.
reported by Bryan Linton


# 1.89 17-Nov-2018 cheloha

Add new KERN_CPUSTATS sysctl(2) so we can identify offline CPUs.

Because of hw.smt we need a way to determine whether a given CPU is "online"
or "offline" from userspace. KERN_CPTIME2 is an array, and so cannot be
cleanly extended for this purpose, so add a new sysctl(2) KERN_CPUSTATS
with an extensible struct. At the moment it's just KERN_CPTIME2 with a
flags member, but it can grow as needed.

KERN_CPUSTATS appears to have been defined by BSDi long ago, but there are
few (if any) packages in the wild still using the symbol so breakage in ports
should be near zero. No other system inherited the symbol from BSDi, either.

Then, use the new sysctl(2) in systat(1) and top(1):

- systat(1) draws placeholder marks ('-') instead of percentages for
offline CPUs in the cpu view.

- systat(1) omits offline CPU ticks when drawing the "big bar" in
the vmstat view. The upshot is that the bar isn't half idle when
half your logical CPUs are disabled.

- top(1) does not draw lines for offline CPUs; if CPUs toggle on or
offline in interactive mode we redraw the display to expand/reduce
space for the new/missing CPUs. This is consistent with what some
top(1) implementations do on Linux.

- top(1) omits offline CPUs from the totals when CPU totals are
combined into a single line (the '-1' flag).

Originally prompted by deraadt@. Discussed endlessly with deraadt@,
ketennis@, and sthen@. Tested by jmc@ and jca@. Earlier versions also
discussed with jca@. Earlier versions tested by jmc@, tb@, and many
others.

docs ok jmc@, kernel bits ok ketennis@, everything ok sthen@,
"Is your stuff in yet?" deraadt@


Revision tags: OPENBSD_6_4_BASE
# 1.88 05-Oct-2018 cheloha

Revert KERN_CPTIME2 ENODEV changes in kernel and userspace.

ok kettenis deraadt


# 1.87 26-Sep-2018 cheloha

KERN_CPTIME2: set ENODEV if the CPU is offline.

This lets userspace distinguish between idle CPUs and those that are
not schedulable because hw.smt=0.

A subsequent commit probably needs to add documentation for this
to sysctl.2 (and perhaps elsewhere) after the dust settles.

Also included here are changes to systat(1) and top(1) that account
for the ENODEV case and adjust behavior accordingly:

- systat(1)'s cpu view prints placeholder marks ('-') instead of
percentages for each state if the given CPU is offline.

- systat(1)'s vmstat view checks for offline CPUs when computing the
machine state total and excludes them, so the CPU usage graph
only represents the states for online CPUs.

- top(1) does not draw CPU rows for offline CPUs when the view is
redrawn. If CPUs "go offline", percentages for each state are
replaced by placeholder marks ('-'); the view will need to be
redrawn to remove these rows. If CPUs "go online" the view will
need to be redrawn to show these new CPUs. In "combined CPU" mode,
the count and the state totals only represent online CPUs.

Ports using KERN_CPTIME2 will need to be updated. The changes
described above to make systat(1) and top(1) aware of the ENODEV
case *and* gracefully handle a changing HW_NCPUONLINE while the
application is running are not necessarily appropriate for each
and every port.

The changes described above are so extensive in part to demonstrate
one way a program *might* be made robust to changing CPU availability.
In particular, changing hw.smt after boot is an extremely rare event,
and this needs to be weighed when updating ports.

The logic needed to account for the KERN_CPTIME2 ENODEV case is
very roughly:

if (sysctl(...) == -1) {
if (errno != ENODEV) {
/* Actual error occurred. */
} else {
/* CPU is offline. */
}
} else {
/* CPU is online and CPU states were set by sysctl(2). */
}

Prompted by deraadt@. Basic idea for ENODEV from kettenis@. Discussed at
length with kettenis@. Additional testing by tb@.

No complaints from hackers@ after a week.

ok kettenis@, "I think you should commit [now]" deraadt@


# 1.86 22-Jun-2018 krw

Constrain IPKTS/OPKTS from floating down beyond the rest of the
displayed lines. Makes vmstat view in tall windows easier to read.

ok sthen@


# 1.85 19-May-2018 bluhm

Do not ignore nice time in systat(1). The sum would not be 100%,
a busy machine would look idle. As %Nic does not fit in the columns,
add it to %Usr. Introduce @ for spinning time to keep the characters
people are used to. Put %Spn between %Int and %Sys like in top.
OK visa@ mpi@


# 1.84 14-May-2018 mpi

Stopping counting and reporting CPU time spent spinning on a lock as
system time.

Introduce a new CP_SPIN "scheduler state" and modify userland tools
to display the % of timer a CPU spents spinning.

Based on a diff from jmatthew@, ok pirofti@, bluhm@, visa@, deraadt@


# 1.83 03-May-2018 otto

test for failing allocation using the standard idiom; prompted by Nan Xiao
ok tb@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.82 18-Dec-2016 krw

Remove statements that have no effect from X(), Y() and Z() #define's.
Leftovers from the re-engining of systat eight years ago. Makes gcc
quieter.

ok otto@ deraadt@


# 1.81 24-Aug-2016 guenther

Convert quad_t to int64_t and %q to %ll
Convert bzero() to memset() and bcopy() to memcpy()

ok natano@ millert@


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.80 20-Aug-2015 deraadt

Do not cast result of malloc/calloc/realloc* if stdlib.h is in scope
ok krw millert


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.79 16-Jan-2015 deraadt

first batch of programs adapting to the namespace cleanup
(pfvar.h nameser.h proc.h ucred.h)
ok guenther millert, and some review from doug as well.


# 1.78 23-Nov-2014 guenther

<sys/buf.h> isn't actually needed here

ok tedu@


# 1.77 15-Sep-2014 miod

Remove non-standard <sys/dkstat.h> header. It has not contained anything
related to disk stastics for almost 17 years, and the remaining
userland-visible defines duplicate those found in <sys/sched.h>.

Move the remaining _KERNEL defines to <sys/tty.h> where they belong, and
update all users to cope with this.

ok kettenis@


Revision tags: OPENBSD_5_6_BASE
# 1.76 08-Apr-2014 mpi

Use VM_UVMEXP instead of VM_METER for memory usages and directly
include <sys/vmmeter.h> where it is needed instead of relying on
it being included by <uvm/uvm_extern.h>.

miod@ likes it, ok guenther@


Revision tags: OPENBSD_5_5_BASE
# 1.75 31-Oct-2013 deraadt

sometimes we find .h we no longer need


Revision tags: OPENBSD_5_4_BASE
# 1.74 14-May-2013 miod

Don't display swapin/swapout uvmexp fields


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.73 19-Nov-2010 mikeb

Make KERN_CPTIME return an avarage number of ticks across all CPUs
tedu agreed with an idea, tested by Luis Useche and me; ok deraadt


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE
# 1.72 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


# 1.71 14-Aug-2009 deraadt

tie IPKTS/OPKTS to bottom corner for smaller screens


# 1.70 13-Aug-2009 deraadt

there are louder and louder moans about the inability to see packet
rates at the same time as interrupt counts, so sneak them into the
bottom corner of the vmstat screen
ok dlg


Revision tags: OPENBSD_4_6_BASE
# 1.69 03-May-2009 drahn

Hinge at the natural rollover point 9999x instead of 1024x when switching to
the next unit K->M->G. ok deraadt@


# 1.68 30-Mar-2009 deraadt

allow the disk transfer speed numbers to show useable numbers when disks
get really fast; ok canacar


Revision tags: OPENBSD_4_5_BASE
# 1.67 07-Dec-2008 canacar

Warning cleanup including unused variables and shadowed names


# 1.66 01-Nov-2008 canacar

Improve reporting of cache misses in the vmstat view. Previously
the misses field may report negative values. The hit/miss numbers
does not exactly reflect the statistics collected by the kernel
but this is close enough.

Report & patch from Bjorn Anderss, input from beck@ and thib@


Revision tags: OPENBSD_4_4_BASE
# 1.65 13-Jun-2008 deraadt

compile on older gcc; no decl after code


# 1.64 12-Jun-2008 canacar

New display engine for systat, based on pftop. Adds new views for pf
(status, state, rule, queue). While all displays work, some keyboard
comands are not implemented yet. Other features include better handling
of display resize and scrolling for long views. Committing now to fix
the remaining issues in the tree.
Testing and comments by otto@ and harding@, ok deraadt@


Revision tags: OPENBSD_4_3_BASE
# 1.63 01-Sep-2007 deraadt

malloc(n * m) -> calloc(n, m); from zinovik


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.62 25-Feb-2007 deraadt

use the 1 line load line from 'systat vm' on all the other displays, giving
them more room. much cleaner, and it is less code too; ok deanna


# 1.61 13-Nov-2006 otto

fix macro abuse leading to stray numbers in the vm display.
ok a whole lot of devs@


Revision tags: OPENBSD_4_0_BASE
# 1.60 14-Apr-2006 dlg

remove comments that says we dont count intr time and remove some code that
fudges the output to stay clean when intr time wasnt shown. not needed
since we show it now.


# 1.59 14-Apr-2006 dlg

show cpu time spent in interrupts. ive been wanting this for years.

tweaks by deraadt@ ok by many


# 1.58 31-Mar-2006 deraadt

spacing


# 1.57 31-Mar-2006 deraadt

fairly simple cleanup, lots of testing done


# 1.56 28-Mar-2006 mickey

give more space to the memory columns in vm page; deraadt@ ok


Revision tags: OPENBSD_3_9_BASE
# 1.55 28-Sep-2005 pedro

- when we run out of static kernel map entries, grab a fresh page using
the uvm_km_page allocator and use it instead of calling panic()
- add a counter to uvmexp so we can keep track of how many map entries
we have in use

idea from tedu@, long ago, okay deraadt@


Revision tags: OPENBSD_3_8_BASE
# 1.54 04-Apr-2005 deraadt

nlist.h not needed


Revision tags: OPENBSD_3_7_BASE
# 1.53 23-Sep-2004 deraadt

adapt to KERN_INTRCNT_CNT returning a quad, from danh (imported now to
avoid tree breakage)


Revision tags: OPENBSD_3_6_BASE
# 1.52 09-Jul-2004 deraadt

remove post-mortem stuff (sysctl only here)


# 1.51 28-Jun-2004 aaron

Remove special #if defined(__i386__) code from systat and vmstat. We now use
sysctl to fetch interrupt counters on all architectures. Also add new '-z'
flag to vmstat which means show all devices, even those that have not yet
generated an interrupt. deraadt@ tholo@ drahn@ millert@ ok


# 1.50 11-Jun-2004 deraadt

divide etime by ncpu


# 1.49 11-Jun-2004 deraadt

oops


# 1.48 11-Jun-2004 deraadt

on i386 machines, attempt to peek inside apic_intrhand[] as well, so that
MP machines get interrupt counters. will be replaced by a MI subsystem
one day. most code from drahn, few final bugs fixed by me


# 1.47 22-May-2004 henning

with modern disks data transfers rates above 10000 kByte/s are seen
regularily, make the disk columns a little wider so it doesn't run into
the neighboring column, theo ok


# 1.46 23-Apr-2004 tedu

don't print stats until they're stable, prevents seeing weird stuff in
disk columns. tested by jolan@. from pedro martelletto


Revision tags: OPENBSD_3_5_BASE
# 1.45 15-Feb-2004 tedu

'split' command for iostat mode
from Pedro Martelletto <pbastos@rdc.puc-rio.br>


# 1.44 15-Feb-2004 tedu

new arg to disk_unbusy, to record separate read/write statistics.
looked at by various, testing henning@ mcbride@ dan weeks
mostly from netbsd via Pedro Martelletto <pbastos@rdc.puc-rio.br>


# 1.43 16-Oct-2003 mickey

duh


# 1.42 15-Oct-2003 mickey

also print the uvmexp.zeropages if there is space in vm screen


Revision tags: OPENBSD_3_4_BASE
# 1.41 03-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


# 1.40 14-Apr-2003 deraadt

remove old comment


# 1.39 08-Apr-2003 deraadt

string cleaning; ok tdeval


Revision tags: OPENBSD_3_3_BASE
# 1.38 28-Feb-2003 jason

intrcnt's are ints not longs (at least according to the new kern.intrcnt stuff)


# 1.37 16-Dec-2002 tdeval

Make systat(1), iostat(8) and vmstat(8) automatically update their disk
statistics when a device is added/removed. ok deraadt@


Revision tags: OPENBSD_3_2_BASE
# 1.36 19-Jun-2002 deraadt

mark which nlist[] kmem entries are not needed in the sysctl case, and which are


# 1.35 18-Jun-2002 deraadt

ANSI


# 1.34 29-Apr-2002 millert

Fix 32bit int oflow when there is > 2GB vm; peters AT telia DOT net


Revision tags: OPENBSD_3_1_BASE
# 1.33 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


# 1.32 16-Feb-2002 tdeval

Some disk names are longer than 4. Cope with that.
ok deraadt@


# 1.31 07-Dec-2001 deraadt

move back. pvalchev -- the bug was quite obscure


# 1.30 07-Dec-2001 pvalchev

back out latest changes which cause problems on alpha/sparc64 until
they are fixed


# 1.29 23-Nov-2001 deraadt

fix signal races. use sysctl() instead of kvm where possible, and then KNF
the hell out of it; checked by miod


# 1.28 19-Nov-2001 mpech

kill more registers

millert@ ok


# 1.27 18-Nov-2001 deraadt

slightly expand the Csw/Trp/Sys/Int/Sof spacing


# 1.26 06-Nov-2001 art

New vm includes.


Revision tags: OPENBSD_3_0_BASE
# 1.25 28-Aug-2001 weingart

Add information on number/percentage of namei calls missed the cache.
millert@ ok.


# 1.24 27-Jun-2001 art

UVM is no longer an option


# 1.23 22-Jun-2001 lebel

use strlcpy vs strncpy+a[len-1]='\0'


# 1.22 04-May-2001 ericj

handle kvm_nlist() failing, from pr#1798.
Patch similar to the one submitted by <peterw@documenta.com.au>


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.21 22-Feb-2000 deraadt

_total is no longer a symbol in the kernel


# 1.20 26-Oct-1999 art

Fix printing of interrupts with UVM.


# 1.19 26-Oct-1999 art

support UVM. (much code from NetBSD)


Revision tags: OPENBSD_2_6_BASE
# 1.18 16-Jun-1999 espie

Fixed i386 -> __i386__


Revision tags: OPENBSD_2_5_BASE
# 1.17 19-Dec-1998 deraadt

move Act Free field over one


Revision tags: OPENBSD_2_4_BASE
# 1.16 13-Jul-1998 millert

ftpd: sleep for an indeterminate amount for non-existant logins
to simulate a crypt, like login does.
Use SEEK_* not L_* and kill some 0L's used in lseek while we're there.


# 1.15 12-Jun-1998 marc

fix vm load display


Revision tags: OPENBSD_2_3_BASE
# 1.14 19-Dec-1997 deraadt

comment this strncpy is safe


# 1.13 19-Dec-1997 deraadt

proactive buffer blocks


# 1.12 19-Dec-1997 deraadt

bye bye sprintf


# 1.11 24-Nov-1997 kstailey

Deal with the fact that PUTRATE() is a macro that contains braces by
surrounding it with braces after an ``if ()''.


# 1.10 22-Nov-1997 mickey

remove unused kernel vars


# 1.9 22-Nov-1997 kstailey

back out 1.8, will fix in another way.


# 1.8 22-Nov-1997 kstailey

Make vmstat mode display actually fit in 80x24.
Exploits fact that swap display is always blank.


Revision tags: OPENBSD_2_2_BASE
# 1.7 29-Jul-1997 flipk

delete accidental #if 0


# 1.6 29-Jul-1997 flipk

1) display full time string in 'vmstat' display so you can tell
the difference between an inactive display and a hung machine.
2) Update the man page for 'vmstat' to reflect reality (and actually
explain all those vm abbreviations).

netbsd PR bin/2756 (Jonathan Stone <jonathan@DSG.Stanford.EDU>


Revision tags: OPENBSD_2_1_BASE
# 1.5 20-Dec-1996 downsj

support four letter device names


Revision tags: OPENBSD_2_0_BASE
# 1.4 26-Jun-1996 deraadt

rcsid


# 1.3 25-Jun-1996 tholo

Show interrupt counts on i386.


# 1.2 22-May-1996 deraadt

libutil


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.94 22-Feb-2022 deraadt

MAXCOMLEN is no longer needed in these programs, so remove the annotation
from sys/param.h include lines, or remove the include lines entirely if
it this was the least requirement.
ok millert


# 1.93 22-Feb-2022 deraadt

need a local nitems() definition


# 1.92 20-Feb-2022 deraadt

sys/proc.h requires sys/signal.h (will become visible when sys/param.h
is removed)


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.91 28-Jun-2019 deraadt

When system calls indicate an error they return -1, not some arbitrary
value < 0. errno is only updated in this case. Change all (most?)
callers of syscalls to follow this better, and let's see if this strictness
helps us in the future.


Revision tags: OPENBSD_6_5_BASE
# 1.90 20-Jan-2019 tedu

don't reuse global between functions; the value is wrong.
reported by Bryan Linton


# 1.89 17-Nov-2018 cheloha

Add new KERN_CPUSTATS sysctl(2) so we can identify offline CPUs.

Because of hw.smt we need a way to determine whether a given CPU is "online"
or "offline" from userspace. KERN_CPTIME2 is an array, and so cannot be
cleanly extended for this purpose, so add a new sysctl(2) KERN_CPUSTATS
with an extensible struct. At the moment it's just KERN_CPTIME2 with a
flags member, but it can grow as needed.

KERN_CPUSTATS appears to have been defined by BSDi long ago, but there are
few (if any) packages in the wild still using the symbol so breakage in ports
should be near zero. No other system inherited the symbol from BSDi, either.

Then, use the new sysctl(2) in systat(1) and top(1):

- systat(1) draws placeholder marks ('-') instead of percentages for
offline CPUs in the cpu view.

- systat(1) omits offline CPU ticks when drawing the "big bar" in
the vmstat view. The upshot is that the bar isn't half idle when
half your logical CPUs are disabled.

- top(1) does not draw lines for offline CPUs; if CPUs toggle on or
offline in interactive mode we redraw the display to expand/reduce
space for the new/missing CPUs. This is consistent with what some
top(1) implementations do on Linux.

- top(1) omits offline CPUs from the totals when CPU totals are
combined into a single line (the '-1' flag).

Originally prompted by deraadt@. Discussed endlessly with deraadt@,
ketennis@, and sthen@. Tested by jmc@ and jca@. Earlier versions also
discussed with jca@. Earlier versions tested by jmc@, tb@, and many
others.

docs ok jmc@, kernel bits ok ketennis@, everything ok sthen@,
"Is your stuff in yet?" deraadt@


Revision tags: OPENBSD_6_4_BASE
# 1.88 05-Oct-2018 cheloha

Revert KERN_CPTIME2 ENODEV changes in kernel and userspace.

ok kettenis deraadt


# 1.87 26-Sep-2018 cheloha

KERN_CPTIME2: set ENODEV if the CPU is offline.

This lets userspace distinguish between idle CPUs and those that are
not schedulable because hw.smt=0.

A subsequent commit probably needs to add documentation for this
to sysctl.2 (and perhaps elsewhere) after the dust settles.

Also included here are changes to systat(1) and top(1) that account
for the ENODEV case and adjust behavior accordingly:

- systat(1)'s cpu view prints placeholder marks ('-') instead of
percentages for each state if the given CPU is offline.

- systat(1)'s vmstat view checks for offline CPUs when computing the
machine state total and excludes them, so the CPU usage graph
only represents the states for online CPUs.

- top(1) does not draw CPU rows for offline CPUs when the view is
redrawn. If CPUs "go offline", percentages for each state are
replaced by placeholder marks ('-'); the view will need to be
redrawn to remove these rows. If CPUs "go online" the view will
need to be redrawn to show these new CPUs. In "combined CPU" mode,
the count and the state totals only represent online CPUs.

Ports using KERN_CPTIME2 will need to be updated. The changes
described above to make systat(1) and top(1) aware of the ENODEV
case *and* gracefully handle a changing HW_NCPUONLINE while the
application is running are not necessarily appropriate for each
and every port.

The changes described above are so extensive in part to demonstrate
one way a program *might* be made robust to changing CPU availability.
In particular, changing hw.smt after boot is an extremely rare event,
and this needs to be weighed when updating ports.

The logic needed to account for the KERN_CPTIME2 ENODEV case is
very roughly:

if (sysctl(...) == -1) {
if (errno != ENODEV) {
/* Actual error occurred. */
} else {
/* CPU is offline. */
}
} else {
/* CPU is online and CPU states were set by sysctl(2). */
}

Prompted by deraadt@. Basic idea for ENODEV from kettenis@. Discussed at
length with kettenis@. Additional testing by tb@.

No complaints from hackers@ after a week.

ok kettenis@, "I think you should commit [now]" deraadt@


# 1.86 22-Jun-2018 krw

Constrain IPKTS/OPKTS from floating down beyond the rest of the
displayed lines. Makes vmstat view in tall windows easier to read.

ok sthen@


# 1.85 19-May-2018 bluhm

Do not ignore nice time in systat(1). The sum would not be 100%,
a busy machine would look idle. As %Nic does not fit in the columns,
add it to %Usr. Introduce @ for spinning time to keep the characters
people are used to. Put %Spn between %Int and %Sys like in top.
OK visa@ mpi@


# 1.84 14-May-2018 mpi

Stopping counting and reporting CPU time spent spinning on a lock as
system time.

Introduce a new CP_SPIN "scheduler state" and modify userland tools
to display the % of timer a CPU spents spinning.

Based on a diff from jmatthew@, ok pirofti@, bluhm@, visa@, deraadt@


# 1.83 03-May-2018 otto

test for failing allocation using the standard idiom; prompted by Nan Xiao
ok tb@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.82 18-Dec-2016 krw

Remove statements that have no effect from X(), Y() and Z() #define's.
Leftovers from the re-engining of systat eight years ago. Makes gcc
quieter.

ok otto@ deraadt@


# 1.81 24-Aug-2016 guenther

Convert quad_t to int64_t and %q to %ll
Convert bzero() to memset() and bcopy() to memcpy()

ok natano@ millert@


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.80 20-Aug-2015 deraadt

Do not cast result of malloc/calloc/realloc* if stdlib.h is in scope
ok krw millert


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.79 16-Jan-2015 deraadt

first batch of programs adapting to the namespace cleanup
(pfvar.h nameser.h proc.h ucred.h)
ok guenther millert, and some review from doug as well.


# 1.78 23-Nov-2014 guenther

<sys/buf.h> isn't actually needed here

ok tedu@


# 1.77 15-Sep-2014 miod

Remove non-standard <sys/dkstat.h> header. It has not contained anything
related to disk stastics for almost 17 years, and the remaining
userland-visible defines duplicate those found in <sys/sched.h>.

Move the remaining _KERNEL defines to <sys/tty.h> where they belong, and
update all users to cope with this.

ok kettenis@


Revision tags: OPENBSD_5_6_BASE
# 1.76 08-Apr-2014 mpi

Use VM_UVMEXP instead of VM_METER for memory usages and directly
include <sys/vmmeter.h> where it is needed instead of relying on
it being included by <uvm/uvm_extern.h>.

miod@ likes it, ok guenther@


Revision tags: OPENBSD_5_5_BASE
# 1.75 31-Oct-2013 deraadt

sometimes we find .h we no longer need


Revision tags: OPENBSD_5_4_BASE
# 1.74 14-May-2013 miod

Don't display swapin/swapout uvmexp fields


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.73 19-Nov-2010 mikeb

Make KERN_CPTIME return an avarage number of ticks across all CPUs
tedu agreed with an idea, tested by Luis Useche and me; ok deraadt


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE
# 1.72 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


# 1.71 14-Aug-2009 deraadt

tie IPKTS/OPKTS to bottom corner for smaller screens


# 1.70 13-Aug-2009 deraadt

there are louder and louder moans about the inability to see packet
rates at the same time as interrupt counts, so sneak them into the
bottom corner of the vmstat screen
ok dlg


Revision tags: OPENBSD_4_6_BASE
# 1.69 03-May-2009 drahn

Hinge at the natural rollover point 9999x instead of 1024x when switching to
the next unit K->M->G. ok deraadt@


# 1.68 30-Mar-2009 deraadt

allow the disk transfer speed numbers to show useable numbers when disks
get really fast; ok canacar


Revision tags: OPENBSD_4_5_BASE
# 1.67 07-Dec-2008 canacar

Warning cleanup including unused variables and shadowed names


# 1.66 01-Nov-2008 canacar

Improve reporting of cache misses in the vmstat view. Previously
the misses field may report negative values. The hit/miss numbers
does not exactly reflect the statistics collected by the kernel
but this is close enough.

Report & patch from Bjorn Anderss, input from beck@ and thib@


Revision tags: OPENBSD_4_4_BASE
# 1.65 13-Jun-2008 deraadt

compile on older gcc; no decl after code


# 1.64 12-Jun-2008 canacar

New display engine for systat, based on pftop. Adds new views for pf
(status, state, rule, queue). While all displays work, some keyboard
comands are not implemented yet. Other features include better handling
of display resize and scrolling for long views. Committing now to fix
the remaining issues in the tree.
Testing and comments by otto@ and harding@, ok deraadt@


Revision tags: OPENBSD_4_3_BASE
# 1.63 01-Sep-2007 deraadt

malloc(n * m) -> calloc(n, m); from zinovik


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.62 25-Feb-2007 deraadt

use the 1 line load line from 'systat vm' on all the other displays, giving
them more room. much cleaner, and it is less code too; ok deanna


# 1.61 13-Nov-2006 otto

fix macro abuse leading to stray numbers in the vm display.
ok a whole lot of devs@


Revision tags: OPENBSD_4_0_BASE
# 1.60 14-Apr-2006 dlg

remove comments that says we dont count intr time and remove some code that
fudges the output to stay clean when intr time wasnt shown. not needed
since we show it now.


# 1.59 14-Apr-2006 dlg

show cpu time spent in interrupts. ive been wanting this for years.

tweaks by deraadt@ ok by many


# 1.58 31-Mar-2006 deraadt

spacing


# 1.57 31-Mar-2006 deraadt

fairly simple cleanup, lots of testing done


# 1.56 28-Mar-2006 mickey

give more space to the memory columns in vm page; deraadt@ ok


Revision tags: OPENBSD_3_9_BASE
# 1.55 28-Sep-2005 pedro

- when we run out of static kernel map entries, grab a fresh page using
the uvm_km_page allocator and use it instead of calling panic()
- add a counter to uvmexp so we can keep track of how many map entries
we have in use

idea from tedu@, long ago, okay deraadt@


Revision tags: OPENBSD_3_8_BASE
# 1.54 04-Apr-2005 deraadt

nlist.h not needed


Revision tags: OPENBSD_3_7_BASE
# 1.53 23-Sep-2004 deraadt

adapt to KERN_INTRCNT_CNT returning a quad, from danh (imported now to
avoid tree breakage)


Revision tags: OPENBSD_3_6_BASE
# 1.52 09-Jul-2004 deraadt

remove post-mortem stuff (sysctl only here)


# 1.51 28-Jun-2004 aaron

Remove special #if defined(__i386__) code from systat and vmstat. We now use
sysctl to fetch interrupt counters on all architectures. Also add new '-z'
flag to vmstat which means show all devices, even those that have not yet
generated an interrupt. deraadt@ tholo@ drahn@ millert@ ok


# 1.50 11-Jun-2004 deraadt

divide etime by ncpu


# 1.49 11-Jun-2004 deraadt

oops


# 1.48 11-Jun-2004 deraadt

on i386 machines, attempt to peek inside apic_intrhand[] as well, so that
MP machines get interrupt counters. will be replaced by a MI subsystem
one day. most code from drahn, few final bugs fixed by me


# 1.47 22-May-2004 henning

with modern disks data transfers rates above 10000 kByte/s are seen
regularily, make the disk columns a little wider so it doesn't run into
the neighboring column, theo ok


# 1.46 23-Apr-2004 tedu

don't print stats until they're stable, prevents seeing weird stuff in
disk columns. tested by jolan@. from pedro martelletto


Revision tags: OPENBSD_3_5_BASE
# 1.45 15-Feb-2004 tedu

'split' command for iostat mode
from Pedro Martelletto <pbastos@rdc.puc-rio.br>


# 1.44 15-Feb-2004 tedu

new arg to disk_unbusy, to record separate read/write statistics.
looked at by various, testing henning@ mcbride@ dan weeks
mostly from netbsd via Pedro Martelletto <pbastos@rdc.puc-rio.br>


# 1.43 16-Oct-2003 mickey

duh


# 1.42 15-Oct-2003 mickey

also print the uvmexp.zeropages if there is space in vm screen


Revision tags: OPENBSD_3_4_BASE
# 1.41 03-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


# 1.40 14-Apr-2003 deraadt

remove old comment


# 1.39 08-Apr-2003 deraadt

string cleaning; ok tdeval


Revision tags: OPENBSD_3_3_BASE
# 1.38 28-Feb-2003 jason

intrcnt's are ints not longs (at least according to the new kern.intrcnt stuff)


# 1.37 16-Dec-2002 tdeval

Make systat(1), iostat(8) and vmstat(8) automatically update their disk
statistics when a device is added/removed. ok deraadt@


Revision tags: OPENBSD_3_2_BASE
# 1.36 19-Jun-2002 deraadt

mark which nlist[] kmem entries are not needed in the sysctl case, and which are


# 1.35 18-Jun-2002 deraadt

ANSI


# 1.34 29-Apr-2002 millert

Fix 32bit int oflow when there is > 2GB vm; peters AT telia DOT net


Revision tags: OPENBSD_3_1_BASE
# 1.33 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


# 1.32 16-Feb-2002 tdeval

Some disk names are longer than 4. Cope with that.
ok deraadt@


# 1.31 07-Dec-2001 deraadt

move back. pvalchev -- the bug was quite obscure


# 1.30 07-Dec-2001 pvalchev

back out latest changes which cause problems on alpha/sparc64 until
they are fixed


# 1.29 23-Nov-2001 deraadt

fix signal races. use sysctl() instead of kvm where possible, and then KNF
the hell out of it; checked by miod


# 1.28 19-Nov-2001 mpech

kill more registers

millert@ ok


# 1.27 18-Nov-2001 deraadt

slightly expand the Csw/Trp/Sys/Int/Sof spacing


# 1.26 06-Nov-2001 art

New vm includes.


Revision tags: OPENBSD_3_0_BASE
# 1.25 28-Aug-2001 weingart

Add information on number/percentage of namei calls missed the cache.
millert@ ok.


# 1.24 27-Jun-2001 art

UVM is no longer an option


# 1.23 22-Jun-2001 lebel

use strlcpy vs strncpy+a[len-1]='\0'


# 1.22 04-May-2001 ericj

handle kvm_nlist() failing, from pr#1798.
Patch similar to the one submitted by <peterw@documenta.com.au>


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.21 22-Feb-2000 deraadt

_total is no longer a symbol in the kernel


# 1.20 26-Oct-1999 art

Fix printing of interrupts with UVM.


# 1.19 26-Oct-1999 art

support UVM. (much code from NetBSD)


Revision tags: OPENBSD_2_6_BASE
# 1.18 16-Jun-1999 espie

Fixed i386 -> __i386__


Revision tags: OPENBSD_2_5_BASE
# 1.17 19-Dec-1998 deraadt

move Act Free field over one


Revision tags: OPENBSD_2_4_BASE
# 1.16 13-Jul-1998 millert

ftpd: sleep for an indeterminate amount for non-existant logins
to simulate a crypt, like login does.
Use SEEK_* not L_* and kill some 0L's used in lseek while we're there.


# 1.15 12-Jun-1998 marc

fix vm load display


Revision tags: OPENBSD_2_3_BASE
# 1.14 19-Dec-1997 deraadt

comment this strncpy is safe


# 1.13 19-Dec-1997 deraadt

proactive buffer blocks


# 1.12 19-Dec-1997 deraadt

bye bye sprintf


# 1.11 24-Nov-1997 kstailey

Deal with the fact that PUTRATE() is a macro that contains braces by
surrounding it with braces after an ``if ()''.


# 1.10 22-Nov-1997 mickey

remove unused kernel vars


# 1.9 22-Nov-1997 kstailey

back out 1.8, will fix in another way.


# 1.8 22-Nov-1997 kstailey

Make vmstat mode display actually fit in 80x24.
Exploits fact that swap display is always blank.


Revision tags: OPENBSD_2_2_BASE
# 1.7 29-Jul-1997 flipk

delete accidental #if 0


# 1.6 29-Jul-1997 flipk

1) display full time string in 'vmstat' display so you can tell
the difference between an inactive display and a hung machine.
2) Update the man page for 'vmstat' to reflect reality (and actually
explain all those vm abbreviations).

netbsd PR bin/2756 (Jonathan Stone <jonathan@DSG.Stanford.EDU>


Revision tags: OPENBSD_2_1_BASE
# 1.5 20-Dec-1996 downsj

support four letter device names


Revision tags: OPENBSD_2_0_BASE
# 1.4 26-Jun-1996 deraadt

rcsid


# 1.3 25-Jun-1996 tholo

Show interrupt counts on i386.


# 1.2 22-May-1996 deraadt

libutil


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.93 22-Feb-2022 deraadt

need a local nitems() definition


# 1.92 20-Feb-2022 deraadt

sys/proc.h requires sys/signal.h (will become visible when sys/param.h
is removed)


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.91 28-Jun-2019 deraadt

When system calls indicate an error they return -1, not some arbitrary
value < 0. errno is only updated in this case. Change all (most?)
callers of syscalls to follow this better, and let's see if this strictness
helps us in the future.


Revision tags: OPENBSD_6_5_BASE
# 1.90 20-Jan-2019 tedu

don't reuse global between functions; the value is wrong.
reported by Bryan Linton


# 1.89 17-Nov-2018 cheloha

Add new KERN_CPUSTATS sysctl(2) so we can identify offline CPUs.

Because of hw.smt we need a way to determine whether a given CPU is "online"
or "offline" from userspace. KERN_CPTIME2 is an array, and so cannot be
cleanly extended for this purpose, so add a new sysctl(2) KERN_CPUSTATS
with an extensible struct. At the moment it's just KERN_CPTIME2 with a
flags member, but it can grow as needed.

KERN_CPUSTATS appears to have been defined by BSDi long ago, but there are
few (if any) packages in the wild still using the symbol so breakage in ports
should be near zero. No other system inherited the symbol from BSDi, either.

Then, use the new sysctl(2) in systat(1) and top(1):

- systat(1) draws placeholder marks ('-') instead of percentages for
offline CPUs in the cpu view.

- systat(1) omits offline CPU ticks when drawing the "big bar" in
the vmstat view. The upshot is that the bar isn't half idle when
half your logical CPUs are disabled.

- top(1) does not draw lines for offline CPUs; if CPUs toggle on or
offline in interactive mode we redraw the display to expand/reduce
space for the new/missing CPUs. This is consistent with what some
top(1) implementations do on Linux.

- top(1) omits offline CPUs from the totals when CPU totals are
combined into a single line (the '-1' flag).

Originally prompted by deraadt@. Discussed endlessly with deraadt@,
ketennis@, and sthen@. Tested by jmc@ and jca@. Earlier versions also
discussed with jca@. Earlier versions tested by jmc@, tb@, and many
others.

docs ok jmc@, kernel bits ok ketennis@, everything ok sthen@,
"Is your stuff in yet?" deraadt@


Revision tags: OPENBSD_6_4_BASE
# 1.88 05-Oct-2018 cheloha

Revert KERN_CPTIME2 ENODEV changes in kernel and userspace.

ok kettenis deraadt


# 1.87 26-Sep-2018 cheloha

KERN_CPTIME2: set ENODEV if the CPU is offline.

This lets userspace distinguish between idle CPUs and those that are
not schedulable because hw.smt=0.

A subsequent commit probably needs to add documentation for this
to sysctl.2 (and perhaps elsewhere) after the dust settles.

Also included here are changes to systat(1) and top(1) that account
for the ENODEV case and adjust behavior accordingly:

- systat(1)'s cpu view prints placeholder marks ('-') instead of
percentages for each state if the given CPU is offline.

- systat(1)'s vmstat view checks for offline CPUs when computing the
machine state total and excludes them, so the CPU usage graph
only represents the states for online CPUs.

- top(1) does not draw CPU rows for offline CPUs when the view is
redrawn. If CPUs "go offline", percentages for each state are
replaced by placeholder marks ('-'); the view will need to be
redrawn to remove these rows. If CPUs "go online" the view will
need to be redrawn to show these new CPUs. In "combined CPU" mode,
the count and the state totals only represent online CPUs.

Ports using KERN_CPTIME2 will need to be updated. The changes
described above to make systat(1) and top(1) aware of the ENODEV
case *and* gracefully handle a changing HW_NCPUONLINE while the
application is running are not necessarily appropriate for each
and every port.

The changes described above are so extensive in part to demonstrate
one way a program *might* be made robust to changing CPU availability.
In particular, changing hw.smt after boot is an extremely rare event,
and this needs to be weighed when updating ports.

The logic needed to account for the KERN_CPTIME2 ENODEV case is
very roughly:

if (sysctl(...) == -1) {
if (errno != ENODEV) {
/* Actual error occurred. */
} else {
/* CPU is offline. */
}
} else {
/* CPU is online and CPU states were set by sysctl(2). */
}

Prompted by deraadt@. Basic idea for ENODEV from kettenis@. Discussed at
length with kettenis@. Additional testing by tb@.

No complaints from hackers@ after a week.

ok kettenis@, "I think you should commit [now]" deraadt@


# 1.86 22-Jun-2018 krw

Constrain IPKTS/OPKTS from floating down beyond the rest of the
displayed lines. Makes vmstat view in tall windows easier to read.

ok sthen@


# 1.85 19-May-2018 bluhm

Do not ignore nice time in systat(1). The sum would not be 100%,
a busy machine would look idle. As %Nic does not fit in the columns,
add it to %Usr. Introduce @ for spinning time to keep the characters
people are used to. Put %Spn between %Int and %Sys like in top.
OK visa@ mpi@


# 1.84 14-May-2018 mpi

Stopping counting and reporting CPU time spent spinning on a lock as
system time.

Introduce a new CP_SPIN "scheduler state" and modify userland tools
to display the % of timer a CPU spents spinning.

Based on a diff from jmatthew@, ok pirofti@, bluhm@, visa@, deraadt@


# 1.83 03-May-2018 otto

test for failing allocation using the standard idiom; prompted by Nan Xiao
ok tb@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.82 18-Dec-2016 krw

Remove statements that have no effect from X(), Y() and Z() #define's.
Leftovers from the re-engining of systat eight years ago. Makes gcc
quieter.

ok otto@ deraadt@


# 1.81 24-Aug-2016 guenther

Convert quad_t to int64_t and %q to %ll
Convert bzero() to memset() and bcopy() to memcpy()

ok natano@ millert@


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.80 20-Aug-2015 deraadt

Do not cast result of malloc/calloc/realloc* if stdlib.h is in scope
ok krw millert


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.79 16-Jan-2015 deraadt

first batch of programs adapting to the namespace cleanup
(pfvar.h nameser.h proc.h ucred.h)
ok guenther millert, and some review from doug as well.


# 1.78 23-Nov-2014 guenther

<sys/buf.h> isn't actually needed here

ok tedu@


# 1.77 15-Sep-2014 miod

Remove non-standard <sys/dkstat.h> header. It has not contained anything
related to disk stastics for almost 17 years, and the remaining
userland-visible defines duplicate those found in <sys/sched.h>.

Move the remaining _KERNEL defines to <sys/tty.h> where they belong, and
update all users to cope with this.

ok kettenis@


Revision tags: OPENBSD_5_6_BASE
# 1.76 08-Apr-2014 mpi

Use VM_UVMEXP instead of VM_METER for memory usages and directly
include <sys/vmmeter.h> where it is needed instead of relying on
it being included by <uvm/uvm_extern.h>.

miod@ likes it, ok guenther@


Revision tags: OPENBSD_5_5_BASE
# 1.75 31-Oct-2013 deraadt

sometimes we find .h we no longer need


Revision tags: OPENBSD_5_4_BASE
# 1.74 14-May-2013 miod

Don't display swapin/swapout uvmexp fields


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.73 19-Nov-2010 mikeb

Make KERN_CPTIME return an avarage number of ticks across all CPUs
tedu agreed with an idea, tested by Luis Useche and me; ok deraadt


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE
# 1.72 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


# 1.71 14-Aug-2009 deraadt

tie IPKTS/OPKTS to bottom corner for smaller screens


# 1.70 13-Aug-2009 deraadt

there are louder and louder moans about the inability to see packet
rates at the same time as interrupt counts, so sneak them into the
bottom corner of the vmstat screen
ok dlg


Revision tags: OPENBSD_4_6_BASE
# 1.69 03-May-2009 drahn

Hinge at the natural rollover point 9999x instead of 1024x when switching to
the next unit K->M->G. ok deraadt@


# 1.68 30-Mar-2009 deraadt

allow the disk transfer speed numbers to show useable numbers when disks
get really fast; ok canacar


Revision tags: OPENBSD_4_5_BASE
# 1.67 07-Dec-2008 canacar

Warning cleanup including unused variables and shadowed names


# 1.66 01-Nov-2008 canacar

Improve reporting of cache misses in the vmstat view. Previously
the misses field may report negative values. The hit/miss numbers
does not exactly reflect the statistics collected by the kernel
but this is close enough.

Report & patch from Bjorn Anderss, input from beck@ and thib@


Revision tags: OPENBSD_4_4_BASE
# 1.65 13-Jun-2008 deraadt

compile on older gcc; no decl after code


# 1.64 12-Jun-2008 canacar

New display engine for systat, based on pftop. Adds new views for pf
(status, state, rule, queue). While all displays work, some keyboard
comands are not implemented yet. Other features include better handling
of display resize and scrolling for long views. Committing now to fix
the remaining issues in the tree.
Testing and comments by otto@ and harding@, ok deraadt@


Revision tags: OPENBSD_4_3_BASE
# 1.63 01-Sep-2007 deraadt

malloc(n * m) -> calloc(n, m); from zinovik


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.62 25-Feb-2007 deraadt

use the 1 line load line from 'systat vm' on all the other displays, giving
them more room. much cleaner, and it is less code too; ok deanna


# 1.61 13-Nov-2006 otto

fix macro abuse leading to stray numbers in the vm display.
ok a whole lot of devs@


Revision tags: OPENBSD_4_0_BASE
# 1.60 14-Apr-2006 dlg

remove comments that says we dont count intr time and remove some code that
fudges the output to stay clean when intr time wasnt shown. not needed
since we show it now.


# 1.59 14-Apr-2006 dlg

show cpu time spent in interrupts. ive been wanting this for years.

tweaks by deraadt@ ok by many


# 1.58 31-Mar-2006 deraadt

spacing


# 1.57 31-Mar-2006 deraadt

fairly simple cleanup, lots of testing done


# 1.56 28-Mar-2006 mickey

give more space to the memory columns in vm page; deraadt@ ok


Revision tags: OPENBSD_3_9_BASE
# 1.55 28-Sep-2005 pedro

- when we run out of static kernel map entries, grab a fresh page using
the uvm_km_page allocator and use it instead of calling panic()
- add a counter to uvmexp so we can keep track of how many map entries
we have in use

idea from tedu@, long ago, okay deraadt@


Revision tags: OPENBSD_3_8_BASE
# 1.54 04-Apr-2005 deraadt

nlist.h not needed


Revision tags: OPENBSD_3_7_BASE
# 1.53 23-Sep-2004 deraadt

adapt to KERN_INTRCNT_CNT returning a quad, from danh (imported now to
avoid tree breakage)


Revision tags: OPENBSD_3_6_BASE
# 1.52 09-Jul-2004 deraadt

remove post-mortem stuff (sysctl only here)


# 1.51 28-Jun-2004 aaron

Remove special #if defined(__i386__) code from systat and vmstat. We now use
sysctl to fetch interrupt counters on all architectures. Also add new '-z'
flag to vmstat which means show all devices, even those that have not yet
generated an interrupt. deraadt@ tholo@ drahn@ millert@ ok


# 1.50 11-Jun-2004 deraadt

divide etime by ncpu


# 1.49 11-Jun-2004 deraadt

oops


# 1.48 11-Jun-2004 deraadt

on i386 machines, attempt to peek inside apic_intrhand[] as well, so that
MP machines get interrupt counters. will be replaced by a MI subsystem
one day. most code from drahn, few final bugs fixed by me


# 1.47 22-May-2004 henning

with modern disks data transfers rates above 10000 kByte/s are seen
regularily, make the disk columns a little wider so it doesn't run into
the neighboring column, theo ok


# 1.46 23-Apr-2004 tedu

don't print stats until they're stable, prevents seeing weird stuff in
disk columns. tested by jolan@. from pedro martelletto


Revision tags: OPENBSD_3_5_BASE
# 1.45 15-Feb-2004 tedu

'split' command for iostat mode
from Pedro Martelletto <pbastos@rdc.puc-rio.br>


# 1.44 15-Feb-2004 tedu

new arg to disk_unbusy, to record separate read/write statistics.
looked at by various, testing henning@ mcbride@ dan weeks
mostly from netbsd via Pedro Martelletto <pbastos@rdc.puc-rio.br>


# 1.43 16-Oct-2003 mickey

duh


# 1.42 15-Oct-2003 mickey

also print the uvmexp.zeropages if there is space in vm screen


Revision tags: OPENBSD_3_4_BASE
# 1.41 03-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


# 1.40 14-Apr-2003 deraadt

remove old comment


# 1.39 08-Apr-2003 deraadt

string cleaning; ok tdeval


Revision tags: OPENBSD_3_3_BASE
# 1.38 28-Feb-2003 jason

intrcnt's are ints not longs (at least according to the new kern.intrcnt stuff)


# 1.37 16-Dec-2002 tdeval

Make systat(1), iostat(8) and vmstat(8) automatically update their disk
statistics when a device is added/removed. ok deraadt@


Revision tags: OPENBSD_3_2_BASE
# 1.36 19-Jun-2002 deraadt

mark which nlist[] kmem entries are not needed in the sysctl case, and which are


# 1.35 18-Jun-2002 deraadt

ANSI


# 1.34 29-Apr-2002 millert

Fix 32bit int oflow when there is > 2GB vm; peters AT telia DOT net


Revision tags: OPENBSD_3_1_BASE
# 1.33 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


# 1.32 16-Feb-2002 tdeval

Some disk names are longer than 4. Cope with that.
ok deraadt@


# 1.31 07-Dec-2001 deraadt

move back. pvalchev -- the bug was quite obscure


# 1.30 07-Dec-2001 pvalchev

back out latest changes which cause problems on alpha/sparc64 until
they are fixed


# 1.29 23-Nov-2001 deraadt

fix signal races. use sysctl() instead of kvm where possible, and then KNF
the hell out of it; checked by miod


# 1.28 19-Nov-2001 mpech

kill more registers

millert@ ok


# 1.27 18-Nov-2001 deraadt

slightly expand the Csw/Trp/Sys/Int/Sof spacing


# 1.26 06-Nov-2001 art

New vm includes.


Revision tags: OPENBSD_3_0_BASE
# 1.25 28-Aug-2001 weingart

Add information on number/percentage of namei calls missed the cache.
millert@ ok.


# 1.24 27-Jun-2001 art

UVM is no longer an option


# 1.23 22-Jun-2001 lebel

use strlcpy vs strncpy+a[len-1]='\0'


# 1.22 04-May-2001 ericj

handle kvm_nlist() failing, from pr#1798.
Patch similar to the one submitted by <peterw@documenta.com.au>


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.21 22-Feb-2000 deraadt

_total is no longer a symbol in the kernel


# 1.20 26-Oct-1999 art

Fix printing of interrupts with UVM.


# 1.19 26-Oct-1999 art

support UVM. (much code from NetBSD)


Revision tags: OPENBSD_2_6_BASE
# 1.18 16-Jun-1999 espie

Fixed i386 -> __i386__


Revision tags: OPENBSD_2_5_BASE
# 1.17 19-Dec-1998 deraadt

move Act Free field over one


Revision tags: OPENBSD_2_4_BASE
# 1.16 13-Jul-1998 millert

ftpd: sleep for an indeterminate amount for non-existant logins
to simulate a crypt, like login does.
Use SEEK_* not L_* and kill some 0L's used in lseek while we're there.


# 1.15 12-Jun-1998 marc

fix vm load display


Revision tags: OPENBSD_2_3_BASE
# 1.14 19-Dec-1997 deraadt

comment this strncpy is safe


# 1.13 19-Dec-1997 deraadt

proactive buffer blocks


# 1.12 19-Dec-1997 deraadt

bye bye sprintf


# 1.11 24-Nov-1997 kstailey

Deal with the fact that PUTRATE() is a macro that contains braces by
surrounding it with braces after an ``if ()''.


# 1.10 22-Nov-1997 mickey

remove unused kernel vars


# 1.9 22-Nov-1997 kstailey

back out 1.8, will fix in another way.


# 1.8 22-Nov-1997 kstailey

Make vmstat mode display actually fit in 80x24.
Exploits fact that swap display is always blank.


Revision tags: OPENBSD_2_2_BASE
# 1.7 29-Jul-1997 flipk

delete accidental #if 0


# 1.6 29-Jul-1997 flipk

1) display full time string in 'vmstat' display so you can tell
the difference between an inactive display and a hung machine.
2) Update the man page for 'vmstat' to reflect reality (and actually
explain all those vm abbreviations).

netbsd PR bin/2756 (Jonathan Stone <jonathan@DSG.Stanford.EDU>


Revision tags: OPENBSD_2_1_BASE
# 1.5 20-Dec-1996 downsj

support four letter device names


Revision tags: OPENBSD_2_0_BASE
# 1.4 26-Jun-1996 deraadt

rcsid


# 1.3 25-Jun-1996 tholo

Show interrupt counts on i386.


# 1.2 22-May-1996 deraadt

libutil


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.92 20-Feb-2022 deraadt

sys/proc.h requires sys/signal.h (will become visible when sys/param.h
is removed)


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.91 28-Jun-2019 deraadt

When system calls indicate an error they return -1, not some arbitrary
value < 0. errno is only updated in this case. Change all (most?)
callers of syscalls to follow this better, and let's see if this strictness
helps us in the future.


Revision tags: OPENBSD_6_5_BASE
# 1.90 20-Jan-2019 tedu

don't reuse global between functions; the value is wrong.
reported by Bryan Linton


# 1.89 17-Nov-2018 cheloha

Add new KERN_CPUSTATS sysctl(2) so we can identify offline CPUs.

Because of hw.smt we need a way to determine whether a given CPU is "online"
or "offline" from userspace. KERN_CPTIME2 is an array, and so cannot be
cleanly extended for this purpose, so add a new sysctl(2) KERN_CPUSTATS
with an extensible struct. At the moment it's just KERN_CPTIME2 with a
flags member, but it can grow as needed.

KERN_CPUSTATS appears to have been defined by BSDi long ago, but there are
few (if any) packages in the wild still using the symbol so breakage in ports
should be near zero. No other system inherited the symbol from BSDi, either.

Then, use the new sysctl(2) in systat(1) and top(1):

- systat(1) draws placeholder marks ('-') instead of percentages for
offline CPUs in the cpu view.

- systat(1) omits offline CPU ticks when drawing the "big bar" in
the vmstat view. The upshot is that the bar isn't half idle when
half your logical CPUs are disabled.

- top(1) does not draw lines for offline CPUs; if CPUs toggle on or
offline in interactive mode we redraw the display to expand/reduce
space for the new/missing CPUs. This is consistent with what some
top(1) implementations do on Linux.

- top(1) omits offline CPUs from the totals when CPU totals are
combined into a single line (the '-1' flag).

Originally prompted by deraadt@. Discussed endlessly with deraadt@,
ketennis@, and sthen@. Tested by jmc@ and jca@. Earlier versions also
discussed with jca@. Earlier versions tested by jmc@, tb@, and many
others.

docs ok jmc@, kernel bits ok ketennis@, everything ok sthen@,
"Is your stuff in yet?" deraadt@


Revision tags: OPENBSD_6_4_BASE
# 1.88 05-Oct-2018 cheloha

Revert KERN_CPTIME2 ENODEV changes in kernel and userspace.

ok kettenis deraadt


# 1.87 26-Sep-2018 cheloha

KERN_CPTIME2: set ENODEV if the CPU is offline.

This lets userspace distinguish between idle CPUs and those that are
not schedulable because hw.smt=0.

A subsequent commit probably needs to add documentation for this
to sysctl.2 (and perhaps elsewhere) after the dust settles.

Also included here are changes to systat(1) and top(1) that account
for the ENODEV case and adjust behavior accordingly:

- systat(1)'s cpu view prints placeholder marks ('-') instead of
percentages for each state if the given CPU is offline.

- systat(1)'s vmstat view checks for offline CPUs when computing the
machine state total and excludes them, so the CPU usage graph
only represents the states for online CPUs.

- top(1) does not draw CPU rows for offline CPUs when the view is
redrawn. If CPUs "go offline", percentages for each state are
replaced by placeholder marks ('-'); the view will need to be
redrawn to remove these rows. If CPUs "go online" the view will
need to be redrawn to show these new CPUs. In "combined CPU" mode,
the count and the state totals only represent online CPUs.

Ports using KERN_CPTIME2 will need to be updated. The changes
described above to make systat(1) and top(1) aware of the ENODEV
case *and* gracefully handle a changing HW_NCPUONLINE while the
application is running are not necessarily appropriate for each
and every port.

The changes described above are so extensive in part to demonstrate
one way a program *might* be made robust to changing CPU availability.
In particular, changing hw.smt after boot is an extremely rare event,
and this needs to be weighed when updating ports.

The logic needed to account for the KERN_CPTIME2 ENODEV case is
very roughly:

if (sysctl(...) == -1) {
if (errno != ENODEV) {
/* Actual error occurred. */
} else {
/* CPU is offline. */
}
} else {
/* CPU is online and CPU states were set by sysctl(2). */
}

Prompted by deraadt@. Basic idea for ENODEV from kettenis@. Discussed at
length with kettenis@. Additional testing by tb@.

No complaints from hackers@ after a week.

ok kettenis@, "I think you should commit [now]" deraadt@


# 1.86 22-Jun-2018 krw

Constrain IPKTS/OPKTS from floating down beyond the rest of the
displayed lines. Makes vmstat view in tall windows easier to read.

ok sthen@


# 1.85 19-May-2018 bluhm

Do not ignore nice time in systat(1). The sum would not be 100%,
a busy machine would look idle. As %Nic does not fit in the columns,
add it to %Usr. Introduce @ for spinning time to keep the characters
people are used to. Put %Spn between %Int and %Sys like in top.
OK visa@ mpi@


# 1.84 14-May-2018 mpi

Stopping counting and reporting CPU time spent spinning on a lock as
system time.

Introduce a new CP_SPIN "scheduler state" and modify userland tools
to display the % of timer a CPU spents spinning.

Based on a diff from jmatthew@, ok pirofti@, bluhm@, visa@, deraadt@


# 1.83 03-May-2018 otto

test for failing allocation using the standard idiom; prompted by Nan Xiao
ok tb@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.82 18-Dec-2016 krw

Remove statements that have no effect from X(), Y() and Z() #define's.
Leftovers from the re-engining of systat eight years ago. Makes gcc
quieter.

ok otto@ deraadt@


# 1.81 24-Aug-2016 guenther

Convert quad_t to int64_t and %q to %ll
Convert bzero() to memset() and bcopy() to memcpy()

ok natano@ millert@


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.80 20-Aug-2015 deraadt

Do not cast result of malloc/calloc/realloc* if stdlib.h is in scope
ok krw millert


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.79 16-Jan-2015 deraadt

first batch of programs adapting to the namespace cleanup
(pfvar.h nameser.h proc.h ucred.h)
ok guenther millert, and some review from doug as well.


# 1.78 23-Nov-2014 guenther

<sys/buf.h> isn't actually needed here

ok tedu@


# 1.77 15-Sep-2014 miod

Remove non-standard <sys/dkstat.h> header. It has not contained anything
related to disk stastics for almost 17 years, and the remaining
userland-visible defines duplicate those found in <sys/sched.h>.

Move the remaining _KERNEL defines to <sys/tty.h> where they belong, and
update all users to cope with this.

ok kettenis@


Revision tags: OPENBSD_5_6_BASE
# 1.76 08-Apr-2014 mpi

Use VM_UVMEXP instead of VM_METER for memory usages and directly
include <sys/vmmeter.h> where it is needed instead of relying on
it being included by <uvm/uvm_extern.h>.

miod@ likes it, ok guenther@


Revision tags: OPENBSD_5_5_BASE
# 1.75 31-Oct-2013 deraadt

sometimes we find .h we no longer need


Revision tags: OPENBSD_5_4_BASE
# 1.74 14-May-2013 miod

Don't display swapin/swapout uvmexp fields


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.73 19-Nov-2010 mikeb

Make KERN_CPTIME return an avarage number of ticks across all CPUs
tedu agreed with an idea, tested by Luis Useche and me; ok deraadt


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE
# 1.72 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


# 1.71 14-Aug-2009 deraadt

tie IPKTS/OPKTS to bottom corner for smaller screens


# 1.70 13-Aug-2009 deraadt

there are louder and louder moans about the inability to see packet
rates at the same time as interrupt counts, so sneak them into the
bottom corner of the vmstat screen
ok dlg


Revision tags: OPENBSD_4_6_BASE
# 1.69 03-May-2009 drahn

Hinge at the natural rollover point 9999x instead of 1024x when switching to
the next unit K->M->G. ok deraadt@


# 1.68 30-Mar-2009 deraadt

allow the disk transfer speed numbers to show useable numbers when disks
get really fast; ok canacar


Revision tags: OPENBSD_4_5_BASE
# 1.67 07-Dec-2008 canacar

Warning cleanup including unused variables and shadowed names


# 1.66 01-Nov-2008 canacar

Improve reporting of cache misses in the vmstat view. Previously
the misses field may report negative values. The hit/miss numbers
does not exactly reflect the statistics collected by the kernel
but this is close enough.

Report & patch from Bjorn Anderss, input from beck@ and thib@


Revision tags: OPENBSD_4_4_BASE
# 1.65 13-Jun-2008 deraadt

compile on older gcc; no decl after code


# 1.64 12-Jun-2008 canacar

New display engine for systat, based on pftop. Adds new views for pf
(status, state, rule, queue). While all displays work, some keyboard
comands are not implemented yet. Other features include better handling
of display resize and scrolling for long views. Committing now to fix
the remaining issues in the tree.
Testing and comments by otto@ and harding@, ok deraadt@


Revision tags: OPENBSD_4_3_BASE
# 1.63 01-Sep-2007 deraadt

malloc(n * m) -> calloc(n, m); from zinovik


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.62 25-Feb-2007 deraadt

use the 1 line load line from 'systat vm' on all the other displays, giving
them more room. much cleaner, and it is less code too; ok deanna


# 1.61 13-Nov-2006 otto

fix macro abuse leading to stray numbers in the vm display.
ok a whole lot of devs@


Revision tags: OPENBSD_4_0_BASE
# 1.60 14-Apr-2006 dlg

remove comments that says we dont count intr time and remove some code that
fudges the output to stay clean when intr time wasnt shown. not needed
since we show it now.


# 1.59 14-Apr-2006 dlg

show cpu time spent in interrupts. ive been wanting this for years.

tweaks by deraadt@ ok by many


# 1.58 31-Mar-2006 deraadt

spacing


# 1.57 31-Mar-2006 deraadt

fairly simple cleanup, lots of testing done


# 1.56 28-Mar-2006 mickey

give more space to the memory columns in vm page; deraadt@ ok


Revision tags: OPENBSD_3_9_BASE
# 1.55 28-Sep-2005 pedro

- when we run out of static kernel map entries, grab a fresh page using
the uvm_km_page allocator and use it instead of calling panic()
- add a counter to uvmexp so we can keep track of how many map entries
we have in use

idea from tedu@, long ago, okay deraadt@


Revision tags: OPENBSD_3_8_BASE
# 1.54 04-Apr-2005 deraadt

nlist.h not needed


Revision tags: OPENBSD_3_7_BASE
# 1.53 23-Sep-2004 deraadt

adapt to KERN_INTRCNT_CNT returning a quad, from danh (imported now to
avoid tree breakage)


Revision tags: OPENBSD_3_6_BASE
# 1.52 09-Jul-2004 deraadt

remove post-mortem stuff (sysctl only here)


# 1.51 28-Jun-2004 aaron

Remove special #if defined(__i386__) code from systat and vmstat. We now use
sysctl to fetch interrupt counters on all architectures. Also add new '-z'
flag to vmstat which means show all devices, even those that have not yet
generated an interrupt. deraadt@ tholo@ drahn@ millert@ ok


# 1.50 11-Jun-2004 deraadt

divide etime by ncpu


# 1.49 11-Jun-2004 deraadt

oops


# 1.48 11-Jun-2004 deraadt

on i386 machines, attempt to peek inside apic_intrhand[] as well, so that
MP machines get interrupt counters. will be replaced by a MI subsystem
one day. most code from drahn, few final bugs fixed by me


# 1.47 22-May-2004 henning

with modern disks data transfers rates above 10000 kByte/s are seen
regularily, make the disk columns a little wider so it doesn't run into
the neighboring column, theo ok


# 1.46 23-Apr-2004 tedu

don't print stats until they're stable, prevents seeing weird stuff in
disk columns. tested by jolan@. from pedro martelletto


Revision tags: OPENBSD_3_5_BASE
# 1.45 15-Feb-2004 tedu

'split' command for iostat mode
from Pedro Martelletto <pbastos@rdc.puc-rio.br>


# 1.44 15-Feb-2004 tedu

new arg to disk_unbusy, to record separate read/write statistics.
looked at by various, testing henning@ mcbride@ dan weeks
mostly from netbsd via Pedro Martelletto <pbastos@rdc.puc-rio.br>


# 1.43 16-Oct-2003 mickey

duh


# 1.42 15-Oct-2003 mickey

also print the uvmexp.zeropages if there is space in vm screen


Revision tags: OPENBSD_3_4_BASE
# 1.41 03-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


# 1.40 14-Apr-2003 deraadt

remove old comment


# 1.39 08-Apr-2003 deraadt

string cleaning; ok tdeval


Revision tags: OPENBSD_3_3_BASE
# 1.38 28-Feb-2003 jason

intrcnt's are ints not longs (at least according to the new kern.intrcnt stuff)


# 1.37 16-Dec-2002 tdeval

Make systat(1), iostat(8) and vmstat(8) automatically update their disk
statistics when a device is added/removed. ok deraadt@


Revision tags: OPENBSD_3_2_BASE
# 1.36 19-Jun-2002 deraadt

mark which nlist[] kmem entries are not needed in the sysctl case, and which are


# 1.35 18-Jun-2002 deraadt

ANSI


# 1.34 29-Apr-2002 millert

Fix 32bit int oflow when there is > 2GB vm; peters AT telia DOT net


Revision tags: OPENBSD_3_1_BASE
# 1.33 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


# 1.32 16-Feb-2002 tdeval

Some disk names are longer than 4. Cope with that.
ok deraadt@


# 1.31 07-Dec-2001 deraadt

move back. pvalchev -- the bug was quite obscure


# 1.30 07-Dec-2001 pvalchev

back out latest changes which cause problems on alpha/sparc64 until
they are fixed


# 1.29 23-Nov-2001 deraadt

fix signal races. use sysctl() instead of kvm where possible, and then KNF
the hell out of it; checked by miod


# 1.28 19-Nov-2001 mpech

kill more registers

millert@ ok


# 1.27 18-Nov-2001 deraadt

slightly expand the Csw/Trp/Sys/Int/Sof spacing


# 1.26 06-Nov-2001 art

New vm includes.


Revision tags: OPENBSD_3_0_BASE
# 1.25 28-Aug-2001 weingart

Add information on number/percentage of namei calls missed the cache.
millert@ ok.


# 1.24 27-Jun-2001 art

UVM is no longer an option


# 1.23 22-Jun-2001 lebel

use strlcpy vs strncpy+a[len-1]='\0'


# 1.22 04-May-2001 ericj

handle kvm_nlist() failing, from pr#1798.
Patch similar to the one submitted by <peterw@documenta.com.au>


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.21 22-Feb-2000 deraadt

_total is no longer a symbol in the kernel


# 1.20 26-Oct-1999 art

Fix printing of interrupts with UVM.


# 1.19 26-Oct-1999 art

support UVM. (much code from NetBSD)


Revision tags: OPENBSD_2_6_BASE
# 1.18 16-Jun-1999 espie

Fixed i386 -> __i386__


Revision tags: OPENBSD_2_5_BASE
# 1.17 19-Dec-1998 deraadt

move Act Free field over one


Revision tags: OPENBSD_2_4_BASE
# 1.16 13-Jul-1998 millert

ftpd: sleep for an indeterminate amount for non-existant logins
to simulate a crypt, like login does.
Use SEEK_* not L_* and kill some 0L's used in lseek while we're there.


# 1.15 12-Jun-1998 marc

fix vm load display


Revision tags: OPENBSD_2_3_BASE
# 1.14 19-Dec-1997 deraadt

comment this strncpy is safe


# 1.13 19-Dec-1997 deraadt

proactive buffer blocks


# 1.12 19-Dec-1997 deraadt

bye bye sprintf


# 1.11 24-Nov-1997 kstailey

Deal with the fact that PUTRATE() is a macro that contains braces by
surrounding it with braces after an ``if ()''.


# 1.10 22-Nov-1997 mickey

remove unused kernel vars


# 1.9 22-Nov-1997 kstailey

back out 1.8, will fix in another way.


# 1.8 22-Nov-1997 kstailey

Make vmstat mode display actually fit in 80x24.
Exploits fact that swap display is always blank.


Revision tags: OPENBSD_2_2_BASE
# 1.7 29-Jul-1997 flipk

delete accidental #if 0


# 1.6 29-Jul-1997 flipk

1) display full time string in 'vmstat' display so you can tell
the difference between an inactive display and a hung machine.
2) Update the man page for 'vmstat' to reflect reality (and actually
explain all those vm abbreviations).

netbsd PR bin/2756 (Jonathan Stone <jonathan@DSG.Stanford.EDU>


Revision tags: OPENBSD_2_1_BASE
# 1.5 20-Dec-1996 downsj

support four letter device names


Revision tags: OPENBSD_2_0_BASE
# 1.4 26-Jun-1996 deraadt

rcsid


# 1.3 25-Jun-1996 tholo

Show interrupt counts on i386.


# 1.2 22-May-1996 deraadt

libutil


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.91 28-Jun-2019 deraadt

When system calls indicate an error they return -1, not some arbitrary
value < 0. errno is only updated in this case. Change all (most?)
callers of syscalls to follow this better, and let's see if this strictness
helps us in the future.


Revision tags: OPENBSD_6_5_BASE
# 1.90 20-Jan-2019 tedu

don't reuse global between functions; the value is wrong.
reported by Bryan Linton


# 1.89 17-Nov-2018 cheloha

Add new KERN_CPUSTATS sysctl(2) so we can identify offline CPUs.

Because of hw.smt we need a way to determine whether a given CPU is "online"
or "offline" from userspace. KERN_CPTIME2 is an array, and so cannot be
cleanly extended for this purpose, so add a new sysctl(2) KERN_CPUSTATS
with an extensible struct. At the moment it's just KERN_CPTIME2 with a
flags member, but it can grow as needed.

KERN_CPUSTATS appears to have been defined by BSDi long ago, but there are
few (if any) packages in the wild still using the symbol so breakage in ports
should be near zero. No other system inherited the symbol from BSDi, either.

Then, use the new sysctl(2) in systat(1) and top(1):

- systat(1) draws placeholder marks ('-') instead of percentages for
offline CPUs in the cpu view.

- systat(1) omits offline CPU ticks when drawing the "big bar" in
the vmstat view. The upshot is that the bar isn't half idle when
half your logical CPUs are disabled.

- top(1) does not draw lines for offline CPUs; if CPUs toggle on or
offline in interactive mode we redraw the display to expand/reduce
space for the new/missing CPUs. This is consistent with what some
top(1) implementations do on Linux.

- top(1) omits offline CPUs from the totals when CPU totals are
combined into a single line (the '-1' flag).

Originally prompted by deraadt@. Discussed endlessly with deraadt@,
ketennis@, and sthen@. Tested by jmc@ and jca@. Earlier versions also
discussed with jca@. Earlier versions tested by jmc@, tb@, and many
others.

docs ok jmc@, kernel bits ok ketennis@, everything ok sthen@,
"Is your stuff in yet?" deraadt@


Revision tags: OPENBSD_6_4_BASE
# 1.88 05-Oct-2018 cheloha

Revert KERN_CPTIME2 ENODEV changes in kernel and userspace.

ok kettenis deraadt


# 1.87 26-Sep-2018 cheloha

KERN_CPTIME2: set ENODEV if the CPU is offline.

This lets userspace distinguish between idle CPUs and those that are
not schedulable because hw.smt=0.

A subsequent commit probably needs to add documentation for this
to sysctl.2 (and perhaps elsewhere) after the dust settles.

Also included here are changes to systat(1) and top(1) that account
for the ENODEV case and adjust behavior accordingly:

- systat(1)'s cpu view prints placeholder marks ('-') instead of
percentages for each state if the given CPU is offline.

- systat(1)'s vmstat view checks for offline CPUs when computing the
machine state total and excludes them, so the CPU usage graph
only represents the states for online CPUs.

- top(1) does not draw CPU rows for offline CPUs when the view is
redrawn. If CPUs "go offline", percentages for each state are
replaced by placeholder marks ('-'); the view will need to be
redrawn to remove these rows. If CPUs "go online" the view will
need to be redrawn to show these new CPUs. In "combined CPU" mode,
the count and the state totals only represent online CPUs.

Ports using KERN_CPTIME2 will need to be updated. The changes
described above to make systat(1) and top(1) aware of the ENODEV
case *and* gracefully handle a changing HW_NCPUONLINE while the
application is running are not necessarily appropriate for each
and every port.

The changes described above are so extensive in part to demonstrate
one way a program *might* be made robust to changing CPU availability.
In particular, changing hw.smt after boot is an extremely rare event,
and this needs to be weighed when updating ports.

The logic needed to account for the KERN_CPTIME2 ENODEV case is
very roughly:

if (sysctl(...) == -1) {
if (errno != ENODEV) {
/* Actual error occurred. */
} else {
/* CPU is offline. */
}
} else {
/* CPU is online and CPU states were set by sysctl(2). */
}

Prompted by deraadt@. Basic idea for ENODEV from kettenis@. Discussed at
length with kettenis@. Additional testing by tb@.

No complaints from hackers@ after a week.

ok kettenis@, "I think you should commit [now]" deraadt@


# 1.86 22-Jun-2018 krw

Constrain IPKTS/OPKTS from floating down beyond the rest of the
displayed lines. Makes vmstat view in tall windows easier to read.

ok sthen@


# 1.85 19-May-2018 bluhm

Do not ignore nice time in systat(1). The sum would not be 100%,
a busy machine would look idle. As %Nic does not fit in the columns,
add it to %Usr. Introduce @ for spinning time to keep the characters
people are used to. Put %Spn between %Int and %Sys like in top.
OK visa@ mpi@


# 1.84 14-May-2018 mpi

Stopping counting and reporting CPU time spent spinning on a lock as
system time.

Introduce a new CP_SPIN "scheduler state" and modify userland tools
to display the % of timer a CPU spents spinning.

Based on a diff from jmatthew@, ok pirofti@, bluhm@, visa@, deraadt@


# 1.83 03-May-2018 otto

test for failing allocation using the standard idiom; prompted by Nan Xiao
ok tb@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.82 18-Dec-2016 krw

Remove statements that have no effect from X(), Y() and Z() #define's.
Leftovers from the re-engining of systat eight years ago. Makes gcc
quieter.

ok otto@ deraadt@


# 1.81 24-Aug-2016 guenther

Convert quad_t to int64_t and %q to %ll
Convert bzero() to memset() and bcopy() to memcpy()

ok natano@ millert@


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.80 20-Aug-2015 deraadt

Do not cast result of malloc/calloc/realloc* if stdlib.h is in scope
ok krw millert


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.79 16-Jan-2015 deraadt

first batch of programs adapting to the namespace cleanup
(pfvar.h nameser.h proc.h ucred.h)
ok guenther millert, and some review from doug as well.


# 1.78 23-Nov-2014 guenther

<sys/buf.h> isn't actually needed here

ok tedu@


# 1.77 15-Sep-2014 miod

Remove non-standard <sys/dkstat.h> header. It has not contained anything
related to disk stastics for almost 17 years, and the remaining
userland-visible defines duplicate those found in <sys/sched.h>.

Move the remaining _KERNEL defines to <sys/tty.h> where they belong, and
update all users to cope with this.

ok kettenis@


Revision tags: OPENBSD_5_6_BASE
# 1.76 08-Apr-2014 mpi

Use VM_UVMEXP instead of VM_METER for memory usages and directly
include <sys/vmmeter.h> where it is needed instead of relying on
it being included by <uvm/uvm_extern.h>.

miod@ likes it, ok guenther@


Revision tags: OPENBSD_5_5_BASE
# 1.75 31-Oct-2013 deraadt

sometimes we find .h we no longer need


Revision tags: OPENBSD_5_4_BASE
# 1.74 14-May-2013 miod

Don't display swapin/swapout uvmexp fields


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.73 19-Nov-2010 mikeb

Make KERN_CPTIME return an avarage number of ticks across all CPUs
tedu agreed with an idea, tested by Luis Useche and me; ok deraadt


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE
# 1.72 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


# 1.71 14-Aug-2009 deraadt

tie IPKTS/OPKTS to bottom corner for smaller screens


# 1.70 13-Aug-2009 deraadt

there are louder and louder moans about the inability to see packet
rates at the same time as interrupt counts, so sneak them into the
bottom corner of the vmstat screen
ok dlg


Revision tags: OPENBSD_4_6_BASE
# 1.69 03-May-2009 drahn

Hinge at the natural rollover point 9999x instead of 1024x when switching to
the next unit K->M->G. ok deraadt@


# 1.68 30-Mar-2009 deraadt

allow the disk transfer speed numbers to show useable numbers when disks
get really fast; ok canacar


Revision tags: OPENBSD_4_5_BASE
# 1.67 07-Dec-2008 canacar

Warning cleanup including unused variables and shadowed names


# 1.66 01-Nov-2008 canacar

Improve reporting of cache misses in the vmstat view. Previously
the misses field may report negative values. The hit/miss numbers
does not exactly reflect the statistics collected by the kernel
but this is close enough.

Report & patch from Bjorn Anderss, input from beck@ and thib@


Revision tags: OPENBSD_4_4_BASE
# 1.65 13-Jun-2008 deraadt

compile on older gcc; no decl after code


# 1.64 12-Jun-2008 canacar

New display engine for systat, based on pftop. Adds new views for pf
(status, state, rule, queue). While all displays work, some keyboard
comands are not implemented yet. Other features include better handling
of display resize and scrolling for long views. Committing now to fix
the remaining issues in the tree.
Testing and comments by otto@ and harding@, ok deraadt@


Revision tags: OPENBSD_4_3_BASE
# 1.63 01-Sep-2007 deraadt

malloc(n * m) -> calloc(n, m); from zinovik


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.62 25-Feb-2007 deraadt

use the 1 line load line from 'systat vm' on all the other displays, giving
them more room. much cleaner, and it is less code too; ok deanna


# 1.61 13-Nov-2006 otto

fix macro abuse leading to stray numbers in the vm display.
ok a whole lot of devs@


Revision tags: OPENBSD_4_0_BASE
# 1.60 14-Apr-2006 dlg

remove comments that says we dont count intr time and remove some code that
fudges the output to stay clean when intr time wasnt shown. not needed
since we show it now.


# 1.59 14-Apr-2006 dlg

show cpu time spent in interrupts. ive been wanting this for years.

tweaks by deraadt@ ok by many


# 1.58 31-Mar-2006 deraadt

spacing


# 1.57 31-Mar-2006 deraadt

fairly simple cleanup, lots of testing done


# 1.56 28-Mar-2006 mickey

give more space to the memory columns in vm page; deraadt@ ok


Revision tags: OPENBSD_3_9_BASE
# 1.55 28-Sep-2005 pedro

- when we run out of static kernel map entries, grab a fresh page using
the uvm_km_page allocator and use it instead of calling panic()
- add a counter to uvmexp so we can keep track of how many map entries
we have in use

idea from tedu@, long ago, okay deraadt@


Revision tags: OPENBSD_3_8_BASE
# 1.54 04-Apr-2005 deraadt

nlist.h not needed


Revision tags: OPENBSD_3_7_BASE
# 1.53 23-Sep-2004 deraadt

adapt to KERN_INTRCNT_CNT returning a quad, from danh (imported now to
avoid tree breakage)


Revision tags: OPENBSD_3_6_BASE
# 1.52 09-Jul-2004 deraadt

remove post-mortem stuff (sysctl only here)


# 1.51 28-Jun-2004 aaron

Remove special #if defined(__i386__) code from systat and vmstat. We now use
sysctl to fetch interrupt counters on all architectures. Also add new '-z'
flag to vmstat which means show all devices, even those that have not yet
generated an interrupt. deraadt@ tholo@ drahn@ millert@ ok


# 1.50 11-Jun-2004 deraadt

divide etime by ncpu


# 1.49 11-Jun-2004 deraadt

oops


# 1.48 11-Jun-2004 deraadt

on i386 machines, attempt to peek inside apic_intrhand[] as well, so that
MP machines get interrupt counters. will be replaced by a MI subsystem
one day. most code from drahn, few final bugs fixed by me


# 1.47 22-May-2004 henning

with modern disks data transfers rates above 10000 kByte/s are seen
regularily, make the disk columns a little wider so it doesn't run into
the neighboring column, theo ok


# 1.46 23-Apr-2004 tedu

don't print stats until they're stable, prevents seeing weird stuff in
disk columns. tested by jolan@. from pedro martelletto


Revision tags: OPENBSD_3_5_BASE
# 1.45 15-Feb-2004 tedu

'split' command for iostat mode
from Pedro Martelletto <pbastos@rdc.puc-rio.br>


# 1.44 15-Feb-2004 tedu

new arg to disk_unbusy, to record separate read/write statistics.
looked at by various, testing henning@ mcbride@ dan weeks
mostly from netbsd via Pedro Martelletto <pbastos@rdc.puc-rio.br>


# 1.43 16-Oct-2003 mickey

duh


# 1.42 15-Oct-2003 mickey

also print the uvmexp.zeropages if there is space in vm screen


Revision tags: OPENBSD_3_4_BASE
# 1.41 03-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


# 1.40 14-Apr-2003 deraadt

remove old comment


# 1.39 08-Apr-2003 deraadt

string cleaning; ok tdeval


Revision tags: OPENBSD_3_3_BASE
# 1.38 28-Feb-2003 jason

intrcnt's are ints not longs (at least according to the new kern.intrcnt stuff)


# 1.37 16-Dec-2002 tdeval

Make systat(1), iostat(8) and vmstat(8) automatically update their disk
statistics when a device is added/removed. ok deraadt@


Revision tags: OPENBSD_3_2_BASE
# 1.36 19-Jun-2002 deraadt

mark which nlist[] kmem entries are not needed in the sysctl case, and which are


# 1.35 18-Jun-2002 deraadt

ANSI


# 1.34 29-Apr-2002 millert

Fix 32bit int oflow when there is > 2GB vm; peters AT telia DOT net


Revision tags: OPENBSD_3_1_BASE
# 1.33 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


# 1.32 16-Feb-2002 tdeval

Some disk names are longer than 4. Cope with that.
ok deraadt@


# 1.31 07-Dec-2001 deraadt

move back. pvalchev -- the bug was quite obscure


# 1.30 07-Dec-2001 pvalchev

back out latest changes which cause problems on alpha/sparc64 until
they are fixed


# 1.29 23-Nov-2001 deraadt

fix signal races. use sysctl() instead of kvm where possible, and then KNF
the hell out of it; checked by miod


# 1.28 19-Nov-2001 mpech

kill more registers

millert@ ok


# 1.27 18-Nov-2001 deraadt

slightly expand the Csw/Trp/Sys/Int/Sof spacing


# 1.26 06-Nov-2001 art

New vm includes.


Revision tags: OPENBSD_3_0_BASE
# 1.25 28-Aug-2001 weingart

Add information on number/percentage of namei calls missed the cache.
millert@ ok.


# 1.24 27-Jun-2001 art

UVM is no longer an option


# 1.23 22-Jun-2001 lebel

use strlcpy vs strncpy+a[len-1]='\0'


# 1.22 04-May-2001 ericj

handle kvm_nlist() failing, from pr#1798.
Patch similar to the one submitted by <peterw@documenta.com.au>


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.21 22-Feb-2000 deraadt

_total is no longer a symbol in the kernel


# 1.20 26-Oct-1999 art

Fix printing of interrupts with UVM.


# 1.19 26-Oct-1999 art

support UVM. (much code from NetBSD)


Revision tags: OPENBSD_2_6_BASE
# 1.18 16-Jun-1999 espie

Fixed i386 -> __i386__


Revision tags: OPENBSD_2_5_BASE
# 1.17 19-Dec-1998 deraadt

move Act Free field over one


Revision tags: OPENBSD_2_4_BASE
# 1.16 13-Jul-1998 millert

ftpd: sleep for an indeterminate amount for non-existant logins
to simulate a crypt, like login does.
Use SEEK_* not L_* and kill some 0L's used in lseek while we're there.


# 1.15 12-Jun-1998 marc

fix vm load display


Revision tags: OPENBSD_2_3_BASE
# 1.14 19-Dec-1997 deraadt

comment this strncpy is safe


# 1.13 19-Dec-1997 deraadt

proactive buffer blocks


# 1.12 19-Dec-1997 deraadt

bye bye sprintf


# 1.11 24-Nov-1997 kstailey

Deal with the fact that PUTRATE() is a macro that contains braces by
surrounding it with braces after an ``if ()''.


# 1.10 22-Nov-1997 mickey

remove unused kernel vars


# 1.9 22-Nov-1997 kstailey

back out 1.8, will fix in another way.


# 1.8 22-Nov-1997 kstailey

Make vmstat mode display actually fit in 80x24.
Exploits fact that swap display is always blank.


Revision tags: OPENBSD_2_2_BASE
# 1.7 29-Jul-1997 flipk

delete accidental #if 0


# 1.6 29-Jul-1997 flipk

1) display full time string in 'vmstat' display so you can tell
the difference between an inactive display and a hung machine.
2) Update the man page for 'vmstat' to reflect reality (and actually
explain all those vm abbreviations).

netbsd PR bin/2756 (Jonathan Stone <jonathan@DSG.Stanford.EDU>


Revision tags: OPENBSD_2_1_BASE
# 1.5 20-Dec-1996 downsj

support four letter device names


Revision tags: OPENBSD_2_0_BASE
# 1.4 26-Jun-1996 deraadt

rcsid


# 1.3 25-Jun-1996 tholo

Show interrupt counts on i386.


# 1.2 22-May-1996 deraadt

libutil


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.90 20-Jan-2019 tedu

don't reuse global between functions; the value is wrong.
reported by Bryan Linton


# 1.89 17-Nov-2018 cheloha

Add new KERN_CPUSTATS sysctl(2) so we can identify offline CPUs.

Because of hw.smt we need a way to determine whether a given CPU is "online"
or "offline" from userspace. KERN_CPTIME2 is an array, and so cannot be
cleanly extended for this purpose, so add a new sysctl(2) KERN_CPUSTATS
with an extensible struct. At the moment it's just KERN_CPTIME2 with a
flags member, but it can grow as needed.

KERN_CPUSTATS appears to have been defined by BSDi long ago, but there are
few (if any) packages in the wild still using the symbol so breakage in ports
should be near zero. No other system inherited the symbol from BSDi, either.

Then, use the new sysctl(2) in systat(1) and top(1):

- systat(1) draws placeholder marks ('-') instead of percentages for
offline CPUs in the cpu view.

- systat(1) omits offline CPU ticks when drawing the "big bar" in
the vmstat view. The upshot is that the bar isn't half idle when
half your logical CPUs are disabled.

- top(1) does not draw lines for offline CPUs; if CPUs toggle on or
offline in interactive mode we redraw the display to expand/reduce
space for the new/missing CPUs. This is consistent with what some
top(1) implementations do on Linux.

- top(1) omits offline CPUs from the totals when CPU totals are
combined into a single line (the '-1' flag).

Originally prompted by deraadt@. Discussed endlessly with deraadt@,
ketennis@, and sthen@. Tested by jmc@ and jca@. Earlier versions also
discussed with jca@. Earlier versions tested by jmc@, tb@, and many
others.

docs ok jmc@, kernel bits ok ketennis@, everything ok sthen@,
"Is your stuff in yet?" deraadt@


Revision tags: OPENBSD_6_4_BASE
# 1.88 05-Oct-2018 cheloha

Revert KERN_CPTIME2 ENODEV changes in kernel and userspace.

ok kettenis deraadt


# 1.87 26-Sep-2018 cheloha

KERN_CPTIME2: set ENODEV if the CPU is offline.

This lets userspace distinguish between idle CPUs and those that are
not schedulable because hw.smt=0.

A subsequent commit probably needs to add documentation for this
to sysctl.2 (and perhaps elsewhere) after the dust settles.

Also included here are changes to systat(1) and top(1) that account
for the ENODEV case and adjust behavior accordingly:

- systat(1)'s cpu view prints placeholder marks ('-') instead of
percentages for each state if the given CPU is offline.

- systat(1)'s vmstat view checks for offline CPUs when computing the
machine state total and excludes them, so the CPU usage graph
only represents the states for online CPUs.

- top(1) does not draw CPU rows for offline CPUs when the view is
redrawn. If CPUs "go offline", percentages for each state are
replaced by placeholder marks ('-'); the view will need to be
redrawn to remove these rows. If CPUs "go online" the view will
need to be redrawn to show these new CPUs. In "combined CPU" mode,
the count and the state totals only represent online CPUs.

Ports using KERN_CPTIME2 will need to be updated. The changes
described above to make systat(1) and top(1) aware of the ENODEV
case *and* gracefully handle a changing HW_NCPUONLINE while the
application is running are not necessarily appropriate for each
and every port.

The changes described above are so extensive in part to demonstrate
one way a program *might* be made robust to changing CPU availability.
In particular, changing hw.smt after boot is an extremely rare event,
and this needs to be weighed when updating ports.

The logic needed to account for the KERN_CPTIME2 ENODEV case is
very roughly:

if (sysctl(...) == -1) {
if (errno != ENODEV) {
/* Actual error occurred. */
} else {
/* CPU is offline. */
}
} else {
/* CPU is online and CPU states were set by sysctl(2). */
}

Prompted by deraadt@. Basic idea for ENODEV from kettenis@. Discussed at
length with kettenis@. Additional testing by tb@.

No complaints from hackers@ after a week.

ok kettenis@, "I think you should commit [now]" deraadt@


# 1.86 22-Jun-2018 krw

Constrain IPKTS/OPKTS from floating down beyond the rest of the
displayed lines. Makes vmstat view in tall windows easier to read.

ok sthen@


# 1.85 19-May-2018 bluhm

Do not ignore nice time in systat(1). The sum would not be 100%,
a busy machine would look idle. As %Nic does not fit in the columns,
add it to %Usr. Introduce @ for spinning time to keep the characters
people are used to. Put %Spn between %Int and %Sys like in top.
OK visa@ mpi@


# 1.84 14-May-2018 mpi

Stopping counting and reporting CPU time spent spinning on a lock as
system time.

Introduce a new CP_SPIN "scheduler state" and modify userland tools
to display the % of timer a CPU spents spinning.

Based on a diff from jmatthew@, ok pirofti@, bluhm@, visa@, deraadt@


# 1.83 03-May-2018 otto

test for failing allocation using the standard idiom; prompted by Nan Xiao
ok tb@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.82 18-Dec-2016 krw

Remove statements that have no effect from X(), Y() and Z() #define's.
Leftovers from the re-engining of systat eight years ago. Makes gcc
quieter.

ok otto@ deraadt@


# 1.81 24-Aug-2016 guenther

Convert quad_t to int64_t and %q to %ll
Convert bzero() to memset() and bcopy() to memcpy()

ok natano@ millert@


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.80 20-Aug-2015 deraadt

Do not cast result of malloc/calloc/realloc* if stdlib.h is in scope
ok krw millert


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.79 16-Jan-2015 deraadt

first batch of programs adapting to the namespace cleanup
(pfvar.h nameser.h proc.h ucred.h)
ok guenther millert, and some review from doug as well.


# 1.78 23-Nov-2014 guenther

<sys/buf.h> isn't actually needed here

ok tedu@


# 1.77 15-Sep-2014 miod

Remove non-standard <sys/dkstat.h> header. It has not contained anything
related to disk stastics for almost 17 years, and the remaining
userland-visible defines duplicate those found in <sys/sched.h>.

Move the remaining _KERNEL defines to <sys/tty.h> where they belong, and
update all users to cope with this.

ok kettenis@


Revision tags: OPENBSD_5_6_BASE
# 1.76 08-Apr-2014 mpi

Use VM_UVMEXP instead of VM_METER for memory usages and directly
include <sys/vmmeter.h> where it is needed instead of relying on
it being included by <uvm/uvm_extern.h>.

miod@ likes it, ok guenther@


Revision tags: OPENBSD_5_5_BASE
# 1.75 31-Oct-2013 deraadt

sometimes we find .h we no longer need


Revision tags: OPENBSD_5_4_BASE
# 1.74 14-May-2013 miod

Don't display swapin/swapout uvmexp fields


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.73 19-Nov-2010 mikeb

Make KERN_CPTIME return an avarage number of ticks across all CPUs
tedu agreed with an idea, tested by Luis Useche and me; ok deraadt


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE
# 1.72 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


# 1.71 14-Aug-2009 deraadt

tie IPKTS/OPKTS to bottom corner for smaller screens


# 1.70 13-Aug-2009 deraadt

there are louder and louder moans about the inability to see packet
rates at the same time as interrupt counts, so sneak them into the
bottom corner of the vmstat screen
ok dlg


Revision tags: OPENBSD_4_6_BASE
# 1.69 03-May-2009 drahn

Hinge at the natural rollover point 9999x instead of 1024x when switching to
the next unit K->M->G. ok deraadt@


# 1.68 30-Mar-2009 deraadt

allow the disk transfer speed numbers to show useable numbers when disks
get really fast; ok canacar


Revision tags: OPENBSD_4_5_BASE
# 1.67 07-Dec-2008 canacar

Warning cleanup including unused variables and shadowed names


# 1.66 01-Nov-2008 canacar

Improve reporting of cache misses in the vmstat view. Previously
the misses field may report negative values. The hit/miss numbers
does not exactly reflect the statistics collected by the kernel
but this is close enough.

Report & patch from Bjorn Anderss, input from beck@ and thib@


Revision tags: OPENBSD_4_4_BASE
# 1.65 13-Jun-2008 deraadt

compile on older gcc; no decl after code


# 1.64 12-Jun-2008 canacar

New display engine for systat, based on pftop. Adds new views for pf
(status, state, rule, queue). While all displays work, some keyboard
comands are not implemented yet. Other features include better handling
of display resize and scrolling for long views. Committing now to fix
the remaining issues in the tree.
Testing and comments by otto@ and harding@, ok deraadt@


Revision tags: OPENBSD_4_3_BASE
# 1.63 01-Sep-2007 deraadt

malloc(n * m) -> calloc(n, m); from zinovik


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.62 25-Feb-2007 deraadt

use the 1 line load line from 'systat vm' on all the other displays, giving
them more room. much cleaner, and it is less code too; ok deanna


# 1.61 13-Nov-2006 otto

fix macro abuse leading to stray numbers in the vm display.
ok a whole lot of devs@


Revision tags: OPENBSD_4_0_BASE
# 1.60 14-Apr-2006 dlg

remove comments that says we dont count intr time and remove some code that
fudges the output to stay clean when intr time wasnt shown. not needed
since we show it now.


# 1.59 14-Apr-2006 dlg

show cpu time spent in interrupts. ive been wanting this for years.

tweaks by deraadt@ ok by many


# 1.58 31-Mar-2006 deraadt

spacing


# 1.57 31-Mar-2006 deraadt

fairly simple cleanup, lots of testing done


# 1.56 28-Mar-2006 mickey

give more space to the memory columns in vm page; deraadt@ ok


Revision tags: OPENBSD_3_9_BASE
# 1.55 28-Sep-2005 pedro

- when we run out of static kernel map entries, grab a fresh page using
the uvm_km_page allocator and use it instead of calling panic()
- add a counter to uvmexp so we can keep track of how many map entries
we have in use

idea from tedu@, long ago, okay deraadt@


Revision tags: OPENBSD_3_8_BASE
# 1.54 04-Apr-2005 deraadt

nlist.h not needed


Revision tags: OPENBSD_3_7_BASE
# 1.53 23-Sep-2004 deraadt

adapt to KERN_INTRCNT_CNT returning a quad, from danh (imported now to
avoid tree breakage)


Revision tags: OPENBSD_3_6_BASE
# 1.52 09-Jul-2004 deraadt

remove post-mortem stuff (sysctl only here)


# 1.51 28-Jun-2004 aaron

Remove special #if defined(__i386__) code from systat and vmstat. We now use
sysctl to fetch interrupt counters on all architectures. Also add new '-z'
flag to vmstat which means show all devices, even those that have not yet
generated an interrupt. deraadt@ tholo@ drahn@ millert@ ok


# 1.50 11-Jun-2004 deraadt

divide etime by ncpu


# 1.49 11-Jun-2004 deraadt

oops


# 1.48 11-Jun-2004 deraadt

on i386 machines, attempt to peek inside apic_intrhand[] as well, so that
MP machines get interrupt counters. will be replaced by a MI subsystem
one day. most code from drahn, few final bugs fixed by me


# 1.47 22-May-2004 henning

with modern disks data transfers rates above 10000 kByte/s are seen
regularily, make the disk columns a little wider so it doesn't run into
the neighboring column, theo ok


# 1.46 23-Apr-2004 tedu

don't print stats until they're stable, prevents seeing weird stuff in
disk columns. tested by jolan@. from pedro martelletto


Revision tags: OPENBSD_3_5_BASE
# 1.45 15-Feb-2004 tedu

'split' command for iostat mode
from Pedro Martelletto <pbastos@rdc.puc-rio.br>


# 1.44 15-Feb-2004 tedu

new arg to disk_unbusy, to record separate read/write statistics.
looked at by various, testing henning@ mcbride@ dan weeks
mostly from netbsd via Pedro Martelletto <pbastos@rdc.puc-rio.br>


# 1.43 16-Oct-2003 mickey

duh


# 1.42 15-Oct-2003 mickey

also print the uvmexp.zeropages if there is space in vm screen


Revision tags: OPENBSD_3_4_BASE
# 1.41 03-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


# 1.40 14-Apr-2003 deraadt

remove old comment


# 1.39 08-Apr-2003 deraadt

string cleaning; ok tdeval


Revision tags: OPENBSD_3_3_BASE
# 1.38 28-Feb-2003 jason

intrcnt's are ints not longs (at least according to the new kern.intrcnt stuff)


# 1.37 16-Dec-2002 tdeval

Make systat(1), iostat(8) and vmstat(8) automatically update their disk
statistics when a device is added/removed. ok deraadt@


Revision tags: OPENBSD_3_2_BASE
# 1.36 19-Jun-2002 deraadt

mark which nlist[] kmem entries are not needed in the sysctl case, and which are


# 1.35 18-Jun-2002 deraadt

ANSI


# 1.34 29-Apr-2002 millert

Fix 32bit int oflow when there is > 2GB vm; peters AT telia DOT net


Revision tags: OPENBSD_3_1_BASE
# 1.33 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


# 1.32 16-Feb-2002 tdeval

Some disk names are longer than 4. Cope with that.
ok deraadt@


# 1.31 07-Dec-2001 deraadt

move back. pvalchev -- the bug was quite obscure


# 1.30 07-Dec-2001 pvalchev

back out latest changes which cause problems on alpha/sparc64 until
they are fixed


# 1.29 23-Nov-2001 deraadt

fix signal races. use sysctl() instead of kvm where possible, and then KNF
the hell out of it; checked by miod


# 1.28 19-Nov-2001 mpech

kill more registers

millert@ ok


# 1.27 18-Nov-2001 deraadt

slightly expand the Csw/Trp/Sys/Int/Sof spacing


# 1.26 06-Nov-2001 art

New vm includes.


Revision tags: OPENBSD_3_0_BASE
# 1.25 28-Aug-2001 weingart

Add information on number/percentage of namei calls missed the cache.
millert@ ok.


# 1.24 27-Jun-2001 art

UVM is no longer an option


# 1.23 22-Jun-2001 lebel

use strlcpy vs strncpy+a[len-1]='\0'


# 1.22 04-May-2001 ericj

handle kvm_nlist() failing, from pr#1798.
Patch similar to the one submitted by <peterw@documenta.com.au>


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.21 22-Feb-2000 deraadt

_total is no longer a symbol in the kernel


# 1.20 26-Oct-1999 art

Fix printing of interrupts with UVM.


# 1.19 26-Oct-1999 art

support UVM. (much code from NetBSD)


Revision tags: OPENBSD_2_6_BASE
# 1.18 16-Jun-1999 espie

Fixed i386 -> __i386__


Revision tags: OPENBSD_2_5_BASE
# 1.17 19-Dec-1998 deraadt

move Act Free field over one


Revision tags: OPENBSD_2_4_BASE
# 1.16 13-Jul-1998 millert

ftpd: sleep for an indeterminate amount for non-existant logins
to simulate a crypt, like login does.
Use SEEK_* not L_* and kill some 0L's used in lseek while we're there.


# 1.15 12-Jun-1998 marc

fix vm load display


Revision tags: OPENBSD_2_3_BASE
# 1.14 19-Dec-1997 deraadt

comment this strncpy is safe


# 1.13 19-Dec-1997 deraadt

proactive buffer blocks


# 1.12 19-Dec-1997 deraadt

bye bye sprintf


# 1.11 24-Nov-1997 kstailey

Deal with the fact that PUTRATE() is a macro that contains braces by
surrounding it with braces after an ``if ()''.


# 1.10 22-Nov-1997 mickey

remove unused kernel vars


# 1.9 22-Nov-1997 kstailey

back out 1.8, will fix in another way.


# 1.8 22-Nov-1997 kstailey

Make vmstat mode display actually fit in 80x24.
Exploits fact that swap display is always blank.


Revision tags: OPENBSD_2_2_BASE
# 1.7 29-Jul-1997 flipk

delete accidental #if 0


# 1.6 29-Jul-1997 flipk

1) display full time string in 'vmstat' display so you can tell
the difference between an inactive display and a hung machine.
2) Update the man page for 'vmstat' to reflect reality (and actually
explain all those vm abbreviations).

netbsd PR bin/2756 (Jonathan Stone <jonathan@DSG.Stanford.EDU>


Revision tags: OPENBSD_2_1_BASE
# 1.5 20-Dec-1996 downsj

support four letter device names


Revision tags: OPENBSD_2_0_BASE
# 1.4 26-Jun-1996 deraadt

rcsid


# 1.3 25-Jun-1996 tholo

Show interrupt counts on i386.


# 1.2 22-May-1996 deraadt

libutil


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.89 17-Nov-2018 cheloha

Add new KERN_CPUSTATS sysctl(2) so we can identify offline CPUs.

Because of hw.smt we need a way to determine whether a given CPU is "online"
or "offline" from userspace. KERN_CPTIME2 is an array, and so cannot be
cleanly extended for this purpose, so add a new sysctl(2) KERN_CPUSTATS
with an extensible struct. At the moment it's just KERN_CPTIME2 with a
flags member, but it can grow as needed.

KERN_CPUSTATS appears to have been defined by BSDi long ago, but there are
few (if any) packages in the wild still using the symbol so breakage in ports
should be near zero. No other system inherited the symbol from BSDi, either.

Then, use the new sysctl(2) in systat(1) and top(1):

- systat(1) draws placeholder marks ('-') instead of percentages for
offline CPUs in the cpu view.

- systat(1) omits offline CPU ticks when drawing the "big bar" in
the vmstat view. The upshot is that the bar isn't half idle when
half your logical CPUs are disabled.

- top(1) does not draw lines for offline CPUs; if CPUs toggle on or
offline in interactive mode we redraw the display to expand/reduce
space for the new/missing CPUs. This is consistent with what some
top(1) implementations do on Linux.

- top(1) omits offline CPUs from the totals when CPU totals are
combined into a single line (the '-1' flag).

Originally prompted by deraadt@. Discussed endlessly with deraadt@,
ketennis@, and sthen@. Tested by jmc@ and jca@. Earlier versions also
discussed with jca@. Earlier versions tested by jmc@, tb@, and many
others.

docs ok jmc@, kernel bits ok ketennis@, everything ok sthen@,
"Is your stuff in yet?" deraadt@


Revision tags: OPENBSD_6_4_BASE
# 1.88 05-Oct-2018 cheloha

Revert KERN_CPTIME2 ENODEV changes in kernel and userspace.

ok kettenis deraadt


# 1.87 26-Sep-2018 cheloha

KERN_CPTIME2: set ENODEV if the CPU is offline.

This lets userspace distinguish between idle CPUs and those that are
not schedulable because hw.smt=0.

A subsequent commit probably needs to add documentation for this
to sysctl.2 (and perhaps elsewhere) after the dust settles.

Also included here are changes to systat(1) and top(1) that account
for the ENODEV case and adjust behavior accordingly:

- systat(1)'s cpu view prints placeholder marks ('-') instead of
percentages for each state if the given CPU is offline.

- systat(1)'s vmstat view checks for offline CPUs when computing the
machine state total and excludes them, so the CPU usage graph
only represents the states for online CPUs.

- top(1) does not draw CPU rows for offline CPUs when the view is
redrawn. If CPUs "go offline", percentages for each state are
replaced by placeholder marks ('-'); the view will need to be
redrawn to remove these rows. If CPUs "go online" the view will
need to be redrawn to show these new CPUs. In "combined CPU" mode,
the count and the state totals only represent online CPUs.

Ports using KERN_CPTIME2 will need to be updated. The changes
described above to make systat(1) and top(1) aware of the ENODEV
case *and* gracefully handle a changing HW_NCPUONLINE while the
application is running are not necessarily appropriate for each
and every port.

The changes described above are so extensive in part to demonstrate
one way a program *might* be made robust to changing CPU availability.
In particular, changing hw.smt after boot is an extremely rare event,
and this needs to be weighed when updating ports.

The logic needed to account for the KERN_CPTIME2 ENODEV case is
very roughly:

if (sysctl(...) == -1) {
if (errno != ENODEV) {
/* Actual error occurred. */
} else {
/* CPU is offline. */
}
} else {
/* CPU is online and CPU states were set by sysctl(2). */
}

Prompted by deraadt@. Basic idea for ENODEV from kettenis@. Discussed at
length with kettenis@. Additional testing by tb@.

No complaints from hackers@ after a week.

ok kettenis@, "I think you should commit [now]" deraadt@


# 1.86 22-Jun-2018 krw

Constrain IPKTS/OPKTS from floating down beyond the rest of the
displayed lines. Makes vmstat view in tall windows easier to read.

ok sthen@


# 1.85 19-May-2018 bluhm

Do not ignore nice time in systat(1). The sum would not be 100%,
a busy machine would look idle. As %Nic does not fit in the columns,
add it to %Usr. Introduce @ for spinning time to keep the characters
people are used to. Put %Spn between %Int and %Sys like in top.
OK visa@ mpi@


# 1.84 14-May-2018 mpi

Stopping counting and reporting CPU time spent spinning on a lock as
system time.

Introduce a new CP_SPIN "scheduler state" and modify userland tools
to display the % of timer a CPU spents spinning.

Based on a diff from jmatthew@, ok pirofti@, bluhm@, visa@, deraadt@


# 1.83 03-May-2018 otto

test for failing allocation using the standard idiom; prompted by Nan Xiao
ok tb@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.82 18-Dec-2016 krw

Remove statements that have no effect from X(), Y() and Z() #define's.
Leftovers from the re-engining of systat eight years ago. Makes gcc
quieter.

ok otto@ deraadt@


# 1.81 24-Aug-2016 guenther

Convert quad_t to int64_t and %q to %ll
Convert bzero() to memset() and bcopy() to memcpy()

ok natano@ millert@


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.80 20-Aug-2015 deraadt

Do not cast result of malloc/calloc/realloc* if stdlib.h is in scope
ok krw millert


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.79 16-Jan-2015 deraadt

first batch of programs adapting to the namespace cleanup
(pfvar.h nameser.h proc.h ucred.h)
ok guenther millert, and some review from doug as well.


# 1.78 23-Nov-2014 guenther

<sys/buf.h> isn't actually needed here

ok tedu@


# 1.77 15-Sep-2014 miod

Remove non-standard <sys/dkstat.h> header. It has not contained anything
related to disk stastics for almost 17 years, and the remaining
userland-visible defines duplicate those found in <sys/sched.h>.

Move the remaining _KERNEL defines to <sys/tty.h> where they belong, and
update all users to cope with this.

ok kettenis@


Revision tags: OPENBSD_5_6_BASE
# 1.76 08-Apr-2014 mpi

Use VM_UVMEXP instead of VM_METER for memory usages and directly
include <sys/vmmeter.h> where it is needed instead of relying on
it being included by <uvm/uvm_extern.h>.

miod@ likes it, ok guenther@


Revision tags: OPENBSD_5_5_BASE
# 1.75 31-Oct-2013 deraadt

sometimes we find .h we no longer need


Revision tags: OPENBSD_5_4_BASE
# 1.74 14-May-2013 miod

Don't display swapin/swapout uvmexp fields


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.73 19-Nov-2010 mikeb

Make KERN_CPTIME return an avarage number of ticks across all CPUs
tedu agreed with an idea, tested by Luis Useche and me; ok deraadt


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE
# 1.72 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


# 1.71 14-Aug-2009 deraadt

tie IPKTS/OPKTS to bottom corner for smaller screens


# 1.70 13-Aug-2009 deraadt

there are louder and louder moans about the inability to see packet
rates at the same time as interrupt counts, so sneak them into the
bottom corner of the vmstat screen
ok dlg


Revision tags: OPENBSD_4_6_BASE
# 1.69 03-May-2009 drahn

Hinge at the natural rollover point 9999x instead of 1024x when switching to
the next unit K->M->G. ok deraadt@


# 1.68 30-Mar-2009 deraadt

allow the disk transfer speed numbers to show useable numbers when disks
get really fast; ok canacar


Revision tags: OPENBSD_4_5_BASE
# 1.67 07-Dec-2008 canacar

Warning cleanup including unused variables and shadowed names


# 1.66 01-Nov-2008 canacar

Improve reporting of cache misses in the vmstat view. Previously
the misses field may report negative values. The hit/miss numbers
does not exactly reflect the statistics collected by the kernel
but this is close enough.

Report & patch from Bjorn Anderss, input from beck@ and thib@


Revision tags: OPENBSD_4_4_BASE
# 1.65 13-Jun-2008 deraadt

compile on older gcc; no decl after code


# 1.64 12-Jun-2008 canacar

New display engine for systat, based on pftop. Adds new views for pf
(status, state, rule, queue). While all displays work, some keyboard
comands are not implemented yet. Other features include better handling
of display resize and scrolling for long views. Committing now to fix
the remaining issues in the tree.
Testing and comments by otto@ and harding@, ok deraadt@


Revision tags: OPENBSD_4_3_BASE
# 1.63 01-Sep-2007 deraadt

malloc(n * m) -> calloc(n, m); from zinovik


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.62 25-Feb-2007 deraadt

use the 1 line load line from 'systat vm' on all the other displays, giving
them more room. much cleaner, and it is less code too; ok deanna


# 1.61 13-Nov-2006 otto

fix macro abuse leading to stray numbers in the vm display.
ok a whole lot of devs@


Revision tags: OPENBSD_4_0_BASE
# 1.60 14-Apr-2006 dlg

remove comments that says we dont count intr time and remove some code that
fudges the output to stay clean when intr time wasnt shown. not needed
since we show it now.


# 1.59 14-Apr-2006 dlg

show cpu time spent in interrupts. ive been wanting this for years.

tweaks by deraadt@ ok by many


# 1.58 31-Mar-2006 deraadt

spacing


# 1.57 31-Mar-2006 deraadt

fairly simple cleanup, lots of testing done


# 1.56 28-Mar-2006 mickey

give more space to the memory columns in vm page; deraadt@ ok


Revision tags: OPENBSD_3_9_BASE
# 1.55 28-Sep-2005 pedro

- when we run out of static kernel map entries, grab a fresh page using
the uvm_km_page allocator and use it instead of calling panic()
- add a counter to uvmexp so we can keep track of how many map entries
we have in use

idea from tedu@, long ago, okay deraadt@


Revision tags: OPENBSD_3_8_BASE
# 1.54 04-Apr-2005 deraadt

nlist.h not needed


Revision tags: OPENBSD_3_7_BASE
# 1.53 23-Sep-2004 deraadt

adapt to KERN_INTRCNT_CNT returning a quad, from danh (imported now to
avoid tree breakage)


Revision tags: OPENBSD_3_6_BASE
# 1.52 09-Jul-2004 deraadt

remove post-mortem stuff (sysctl only here)


# 1.51 28-Jun-2004 aaron

Remove special #if defined(__i386__) code from systat and vmstat. We now use
sysctl to fetch interrupt counters on all architectures. Also add new '-z'
flag to vmstat which means show all devices, even those that have not yet
generated an interrupt. deraadt@ tholo@ drahn@ millert@ ok


# 1.50 11-Jun-2004 deraadt

divide etime by ncpu


# 1.49 11-Jun-2004 deraadt

oops


# 1.48 11-Jun-2004 deraadt

on i386 machines, attempt to peek inside apic_intrhand[] as well, so that
MP machines get interrupt counters. will be replaced by a MI subsystem
one day. most code from drahn, few final bugs fixed by me


# 1.47 22-May-2004 henning

with modern disks data transfers rates above 10000 kByte/s are seen
regularily, make the disk columns a little wider so it doesn't run into
the neighboring column, theo ok


# 1.46 23-Apr-2004 tedu

don't print stats until they're stable, prevents seeing weird stuff in
disk columns. tested by jolan@. from pedro martelletto


Revision tags: OPENBSD_3_5_BASE
# 1.45 15-Feb-2004 tedu

'split' command for iostat mode
from Pedro Martelletto <pbastos@rdc.puc-rio.br>


# 1.44 15-Feb-2004 tedu

new arg to disk_unbusy, to record separate read/write statistics.
looked at by various, testing henning@ mcbride@ dan weeks
mostly from netbsd via Pedro Martelletto <pbastos@rdc.puc-rio.br>


# 1.43 16-Oct-2003 mickey

duh


# 1.42 15-Oct-2003 mickey

also print the uvmexp.zeropages if there is space in vm screen


Revision tags: OPENBSD_3_4_BASE
# 1.41 03-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


# 1.40 14-Apr-2003 deraadt

remove old comment


# 1.39 08-Apr-2003 deraadt

string cleaning; ok tdeval


Revision tags: OPENBSD_3_3_BASE
# 1.38 28-Feb-2003 jason

intrcnt's are ints not longs (at least according to the new kern.intrcnt stuff)


# 1.37 16-Dec-2002 tdeval

Make systat(1), iostat(8) and vmstat(8) automatically update their disk
statistics when a device is added/removed. ok deraadt@


Revision tags: OPENBSD_3_2_BASE
# 1.36 19-Jun-2002 deraadt

mark which nlist[] kmem entries are not needed in the sysctl case, and which are


# 1.35 18-Jun-2002 deraadt

ANSI


# 1.34 29-Apr-2002 millert

Fix 32bit int oflow when there is > 2GB vm; peters AT telia DOT net


Revision tags: OPENBSD_3_1_BASE
# 1.33 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


# 1.32 16-Feb-2002 tdeval

Some disk names are longer than 4. Cope with that.
ok deraadt@


# 1.31 07-Dec-2001 deraadt

move back. pvalchev -- the bug was quite obscure


# 1.30 07-Dec-2001 pvalchev

back out latest changes which cause problems on alpha/sparc64 until
they are fixed


# 1.29 23-Nov-2001 deraadt

fix signal races. use sysctl() instead of kvm where possible, and then KNF
the hell out of it; checked by miod


# 1.28 19-Nov-2001 mpech

kill more registers

millert@ ok


# 1.27 18-Nov-2001 deraadt

slightly expand the Csw/Trp/Sys/Int/Sof spacing


# 1.26 06-Nov-2001 art

New vm includes.


Revision tags: OPENBSD_3_0_BASE
# 1.25 28-Aug-2001 weingart

Add information on number/percentage of namei calls missed the cache.
millert@ ok.


# 1.24 27-Jun-2001 art

UVM is no longer an option


# 1.23 22-Jun-2001 lebel

use strlcpy vs strncpy+a[len-1]='\0'


# 1.22 04-May-2001 ericj

handle kvm_nlist() failing, from pr#1798.
Patch similar to the one submitted by <peterw@documenta.com.au>


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.21 22-Feb-2000 deraadt

_total is no longer a symbol in the kernel


# 1.20 26-Oct-1999 art

Fix printing of interrupts with UVM.


# 1.19 26-Oct-1999 art

support UVM. (much code from NetBSD)


Revision tags: OPENBSD_2_6_BASE
# 1.18 16-Jun-1999 espie

Fixed i386 -> __i386__


Revision tags: OPENBSD_2_5_BASE
# 1.17 19-Dec-1998 deraadt

move Act Free field over one


Revision tags: OPENBSD_2_4_BASE
# 1.16 13-Jul-1998 millert

ftpd: sleep for an indeterminate amount for non-existant logins
to simulate a crypt, like login does.
Use SEEK_* not L_* and kill some 0L's used in lseek while we're there.


# 1.15 12-Jun-1998 marc

fix vm load display


Revision tags: OPENBSD_2_3_BASE
# 1.14 19-Dec-1997 deraadt

comment this strncpy is safe


# 1.13 19-Dec-1997 deraadt

proactive buffer blocks


# 1.12 19-Dec-1997 deraadt

bye bye sprintf


# 1.11 24-Nov-1997 kstailey

Deal with the fact that PUTRATE() is a macro that contains braces by
surrounding it with braces after an ``if ()''.


# 1.10 22-Nov-1997 mickey

remove unused kernel vars


# 1.9 22-Nov-1997 kstailey

back out 1.8, will fix in another way.


# 1.8 22-Nov-1997 kstailey

Make vmstat mode display actually fit in 80x24.
Exploits fact that swap display is always blank.


Revision tags: OPENBSD_2_2_BASE
# 1.7 29-Jul-1997 flipk

delete accidental #if 0


# 1.6 29-Jul-1997 flipk

1) display full time string in 'vmstat' display so you can tell
the difference between an inactive display and a hung machine.
2) Update the man page for 'vmstat' to reflect reality (and actually
explain all those vm abbreviations).

netbsd PR bin/2756 (Jonathan Stone <jonathan@DSG.Stanford.EDU>


Revision tags: OPENBSD_2_1_BASE
# 1.5 20-Dec-1996 downsj

support four letter device names


Revision tags: OPENBSD_2_0_BASE
# 1.4 26-Jun-1996 deraadt

rcsid


# 1.3 25-Jun-1996 tholo

Show interrupt counts on i386.


# 1.2 22-May-1996 deraadt

libutil


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.88 05-Oct-2018 cheloha

Revert KERN_CPTIME2 ENODEV changes in kernel and userspace.

ok kettenis deraadt


# 1.87 26-Sep-2018 cheloha

KERN_CPTIME2: set ENODEV if the CPU is offline.

This lets userspace distinguish between idle CPUs and those that are
not schedulable because hw.smt=0.

A subsequent commit probably needs to add documentation for this
to sysctl.2 (and perhaps elsewhere) after the dust settles.

Also included here are changes to systat(1) and top(1) that account
for the ENODEV case and adjust behavior accordingly:

- systat(1)'s cpu view prints placeholder marks ('-') instead of
percentages for each state if the given CPU is offline.

- systat(1)'s vmstat view checks for offline CPUs when computing the
machine state total and excludes them, so the CPU usage graph
only represents the states for online CPUs.

- top(1) does not draw CPU rows for offline CPUs when the view is
redrawn. If CPUs "go offline", percentages for each state are
replaced by placeholder marks ('-'); the view will need to be
redrawn to remove these rows. If CPUs "go online" the view will
need to be redrawn to show these new CPUs. In "combined CPU" mode,
the count and the state totals only represent online CPUs.

Ports using KERN_CPTIME2 will need to be updated. The changes
described above to make systat(1) and top(1) aware of the ENODEV
case *and* gracefully handle a changing HW_NCPUONLINE while the
application is running are not necessarily appropriate for each
and every port.

The changes described above are so extensive in part to demonstrate
one way a program *might* be made robust to changing CPU availability.
In particular, changing hw.smt after boot is an extremely rare event,
and this needs to be weighed when updating ports.

The logic needed to account for the KERN_CPTIME2 ENODEV case is
very roughly:

if (sysctl(...) == -1) {
if (errno != ENODEV) {
/* Actual error occurred. */
} else {
/* CPU is offline. */
}
} else {
/* CPU is online and CPU states were set by sysctl(2). */
}

Prompted by deraadt@. Basic idea for ENODEV from kettenis@. Discussed at
length with kettenis@. Additional testing by tb@.

No complaints from hackers@ after a week.

ok kettenis@, "I think you should commit [now]" deraadt@


# 1.86 22-Jun-2018 krw

Constrain IPKTS/OPKTS from floating down beyond the rest of the
displayed lines. Makes vmstat view in tall windows easier to read.

ok sthen@


# 1.85 19-May-2018 bluhm

Do not ignore nice time in systat(1). The sum would not be 100%,
a busy machine would look idle. As %Nic does not fit in the columns,
add it to %Usr. Introduce @ for spinning time to keep the characters
people are used to. Put %Spn between %Int and %Sys like in top.
OK visa@ mpi@


# 1.84 14-May-2018 mpi

Stopping counting and reporting CPU time spent spinning on a lock as
system time.

Introduce a new CP_SPIN "scheduler state" and modify userland tools
to display the % of timer a CPU spents spinning.

Based on a diff from jmatthew@, ok pirofti@, bluhm@, visa@, deraadt@


# 1.83 03-May-2018 otto

test for failing allocation using the standard idiom; prompted by Nan Xiao
ok tb@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.82 18-Dec-2016 krw

Remove statements that have no effect from X(), Y() and Z() #define's.
Leftovers from the re-engining of systat eight years ago. Makes gcc
quieter.

ok otto@ deraadt@


# 1.81 24-Aug-2016 guenther

Convert quad_t to int64_t and %q to %ll
Convert bzero() to memset() and bcopy() to memcpy()

ok natano@ millert@


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.80 20-Aug-2015 deraadt

Do not cast result of malloc/calloc/realloc* if stdlib.h is in scope
ok krw millert


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.79 16-Jan-2015 deraadt

first batch of programs adapting to the namespace cleanup
(pfvar.h nameser.h proc.h ucred.h)
ok guenther millert, and some review from doug as well.


# 1.78 23-Nov-2014 guenther

<sys/buf.h> isn't actually needed here

ok tedu@


# 1.77 15-Sep-2014 miod

Remove non-standard <sys/dkstat.h> header. It has not contained anything
related to disk stastics for almost 17 years, and the remaining
userland-visible defines duplicate those found in <sys/sched.h>.

Move the remaining _KERNEL defines to <sys/tty.h> where they belong, and
update all users to cope with this.

ok kettenis@


Revision tags: OPENBSD_5_6_BASE
# 1.76 08-Apr-2014 mpi

Use VM_UVMEXP instead of VM_METER for memory usages and directly
include <sys/vmmeter.h> where it is needed instead of relying on
it being included by <uvm/uvm_extern.h>.

miod@ likes it, ok guenther@


Revision tags: OPENBSD_5_5_BASE
# 1.75 31-Oct-2013 deraadt

sometimes we find .h we no longer need


Revision tags: OPENBSD_5_4_BASE
# 1.74 14-May-2013 miod

Don't display swapin/swapout uvmexp fields


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.73 19-Nov-2010 mikeb

Make KERN_CPTIME return an avarage number of ticks across all CPUs
tedu agreed with an idea, tested by Luis Useche and me; ok deraadt


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE
# 1.72 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


# 1.71 14-Aug-2009 deraadt

tie IPKTS/OPKTS to bottom corner for smaller screens


# 1.70 13-Aug-2009 deraadt

there are louder and louder moans about the inability to see packet
rates at the same time as interrupt counts, so sneak them into the
bottom corner of the vmstat screen
ok dlg


Revision tags: OPENBSD_4_6_BASE
# 1.69 03-May-2009 drahn

Hinge at the natural rollover point 9999x instead of 1024x when switching to
the next unit K->M->G. ok deraadt@


# 1.68 30-Mar-2009 deraadt

allow the disk transfer speed numbers to show useable numbers when disks
get really fast; ok canacar


Revision tags: OPENBSD_4_5_BASE
# 1.67 07-Dec-2008 canacar

Warning cleanup including unused variables and shadowed names


# 1.66 01-Nov-2008 canacar

Improve reporting of cache misses in the vmstat view. Previously
the misses field may report negative values. The hit/miss numbers
does not exactly reflect the statistics collected by the kernel
but this is close enough.

Report & patch from Bjorn Anderss, input from beck@ and thib@


Revision tags: OPENBSD_4_4_BASE
# 1.65 13-Jun-2008 deraadt

compile on older gcc; no decl after code


# 1.64 12-Jun-2008 canacar

New display engine for systat, based on pftop. Adds new views for pf
(status, state, rule, queue). While all displays work, some keyboard
comands are not implemented yet. Other features include better handling
of display resize and scrolling for long views. Committing now to fix
the remaining issues in the tree.
Testing and comments by otto@ and harding@, ok deraadt@


Revision tags: OPENBSD_4_3_BASE
# 1.63 01-Sep-2007 deraadt

malloc(n * m) -> calloc(n, m); from zinovik


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.62 25-Feb-2007 deraadt

use the 1 line load line from 'systat vm' on all the other displays, giving
them more room. much cleaner, and it is less code too; ok deanna


# 1.61 13-Nov-2006 otto

fix macro abuse leading to stray numbers in the vm display.
ok a whole lot of devs@


Revision tags: OPENBSD_4_0_BASE
# 1.60 14-Apr-2006 dlg

remove comments that says we dont count intr time and remove some code that
fudges the output to stay clean when intr time wasnt shown. not needed
since we show it now.


# 1.59 14-Apr-2006 dlg

show cpu time spent in interrupts. ive been wanting this for years.

tweaks by deraadt@ ok by many


# 1.58 31-Mar-2006 deraadt

spacing


# 1.57 31-Mar-2006 deraadt

fairly simple cleanup, lots of testing done


# 1.56 28-Mar-2006 mickey

give more space to the memory columns in vm page; deraadt@ ok


Revision tags: OPENBSD_3_9_BASE
# 1.55 28-Sep-2005 pedro

- when we run out of static kernel map entries, grab a fresh page using
the uvm_km_page allocator and use it instead of calling panic()
- add a counter to uvmexp so we can keep track of how many map entries
we have in use

idea from tedu@, long ago, okay deraadt@


Revision tags: OPENBSD_3_8_BASE
# 1.54 04-Apr-2005 deraadt

nlist.h not needed


Revision tags: OPENBSD_3_7_BASE
# 1.53 23-Sep-2004 deraadt

adapt to KERN_INTRCNT_CNT returning a quad, from danh (imported now to
avoid tree breakage)


Revision tags: OPENBSD_3_6_BASE
# 1.52 09-Jul-2004 deraadt

remove post-mortem stuff (sysctl only here)


# 1.51 28-Jun-2004 aaron

Remove special #if defined(__i386__) code from systat and vmstat. We now use
sysctl to fetch interrupt counters on all architectures. Also add new '-z'
flag to vmstat which means show all devices, even those that have not yet
generated an interrupt. deraadt@ tholo@ drahn@ millert@ ok


# 1.50 11-Jun-2004 deraadt

divide etime by ncpu


# 1.49 11-Jun-2004 deraadt

oops


# 1.48 11-Jun-2004 deraadt

on i386 machines, attempt to peek inside apic_intrhand[] as well, so that
MP machines get interrupt counters. will be replaced by a MI subsystem
one day. most code from drahn, few final bugs fixed by me


# 1.47 22-May-2004 henning

with modern disks data transfers rates above 10000 kByte/s are seen
regularily, make the disk columns a little wider so it doesn't run into
the neighboring column, theo ok


# 1.46 23-Apr-2004 tedu

don't print stats until they're stable, prevents seeing weird stuff in
disk columns. tested by jolan@. from pedro martelletto


Revision tags: OPENBSD_3_5_BASE
# 1.45 15-Feb-2004 tedu

'split' command for iostat mode
from Pedro Martelletto <pbastos@rdc.puc-rio.br>


# 1.44 15-Feb-2004 tedu

new arg to disk_unbusy, to record separate read/write statistics.
looked at by various, testing henning@ mcbride@ dan weeks
mostly from netbsd via Pedro Martelletto <pbastos@rdc.puc-rio.br>


# 1.43 16-Oct-2003 mickey

duh


# 1.42 15-Oct-2003 mickey

also print the uvmexp.zeropages if there is space in vm screen


Revision tags: OPENBSD_3_4_BASE
# 1.41 03-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


# 1.40 14-Apr-2003 deraadt

remove old comment


# 1.39 08-Apr-2003 deraadt

string cleaning; ok tdeval


Revision tags: OPENBSD_3_3_BASE
# 1.38 28-Feb-2003 jason

intrcnt's are ints not longs (at least according to the new kern.intrcnt stuff)


# 1.37 16-Dec-2002 tdeval

Make systat(1), iostat(8) and vmstat(8) automatically update their disk
statistics when a device is added/removed. ok deraadt@


Revision tags: OPENBSD_3_2_BASE
# 1.36 19-Jun-2002 deraadt

mark which nlist[] kmem entries are not needed in the sysctl case, and which are


# 1.35 18-Jun-2002 deraadt

ANSI


# 1.34 29-Apr-2002 millert

Fix 32bit int oflow when there is > 2GB vm; peters AT telia DOT net


Revision tags: OPENBSD_3_1_BASE
# 1.33 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


# 1.32 16-Feb-2002 tdeval

Some disk names are longer than 4. Cope with that.
ok deraadt@


# 1.31 07-Dec-2001 deraadt

move back. pvalchev -- the bug was quite obscure


# 1.30 07-Dec-2001 pvalchev

back out latest changes which cause problems on alpha/sparc64 until
they are fixed


# 1.29 23-Nov-2001 deraadt

fix signal races. use sysctl() instead of kvm where possible, and then KNF
the hell out of it; checked by miod


# 1.28 19-Nov-2001 mpech

kill more registers

millert@ ok


# 1.27 18-Nov-2001 deraadt

slightly expand the Csw/Trp/Sys/Int/Sof spacing


# 1.26 06-Nov-2001 art

New vm includes.


Revision tags: OPENBSD_3_0_BASE
# 1.25 28-Aug-2001 weingart

Add information on number/percentage of namei calls missed the cache.
millert@ ok.


# 1.24 27-Jun-2001 art

UVM is no longer an option


# 1.23 22-Jun-2001 lebel

use strlcpy vs strncpy+a[len-1]='\0'


# 1.22 04-May-2001 ericj

handle kvm_nlist() failing, from pr#1798.
Patch similar to the one submitted by <peterw@documenta.com.au>


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.21 22-Feb-2000 deraadt

_total is no longer a symbol in the kernel


# 1.20 26-Oct-1999 art

Fix printing of interrupts with UVM.


# 1.19 26-Oct-1999 art

support UVM. (much code from NetBSD)


Revision tags: OPENBSD_2_6_BASE
# 1.18 16-Jun-1999 espie

Fixed i386 -> __i386__


Revision tags: OPENBSD_2_5_BASE
# 1.17 19-Dec-1998 deraadt

move Act Free field over one


Revision tags: OPENBSD_2_4_BASE
# 1.16 13-Jul-1998 millert

ftpd: sleep for an indeterminate amount for non-existant logins
to simulate a crypt, like login does.
Use SEEK_* not L_* and kill some 0L's used in lseek while we're there.


# 1.15 12-Jun-1998 marc

fix vm load display


Revision tags: OPENBSD_2_3_BASE
# 1.14 19-Dec-1997 deraadt

comment this strncpy is safe


# 1.13 19-Dec-1997 deraadt

proactive buffer blocks


# 1.12 19-Dec-1997 deraadt

bye bye sprintf


# 1.11 24-Nov-1997 kstailey

Deal with the fact that PUTRATE() is a macro that contains braces by
surrounding it with braces after an ``if ()''.


# 1.10 22-Nov-1997 mickey

remove unused kernel vars


# 1.9 22-Nov-1997 kstailey

back out 1.8, will fix in another way.


# 1.8 22-Nov-1997 kstailey

Make vmstat mode display actually fit in 80x24.
Exploits fact that swap display is always blank.


Revision tags: OPENBSD_2_2_BASE
# 1.7 29-Jul-1997 flipk

delete accidental #if 0


# 1.6 29-Jul-1997 flipk

1) display full time string in 'vmstat' display so you can tell
the difference between an inactive display and a hung machine.
2) Update the man page for 'vmstat' to reflect reality (and actually
explain all those vm abbreviations).

netbsd PR bin/2756 (Jonathan Stone <jonathan@DSG.Stanford.EDU>


Revision tags: OPENBSD_2_1_BASE
# 1.5 20-Dec-1996 downsj

support four letter device names


Revision tags: OPENBSD_2_0_BASE
# 1.4 26-Jun-1996 deraadt

rcsid


# 1.3 25-Jun-1996 tholo

Show interrupt counts on i386.


# 1.2 22-May-1996 deraadt

libutil


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.87 26-Sep-2018 cheloha

KERN_CPTIME2: set ENODEV if the CPU is offline.

This lets userspace distinguish between idle CPUs and those that are
not schedulable because hw.smt=0.

A subsequent commit probably needs to add documentation for this
to sysctl.2 (and perhaps elsewhere) after the dust settles.

Also included here are changes to systat(1) and top(1) that account
for the ENODEV case and adjust behavior accordingly:

- systat(1)'s cpu view prints placeholder marks ('-') instead of
percentages for each state if the given CPU is offline.

- systat(1)'s vmstat view checks for offline CPUs when computing the
machine state total and excludes them, so the CPU usage graph
only represents the states for online CPUs.

- top(1) does not draw CPU rows for offline CPUs when the view is
redrawn. If CPUs "go offline", percentages for each state are
replaced by placeholder marks ('-'); the view will need to be
redrawn to remove these rows. If CPUs "go online" the view will
need to be redrawn to show these new CPUs. In "combined CPU" mode,
the count and the state totals only represent online CPUs.

Ports using KERN_CPTIME2 will need to be updated. The changes
described above to make systat(1) and top(1) aware of the ENODEV
case *and* gracefully handle a changing HW_NCPUONLINE while the
application is running are not necessarily appropriate for each
and every port.

The changes described above are so extensive in part to demonstrate
one way a program *might* be made robust to changing CPU availability.
In particular, changing hw.smt after boot is an extremely rare event,
and this needs to be weighed when updating ports.

The logic needed to account for the KERN_CPTIME2 ENODEV case is
very roughly:

if (sysctl(...) == -1) {
if (errno != ENODEV) {
/* Actual error occurred. */
} else {
/* CPU is offline. */
}
} else {
/* CPU is online and CPU states were set by sysctl(2). */
}

Prompted by deraadt@. Basic idea for ENODEV from kettenis@. Discussed at
length with kettenis@. Additional testing by tb@.

No complaints from hackers@ after a week.

ok kettenis@, "I think you should commit [now]" deraadt@


# 1.86 22-Jun-2018 krw

Constrain IPKTS/OPKTS from floating down beyond the rest of the
displayed lines. Makes vmstat view in tall windows easier to read.

ok sthen@


# 1.85 19-May-2018 bluhm

Do not ignore nice time in systat(1). The sum would not be 100%,
a busy machine would look idle. As %Nic does not fit in the columns,
add it to %Usr. Introduce @ for spinning time to keep the characters
people are used to. Put %Spn between %Int and %Sys like in top.
OK visa@ mpi@


# 1.84 14-May-2018 mpi

Stopping counting and reporting CPU time spent spinning on a lock as
system time.

Introduce a new CP_SPIN "scheduler state" and modify userland tools
to display the % of timer a CPU spents spinning.

Based on a diff from jmatthew@, ok pirofti@, bluhm@, visa@, deraadt@


# 1.83 03-May-2018 otto

test for failing allocation using the standard idiom; prompted by Nan Xiao
ok tb@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.82 18-Dec-2016 krw

Remove statements that have no effect from X(), Y() and Z() #define's.
Leftovers from the re-engining of systat eight years ago. Makes gcc
quieter.

ok otto@ deraadt@


# 1.81 24-Aug-2016 guenther

Convert quad_t to int64_t and %q to %ll
Convert bzero() to memset() and bcopy() to memcpy()

ok natano@ millert@


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.80 20-Aug-2015 deraadt

Do not cast result of malloc/calloc/realloc* if stdlib.h is in scope
ok krw millert


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.79 16-Jan-2015 deraadt

first batch of programs adapting to the namespace cleanup
(pfvar.h nameser.h proc.h ucred.h)
ok guenther millert, and some review from doug as well.


# 1.78 23-Nov-2014 guenther

<sys/buf.h> isn't actually needed here

ok tedu@


# 1.77 15-Sep-2014 miod

Remove non-standard <sys/dkstat.h> header. It has not contained anything
related to disk stastics for almost 17 years, and the remaining
userland-visible defines duplicate those found in <sys/sched.h>.

Move the remaining _KERNEL defines to <sys/tty.h> where they belong, and
update all users to cope with this.

ok kettenis@


Revision tags: OPENBSD_5_6_BASE
# 1.76 08-Apr-2014 mpi

Use VM_UVMEXP instead of VM_METER for memory usages and directly
include <sys/vmmeter.h> where it is needed instead of relying on
it being included by <uvm/uvm_extern.h>.

miod@ likes it, ok guenther@


Revision tags: OPENBSD_5_5_BASE
# 1.75 31-Oct-2013 deraadt

sometimes we find .h we no longer need


Revision tags: OPENBSD_5_4_BASE
# 1.74 14-May-2013 miod

Don't display swapin/swapout uvmexp fields


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.73 19-Nov-2010 mikeb

Make KERN_CPTIME return an avarage number of ticks across all CPUs
tedu agreed with an idea, tested by Luis Useche and me; ok deraadt


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE
# 1.72 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


# 1.71 14-Aug-2009 deraadt

tie IPKTS/OPKTS to bottom corner for smaller screens


# 1.70 13-Aug-2009 deraadt

there are louder and louder moans about the inability to see packet
rates at the same time as interrupt counts, so sneak them into the
bottom corner of the vmstat screen
ok dlg


Revision tags: OPENBSD_4_6_BASE
# 1.69 03-May-2009 drahn

Hinge at the natural rollover point 9999x instead of 1024x when switching to
the next unit K->M->G. ok deraadt@


# 1.68 30-Mar-2009 deraadt

allow the disk transfer speed numbers to show useable numbers when disks
get really fast; ok canacar


Revision tags: OPENBSD_4_5_BASE
# 1.67 07-Dec-2008 canacar

Warning cleanup including unused variables and shadowed names


# 1.66 01-Nov-2008 canacar

Improve reporting of cache misses in the vmstat view. Previously
the misses field may report negative values. The hit/miss numbers
does not exactly reflect the statistics collected by the kernel
but this is close enough.

Report & patch from Bjorn Anderss, input from beck@ and thib@


Revision tags: OPENBSD_4_4_BASE
# 1.65 13-Jun-2008 deraadt

compile on older gcc; no decl after code


# 1.64 12-Jun-2008 canacar

New display engine for systat, based on pftop. Adds new views for pf
(status, state, rule, queue). While all displays work, some keyboard
comands are not implemented yet. Other features include better handling
of display resize and scrolling for long views. Committing now to fix
the remaining issues in the tree.
Testing and comments by otto@ and harding@, ok deraadt@


Revision tags: OPENBSD_4_3_BASE
# 1.63 01-Sep-2007 deraadt

malloc(n * m) -> calloc(n, m); from zinovik


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.62 25-Feb-2007 deraadt

use the 1 line load line from 'systat vm' on all the other displays, giving
them more room. much cleaner, and it is less code too; ok deanna


# 1.61 13-Nov-2006 otto

fix macro abuse leading to stray numbers in the vm display.
ok a whole lot of devs@


Revision tags: OPENBSD_4_0_BASE
# 1.60 14-Apr-2006 dlg

remove comments that says we dont count intr time and remove some code that
fudges the output to stay clean when intr time wasnt shown. not needed
since we show it now.


# 1.59 14-Apr-2006 dlg

show cpu time spent in interrupts. ive been wanting this for years.

tweaks by deraadt@ ok by many


# 1.58 31-Mar-2006 deraadt

spacing


# 1.57 31-Mar-2006 deraadt

fairly simple cleanup, lots of testing done


# 1.56 28-Mar-2006 mickey

give more space to the memory columns in vm page; deraadt@ ok


Revision tags: OPENBSD_3_9_BASE
# 1.55 28-Sep-2005 pedro

- when we run out of static kernel map entries, grab a fresh page using
the uvm_km_page allocator and use it instead of calling panic()
- add a counter to uvmexp so we can keep track of how many map entries
we have in use

idea from tedu@, long ago, okay deraadt@


Revision tags: OPENBSD_3_8_BASE
# 1.54 04-Apr-2005 deraadt

nlist.h not needed


Revision tags: OPENBSD_3_7_BASE
# 1.53 23-Sep-2004 deraadt

adapt to KERN_INTRCNT_CNT returning a quad, from danh (imported now to
avoid tree breakage)


Revision tags: OPENBSD_3_6_BASE
# 1.52 09-Jul-2004 deraadt

remove post-mortem stuff (sysctl only here)


# 1.51 28-Jun-2004 aaron

Remove special #if defined(__i386__) code from systat and vmstat. We now use
sysctl to fetch interrupt counters on all architectures. Also add new '-z'
flag to vmstat which means show all devices, even those that have not yet
generated an interrupt. deraadt@ tholo@ drahn@ millert@ ok


# 1.50 11-Jun-2004 deraadt

divide etime by ncpu


# 1.49 11-Jun-2004 deraadt

oops


# 1.48 11-Jun-2004 deraadt

on i386 machines, attempt to peek inside apic_intrhand[] as well, so that
MP machines get interrupt counters. will be replaced by a MI subsystem
one day. most code from drahn, few final bugs fixed by me


# 1.47 22-May-2004 henning

with modern disks data transfers rates above 10000 kByte/s are seen
regularily, make the disk columns a little wider so it doesn't run into
the neighboring column, theo ok


# 1.46 23-Apr-2004 tedu

don't print stats until they're stable, prevents seeing weird stuff in
disk columns. tested by jolan@. from pedro martelletto


Revision tags: OPENBSD_3_5_BASE
# 1.45 15-Feb-2004 tedu

'split' command for iostat mode
from Pedro Martelletto <pbastos@rdc.puc-rio.br>


# 1.44 15-Feb-2004 tedu

new arg to disk_unbusy, to record separate read/write statistics.
looked at by various, testing henning@ mcbride@ dan weeks
mostly from netbsd via Pedro Martelletto <pbastos@rdc.puc-rio.br>


# 1.43 16-Oct-2003 mickey

duh


# 1.42 15-Oct-2003 mickey

also print the uvmexp.zeropages if there is space in vm screen


Revision tags: OPENBSD_3_4_BASE
# 1.41 03-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


# 1.40 14-Apr-2003 deraadt

remove old comment


# 1.39 08-Apr-2003 deraadt

string cleaning; ok tdeval


Revision tags: OPENBSD_3_3_BASE
# 1.38 28-Feb-2003 jason

intrcnt's are ints not longs (at least according to the new kern.intrcnt stuff)


# 1.37 16-Dec-2002 tdeval

Make systat(1), iostat(8) and vmstat(8) automatically update their disk
statistics when a device is added/removed. ok deraadt@


Revision tags: OPENBSD_3_2_BASE
# 1.36 19-Jun-2002 deraadt

mark which nlist[] kmem entries are not needed in the sysctl case, and which are


# 1.35 18-Jun-2002 deraadt

ANSI


# 1.34 29-Apr-2002 millert

Fix 32bit int oflow when there is > 2GB vm; peters AT telia DOT net


Revision tags: OPENBSD_3_1_BASE
# 1.33 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


# 1.32 16-Feb-2002 tdeval

Some disk names are longer than 4. Cope with that.
ok deraadt@


# 1.31 07-Dec-2001 deraadt

move back. pvalchev -- the bug was quite obscure


# 1.30 07-Dec-2001 pvalchev

back out latest changes which cause problems on alpha/sparc64 until
they are fixed


# 1.29 23-Nov-2001 deraadt

fix signal races. use sysctl() instead of kvm where possible, and then KNF
the hell out of it; checked by miod


# 1.28 19-Nov-2001 mpech

kill more registers

millert@ ok


# 1.27 18-Nov-2001 deraadt

slightly expand the Csw/Trp/Sys/Int/Sof spacing


# 1.26 06-Nov-2001 art

New vm includes.


Revision tags: OPENBSD_3_0_BASE
# 1.25 28-Aug-2001 weingart

Add information on number/percentage of namei calls missed the cache.
millert@ ok.


# 1.24 27-Jun-2001 art

UVM is no longer an option


# 1.23 22-Jun-2001 lebel

use strlcpy vs strncpy+a[len-1]='\0'


# 1.22 04-May-2001 ericj

handle kvm_nlist() failing, from pr#1798.
Patch similar to the one submitted by <peterw@documenta.com.au>


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.21 22-Feb-2000 deraadt

_total is no longer a symbol in the kernel


# 1.20 26-Oct-1999 art

Fix printing of interrupts with UVM.


# 1.19 26-Oct-1999 art

support UVM. (much code from NetBSD)


Revision tags: OPENBSD_2_6_BASE
# 1.18 16-Jun-1999 espie

Fixed i386 -> __i386__


Revision tags: OPENBSD_2_5_BASE
# 1.17 19-Dec-1998 deraadt

move Act Free field over one


Revision tags: OPENBSD_2_4_BASE
# 1.16 13-Jul-1998 millert

ftpd: sleep for an indeterminate amount for non-existant logins
to simulate a crypt, like login does.
Use SEEK_* not L_* and kill some 0L's used in lseek while we're there.


# 1.15 12-Jun-1998 marc

fix vm load display


Revision tags: OPENBSD_2_3_BASE
# 1.14 19-Dec-1997 deraadt

comment this strncpy is safe


# 1.13 19-Dec-1997 deraadt

proactive buffer blocks


# 1.12 19-Dec-1997 deraadt

bye bye sprintf


# 1.11 24-Nov-1997 kstailey

Deal with the fact that PUTRATE() is a macro that contains braces by
surrounding it with braces after an ``if ()''.


# 1.10 22-Nov-1997 mickey

remove unused kernel vars


# 1.9 22-Nov-1997 kstailey

back out 1.8, will fix in another way.


# 1.8 22-Nov-1997 kstailey

Make vmstat mode display actually fit in 80x24.
Exploits fact that swap display is always blank.


Revision tags: OPENBSD_2_2_BASE
# 1.7 29-Jul-1997 flipk

delete accidental #if 0


# 1.6 29-Jul-1997 flipk

1) display full time string in 'vmstat' display so you can tell
the difference between an inactive display and a hung machine.
2) Update the man page for 'vmstat' to reflect reality (and actually
explain all those vm abbreviations).

netbsd PR bin/2756 (Jonathan Stone <jonathan@DSG.Stanford.EDU>


Revision tags: OPENBSD_2_1_BASE
# 1.5 20-Dec-1996 downsj

support four letter device names


Revision tags: OPENBSD_2_0_BASE
# 1.4 26-Jun-1996 deraadt

rcsid


# 1.3 25-Jun-1996 tholo

Show interrupt counts on i386.


# 1.2 22-May-1996 deraadt

libutil


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.86 22-Jun-2018 krw

Constrain IPKTS/OPKTS from floating down beyond the rest of the
displayed lines. Makes vmstat view in tall windows easier to read.

ok sthen@


# 1.85 19-May-2018 bluhm

Do not ignore nice time in systat(1). The sum would not be 100%,
a busy machine would look idle. As %Nic does not fit in the columns,
add it to %Usr. Introduce @ for spinning time to keep the characters
people are used to. Put %Spn between %Int and %Sys like in top.
OK visa@ mpi@


# 1.84 14-May-2018 mpi

Stopping counting and reporting CPU time spent spinning on a lock as
system time.

Introduce a new CP_SPIN "scheduler state" and modify userland tools
to display the % of timer a CPU spents spinning.

Based on a diff from jmatthew@, ok pirofti@, bluhm@, visa@, deraadt@


# 1.83 03-May-2018 otto

test for failing allocation using the standard idiom; prompted by Nan Xiao
ok tb@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.82 18-Dec-2016 krw

Remove statements that have no effect from X(), Y() and Z() #define's.
Leftovers from the re-engining of systat eight years ago. Makes gcc
quieter.

ok otto@ deraadt@


# 1.81 24-Aug-2016 guenther

Convert quad_t to int64_t and %q to %ll
Convert bzero() to memset() and bcopy() to memcpy()

ok natano@ millert@


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.80 20-Aug-2015 deraadt

Do not cast result of malloc/calloc/realloc* if stdlib.h is in scope
ok krw millert


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.79 16-Jan-2015 deraadt

first batch of programs adapting to the namespace cleanup
(pfvar.h nameser.h proc.h ucred.h)
ok guenther millert, and some review from doug as well.


# 1.78 23-Nov-2014 guenther

<sys/buf.h> isn't actually needed here

ok tedu@


# 1.77 15-Sep-2014 miod

Remove non-standard <sys/dkstat.h> header. It has not contained anything
related to disk stastics for almost 17 years, and the remaining
userland-visible defines duplicate those found in <sys/sched.h>.

Move the remaining _KERNEL defines to <sys/tty.h> where they belong, and
update all users to cope with this.

ok kettenis@


Revision tags: OPENBSD_5_6_BASE
# 1.76 08-Apr-2014 mpi

Use VM_UVMEXP instead of VM_METER for memory usages and directly
include <sys/vmmeter.h> where it is needed instead of relying on
it being included by <uvm/uvm_extern.h>.

miod@ likes it, ok guenther@


Revision tags: OPENBSD_5_5_BASE
# 1.75 31-Oct-2013 deraadt

sometimes we find .h we no longer need


Revision tags: OPENBSD_5_4_BASE
# 1.74 14-May-2013 miod

Don't display swapin/swapout uvmexp fields


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.73 19-Nov-2010 mikeb

Make KERN_CPTIME return an avarage number of ticks across all CPUs
tedu agreed with an idea, tested by Luis Useche and me; ok deraadt


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE
# 1.72 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


# 1.71 14-Aug-2009 deraadt

tie IPKTS/OPKTS to bottom corner for smaller screens


# 1.70 13-Aug-2009 deraadt

there are louder and louder moans about the inability to see packet
rates at the same time as interrupt counts, so sneak them into the
bottom corner of the vmstat screen
ok dlg


Revision tags: OPENBSD_4_6_BASE
# 1.69 03-May-2009 drahn

Hinge at the natural rollover point 9999x instead of 1024x when switching to
the next unit K->M->G. ok deraadt@


# 1.68 30-Mar-2009 deraadt

allow the disk transfer speed numbers to show useable numbers when disks
get really fast; ok canacar


Revision tags: OPENBSD_4_5_BASE
# 1.67 07-Dec-2008 canacar

Warning cleanup including unused variables and shadowed names


# 1.66 01-Nov-2008 canacar

Improve reporting of cache misses in the vmstat view. Previously
the misses field may report negative values. The hit/miss numbers
does not exactly reflect the statistics collected by the kernel
but this is close enough.

Report & patch from Bjorn Anderss, input from beck@ and thib@


Revision tags: OPENBSD_4_4_BASE
# 1.65 13-Jun-2008 deraadt

compile on older gcc; no decl after code


# 1.64 12-Jun-2008 canacar

New display engine for systat, based on pftop. Adds new views for pf
(status, state, rule, queue). While all displays work, some keyboard
comands are not implemented yet. Other features include better handling
of display resize and scrolling for long views. Committing now to fix
the remaining issues in the tree.
Testing and comments by otto@ and harding@, ok deraadt@


Revision tags: OPENBSD_4_3_BASE
# 1.63 01-Sep-2007 deraadt

malloc(n * m) -> calloc(n, m); from zinovik


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.62 25-Feb-2007 deraadt

use the 1 line load line from 'systat vm' on all the other displays, giving
them more room. much cleaner, and it is less code too; ok deanna


# 1.61 13-Nov-2006 otto

fix macro abuse leading to stray numbers in the vm display.
ok a whole lot of devs@


Revision tags: OPENBSD_4_0_BASE
# 1.60 14-Apr-2006 dlg

remove comments that says we dont count intr time and remove some code that
fudges the output to stay clean when intr time wasnt shown. not needed
since we show it now.


# 1.59 14-Apr-2006 dlg

show cpu time spent in interrupts. ive been wanting this for years.

tweaks by deraadt@ ok by many


# 1.58 31-Mar-2006 deraadt

spacing


# 1.57 31-Mar-2006 deraadt

fairly simple cleanup, lots of testing done


# 1.56 28-Mar-2006 mickey

give more space to the memory columns in vm page; deraadt@ ok


Revision tags: OPENBSD_3_9_BASE
# 1.55 28-Sep-2005 pedro

- when we run out of static kernel map entries, grab a fresh page using
the uvm_km_page allocator and use it instead of calling panic()
- add a counter to uvmexp so we can keep track of how many map entries
we have in use

idea from tedu@, long ago, okay deraadt@


Revision tags: OPENBSD_3_8_BASE
# 1.54 04-Apr-2005 deraadt

nlist.h not needed


Revision tags: OPENBSD_3_7_BASE
# 1.53 23-Sep-2004 deraadt

adapt to KERN_INTRCNT_CNT returning a quad, from danh (imported now to
avoid tree breakage)


Revision tags: OPENBSD_3_6_BASE
# 1.52 09-Jul-2004 deraadt

remove post-mortem stuff (sysctl only here)


# 1.51 28-Jun-2004 aaron

Remove special #if defined(__i386__) code from systat and vmstat. We now use
sysctl to fetch interrupt counters on all architectures. Also add new '-z'
flag to vmstat which means show all devices, even those that have not yet
generated an interrupt. deraadt@ tholo@ drahn@ millert@ ok


# 1.50 11-Jun-2004 deraadt

divide etime by ncpu


# 1.49 11-Jun-2004 deraadt

oops


# 1.48 11-Jun-2004 deraadt

on i386 machines, attempt to peek inside apic_intrhand[] as well, so that
MP machines get interrupt counters. will be replaced by a MI subsystem
one day. most code from drahn, few final bugs fixed by me


# 1.47 22-May-2004 henning

with modern disks data transfers rates above 10000 kByte/s are seen
regularily, make the disk columns a little wider so it doesn't run into
the neighboring column, theo ok


# 1.46 23-Apr-2004 tedu

don't print stats until they're stable, prevents seeing weird stuff in
disk columns. tested by jolan@. from pedro martelletto


Revision tags: OPENBSD_3_5_BASE
# 1.45 15-Feb-2004 tedu

'split' command for iostat mode
from Pedro Martelletto <pbastos@rdc.puc-rio.br>


# 1.44 15-Feb-2004 tedu

new arg to disk_unbusy, to record separate read/write statistics.
looked at by various, testing henning@ mcbride@ dan weeks
mostly from netbsd via Pedro Martelletto <pbastos@rdc.puc-rio.br>


# 1.43 16-Oct-2003 mickey

duh


# 1.42 15-Oct-2003 mickey

also print the uvmexp.zeropages if there is space in vm screen


Revision tags: OPENBSD_3_4_BASE
# 1.41 03-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


# 1.40 14-Apr-2003 deraadt

remove old comment


# 1.39 08-Apr-2003 deraadt

string cleaning; ok tdeval


Revision tags: OPENBSD_3_3_BASE
# 1.38 28-Feb-2003 jason

intrcnt's are ints not longs (at least according to the new kern.intrcnt stuff)


# 1.37 16-Dec-2002 tdeval

Make systat(1), iostat(8) and vmstat(8) automatically update their disk
statistics when a device is added/removed. ok deraadt@


Revision tags: OPENBSD_3_2_BASE
# 1.36 19-Jun-2002 deraadt

mark which nlist[] kmem entries are not needed in the sysctl case, and which are


# 1.35 18-Jun-2002 deraadt

ANSI


# 1.34 29-Apr-2002 millert

Fix 32bit int oflow when there is > 2GB vm; peters AT telia DOT net


Revision tags: OPENBSD_3_1_BASE
# 1.33 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


# 1.32 16-Feb-2002 tdeval

Some disk names are longer than 4. Cope with that.
ok deraadt@


# 1.31 07-Dec-2001 deraadt

move back. pvalchev -- the bug was quite obscure


# 1.30 07-Dec-2001 pvalchev

back out latest changes which cause problems on alpha/sparc64 until
they are fixed


# 1.29 23-Nov-2001 deraadt

fix signal races. use sysctl() instead of kvm where possible, and then KNF
the hell out of it; checked by miod


# 1.28 19-Nov-2001 mpech

kill more registers

millert@ ok


# 1.27 18-Nov-2001 deraadt

slightly expand the Csw/Trp/Sys/Int/Sof spacing


# 1.26 06-Nov-2001 art

New vm includes.


Revision tags: OPENBSD_3_0_BASE
# 1.25 28-Aug-2001 weingart

Add information on number/percentage of namei calls missed the cache.
millert@ ok.


# 1.24 27-Jun-2001 art

UVM is no longer an option


# 1.23 22-Jun-2001 lebel

use strlcpy vs strncpy+a[len-1]='\0'


# 1.22 04-May-2001 ericj

handle kvm_nlist() failing, from pr#1798.
Patch similar to the one submitted by <peterw@documenta.com.au>


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.21 22-Feb-2000 deraadt

_total is no longer a symbol in the kernel


# 1.20 26-Oct-1999 art

Fix printing of interrupts with UVM.


# 1.19 26-Oct-1999 art

support UVM. (much code from NetBSD)


Revision tags: OPENBSD_2_6_BASE
# 1.18 16-Jun-1999 espie

Fixed i386 -> __i386__


Revision tags: OPENBSD_2_5_BASE
# 1.17 19-Dec-1998 deraadt

move Act Free field over one


Revision tags: OPENBSD_2_4_BASE
# 1.16 13-Jul-1998 millert

ftpd: sleep for an indeterminate amount for non-existant logins
to simulate a crypt, like login does.
Use SEEK_* not L_* and kill some 0L's used in lseek while we're there.


# 1.15 12-Jun-1998 marc

fix vm load display


Revision tags: OPENBSD_2_3_BASE
# 1.14 19-Dec-1997 deraadt

comment this strncpy is safe


# 1.13 19-Dec-1997 deraadt

proactive buffer blocks


# 1.12 19-Dec-1997 deraadt

bye bye sprintf


# 1.11 24-Nov-1997 kstailey

Deal with the fact that PUTRATE() is a macro that contains braces by
surrounding it with braces after an ``if ()''.


# 1.10 22-Nov-1997 mickey

remove unused kernel vars


# 1.9 22-Nov-1997 kstailey

back out 1.8, will fix in another way.


# 1.8 22-Nov-1997 kstailey

Make vmstat mode display actually fit in 80x24.
Exploits fact that swap display is always blank.


Revision tags: OPENBSD_2_2_BASE
# 1.7 29-Jul-1997 flipk

delete accidental #if 0


# 1.6 29-Jul-1997 flipk

1) display full time string in 'vmstat' display so you can tell
the difference between an inactive display and a hung machine.
2) Update the man page for 'vmstat' to reflect reality (and actually
explain all those vm abbreviations).

netbsd PR bin/2756 (Jonathan Stone <jonathan@DSG.Stanford.EDU>


Revision tags: OPENBSD_2_1_BASE
# 1.5 20-Dec-1996 downsj

support four letter device names


Revision tags: OPENBSD_2_0_BASE
# 1.4 26-Jun-1996 deraadt

rcsid


# 1.3 25-Jun-1996 tholo

Show interrupt counts on i386.


# 1.2 22-May-1996 deraadt

libutil


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.83 03-May-2018 otto

test for failing allocation using the standard idiom; prompted by Nan Xiao
ok tb@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.82 18-Dec-2016 krw

Remove statements that have no effect from X(), Y() and Z() #define's.
Leftovers from the re-engining of systat eight years ago. Makes gcc
quieter.

ok otto@ deraadt@


# 1.81 24-Aug-2016 guenther

Convert quad_t to int64_t and %q to %ll
Convert bzero() to memset() and bcopy() to memcpy()

ok natano@ millert@


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.80 20-Aug-2015 deraadt

Do not cast result of malloc/calloc/realloc* if stdlib.h is in scope
ok krw millert


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.79 16-Jan-2015 deraadt

first batch of programs adapting to the namespace cleanup
(pfvar.h nameser.h proc.h ucred.h)
ok guenther millert, and some review from doug as well.


# 1.78 23-Nov-2014 guenther

<sys/buf.h> isn't actually needed here

ok tedu@


# 1.77 15-Sep-2014 miod

Remove non-standard <sys/dkstat.h> header. It has not contained anything
related to disk stastics for almost 17 years, and the remaining
userland-visible defines duplicate those found in <sys/sched.h>.

Move the remaining _KERNEL defines to <sys/tty.h> where they belong, and
update all users to cope with this.

ok kettenis@


Revision tags: OPENBSD_5_6_BASE
# 1.76 08-Apr-2014 mpi

Use VM_UVMEXP instead of VM_METER for memory usages and directly
include <sys/vmmeter.h> where it is needed instead of relying on
it being included by <uvm/uvm_extern.h>.

miod@ likes it, ok guenther@


Revision tags: OPENBSD_5_5_BASE
# 1.75 31-Oct-2013 deraadt

sometimes we find .h we no longer need


Revision tags: OPENBSD_5_4_BASE
# 1.74 14-May-2013 miod

Don't display swapin/swapout uvmexp fields


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.73 19-Nov-2010 mikeb

Make KERN_CPTIME return an avarage number of ticks across all CPUs
tedu agreed with an idea, tested by Luis Useche and me; ok deraadt


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE
# 1.72 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


# 1.71 14-Aug-2009 deraadt

tie IPKTS/OPKTS to bottom corner for smaller screens


# 1.70 13-Aug-2009 deraadt

there are louder and louder moans about the inability to see packet
rates at the same time as interrupt counts, so sneak them into the
bottom corner of the vmstat screen
ok dlg


Revision tags: OPENBSD_4_6_BASE
# 1.69 03-May-2009 drahn

Hinge at the natural rollover point 9999x instead of 1024x when switching to
the next unit K->M->G. ok deraadt@


# 1.68 30-Mar-2009 deraadt

allow the disk transfer speed numbers to show useable numbers when disks
get really fast; ok canacar


Revision tags: OPENBSD_4_5_BASE
# 1.67 07-Dec-2008 canacar

Warning cleanup including unused variables and shadowed names


# 1.66 01-Nov-2008 canacar

Improve reporting of cache misses in the vmstat view. Previously
the misses field may report negative values. The hit/miss numbers
does not exactly reflect the statistics collected by the kernel
but this is close enough.

Report & patch from Bjorn Anderss, input from beck@ and thib@


Revision tags: OPENBSD_4_4_BASE
# 1.65 13-Jun-2008 deraadt

compile on older gcc; no decl after code


# 1.64 12-Jun-2008 canacar

New display engine for systat, based on pftop. Adds new views for pf
(status, state, rule, queue). While all displays work, some keyboard
comands are not implemented yet. Other features include better handling
of display resize and scrolling for long views. Committing now to fix
the remaining issues in the tree.
Testing and comments by otto@ and harding@, ok deraadt@


Revision tags: OPENBSD_4_3_BASE
# 1.63 01-Sep-2007 deraadt

malloc(n * m) -> calloc(n, m); from zinovik


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.62 25-Feb-2007 deraadt

use the 1 line load line from 'systat vm' on all the other displays, giving
them more room. much cleaner, and it is less code too; ok deanna


# 1.61 13-Nov-2006 otto

fix macro abuse leading to stray numbers in the vm display.
ok a whole lot of devs@


Revision tags: OPENBSD_4_0_BASE
# 1.60 14-Apr-2006 dlg

remove comments that says we dont count intr time and remove some code that
fudges the output to stay clean when intr time wasnt shown. not needed
since we show it now.


# 1.59 14-Apr-2006 dlg

show cpu time spent in interrupts. ive been wanting this for years.

tweaks by deraadt@ ok by many


# 1.58 31-Mar-2006 deraadt

spacing


# 1.57 31-Mar-2006 deraadt

fairly simple cleanup, lots of testing done


# 1.56 28-Mar-2006 mickey

give more space to the memory columns in vm page; deraadt@ ok


Revision tags: OPENBSD_3_9_BASE
# 1.55 28-Sep-2005 pedro

- when we run out of static kernel map entries, grab a fresh page using
the uvm_km_page allocator and use it instead of calling panic()
- add a counter to uvmexp so we can keep track of how many map entries
we have in use

idea from tedu@, long ago, okay deraadt@


Revision tags: OPENBSD_3_8_BASE
# 1.54 04-Apr-2005 deraadt

nlist.h not needed


Revision tags: OPENBSD_3_7_BASE
# 1.53 23-Sep-2004 deraadt

adapt to KERN_INTRCNT_CNT returning a quad, from danh (imported now to
avoid tree breakage)


Revision tags: OPENBSD_3_6_BASE
# 1.52 09-Jul-2004 deraadt

remove post-mortem stuff (sysctl only here)


# 1.51 28-Jun-2004 aaron

Remove special #if defined(__i386__) code from systat and vmstat. We now use
sysctl to fetch interrupt counters on all architectures. Also add new '-z'
flag to vmstat which means show all devices, even those that have not yet
generated an interrupt. deraadt@ tholo@ drahn@ millert@ ok


# 1.50 11-Jun-2004 deraadt

divide etime by ncpu


# 1.49 11-Jun-2004 deraadt

oops


# 1.48 11-Jun-2004 deraadt

on i386 machines, attempt to peek inside apic_intrhand[] as well, so that
MP machines get interrupt counters. will be replaced by a MI subsystem
one day. most code from drahn, few final bugs fixed by me


# 1.47 22-May-2004 henning

with modern disks data transfers rates above 10000 kByte/s are seen
regularily, make the disk columns a little wider so it doesn't run into
the neighboring column, theo ok


# 1.46 23-Apr-2004 tedu

don't print stats until they're stable, prevents seeing weird stuff in
disk columns. tested by jolan@. from pedro martelletto


Revision tags: OPENBSD_3_5_BASE
# 1.45 15-Feb-2004 tedu

'split' command for iostat mode
from Pedro Martelletto <pbastos@rdc.puc-rio.br>


# 1.44 15-Feb-2004 tedu

new arg to disk_unbusy, to record separate read/write statistics.
looked at by various, testing henning@ mcbride@ dan weeks
mostly from netbsd via Pedro Martelletto <pbastos@rdc.puc-rio.br>


# 1.43 16-Oct-2003 mickey

duh


# 1.42 15-Oct-2003 mickey

also print the uvmexp.zeropages if there is space in vm screen


Revision tags: OPENBSD_3_4_BASE
# 1.41 03-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


# 1.40 14-Apr-2003 deraadt

remove old comment


# 1.39 08-Apr-2003 deraadt

string cleaning; ok tdeval


Revision tags: OPENBSD_3_3_BASE
# 1.38 28-Feb-2003 jason

intrcnt's are ints not longs (at least according to the new kern.intrcnt stuff)


# 1.37 16-Dec-2002 tdeval

Make systat(1), iostat(8) and vmstat(8) automatically update their disk
statistics when a device is added/removed. ok deraadt@


Revision tags: OPENBSD_3_2_BASE
# 1.36 19-Jun-2002 deraadt

mark which nlist[] kmem entries are not needed in the sysctl case, and which are


# 1.35 18-Jun-2002 deraadt

ANSI


# 1.34 29-Apr-2002 millert

Fix 32bit int oflow when there is > 2GB vm; peters AT telia DOT net


Revision tags: OPENBSD_3_1_BASE
# 1.33 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


# 1.32 16-Feb-2002 tdeval

Some disk names are longer than 4. Cope with that.
ok deraadt@


# 1.31 07-Dec-2001 deraadt

move back. pvalchev -- the bug was quite obscure


# 1.30 07-Dec-2001 pvalchev

back out latest changes which cause problems on alpha/sparc64 until
they are fixed


# 1.29 23-Nov-2001 deraadt

fix signal races. use sysctl() instead of kvm where possible, and then KNF
the hell out of it; checked by miod


# 1.28 19-Nov-2001 mpech

kill more registers

millert@ ok


# 1.27 18-Nov-2001 deraadt

slightly expand the Csw/Trp/Sys/Int/Sof spacing


# 1.26 06-Nov-2001 art

New vm includes.


Revision tags: OPENBSD_3_0_BASE
# 1.25 28-Aug-2001 weingart

Add information on number/percentage of namei calls missed the cache.
millert@ ok.


# 1.24 27-Jun-2001 art

UVM is no longer an option


# 1.23 22-Jun-2001 lebel

use strlcpy vs strncpy+a[len-1]='\0'


# 1.22 04-May-2001 ericj

handle kvm_nlist() failing, from pr#1798.
Patch similar to the one submitted by <peterw@documenta.com.au>


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.21 22-Feb-2000 deraadt

_total is no longer a symbol in the kernel


# 1.20 26-Oct-1999 art

Fix printing of interrupts with UVM.


# 1.19 26-Oct-1999 art

support UVM. (much code from NetBSD)


Revision tags: OPENBSD_2_6_BASE
# 1.18 16-Jun-1999 espie

Fixed i386 -> __i386__


Revision tags: OPENBSD_2_5_BASE
# 1.17 19-Dec-1998 deraadt

move Act Free field over one


Revision tags: OPENBSD_2_4_BASE
# 1.16 13-Jul-1998 millert

ftpd: sleep for an indeterminate amount for non-existant logins
to simulate a crypt, like login does.
Use SEEK_* not L_* and kill some 0L's used in lseek while we're there.


# 1.15 12-Jun-1998 marc

fix vm load display


Revision tags: OPENBSD_2_3_BASE
# 1.14 19-Dec-1997 deraadt

comment this strncpy is safe


# 1.13 19-Dec-1997 deraadt

proactive buffer blocks


# 1.12 19-Dec-1997 deraadt

bye bye sprintf


# 1.11 24-Nov-1997 kstailey

Deal with the fact that PUTRATE() is a macro that contains braces by
surrounding it with braces after an ``if ()''.


# 1.10 22-Nov-1997 mickey

remove unused kernel vars


# 1.9 22-Nov-1997 kstailey

back out 1.8, will fix in another way.


# 1.8 22-Nov-1997 kstailey

Make vmstat mode display actually fit in 80x24.
Exploits fact that swap display is always blank.


Revision tags: OPENBSD_2_2_BASE
# 1.7 29-Jul-1997 flipk

delete accidental #if 0


# 1.6 29-Jul-1997 flipk

1) display full time string in 'vmstat' display so you can tell
the difference between an inactive display and a hung machine.
2) Update the man page for 'vmstat' to reflect reality (and actually
explain all those vm abbreviations).

netbsd PR bin/2756 (Jonathan Stone <jonathan@DSG.Stanford.EDU>


Revision tags: OPENBSD_2_1_BASE
# 1.5 20-Dec-1996 downsj

support four letter device names


Revision tags: OPENBSD_2_0_BASE
# 1.4 26-Jun-1996 deraadt

rcsid


# 1.3 25-Jun-1996 tholo

Show interrupt counts on i386.


# 1.2 22-May-1996 deraadt

libutil


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.82 18-Dec-2016 krw

Remove statements that have no effect from X(), Y() and Z() #define's.
Leftovers from the re-engining of systat eight years ago. Makes gcc
quieter.

ok otto@ deraadt@


# 1.81 24-Aug-2016 guenther

Convert quad_t to int64_t and %q to %ll
Convert bzero() to memset() and bcopy() to memcpy()

ok natano@ millert@


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.80 20-Aug-2015 deraadt

Do not cast result of malloc/calloc/realloc* if stdlib.h is in scope
ok krw millert


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.79 16-Jan-2015 deraadt

first batch of programs adapting to the namespace cleanup
(pfvar.h nameser.h proc.h ucred.h)
ok guenther millert, and some review from doug as well.


# 1.78 23-Nov-2014 guenther

<sys/buf.h> isn't actually needed here

ok tedu@


# 1.77 15-Sep-2014 miod

Remove non-standard <sys/dkstat.h> header. It has not contained anything
related to disk stastics for almost 17 years, and the remaining
userland-visible defines duplicate those found in <sys/sched.h>.

Move the remaining _KERNEL defines to <sys/tty.h> where they belong, and
update all users to cope with this.

ok kettenis@


Revision tags: OPENBSD_5_6_BASE
# 1.76 08-Apr-2014 mpi

Use VM_UVMEXP instead of VM_METER for memory usages and directly
include <sys/vmmeter.h> where it is needed instead of relying on
it being included by <uvm/uvm_extern.h>.

miod@ likes it, ok guenther@


Revision tags: OPENBSD_5_5_BASE
# 1.75 31-Oct-2013 deraadt

sometimes we find .h we no longer need


Revision tags: OPENBSD_5_4_BASE
# 1.74 14-May-2013 miod

Don't display swapin/swapout uvmexp fields


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.73 19-Nov-2010 mikeb

Make KERN_CPTIME return an avarage number of ticks across all CPUs
tedu agreed with an idea, tested by Luis Useche and me; ok deraadt


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE
# 1.72 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


# 1.71 14-Aug-2009 deraadt

tie IPKTS/OPKTS to bottom corner for smaller screens


# 1.70 13-Aug-2009 deraadt

there are louder and louder moans about the inability to see packet
rates at the same time as interrupt counts, so sneak them into the
bottom corner of the vmstat screen
ok dlg


Revision tags: OPENBSD_4_6_BASE
# 1.69 03-May-2009 drahn

Hinge at the natural rollover point 9999x instead of 1024x when switching to
the next unit K->M->G. ok deraadt@


# 1.68 30-Mar-2009 deraadt

allow the disk transfer speed numbers to show useable numbers when disks
get really fast; ok canacar


Revision tags: OPENBSD_4_5_BASE
# 1.67 07-Dec-2008 canacar

Warning cleanup including unused variables and shadowed names


# 1.66 01-Nov-2008 canacar

Improve reporting of cache misses in the vmstat view. Previously
the misses field may report negative values. The hit/miss numbers
does not exactly reflect the statistics collected by the kernel
but this is close enough.

Report & patch from Bjorn Anderss, input from beck@ and thib@


Revision tags: OPENBSD_4_4_BASE
# 1.65 13-Jun-2008 deraadt

compile on older gcc; no decl after code


# 1.64 12-Jun-2008 canacar

New display engine for systat, based on pftop. Adds new views for pf
(status, state, rule, queue). While all displays work, some keyboard
comands are not implemented yet. Other features include better handling
of display resize and scrolling for long views. Committing now to fix
the remaining issues in the tree.
Testing and comments by otto@ and harding@, ok deraadt@


Revision tags: OPENBSD_4_3_BASE
# 1.63 01-Sep-2007 deraadt

malloc(n * m) -> calloc(n, m); from zinovik


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.62 25-Feb-2007 deraadt

use the 1 line load line from 'systat vm' on all the other displays, giving
them more room. much cleaner, and it is less code too; ok deanna


# 1.61 13-Nov-2006 otto

fix macro abuse leading to stray numbers in the vm display.
ok a whole lot of devs@


Revision tags: OPENBSD_4_0_BASE
# 1.60 14-Apr-2006 dlg

remove comments that says we dont count intr time and remove some code that
fudges the output to stay clean when intr time wasnt shown. not needed
since we show it now.


# 1.59 14-Apr-2006 dlg

show cpu time spent in interrupts. ive been wanting this for years.

tweaks by deraadt@ ok by many


# 1.58 31-Mar-2006 deraadt

spacing


# 1.57 31-Mar-2006 deraadt

fairly simple cleanup, lots of testing done


# 1.56 28-Mar-2006 mickey

give more space to the memory columns in vm page; deraadt@ ok


Revision tags: OPENBSD_3_9_BASE
# 1.55 28-Sep-2005 pedro

- when we run out of static kernel map entries, grab a fresh page using
the uvm_km_page allocator and use it instead of calling panic()
- add a counter to uvmexp so we can keep track of how many map entries
we have in use

idea from tedu@, long ago, okay deraadt@


Revision tags: OPENBSD_3_8_BASE
# 1.54 04-Apr-2005 deraadt

nlist.h not needed


Revision tags: OPENBSD_3_7_BASE
# 1.53 23-Sep-2004 deraadt

adapt to KERN_INTRCNT_CNT returning a quad, from danh (imported now to
avoid tree breakage)


Revision tags: OPENBSD_3_6_BASE
# 1.52 09-Jul-2004 deraadt

remove post-mortem stuff (sysctl only here)


# 1.51 28-Jun-2004 aaron

Remove special #if defined(__i386__) code from systat and vmstat. We now use
sysctl to fetch interrupt counters on all architectures. Also add new '-z'
flag to vmstat which means show all devices, even those that have not yet
generated an interrupt. deraadt@ tholo@ drahn@ millert@ ok


# 1.50 11-Jun-2004 deraadt

divide etime by ncpu


# 1.49 11-Jun-2004 deraadt

oops


# 1.48 11-Jun-2004 deraadt

on i386 machines, attempt to peek inside apic_intrhand[] as well, so that
MP machines get interrupt counters. will be replaced by a MI subsystem
one day. most code from drahn, few final bugs fixed by me


# 1.47 22-May-2004 henning

with modern disks data transfers rates above 10000 kByte/s are seen
regularily, make the disk columns a little wider so it doesn't run into
the neighboring column, theo ok


# 1.46 23-Apr-2004 tedu

don't print stats until they're stable, prevents seeing weird stuff in
disk columns. tested by jolan@. from pedro martelletto


Revision tags: OPENBSD_3_5_BASE
# 1.45 15-Feb-2004 tedu

'split' command for iostat mode
from Pedro Martelletto <pbastos@rdc.puc-rio.br>


# 1.44 15-Feb-2004 tedu

new arg to disk_unbusy, to record separate read/write statistics.
looked at by various, testing henning@ mcbride@ dan weeks
mostly from netbsd via Pedro Martelletto <pbastos@rdc.puc-rio.br>


# 1.43 16-Oct-2003 mickey

duh


# 1.42 15-Oct-2003 mickey

also print the uvmexp.zeropages if there is space in vm screen


Revision tags: OPENBSD_3_4_BASE
# 1.41 03-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


# 1.40 14-Apr-2003 deraadt

remove old comment


# 1.39 08-Apr-2003 deraadt

string cleaning; ok tdeval


Revision tags: OPENBSD_3_3_BASE
# 1.38 28-Feb-2003 jason

intrcnt's are ints not longs (at least according to the new kern.intrcnt stuff)


# 1.37 16-Dec-2002 tdeval

Make systat(1), iostat(8) and vmstat(8) automatically update their disk
statistics when a device is added/removed. ok deraadt@


Revision tags: OPENBSD_3_2_BASE
# 1.36 19-Jun-2002 deraadt

mark which nlist[] kmem entries are not needed in the sysctl case, and which are


# 1.35 18-Jun-2002 deraadt

ANSI


# 1.34 29-Apr-2002 millert

Fix 32bit int oflow when there is > 2GB vm; peters AT telia DOT net


Revision tags: OPENBSD_3_1_BASE
# 1.33 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


# 1.32 16-Feb-2002 tdeval

Some disk names are longer than 4. Cope with that.
ok deraadt@


# 1.31 07-Dec-2001 deraadt

move back. pvalchev -- the bug was quite obscure


# 1.30 07-Dec-2001 pvalchev

back out latest changes which cause problems on alpha/sparc64 until
they are fixed


# 1.29 23-Nov-2001 deraadt

fix signal races. use sysctl() instead of kvm where possible, and then KNF
the hell out of it; checked by miod


# 1.28 19-Nov-2001 mpech

kill more registers

millert@ ok


# 1.27 18-Nov-2001 deraadt

slightly expand the Csw/Trp/Sys/Int/Sof spacing


# 1.26 06-Nov-2001 art

New vm includes.


Revision tags: OPENBSD_3_0_BASE
# 1.25 28-Aug-2001 weingart

Add information on number/percentage of namei calls missed the cache.
millert@ ok.


# 1.24 27-Jun-2001 art

UVM is no longer an option


# 1.23 22-Jun-2001 lebel

use strlcpy vs strncpy+a[len-1]='\0'


# 1.22 04-May-2001 ericj

handle kvm_nlist() failing, from pr#1798.
Patch similar to the one submitted by <peterw@documenta.com.au>


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.21 22-Feb-2000 deraadt

_total is no longer a symbol in the kernel


# 1.20 26-Oct-1999 art

Fix printing of interrupts with UVM.


# 1.19 26-Oct-1999 art

support UVM. (much code from NetBSD)


Revision tags: OPENBSD_2_6_BASE
# 1.18 16-Jun-1999 espie

Fixed i386 -> __i386__


Revision tags: OPENBSD_2_5_BASE
# 1.17 19-Dec-1998 deraadt

move Act Free field over one


Revision tags: OPENBSD_2_4_BASE
# 1.16 13-Jul-1998 millert

ftpd: sleep for an indeterminate amount for non-existant logins
to simulate a crypt, like login does.
Use SEEK_* not L_* and kill some 0L's used in lseek while we're there.


# 1.15 12-Jun-1998 marc

fix vm load display


Revision tags: OPENBSD_2_3_BASE
# 1.14 19-Dec-1997 deraadt

comment this strncpy is safe


# 1.13 19-Dec-1997 deraadt

proactive buffer blocks


# 1.12 19-Dec-1997 deraadt

bye bye sprintf


# 1.11 24-Nov-1997 kstailey

Deal with the fact that PUTRATE() is a macro that contains braces by
surrounding it with braces after an ``if ()''.


# 1.10 22-Nov-1997 mickey

remove unused kernel vars


# 1.9 22-Nov-1997 kstailey

back out 1.8, will fix in another way.


# 1.8 22-Nov-1997 kstailey

Make vmstat mode display actually fit in 80x24.
Exploits fact that swap display is always blank.


Revision tags: OPENBSD_2_2_BASE
# 1.7 29-Jul-1997 flipk

delete accidental #if 0


# 1.6 29-Jul-1997 flipk

1) display full time string in 'vmstat' display so you can tell
the difference between an inactive display and a hung machine.
2) Update the man page for 'vmstat' to reflect reality (and actually
explain all those vm abbreviations).

netbsd PR bin/2756 (Jonathan Stone <jonathan@DSG.Stanford.EDU>


Revision tags: OPENBSD_2_1_BASE
# 1.5 20-Dec-1996 downsj

support four letter device names


Revision tags: OPENBSD_2_0_BASE
# 1.4 26-Jun-1996 deraadt

rcsid


# 1.3 25-Jun-1996 tholo

Show interrupt counts on i386.


# 1.2 22-May-1996 deraadt

libutil


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision