Use kern.cp_time to fetch cp_time[]. Don't support fetching it from

crash dumps yet, as that requires determining which CPU we should fetch
it from, etc.
This commit is contained in:
thorpej 2000-06-04 16:06:25 +00:00
parent 581e676913
commit 13ba787e60
6 changed files with 80 additions and 37 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: extern.h,v 1.21 2000/01/08 23:12:37 itojun Exp $ */
/* $NetBSD: extern.h,v 1.22 2000/06/04 16:06:25 thorpej Exp $ */
/*-
* Copyright (c) 1991, 1993
@ -60,6 +60,7 @@ extern int nports;
extern int protos;
extern int verbose;
extern int nflag;
extern char *memf;
struct inpcb;
#ifdef INET6
@ -100,6 +101,7 @@ void fetchnetstat __P((void));
void fetchpigs __P((void));
void fetchswap __P((void));
void fetchtcp __P((void));
int fetch_cptime __P((u_int64_t *));
void global_help __P((char *args));
void global_interval __P((char *args));
void global_load __P((char *args));

View File

@ -1,4 +1,4 @@
/* $NetBSD: fetch.c,v 1.5 1999/04/24 23:36:36 ross Exp $ */
/* $NetBSD: fetch.c,v 1.6 2000/06/04 16:06:25 thorpej Exp $ */
/*-
* Copyright (c) 1980, 1992, 1993
@ -38,10 +38,13 @@
#if 0
static char sccsid[] = "@(#)fetch.c 8.1 (Berkeley) 6/6/93";
#endif
__RCSID("$NetBSD: fetch.c,v 1.5 1999/04/24 23:36:36 ross Exp $");
__RCSID("$NetBSD: fetch.c,v 1.6 2000/06/04 16:06:25 thorpej Exp $");
#endif /* not lint */
#include <sys/types.h>
#include <sys/param.h>
#include <sys/sched.h>
#include <sys/sysctl.h>
#include <string.h>
#include "systat.h"
#include "extern.h"
@ -57,3 +60,30 @@ kvm_ckread(a, b, l)
} else
return (1);
}
int
fetch_cptime(cptime)
u_int64_t *cptime;
{
size_t ssize;
int mib[2];
/*
* XXX Need to locate the `correct' CPU when looking for this
* XXX in crash dumps. Just don't report it for now, in that
* XXX case.
*/
ssize = CPUSTATES * sizeof(u_int64_t);
memset(cptime, 0, ssize);
if (memf == NULL) {
mib[0] = CTL_KERN;
mib[1] = KERN_CP_TIME;
if (sysctl(mib, 2, cptime, &ssize, NULL, 0) < 0) {
if (verbose)
error("error fetching cp_time\n");
return (0);
} else
return (1);
}
return (1);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: pigs.c,v 1.17 2000/06/04 01:53:51 perry Exp $ */
/* $NetBSD: pigs.c,v 1.18 2000/06/04 16:06:26 thorpej Exp $ */
/*-
* Copyright (c) 1980, 1992, 1993
@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)pigs.c 8.2 (Berkeley) 9/23/93";
#endif
__RCSID("$NetBSD: pigs.c,v 1.17 2000/06/04 01:53:51 perry Exp $");
__RCSID("$NetBSD: pigs.c,v 1.18 2000/06/04 16:06:26 thorpej Exp $");
#endif /* not lint */
/*
@ -69,7 +69,7 @@ int compare_pctcpu __P((const void *, const void *));
int nproc;
struct p_times *pt;
long stime[CPUSTATES];
u_int64_t stime[CPUSTATES];
long mempages;
int fscale;
double lccpu;
@ -153,13 +153,11 @@ showpigs()
static struct nlist namelist[] = {
#define X_FIRST 0
#define X_CPTIME 0
{ "_cp_time" },
#define X_CCPU 1
#define X_CCPU 0
{ "_ccpu" },
#define X_FSCALE 2
#define X_FSCALE 1
{ "_fscale" },
#define X_PHYSMEM 3
#define X_PHYSMEM 2
{ "_physmem" },
{ "" }
};
@ -179,7 +177,7 @@ initpigs()
return(0);
}
}
KREAD(NPTR(X_CPTIME), stime, sizeof (stime));
(void) fetch_cptime(stime);
KREAD(NPTR(X_PHYSMEM), &mempages, sizeof (mempages));
NREAD(X_CCPU, &ccpu, sizeof ccpu);
NREAD(X_FSCALE, &fscale, sizeof fscale);
@ -196,7 +194,7 @@ fetchpigs()
struct proc *pp;
float *pctp;
struct kinfo_proc *kpp;
long ctime[CPUSTATES];
u_int64_t ctime[CPUSTATES];
double t;
static int lastnproc = 0;
@ -235,7 +233,7 @@ fetchpigs()
/*
* and for the imaginary "idle" process
*/
KREAD(NPTR(X_CPTIME), ctime, sizeof (ctime));
(void) fetch_cptime(ctime);
t = 0;
for (i = 0; i < CPUSTATES; i++)
t += ctime[i] - stime[i];

View File

@ -1,4 +1,4 @@
/* $NetBSD: ps.h,v 1.1 1999/02/21 21:48:07 jwise Exp $ */
/* $NetBSD: ps.h,v 1.2 2000/06/04 16:06:26 thorpej Exp $ */
/*-
* Copyright (c) 1999
@ -39,7 +39,7 @@ extern struct p_times {
struct kinfo_proc *pt_kp;
} *pt;
extern long stime[CPUSTATES];
extern u_int64_t stime[CPUSTATES];
extern int fscale;
extern double lccpu;
extern long mempages;

View File

@ -1,4 +1,4 @@
/* $NetBSD: vmstat.c,v 1.26 2000/06/04 01:53:51 perry Exp $ */
/* $NetBSD: vmstat.c,v 1.27 2000/06/04 16:06:26 thorpej Exp $ */
/*-
* Copyright (c) 1983, 1989, 1992, 1993
@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)vmstat.c 8.2 (Berkeley) 1/12/94";
#endif
__RCSID("$NetBSD: vmstat.c,v 1.26 2000/06/04 01:53:51 perry Exp $");
__RCSID("$NetBSD: vmstat.c,v 1.27 2000/06/04 16:06:26 thorpej Exp $");
#endif /* not lint */
/*
@ -139,19 +139,17 @@ closekre(w)
static struct nlist namelist[] = {
#define X_CPTIME 0
{ "_cp_time" },
#define X_TOTAL 1
#define X_TOTAL 0
{ "_total" },
#define X_NCHSTATS 2
#define X_NCHSTATS 1
{ "_nchstats" },
#define X_INTRNAMES 3
#define X_INTRNAMES 2
{ "_intrnames" },
#define X_EINTRNAMES 4
#define X_EINTRNAMES 3
{ "_eintrnames" },
#define X_INTRCNT 5
#define X_INTRCNT 4
{ "_intrcnt" },
#define X_EINTRCNT 6
#define X_EINTRCNT 5
{ "_eintrcnt" },
{ "" },
};
@ -610,7 +608,7 @@ getinfo(s, st)
size_t size;
dkreadstats();
NREAD(X_CPTIME, s->time, sizeof s->time);
(void) fetch_cptime(s->time);
NREAD(X_NCHSTATS, &s->nchstats, sizeof s->nchstats);
NREAD(X_INTRCNT, s->intrcnt, nintr * LONG);
size = sizeof(s->uvmexp);

View File

@ -1,4 +1,4 @@
/* $NetBSD: dkstats.c,v 1.7 2000/06/03 21:00:43 thorpej Exp $ */
/* $NetBSD: dkstats.c,v 1.8 2000/06/04 16:10:17 thorpej Exp $ */
/*
* Copyright (c) 1996 John M. Vinopal
@ -32,9 +32,10 @@
* SUCH DAMAGE.
*/
#include <sys/types.h>
#include <sys/param.h>
#include <sys/sched.h>
#include <sys/dkstat.h>
#include <sys/sysctl.h>
#include <sys/time.h>
#include <sys/disk.h>
@ -54,15 +55,13 @@ static struct nlist namelist[] = {
{ "_tk_nin" }, /* tty characters in */
#define X_TK_NOUT 1
{ "_tk_nout" }, /* tty characters out */
#define X_CP_TIME 2
{ "_cp_time" }, /* system timer ticks */
#define X_HZ 3
#define X_HZ 2
{ "_hz" }, /* ticks per second */
#define X_STATHZ 4
#define X_STATHZ 3
{ "_stathz" },
#define X_DISK_COUNT 5
#define X_DISK_COUNT 4
{ "_disk_count" }, /* number of disks */
#define X_DISKLIST 6
#define X_DISKLIST 5
{ "_disklist" }, /* TAILQ of disks */
{ NULL },
};
@ -153,6 +152,8 @@ void
dkreadstats()
{
struct disk cur_disk, *p;
size_t ssize;
int mib[2];
int i;
p = dk_drivehead;
@ -165,7 +166,21 @@ dkreadstats()
timerset(&(cur_disk.dk_time), &(cur.dk_time[i]));
p = cur_disk.dk_link.tqe_next;
}
deref_nl(X_CP_TIME, cur.cp_time, sizeof(cur.cp_time));
/*
* XXX Need to locate the `correct' CPU when looking for this
* XXX in crash dumps. Just don't report it for now, in that
* XXX case.
*/
ssize = sizeof(cur.cp_time);
memset(cur.cp_time, 0, ssize);
if (memf == NULL) {
mib[0] = CTL_KERN;
mib[1] = KERN_CP_TIME;
if (sysctl(mib, 2, cur.cp_time, &ssize, NULL, 0) < 0)
memset(cur.cp_time, 0, sizeof(cur.cp_time));
}
deref_nl(X_TK_NIN, &cur.tk_nin, sizeof(cur.tk_nin));
deref_nl(X_TK_NOUT, &cur.tk_nout, sizeof(cur.tk_nout));
}