Module Name:    src
Committed By:   ryo
Date:           Thu Dec  1 00:27:59 UTC 2022

Modified Files:
        src/sys/dev/tprof: tprof.c

Log Message:
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().


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/sys/dev/tprof/tprof.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/tprof/tprof.c
diff -u src/sys/dev/tprof/tprof.c:1.17 src/sys/dev/tprof/tprof.c:1.18
--- src/sys/dev/tprof/tprof.c:1.17	Mon Mar 28 12:33:21 2022
+++ src/sys/dev/tprof/tprof.c	Thu Dec  1 00:27:59 2022
@@ -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 kcondvar_t tprof_cv;		/* L: */
 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 @@ tprof_cpu(struct cpu_info *ci)
 	 * 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 @@ tprof_backend_lookup(const char *name)
 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;

Reply via email to