Skip to content

Commit

Permalink
plic, aplic: handle all pending interrupts for hart
Browse files Browse the repository at this point in the history
Otherwise, we are going to take another interrupt-induced exception
immediately upon execution of the sret instruction -- overall wasting
cycles.

Reviewed by:	br
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D47134
  • Loading branch information
mhorne committed Oct 30, 2024
1 parent 5050fdb commit d584228
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
18 changes: 10 additions & 8 deletions sys/riscv/riscv/aplic.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,21 +224,23 @@ aplic_intr(void *arg)
{
struct aplic_softc *sc;
struct trapframe *tf;
u_int claimi, prio, irq;
uint32_t claimi;
u_int prio, irq;
int cpu;

sc = arg;
cpu = PCPU_GET(cpuid);

/* Claim any pending interrupt. */
claimi = aplic_read(sc, APLIC_IDC_CLAIMI(sc, cpu));
prio = APLIC_IDC_CLAIMI_PRIO(claimi);
irq = APLIC_IDC_CLAIMI_IRQ(claimi);
/* Claim all pending interrupts. */
while ((claimi = aplic_read(sc, APLIC_IDC_CLAIMI(sc, cpu))) != 0) {
prio = APLIC_IDC_CLAIMI_PRIO(claimi);
irq = APLIC_IDC_CLAIMI_IRQ(claimi);

KASSERT((irq != 0), ("Invalid IRQ 0"));
KASSERT((irq != 0), ("Invalid IRQ 0"));

tf = curthread->td_intr_frame;
aplic_irq_dispatch(sc, irq, prio, tf);
tf = curthread->td_intr_frame;
aplic_irq_dispatch(sc, irq, prio, tf);
}

return (FILTER_HANDLED);
}
Expand Down
5 changes: 2 additions & 3 deletions sys/riscv/riscv/plic.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,8 @@ plic_intr(void *arg)
sc = arg;
cpu = PCPU_GET(cpuid);

/* Claim any pending interrupt. */
pending = RD4(sc, PLIC_CLAIM(sc, cpu));
if (pending) {
/* Claim all pending interrupts. */
while ((pending = RD4(sc, PLIC_CLAIM(sc, cpu))) != 0) {
tf = curthread->td_intr_frame;
plic_irq_dispatch(sc, pending, tf);
}
Expand Down

0 comments on commit d584228

Please sign in to comment.