summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjhb <jhb@FreeBSD.org>2008-08-19 21:33:09 +0000
committerjhb <jhb@FreeBSD.org>2008-08-19 21:33:09 +0000
commitc990b20179fd8f3fcbfb695e812666877aa20419 (patch)
tree1dc18c736ab6b496f42c560e76245b53c597656b
parent67b02c52de29cfb44eea11a7c46f7bf5de57bf36 (diff)
downloadFreeBSD-src-c990b20179fd8f3fcbfb695e812666877aa20419.zip
FreeBSD-src-c990b20179fd8f3fcbfb695e812666877aa20419.tar.gz
Use kvm_getcptime(3) to fetch the global CPU time stats from a crashdump
since the 'cp_time' symbol doesn't exist in recent kernels. This fixes iostat and vmstat on crash dumps. MFC after: 1 week
-rw-r--r--usr.bin/vmstat/vmstat.c29
-rw-r--r--usr.sbin/iostat/iostat.c22
2 files changed, 28 insertions, 23 deletions
diff --git a/usr.bin/vmstat/vmstat.c b/usr.bin/vmstat/vmstat.c
index 3b5c5e3..44b199ab 100644
--- a/usr.bin/vmstat/vmstat.c
+++ b/usr.bin/vmstat/vmstat.c
@@ -81,29 +81,27 @@ __FBSDID("$FreeBSD$");
static char da[] = "da";
static struct nlist namelist[] = {
-#define X_CPTIME 0
- { "_cp_time" },
-#define X_SUM 1
+#define X_SUM 0
{ "_cnt" },
-#define X_BOOTTIME 2
+#define X_BOOTTIME 1
{ "_boottime" },
-#define X_HZ 3
+#define X_HZ 2
{ "_hz" },
-#define X_STATHZ 4
+#define X_STATHZ 3
{ "_stathz" },
-#define X_NCHSTATS 5
+#define X_NCHSTATS 4
{ "_nchstats" },
-#define X_INTRNAMES 6
+#define X_INTRNAMES 5
{ "_intrnames" },
-#define X_EINTRNAMES 7
+#define X_EINTRNAMES 6
{ "_eintrnames" },
-#define X_INTRCNT 8
+#define X_INTRCNT 7
{ "_intrcnt" },
-#define X_EINTRCNT 9
+#define X_EINTRCNT 8
{ "_eintrcnt" },
-#define X_KMEMSTATS 10
+#define X_KMEMSTATS 9
{ "_kmemstatistics" },
-#define X_KMEMZONES 11
+#define X_KMEMZONES 10
{ "_kmemzones" },
#ifdef notyet
#define X_DEFICIT XXX
@@ -116,7 +114,7 @@ static struct nlist namelist[] = {
{ "_xstats" },
#define X_END XXX
#else
-#define X_END 12
+#define X_END 11
#endif
{ "" },
};
@@ -610,7 +608,8 @@ dovmstat(unsigned int interval, int reps)
if (!--hdrcnt)
printhdr(ncpus, cpumask);
if (kd != NULL) {
- kread(X_CPTIME, cur.cp_time, sizeof(cur.cp_time));
+ if (kvm_getcptime(kd, cur.cp_time) < 0)
+ errx(1, "kvm_getcptime: %s", kvm_geterr(kd));
} else {
size = sizeof(cur.cp_time);
mysysctl("kern.cp_time", &cur.cp_time, &size, NULL, 0);
diff --git a/usr.sbin/iostat/iostat.c b/usr.sbin/iostat/iostat.c
index b349cd2..d8e0bf4 100644
--- a/usr.sbin/iostat/iostat.c
+++ b/usr.sbin/iostat/iostat.c
@@ -124,11 +124,9 @@ struct nlist namelist[] = {
{ "_tk_nin" },
#define X_TK_NOUT 1
{ "_tk_nout" },
-#define X_CP_TIME 2
- { "_cp_time" },
-#define X_BOOTTIME 3
+#define X_BOOTTIME 2
{ "_boottime" },
-#define X_END 3
+#define X_END 2
{ NULL },
};
@@ -463,11 +461,19 @@ main(int argc, char **argv)
}
if (Cflag > 0) {
- if (readvar(kd, "kern.cp_time", X_CP_TIME,
- &cur.cp_time, sizeof(cur.cp_time)) != 0) {
- Cflag = 0;
- warnx("disabling CPU time statistics");
+ if (kd == NULL) {
+ if (readvar(kd, "kern.cp_time", 0,
+ &cur.cp_time, sizeof(cur.cp_time)) != 0)
+ Cflag = 0;
+ } else {
+ if (kvm_getcptime(kd, cur.cp_time) < 0) {
+ warnx("kvm_getcptime: %s",
+ kvm_geterr(kd));
+ Cflag = 0;
+ }
}
+ if (Cflag == 0)
+ warnx("disabling CPU time statistics");
}
if (!--headercount) {
OpenPOWER on IntegriCloud