Module Name: src Committed By: skrll Date: Mon Dec 25 13:21:30 UTC 2023
Modified Files: src/sys/arch/riscv/fdt: intc_fdt.c src/sys/arch/riscv/include: cpu.h Log Message: Count interrupts across harts and their local interrupt controllers correctly. To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/sys/arch/riscv/fdt/intc_fdt.c cvs rdiff -u -r1.14 -r1.15 src/sys/arch/riscv/include/cpu.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/arch/riscv/fdt/intc_fdt.c diff -u src/sys/arch/riscv/fdt/intc_fdt.c:1.2 src/sys/arch/riscv/fdt/intc_fdt.c:1.3 --- src/sys/arch/riscv/fdt/intc_fdt.c:1.2 Mon Jun 12 19:04:13 2023 +++ src/sys/arch/riscv/fdt/intc_fdt.c Mon Dec 25 13:21:30 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: intc_fdt.c,v 1.2 2023/06/12 19:04:13 skrll Exp $ */ +/* $NetBSD: intc_fdt.c,v 1.3 2023/12/25 13:21:30 skrll Exp $ */ /*- * Copyright (c) 2023 The NetBSD Foundation, Inc. @@ -32,7 +32,7 @@ #include "opt_multiprocessor.h" #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: intc_fdt.c,v 1.2 2023/06/12 19:04:13 skrll Exp $"); +__KERNEL_RCSID(0, "$NetBSD: intc_fdt.c,v 1.3 2023/12/25 13:21:30 skrll Exp $"); #include <sys/param.h> @@ -90,13 +90,36 @@ struct intc_fdt_softc { struct intc_irq *sc_irq[IRQ_NSOURCES]; - struct evcnt *sc_evs[IRQ_NSOURCES]; + struct evcnt sc_evs[IRQ_NSOURCES]; struct cpu_info *sc_ci; cpuid_t sc_hartid; }; -static struct intc_fdt_softc *intc_sc; +static const char * const intc_sources[IRQ_NSOURCES] = { + /* Software interrupts */ + "(reserved)", + "Supervisor software", + "Virtual Supervisor software", + "Machine software", + + /* Timer interrupts */ + "(reserved)", + "Supervisor timer", + "Virtual Supervisor timer", + "Machine timer", + + /* External interrupts */ + "(reserved)", + "Supervisor external", + "Virtual Supervisor external", + "Machine external", + + "(reserved)", + "Supervisor guest external.", + "(reserved)", + "(reserved)" +}; static void * @@ -118,6 +141,9 @@ intc_intr_establish(struct intc_fdt_soft irq->intr_source = source; TAILQ_INIT(&irq->intr_handlers); sc->sc_irq[source] = irq; + + evcnt_attach_dynamic(&sc->sc_evs[source], EVCNT_TYPE_INTR, NULL, + device_xname(sc->sc_dev), intc_sources[source]); } else { if (irq->intr_arg == NULL || arg == NULL) { device_printf(dev, @@ -185,31 +211,6 @@ intc_fdt_disestablish(device_t dev, void } -static const char * const intc_sources[IRQ_NSOURCES] = { - /* Software interrupts */ - "(reserved)", - "Supervisor software", - "Virtual Supervisor software", - "Machine software", - - /* Timer interrupts */ - "(reserved)", - "Supervisor timer", - "Virtual Supervisor timer", - "Machine timer", - - /* External interrupts */ - "(reserved)", - "Supervisor external", - "Virtual Supervisor external", - "Machine external", - - "(reserved)", - "Supervisor guest external.", - "(reserved)", - "(reserved)" -}; - static bool intc_fdt_intrstr(device_t dev, u_int *specifier, char *buf, size_t buflen) { @@ -246,7 +247,7 @@ intc_intr_handler(struct trapframe *tf, KASSERT(CAUSE_INTERRUPT_P(cause)); - struct intc_fdt_softc * const sc = intc_sc; + struct intc_fdt_softc * const sc = ci->ci_intcsoftc; ci->ci_intr_depth++; ci->ci_data.cpu_nintr++; @@ -259,6 +260,8 @@ intc_intr_handler(struct trapframe *tf, int source = ffs(pending) - 1; struct intc_irq *irq = sc->sc_irq[source]; + sc->sc_evs[source].ev_count++; + KASSERTMSG(irq != NULL, "source %d\n", source); if (irq) { @@ -326,13 +329,13 @@ intc_attach(device_t parent, device_t se aprint_normal(": local interrupt controller\n"); struct intc_fdt_softc * const sc = device_private(self); - intc_sc = sc; riscv_intr_set_handler(intc_intr_handler); sc->sc_dev = self; sc->sc_ci = ci; sc->sc_hartid = ci->ci_cpuid; + ci->ci_intcsoftc = sc; intc_intr_establish(sc, IRQ_SUPERVISOR_TIMER, IPL_SCHED, IST_MPSAFE, riscv_timer_intr, NULL, "clock"); Index: src/sys/arch/riscv/include/cpu.h diff -u src/sys/arch/riscv/include/cpu.h:1.14 src/sys/arch/riscv/include/cpu.h:1.15 --- src/sys/arch/riscv/include/cpu.h:1.14 Sun Sep 3 08:48:20 2023 +++ src/sys/arch/riscv/include/cpu.h Mon Dec 25 13:21:30 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: cpu.h,v 1.14 2023/09/03 08:48:20 skrll Exp $ */ +/* $NetBSD: cpu.h,v 1.15 2023/12/25 13:21:30 skrll Exp $ */ /*- * Copyright (c) 2014 The NetBSD Foundation, Inc. @@ -92,6 +92,7 @@ struct cpu_info { #define CPUF_RUNNING __BIT(2) /* CPU is running */ #define CPUF_PAUSED __BIT(3) /* CPU is paused */ + void *ci_intcsoftc; volatile u_long ci_request_ipis; /* bitmask of IPIs requested */ u_long ci_active_ipis; /* bitmask of IPIs being serviced */