-/* $OpenBSD: main.c,v 1.76 2021/07/12 15:09:20 beck Exp $ */
+/* $OpenBSD: main.c,v 1.77 2022/12/04 18:01:57 cheloha Exp $ */
/*
* Copyright (c) 2001, 2007 Can Erkin Acar
* Copyright (c) 2001 Daniel Hartmeier
double naptime = 5.0;
int verbose = 1; /* to report kvm read errs */
int nflag = 1;
-int ut, hz, stathz;
+int ut, hz;
char hostname[HOST_NAME_MAX+1];
WINDOW *wnd;
int CMDLINE;
mib[1] = KERN_CLOCKRATE;
if (sysctl(mib, 2, &cinf, &size, NULL, 0) == -1)
return;
- stathz = cinf.stathz;
hz = cinf.hz;
}
-/* $OpenBSD: vmstat.c,v 1.94 2022/02/22 17:35:01 deraadt Exp $ */
+/* $OpenBSD: vmstat.c,v 1.95 2022/12/04 18:01:57 cheloha Exp $ */
/* $NetBSD: vmstat.c,v 1.5 1996/05/10 23:16:40 thorpej Exp $ */
/*-
int vm_keyboard_callback(int);
static time_t t;
-static float hertz;
static int nintr;
static long *intrloc;
static char **intrname;
int mib[4], i;
size_t size;
- hertz = stathz;
if (!dkinit(1))
return(0);
Y(fld); \
putint((int)((float)s.fld/etime + 0.5), l, c, w); \
} while (0)
-#define MAXFAIL 5
static char cpuchar[] = { '|', '@', '=', '>', ' ' };
static char cpuorder[] = { CP_INTR, CP_SPIN, CP_SYS, CP_USER, CP_IDLE };
void
showkre(void)
{
+ static struct timespec prev;
+ struct timespec elapsed, now;
float f1, f2;
int psiz;
u_int64_t inttotal, intcnt;
int i, l, c;
- static int failcnt = 0, first_run = 0;
+ static int first_run = 0;
double etime;
+ clock_gettime(CLOCK_UPTIME, &now);
+ timespecsub(&now, &prev, &elapsed);
+ prev = now;
if (state == TIME) {
if (!first_run) {
first_run = 1;
return;
}
}
- etime = 0;
- for (i = 0; i < CPUSTATES; i++) {
+ etime = elapsed.tv_sec + elapsed.tv_nsec / 1000000000.0;
+ for (i = 0; i < CPUSTATES; i++)
X(cpustats.cs_time);
- etime += s.cpustats.cs_time[i];
- }
- if (etime < 5.0) { /* < 5 ticks - ignore this trash */
- if (failcnt++ >= MAXFAIL) {
- error("The alternate system clock has died!");
- failcnt = 0;
- }
- return;
- }
- failcnt = 0;
- etime /= hertz;
inttotal = 0;
for (i = 0; i < nintr; i++) {
t = intcnt = s.intrcnt[i];