accept either "time_second" or "time" as kernel timevariable in
order to support common userland in enviroments where timecounter kernels and non timecounter kernel co-exist (e.g. xen & i386)
This commit is contained in:
parent
86c579f9d0
commit
e386d70092
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: savecore.c,v 1.67 2006/06/07 20:56:19 kardel Exp $ */
|
||||
/* $NetBSD: savecore.c,v 1.68 2006/07/09 06:45:09 kardel Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1986, 1992, 1993
|
||||
|
@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1986, 1992, 1993\n\
|
|||
#if 0
|
||||
static char sccsid[] = "@(#)savecore.c 8.5 (Berkeley) 4/28/95";
|
||||
#else
|
||||
__RCSID("$NetBSD: savecore.c,v 1.67 2006/06/07 20:56:19 kardel Exp $");
|
||||
__RCSID("$NetBSD: savecore.c,v 1.68 2006/07/09 06:45:09 kardel Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
|
@ -76,39 +76,34 @@ struct nlist current_nl[] = { /* Namelist for currently running system. */
|
|||
#define X_DUMPLO 1
|
||||
{ "_dumplo" },
|
||||
#define X_TIME_SECOND 2
|
||||
#ifdef __HAVE_TIMECOUNTER
|
||||
{ "_time_second" },
|
||||
#else
|
||||
{ "_time" }, /* XXX uses same array slot as "X_TIME_SECOND" */
|
||||
#endif
|
||||
#define X_DUMPSIZE 3
|
||||
#define X_TIME 3
|
||||
{ "_time" },
|
||||
#define X_DUMPSIZE 4
|
||||
{ "_dumpsize" },
|
||||
#define X_VERSION 4
|
||||
#define X_VERSION 5
|
||||
{ "_version" },
|
||||
#define X_DUMPMAG 5
|
||||
#define X_DUMPMAG 6
|
||||
{ "_dumpmag" },
|
||||
#define X_PANICSTR 6
|
||||
#define X_PANICSTR 7
|
||||
{ "_panicstr" },
|
||||
#define X_PANICSTART 7
|
||||
#define X_PANICSTART 8
|
||||
{ "_panicstart" },
|
||||
#define X_PANICEND 8
|
||||
#define X_PANICEND 9
|
||||
{ "_panicend" },
|
||||
#define X_MSGBUF 9
|
||||
#define X_MSGBUF 10
|
||||
{ "_msgbufp" },
|
||||
{ NULL },
|
||||
};
|
||||
int cursyms[] = { X_DUMPDEV, X_DUMPLO, X_VERSION, X_DUMPMAG, -1 };
|
||||
int dumpsyms[] = { X_TIME_SECOND, X_DUMPSIZE, X_VERSION, X_PANICSTR, X_DUMPMAG,
|
||||
int dumpsyms[] = { X_TIME_SECOND, X_TIME, X_DUMPSIZE, X_VERSION, X_PANICSTR, X_DUMPMAG,
|
||||
-1 };
|
||||
|
||||
struct nlist dump_nl[] = { /* Name list for dumped system. */
|
||||
{ "_dumpdev" }, /* Entries MUST be the same as */
|
||||
{ "_dumplo" }, /* those in current_nl[]. */
|
||||
#ifdef __HAVE_TIMECOUNTER
|
||||
{ "_time_second" },
|
||||
#else
|
||||
{ "_time" }, /* XXX uses same array slot as "X_TIME_SECOND" */
|
||||
#endif
|
||||
{ "_time" },
|
||||
{ "_dumpsize" },
|
||||
{ "_version" },
|
||||
{ "_dumpmag" },
|
||||
|
@ -272,7 +267,9 @@ kmem_setup(void)
|
|||
kvm_geterr(kd_kern));
|
||||
|
||||
for (i = 0; cursyms[i] != -1; i++)
|
||||
if (current_nl[cursyms[i]].n_value == 0) {
|
||||
if (current_nl[cursyms[i]].n_value == 0 &&
|
||||
cursyms[i] != X_TIME_SECOND &&
|
||||
cursyms[i] != X_TIME) {
|
||||
syslog(LOG_ERR, "%s: %s not in namelist",
|
||||
kernel, current_nl[cursyms[i]].n_name);
|
||||
exit(1);
|
||||
|
@ -329,7 +326,9 @@ kmem_setup(void)
|
|||
kvm_geterr(kd_dump));
|
||||
|
||||
for (i = 0; dumpsyms[i] != -1; i++)
|
||||
if (dump_nl[dumpsyms[i]].n_value == 0) {
|
||||
if (dump_nl[dumpsyms[i]].n_value == 0 &&
|
||||
dumpsyms[i] != X_TIME_SECOND &&
|
||||
dumpsyms[i] != X_TIME) {
|
||||
syslog(LOG_ERR, "%s: %s not in namelist",
|
||||
kernel, dump_nl[dumpsyms[i]].n_name);
|
||||
exit(1);
|
||||
|
@ -690,24 +689,16 @@ int
|
|||
get_crashtime(void)
|
||||
{
|
||||
time_t dumptime; /* Time the dump was taken. */
|
||||
#ifndef __HAVE_TIMECOUNTER
|
||||
struct timeval dtime;
|
||||
#endif
|
||||
|
||||
#ifdef __HAVE_TIMECOUNTER
|
||||
if (KREAD(kd_dump, dump_nl[X_TIME_SECOND].n_value, &dumptime) != 0) {
|
||||
if (verbose)
|
||||
syslog(LOG_WARNING, "kvm_read: %s", kvm_geterr(kd_dump));
|
||||
return (0);
|
||||
if (KREAD(kd_dump, dump_nl[X_TIME].n_value, &dtime) != 0) {
|
||||
if (verbose)
|
||||
syslog(LOG_WARNING, "kvm_read: %s (and _time_seconf is not defined also)", kvm_geterr(kd_dump));
|
||||
return (0);
|
||||
}
|
||||
dumptime = dtime.tv_sec;
|
||||
}
|
||||
#else
|
||||
if (KREAD(kd_dump, dump_nl[X_TIME_SECOND].n_value, &dtime) != 0) {
|
||||
if (verbose)
|
||||
syslog(LOG_WARNING, "kvm_read: %s", kvm_geterr(kd_dump));
|
||||
return (0);
|
||||
}
|
||||
dumptime = dtime.tv_sec;
|
||||
#endif
|
||||
if (dumptime == 0) {
|
||||
if (verbose)
|
||||
syslog(LOG_ERR, "dump time is zero");
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: vmstat.c,v 1.146 2006/07/08 14:58:51 yamt Exp $ */
|
||||
/* $NetBSD: vmstat.c,v 1.147 2006/07/09 06:43:16 kardel Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1998, 2000, 2001 The NetBSD Foundation, Inc.
|
||||
|
@ -77,7 +77,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 1986, 1991, 1993\n\
|
|||
#if 0
|
||||
static char sccsid[] = "@(#)vmstat.c 8.2 (Berkeley) 3/1/95";
|
||||
#else
|
||||
__RCSID("$NetBSD: vmstat.c,v 1.146 2006/07/08 14:58:51 yamt Exp $");
|
||||
__RCSID("$NetBSD: vmstat.c,v 1.147 2006/07/09 06:43:16 kardel Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
|
@ -158,12 +158,10 @@ struct nlist namelist[] =
|
|||
#define X_UVMEXP 8
|
||||
{ "_uvmexp" },
|
||||
#define X_TIME_SECOND 9
|
||||
#ifdef __HAVE_TIMECOUNTER
|
||||
{ "_time_second" },
|
||||
#else
|
||||
{ "_time" }, /* XXX uses same array slot as "X_TIME_SECOND" */
|
||||
#endif
|
||||
#define X_NL_SIZE 10
|
||||
#define X_TIME 10
|
||||
{ "_time" },
|
||||
#define X_NL_SIZE 11
|
||||
{ NULL },
|
||||
};
|
||||
|
||||
|
@ -267,6 +265,7 @@ void dovmstat(struct timespec *, int);
|
|||
void print_total_hdr(void);
|
||||
void dovmtotal(struct timespec *, int);
|
||||
void kread(struct nlist *, int, void *, size_t);
|
||||
int kreadc(struct nlist *, int, void *, size_t);
|
||||
void needhdr(int);
|
||||
long getuptime(void);
|
||||
void printhdr(void);
|
||||
|
@ -388,14 +387,21 @@ main(int argc, char *argv[])
|
|||
(void)setgid(getgid());
|
||||
|
||||
if ((c = kvm_nlist(kd, namelist)) != 0) {
|
||||
int doexit = 0;
|
||||
if (c == -1)
|
||||
errx(1, "kvm_nlist: %s %s", "namelist", kvm_geterr(kd));
|
||||
(void)fprintf(stderr, "vmstat: undefined symbols:");
|
||||
for (c = 0; c < sizeof(namelist) / sizeof(namelist[0])-1; c++)
|
||||
if (namelist[c].n_type == 0)
|
||||
if (namelist[c].n_type == 0 &&
|
||||
c != X_TIME_SECOND &&
|
||||
c != X_TIME) {
|
||||
if (doexit++ == 0)
|
||||
(void)fprintf(stderr, "vmstat: undefined symbols:");
|
||||
fprintf(stderr, " %s", namelist[c].n_name);
|
||||
(void)fputc('\n', stderr);
|
||||
exit(1);
|
||||
}
|
||||
if (doexit) {
|
||||
(void)fputc('\n', stderr);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
if (todo & INTRSTAT)
|
||||
(void) kvm_nlist(kd, intrnl);
|
||||
|
@ -539,12 +545,11 @@ getuptime(void)
|
|||
|
||||
if (boottime.tv_sec == 0)
|
||||
kread(namelist, X_BOOTTIME, &boottime, sizeof(boottime));
|
||||
#ifdef __HAVE_TIMECOUNTER
|
||||
kread(namelist, X_TIME_SECOND, &now.tv_sec, sizeof(now));
|
||||
now.tv_usec = 0;
|
||||
#else
|
||||
kread(namelist, X_TIME_SECOND, &now, sizeof(now));
|
||||
#endif
|
||||
if (kreadc(namelist, X_TIME_SECOND, &now.tv_sec, sizeof(now))) {
|
||||
now.tv_usec = 0;
|
||||
} else {
|
||||
kread(namelist, X_TIME, &now, sizeof(now));
|
||||
}
|
||||
uptime = now.tv_sec - boottime.tv_sec;
|
||||
if (uptime <= 0 || uptime > 60*60*24*365*10)
|
||||
errx(1, "time makes no sense; namelist must be wrong.");
|
||||
|
@ -1476,6 +1481,23 @@ dohashstat(int verbose, int todo, const char *hashname)
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* kreadc like kread but returns 1 if sucessful, 0 otherwise
|
||||
*/
|
||||
int
|
||||
kreadc(struct nlist *nl, int nlx, void *addr, size_t size)
|
||||
{
|
||||
const char *sym;
|
||||
|
||||
sym = nl[nlx].n_name;
|
||||
if (*sym == '_')
|
||||
++sym;
|
||||
if (nl[nlx].n_type == 0 || nl[nlx].n_value == 0)
|
||||
return 0;
|
||||
deref_kptr((void *)nl[nlx].n_value, addr, size, sym);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* kread reads something from the kernel, given its nlist index in namelist[].
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue