Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/tprof don't call kpreempt_{disable,enable}() from an...



details:   https://anonhg.NetBSD.org/src/rev/9947feb9d5f7
branches:  trunk
changeset: 372475:9947feb9d5f7
user:      ryo <ryo%NetBSD.org@localhost>
date:      Thu Dec 01 00:27:59 2022 +0000

description:
don't call kpreempt_{disable,enable}() from an interrupt handler.

Fixed a problem in which the system would freeze if a high load (e.g., build.sh -j20)
was applied while running `tprof monitor -e LsNotHaltedCyc ...' on x86.

This almost eliminates the problem, but still is not enough. tprof_x86 uses NMI
interrupts, which are interrupted even in splhigh(), leaving the possibility of
being interrupted in the splhigh section of percpu_cpu_swap().

diffstat:

 sys/dev/tprof/tprof.c |  20 ++++++++++++++------
 1 files changed, 14 insertions(+), 6 deletions(-)

diffs (57 lines):

diff -r 45f80c8dd821 -r 9947feb9d5f7 sys/dev/tprof/tprof.c
--- a/sys/dev/tprof/tprof.c     Wed Nov 30 20:59:28 2022 +0000
+++ b/sys/dev/tprof/tprof.c     Thu Dec 01 00:27:59 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tprof.c,v 1.17 2022/03/28 12:33:21 riastradh Exp $     */
+/*     $NetBSD: tprof.c,v 1.18 2022/12/01 00:27:59 ryo Exp $   */
 
 /*-
  * Copyright (c)2008,2009,2010 YAMAMOTO Takashi,
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tprof.c,v 1.17 2022/03/28 12:33:21 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tprof.c,v 1.18 2022/12/01 00:27:59 ryo Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -115,9 +115,18 @@
 static struct tprof_stat tprof_stat;   /* L: */
 
 static tprof_cpu_t *
+tprof_cpu_direct(struct cpu_info *ci)
+{
+       tprof_cpu_t **cp;
+
+       cp = percpu_getptr_remote(tprof_cpus, ci);
+       return *cp;
+}
+
+static tprof_cpu_t *
 tprof_cpu(struct cpu_info *ci)
 {
-       tprof_cpu_t **cp, *c;
+       tprof_cpu_t *c;
 
        /*
         * As long as xcalls are blocked -- e.g., by kpreempt_disable
@@ -126,8 +135,7 @@
         * moved to a new buffer, but we can safely read from it.
         */
        kpreempt_disable();
-       cp = percpu_getptr_remote(tprof_cpus, ci);
-       c = *cp;
+       c = tprof_cpu_direct(ci);
        kpreempt_enable();
 
        return c;
@@ -433,7 +441,7 @@
 void
 tprof_sample(void *unused, const tprof_frame_info_t *tfi)
 {
-       tprof_cpu_t * const c = tprof_curcpu();
+       tprof_cpu_t * const c = tprof_cpu_direct(curcpu());
        tprof_buf_t * const buf = c->c_buf;
        tprof_sample_t *sp;
        const uintptr_t pc = tfi->tfi_pc;



Home | Main Index | Thread Index | Old Index