From 3242c748ea74256b58d8ef0f7a7783b8473847c3 Mon Sep 17 00:00:00 2001 From: Sepherosa Ziehau Date: Sun, 10 Apr 2011 19:18:17 +0800 Subject: [PATCH] intrcnt: Fix long standing interrupt name/count array mismatch hw.intrnames always returns all interrupts' name, while hw.intrcnt only returns count of interrupts that get installed. This mismatching cause utilities like vmstat(8) to report wrong interrupt counts. Keep the old symantic of hw.intrcnt and add hw.intrcnt_all, which returns count of all interrupts. Let vmstat(8) and systat(1) use hw.intrcnt_all. --- sys/kern/kern_intr.c | 21 +++++++++++++++++++++ usr.bin/systat/vmstat.c | 2 +- usr.bin/vmstat/vmstat.c | 2 +- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/sys/kern/kern_intr.c b/sys/kern/kern_intr.c index 31860a1cc1..7d9fa22500 100644 --- a/sys/kern/kern_intr.c +++ b/sys/kern/kern_intr.c @@ -1077,6 +1077,27 @@ failed: SYSCTL_PROC(_hw, OID_AUTO, intrcnt, CTLTYPE_OPAQUE | CTLFLAG_RD, NULL, 0, sysctl_intrcnt, "", "Interrupt Counts"); +static int +sysctl_intrcnt_all(SYSCTL_HANDLER_ARGS) +{ + struct intr_info *info; + int error = 0; + int intr; + + for (intr = 0; intr < MAX_INTS; ++intr) { + info = &intr_info_ary[intr]; + + error = SYSCTL_OUT(req, &info->i_count, sizeof(info->i_count)); + if (error) + goto failed; + } +failed: + return(error); +} + +SYSCTL_PROC(_hw, OID_AUTO, intrcnt_all, CTLTYPE_OPAQUE | CTLFLAG_RD, + NULL, 0, sysctl_intrcnt_all, "", "Interrupt Counts"); + static void int_moveto_destcpu(int *orig_cpuid0, int *cpuid0, int intr) { diff --git a/usr.bin/systat/vmstat.c b/usr.bin/systat/vmstat.c index 6d4e6fe066..c4d4bed414 100644 --- a/usr.bin/systat/vmstat.c +++ b/usr.bin/systat/vmstat.c @@ -780,7 +780,7 @@ getinfo(struct Info *ls) if (nintr) { size = nintr * sizeof(ls->intrcnt[0]); - sysctlbyname("hw.intrcnt", ls->intrcnt, &size, NULL, 0); + sysctlbyname("hw.intrcnt_all", ls->intrcnt, &size, NULL, 0); } size = sizeof(ls->Total); if (sysctlbyname("vm.vmtotal", &ls->Total, &size, NULL, 0) < 0) { diff --git a/usr.bin/vmstat/vmstat.c b/usr.bin/vmstat/vmstat.c index 7755821fb0..ac5cbb342d 100644 --- a/usr.bin/vmstat/vmstat.c +++ b/usr.bin/vmstat/vmstat.c @@ -743,7 +743,7 @@ dointr(void) intrcnt = calloc(nintr, sizeof(*intrcnt)); if (intrcnt == NULL) err(1, "malloc"); - sysctlbyname("hw.intrcnt", intrcnt, &size, NULL, 0); + sysctlbyname("hw.intrcnt_all", intrcnt, &size, NULL, 0); nwidth = 21; for (i = 0; i < nintr; ++i) { -- 2.41.0