Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Expose olde style intrcnt interrupt accounting via event...



details:   https://anonhg.NetBSD.org/src/rev/8aa22a4854f8
branches:  trunk
changeset: 982105:8aa22a4854f8
user:      simonb <simonb%NetBSD.org@localhost>
date:      Thu Apr 01 04:41:38 2021 +0000

description:
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.

diffstat:

 sys/kern/init_main.c  |   7 ++++-
 sys/kern/subr_evcnt.c |  63 +++++++++++++++++++++++++++++++++++++++++++++++++-
 sys/sys/evcnt.h       |   6 ++++-
 3 files changed, 71 insertions(+), 5 deletions(-)

diffs (143 lines):

diff -r b50f30cd3bec -r 8aa22a4854f8 sys/kern/init_main.c
--- a/sys/kern/init_main.c      Thu Apr 01 04:35:45 2021 +0000
+++ b/sys/kern/init_main.c      Thu Apr 01 04:41:38 2021 +0000
@@ -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 @@
 
        /* 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();
diff -r b50f30cd3bec -r 8aa22a4854f8 sys/kern/subr_evcnt.c
--- a/sys/kern/subr_evcnt.c     Thu Apr 01 04:35:45 2021 +0000
+++ b/sys/kern/subr_evcnt.c     Thu Apr 01 04:41:38 2021 +0000
@@ -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 @@
 #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 @@
        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_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
diff -r b50f30cd3bec -r 8aa22a4854f8 sys/sys/evcnt.h
--- a/sys/sys/evcnt.h   Thu Apr 01 04:35:45 2021 +0000
+++ b/sys/sys/evcnt.h   Thu Apr 01 04:41:38 2021 +0000
@@ -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 @@
 #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.



Home | Main Index | Thread Index | Old Index