mirror of
https://git.rtems.org/rtems-libbsd/
synced 2025-10-14 07:59:07 +08:00
Update to FreeBSD head 2017-06-01
Git mirror commit dfb26efac4ce9101dda240e94d9ab53f80a9e131. Update #3472.
This commit is contained in:
@@ -62,6 +62,7 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/user.h>
|
||||
#define _WANT_VMMETER
|
||||
#include <sys/vmmeter.h>
|
||||
#include <sys/pcpu.h>
|
||||
|
||||
@@ -136,7 +137,57 @@ static long select_generation;
|
||||
static char **specified_devices;
|
||||
static devstat_select_mode select_mode;
|
||||
|
||||
static struct vmmeter sum, osum;
|
||||
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;
|
||||
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;
|
||||
|
||||
#define VMSTAT_DEFAULT_LINES 20 /* Default number of `winlines'. */
|
||||
volatile sig_atomic_t wresized; /* Tty resized, when non-zero. */
|
||||
@@ -418,12 +469,11 @@ retry_nlist:
|
||||
|
||||
#ifndef __rtems__
|
||||
static int
|
||||
mysysctl(const char *name, void *oldp, size_t *oldlenp,
|
||||
void *newp, size_t newlen)
|
||||
mysysctl(const char *name, void *oldp, size_t *oldlenp)
|
||||
{
|
||||
int error;
|
||||
|
||||
error = sysctlbyname(name, oldp, oldlenp, newp, newlen);
|
||||
error = sysctlbyname(name, oldp, oldlenp, NULL, 0);
|
||||
if (error != 0 && errno != ENOMEM)
|
||||
xo_err(1, "sysctl(%s)", name);
|
||||
return (error);
|
||||
@@ -504,95 +554,54 @@ getuptime(void)
|
||||
}
|
||||
|
||||
static void
|
||||
fill_pcpu(struct pcpu ***pcpup, int* maxcpup)
|
||||
{
|
||||
struct pcpu **pcpu;
|
||||
|
||||
int maxcpu, i;
|
||||
|
||||
*pcpup = NULL;
|
||||
|
||||
if (kd == NULL)
|
||||
return;
|
||||
|
||||
maxcpu = kvm_getmaxcpu(kd);
|
||||
if (maxcpu < 0)
|
||||
xo_errx(1, "kvm_getmaxcpu: %s", kvm_geterr(kd));
|
||||
|
||||
pcpu = calloc(maxcpu, sizeof(struct pcpu *));
|
||||
if (pcpu == NULL)
|
||||
xo_err(1, "calloc");
|
||||
|
||||
for (i = 0; i < maxcpu; i++) {
|
||||
pcpu[i] = kvm_getpcpu(kd, i);
|
||||
if (pcpu[i] == (struct pcpu *)-1)
|
||||
xo_errx(1, "kvm_getpcpu: %s", kvm_geterr(kd));
|
||||
}
|
||||
|
||||
*maxcpup = maxcpu;
|
||||
*pcpup = pcpu;
|
||||
}
|
||||
|
||||
static void
|
||||
free_pcpu(struct pcpu **pcpu, int maxcpu)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < maxcpu; i++)
|
||||
free(pcpu[i]);
|
||||
free(pcpu);
|
||||
}
|
||||
|
||||
static void
|
||||
fill_vmmeter(struct vmmeter *vmmp)
|
||||
fill_vmmeter(struct __vmmeter *vmmp)
|
||||
{
|
||||
struct pcpu **pcpu;
|
||||
int maxcpu, i;
|
||||
|
||||
if (kd != NULL) {
|
||||
kread(X_SUM, vmmp, sizeof(*vmmp));
|
||||
fill_pcpu(&pcpu, &maxcpu);
|
||||
for (i = 0; i < maxcpu; i++) {
|
||||
if (pcpu[i] == NULL)
|
||||
continue;
|
||||
#define ADD_FROM_PCPU(i, name) \
|
||||
vmmp->name += pcpu[i]->pc_cnt.name
|
||||
ADD_FROM_PCPU(i, v_swtch);
|
||||
ADD_FROM_PCPU(i, v_trap);
|
||||
ADD_FROM_PCPU(i, v_syscall);
|
||||
ADD_FROM_PCPU(i, v_intr);
|
||||
ADD_FROM_PCPU(i, v_soft);
|
||||
ADD_FROM_PCPU(i, v_vm_faults);
|
||||
ADD_FROM_PCPU(i, v_io_faults);
|
||||
ADD_FROM_PCPU(i, v_cow_faults);
|
||||
ADD_FROM_PCPU(i, v_cow_optim);
|
||||
ADD_FROM_PCPU(i, v_zfod);
|
||||
ADD_FROM_PCPU(i, v_ozfod);
|
||||
ADD_FROM_PCPU(i, v_swapin);
|
||||
ADD_FROM_PCPU(i, v_swapout);
|
||||
ADD_FROM_PCPU(i, v_swappgsin);
|
||||
ADD_FROM_PCPU(i, v_swappgsout);
|
||||
ADD_FROM_PCPU(i, v_vnodein);
|
||||
ADD_FROM_PCPU(i, v_vnodeout);
|
||||
ADD_FROM_PCPU(i, v_vnodepgsin);
|
||||
ADD_FROM_PCPU(i, v_vnodepgsout);
|
||||
ADD_FROM_PCPU(i, v_intrans);
|
||||
ADD_FROM_PCPU(i, v_tfree);
|
||||
ADD_FROM_PCPU(i, v_forks);
|
||||
ADD_FROM_PCPU(i, v_vforks);
|
||||
ADD_FROM_PCPU(i, v_rforks);
|
||||
ADD_FROM_PCPU(i, v_kthreads);
|
||||
ADD_FROM_PCPU(i, v_forkpages);
|
||||
ADD_FROM_PCPU(i, v_vforkpages);
|
||||
ADD_FROM_PCPU(i, v_rforkpages);
|
||||
ADD_FROM_PCPU(i, v_kthreadpages);
|
||||
#undef ADD_FROM_PCPU
|
||||
}
|
||||
free_pcpu(pcpu, maxcpu);
|
||||
struct vmmeter vm_cnt;
|
||||
|
||||
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
|
||||
} else {
|
||||
size_t size = sizeof(unsigned int);
|
||||
#define GET_VM_STATS(cat, name) \
|
||||
mysysctl("vm.stats." #cat "." #name, &vmmp->name, &size, NULL, 0)
|
||||
size_t size;
|
||||
|
||||
#define GET_VM_STATS(cat, name) do { \
|
||||
size = sizeof(vmmp->name); \
|
||||
mysysctl("vm.stats." #cat "." #name, &vmmp->name, &size); \
|
||||
} while (0)
|
||||
/* sys */
|
||||
GET_VM_STATS(sys, v_swtch);
|
||||
GET_VM_STATS(sys, v_trap);
|
||||
@@ -657,7 +666,7 @@ fill_vmtotal(struct vmtotal *vmtp)
|
||||
xo_errx(1, "not implemented");
|
||||
} else {
|
||||
size_t size = sizeof(*vmtp);
|
||||
mysysctl("vm.vmtotal", vmtp, &size, NULL, 0);
|
||||
mysysctl("vm.vmtotal", vmtp, &size);
|
||||
if (size != sizeof(*vmtp))
|
||||
xo_errx(1, "vm.total size mismatch");
|
||||
}
|
||||
@@ -681,14 +690,14 @@ getcpuinfo(u_long *maskp, int *maxidp)
|
||||
mask = 0;
|
||||
ncpus = 0;
|
||||
size = sizeof(maxcpu);
|
||||
mysysctl("kern.smp.maxcpus", &maxcpu, &size, NULL, 0);
|
||||
mysysctl("kern.smp.maxcpus", &maxcpu, &size);
|
||||
if (size != sizeof(maxcpu))
|
||||
xo_errx(1, "sysctl kern.smp.maxcpus");
|
||||
size = sizeof(long) * maxcpu * CPUSTATES;
|
||||
times = malloc(size);
|
||||
if (times == NULL)
|
||||
xo_err(1, "malloc %zd bytes", size);
|
||||
mysysctl("kern.cp_times", times, &size, NULL, 0);
|
||||
mysysctl("kern.cp_times", times, &size);
|
||||
maxid = (size / CPUSTATES / sizeof(long)) - 1;
|
||||
for (i = 0; i <= maxid; i++) {
|
||||
empty = 1;
|
||||
@@ -779,7 +788,7 @@ dovmstat(unsigned int interval, int reps)
|
||||
struct clockinfo clockrate;
|
||||
|
||||
size = sizeof(clockrate);
|
||||
mysysctl("kern.clockrate", &clockrate, &size, NULL, 0);
|
||||
mysysctl("kern.clockrate", &clockrate, &size);
|
||||
if (size != sizeof(clockrate))
|
||||
xo_errx(1, "clockrate size mismatch");
|
||||
hz = clockrate.hz;
|
||||
@@ -799,13 +808,13 @@ dovmstat(unsigned int interval, int reps)
|
||||
xo_errx(1, "kvm_getcptime: %s", kvm_geterr(kd));
|
||||
} else {
|
||||
size = sizeof(cur.cp_time);
|
||||
mysysctl("kern.cp_time", &cur.cp_time, &size, NULL, 0);
|
||||
mysysctl("kern.cp_time", &cur.cp_time, &size);
|
||||
if (size != sizeof(cur.cp_time))
|
||||
xo_errx(1, "cp_time size mismatch");
|
||||
}
|
||||
if (Pflag) {
|
||||
size = size_cp_times;
|
||||
mysysctl("kern.cp_times", cur_cp_times, &size, NULL, 0);
|
||||
mysysctl("kern.cp_times", cur_cp_times, &size);
|
||||
if (size != size_cp_times)
|
||||
xo_errx(1, "cp_times mismatch");
|
||||
}
|
||||
@@ -1158,7 +1167,7 @@ dosum(void)
|
||||
kread(X_NCHSTATS, &lnchstats, sizeof(lnchstats));
|
||||
} else {
|
||||
size_t size = sizeof(lnchstats);
|
||||
mysysctl("vfs.cache.nchstats", &lnchstats, &size, NULL, 0);
|
||||
mysysctl("vfs.cache.nchstats", &lnchstats, &size);
|
||||
if (size != sizeof(lnchstats))
|
||||
xo_errx(1, "vfs.cache.nchstats size mismatch");
|
||||
}
|
||||
@@ -1348,8 +1357,7 @@ read_intrcnts(unsigned long **intrcnts)
|
||||
*intrcnts = reallocf(*intrcnts, intrcntlen);
|
||||
if (*intrcnts == NULL)
|
||||
err(1, "reallocf()");
|
||||
if (mysysctl("hw.intrcnt",
|
||||
*intrcnts, &intrcntlen, NULL, 0) == 0)
|
||||
if (mysysctl("hw.intrcnt", *intrcnts, &intrcntlen) == 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1417,8 +1425,7 @@ dointr(unsigned int interval, int reps)
|
||||
for (intrnames = NULL, inamlen = 1024; ; inamlen *= 2) {
|
||||
if ((intrnames = reallocf(intrnames, inamlen)) == NULL)
|
||||
xo_err(1, "reallocf()");
|
||||
if (mysysctl("hw.intrnames",
|
||||
intrnames, &inamlen, NULL, 0) == 0)
|
||||
if (mysysctl("hw.intrnames", intrnames, &inamlen) == 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1701,6 +1708,9 @@ display_object(struct kinfo_vmobject *kvo)
|
||||
case KVME_TYPE_SG:
|
||||
str = "sg";
|
||||
break;
|
||||
case KVME_TYPE_MGTDEVICE:
|
||||
str = "md";
|
||||
break;
|
||||
case KVME_TYPE_UNKNOWN:
|
||||
default:
|
||||
str = "??";
|
||||
|
Reference in New Issue
Block a user