tech-kern archive

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

Re: xcall while cold == 1



On 2017/12/26 11:59, Masanobu SAITOH wrote:
On 2017/12/25 20:26, Martin Husemann wrote:
On Mon, Dec 25, 2017 at 03:42:06PM +0900, Masanobu SAITOH wrote:
  Is this intended behavior? Is it possible to use xcall while
cold==1?

Cold is (as you noted) not the right condition (but pretty close).

Xcalls don't really make any sense before cpus have been spun up.
In your case it might be good to do the loop checking for SPCF_RUNNING
and if <= 1 is found, use the code path for single cpu systems (the
current else statatement).

In init_main.c::configure2():

        cold = 0;       /* clocks are running, we're warm now! */
        s = splsched();
        curcpu()->ci_schedstate.spc_flags |= SPCF_RUNNING;
        splx(s);

        /* Boot the secondary processors. */
        for (CPU_INFO_FOREACH(cii, ci)) {
                uvm_cpu_attach(ci);
        }
        mp_online = true;

so checking mp_online is the best, right?

Martin


Updated diff:
-----------------
Index: kern_softint.c
===================================================================
RCS file: /cvsroot/src/sys/kern/kern_softint.c,v
retrieving revision 1.44
diff -u -p -r1.44 kern_softint.c
--- kern_softint.c	22 Nov 2017 02:20:21 -0000	1.44
+++ kern_softint.c	26 Dec 2017 07:47:57 -0000
@@ -177,6 +177,7 @@ __KERNEL_RCSID(0, "$NetBSD: kern_softint
 #include <sys/intr.h>
 #include <sys/ipi.h>
 #include <sys/mutex.h>
+#include <sys/kernel.h>
 #include <sys/kthread.h>
 #include <sys/evcnt.h>
 #include <sys/cpu.h>
@@ -430,8 +431,10 @@ softint_disestablish(void *arg)
 	 * it again.  So, we are only looking for handler records with
 	 * SOFTINT_ACTIVE already set.
 	 */
-	where = xc_broadcast(0, (xcfunc_t)nullop, NULL, NULL);
-	xc_wait(where);
+	if (__predict_true(mp_online)) {
+		where = xc_broadcast(0, (xcfunc_t)nullop, NULL, NULL);
+		xc_wait(where);
+	}
for (;;) {
 		/* Collect flag values from each CPU. */
Index: subr_pserialize.c
===================================================================
RCS file: /cvsroot/src/sys/kern/subr_pserialize.c,v
retrieving revision 1.9
diff -u -p -r1.9 subr_pserialize.c
--- subr_pserialize.c	21 Nov 2017 08:49:14 -0000	1.9
+++ subr_pserialize.c	26 Dec 2017 07:47:57 -0000
@@ -157,6 +157,11 @@ pserialize_perform(pserialize_t psz)
 	KASSERT(psz->psz_owner == NULL);
 	KASSERT(ncpu > 0);
+ if (__predict_false(mp_online == false)) {
+		psz_ev_excl.ev_count++;
+		return;
+	}
+
 	/*
 	 * Set up the object and put it onto the queue.  The lock
 	 * activity here provides the necessary memory barrier to
Index: subr_psref.c
===================================================================
RCS file: /cvsroot/src/sys/kern/subr_psref.c,v
retrieving revision 1.9
diff -u -p -r1.9 subr_psref.c
--- subr_psref.c	14 Dec 2017 05:45:55 -0000	1.9
+++ subr_psref.c	26 Dec 2017 07:47:57 -0000
@@ -429,8 +429,14 @@ psreffed_p(struct psref_target *target,
 		.ret = false,
 	};
- /* Ask all CPUs to say whether they hold a psref to the target. */
-	xc_wait(xc_broadcast(0, &psreffed_p_xc, &P, NULL));
+	if (__predict_true(mp_online)) {
+		/*
+		 * Ask all CPUs to say whether they hold a psref to the
+		 * target.
+		 */
+		xc_wait(xc_broadcast(0, &psreffed_p_xc, &P, NULL));
+	} else
+		psreffed_p_xc(&P, NULL);
return P.ret;
 }
-----------------

 It might not be required to increment psz_ev_excl evcnt in softint_disestablish()
when mp_online == false.

--
-----------------------------------------------
                SAITOH Masanobu (msaitoh%execsw.org@localhost
                                 msaitoh%netbsd.org@localhost)



Home | Main Index | Thread Index | Old Index