Module Name:    src
Committed By:   simonb
Date:           Thu Apr  1 04:41:38 UTC 2021

Modified Files:
        src/sys/kern: init_main.c subr_evcnt.c
        src/sys/sys: evcnt.h

Log Message:
Expose olde style intrcnt interrupt accounting via event counters.
This code will be garbage collected once our last legacy intrcnt
user is update to native evcnts.


To generate a diff of this commit:
cvs rdiff -u -r1.534 -r1.535 src/sys/kern/init_main.c
cvs rdiff -u -r1.13 -r1.14 src/sys/kern/subr_evcnt.c
cvs rdiff -u -r1.8 -r1.9 src/sys/sys/evcnt.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/init_main.c
diff -u src/sys/kern/init_main.c:1.534 src/sys/kern/init_main.c:1.535
--- src/sys/kern/init_main.c:1.534	Sat Dec  5 18:17:01 2020
+++ src/sys/kern/init_main.c	Thu Apr  1 04:41:38 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: init_main.c,v 1.534 2020/12/05 18:17:01 thorpej Exp $	*/
+/*	$NetBSD: init_main.c,v 1.535 2021/04/01 04:41:38 simonb Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009, 2019 The NetBSD Foundation, Inc.
@@ -97,7 +97,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.534 2020/12/05 18:17:01 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.535 2021/04/01 04:41:38 simonb Exp $");
 
 #include "opt_cnmagic.h"
 #include "opt_ddb.h"
@@ -548,6 +548,9 @@ main(void)
 
 	/* Configure the system hardware.  This will enable interrupts. */
 	configure();
+#ifdef __HAVE_LEGACY_INTRCNT
+	evcnt_attach_legacy_intrcnt();
+#endif
 
 	/* Once all CPUs are detected, initialize the per-CPU cprng_fast.  */
 	cprng_fast_init();

Index: src/sys/kern/subr_evcnt.c
diff -u src/sys/kern/subr_evcnt.c:1.13 src/sys/kern/subr_evcnt.c:1.14
--- src/sys/kern/subr_evcnt.c:1.13	Sat Nov 24 17:40:37 2018
+++ src/sys/kern/subr_evcnt.c	Thu Apr  1 04:41:38 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_evcnt.c,v 1.13 2018/11/24 17:40:37 maxv Exp $ */
+/* $NetBSD: subr_evcnt.c,v 1.14 2021/04/01 04:41:38 simonb Exp $ */
 
 /*
  * Copyright (c) 1996, 2000 Christopher G. Demetriou
@@ -77,7 +77,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_evcnt.c,v 1.13 2018/11/24 17:40:37 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_evcnt.c,v 1.14 2021/04/01 04:41:38 simonb Exp $");
 
 #include <sys/param.h>
 #include <sys/evcnt.h>
@@ -86,6 +86,25 @@ __KERNEL_RCSID(0, "$NetBSD: subr_evcnt.c
 #include <sys/sysctl.h>
 #include <sys/systm.h>
 
+/*
+ * Everything related to __HAVE_LEGACY_INTRCNT can disappear once
+ * no more ports are using old-style intrcnt/intrnames interrupt
+ * accounting.  The follow files have __HAVE_LEGACY_INTRCNT code:
+ *
+ *   sys/kern/init_main.c
+ *   sys/kern/subr_evcnt.c
+ *   sys/sys/evcnt.h
+ *   sys/arch/<port>/include/types.h
+ */
+#ifdef _RUMPKERNEL
+/* RUMP doesn't need/want to know about intrcnts */
+#undef __HAVE_LEGACY_INTRCNT
+#endif
+
+#ifdef __HAVE_LEGACY_INTRCNT
+static void evcnt_update_intrcnt(void);
+#endif
+
 /* list of all events */
 struct evcntlist allevents = TAILQ_HEAD_INITIALIZER(allevents);
 static kmutex_t evcnt_lock __cacheline_aligned;
@@ -271,6 +290,9 @@ sysctl_doevcnt(SYSCTLFN_ARGS)
 	needed = 0;
 
 	mutex_enter(&evcnt_lock);
+#ifdef __HAVE_LEGACY_INTRCNT
+	evcnt_update_intrcnt();
+#endif
 	TAILQ_FOREACH(ev, &allevents, ev_list) {
 		if (filter != EVCNT_TYPE_ANY && filter != ev->ev_type)
 			continue;
@@ -356,3 +378,40 @@ SYSCTL_SETUP(sysctl_evcnt_setup, "sysctl
 		       sysctl_doevcnt, 0, NULL, 0,
 		       CTL_KERN, KERN_EVCNT, CTL_EOL);
 }
+
+#ifdef __HAVE_LEGACY_INTRCNT
+extern long intrcnt[], eintrcnt[];
+extern char intrnames[];
+static size_t nintr;
+struct evcnt *intr_evcnts;
+/*
+ * Remove the following when the last intrcnt/intrnames user is cleaned up.
+ */
+void
+evcnt_attach_legacy_intrcnt(void)
+{
+	size_t i;
+	const char *cp;
+
+	nintr = ((intptr_t)eintrcnt - (intptr_t)intrcnt) / sizeof(long);
+	intr_evcnts = kmem_alloc(sizeof(struct evcnt) * nintr, KM_SLEEP);
+	for (cp = intrnames, i = 0; i < nintr; i++) {
+		evcnt_attach_dynamic(&intr_evcnts[i], EVCNT_TYPE_INTR,
+		    NULL, "cpu", cp);
+		cp += strlen(cp) + 1;
+	}
+}
+
+static void
+evcnt_update_intrcnt(void)
+{
+	size_t i;
+
+	KASSERT(nintr > 0);
+	KASSERT(intr_evcnts != NULL);
+
+	for (i = 0; i < nintr; i++) {
+		intr_evcnts[i].ev_count = intrcnt[i];
+	}
+}
+#endif

Index: src/sys/sys/evcnt.h
diff -u src/sys/sys/evcnt.h:1.8 src/sys/sys/evcnt.h:1.9
--- src/sys/sys/evcnt.h:1.8	Sat Jan 29 18:21:22 2011
+++ src/sys/sys/evcnt.h	Thu Apr  1 04:41:38 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: evcnt.h,v 1.8 2011/01/29 18:21:22 matt Exp $	*/
+/*	$NetBSD: evcnt.h,v 1.9 2021/04/01 04:41:38 simonb Exp $	*/
 
 /*
  * Copyright (c) 1996, 2000 Christopher G. Demetriou
@@ -104,6 +104,10 @@ TAILQ_HEAD(evcntlist, evcnt);
 #define	EVCNT_TYPE_INTR		1	/* interrupt; count with vmstat -i */
 #define	EVCNT_TYPE_TRAP		2	/* processor trap/execption */
 
+#ifdef __HAVE_LEGACY_INTRCNT
+void evcnt_attach_legacy_intrcnt(void);
+#endif
+
 /*
  * initializer for an event count structure.  the lengths are initted and
  * it is added to the evcnt list at attach time.

Reply via email to