git: dfea72b70f3f - stable/13 - riscv: improve KTR_TRAP trace entries

From: Mitchell Horne <mhorne_at_FreeBSD.org>
Date: Fri, 07 Jul 2023 19:25:05 UTC
The branch stable/13 has been updated by mhorne:

URL: https://cgit.FreeBSD.org/src/commit/?id=dfea72b70f3fd83426d71252fa33f8f04b3d90c9

commit dfea72b70f3fd83426d71252fa33f8f04b3d90c9
Author:     Mitchell Horne <mhorne@FreeBSD.org>
AuthorDate: 2023-06-20 14:52:26 +0000
Commit:     Mitchell Horne <mhorne@FreeBSD.org>
CommitDate: 2023-07-07 19:20:51 +0000

    riscv: improve KTR_TRAP trace entries
    
    For more informative records of exceptions, include key details such as
    the exception code and stval register contents. Remove the curthread
    argument as it is redundant (saved with every ktr entry), and the
    trapframe as it is somewhat meaningless.
    
    Add a new KTR_TRAP trace record for interrupts.
    
    Reviewed by:    markj, jhb
    MFC after:      3 days
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D40584
    
    (cherry picked from commit 7756232199adf60343ae0b940e2b27fe363905bc)
---
 sys/riscv/riscv/intr_machdep.c | 3 +++
 sys/riscv/riscv/trap.c         | 8 ++++----
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/sys/riscv/riscv/intr_machdep.c b/sys/riscv/riscv/intr_machdep.c
index d84f4ea1cb91..1ee2c0984205 100644
--- a/sys/riscv/riscv/intr_machdep.c
+++ b/sys/riscv/riscv/intr_machdep.c
@@ -163,6 +163,9 @@ riscv_cpu_intr(struct trapframe *frame)
 
 	active_irq = frame->tf_scause & SCAUSE_CODE;
 
+	CTR3(KTR_TRAP, "%s: irq=%d, umode=%d", __func__, active_irq,
+	    TRAPF_USERMODE(frame));
+
 	switch (active_irq) {
 	case IRQ_SOFTWARE_USER:
 	case IRQ_SOFTWARE_SUPERVISOR:
diff --git a/sys/riscv/riscv/trap.c b/sys/riscv/riscv/trap.c
index 4da6c9d21502..9e75f0e0530d 100644
--- a/sys/riscv/riscv/trap.c
+++ b/sys/riscv/riscv/trap.c
@@ -292,8 +292,8 @@ do_trap_supervisor(struct trapframe *frame)
 		return;
 #endif
 
-	CTR3(KTR_TRAP, "do_trap_supervisor: curthread: %p, sepc: %lx, frame: %p",
-	    curthread, frame->tf_sepc, frame);
+	CTR4(KTR_TRAP, "%s: exception=%lu, sepc=%lx, stval=%lx", __func__,
+	    exception, frame->tf_sepc, frame->tf_stval);
 
 	switch (exception) {
 	case SCAUSE_LOAD_ACCESS_FAULT:
@@ -366,8 +366,8 @@ do_trap_user(struct trapframe *frame)
 	}
 	intr_enable();
 
-	CTR3(KTR_TRAP, "do_trap_user: curthread: %p, sepc: %lx, frame: %p",
-	    curthread, frame->tf_sepc, frame);
+	CTR4(KTR_TRAP, "%s: exception=%lu, sepc=%lx, stval=%lx", __func__,
+	    exception, frame->tf_sepc, frame->tf_stval);
 
 	switch (exception) {
 	case SCAUSE_LOAD_ACCESS_FAULT: