2017-11-20 19:49:47 +00:00
|
|
|
/*-
|
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
*
|
1994-05-27 12:33:43 +00:00
|
|
|
* Copyright (c) 1980, 1986, 1991, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2017-02-28 23:42:47 +00:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1994-05-27 12:33:43 +00:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef lint
|
1997-08-25 06:40:05 +00:00
|
|
|
static const char copyright[] =
|
1994-05-27 12:33:43 +00:00
|
|
|
"@(#) Copyright (c) 1980, 1986, 1991, 1993\n\
|
|
|
|
The Regents of the University of California. All rights reserved.\n";
|
2003-12-11 10:58:29 +00:00
|
|
|
#endif /* not lint */
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2003-12-11 10:58:29 +00:00
|
|
|
#if 0
|
1994-05-27 12:33:43 +00:00
|
|
|
#ifndef lint
|
2003-12-11 10:58:29 +00:00
|
|
|
static char sccsid[] = "@(#)vmstat.c 8.1 (Berkeley) 6/6/93";
|
|
|
|
#endif /* not lint */
|
1997-08-25 06:40:05 +00:00
|
|
|
#endif
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2003-12-11 10:58:29 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/proc.h>
|
1995-12-13 15:01:13 +00:00
|
|
|
#include <sys/uio.h>
|
1994-05-27 12:33:43 +00:00
|
|
|
#include <sys/namei.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/signal.h>
|
|
|
|
#include <sys/fcntl.h>
|
|
|
|
#include <sys/ioctl.h>
|
2003-02-16 16:01:52 +00:00
|
|
|
#include <sys/resource.h>
|
1994-05-27 12:33:43 +00:00
|
|
|
#include <sys/sysctl.h>
|
2010-05-21 17:10:52 +00:00
|
|
|
#include <sys/time.h>
|
2015-05-27 18:11:05 +00:00
|
|
|
#include <sys/user.h>
|
- Remove 'struct vmmeter' from 'struct pcpu', leaving only global vmmeter
in place. To do per-cpu stats, convert all fields that previously were
maintained in the vmmeters that sit in pcpus to counter(9).
- Since some vmmeter stats may be touched at very early stages of boot,
before we have set up UMA and we can do counter_u64_alloc(), provide an
early counter mechanism:
o Leave one spare uint64_t in struct pcpu, named pc_early_dummy_counter.
o Point counter(9) fields of vmmeter to pcpu[0].pc_early_dummy_counter,
so that at early stages of boot, before counters are allocated we already
point to a counter that can be safely written to.
o For sparc64 that required a whole dummy pcpu[MAXCPU] array.
Further related changes:
- Don't include vmmeter.h into pcpu.h.
- vm.stats.vm.v_swappgsout and vm.stats.vm.v_swappgsin changed to 64-bit,
to match kernel representation.
- struct vmmeter hidden under _KERNEL, and only vmstat(1) is an exclusion.
This is based on benno@'s 4-year old patch:
https://lists.freebsd.org/pipermail/freebsd-arch/2013-July/014471.html
Reviewed by: kib, gallatin, marius, lidl
Differential Revision: https://reviews.freebsd.org/D10156
2017-04-17 17:34:47 +00:00
|
|
|
#define _WANT_VMMETER
|
1995-12-13 11:33:34 +00:00
|
|
|
#include <sys/vmmeter.h>
|
2009-10-29 17:34:02 +00:00
|
|
|
#include <sys/pcpu.h>
|
1995-12-13 15:01:13 +00:00
|
|
|
|
|
|
|
#include <vm/vm_param.h>
|
|
|
|
|
1997-08-25 06:40:05 +00:00
|
|
|
#include <ctype.h>
|
2001-12-11 22:59:36 +00:00
|
|
|
#include <devstat.h>
|
1997-08-25 06:40:05 +00:00
|
|
|
#include <err.h>
|
1994-05-27 12:33:43 +00:00
|
|
|
#include <errno.h>
|
2011-12-17 19:22:24 +00:00
|
|
|
#include <inttypes.h>
|
1997-08-25 06:40:05 +00:00
|
|
|
#include <kvm.h>
|
|
|
|
#include <limits.h>
|
2005-07-25 22:35:10 +00:00
|
|
|
#include <memstat.h>
|
1997-08-25 06:40:05 +00:00
|
|
|
#include <nlist.h>
|
|
|
|
#include <paths.h>
|
1994-05-27 12:33:43 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
1997-10-06 18:52:16 +00:00
|
|
|
#include <sysexits.h>
|
1997-08-25 06:40:05 +00:00
|
|
|
#include <time.h>
|
|
|
|
#include <unistd.h>
|
2007-12-13 02:36:11 +00:00
|
|
|
#include <libutil.h>
|
2015-11-20 05:15:34 +00:00
|
|
|
#include <libxo/xo.h>
|
|
|
|
|
|
|
|
#define VMSTAT_XO_VERSION "1"
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2001-12-11 22:59:36 +00:00
|
|
|
static char da[] = "da";
|
|
|
|
|
2017-12-01 22:38:28 +00:00
|
|
|
enum x_stats { X_SUM, X_HZ, X_STATHZ, X_NCHSTATS, X_INTRNAMES, X_SINTRNAMES,
|
Dynamically allocate IRQ ranges on x86.
Previously, x86 used static ranges of IRQ values for different types
of I/O interrupts. Interrupt pins on I/O APICs and 8259A PICs used
IRQ values from 0 to 254. MSI interrupts used a compile-time-defined
range starting at 256, and Xen event channels used a
compile-time-defined range after MSI. Some recent systems have more
than 255 I/O APIC interrupt pins which resulted in those IRQ values
overflowing into the MSI range triggering an assertion failure.
Replace statically assigned ranges with dynamic ranges. Do a single
pass computing the sizes of the IRQ ranges (PICs, MSI, Xen) to
determine the total number of IRQs required. Allocate the interrupt
source and interrupt count arrays dynamically once this pass has
completed. To minimize runtime complexity these arrays are only sized
once during bootup. The PIC range is determined by the PICs present
in the system. The MSI and Xen ranges continue to use a fixed size,
though this does make it possible to turn the MSI range size into a
tunable in the future.
As a result, various places are updated to use dynamic limits instead
of constants. In addition, the vmstat(8) utility has been taught to
understand that some kernels may treat 'intrcnt' and 'intrnames' as
pointers rather than arrays when extracting interrupt stats from a
crashdump. This is determined by the presence (vs absence) of a
global 'nintrcnt' symbol.
This change reverts r189404 which worked around a buggy BIOS which
enumerated an I/O APIC twice (using the same memory mapped address for
both entries but using an IRQ base of 256 for one entry and a valid
IRQ base for the second entry). Making the "base" of MSI IRQ values
dynamic avoids the panic that r189404 worked around, and there may now
be valid I/O APICs with an IRQ base above 256 which this workaround
would incorrectly skip.
If in the future the issue reported in PR 130483 reoccurs, we will
have to add a pass over the I/O APIC entries in the MADT to detect
duplicates using the memory mapped address and use some strategy to
choose the "correct" one.
While here, reserve room in intrcnts for the Hyper-V counters.
PR: 229429, 130483
Reviewed by: kib, royger, cem
Tested by: royger (Xen), kib (DMAR)
Approved by: re (gjb)
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D16861
2018-08-28 21:09:19 +00:00
|
|
|
X_INTRCNT, X_SINTRCNT, X_NINTRCNT };
|
2017-12-01 22:38:28 +00:00
|
|
|
|
2001-12-11 22:59:36 +00:00
|
|
|
static struct nlist namelist[] = {
|
2017-12-01 22:38:28 +00:00
|
|
|
[X_SUM] = { .n_name = "_vm_cnt", },
|
|
|
|
[X_HZ] = { .n_name = "_hz", },
|
|
|
|
[X_STATHZ] = { .n_name = "_stathz", },
|
|
|
|
[X_NCHSTATS] = { .n_name = "_nchstats", },
|
|
|
|
[X_INTRNAMES] = { .n_name = "_intrnames", },
|
|
|
|
[X_SINTRNAMES] = { .n_name = "_sintrnames", },
|
|
|
|
[X_INTRCNT] = { .n_name = "_intrcnt", },
|
|
|
|
[X_SINTRCNT] = { .n_name = "_sintrcnt", },
|
Dynamically allocate IRQ ranges on x86.
Previously, x86 used static ranges of IRQ values for different types
of I/O interrupts. Interrupt pins on I/O APICs and 8259A PICs used
IRQ values from 0 to 254. MSI interrupts used a compile-time-defined
range starting at 256, and Xen event channels used a
compile-time-defined range after MSI. Some recent systems have more
than 255 I/O APIC interrupt pins which resulted in those IRQ values
overflowing into the MSI range triggering an assertion failure.
Replace statically assigned ranges with dynamic ranges. Do a single
pass computing the sizes of the IRQ ranges (PICs, MSI, Xen) to
determine the total number of IRQs required. Allocate the interrupt
source and interrupt count arrays dynamically once this pass has
completed. To minimize runtime complexity these arrays are only sized
once during bootup. The PIC range is determined by the PICs present
in the system. The MSI and Xen ranges continue to use a fixed size,
though this does make it possible to turn the MSI range size into a
tunable in the future.
As a result, various places are updated to use dynamic limits instead
of constants. In addition, the vmstat(8) utility has been taught to
understand that some kernels may treat 'intrcnt' and 'intrnames' as
pointers rather than arrays when extracting interrupt stats from a
crashdump. This is determined by the presence (vs absence) of a
global 'nintrcnt' symbol.
This change reverts r189404 which worked around a buggy BIOS which
enumerated an I/O APIC twice (using the same memory mapped address for
both entries but using an IRQ base of 256 for one entry and a valid
IRQ base for the second entry). Making the "base" of MSI IRQ values
dynamic avoids the panic that r189404 worked around, and there may now
be valid I/O APICs with an IRQ base above 256 which this workaround
would incorrectly skip.
If in the future the issue reported in PR 130483 reoccurs, we will
have to add a pass over the I/O APIC entries in the MADT to detect
duplicates using the memory mapped address and use some strategy to
choose the "correct" one.
While here, reserve room in intrcnts for the Hyper-V counters.
PR: 229429, 130483
Reviewed by: kib, royger, cem
Tested by: royger (Xen), kib (DMAR)
Approved by: re (gjb)
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D16861
2018-08-28 21:09:19 +00:00
|
|
|
[X_NINTRCNT] = { .n_name = "_nintrcnt", },
|
2017-12-01 22:38:28 +00:00
|
|
|
{ .n_name = NULL, },
|
1994-05-27 12:33:43 +00:00
|
|
|
};
|
|
|
|
|
2003-12-07 17:46:14 +00:00
|
|
|
static struct devstat_match *matches;
|
2017-12-01 22:38:28 +00:00
|
|
|
static struct device_selection *dev_select;
|
|
|
|
static struct statinfo cur, last;
|
2003-12-07 17:46:14 +00:00
|
|
|
static devstat_select_mode select_mode;
|
2017-12-01 22:38:28 +00:00
|
|
|
static size_t size_cp_times;
|
|
|
|
static long *cur_cp_times, *last_cp_times;
|
|
|
|
static long generation, select_generation;
|
|
|
|
static int hz, hdrcnt, maxshowdevs;
|
|
|
|
static int num_devices, num_devices_specified;
|
|
|
|
static int num_matches, num_selected, num_selections;
|
|
|
|
static char **specified_devices;
|
2003-12-07 17:46:14 +00:00
|
|
|
|
- Remove 'struct vmmeter' from 'struct pcpu', leaving only global vmmeter
in place. To do per-cpu stats, convert all fields that previously were
maintained in the vmmeters that sit in pcpus to counter(9).
- Since some vmmeter stats may be touched at very early stages of boot,
before we have set up UMA and we can do counter_u64_alloc(), provide an
early counter mechanism:
o Leave one spare uint64_t in struct pcpu, named pc_early_dummy_counter.
o Point counter(9) fields of vmmeter to pcpu[0].pc_early_dummy_counter,
so that at early stages of boot, before counters are allocated we already
point to a counter that can be safely written to.
o For sparc64 that required a whole dummy pcpu[MAXCPU] array.
Further related changes:
- Don't include vmmeter.h into pcpu.h.
- vm.stats.vm.v_swappgsout and vm.stats.vm.v_swappgsin changed to 64-bit,
to match kernel representation.
- struct vmmeter hidden under _KERNEL, and only vmstat(1) is an exclusion.
This is based on benno@'s 4-year old patch:
https://lists.freebsd.org/pipermail/freebsd-arch/2013-July/014471.html
Reviewed by: kib, gallatin, marius, lidl
Differential Revision: https://reviews.freebsd.org/D10156
2017-04-17 17:34:47 +00:00
|
|
|
static struct __vmmeter {
|
|
|
|
uint64_t v_swtch;
|
|
|
|
uint64_t v_trap;
|
|
|
|
uint64_t v_syscall;
|
|
|
|
uint64_t v_intr;
|
|
|
|
uint64_t v_soft;
|
|
|
|
uint64_t v_vm_faults;
|
|
|
|
uint64_t v_io_faults;
|
|
|
|
uint64_t v_cow_faults;
|
|
|
|
uint64_t v_cow_optim;
|
|
|
|
uint64_t v_zfod;
|
|
|
|
uint64_t v_ozfod;
|
|
|
|
uint64_t v_swapin;
|
|
|
|
uint64_t v_swapout;
|
|
|
|
uint64_t v_swappgsin;
|
|
|
|
uint64_t v_swappgsout;
|
|
|
|
uint64_t v_vnodein;
|
|
|
|
uint64_t v_vnodeout;
|
|
|
|
uint64_t v_vnodepgsin;
|
|
|
|
uint64_t v_vnodepgsout;
|
|
|
|
uint64_t v_intrans;
|
|
|
|
uint64_t v_reactivated;
|
|
|
|
uint64_t v_pdwakeups;
|
|
|
|
uint64_t v_pdpages;
|
|
|
|
uint64_t v_pdshortfalls;
|
|
|
|
uint64_t v_dfree;
|
|
|
|
uint64_t v_pfree;
|
|
|
|
uint64_t v_tfree;
|
|
|
|
uint64_t v_forks;
|
|
|
|
uint64_t v_vforks;
|
|
|
|
uint64_t v_rforks;
|
|
|
|
uint64_t v_kthreads;
|
|
|
|
uint64_t v_forkpages;
|
|
|
|
uint64_t v_vforkpages;
|
|
|
|
uint64_t v_rforkpages;
|
|
|
|
uint64_t v_kthreadpages;
|
|
|
|
u_int v_page_size;
|
|
|
|
u_int v_page_count;
|
|
|
|
u_int v_free_reserved;
|
|
|
|
u_int v_free_target;
|
|
|
|
u_int v_free_min;
|
|
|
|
u_int v_free_count;
|
|
|
|
u_int v_wire_count;
|
Provide separate accounting for user-wired pages.
Historically we have not distinguished between kernel wirings and user
wirings for accounting purposes. User wirings (via mlock(2)) were
subject to a global limit on the number of wired pages, so if large
swaths of physical memory were wired by the kernel, as happens with
the ZFS ARC among other things, the limit could be exceeded, causing
user wirings to fail.
The change adds a new counter, v_user_wire_count, which counts the
number of virtual pages wired by user processes via mlock(2) and
mlockall(2). Only user-wired pages are subject to the system-wide
limit which helps provide some safety against deadlocks. In
particular, while sources of kernel wirings typically support some
backpressure mechanism, there is no way to reclaim user-wired pages
shorting of killing the wiring process. The limit is exported as
vm.max_user_wired, renamed from vm.max_wired, and changed from u_int
to u_long.
The choice to count virtual user-wired pages rather than physical
pages was done for simplicity. There are mechanisms that can cause
user-wired mappings to be destroyed while maintaining a wiring of
the backing physical page; these make it difficult to accurately
track user wirings at the physical page layer.
The change also closes some holes which allowed user wirings to succeed
even when they would cause the system limit to be exceeded. For
instance, mmap() may now fail with ENOMEM in a process that has called
mlockall(MCL_FUTURE) if the new mapping would cause the user wiring
limit to be exceeded.
Note that bhyve -S is subject to the user wiring limit, which defaults
to 1/3 of physical RAM. Users that wish to exceed the limit must tune
vm.max_user_wired.
Reviewed by: kib, ngie (mlock() test changes)
Tested by: pho (earlier version)
MFC after: 45 days
Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D19908
2019-05-13 16:38:48 +00:00
|
|
|
u_long v_user_wire_count;
|
- Remove 'struct vmmeter' from 'struct pcpu', leaving only global vmmeter
in place. To do per-cpu stats, convert all fields that previously were
maintained in the vmmeters that sit in pcpus to counter(9).
- Since some vmmeter stats may be touched at very early stages of boot,
before we have set up UMA and we can do counter_u64_alloc(), provide an
early counter mechanism:
o Leave one spare uint64_t in struct pcpu, named pc_early_dummy_counter.
o Point counter(9) fields of vmmeter to pcpu[0].pc_early_dummy_counter,
so that at early stages of boot, before counters are allocated we already
point to a counter that can be safely written to.
o For sparc64 that required a whole dummy pcpu[MAXCPU] array.
Further related changes:
- Don't include vmmeter.h into pcpu.h.
- vm.stats.vm.v_swappgsout and vm.stats.vm.v_swappgsin changed to 64-bit,
to match kernel representation.
- struct vmmeter hidden under _KERNEL, and only vmstat(1) is an exclusion.
This is based on benno@'s 4-year old patch:
https://lists.freebsd.org/pipermail/freebsd-arch/2013-July/014471.html
Reviewed by: kib, gallatin, marius, lidl
Differential Revision: https://reviews.freebsd.org/D10156
2017-04-17 17:34:47 +00:00
|
|
|
u_int v_active_count;
|
|
|
|
u_int v_inactive_target;
|
|
|
|
u_int v_inactive_count;
|
|
|
|
u_int v_laundry_count;
|
|
|
|
u_int v_pageout_free_min;
|
|
|
|
u_int v_interrupt_free_min;
|
|
|
|
u_int v_free_severe;
|
|
|
|
} sum, osum;
|
2003-12-07 17:46:14 +00:00
|
|
|
|
2008-11-04 18:02:35 +00:00
|
|
|
#define VMSTAT_DEFAULT_LINES 20 /* Default number of `winlines'. */
|
2017-12-01 22:38:28 +00:00
|
|
|
static volatile sig_atomic_t wresized; /* Tty resized when non-zero. */
|
2008-11-04 18:02:35 +00:00
|
|
|
static int winlines = VMSTAT_DEFAULT_LINES; /* Current number of tty rows. */
|
|
|
|
|
2003-12-07 17:46:14 +00:00
|
|
|
static int aflag;
|
|
|
|
static int nflag;
|
2007-12-13 02:36:11 +00:00
|
|
|
static int Pflag;
|
|
|
|
static int hflag;
|
2003-12-07 17:46:14 +00:00
|
|
|
|
2017-12-01 22:38:28 +00:00
|
|
|
static kvm_t *kd;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
#define FORKSTAT 0x01
|
|
|
|
#define INTRSTAT 0x02
|
|
|
|
#define MEMSTAT 0x04
|
|
|
|
#define SUMSTAT 0x08
|
|
|
|
#define TIMESTAT 0x10
|
|
|
|
#define VMSTAT 0x20
|
2017-12-01 22:38:28 +00:00
|
|
|
#define ZMEMSTAT 0x40
|
2015-05-27 18:11:05 +00:00
|
|
|
#define OBJSTAT 0x80
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2002-03-22 01:42:45 +00:00
|
|
|
static void cpustats(void);
|
2017-12-01 22:38:28 +00:00
|
|
|
static void pcpustats(u_long, int);
|
2002-03-22 01:42:45 +00:00
|
|
|
static void devstats(void);
|
2003-11-08 07:24:03 +00:00
|
|
|
static void doforkst(void);
|
2015-01-23 16:15:55 +00:00
|
|
|
static void dointr(unsigned int, int);
|
2015-05-27 18:11:05 +00:00
|
|
|
static void doobjstat(void);
|
2002-03-22 01:42:45 +00:00
|
|
|
static void dosum(void);
|
2003-12-10 21:43:10 +00:00
|
|
|
static void dovmstat(unsigned int, int);
|
2005-08-06 13:56:21 +00:00
|
|
|
static void domemstat_malloc(void);
|
2005-08-01 21:33:17 +00:00
|
|
|
static void domemstat_zone(void);
|
2002-03-22 01:42:45 +00:00
|
|
|
static void kread(int, void *, size_t);
|
2004-06-30 01:34:26 +00:00
|
|
|
static void kreado(int, void *, size_t, size_t);
|
Dynamically allocate IRQ ranges on x86.
Previously, x86 used static ranges of IRQ values for different types
of I/O interrupts. Interrupt pins on I/O APICs and 8259A PICs used
IRQ values from 0 to 254. MSI interrupts used a compile-time-defined
range starting at 256, and Xen event channels used a
compile-time-defined range after MSI. Some recent systems have more
than 255 I/O APIC interrupt pins which resulted in those IRQ values
overflowing into the MSI range triggering an assertion failure.
Replace statically assigned ranges with dynamic ranges. Do a single
pass computing the sizes of the IRQ ranges (PICs, MSI, Xen) to
determine the total number of IRQs required. Allocate the interrupt
source and interrupt count arrays dynamically once this pass has
completed. To minimize runtime complexity these arrays are only sized
once during bootup. The PIC range is determined by the PICs present
in the system. The MSI and Xen ranges continue to use a fixed size,
though this does make it possible to turn the MSI range size into a
tunable in the future.
As a result, various places are updated to use dynamic limits instead
of constants. In addition, the vmstat(8) utility has been taught to
understand that some kernels may treat 'intrcnt' and 'intrnames' as
pointers rather than arrays when extracting interrupt stats from a
crashdump. This is determined by the presence (vs absence) of a
global 'nintrcnt' symbol.
This change reverts r189404 which worked around a buggy BIOS which
enumerated an I/O APIC twice (using the same memory mapped address for
both entries but using an IRQ base of 256 for one entry and a valid
IRQ base for the second entry). Making the "base" of MSI IRQ values
dynamic avoids the panic that r189404 worked around, and there may now
be valid I/O APICs with an IRQ base above 256 which this workaround
would incorrectly skip.
If in the future the issue reported in PR 130483 reoccurs, we will
have to add a pass over the I/O APIC entries in the MADT to detect
duplicates using the memory mapped address and use some strategy to
choose the "correct" one.
While here, reserve room in intrcnts for the Hyper-V counters.
PR: 229429, 130483
Reviewed by: kib, royger, cem
Tested by: royger (Xen), kib (DMAR)
Approved by: re (gjb)
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D16861
2018-08-28 21:09:19 +00:00
|
|
|
static void kreadptr(uintptr_t, void *, size_t);
|
2002-03-22 01:42:45 +00:00
|
|
|
static void needhdr(int);
|
2008-11-04 18:02:35 +00:00
|
|
|
static void needresize(int);
|
|
|
|
static void doresize(void);
|
2007-12-13 02:36:11 +00:00
|
|
|
static void printhdr(int, u_long);
|
2002-03-22 01:42:45 +00:00
|
|
|
static void usage(void);
|
|
|
|
|
|
|
|
static long pct(long, long);
|
2015-01-23 16:21:31 +00:00
|
|
|
static long long getuptime(void);
|
2002-03-22 01:42:45 +00:00
|
|
|
|
2017-12-01 22:38:28 +00:00
|
|
|
static char **getdrivedata(char **);
|
1994-05-27 12:33:43 +00:00
|
|
|
|
1997-08-25 06:40:05 +00:00
|
|
|
int
|
2003-12-07 17:46:14 +00:00
|
|
|
main(int argc, char *argv[])
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2017-12-01 22:38:28 +00:00
|
|
|
char *bp, *buf, *memf, *nlistf;
|
2010-05-21 17:10:52 +00:00
|
|
|
float f;
|
2018-06-13 08:52:04 +00:00
|
|
|
int bufsize, c, reps, todo;
|
|
|
|
size_t len;
|
2017-12-01 22:38:28 +00:00
|
|
|
unsigned int interval;
|
2001-06-19 17:59:40 +00:00
|
|
|
char errbuf[_POSIX2_LINE_MAX];
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
memf = nlistf = NULL;
|
|
|
|
interval = reps = todo = 0;
|
1999-02-10 00:46:27 +00:00
|
|
|
maxshowdevs = 2;
|
2007-12-13 02:36:11 +00:00
|
|
|
hflag = isatty(1);
|
2015-11-20 05:15:34 +00:00
|
|
|
|
|
|
|
argc = xo_parse_args(argc, argv);
|
|
|
|
if (argc < 0)
|
2017-12-01 22:38:28 +00:00
|
|
|
return (argc);
|
2015-11-20 05:15:34 +00:00
|
|
|
|
2018-08-20 09:29:21 +00:00
|
|
|
while ((c = getopt(argc, argv, "ac:fhHiM:mN:n:oPp:sw:z")) != -1) {
|
1994-05-27 12:33:43 +00:00
|
|
|
switch (c) {
|
2003-12-07 17:46:14 +00:00
|
|
|
case 'a':
|
|
|
|
aflag++;
|
|
|
|
break;
|
1994-05-27 12:33:43 +00:00
|
|
|
case 'c':
|
|
|
|
reps = atoi(optarg);
|
|
|
|
break;
|
2007-12-13 02:36:11 +00:00
|
|
|
case 'P':
|
|
|
|
Pflag++;
|
|
|
|
break;
|
1994-05-27 12:33:43 +00:00
|
|
|
case 'f':
|
2003-04-14 07:21:03 +00:00
|
|
|
todo |= FORKSTAT;
|
1997-10-06 18:52:16 +00:00
|
|
|
break;
|
2007-12-13 02:36:11 +00:00
|
|
|
case 'h':
|
|
|
|
hflag = 1;
|
|
|
|
break;
|
|
|
|
case 'H':
|
|
|
|
hflag = 0;
|
|
|
|
break;
|
1994-05-27 12:33:43 +00:00
|
|
|
case 'i':
|
|
|
|
todo |= INTRSTAT;
|
|
|
|
break;
|
|
|
|
case 'M':
|
|
|
|
memf = optarg;
|
|
|
|
break;
|
|
|
|
case 'm':
|
|
|
|
todo |= MEMSTAT;
|
|
|
|
break;
|
|
|
|
case 'N':
|
|
|
|
nlistf = optarg;
|
|
|
|
break;
|
1998-09-15 08:16:45 +00:00
|
|
|
case 'n':
|
1998-09-16 18:20:23 +00:00
|
|
|
nflag = 1;
|
1998-09-15 08:16:45 +00:00
|
|
|
maxshowdevs = atoi(optarg);
|
|
|
|
if (maxshowdevs < 0)
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_errx(1, "number of devices %d is < 0",
|
2017-12-01 22:38:28 +00:00
|
|
|
maxshowdevs);
|
1998-09-15 08:16:45 +00:00
|
|
|
break;
|
2015-05-27 18:11:05 +00:00
|
|
|
case 'o':
|
|
|
|
todo |= OBJSTAT;
|
|
|
|
break;
|
1998-09-15 08:16:45 +00:00
|
|
|
case 'p':
|
2017-12-01 22:38:28 +00:00
|
|
|
if (devstat_buildmatch(optarg, &matches, &num_matches)
|
|
|
|
!= 0)
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_errx(1, "%s", devstat_errbuf);
|
1998-09-15 08:16:45 +00:00
|
|
|
break;
|
1994-05-27 12:33:43 +00:00
|
|
|
case 's':
|
|
|
|
todo |= SUMSTAT;
|
|
|
|
break;
|
|
|
|
case 'w':
|
2010-05-21 17:10:52 +00:00
|
|
|
/* Convert to milliseconds. */
|
|
|
|
f = atof(optarg);
|
|
|
|
interval = f * 1000;
|
1994-05-27 12:33:43 +00:00
|
|
|
break;
|
1999-02-15 14:15:28 +00:00
|
|
|
case 'z':
|
|
|
|
todo |= ZMEMSTAT;
|
|
|
|
break;
|
1994-05-27 12:33:43 +00:00
|
|
|
case '?':
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_set_version(VMSTAT_XO_VERSION);
|
1994-05-27 12:33:43 +00:00
|
|
|
if (todo == 0)
|
|
|
|
todo = VMSTAT;
|
|
|
|
|
2003-12-07 17:46:14 +00:00
|
|
|
if (memf != NULL) {
|
|
|
|
kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, errbuf);
|
|
|
|
if (kd == NULL)
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_errx(1, "kvm_openfiles: %s", errbuf);
|
2003-12-07 17:46:14 +00:00
|
|
|
}
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2014-07-11 16:45:55 +00:00
|
|
|
retry_nlist:
|
2003-12-07 17:46:14 +00:00
|
|
|
if (kd != NULL && (c = kvm_nlist(kd, namelist)) != 0) {
|
1994-05-27 12:33:43 +00:00
|
|
|
if (c > 0) {
|
2018-06-13 08:52:04 +00:00
|
|
|
bufsize = 0;
|
|
|
|
len = 0;
|
2017-12-01 22:38:28 +00:00
|
|
|
|
2014-07-11 16:45:55 +00:00
|
|
|
/*
|
2017-12-01 22:38:28 +00:00
|
|
|
* 'cnt' was renamed to 'vm_cnt'. If 'vm_cnt' is not
|
2014-07-11 16:45:55 +00:00
|
|
|
* found try looking up older 'cnt' symbol.
|
|
|
|
* */
|
|
|
|
if (namelist[X_SUM].n_type == 0 &&
|
|
|
|
strcmp(namelist[X_SUM].n_name, "_vm_cnt") == 0) {
|
|
|
|
namelist[X_SUM].n_name = "_cnt";
|
|
|
|
goto retry_nlist;
|
|
|
|
}
|
2017-12-01 22:38:28 +00:00
|
|
|
|
Dynamically allocate IRQ ranges on x86.
Previously, x86 used static ranges of IRQ values for different types
of I/O interrupts. Interrupt pins on I/O APICs and 8259A PICs used
IRQ values from 0 to 254. MSI interrupts used a compile-time-defined
range starting at 256, and Xen event channels used a
compile-time-defined range after MSI. Some recent systems have more
than 255 I/O APIC interrupt pins which resulted in those IRQ values
overflowing into the MSI range triggering an assertion failure.
Replace statically assigned ranges with dynamic ranges. Do a single
pass computing the sizes of the IRQ ranges (PICs, MSI, Xen) to
determine the total number of IRQs required. Allocate the interrupt
source and interrupt count arrays dynamically once this pass has
completed. To minimize runtime complexity these arrays are only sized
once during bootup. The PIC range is determined by the PICs present
in the system. The MSI and Xen ranges continue to use a fixed size,
though this does make it possible to turn the MSI range size into a
tunable in the future.
As a result, various places are updated to use dynamic limits instead
of constants. In addition, the vmstat(8) utility has been taught to
understand that some kernels may treat 'intrcnt' and 'intrnames' as
pointers rather than arrays when extracting interrupt stats from a
crashdump. This is determined by the presence (vs absence) of a
global 'nintrcnt' symbol.
This change reverts r189404 which worked around a buggy BIOS which
enumerated an I/O APIC twice (using the same memory mapped address for
both entries but using an IRQ base of 256 for one entry and a valid
IRQ base for the second entry). Making the "base" of MSI IRQ values
dynamic avoids the panic that r189404 worked around, and there may now
be valid I/O APICs with an IRQ base above 256 which this workaround
would incorrectly skip.
If in the future the issue reported in PR 130483 reoccurs, we will
have to add a pass over the I/O APIC entries in the MADT to detect
duplicates using the memory mapped address and use some strategy to
choose the "correct" one.
While here, reserve room in intrcnts for the Hyper-V counters.
PR: 229429, 130483
Reviewed by: kib, royger, cem
Tested by: royger (Xen), kib (DMAR)
Approved by: re (gjb)
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D16861
2018-08-28 21:09:19 +00:00
|
|
|
/*
|
|
|
|
* 'nintrcnt' doesn't exist in older kernels, but
|
|
|
|
* that isn't fatal.
|
|
|
|
*/
|
|
|
|
if (namelist[X_NINTRCNT].n_type == 0 && c == 1)
|
|
|
|
goto nlist_ok;
|
|
|
|
|
2017-03-11 04:36:15 +00:00
|
|
|
for (c = 0; c < (int)(nitems(namelist)); c++)
|
1994-05-27 12:33:43 +00:00
|
|
|
if (namelist[c].n_type == 0)
|
2017-12-01 22:38:28 +00:00
|
|
|
bufsize += strlen(namelist[c].n_name)
|
|
|
|
+ 1;
|
2015-11-20 05:15:34 +00:00
|
|
|
bufsize += len + 1;
|
|
|
|
buf = bp = alloca(bufsize);
|
|
|
|
|
2017-03-11 04:36:15 +00:00
|
|
|
for (c = 0; c < (int)(nitems(namelist)); c++)
|
2015-11-20 05:15:34 +00:00
|
|
|
if (namelist[c].n_type == 0) {
|
|
|
|
xo_error(" %s",
|
1994-05-27 12:33:43 +00:00
|
|
|
namelist[c].n_name);
|
2015-11-20 05:15:34 +00:00
|
|
|
len = strlen(namelist[c].n_name);
|
|
|
|
*bp++ = ' ';
|
|
|
|
memcpy(bp, namelist[c].n_name, len);
|
|
|
|
bp += len;
|
|
|
|
}
|
|
|
|
*bp = '\0';
|
|
|
|
xo_error("undefined symbols:\n", buf);
|
1994-05-27 12:33:43 +00:00
|
|
|
} else
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_warnx("kvm_nlist: %s", kvm_geterr(kd));
|
|
|
|
xo_finish();
|
1994-05-27 12:33:43 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
Dynamically allocate IRQ ranges on x86.
Previously, x86 used static ranges of IRQ values for different types
of I/O interrupts. Interrupt pins on I/O APICs and 8259A PICs used
IRQ values from 0 to 254. MSI interrupts used a compile-time-defined
range starting at 256, and Xen event channels used a
compile-time-defined range after MSI. Some recent systems have more
than 255 I/O APIC interrupt pins which resulted in those IRQ values
overflowing into the MSI range triggering an assertion failure.
Replace statically assigned ranges with dynamic ranges. Do a single
pass computing the sizes of the IRQ ranges (PICs, MSI, Xen) to
determine the total number of IRQs required. Allocate the interrupt
source and interrupt count arrays dynamically once this pass has
completed. To minimize runtime complexity these arrays are only sized
once during bootup. The PIC range is determined by the PICs present
in the system. The MSI and Xen ranges continue to use a fixed size,
though this does make it possible to turn the MSI range size into a
tunable in the future.
As a result, various places are updated to use dynamic limits instead
of constants. In addition, the vmstat(8) utility has been taught to
understand that some kernels may treat 'intrcnt' and 'intrnames' as
pointers rather than arrays when extracting interrupt stats from a
crashdump. This is determined by the presence (vs absence) of a
global 'nintrcnt' symbol.
This change reverts r189404 which worked around a buggy BIOS which
enumerated an I/O APIC twice (using the same memory mapped address for
both entries but using an IRQ base of 256 for one entry and a valid
IRQ base for the second entry). Making the "base" of MSI IRQ values
dynamic avoids the panic that r189404 worked around, and there may now
be valid I/O APICs with an IRQ base above 256 which this workaround
would incorrectly skip.
If in the future the issue reported in PR 130483 reoccurs, we will
have to add a pass over the I/O APIC entries in the MADT to detect
duplicates using the memory mapped address and use some strategy to
choose the "correct" one.
While here, reserve room in intrcnts for the Hyper-V counters.
PR: 229429, 130483
Reviewed by: kib, royger, cem
Tested by: royger (Xen), kib (DMAR)
Approved by: re (gjb)
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D16861
2018-08-28 21:09:19 +00:00
|
|
|
nlist_ok:
|
2007-12-13 02:36:11 +00:00
|
|
|
if (kd && Pflag)
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_errx(1, "Cannot use -P with crash dumps");
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
if (todo & VMSTAT) {
|
Add a prioritization field to the devstat_add_entry() call so that
peripheral drivers can determine where in the devstat(9) list they are
inserted.
This requires recompilation of libdevstat, systat, vmstat, rpc.rstatd, and
any ports that depend on the devstat code, since the size of the devstat
structure has changed. The devstat version number has been incremented as
well to reflect the change.
This sorts devices in the devstat list in "more interesting" to "less
interesting" order. So, for instance, da devices are now more important
than floppy drives, and so will appear before floppy drives in the default
output from systat, iostat, vmstat, etc.
The order of devices is, for now, kept in a central table in devicestat.h.
If individual drivers were able to make a meaningful decision on what
priority they should be at attach time, we could consider splitting the
priority information out into the various drivers. For now, though, they
have no way of knowing that, so it's easier to put them in an easy to find
table.
Also, move the checkversion() call in vmstat(8) to a more logical place.
Thanks to Bruce and David O'Brien for suggestions, for reviewing this, and
for putting up with the long time it has taken me to commit it. Bruce did
object somewhat to the central priority table (he would rather the
priorities be distributed in each driver), so his objection is duly noted
here.
Reviewed by: bde, obrien
1999-02-10 00:04:13 +00:00
|
|
|
/*
|
|
|
|
* Make sure that the userland devstat version matches the
|
|
|
|
* kernel devstat version. If not, exit and print a
|
|
|
|
* message informing the user of his mistake.
|
|
|
|
*/
|
2003-03-15 21:25:44 +00:00
|
|
|
if (devstat_checkversion(NULL) < 0)
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_errx(1, "%s", devstat_errbuf);
|
Add a prioritization field to the devstat_add_entry() call so that
peripheral drivers can determine where in the devstat(9) list they are
inserted.
This requires recompilation of libdevstat, systat, vmstat, rpc.rstatd, and
any ports that depend on the devstat code, since the size of the devstat
structure has changed. The devstat version number has been incremented as
well to reflect the change.
This sorts devices in the devstat list in "more interesting" to "less
interesting" order. So, for instance, da devices are now more important
than floppy drives, and so will appear before floppy drives in the default
output from systat, iostat, vmstat, etc.
The order of devices is, for now, kept in a central table in devicestat.h.
If individual drivers were able to make a meaningful decision on what
priority they should be at attach time, we could consider splitting the
priority information out into the various drivers. For now, though, they
have no way of knowing that, so it's easier to put them in an easy to find
table.
Also, move the checkversion() call in vmstat(8) to a more logical place.
Thanks to Bruce and David O'Brien for suggestions, for reviewing this, and
for putting up with the long time it has taken me to commit it. Bruce did
object somewhat to the central priority table (he would rather the
priorities be distributed in each driver), so his objection is duly noted
here.
Reviewed by: bde, obrien
1999-02-10 00:04:13 +00:00
|
|
|
|
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
argv = getdrivedata(argv);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*argv) {
|
2010-05-21 17:10:52 +00:00
|
|
|
f = atof(*argv);
|
|
|
|
interval = f * 1000;
|
1994-05-27 12:33:43 +00:00
|
|
|
if (*++argv)
|
|
|
|
reps = atoi(*argv);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (interval) {
|
|
|
|
if (!reps)
|
|
|
|
reps = -1;
|
|
|
|
} else if (reps)
|
2010-05-21 17:10:52 +00:00
|
|
|
interval = 1 * 1000;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
if (todo & FORKSTAT)
|
|
|
|
doforkst();
|
|
|
|
if (todo & MEMSTAT)
|
2005-08-06 13:56:21 +00:00
|
|
|
domemstat_malloc();
|
1999-02-13 09:59:24 +00:00
|
|
|
if (todo & ZMEMSTAT)
|
2005-08-01 21:33:17 +00:00
|
|
|
domemstat_zone();
|
1994-05-27 12:33:43 +00:00
|
|
|
if (todo & SUMSTAT)
|
|
|
|
dosum();
|
2015-05-27 18:11:05 +00:00
|
|
|
if (todo & OBJSTAT)
|
|
|
|
doobjstat();
|
1994-05-27 12:33:43 +00:00
|
|
|
if (todo & INTRSTAT)
|
2015-01-23 16:15:55 +00:00
|
|
|
dointr(interval, reps);
|
1994-05-27 12:33:43 +00:00
|
|
|
if (todo & VMSTAT)
|
|
|
|
dovmstat(interval, reps);
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_finish();
|
1994-05-27 12:33:43 +00:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2003-12-07 17:46:14 +00:00
|
|
|
static int
|
2017-04-21 00:00:23 +00:00
|
|
|
mysysctl(const char *name, void *oldp, size_t *oldlenp)
|
2003-12-07 17:46:14 +00:00
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
2017-04-21 00:00:23 +00:00
|
|
|
error = sysctlbyname(name, oldp, oldlenp, NULL, 0);
|
2003-12-07 17:46:14 +00:00
|
|
|
if (error != 0 && errno != ENOMEM)
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_err(1, "sysctl(%s)", name);
|
2003-12-07 17:46:14 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static char **
|
|
|
|
getdrivedata(char **argv)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2017-12-01 22:38:28 +00:00
|
|
|
|
2003-03-15 21:25:44 +00:00
|
|
|
if ((num_devices = devstat_getnumdevs(NULL)) < 0)
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_errx(1, "%s", devstat_errbuf);
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2009-02-21 03:43:20 +00:00
|
|
|
cur.dinfo = (struct devinfo *)calloc(1, sizeof(struct devinfo));
|
|
|
|
last.dinfo = (struct devinfo *)calloc(1, sizeof(struct devinfo));
|
1998-09-15 08:16:45 +00:00
|
|
|
|
2003-03-15 21:25:44 +00:00
|
|
|
if (devstat_getdevs(NULL, &cur) == -1)
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_errx(1, "%s", devstat_errbuf);
|
1998-09-15 08:16:45 +00:00
|
|
|
|
|
|
|
num_devices = cur.dinfo->numdevs;
|
|
|
|
generation = cur.dinfo->generation;
|
|
|
|
|
2017-12-01 22:38:28 +00:00
|
|
|
specified_devices = malloc(sizeof(char *));
|
1998-09-15 08:16:45 +00:00
|
|
|
for (num_devices_specified = 0; *argv; ++argv) {
|
1994-05-27 12:33:43 +00:00
|
|
|
if (isdigit(**argv))
|
|
|
|
break;
|
1998-09-15 08:16:45 +00:00
|
|
|
num_devices_specified++;
|
2018-06-13 08:52:04 +00:00
|
|
|
specified_devices = reallocf(specified_devices,
|
2017-12-01 22:38:28 +00:00
|
|
|
sizeof(char *) * num_devices_specified);
|
2018-06-13 08:52:04 +00:00
|
|
|
if (specified_devices == NULL) {
|
|
|
|
xo_errx(1, "%s", "reallocf (specified_devices)");
|
|
|
|
}
|
1998-09-15 08:16:45 +00:00
|
|
|
specified_devices[num_devices_specified - 1] = *argv;
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
1998-09-15 08:16:45 +00:00
|
|
|
dev_select = NULL;
|
|
|
|
|
1998-09-16 18:20:23 +00:00
|
|
|
if (nflag == 0 && maxshowdevs < num_devices_specified)
|
2017-12-01 22:38:28 +00:00
|
|
|
maxshowdevs = num_devices_specified;
|
1998-09-16 18:20:23 +00:00
|
|
|
|
1998-09-15 08:16:45 +00:00
|
|
|
/*
|
|
|
|
* People are generally only interested in disk statistics when
|
|
|
|
* they're running vmstat. So, that's what we're going to give
|
|
|
|
* them if they don't specify anything by default. We'll also give
|
|
|
|
* them any other random devices in the system so that we get to
|
|
|
|
* maxshowdevs devices, if that many devices exist. If the user
|
|
|
|
* specifies devices on the command line, either through a pattern
|
|
|
|
* match or by naming them explicitly, we will give the user only
|
|
|
|
* those devices.
|
|
|
|
*/
|
|
|
|
if ((num_devices_specified == 0) && (num_matches == 0)) {
|
2003-03-15 21:25:44 +00:00
|
|
|
if (devstat_buildmatch(da, &matches, &num_matches) != 0)
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_errx(1, "%s", devstat_errbuf);
|
1998-09-15 08:16:45 +00:00
|
|
|
select_mode = DS_SELECT_ADD;
|
|
|
|
} else
|
|
|
|
select_mode = DS_SELECT_ONLY;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* At this point, selectdevs will almost surely indicate that the
|
|
|
|
* device list has changed, so we don't look for return values of 0
|
|
|
|
* or 1. If we get back -1, though, there is an error.
|
|
|
|
*/
|
2003-03-15 21:25:44 +00:00
|
|
|
if (devstat_selectdevs(&dev_select, &num_selected, &num_selections,
|
2017-12-01 22:38:28 +00:00
|
|
|
&select_generation, generation, cur.dinfo->devices,
|
|
|
|
num_devices, matches, num_matches, specified_devices,
|
|
|
|
num_devices_specified, select_mode,
|
|
|
|
maxshowdevs, 0) == -1)
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_errx(1, "%s", devstat_errbuf);
|
1998-09-15 08:16:45 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
return(argv);
|
|
|
|
}
|
|
|
|
|
2015-01-23 16:21:31 +00:00
|
|
|
/* Return system uptime in nanoseconds */
|
|
|
|
static long long
|
2003-12-07 17:46:14 +00:00
|
|
|
getuptime(void)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2005-10-17 15:37:22 +00:00
|
|
|
struct timespec sp;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2015-01-23 16:18:39 +00:00
|
|
|
(void)clock_gettime(CLOCK_UPTIME, &sp);
|
2015-01-23 16:21:31 +00:00
|
|
|
return((long long)sp.tv_sec * 1000000000LL + sp.tv_nsec);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
2009-10-29 17:34:02 +00:00
|
|
|
static void
|
- Remove 'struct vmmeter' from 'struct pcpu', leaving only global vmmeter
in place. To do per-cpu stats, convert all fields that previously were
maintained in the vmmeters that sit in pcpus to counter(9).
- Since some vmmeter stats may be touched at very early stages of boot,
before we have set up UMA and we can do counter_u64_alloc(), provide an
early counter mechanism:
o Leave one spare uint64_t in struct pcpu, named pc_early_dummy_counter.
o Point counter(9) fields of vmmeter to pcpu[0].pc_early_dummy_counter,
so that at early stages of boot, before counters are allocated we already
point to a counter that can be safely written to.
o For sparc64 that required a whole dummy pcpu[MAXCPU] array.
Further related changes:
- Don't include vmmeter.h into pcpu.h.
- vm.stats.vm.v_swappgsout and vm.stats.vm.v_swappgsin changed to 64-bit,
to match kernel representation.
- struct vmmeter hidden under _KERNEL, and only vmstat(1) is an exclusion.
This is based on benno@'s 4-year old patch:
https://lists.freebsd.org/pipermail/freebsd-arch/2013-July/014471.html
Reviewed by: kib, gallatin, marius, lidl
Differential Revision: https://reviews.freebsd.org/D10156
2017-04-17 17:34:47 +00:00
|
|
|
fill_vmmeter(struct __vmmeter *vmmp)
|
2003-12-07 17:46:14 +00:00
|
|
|
{
|
2017-12-01 22:38:28 +00:00
|
|
|
struct vmmeter vm_cnt;
|
|
|
|
size_t size;
|
2009-10-29 17:34:02 +00:00
|
|
|
|
2003-12-07 17:46:14 +00:00
|
|
|
if (kd != NULL) {
|
- Remove 'struct vmmeter' from 'struct pcpu', leaving only global vmmeter
in place. To do per-cpu stats, convert all fields that previously were
maintained in the vmmeters that sit in pcpus to counter(9).
- Since some vmmeter stats may be touched at very early stages of boot,
before we have set up UMA and we can do counter_u64_alloc(), provide an
early counter mechanism:
o Leave one spare uint64_t in struct pcpu, named pc_early_dummy_counter.
o Point counter(9) fields of vmmeter to pcpu[0].pc_early_dummy_counter,
so that at early stages of boot, before counters are allocated we already
point to a counter that can be safely written to.
o For sparc64 that required a whole dummy pcpu[MAXCPU] array.
Further related changes:
- Don't include vmmeter.h into pcpu.h.
- vm.stats.vm.v_swappgsout and vm.stats.vm.v_swappgsin changed to 64-bit,
to match kernel representation.
- struct vmmeter hidden under _KERNEL, and only vmstat(1) is an exclusion.
This is based on benno@'s 4-year old patch:
https://lists.freebsd.org/pipermail/freebsd-arch/2013-July/014471.html
Reviewed by: kib, gallatin, marius, lidl
Differential Revision: https://reviews.freebsd.org/D10156
2017-04-17 17:34:47 +00:00
|
|
|
kread(X_SUM, &vm_cnt, sizeof(vm_cnt));
|
|
|
|
#define GET_COUNTER(name) \
|
|
|
|
vmmp->name = kvm_counter_u64_fetch(kd, (u_long)vm_cnt.name)
|
|
|
|
GET_COUNTER(v_swtch);
|
|
|
|
GET_COUNTER(v_trap);
|
|
|
|
GET_COUNTER(v_syscall);
|
|
|
|
GET_COUNTER(v_intr);
|
|
|
|
GET_COUNTER(v_soft);
|
|
|
|
GET_COUNTER(v_vm_faults);
|
|
|
|
GET_COUNTER(v_io_faults);
|
|
|
|
GET_COUNTER(v_cow_faults);
|
|
|
|
GET_COUNTER(v_cow_optim);
|
|
|
|
GET_COUNTER(v_zfod);
|
|
|
|
GET_COUNTER(v_ozfod);
|
|
|
|
GET_COUNTER(v_swapin);
|
|
|
|
GET_COUNTER(v_swapout);
|
|
|
|
GET_COUNTER(v_swappgsin);
|
|
|
|
GET_COUNTER(v_swappgsout);
|
|
|
|
GET_COUNTER(v_vnodein);
|
|
|
|
GET_COUNTER(v_vnodeout);
|
|
|
|
GET_COUNTER(v_vnodepgsin);
|
|
|
|
GET_COUNTER(v_vnodepgsout);
|
|
|
|
GET_COUNTER(v_intrans);
|
|
|
|
GET_COUNTER(v_tfree);
|
|
|
|
GET_COUNTER(v_forks);
|
|
|
|
GET_COUNTER(v_vforks);
|
|
|
|
GET_COUNTER(v_rforks);
|
|
|
|
GET_COUNTER(v_kthreads);
|
|
|
|
GET_COUNTER(v_forkpages);
|
|
|
|
GET_COUNTER(v_vforkpages);
|
|
|
|
GET_COUNTER(v_rforkpages);
|
|
|
|
GET_COUNTER(v_kthreadpages);
|
|
|
|
#undef GET_COUNTER
|
2003-12-07 17:46:14 +00:00
|
|
|
} else {
|
2017-04-21 00:00:23 +00:00
|
|
|
#define GET_VM_STATS(cat, name) do { \
|
|
|
|
size = sizeof(vmmp->name); \
|
|
|
|
mysysctl("vm.stats." #cat "." #name, &vmmp->name, &size); \
|
|
|
|
} while (0)
|
2003-12-07 17:46:14 +00:00
|
|
|
/* sys */
|
|
|
|
GET_VM_STATS(sys, v_swtch);
|
|
|
|
GET_VM_STATS(sys, v_trap);
|
|
|
|
GET_VM_STATS(sys, v_syscall);
|
|
|
|
GET_VM_STATS(sys, v_intr);
|
|
|
|
GET_VM_STATS(sys, v_soft);
|
|
|
|
|
|
|
|
/* vm */
|
2003-12-10 22:19:19 +00:00
|
|
|
GET_VM_STATS(vm, v_vm_faults);
|
2013-01-28 12:58:37 +00:00
|
|
|
GET_VM_STATS(vm, v_io_faults);
|
2003-12-10 22:19:19 +00:00
|
|
|
GET_VM_STATS(vm, v_cow_faults);
|
|
|
|
GET_VM_STATS(vm, v_cow_optim);
|
|
|
|
GET_VM_STATS(vm, v_zfod);
|
|
|
|
GET_VM_STATS(vm, v_ozfod);
|
|
|
|
GET_VM_STATS(vm, v_swapin);
|
|
|
|
GET_VM_STATS(vm, v_swapout);
|
|
|
|
GET_VM_STATS(vm, v_swappgsin);
|
|
|
|
GET_VM_STATS(vm, v_swappgsout);
|
|
|
|
GET_VM_STATS(vm, v_vnodein);
|
|
|
|
GET_VM_STATS(vm, v_vnodeout);
|
|
|
|
GET_VM_STATS(vm, v_vnodepgsin);
|
|
|
|
GET_VM_STATS(vm, v_vnodepgsout);
|
|
|
|
GET_VM_STATS(vm, v_intrans);
|
|
|
|
GET_VM_STATS(vm, v_reactivated);
|
|
|
|
GET_VM_STATS(vm, v_pdwakeups);
|
|
|
|
GET_VM_STATS(vm, v_pdpages);
|
2016-11-10 19:55:45 +00:00
|
|
|
GET_VM_STATS(vm, v_pdshortfalls);
|
2003-12-10 22:19:19 +00:00
|
|
|
GET_VM_STATS(vm, v_dfree);
|
|
|
|
GET_VM_STATS(vm, v_pfree);
|
|
|
|
GET_VM_STATS(vm, v_tfree);
|
|
|
|
GET_VM_STATS(vm, v_page_size);
|
|
|
|
GET_VM_STATS(vm, v_page_count);
|
|
|
|
GET_VM_STATS(vm, v_free_reserved);
|
|
|
|
GET_VM_STATS(vm, v_free_target);
|
|
|
|
GET_VM_STATS(vm, v_free_min);
|
|
|
|
GET_VM_STATS(vm, v_free_count);
|
|
|
|
GET_VM_STATS(vm, v_wire_count);
|
Provide separate accounting for user-wired pages.
Historically we have not distinguished between kernel wirings and user
wirings for accounting purposes. User wirings (via mlock(2)) were
subject to a global limit on the number of wired pages, so if large
swaths of physical memory were wired by the kernel, as happens with
the ZFS ARC among other things, the limit could be exceeded, causing
user wirings to fail.
The change adds a new counter, v_user_wire_count, which counts the
number of virtual pages wired by user processes via mlock(2) and
mlockall(2). Only user-wired pages are subject to the system-wide
limit which helps provide some safety against deadlocks. In
particular, while sources of kernel wirings typically support some
backpressure mechanism, there is no way to reclaim user-wired pages
shorting of killing the wiring process. The limit is exported as
vm.max_user_wired, renamed from vm.max_wired, and changed from u_int
to u_long.
The choice to count virtual user-wired pages rather than physical
pages was done for simplicity. There are mechanisms that can cause
user-wired mappings to be destroyed while maintaining a wiring of
the backing physical page; these make it difficult to accurately
track user wirings at the physical page layer.
The change also closes some holes which allowed user wirings to succeed
even when they would cause the system limit to be exceeded. For
instance, mmap() may now fail with ENOMEM in a process that has called
mlockall(MCL_FUTURE) if the new mapping would cause the user wiring
limit to be exceeded.
Note that bhyve -S is subject to the user wiring limit, which defaults
to 1/3 of physical RAM. Users that wish to exceed the limit must tune
vm.max_user_wired.
Reviewed by: kib, ngie (mlock() test changes)
Tested by: pho (earlier version)
MFC after: 45 days
Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D19908
2019-05-13 16:38:48 +00:00
|
|
|
GET_VM_STATS(vm, v_user_wire_count);
|
2003-12-10 22:19:19 +00:00
|
|
|
GET_VM_STATS(vm, v_active_count);
|
|
|
|
GET_VM_STATS(vm, v_inactive_target);
|
|
|
|
GET_VM_STATS(vm, v_inactive_count);
|
2016-11-10 19:55:45 +00:00
|
|
|
GET_VM_STATS(vm, v_laundry_count);
|
2003-12-10 22:19:19 +00:00
|
|
|
GET_VM_STATS(vm, v_pageout_free_min);
|
|
|
|
GET_VM_STATS(vm, v_interrupt_free_min);
|
|
|
|
/*GET_VM_STATS(vm, v_free_severe);*/
|
2003-12-07 17:46:14 +00:00
|
|
|
GET_VM_STATS(vm, v_forks);
|
|
|
|
GET_VM_STATS(vm, v_vforks);
|
|
|
|
GET_VM_STATS(vm, v_rforks);
|
|
|
|
GET_VM_STATS(vm, v_kthreads);
|
|
|
|
GET_VM_STATS(vm, v_forkpages);
|
|
|
|
GET_VM_STATS(vm, v_vforkpages);
|
|
|
|
GET_VM_STATS(vm, v_rforkpages);
|
|
|
|
GET_VM_STATS(vm, v_kthreadpages);
|
|
|
|
#undef GET_VM_STATS
|
|
|
|
}
|
|
|
|
}
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2003-12-07 17:46:14 +00:00
|
|
|
static void
|
|
|
|
fill_vmtotal(struct vmtotal *vmtp)
|
|
|
|
{
|
2017-12-01 22:38:28 +00:00
|
|
|
size_t size;
|
|
|
|
|
2003-12-07 17:46:14 +00:00
|
|
|
if (kd != NULL) {
|
|
|
|
/* XXX fill vmtp */
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_errx(1, "not implemented");
|
2003-12-07 17:46:14 +00:00
|
|
|
} else {
|
2017-12-01 22:38:28 +00:00
|
|
|
size = sizeof(*vmtp);
|
2017-04-21 00:00:23 +00:00
|
|
|
mysysctl("vm.vmtotal", vmtp, &size);
|
2003-12-07 17:46:14 +00:00
|
|
|
if (size != sizeof(*vmtp))
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_errx(1, "vm.total size mismatch");
|
2003-12-07 17:46:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-13 02:36:11 +00:00
|
|
|
/* Determine how many cpu columns, and what index they are in kern.cp_times */
|
2022-09-29 16:27:24 +00:00
|
|
|
static void
|
2007-12-13 02:36:11 +00:00
|
|
|
getcpuinfo(u_long *maskp, int *maxidp)
|
|
|
|
{
|
|
|
|
long *times;
|
|
|
|
u_long mask;
|
2017-12-01 22:38:28 +00:00
|
|
|
size_t size;
|
2022-09-29 16:27:24 +00:00
|
|
|
int empty, i, j, maxcpu, maxid;
|
2007-12-13 02:36:11 +00:00
|
|
|
|
|
|
|
if (kd != NULL)
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_errx(1, "not implemented");
|
2007-12-13 02:36:11 +00:00
|
|
|
mask = 0;
|
|
|
|
size = sizeof(maxcpu);
|
2017-04-21 00:00:23 +00:00
|
|
|
mysysctl("kern.smp.maxcpus", &maxcpu, &size);
|
2007-12-13 02:36:11 +00:00
|
|
|
if (size != sizeof(maxcpu))
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_errx(1, "sysctl kern.smp.maxcpus");
|
2007-12-13 02:36:11 +00:00
|
|
|
size = sizeof(long) * maxcpu * CPUSTATES;
|
|
|
|
times = malloc(size);
|
|
|
|
if (times == NULL)
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_err(1, "malloc %zd bytes", size);
|
2017-04-21 00:00:23 +00:00
|
|
|
mysysctl("kern.cp_times", times, &size);
|
2007-12-13 02:36:11 +00:00
|
|
|
maxid = (size / CPUSTATES / sizeof(long)) - 1;
|
|
|
|
for (i = 0; i <= maxid; i++) {
|
|
|
|
empty = 1;
|
|
|
|
for (j = 0; empty && j < CPUSTATES; j++) {
|
|
|
|
if (times[i * CPUSTATES + j] != 0)
|
|
|
|
empty = 0;
|
|
|
|
}
|
2022-09-29 16:27:24 +00:00
|
|
|
if (!empty)
|
2007-12-13 02:36:11 +00:00
|
|
|
mask |= (1ul << i);
|
|
|
|
}
|
|
|
|
if (maskp)
|
|
|
|
*maskp = mask;
|
|
|
|
if (maxidp)
|
|
|
|
*maxidp = maxid;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2019-11-08 11:09:50 +00:00
|
|
|
prthuman(const char *name, uint64_t val, int size, int flags)
|
2007-12-13 02:36:11 +00:00
|
|
|
{
|
2017-12-01 22:38:28 +00:00
|
|
|
char buf[10];
|
2015-11-20 05:15:34 +00:00
|
|
|
char fmt[128];
|
|
|
|
|
|
|
|
snprintf(fmt, sizeof(fmt), "{:%s/%%*s}", name);
|
2007-12-13 02:36:11 +00:00
|
|
|
|
|
|
|
if (size < 5 || size > 9)
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_errx(1, "doofus");
|
2019-11-08 11:09:50 +00:00
|
|
|
flags |= HN_NOSPACE | HN_DECIMAL;
|
2007-12-13 02:36:11 +00:00
|
|
|
humanize_number(buf, size, val, "", HN_AUTOSCALE, flags);
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_attr("value", "%ju", (uintmax_t) val);
|
|
|
|
xo_emit(fmt, size, buf);
|
2007-12-13 02:36:11 +00:00
|
|
|
}
|
|
|
|
|
2003-12-07 17:46:14 +00:00
|
|
|
static void
|
2003-12-10 21:43:10 +00:00
|
|
|
dovmstat(unsigned int interval, int reps)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2017-12-01 22:38:28 +00:00
|
|
|
struct clockinfo clockrate;
|
1994-05-27 12:33:43 +00:00
|
|
|
struct vmtotal total;
|
1998-09-15 08:16:45 +00:00
|
|
|
struct devinfo *tmp_dinfo;
|
2007-12-13 02:36:11 +00:00
|
|
|
u_long cpumask;
|
2017-12-01 22:38:28 +00:00
|
|
|
size_t size;
|
|
|
|
time_t uptime, halfuptime;
|
2022-09-29 16:27:24 +00:00
|
|
|
int maxid, rate_adj, retval;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2015-01-23 16:21:31 +00:00
|
|
|
uptime = getuptime() / 1000000000LL;
|
1994-05-27 12:33:43 +00:00
|
|
|
halfuptime = uptime / 2;
|
2010-05-21 17:10:52 +00:00
|
|
|
rate_adj = 1;
|
2014-09-10 22:34:08 +00:00
|
|
|
maxid = 0;
|
2017-12-01 22:38:28 +00:00
|
|
|
cpumask = 0;
|
2008-11-04 18:02:35 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If the user stops the program (control-Z) and then resumes it,
|
|
|
|
* print out the header again.
|
|
|
|
*/
|
1994-05-27 12:33:43 +00:00
|
|
|
(void)signal(SIGCONT, needhdr);
|
|
|
|
|
2008-11-04 18:02:35 +00:00
|
|
|
/*
|
|
|
|
* If our standard output is a tty, then install a SIGWINCH handler
|
|
|
|
* and set wresized so that our first iteration through the main
|
2008-11-04 18:20:54 +00:00
|
|
|
* vmstat loop will peek at the terminal's current rows to find out
|
2008-11-04 18:02:35 +00:00
|
|
|
* how many lines can fit in a screenful of output.
|
|
|
|
*/
|
|
|
|
if (isatty(fileno(stdout)) != 0) {
|
|
|
|
wresized = 1;
|
|
|
|
(void)signal(SIGWINCH, needresize);
|
|
|
|
} else {
|
|
|
|
wresized = 0;
|
|
|
|
winlines = VMSTAT_DEFAULT_LINES;
|
|
|
|
}
|
|
|
|
|
2003-12-07 17:46:14 +00:00
|
|
|
if (kd != NULL) {
|
|
|
|
if (namelist[X_STATHZ].n_type != 0 &&
|
|
|
|
namelist[X_STATHZ].n_value != 0)
|
|
|
|
kread(X_STATHZ, &hz, sizeof(hz));
|
|
|
|
if (!hz)
|
|
|
|
kread(X_HZ, &hz, sizeof(hz));
|
|
|
|
} else {
|
|
|
|
size = sizeof(clockrate);
|
2017-04-21 00:00:23 +00:00
|
|
|
mysysctl("kern.clockrate", &clockrate, &size);
|
2003-12-07 17:46:14 +00:00
|
|
|
if (size != sizeof(clockrate))
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_errx(1, "clockrate size mismatch");
|
2003-12-07 17:46:14 +00:00
|
|
|
hz = clockrate.hz;
|
|
|
|
}
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2007-12-13 02:36:11 +00:00
|
|
|
if (Pflag) {
|
2022-09-29 16:27:24 +00:00
|
|
|
getcpuinfo(&cpumask, &maxid);
|
2007-12-13 02:36:11 +00:00
|
|
|
size_cp_times = sizeof(long) * (maxid + 1) * CPUSTATES;
|
2009-02-21 03:43:20 +00:00
|
|
|
cur_cp_times = calloc(1, size_cp_times);
|
|
|
|
last_cp_times = calloc(1, size_cp_times);
|
2007-12-13 02:36:11 +00:00
|
|
|
}
|
1994-05-27 12:33:43 +00:00
|
|
|
for (hdrcnt = 1;;) {
|
|
|
|
if (!--hdrcnt)
|
2014-09-10 22:34:08 +00:00
|
|
|
printhdr(maxid, cpumask);
|
2003-12-07 17:46:14 +00:00
|
|
|
if (kd != NULL) {
|
2008-08-19 21:33:09 +00:00
|
|
|
if (kvm_getcptime(kd, cur.cp_time) < 0)
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_errx(1, "kvm_getcptime: %s", kvm_geterr(kd));
|
2003-12-07 17:46:14 +00:00
|
|
|
} else {
|
|
|
|
size = sizeof(cur.cp_time);
|
2017-04-21 00:00:23 +00:00
|
|
|
mysysctl("kern.cp_time", &cur.cp_time, &size);
|
2003-12-07 17:46:14 +00:00
|
|
|
if (size != sizeof(cur.cp_time))
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_errx(1, "cp_time size mismatch");
|
2003-12-07 17:46:14 +00:00
|
|
|
}
|
2007-12-13 02:36:11 +00:00
|
|
|
if (Pflag) {
|
|
|
|
size = size_cp_times;
|
2017-04-21 00:00:23 +00:00
|
|
|
mysysctl("kern.cp_times", cur_cp_times, &size);
|
2007-12-13 02:36:11 +00:00
|
|
|
if (size != size_cp_times)
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_errx(1, "cp_times mismatch");
|
2007-12-13 02:36:11 +00:00
|
|
|
}
|
1998-09-15 08:16:45 +00:00
|
|
|
|
|
|
|
tmp_dinfo = last.dinfo;
|
|
|
|
last.dinfo = cur.dinfo;
|
|
|
|
cur.dinfo = tmp_dinfo;
|
Run a revision of the devstat interface:
Kernel:
Change statistics to use the *uptime() timescale (ie: relative to
boottime) rather than the UTC aligned timescale. This makes the
device statistics code oblivious to clock steps.
Change timestamps to bintime format, they are cheaper.
Remove the "busy_count", and replace it with two counter fields:
"start_count" and "end_count", which are updated in the down and
up paths respectively. This removes the locking constraint on
devstat.
Add a timestamp argument to devstat_start_transaction(), this will
normally be a timestamp set by the *_bio() function in bp->bio_t0.
Use this field to calculate duration of I/O operations.
Add two timestamp arguments to devstat_end_transaction(), one is
the current time, a NULL pointer means "take timestamp yourself",
the other is the timestamp of when this transaction started (see
above).
Change calculation of busy_time to operate on "the salami principle":
Only when we are idle, which we can determine by the start+end
counts being identical, do we update the "busy_from" field in the
down path. In the up path we accumulate the timeslice in busy_time
and update busy_from.
Change the byte_* and num_* fields into two arrays: bytes[] and
operations[].
Userland:
Change the misleading "busy_time" name to be called "snap_time" and
make the time long double since that is what most users need anyway,
fill it using clock_gettime(CLOCK_MONOTONIC) to put it on the same
timescale as the kernel fields.
Change devstat_compute_etime() to operate on struct bintime.
Remove the version 2 legacy interface: the change to bintime makes
compatibility far too expensive.
Fix a bug in systat's "vm" page where boot relative busy times would
be bogus.
Bump __FreeBSD_version to 500107
Review & Collaboration by: ken
2003-03-15 21:59:06 +00:00
|
|
|
last.snap_time = cur.snap_time;
|
1998-09-15 08:16:45 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Here what we want to do is refresh our device stats.
|
|
|
|
* getdevs() returns 1 when the device list has changed.
|
|
|
|
* If the device list has changed, we want to go through
|
|
|
|
* the selection process again, in case a device that we
|
|
|
|
* were previously displaying has gone away.
|
|
|
|
*/
|
2003-03-15 21:25:44 +00:00
|
|
|
switch (devstat_getdevs(NULL, &cur)) {
|
1998-09-15 08:16:45 +00:00
|
|
|
case -1:
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_errx(1, "%s", devstat_errbuf);
|
1998-09-15 08:16:45 +00:00
|
|
|
break;
|
2017-12-01 22:38:28 +00:00
|
|
|
case 1:
|
1998-09-15 08:16:45 +00:00
|
|
|
num_devices = cur.dinfo->numdevs;
|
|
|
|
generation = cur.dinfo->generation;
|
|
|
|
|
2003-03-15 21:25:44 +00:00
|
|
|
retval = devstat_selectdevs(&dev_select, &num_selected,
|
2017-12-01 22:38:28 +00:00
|
|
|
&num_selections, &select_generation,
|
|
|
|
generation, cur.dinfo->devices,
|
|
|
|
num_devices, matches, num_matches,
|
|
|
|
specified_devices,
|
|
|
|
num_devices_specified, select_mode,
|
|
|
|
maxshowdevs, 0);
|
1998-09-15 08:16:45 +00:00
|
|
|
switch (retval) {
|
|
|
|
case -1:
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_errx(1, "%s", devstat_errbuf);
|
1998-09-15 08:16:45 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
2014-09-10 22:34:08 +00:00
|
|
|
printhdr(maxid, cpumask);
|
1998-09-15 08:16:45 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2017-12-01 22:38:28 +00:00
|
|
|
break;
|
1998-09-15 08:16:45 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-12-07 17:46:14 +00:00
|
|
|
fill_vmmeter(&sum);
|
|
|
|
fill_vmtotal(&total);
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_open_container("processes");
|
2019-11-08 11:09:50 +00:00
|
|
|
xo_emit("{:runnable/%2d} {:waiting/%2ld} "
|
|
|
|
"{:swapped-out/%2ld}", total.t_rq - 1, total.t_dw +
|
2017-12-01 22:38:28 +00:00
|
|
|
total.t_pw, total.t_sw);
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_close_container("processes");
|
|
|
|
xo_open_container("memory");
|
2017-11-23 19:10:09 +00:00
|
|
|
#define vmstat_pgtok(a) ((uintmax_t)(a) * (sum.v_page_size >> 10))
|
2019-12-29 12:24:41 +00:00
|
|
|
#define rate(x) (unsigned long)(((x) * rate_adj + halfuptime) / uptime)
|
2007-12-13 02:36:11 +00:00
|
|
|
if (hflag) {
|
2015-11-20 05:15:34 +00:00
|
|
|
prthuman("available-memory",
|
2019-11-08 11:09:50 +00:00
|
|
|
total.t_avm * (uint64_t)sum.v_page_size, 5, HN_B);
|
2015-11-20 05:15:34 +00:00
|
|
|
prthuman("free-memory",
|
2019-11-08 11:09:50 +00:00
|
|
|
total.t_free * (uint64_t)sum.v_page_size, 5, HN_B);
|
|
|
|
prthuman("total-page-faults",
|
2019-12-29 12:24:41 +00:00
|
|
|
rate(sum.v_vm_faults - osum.v_vm_faults), 5, 0);
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_emit(" ");
|
2007-12-13 02:36:11 +00:00
|
|
|
} else {
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_emit(" ");
|
2017-11-23 19:10:09 +00:00
|
|
|
xo_emit("{:available-memory/%7ju}",
|
2017-12-01 22:38:28 +00:00
|
|
|
vmstat_pgtok(total.t_avm));
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_emit(" ");
|
2017-11-23 19:10:09 +00:00
|
|
|
xo_emit("{:free-memory/%7ju}",
|
2017-12-01 22:38:28 +00:00
|
|
|
vmstat_pgtok(total.t_free));
|
2017-08-08 12:18:11 +00:00
|
|
|
xo_emit(" ");
|
2019-11-08 11:09:50 +00:00
|
|
|
xo_emit("{:total-page-faults/%5lu} ",
|
2019-12-29 12:24:41 +00:00
|
|
|
rate(sum.v_vm_faults - osum.v_vm_faults));
|
2007-12-13 02:36:11 +00:00
|
|
|
}
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_close_container("memory");
|
|
|
|
|
|
|
|
xo_open_container("paging-rates");
|
|
|
|
xo_emit("{:page-reactivated/%3lu} ",
|
2019-12-29 12:24:41 +00:00
|
|
|
rate(sum.v_reactivated - osum.v_reactivated));
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_emit("{:paged-in/%3lu} ",
|
2019-12-29 12:24:41 +00:00
|
|
|
rate(sum.v_swapin + sum.v_vnodein -
|
1994-10-17 10:34:42 +00:00
|
|
|
(osum.v_swapin + osum.v_vnodein)));
|
2019-11-08 11:09:50 +00:00
|
|
|
xo_emit("{:paged-out/%3lu}",
|
2019-12-29 12:24:41 +00:00
|
|
|
rate(sum.v_swapout + sum.v_vnodeout -
|
1994-10-18 15:00:06 +00:00
|
|
|
(osum.v_swapout + osum.v_vnodeout)));
|
2019-11-08 11:09:50 +00:00
|
|
|
if (hflag) {
|
|
|
|
prthuman("freed",
|
2019-12-29 12:24:41 +00:00
|
|
|
rate(sum.v_tfree - osum.v_tfree), 5, 0);
|
2019-11-08 11:09:50 +00:00
|
|
|
prthuman("scanned",
|
2019-12-29 12:24:41 +00:00
|
|
|
rate(sum.v_pdpages - osum.v_pdpages), 5, 0);
|
2019-11-08 11:09:50 +00:00
|
|
|
xo_emit(" ");
|
|
|
|
} else {
|
|
|
|
xo_emit(" ");
|
|
|
|
xo_emit("{:freed/%5lu} ",
|
2019-12-29 12:24:41 +00:00
|
|
|
rate(sum.v_tfree - osum.v_tfree));
|
2019-11-08 11:09:50 +00:00
|
|
|
xo_emit("{:scanned/%4lu} ",
|
2019-12-29 12:24:41 +00:00
|
|
|
rate(sum.v_pdpages - osum.v_pdpages));
|
2019-11-08 11:09:50 +00:00
|
|
|
}
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_close_container("paging-rates");
|
|
|
|
|
1998-09-15 08:16:45 +00:00
|
|
|
devstats();
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_open_container("fault-rates");
|
2019-12-29 12:24:41 +00:00
|
|
|
xo_emit("{:interrupts/%4lu}", rate(sum.v_intr - osum.v_intr));
|
2019-11-08 11:09:50 +00:00
|
|
|
if (hflag) {
|
|
|
|
prthuman("system-calls",
|
2019-12-29 12:24:41 +00:00
|
|
|
rate(sum.v_syscall - osum.v_syscall), 5, 0);
|
2019-11-08 11:09:50 +00:00
|
|
|
prthuman("context-switches",
|
2019-12-29 12:24:41 +00:00
|
|
|
rate(sum.v_swtch - osum.v_swtch), 5, 0);
|
2019-11-08 11:09:50 +00:00
|
|
|
} else {
|
|
|
|
xo_emit(" ");
|
|
|
|
xo_emit("{:system-calls/%5lu} "
|
|
|
|
"{:context-switches/%5lu}",
|
2019-12-29 12:24:41 +00:00
|
|
|
rate(sum.v_syscall - osum.v_syscall),
|
|
|
|
rate(sum.v_swtch - osum.v_swtch));
|
2019-11-08 11:09:50 +00:00
|
|
|
}
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_close_container("fault-rates");
|
2007-12-13 02:36:11 +00:00
|
|
|
if (Pflag)
|
2017-12-01 22:38:28 +00:00
|
|
|
pcpustats(cpumask, maxid);
|
2007-12-13 02:36:11 +00:00
|
|
|
else
|
|
|
|
cpustats();
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_emit("\n");
|
|
|
|
xo_flush();
|
1994-05-27 12:33:43 +00:00
|
|
|
if (reps >= 0 && --reps <= 0)
|
|
|
|
break;
|
|
|
|
osum = sum;
|
|
|
|
uptime = interval;
|
2010-05-21 17:10:52 +00:00
|
|
|
rate_adj = 1000;
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* We round upward to avoid losing low-frequency events
|
2010-05-21 17:10:52 +00:00
|
|
|
* (i.e., >= 1 per interval but < 1 per millisecond).
|
1994-05-27 12:33:43 +00:00
|
|
|
*/
|
1994-10-17 10:34:42 +00:00
|
|
|
if (interval != 1)
|
|
|
|
halfuptime = (uptime + 1) / 2;
|
|
|
|
else
|
|
|
|
halfuptime = 0;
|
2010-05-21 17:10:52 +00:00
|
|
|
(void)usleep(interval * 1000);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-07 17:46:14 +00:00
|
|
|
static void
|
2014-10-26 20:48:26 +00:00
|
|
|
printhdr(int maxid, u_long cpumask)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
1999-02-10 00:46:27 +00:00
|
|
|
int i, num_shown;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2016-04-22 03:46:57 +00:00
|
|
|
num_shown = MIN(num_selected, maxshowdevs);
|
2017-12-01 22:38:28 +00:00
|
|
|
if (hflag)
|
2019-11-08 11:09:50 +00:00
|
|
|
xo_emit(" {T:procs} {T:memory} {T:/page%*s}", 19, "");
|
2017-12-01 22:38:28 +00:00
|
|
|
else
|
2019-10-29 20:28:02 +00:00
|
|
|
xo_emit("{T:procs} {T:memory} {T:/page%*s}", 19, "");
|
1999-02-10 00:46:27 +00:00
|
|
|
if (num_shown > 1)
|
2019-11-08 11:09:50 +00:00
|
|
|
xo_emit(" {T:/disks %*s} ", num_shown * 4 - 7, "");
|
1999-02-10 00:46:27 +00:00
|
|
|
else if (num_shown == 1)
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_emit(" {T:disks}");
|
2019-11-08 11:09:50 +00:00
|
|
|
xo_emit(" {T:faults} ");
|
2007-12-13 02:36:11 +00:00
|
|
|
if (Pflag) {
|
2014-10-26 20:48:26 +00:00
|
|
|
for (i = 0; i <= maxid; i++) {
|
2008-01-18 22:09:44 +00:00
|
|
|
if (cpumask & (1ul << i))
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_emit(" {T:/cpu%d} ", i);
|
2007-12-13 02:36:11 +00:00
|
|
|
}
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_emit("\n");
|
2007-12-13 02:36:11 +00:00
|
|
|
} else
|
2019-11-08 11:09:50 +00:00
|
|
|
xo_emit(" {T:cpu}\n");
|
2014-10-24 04:01:14 +00:00
|
|
|
if (hflag) {
|
2019-11-08 11:09:50 +00:00
|
|
|
xo_emit(" {T:r} {T:b} {T:w} {T:avm} {T:fre} {T:flt} {T:re}"
|
|
|
|
" {T:pi} {T:po} {T:fr} {T:sr} ");
|
2014-10-24 04:01:14 +00:00
|
|
|
} else {
|
2017-12-01 22:38:28 +00:00
|
|
|
xo_emit("{T:r} {T:b} {T:w} {T:avm} {T:fre} {T:flt} "
|
|
|
|
"{T:re} {T:pi} {T:po} {T:fr} {T:sr} ");
|
2014-10-24 04:01:14 +00:00
|
|
|
}
|
1998-09-15 08:16:45 +00:00
|
|
|
for (i = 0; i < num_devices; i++)
|
2017-12-01 22:38:28 +00:00
|
|
|
if ((dev_select[i].selected) &&
|
|
|
|
(dev_select[i].selected <= maxshowdevs))
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_emit("{T:/%c%c%d} ", dev_select[i].device_name[0],
|
2017-12-01 22:38:28 +00:00
|
|
|
dev_select[i].device_name[1],
|
|
|
|
dev_select[i].unit_number);
|
2019-11-08 11:09:50 +00:00
|
|
|
xo_emit(" {T:in} {T:sy} {T:cs}");
|
2007-12-13 02:36:11 +00:00
|
|
|
if (Pflag) {
|
2014-10-26 20:48:26 +00:00
|
|
|
for (i = 0; i <= maxid; i++) {
|
2014-09-10 22:34:08 +00:00
|
|
|
if (cpumask & (1ul << i))
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_emit(" {T:us} {T:sy} {T:id}");
|
2014-09-10 22:34:08 +00:00
|
|
|
}
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_emit("\n");
|
2007-12-13 02:36:11 +00:00
|
|
|
} else
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_emit(" {T:us} {T:sy} {T:id}\n");
|
2008-11-04 18:02:35 +00:00
|
|
|
if (wresized != 0)
|
|
|
|
doresize();
|
|
|
|
hdrcnt = winlines;
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Force a header to be prepended to the next output.
|
|
|
|
*/
|
2003-12-07 17:46:14 +00:00
|
|
|
static void
|
|
|
|
needhdr(int dummy __unused)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
hdrcnt = 1;
|
|
|
|
}
|
|
|
|
|
2008-11-04 18:02:35 +00:00
|
|
|
/*
|
|
|
|
* When the terminal is resized, force an update of the maximum number of rows
|
|
|
|
* printed between each header repetition. Then force a new header to be
|
|
|
|
* prepended to the next output.
|
|
|
|
*/
|
|
|
|
void
|
2017-12-01 22:38:28 +00:00
|
|
|
needresize(int signo __unused)
|
2008-11-04 18:02:35 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
wresized = 1;
|
|
|
|
hdrcnt = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Update the global `winlines' count of terminal rows.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
doresize(void)
|
|
|
|
{
|
|
|
|
struct winsize w;
|
2017-12-01 22:38:28 +00:00
|
|
|
int status;
|
2008-11-04 18:02:35 +00:00
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
status = ioctl(fileno(stdout), TIOCGWINSZ, &w);
|
|
|
|
if (status == -1 && errno == EINTR)
|
|
|
|
continue;
|
|
|
|
else if (status == -1)
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_err(1, "ioctl");
|
2008-11-04 18:02:35 +00:00
|
|
|
if (w.ws_row > 3)
|
|
|
|
winlines = w.ws_row - 3;
|
|
|
|
else
|
|
|
|
winlines = VMSTAT_DEFAULT_LINES;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Inhibit doresize() calls until we are rescheduled by SIGWINCH.
|
|
|
|
*/
|
|
|
|
wresized = 0;
|
|
|
|
}
|
|
|
|
|
2003-12-07 17:46:14 +00:00
|
|
|
static long
|
|
|
|
pct(long top, long bot)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
long ans;
|
|
|
|
|
|
|
|
if (bot == 0)
|
|
|
|
return(0);
|
|
|
|
ans = (quad_t)top * 100 / bot;
|
|
|
|
return (ans);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define PCT(top, bot) pct((long)(top), (long)(bot))
|
|
|
|
|
2003-12-07 17:46:14 +00:00
|
|
|
static void
|
|
|
|
dosum(void)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2001-12-11 22:59:36 +00:00
|
|
|
struct nchstats lnchstats;
|
2017-12-01 22:38:28 +00:00
|
|
|
size_t size;
|
1994-05-27 12:33:43 +00:00
|
|
|
long nchtotal;
|
|
|
|
|
2003-12-07 17:46:14 +00:00
|
|
|
fill_vmmeter(&sum);
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_open_container("summary-statistics");
|
|
|
|
xo_emit("{:context-switches/%9u} {N:cpu context switches}\n",
|
2017-12-01 22:38:28 +00:00
|
|
|
sum.v_swtch);
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_emit("{:interrupts/%9u} {N:device interrupts}\n",
|
2017-12-01 22:38:28 +00:00
|
|
|
sum.v_intr);
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_emit("{:software-interrupts/%9u} {N:software interrupts}\n",
|
2017-12-01 22:38:28 +00:00
|
|
|
sum.v_soft);
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_emit("{:traps/%9u} {N:traps}\n", sum.v_trap);
|
|
|
|
xo_emit("{:system-calls/%9u} {N:system calls}\n",
|
2017-12-01 22:38:28 +00:00
|
|
|
sum.v_syscall);
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_emit("{:kernel-threads/%9u} {N:kernel threads created}\n",
|
2017-12-01 22:38:28 +00:00
|
|
|
sum.v_kthreads);
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_emit("{:forks/%9u} {N: fork() calls}\n", sum.v_forks);
|
|
|
|
xo_emit("{:vforks/%9u} {N:vfork() calls}\n",
|
2017-12-01 22:38:28 +00:00
|
|
|
sum.v_vforks);
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_emit("{:rforks/%9u} {N:rfork() calls}\n",
|
2017-12-01 22:38:28 +00:00
|
|
|
sum.v_rforks);
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_emit("{:swap-ins/%9u} {N:swap pager pageins}\n",
|
2017-12-01 22:38:28 +00:00
|
|
|
sum.v_swapin);
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_emit("{:swap-in-pages/%9u} {N:swap pager pages paged in}\n",
|
2017-12-01 22:38:28 +00:00
|
|
|
sum.v_swappgsin);
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_emit("{:swap-outs/%9u} {N:swap pager pageouts}\n",
|
2017-12-01 22:38:28 +00:00
|
|
|
sum.v_swapout);
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_emit("{:swap-out-pages/%9u} {N:swap pager pages paged out}\n",
|
2017-12-01 22:38:28 +00:00
|
|
|
sum.v_swappgsout);
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_emit("{:vnode-page-ins/%9u} {N:vnode pager pageins}\n",
|
2017-12-01 22:38:28 +00:00
|
|
|
sum.v_vnodein);
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_emit("{:vnode-page-in-pages/%9u} {N:vnode pager pages paged in}\n",
|
2017-12-01 22:38:28 +00:00
|
|
|
sum.v_vnodepgsin);
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_emit("{:vnode-page-outs/%9u} {N:vnode pager pageouts}\n",
|
2017-12-01 22:38:28 +00:00
|
|
|
sum.v_vnodeout);
|
2017-11-11 14:02:21 +00:00
|
|
|
xo_emit("{:vnode-page-out-pages/%9u} {N:vnode pager pages paged out}\n",
|
2017-12-01 22:38:28 +00:00
|
|
|
sum.v_vnodepgsout);
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_emit("{:page-daemon-wakeups/%9u} {N:page daemon wakeups}\n",
|
2017-12-01 22:38:28 +00:00
|
|
|
sum.v_pdwakeups);
|
2017-12-14 15:40:03 +00:00
|
|
|
xo_emit("{:page-daemon-pages/%9u} {N:pages examined by the page "
|
2017-12-01 22:38:28 +00:00
|
|
|
"daemon}\n", sum.v_pdpages);
|
2017-12-14 15:40:03 +00:00
|
|
|
xo_emit("{:page-reclamation-shortfalls/%9u} {N:clean page reclamation "
|
2017-12-01 22:38:28 +00:00
|
|
|
"shortfalls}\n", sum.v_pdshortfalls);
|
2016-11-10 19:55:45 +00:00
|
|
|
xo_emit("{:reactivated/%9u} {N:pages reactivated by the page daemon}\n",
|
2017-12-01 22:38:28 +00:00
|
|
|
sum.v_reactivated);
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_emit("{:copy-on-write-faults/%9u} {N:copy-on-write faults}\n",
|
2017-12-01 22:38:28 +00:00
|
|
|
sum.v_cow_faults);
|
2017-12-14 15:40:03 +00:00
|
|
|
xo_emit("{:copy-on-write-optimized-faults/%9u} {N:copy-on-write "
|
2017-12-01 22:38:28 +00:00
|
|
|
"optimized faults}\n", sum.v_cow_optim);
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_emit("{:zero-fill-pages/%9u} {N:zero fill pages zeroed}\n",
|
2017-12-01 22:38:28 +00:00
|
|
|
sum.v_zfod);
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_emit("{:zero-fill-prezeroed/%9u} {N:zero fill pages prezeroed}\n",
|
2017-12-01 22:38:28 +00:00
|
|
|
sum.v_ozfod);
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_emit("{:intransit-blocking/%9u} {N:intransit blocking page faults}\n",
|
2017-12-01 22:38:28 +00:00
|
|
|
sum.v_intrans);
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_emit("{:total-faults/%9u} {N:total VM faults taken}\n",
|
2017-12-01 22:38:28 +00:00
|
|
|
sum.v_vm_faults);
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_emit("{:faults-requiring-io/%9u} {N:page faults requiring I\\/O}\n",
|
2017-12-01 22:38:28 +00:00
|
|
|
sum.v_io_faults);
|
2017-12-14 15:40:03 +00:00
|
|
|
xo_emit("{:faults-from-thread-creation/%9u} {N:pages affected by "
|
2017-12-01 22:38:28 +00:00
|
|
|
"kernel thread creation}\n", sum.v_kthreadpages);
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_emit("{:faults-from-fork/%9u} {N:pages affected by fork}()\n",
|
2017-12-01 22:38:28 +00:00
|
|
|
sum.v_forkpages);
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_emit("{:faults-from-vfork/%9u} {N:pages affected by vfork}()\n",
|
2017-12-01 22:38:28 +00:00
|
|
|
sum.v_vforkpages);
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_emit("{:pages-rfork/%9u} {N:pages affected by rfork}()\n",
|
2017-12-01 22:38:28 +00:00
|
|
|
sum.v_rforkpages);
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_emit("{:pages-freed/%9u} {N:pages freed}\n",
|
2017-12-01 22:38:28 +00:00
|
|
|
sum.v_tfree);
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_emit("{:pages-freed-by-daemon/%9u} {N:pages freed by daemon}\n",
|
2017-12-01 22:38:28 +00:00
|
|
|
sum.v_dfree);
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_emit("{:pages-freed-on-exit/%9u} {N:pages freed by exiting processes}\n",
|
2017-12-01 22:38:28 +00:00
|
|
|
sum.v_pfree);
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_emit("{:active-pages/%9u} {N:pages active}\n",
|
2017-12-01 22:38:28 +00:00
|
|
|
sum.v_active_count);
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_emit("{:inactive-pages/%9u} {N:pages inactive}\n",
|
2017-12-01 22:38:28 +00:00
|
|
|
sum.v_inactive_count);
|
2016-11-10 19:55:45 +00:00
|
|
|
xo_emit("{:laundry-pages/%9u} {N:pages in the laundry queue}\n",
|
2017-12-01 22:38:28 +00:00
|
|
|
sum.v_laundry_count);
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_emit("{:wired-pages/%9u} {N:pages wired down}\n",
|
2017-12-01 22:38:28 +00:00
|
|
|
sum.v_wire_count);
|
Provide separate accounting for user-wired pages.
Historically we have not distinguished between kernel wirings and user
wirings for accounting purposes. User wirings (via mlock(2)) were
subject to a global limit on the number of wired pages, so if large
swaths of physical memory were wired by the kernel, as happens with
the ZFS ARC among other things, the limit could be exceeded, causing
user wirings to fail.
The change adds a new counter, v_user_wire_count, which counts the
number of virtual pages wired by user processes via mlock(2) and
mlockall(2). Only user-wired pages are subject to the system-wide
limit which helps provide some safety against deadlocks. In
particular, while sources of kernel wirings typically support some
backpressure mechanism, there is no way to reclaim user-wired pages
shorting of killing the wiring process. The limit is exported as
vm.max_user_wired, renamed from vm.max_wired, and changed from u_int
to u_long.
The choice to count virtual user-wired pages rather than physical
pages was done for simplicity. There are mechanisms that can cause
user-wired mappings to be destroyed while maintaining a wiring of
the backing physical page; these make it difficult to accurately
track user wirings at the physical page layer.
The change also closes some holes which allowed user wirings to succeed
even when they would cause the system limit to be exceeded. For
instance, mmap() may now fail with ENOMEM in a process that has called
mlockall(MCL_FUTURE) if the new mapping would cause the user wiring
limit to be exceeded.
Note that bhyve -S is subject to the user wiring limit, which defaults
to 1/3 of physical RAM. Users that wish to exceed the limit must tune
vm.max_user_wired.
Reviewed by: kib, ngie (mlock() test changes)
Tested by: pho (earlier version)
MFC after: 45 days
Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D19908
2019-05-13 16:38:48 +00:00
|
|
|
xo_emit("{:virtual-user-wired-pages/%9lu} {N:virtual user pages wired "
|
|
|
|
"down}\n", sum.v_user_wire_count);
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_emit("{:free-pages/%9u} {N:pages free}\n",
|
2017-12-01 22:38:28 +00:00
|
|
|
sum.v_free_count);
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_emit("{:bytes-per-page/%9u} {N:bytes per page}\n", sum.v_page_size);
|
2003-12-07 17:46:14 +00:00
|
|
|
if (kd != NULL) {
|
|
|
|
kread(X_NCHSTATS, &lnchstats, sizeof(lnchstats));
|
|
|
|
} else {
|
2017-12-01 22:38:28 +00:00
|
|
|
size = sizeof(lnchstats);
|
2017-04-21 00:00:23 +00:00
|
|
|
mysysctl("vfs.cache.nchstats", &lnchstats, &size);
|
2003-12-07 17:46:14 +00:00
|
|
|
if (size != sizeof(lnchstats))
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_errx(1, "vfs.cache.nchstats size mismatch");
|
2003-12-07 17:46:14 +00:00
|
|
|
}
|
2001-12-11 22:59:36 +00:00
|
|
|
nchtotal = lnchstats.ncs_goodhits + lnchstats.ncs_neghits +
|
|
|
|
lnchstats.ncs_badhits + lnchstats.ncs_falsehits +
|
|
|
|
lnchstats.ncs_miss + lnchstats.ncs_long;
|
2015-11-21 23:04:12 +00:00
|
|
|
xo_emit("{:total-name-lookups/%9ld} {N:total name lookups}\n",
|
2017-12-01 22:38:28 +00:00
|
|
|
nchtotal);
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_emit("{P:/%9s} {N:cache hits} "
|
2017-12-01 22:38:28 +00:00
|
|
|
"({:positive-cache-hits/%ld}% pos + "
|
|
|
|
"{:negative-cache-hits/%ld}% {N:neg}) "
|
|
|
|
"system {:cache-hit-percent/%ld}% per-directory\n",
|
2001-12-11 22:59:36 +00:00
|
|
|
"", PCT(lnchstats.ncs_goodhits, nchtotal),
|
|
|
|
PCT(lnchstats.ncs_neghits, nchtotal),
|
|
|
|
PCT(lnchstats.ncs_pass2, nchtotal));
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_emit("{P:/%9s} {L:deletions} {:deletions/%ld}%, "
|
2017-12-01 22:38:28 +00:00
|
|
|
"{L:falsehits} {:false-hits/%ld}%, "
|
|
|
|
"{L:toolong} {:too-long/%ld}%\n", "",
|
2001-12-11 22:59:36 +00:00
|
|
|
PCT(lnchstats.ncs_badhits, nchtotal),
|
|
|
|
PCT(lnchstats.ncs_falsehits, nchtotal),
|
|
|
|
PCT(lnchstats.ncs_long, nchtotal));
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_close_container("summary-statistics");
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
2003-12-07 17:46:14 +00:00
|
|
|
static void
|
|
|
|
doforkst(void)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2017-12-01 22:38:28 +00:00
|
|
|
|
2003-12-07 17:46:14 +00:00
|
|
|
fill_vmmeter(&sum);
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_open_container("fork-statistics");
|
|
|
|
xo_emit("{:fork/%u} {N:forks}, {:fork-pages/%u} {N:pages}, "
|
2017-12-01 22:38:28 +00:00
|
|
|
"{L:average} {:fork-average/%.2f}\n",
|
2003-04-14 07:21:03 +00:00
|
|
|
sum.v_forks, sum.v_forkpages,
|
|
|
|
sum.v_forks == 0 ? 0.0 :
|
|
|
|
(double)sum.v_forkpages / sum.v_forks);
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_emit("{:vfork/%u} {N:vforks}, {:vfork-pages/%u} {N:pages}, "
|
2017-12-01 22:38:28 +00:00
|
|
|
"{L:average} {:vfork-average/%.2f}\n",
|
2003-04-14 07:21:03 +00:00
|
|
|
sum.v_vforks, sum.v_vforkpages,
|
|
|
|
sum.v_vforks == 0 ? 0.0 :
|
|
|
|
(double)sum.v_vforkpages / sum.v_vforks);
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_emit("{:rfork/%u} {N:rforks}, {:rfork-pages/%u} {N:pages}, "
|
2017-12-01 22:38:28 +00:00
|
|
|
"{L:average} {:rfork-average/%.2f}\n",
|
2003-04-14 07:21:03 +00:00
|
|
|
sum.v_rforks, sum.v_rforkpages,
|
|
|
|
sum.v_rforks == 0 ? 0.0 :
|
|
|
|
(double)sum.v_rforkpages / sum.v_rforks);
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_close_container("fork-statistics");
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
1998-09-15 08:16:45 +00:00
|
|
|
static void
|
2003-12-07 17:46:14 +00:00
|
|
|
devstats(void)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2017-12-01 22:38:28 +00:00
|
|
|
long double busy_seconds, transfers_per_second;
|
1994-05-27 12:33:43 +00:00
|
|
|
long tmp;
|
2017-12-01 22:38:28 +00:00
|
|
|
int di, dn, state;
|
2003-12-07 17:46:14 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
for (state = 0; state < CPUSTATES; ++state) {
|
1998-09-15 08:16:45 +00:00
|
|
|
tmp = cur.cp_time[state];
|
|
|
|
cur.cp_time[state] -= last.cp_time[state];
|
|
|
|
last.cp_time[state] = tmp;
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
1998-09-15 08:16:45 +00:00
|
|
|
|
Run a revision of the devstat interface:
Kernel:
Change statistics to use the *uptime() timescale (ie: relative to
boottime) rather than the UTC aligned timescale. This makes the
device statistics code oblivious to clock steps.
Change timestamps to bintime format, they are cheaper.
Remove the "busy_count", and replace it with two counter fields:
"start_count" and "end_count", which are updated in the down and
up paths respectively. This removes the locking constraint on
devstat.
Add a timestamp argument to devstat_start_transaction(), this will
normally be a timestamp set by the *_bio() function in bp->bio_t0.
Use this field to calculate duration of I/O operations.
Add two timestamp arguments to devstat_end_transaction(), one is
the current time, a NULL pointer means "take timestamp yourself",
the other is the timestamp of when this transaction started (see
above).
Change calculation of busy_time to operate on "the salami principle":
Only when we are idle, which we can determine by the start+end
counts being identical, do we update the "busy_from" field in the
down path. In the up path we accumulate the timeslice in busy_time
and update busy_from.
Change the byte_* and num_* fields into two arrays: bytes[] and
operations[].
Userland:
Change the misleading "busy_time" name to be called "snap_time" and
make the time long double since that is what most users need anyway,
fill it using clock_gettime(CLOCK_MONOTONIC) to put it on the same
timescale as the kernel fields.
Change devstat_compute_etime() to operate on struct bintime.
Remove the version 2 legacy interface: the change to bintime makes
compatibility far too expensive.
Fix a bug in systat's "vm" page where boot relative busy times would
be bogus.
Bump __FreeBSD_version to 500107
Review & Collaboration by: ken
2003-03-15 21:59:06 +00:00
|
|
|
busy_seconds = cur.snap_time - last.snap_time;
|
1998-09-15 08:16:45 +00:00
|
|
|
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_open_list("device");
|
1998-09-15 08:16:45 +00:00
|
|
|
for (dn = 0; dn < num_devices; dn++) {
|
2017-12-01 22:38:28 +00:00
|
|
|
if (dev_select[dn].selected == 0 ||
|
|
|
|
dev_select[dn].selected > maxshowdevs)
|
1994-05-27 12:33:43 +00:00
|
|
|
continue;
|
1998-09-15 08:16:45 +00:00
|
|
|
|
|
|
|
di = dev_select[dn].position;
|
|
|
|
|
2001-08-11 19:41:56 +00:00
|
|
|
if (devstat_compute_statistics(&cur.dinfo->devices[di],
|
|
|
|
&last.dinfo->devices[di], busy_seconds,
|
|
|
|
DSM_TRANSFERS_PER_SECOND, &transfers_per_second,
|
|
|
|
DSM_NONE) != 0)
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_errx(1, "%s", devstat_errbuf);
|
|
|
|
|
|
|
|
xo_open_instance("device");
|
|
|
|
xo_emit("{ekq:name/%c%c%d}{:transfers/%3.0Lf} ",
|
2017-12-01 22:38:28 +00:00
|
|
|
dev_select[dn].device_name[0],
|
|
|
|
dev_select[dn].device_name[1],
|
|
|
|
dev_select[dn].unit_number,
|
|
|
|
transfers_per_second);
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_close_instance("device");
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_close_list("device");
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
2007-12-13 02:36:11 +00:00
|
|
|
static void
|
2017-12-01 22:38:28 +00:00
|
|
|
percent(const char *name, double pctv, int *over)
|
2007-12-13 02:36:11 +00:00
|
|
|
{
|
2017-12-01 22:38:28 +00:00
|
|
|
int l;
|
2007-12-13 02:36:11 +00:00
|
|
|
char buf[10];
|
2015-11-20 05:15:34 +00:00
|
|
|
char fmt[128];
|
2007-12-13 02:36:11 +00:00
|
|
|
|
2015-11-20 05:15:34 +00:00
|
|
|
snprintf(fmt, sizeof(fmt), " {:%s/%%*s}", name);
|
2017-12-01 22:38:28 +00:00
|
|
|
l = snprintf(buf, sizeof(buf), "%.0f", pctv);
|
2007-12-13 02:36:11 +00:00
|
|
|
if (l == 1 && *over) {
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_emit(fmt, 1, buf);
|
2007-12-13 02:36:11 +00:00
|
|
|
(*over)--;
|
|
|
|
} else
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_emit(fmt, 2, buf);
|
2007-12-13 02:36:11 +00:00
|
|
|
if (l > 2)
|
|
|
|
(*over)++;
|
|
|
|
}
|
|
|
|
|
2003-12-07 17:46:14 +00:00
|
|
|
static void
|
|
|
|
cpustats(void)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2001-12-11 22:59:36 +00:00
|
|
|
double lpct, total;
|
2017-12-01 22:38:28 +00:00
|
|
|
int state, over;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
total = 0;
|
|
|
|
for (state = 0; state < CPUSTATES; ++state)
|
1998-09-15 08:16:45 +00:00
|
|
|
total += cur.cp_time[state];
|
2018-06-13 08:52:04 +00:00
|
|
|
if (total > 0)
|
2001-12-11 22:59:36 +00:00
|
|
|
lpct = 100.0 / total;
|
1994-05-27 12:33:43 +00:00
|
|
|
else
|
2001-12-11 22:59:36 +00:00
|
|
|
lpct = 0.0;
|
2007-12-13 02:36:11 +00:00
|
|
|
over = 0;
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_open_container("cpu-statistics");
|
2017-12-01 22:38:28 +00:00
|
|
|
percent("user", (cur.cp_time[CP_USER] + cur.cp_time[CP_NICE]) * lpct,
|
|
|
|
&over);
|
|
|
|
percent("system", (cur.cp_time[CP_SYS] + cur.cp_time[CP_INTR]) * lpct,
|
|
|
|
&over);
|
2015-11-20 05:15:34 +00:00
|
|
|
percent("idle", cur.cp_time[CP_IDLE] * lpct, &over);
|
|
|
|
xo_close_container("cpu-statistics");
|
2007-12-13 02:36:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-12-01 22:38:28 +00:00
|
|
|
pcpustats(u_long cpumask, int maxid)
|
2007-12-13 02:36:11 +00:00
|
|
|
{
|
|
|
|
double lpct, total;
|
|
|
|
long tmp;
|
2017-12-01 22:38:28 +00:00
|
|
|
int i, over, state;
|
2007-12-13 02:36:11 +00:00
|
|
|
|
|
|
|
/* devstats does this for cp_time */
|
|
|
|
for (i = 0; i <= maxid; i++) {
|
2008-01-18 22:09:44 +00:00
|
|
|
if ((cpumask & (1ul << i)) == 0)
|
2007-12-13 02:36:11 +00:00
|
|
|
continue;
|
|
|
|
for (state = 0; state < CPUSTATES; ++state) {
|
|
|
|
tmp = cur_cp_times[i * CPUSTATES + state];
|
2014-10-24 04:01:14 +00:00
|
|
|
cur_cp_times[i * CPUSTATES + state] -= last_cp_times[i *
|
|
|
|
CPUSTATES + state];
|
2007-12-13 02:36:11 +00:00
|
|
|
last_cp_times[i * CPUSTATES + state] = tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
over = 0;
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_open_list("cpu");
|
2007-12-13 02:36:11 +00:00
|
|
|
for (i = 0; i <= maxid; i++) {
|
2008-01-18 22:09:44 +00:00
|
|
|
if ((cpumask & (1ul << i)) == 0)
|
2007-12-13 02:36:11 +00:00
|
|
|
continue;
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_open_instance("cpu");
|
|
|
|
xo_emit("{ke:name/%d}", i);
|
2007-12-13 02:36:11 +00:00
|
|
|
total = 0;
|
|
|
|
for (state = 0; state < CPUSTATES; ++state)
|
|
|
|
total += cur_cp_times[i * CPUSTATES + state];
|
|
|
|
if (total)
|
|
|
|
lpct = 100.0 / total;
|
|
|
|
else
|
|
|
|
lpct = 0.0;
|
2015-11-20 05:15:34 +00:00
|
|
|
percent("user", (cur_cp_times[i * CPUSTATES + CP_USER] +
|
2017-12-01 22:38:28 +00:00
|
|
|
cur_cp_times[i * CPUSTATES + CP_NICE]) * lpct, &over);
|
2015-11-20 05:15:34 +00:00
|
|
|
percent("system", (cur_cp_times[i * CPUSTATES + CP_SYS] +
|
2017-12-01 22:38:28 +00:00
|
|
|
cur_cp_times[i * CPUSTATES + CP_INTR]) * lpct, &over);
|
2015-11-20 05:15:34 +00:00
|
|
|
percent("idle", cur_cp_times[i * CPUSTATES + CP_IDLE] * lpct,
|
2017-12-01 22:38:28 +00:00
|
|
|
&over);
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_close_instance("cpu");
|
2007-12-13 02:36:11 +00:00
|
|
|
}
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_close_list("cpu");
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
2015-01-23 16:15:55 +00:00
|
|
|
static unsigned int
|
|
|
|
read_intrcnts(unsigned long **intrcnts)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2015-01-23 16:15:55 +00:00
|
|
|
size_t intrcntlen;
|
Dynamically allocate IRQ ranges on x86.
Previously, x86 used static ranges of IRQ values for different types
of I/O interrupts. Interrupt pins on I/O APICs and 8259A PICs used
IRQ values from 0 to 254. MSI interrupts used a compile-time-defined
range starting at 256, and Xen event channels used a
compile-time-defined range after MSI. Some recent systems have more
than 255 I/O APIC interrupt pins which resulted in those IRQ values
overflowing into the MSI range triggering an assertion failure.
Replace statically assigned ranges with dynamic ranges. Do a single
pass computing the sizes of the IRQ ranges (PICs, MSI, Xen) to
determine the total number of IRQs required. Allocate the interrupt
source and interrupt count arrays dynamically once this pass has
completed. To minimize runtime complexity these arrays are only sized
once during bootup. The PIC range is determined by the PICs present
in the system. The MSI and Xen ranges continue to use a fixed size,
though this does make it possible to turn the MSI range size into a
tunable in the future.
As a result, various places are updated to use dynamic limits instead
of constants. In addition, the vmstat(8) utility has been taught to
understand that some kernels may treat 'intrcnt' and 'intrnames' as
pointers rather than arrays when extracting interrupt stats from a
crashdump. This is determined by the presence (vs absence) of a
global 'nintrcnt' symbol.
This change reverts r189404 which worked around a buggy BIOS which
enumerated an I/O APIC twice (using the same memory mapped address for
both entries but using an IRQ base of 256 for one entry and a valid
IRQ base for the second entry). Making the "base" of MSI IRQ values
dynamic avoids the panic that r189404 worked around, and there may now
be valid I/O APICs with an IRQ base above 256 which this workaround
would incorrectly skip.
If in the future the issue reported in PR 130483 reoccurs, we will
have to add a pass over the I/O APIC entries in the MADT to detect
duplicates using the memory mapped address and use some strategy to
choose the "correct" one.
While here, reserve room in intrcnts for the Hyper-V counters.
PR: 229429, 130483
Reviewed by: kib, royger, cem
Tested by: royger (Xen), kib (DMAR)
Approved by: re (gjb)
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D16861
2018-08-28 21:09:19 +00:00
|
|
|
uintptr_t kaddr;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2003-12-07 17:46:14 +00:00
|
|
|
if (kd != NULL) {
|
2011-07-18 19:42:18 +00:00
|
|
|
kread(X_SINTRCNT, &intrcntlen, sizeof(intrcntlen));
|
2015-01-23 16:15:55 +00:00
|
|
|
if ((*intrcnts = malloc(intrcntlen)) == NULL)
|
2003-12-07 17:46:14 +00:00
|
|
|
err(1, "malloc()");
|
Dynamically allocate IRQ ranges on x86.
Previously, x86 used static ranges of IRQ values for different types
of I/O interrupts. Interrupt pins on I/O APICs and 8259A PICs used
IRQ values from 0 to 254. MSI interrupts used a compile-time-defined
range starting at 256, and Xen event channels used a
compile-time-defined range after MSI. Some recent systems have more
than 255 I/O APIC interrupt pins which resulted in those IRQ values
overflowing into the MSI range triggering an assertion failure.
Replace statically assigned ranges with dynamic ranges. Do a single
pass computing the sizes of the IRQ ranges (PICs, MSI, Xen) to
determine the total number of IRQs required. Allocate the interrupt
source and interrupt count arrays dynamically once this pass has
completed. To minimize runtime complexity these arrays are only sized
once during bootup. The PIC range is determined by the PICs present
in the system. The MSI and Xen ranges continue to use a fixed size,
though this does make it possible to turn the MSI range size into a
tunable in the future.
As a result, various places are updated to use dynamic limits instead
of constants. In addition, the vmstat(8) utility has been taught to
understand that some kernels may treat 'intrcnt' and 'intrnames' as
pointers rather than arrays when extracting interrupt stats from a
crashdump. This is determined by the presence (vs absence) of a
global 'nintrcnt' symbol.
This change reverts r189404 which worked around a buggy BIOS which
enumerated an I/O APIC twice (using the same memory mapped address for
both entries but using an IRQ base of 256 for one entry and a valid
IRQ base for the second entry). Making the "base" of MSI IRQ values
dynamic avoids the panic that r189404 worked around, and there may now
be valid I/O APICs with an IRQ base above 256 which this workaround
would incorrectly skip.
If in the future the issue reported in PR 130483 reoccurs, we will
have to add a pass over the I/O APIC entries in the MADT to detect
duplicates using the memory mapped address and use some strategy to
choose the "correct" one.
While here, reserve room in intrcnts for the Hyper-V counters.
PR: 229429, 130483
Reviewed by: kib, royger, cem
Tested by: royger (Xen), kib (DMAR)
Approved by: re (gjb)
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D16861
2018-08-28 21:09:19 +00:00
|
|
|
if (namelist[X_NINTRCNT].n_type == 0)
|
|
|
|
kread(X_INTRCNT, *intrcnts, intrcntlen);
|
|
|
|
else {
|
|
|
|
kread(X_INTRCNT, &kaddr, sizeof(kaddr));
|
|
|
|
kreadptr(kaddr, *intrcnts, intrcntlen);
|
|
|
|
}
|
2003-12-07 17:46:14 +00:00
|
|
|
} else {
|
2015-01-23 16:15:55 +00:00
|
|
|
for (*intrcnts = NULL, intrcntlen = 1024; ; intrcntlen *= 2) {
|
|
|
|
*intrcnts = reallocf(*intrcnts, intrcntlen);
|
|
|
|
if (*intrcnts == NULL)
|
2003-12-11 07:46:08 +00:00
|
|
|
err(1, "reallocf()");
|
2017-04-21 00:00:23 +00:00
|
|
|
if (mysysctl("hw.intrcnt", *intrcnts, &intrcntlen) == 0)
|
2003-12-11 07:46:08 +00:00
|
|
|
break;
|
|
|
|
}
|
2015-01-23 16:15:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (intrcntlen / sizeof(unsigned long));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
print_intrcnts(unsigned long *intrcnts, unsigned long *old_intrcnts,
|
2017-12-01 22:38:28 +00:00
|
|
|
char *intrnames, unsigned int nintr, size_t istrnamlen, long long period_ms)
|
2015-01-23 16:15:55 +00:00
|
|
|
{
|
|
|
|
uint64_t inttotal, old_inttotal, total_count, total_rate;
|
2017-12-01 22:38:28 +00:00
|
|
|
unsigned long count, rate;
|
2015-01-23 16:15:55 +00:00
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
inttotal = 0;
|
|
|
|
old_inttotal = 0;
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_open_list("interrupt");
|
2022-09-21 02:18:23 +00:00
|
|
|
for (i = 0; i < nintr; i++) {
|
|
|
|
if (intrnames[0] != '\0' && (*intrcnts != 0 || aflag)) {
|
|
|
|
count = *intrcnts - *old_intrcnts;
|
2018-02-08 05:18:30 +00:00
|
|
|
rate = ((uint64_t)count * 1000 + period_ms / 2) / period_ms;
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_open_instance("interrupt");
|
2015-12-01 16:31:07 +00:00
|
|
|
xo_emit("{d:name/%-*s}{ket:name/%s} "
|
|
|
|
"{:total/%20lu} {:rate/%10lu}\n",
|
2022-09-21 02:18:23 +00:00
|
|
|
(int)istrnamlen, intrnames, intrnames, count, rate);
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_close_instance("interrupt");
|
2015-01-23 16:15:55 +00:00
|
|
|
}
|
2022-09-21 02:18:23 +00:00
|
|
|
intrnames += strlen(intrnames) + 1;
|
|
|
|
inttotal += *intrcnts++;
|
|
|
|
old_inttotal += *old_intrcnts++;
|
2015-01-23 16:15:55 +00:00
|
|
|
}
|
|
|
|
total_count = inttotal - old_inttotal;
|
2015-01-23 16:21:31 +00:00
|
|
|
total_rate = (total_count * 1000 + period_ms / 2) / period_ms;
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_close_list("interrupt");
|
2017-12-01 22:38:28 +00:00
|
|
|
xo_emit("{L:/%-*s} {:total-interrupts/%20ju} "
|
|
|
|
"{:total-rate/%10ju}\n", (int)istrnamlen,
|
|
|
|
"Total", (uintmax_t)total_count, (uintmax_t)total_rate);
|
2015-01-23 16:15:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
dointr(unsigned int interval, int reps)
|
|
|
|
{
|
2017-12-01 22:38:28 +00:00
|
|
|
unsigned long *intrcnts, *old_intrcnts;
|
|
|
|
char *intrname, *intrnames;
|
|
|
|
long long period_ms, old_uptime, uptime;
|
2015-01-23 16:15:55 +00:00
|
|
|
size_t clen, inamlen, istrnamlen;
|
Dynamically allocate IRQ ranges on x86.
Previously, x86 used static ranges of IRQ values for different types
of I/O interrupts. Interrupt pins on I/O APICs and 8259A PICs used
IRQ values from 0 to 254. MSI interrupts used a compile-time-defined
range starting at 256, and Xen event channels used a
compile-time-defined range after MSI. Some recent systems have more
than 255 I/O APIC interrupt pins which resulted in those IRQ values
overflowing into the MSI range triggering an assertion failure.
Replace statically assigned ranges with dynamic ranges. Do a single
pass computing the sizes of the IRQ ranges (PICs, MSI, Xen) to
determine the total number of IRQs required. Allocate the interrupt
source and interrupt count arrays dynamically once this pass has
completed. To minimize runtime complexity these arrays are only sized
once during bootup. The PIC range is determined by the PICs present
in the system. The MSI and Xen ranges continue to use a fixed size,
though this does make it possible to turn the MSI range size into a
tunable in the future.
As a result, various places are updated to use dynamic limits instead
of constants. In addition, the vmstat(8) utility has been taught to
understand that some kernels may treat 'intrcnt' and 'intrnames' as
pointers rather than arrays when extracting interrupt stats from a
crashdump. This is determined by the presence (vs absence) of a
global 'nintrcnt' symbol.
This change reverts r189404 which worked around a buggy BIOS which
enumerated an I/O APIC twice (using the same memory mapped address for
both entries but using an IRQ base of 256 for one entry and a valid
IRQ base for the second entry). Making the "base" of MSI IRQ values
dynamic avoids the panic that r189404 worked around, and there may now
be valid I/O APICs with an IRQ base above 256 which this workaround
would incorrectly skip.
If in the future the issue reported in PR 130483 reoccurs, we will
have to add a pass over the I/O APIC entries in the MADT to detect
duplicates using the memory mapped address and use some strategy to
choose the "correct" one.
While here, reserve room in intrcnts for the Hyper-V counters.
PR: 229429, 130483
Reviewed by: kib, royger, cem
Tested by: royger (Xen), kib (DMAR)
Approved by: re (gjb)
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D16861
2018-08-28 21:09:19 +00:00
|
|
|
uintptr_t kaddr;
|
2017-12-01 22:38:28 +00:00
|
|
|
unsigned int nintr;
|
2015-01-23 16:15:55 +00:00
|
|
|
|
2017-12-01 22:38:28 +00:00
|
|
|
old_intrcnts = NULL;
|
2015-01-23 16:15:55 +00:00
|
|
|
uptime = getuptime();
|
|
|
|
|
|
|
|
/* Get the names of each interrupt source */
|
|
|
|
if (kd != NULL) {
|
|
|
|
kread(X_SINTRNAMES, &inamlen, sizeof(inamlen));
|
|
|
|
if ((intrnames = malloc(inamlen)) == NULL)
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_err(1, "malloc()");
|
Dynamically allocate IRQ ranges on x86.
Previously, x86 used static ranges of IRQ values for different types
of I/O interrupts. Interrupt pins on I/O APICs and 8259A PICs used
IRQ values from 0 to 254. MSI interrupts used a compile-time-defined
range starting at 256, and Xen event channels used a
compile-time-defined range after MSI. Some recent systems have more
than 255 I/O APIC interrupt pins which resulted in those IRQ values
overflowing into the MSI range triggering an assertion failure.
Replace statically assigned ranges with dynamic ranges. Do a single
pass computing the sizes of the IRQ ranges (PICs, MSI, Xen) to
determine the total number of IRQs required. Allocate the interrupt
source and interrupt count arrays dynamically once this pass has
completed. To minimize runtime complexity these arrays are only sized
once during bootup. The PIC range is determined by the PICs present
in the system. The MSI and Xen ranges continue to use a fixed size,
though this does make it possible to turn the MSI range size into a
tunable in the future.
As a result, various places are updated to use dynamic limits instead
of constants. In addition, the vmstat(8) utility has been taught to
understand that some kernels may treat 'intrcnt' and 'intrnames' as
pointers rather than arrays when extracting interrupt stats from a
crashdump. This is determined by the presence (vs absence) of a
global 'nintrcnt' symbol.
This change reverts r189404 which worked around a buggy BIOS which
enumerated an I/O APIC twice (using the same memory mapped address for
both entries but using an IRQ base of 256 for one entry and a valid
IRQ base for the second entry). Making the "base" of MSI IRQ values
dynamic avoids the panic that r189404 worked around, and there may now
be valid I/O APICs with an IRQ base above 256 which this workaround
would incorrectly skip.
If in the future the issue reported in PR 130483 reoccurs, we will
have to add a pass over the I/O APIC entries in the MADT to detect
duplicates using the memory mapped address and use some strategy to
choose the "correct" one.
While here, reserve room in intrcnts for the Hyper-V counters.
PR: 229429, 130483
Reviewed by: kib, royger, cem
Tested by: royger (Xen), kib (DMAR)
Approved by: re (gjb)
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D16861
2018-08-28 21:09:19 +00:00
|
|
|
if (namelist[X_NINTRCNT].n_type == 0)
|
|
|
|
kread(X_INTRNAMES, intrnames, inamlen);
|
|
|
|
else {
|
|
|
|
kread(X_INTRNAMES, &kaddr, sizeof(kaddr));
|
|
|
|
kreadptr(kaddr, intrnames, inamlen);
|
|
|
|
}
|
2015-01-23 16:15:55 +00:00
|
|
|
} else {
|
|
|
|
for (intrnames = NULL, inamlen = 1024; ; inamlen *= 2) {
|
|
|
|
if ((intrnames = reallocf(intrnames, inamlen)) == NULL)
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_err(1, "reallocf()");
|
2017-04-21 00:00:23 +00:00
|
|
|
if (mysysctl("hw.intrnames", intrnames, &inamlen) == 0)
|
2003-12-07 17:46:14 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-01-23 16:15:55 +00:00
|
|
|
|
|
|
|
/* Determine the length of the longest interrupt name */
|
|
|
|
intrname = intrnames;
|
2003-11-09 20:39:56 +00:00
|
|
|
istrnamlen = strlen("interrupt");
|
2015-01-23 16:15:55 +00:00
|
|
|
while(*intrname != '\0') {
|
|
|
|
clen = strlen(intrname);
|
2003-10-28 05:02:03 +00:00
|
|
|
if (clen > istrnamlen)
|
|
|
|
istrnamlen = clen;
|
2015-01-23 16:15:55 +00:00
|
|
|
intrname += strlen(intrname) + 1;
|
2003-10-28 05:02:03 +00:00
|
|
|
}
|
2015-12-01 16:31:07 +00:00
|
|
|
xo_emit("{T:/%-*s} {T:/%20s} {T:/%10s}\n",
|
2017-12-01 22:38:28 +00:00
|
|
|
(int)istrnamlen, "interrupt", "total", "rate");
|
2015-01-23 16:15:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Loop reps times printing differential interrupt counts. If reps is
|
|
|
|
* zero, then run just once, printing total counts
|
|
|
|
*/
|
2015-12-01 16:31:07 +00:00
|
|
|
xo_open_container("interrupt-statistics");
|
|
|
|
|
2015-01-23 16:21:31 +00:00
|
|
|
period_ms = uptime / 1000000;
|
2015-01-23 16:15:55 +00:00
|
|
|
while(1) {
|
|
|
|
nintr = read_intrcnts(&intrcnts);
|
|
|
|
/*
|
|
|
|
* Initialize old_intrcnts to 0 for the first pass, so
|
|
|
|
* print_intrcnts will print total interrupts since boot
|
|
|
|
*/
|
|
|
|
if (old_intrcnts == NULL) {
|
|
|
|
old_intrcnts = calloc(nintr, sizeof(unsigned long));
|
|
|
|
if (old_intrcnts == NULL)
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_err(1, "calloc()");
|
2015-01-23 16:15:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
print_intrcnts(intrcnts, old_intrcnts, intrnames, nintr,
|
2015-01-23 16:21:31 +00:00
|
|
|
istrnamlen, period_ms);
|
2015-12-01 16:31:07 +00:00
|
|
|
xo_flush();
|
2015-01-23 16:15:55 +00:00
|
|
|
|
|
|
|
free(old_intrcnts);
|
|
|
|
old_intrcnts = intrcnts;
|
|
|
|
if (reps >= 0 && --reps <= 0)
|
|
|
|
break;
|
|
|
|
usleep(interval * 1000);
|
2015-01-23 16:21:31 +00:00
|
|
|
old_uptime = uptime;
|
|
|
|
uptime = getuptime();
|
|
|
|
period_ms = (uptime - old_uptime) / 1000000;
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
2015-12-01 16:31:07 +00:00
|
|
|
|
|
|
|
xo_close_container("interrupt-statistics");
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
2005-07-25 22:35:10 +00:00
|
|
|
static void
|
|
|
|
domemstat_malloc(void)
|
|
|
|
{
|
|
|
|
struct memory_type_list *mtlp;
|
|
|
|
struct memory_type *mtp;
|
2020-11-02 17:38:08 +00:00
|
|
|
size_t i, zones;
|
|
|
|
int error, first;
|
2005-07-25 22:35:10 +00:00
|
|
|
|
|
|
|
mtlp = memstat_mtl_alloc();
|
|
|
|
if (mtlp == NULL) {
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_warn("memstat_mtl_alloc");
|
2005-07-25 22:35:10 +00:00
|
|
|
return;
|
|
|
|
}
|
2005-08-06 13:56:21 +00:00
|
|
|
if (kd == NULL) {
|
|
|
|
if (memstat_sysctl_malloc(mtlp, 0) < 0) {
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_warnx("memstat_sysctl_malloc: %s",
|
2005-08-06 13:56:21 +00:00
|
|
|
memstat_strerror(memstat_mtl_geterror(mtlp)));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (memstat_kvm_malloc(mtlp, kd) < 0) {
|
|
|
|
error = memstat_mtl_geterror(mtlp);
|
|
|
|
if (error == MEMSTAT_ERROR_KVM)
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_warnx("memstat_kvm_malloc: %s",
|
2005-08-06 13:56:21 +00:00
|
|
|
kvm_geterr(kd));
|
|
|
|
else
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_warnx("memstat_kvm_malloc: %s",
|
2005-08-06 13:56:21 +00:00
|
|
|
memstat_strerror(error));
|
|
|
|
}
|
2005-07-25 22:35:10 +00:00
|
|
|
}
|
2015-12-01 16:31:07 +00:00
|
|
|
xo_open_container("malloc-statistics");
|
2020-11-09 23:00:29 +00:00
|
|
|
xo_emit("{T:/%13s} {T:/%5s} {T:/%6s} {T:/%8s} {T:Size(s)}\n",
|
|
|
|
"Type", "InUse", "MemUse", "Requests");
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_open_list("memory");
|
2020-11-02 17:38:08 +00:00
|
|
|
zones = memstat_malloc_zone_get_count();
|
2005-07-25 22:35:10 +00:00
|
|
|
for (mtp = memstat_mtl_first(mtlp); mtp != NULL;
|
|
|
|
mtp = memstat_mtl_next(mtp)) {
|
|
|
|
if (memstat_get_numallocs(mtp) == 0 &&
|
|
|
|
memstat_get_count(mtp) == 0)
|
|
|
|
continue;
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_open_instance("memory");
|
2017-12-01 22:38:28 +00:00
|
|
|
xo_emit("{k:type/%13s/%s} {:in-use/%5ju} "
|
2020-11-09 23:00:29 +00:00
|
|
|
"{:memory-use/%5ju}{U:K} {:requests/%8ju} ",
|
2017-12-01 22:38:28 +00:00
|
|
|
memstat_get_name(mtp), (uintmax_t)memstat_get_count(mtp),
|
2020-11-09 23:00:29 +00:00
|
|
|
((uintmax_t)memstat_get_bytes(mtp) + 1023) / 1024,
|
2017-12-01 22:38:28 +00:00
|
|
|
(uintmax_t)memstat_get_numallocs(mtp));
|
2005-07-25 22:35:10 +00:00
|
|
|
first = 1;
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_open_list("size");
|
2020-11-02 17:38:08 +00:00
|
|
|
for (i = 0; i < zones; i++) {
|
|
|
|
if (memstat_malloc_zone_used(mtp, i)) {
|
2005-07-25 22:35:10 +00:00
|
|
|
if (!first)
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_emit(",");
|
2020-11-02 17:38:08 +00:00
|
|
|
xo_emit("{l:size/%d}", memstat_malloc_zone_get_size(i));
|
2005-07-25 22:35:10 +00:00
|
|
|
first = 0;
|
|
|
|
}
|
|
|
|
}
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_close_list("size");
|
|
|
|
xo_close_instance("memory");
|
|
|
|
xo_emit("\n");
|
2005-07-25 22:35:10 +00:00
|
|
|
}
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_close_list("memory");
|
2015-12-01 16:31:07 +00:00
|
|
|
xo_close_container("malloc-statistics");
|
2005-07-25 22:35:10 +00:00
|
|
|
memstat_mtl_free(mtlp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
domemstat_zone(void)
|
|
|
|
{
|
|
|
|
struct memory_type_list *mtlp;
|
|
|
|
struct memory_type *mtp;
|
2005-08-01 21:33:17 +00:00
|
|
|
int error;
|
2017-12-01 22:38:28 +00:00
|
|
|
char name[MEMTYPE_MAXNAME + 1];
|
2005-07-25 22:35:10 +00:00
|
|
|
|
|
|
|
mtlp = memstat_mtl_alloc();
|
|
|
|
if (mtlp == NULL) {
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_warn("memstat_mtl_alloc");
|
2005-07-25 22:35:10 +00:00
|
|
|
return;
|
|
|
|
}
|
2005-08-01 21:33:17 +00:00
|
|
|
if (kd == NULL) {
|
|
|
|
if (memstat_sysctl_uma(mtlp, 0) < 0) {
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_warnx("memstat_sysctl_uma: %s",
|
2005-08-01 21:33:17 +00:00
|
|
|
memstat_strerror(memstat_mtl_geterror(mtlp)));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (memstat_kvm_uma(mtlp, kd) < 0) {
|
|
|
|
error = memstat_mtl_geterror(mtlp);
|
|
|
|
if (error == MEMSTAT_ERROR_KVM)
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_warnx("memstat_kvm_uma: %s",
|
2005-08-01 21:33:17 +00:00
|
|
|
kvm_geterr(kd));
|
|
|
|
else
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_warnx("memstat_kvm_uma: %s",
|
2005-08-01 21:33:17 +00:00
|
|
|
memstat_strerror(error));
|
|
|
|
}
|
2005-07-25 22:35:10 +00:00
|
|
|
}
|
2015-12-01 16:31:07 +00:00
|
|
|
xo_open_container("memory-zone-statistics");
|
2019-08-06 21:50:34 +00:00
|
|
|
xo_emit("{T:/%-20s} {T:/%6s} {T:/%6s} {T:/%8s} {T:/%8s} {T:/%8s} {T:/%8s}"
|
2020-11-09 00:05:45 +00:00
|
|
|
"{T:/%4s} {T:/%4s}\n", "ITEM", "SIZE",
|
2019-08-06 21:50:34 +00:00
|
|
|
"LIMIT", "USED", "FREE", "REQ", "FAIL", "SLEEP", "XDOMAIN");
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_open_list("zone");
|
2005-07-25 22:35:10 +00:00
|
|
|
for (mtp = memstat_mtl_first(mtlp); mtp != NULL;
|
|
|
|
mtp = memstat_mtl_next(mtp)) {
|
|
|
|
strlcpy(name, memstat_get_name(mtp), MEMTYPE_MAXNAME);
|
|
|
|
strcat(name, ":");
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_open_instance("zone");
|
2017-12-01 22:38:28 +00:00
|
|
|
xo_emit("{d:name/%-20s}{ke:name/%s} {:size/%6ju}, "
|
|
|
|
"{:limit/%6ju},{:used/%8ju},"
|
|
|
|
"{:free/%8ju},{:requests/%8ju},"
|
2019-08-06 21:50:34 +00:00
|
|
|
"{:fail/%4ju},{:sleep/%4ju},{:xdomain/%4ju}\n", name,
|
2017-12-01 22:38:28 +00:00
|
|
|
memstat_get_name(mtp),
|
|
|
|
(uintmax_t)memstat_get_size(mtp),
|
|
|
|
(uintmax_t)memstat_get_countlimit(mtp),
|
|
|
|
(uintmax_t)memstat_get_count(mtp),
|
|
|
|
(uintmax_t)memstat_get_free(mtp),
|
|
|
|
(uintmax_t)memstat_get_numallocs(mtp),
|
|
|
|
(uintmax_t)memstat_get_failures(mtp),
|
2019-08-06 21:50:34 +00:00
|
|
|
(uintmax_t)memstat_get_sleeps(mtp),
|
|
|
|
(uintmax_t)memstat_get_xdomain(mtp));
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_close_instance("zone");
|
2005-07-25 22:35:10 +00:00
|
|
|
}
|
|
|
|
memstat_mtl_free(mtlp);
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_close_list("zone");
|
2015-12-01 16:31:07 +00:00
|
|
|
xo_close_container("memory-zone-statistics");
|
2005-07-25 22:35:10 +00:00
|
|
|
}
|
|
|
|
|
2015-05-27 18:11:05 +00:00
|
|
|
static void
|
|
|
|
display_object(struct kinfo_vmobject *kvo)
|
|
|
|
{
|
|
|
|
const char *str;
|
|
|
|
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_open_instance("object");
|
2017-11-23 19:10:09 +00:00
|
|
|
xo_emit("{:resident/%5ju} ", (uintmax_t)kvo->kvo_resident);
|
|
|
|
xo_emit("{:active/%5ju} ", (uintmax_t)kvo->kvo_active);
|
|
|
|
xo_emit("{:inactive/%5ju} ", (uintmax_t)kvo->kvo_inactive);
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_emit("{:refcount/%3d} ", kvo->kvo_ref_count);
|
|
|
|
xo_emit("{:shadowcount/%3d} ", kvo->kvo_shadow_count);
|
2021-04-11 09:00:00 +00:00
|
|
|
|
|
|
|
#define MEMATTR_STR(type, val) \
|
|
|
|
if (kvo->kvo_memattr == (type)) { \
|
|
|
|
str = (val); \
|
|
|
|
} else
|
2015-05-27 18:11:05 +00:00
|
|
|
#ifdef VM_MEMATTR_UNCACHEABLE
|
2021-04-11 09:00:00 +00:00
|
|
|
MEMATTR_STR(VM_MEMATTR_UNCACHEABLE, "UC")
|
2015-05-27 18:11:05 +00:00
|
|
|
#endif
|
|
|
|
#ifdef VM_MEMATTR_WRITE_COMBINING
|
2021-04-11 09:00:00 +00:00
|
|
|
MEMATTR_STR(VM_MEMATTR_WRITE_COMBINING, "WC")
|
2015-05-27 18:11:05 +00:00
|
|
|
#endif
|
|
|
|
#ifdef VM_MEMATTR_WRITE_THROUGH
|
2021-04-11 09:00:00 +00:00
|
|
|
MEMATTR_STR(VM_MEMATTR_WRITE_THROUGH, "WT")
|
2015-05-27 18:11:05 +00:00
|
|
|
#endif
|
|
|
|
#ifdef VM_MEMATTR_WRITE_PROTECTED
|
2021-04-11 09:00:00 +00:00
|
|
|
MEMATTR_STR(VM_MEMATTR_WRITE_PROTECTED, "WP")
|
2015-05-27 18:11:05 +00:00
|
|
|
#endif
|
|
|
|
#ifdef VM_MEMATTR_WRITE_BACK
|
2021-04-11 09:00:00 +00:00
|
|
|
MEMATTR_STR(VM_MEMATTR_WRITE_BACK, "WB")
|
2015-05-27 18:11:05 +00:00
|
|
|
#endif
|
|
|
|
#ifdef VM_MEMATTR_WEAK_UNCACHEABLE
|
2021-04-11 09:00:00 +00:00
|
|
|
MEMATTR_STR(VM_MEMATTR_WEAK_UNCACHEABLE, "UC-")
|
2015-05-27 18:11:05 +00:00
|
|
|
#endif
|
2015-05-27 19:49:33 +00:00
|
|
|
#ifdef VM_MEMATTR_WB_WA
|
2021-04-11 09:00:00 +00:00
|
|
|
MEMATTR_STR(VM_MEMATTR_WB_WA, "WB")
|
2015-05-27 18:11:05 +00:00
|
|
|
#endif
|
|
|
|
#ifdef VM_MEMATTR_NOCACHE
|
2021-04-11 09:00:00 +00:00
|
|
|
MEMATTR_STR(VM_MEMATTR_NOCACHE, "NC")
|
2015-05-27 18:11:05 +00:00
|
|
|
#endif
|
|
|
|
#ifdef VM_MEMATTR_DEVICE
|
2021-04-11 09:00:00 +00:00
|
|
|
MEMATTR_STR(VM_MEMATTR_DEVICE, "DEV")
|
2015-05-27 18:11:05 +00:00
|
|
|
#endif
|
2021-04-08 11:54:20 +00:00
|
|
|
#ifdef VM_MEMATTR_DEVICE_NP
|
|
|
|
MEMATTR_STR(VM_MEMATTR_DEVICE, "NP")
|
|
|
|
#endif
|
2015-05-27 18:11:05 +00:00
|
|
|
#ifdef VM_MEMATTR_CACHEABLE
|
2021-04-11 09:00:00 +00:00
|
|
|
MEMATTR_STR(VM_MEMATTR_CACHEABLE, "C")
|
2015-05-27 18:11:05 +00:00
|
|
|
#endif
|
|
|
|
#ifdef VM_MEMATTR_PREFETCHABLE
|
2021-04-11 09:00:00 +00:00
|
|
|
MEMATTR_STR(VM_MEMATTR_PREFETCHABLE, "PRE")
|
2015-05-27 18:11:05 +00:00
|
|
|
#endif
|
2021-04-11 09:00:00 +00:00
|
|
|
{
|
2015-05-27 18:11:05 +00:00
|
|
|
str = "??";
|
|
|
|
}
|
2021-04-11 09:00:00 +00:00
|
|
|
#undef MEMATTR_STR
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_emit("{:attribute/%-3s} ", str);
|
2015-05-27 18:11:05 +00:00
|
|
|
switch (kvo->kvo_type) {
|
|
|
|
case KVME_TYPE_NONE:
|
|
|
|
str = "--";
|
|
|
|
break;
|
|
|
|
case KVME_TYPE_DEFAULT:
|
|
|
|
str = "df";
|
|
|
|
break;
|
|
|
|
case KVME_TYPE_VNODE:
|
|
|
|
str = "vn";
|
|
|
|
break;
|
|
|
|
case KVME_TYPE_SWAP:
|
|
|
|
str = "sw";
|
|
|
|
break;
|
|
|
|
case KVME_TYPE_DEVICE:
|
|
|
|
str = "dv";
|
|
|
|
break;
|
|
|
|
case KVME_TYPE_PHYS:
|
|
|
|
str = "ph";
|
|
|
|
break;
|
|
|
|
case KVME_TYPE_DEAD:
|
|
|
|
str = "dd";
|
|
|
|
break;
|
|
|
|
case KVME_TYPE_SG:
|
|
|
|
str = "sg";
|
|
|
|
break;
|
2017-05-23 07:20:29 +00:00
|
|
|
case KVME_TYPE_MGTDEVICE:
|
|
|
|
str = "md";
|
|
|
|
break;
|
2015-05-27 18:11:05 +00:00
|
|
|
case KVME_TYPE_UNKNOWN:
|
|
|
|
default:
|
|
|
|
str = "??";
|
|
|
|
break;
|
|
|
|
}
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_emit("{:type/%-2s} ", str);
|
|
|
|
xo_emit("{:path/%-s}\n", kvo->kvo_path);
|
|
|
|
xo_close_instance("object");
|
2015-05-27 18:11:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
doobjstat(void)
|
|
|
|
{
|
|
|
|
struct kinfo_vmobject *kvo;
|
|
|
|
int cnt, i;
|
|
|
|
|
|
|
|
kvo = kinfo_getvmobject(&cnt);
|
|
|
|
if (kvo == NULL) {
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_warn("Failed to fetch VM object list");
|
2015-05-27 18:11:05 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_emit("{T:RES/%5s} {T:ACT/%5s} {T:INACT/%5s} {T:REF/%3s} {T:SHD/%3s} "
|
2017-12-01 22:38:28 +00:00
|
|
|
"{T:CM/%3s} {T:TP/%2s} {T:PATH/%s}\n");
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_open_list("object");
|
2015-05-27 18:11:05 +00:00
|
|
|
for (i = 0; i < cnt; i++)
|
|
|
|
display_object(&kvo[i]);
|
|
|
|
free(kvo);
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_close_list("object");
|
2015-05-27 18:11:05 +00:00
|
|
|
}
|
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* kread reads something from the kernel, given its nlist index.
|
|
|
|
*/
|
2003-12-07 17:46:14 +00:00
|
|
|
static void
|
2004-06-30 01:34:26 +00:00
|
|
|
kreado(int nlx, void *addr, size_t size, size_t offset)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2003-12-25 01:32:55 +00:00
|
|
|
const char *sym;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
1998-10-28 06:41:24 +00:00
|
|
|
if (namelist[nlx].n_type == 0 || namelist[nlx].n_value == 0) {
|
1994-05-27 12:33:43 +00:00
|
|
|
sym = namelist[nlx].n_name;
|
|
|
|
if (*sym == '_')
|
|
|
|
++sym;
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_errx(1, "symbol %s not defined", sym);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
2004-06-30 01:34:26 +00:00
|
|
|
if ((size_t)kvm_read(kd, namelist[nlx].n_value + offset, addr,
|
|
|
|
size) != size) {
|
1994-05-27 12:33:43 +00:00
|
|
|
sym = namelist[nlx].n_name;
|
|
|
|
if (*sym == '_')
|
|
|
|
++sym;
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_errx(1, "%s: %s", sym, kvm_geterr(kd));
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-06-30 01:34:26 +00:00
|
|
|
static void
|
|
|
|
kread(int nlx, void *addr, size_t size)
|
|
|
|
{
|
|
|
|
|
2017-12-01 22:38:28 +00:00
|
|
|
kreado(nlx, addr, size, 0);
|
2004-06-30 01:34:26 +00:00
|
|
|
}
|
|
|
|
|
Dynamically allocate IRQ ranges on x86.
Previously, x86 used static ranges of IRQ values for different types
of I/O interrupts. Interrupt pins on I/O APICs and 8259A PICs used
IRQ values from 0 to 254. MSI interrupts used a compile-time-defined
range starting at 256, and Xen event channels used a
compile-time-defined range after MSI. Some recent systems have more
than 255 I/O APIC interrupt pins which resulted in those IRQ values
overflowing into the MSI range triggering an assertion failure.
Replace statically assigned ranges with dynamic ranges. Do a single
pass computing the sizes of the IRQ ranges (PICs, MSI, Xen) to
determine the total number of IRQs required. Allocate the interrupt
source and interrupt count arrays dynamically once this pass has
completed. To minimize runtime complexity these arrays are only sized
once during bootup. The PIC range is determined by the PICs present
in the system. The MSI and Xen ranges continue to use a fixed size,
though this does make it possible to turn the MSI range size into a
tunable in the future.
As a result, various places are updated to use dynamic limits instead
of constants. In addition, the vmstat(8) utility has been taught to
understand that some kernels may treat 'intrcnt' and 'intrnames' as
pointers rather than arrays when extracting interrupt stats from a
crashdump. This is determined by the presence (vs absence) of a
global 'nintrcnt' symbol.
This change reverts r189404 which worked around a buggy BIOS which
enumerated an I/O APIC twice (using the same memory mapped address for
both entries but using an IRQ base of 256 for one entry and a valid
IRQ base for the second entry). Making the "base" of MSI IRQ values
dynamic avoids the panic that r189404 worked around, and there may now
be valid I/O APICs with an IRQ base above 256 which this workaround
would incorrectly skip.
If in the future the issue reported in PR 130483 reoccurs, we will
have to add a pass over the I/O APIC entries in the MADT to detect
duplicates using the memory mapped address and use some strategy to
choose the "correct" one.
While here, reserve room in intrcnts for the Hyper-V counters.
PR: 229429, 130483
Reviewed by: kib, royger, cem
Tested by: royger (Xen), kib (DMAR)
Approved by: re (gjb)
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D16861
2018-08-28 21:09:19 +00:00
|
|
|
static void
|
|
|
|
kreadptr(uintptr_t addr, void *buf, size_t size)
|
|
|
|
{
|
|
|
|
|
|
|
|
if ((size_t)kvm_read(kd, addr, buf, size) != size)
|
|
|
|
xo_errx(1, "%s", kvm_geterr(kd));
|
|
|
|
}
|
|
|
|
|
2018-06-13 08:52:04 +00:00
|
|
|
static void __dead2
|
2003-12-07 17:46:14 +00:00
|
|
|
usage(void)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_error("%s%s",
|
2017-12-01 22:38:28 +00:00
|
|
|
"usage: vmstat [-afHhimoPsz] [-M core [-N system]] [-c count] [-n devs]\n",
|
|
|
|
" [-p type,if,pass] [-w wait] [disks] [wait [count]]\n");
|
2015-11-20 05:15:34 +00:00
|
|
|
xo_finish();
|
1994-05-27 12:33:43 +00:00
|
|
|
exit(1);
|
|
|
|
}
|