Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 24 Jun 2006 02:23:45 GMT
From:      Kip Macy <kmacy@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 99913 for review
Message-ID:  <200606240223.k5O2NjJF087630@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=99913

Change 99913 by kmacy@kmacy_storage:sun4v_work_ifc on 2006/06/24 02:23:21

	remove sched_lock

Affected files ...

.. //depot/projects/kmacy_sun4v/src/sys/dev/md/md.c#4 edit
.. //depot/projects/kmacy_sun4v/src/sys/fs/procfs/procfs_ctl.c#3 edit
.. //depot/projects/kmacy_sun4v/src/sys/fs/procfs/procfs_status.c#3 edit
.. //depot/projects/kmacy_sun4v/src/sys/geom/eli/g_eli.c#5 edit
.. //depot/projects/kmacy_sun4v/src/sys/geom/geom_kern.c#3 edit
.. //depot/projects/kmacy_sun4v/src/sys/geom/mirror/g_mirror.c#5 edit
.. //depot/projects/kmacy_sun4v/src/sys/geom/raid3/g_raid3.c#5 edit
.. //depot/projects/kmacy_sun4v/src/sys/kern/init_main.c#8 edit
.. //depot/projects/kmacy_sun4v/src/sys/kern/kern_acct.c#4 edit
.. //depot/projects/kmacy_sun4v/src/sys/kern/kern_clock.c#6 edit
.. //depot/projects/kmacy_sun4v/src/sys/kern/kern_cpu.c#4 edit
.. //depot/projects/kmacy_sun4v/src/sys/kern/kern_exit.c#7 edit
.. //depot/projects/kmacy_sun4v/src/sys/kern/kern_fork.c#7 edit
.. //depot/projects/kmacy_sun4v/src/sys/kern/kern_idle.c#7 edit
.. //depot/projects/kmacy_sun4v/src/sys/kern/kern_intr.c#6 edit
.. //depot/projects/kmacy_sun4v/src/sys/kern/kern_kthread.c#3 edit
.. //depot/projects/kmacy_sun4v/src/sys/kern/kern_lockf.c#3 edit
.. //depot/projects/kmacy_sun4v/src/sys/kern/kern_mutex.c#16 edit
.. //depot/projects/kmacy_sun4v/src/sys/kern/kern_poll.c#5 edit
.. //depot/projects/kmacy_sun4v/src/sys/kern/kern_proc.c#6 edit
.. //depot/projects/kmacy_sun4v/src/sys/kern/kern_resource.c#7 edit
.. //depot/projects/kmacy_sun4v/src/sys/kern/kern_shutdown.c#5 edit
.. //depot/projects/kmacy_sun4v/src/sys/kern/kern_sig.c#10 edit
.. //depot/projects/kmacy_sun4v/src/sys/kern/kern_subr.c#4 edit
.. //depot/projects/kmacy_sun4v/src/sys/kern/kern_switch.c#9 edit
.. //depot/projects/kmacy_sun4v/src/sys/kern/kern_synch.c#8 edit
.. //depot/projects/kmacy_sun4v/src/sys/kern/kern_thr.c#6 edit
.. //depot/projects/kmacy_sun4v/src/sys/kern/kern_thread.c#6 edit
.. //depot/projects/kmacy_sun4v/src/sys/kern/kern_time.c#5 edit
.. //depot/projects/kmacy_sun4v/src/sys/kern/sched_4bsd.c#10 edit
.. //depot/projects/kmacy_sun4v/src/sys/kern/subr_prof.c#4 edit
.. //depot/projects/kmacy_sun4v/src/sys/kern/subr_sleepqueue.c#8 edit
.. //depot/projects/kmacy_sun4v/src/sys/kern/subr_smp.c#4 edit
.. //depot/projects/kmacy_sun4v/src/sys/kern/subr_taskqueue.c#6 edit
.. //depot/projects/kmacy_sun4v/src/sys/kern/subr_trap.c#5 edit
.. //depot/projects/kmacy_sun4v/src/sys/kern/subr_turnstile.c#7 edit
.. //depot/projects/kmacy_sun4v/src/sys/kern/subr_witness.c#8 edit
.. //depot/projects/kmacy_sun4v/src/sys/kern/sys_generic.c#4 edit
.. //depot/projects/kmacy_sun4v/src/sys/kern/sys_process.c#7 edit
.. //depot/projects/kmacy_sun4v/src/sys/kern/tty.c#4 edit
.. //depot/projects/kmacy_sun4v/src/sys/posix4/ksched.c#7 edit
.. //depot/projects/kmacy_sun4v/src/sys/sparc64/sparc64/genassym.c#23 edit
.. //depot/projects/kmacy_sun4v/src/sys/sun4v/include/pcpu.h#18 edit
.. //depot/projects/kmacy_sun4v/src/sys/sun4v/include/smp.h#5 edit
.. //depot/projects/kmacy_sun4v/src/sys/sun4v/sun4v/exception.S#63 edit
.. //depot/projects/kmacy_sun4v/src/sys/sun4v/sun4v/machdep.c#26 edit
.. //depot/projects/kmacy_sun4v/src/sys/sun4v/sun4v/mp_machdep.c#9 edit
.. //depot/projects/kmacy_sun4v/src/sys/sun4v/sun4v/pmap.c#65 edit
.. //depot/projects/kmacy_sun4v/src/sys/sun4v/sun4v/swtch.S#23 edit
.. //depot/projects/kmacy_sun4v/src/sys/sun4v/sun4v/trap.c#16 edit
.. //depot/projects/kmacy_sun4v/src/sys/sun4v/sun4v/vm_machdep.c#11 edit
.. //depot/projects/kmacy_sun4v/src/sys/sun4v/sun4v/wbuf.S#12 edit
.. //depot/projects/kmacy_sun4v/src/sys/sys/mutex.h#8 edit
.. //depot/projects/kmacy_sun4v/src/sys/sys/pcpu.h#5 edit
.. //depot/projects/kmacy_sun4v/src/sys/sys/pmckern.h#4 edit
.. //depot/projects/kmacy_sun4v/src/sys/sys/proc.h#9 edit
.. //depot/projects/kmacy_sun4v/src/sys/sys/runq.h#5 edit
.. //depot/projects/kmacy_sun4v/src/sys/sys/sched.h#5 edit
.. //depot/projects/kmacy_sun4v/src/sys/ufs/ffs/ffs_snapshot.c#6 edit
.. //depot/projects/kmacy_sun4v/src/sys/vm/vm_glue.c#8 edit
.. //depot/projects/kmacy_sun4v/src/sys/vm/vm_meter.c#6 edit
.. //depot/projects/kmacy_sun4v/src/sys/vm/vm_pageout.c#5 edit
.. //depot/projects/kmacy_sun4v/src/sys/vm/vm_zeroidle.c#5 edit

Differences ...

==== //depot/projects/kmacy_sun4v/src/sys/dev/md/md.c#4 (text+ko) ====

@@ -647,9 +647,10 @@
 	int error;
 
 	sc = arg;
-	mtx_lock_spin(&sched_lock);
+	TD_SLOCK(curthread);
 	sched_prio(curthread, PRIBIO);
-	mtx_unlock_spin(&sched_lock);
+	TD_SUNLOCK(curthread);
+
 
 	for (;;) {
 		mtx_lock(&sc->queue_mtx);

==== //depot/projects/kmacy_sun4v/src/sys/fs/procfs/procfs_ctl.c#3 (text+ko) ====

@@ -47,6 +47,7 @@
 #include <sys/signalvar.h>
 #include <sys/sx.h>
 #include <sys/uio.h>
+#include <sys/ktr.h>
 
 #include <fs/pseudofs/pseudofs.h>
 #include <fs/procfs/procfs.h>
@@ -286,9 +287,9 @@
 		panic("procfs_control");
 	}
 
-	mtx_lock_spin(&sched_lock);
+	PROC_SLOCK(p);
 	thread_unsuspend(p); /* If it can run, let it do so. */
-	mtx_unlock_spin(&sched_lock);
+	PROC_SUNLOCK(p);
 	return (0);
 }
 
@@ -344,9 +345,10 @@
 #endif
 				/* XXXKSE: */
 				p->p_flag &= ~P_STOPPED_SIG;
-				mtx_lock_spin(&sched_lock);
+				PROC_SLOCK(p);
 				thread_unsuspend(p);
-				mtx_unlock_spin(&sched_lock);
+				PROC_SUNLOCK(p);
+
 			} else
 				psignal(p, nm->nm_val);
 			PROC_UNLOCK(p);

==== //depot/projects/kmacy_sun4v/src/sys/fs/procfs/procfs_status.c#3 (text+ko) ====

@@ -52,6 +52,7 @@
 #include <sys/sbuf.h>
 #include <sys/sysent.h>
 #include <sys/tty.h>
+#include <sys/ktr.h>
 
 #include <vm/vm.h>
 #include <vm/pmap.h>
@@ -112,19 +113,17 @@
 		sbuf_printf(sb, "noflags");
 	}
 
-	mtx_lock_spin(&sched_lock);
-	if (p->p_flag & P_SA)
-		wmesg = "-kse- ";
-	else {
-		tdfirst = FIRST_THREAD_IN_PROC(p);
-		if (tdfirst->td_wchan != NULL) {
-			KASSERT(tdfirst->td_wmesg != NULL,
-			    ("wchan %p has no wmesg", tdfirst->td_wchan));
-			wmesg = tdfirst->td_wmesg;
-		} else
-			wmesg = "nochan";
-	}
-	mtx_unlock_spin(&sched_lock);
+	PROC_SLOCK(p);
+	tdfirst = FIRST_THREAD_IN_PROC(p);
+	TD_SLOCK(tdfirst);
+	if (tdfirst->td_wchan != NULL) {
+		KASSERT(tdfirst->td_wmesg != NULL,
+			("wchan %p has no wmesg", tdfirst->td_wchan));
+		wmesg = tdfirst->td_wmesg;
+	} else
+		wmesg = "nochan";
+	TD_SUNLOCK(tdfirst);
+	PROC_SUNLOCK(p);
 
 	if (p->p_sflag & PS_INMEM) {
 		struct timeval start, ut, st;

==== //depot/projects/kmacy_sun4v/src/sys/geom/eli/g_eli.c#5 (text+ko) ====

@@ -399,11 +399,12 @@
 
 	wr = arg;
 	sc = wr->w_softc;
-	mtx_lock_spin(&sched_lock);
+	TD_SLOCK(curthread);
 	sched_prio(curthread, PRIBIO);
-	if (sc->sc_crypto == G_ELI_CRYPTO_SW && g_eli_threads == 0)
+	TD_SUNLOCK(curthread);
+	if (sc->sc_crypto == G_ELI_CRYPTO_SW && g_eli_threads == 0) 
 		sched_bind(curthread, wr->w_number);
-	mtx_unlock_spin(&sched_lock);
+
 
 	G_ELI_DEBUG(1, "Thread %s started.", curthread->td_proc->p_comm);
 

==== //depot/projects/kmacy_sun4v/src/sys/geom/geom_kern.c#3 (text+ko) ====

@@ -88,9 +88,9 @@
 	struct thread *tp = FIRST_THREAD_IN_PROC(p);
 
 	mtx_assert(&Giant, MA_NOTOWNED);
-	mtx_lock_spin(&sched_lock);
+	TD_SLOCK(tp);
 	sched_prio(tp, PRIBIO);
-	mtx_unlock_spin(&sched_lock);
+	TD_SUNLOCK(tp);
 	for(;;) {
 		g_io_schedule_up(tp);
 	}
@@ -111,9 +111,9 @@
 	struct thread *tp = FIRST_THREAD_IN_PROC(p);
 
 	mtx_assert(&Giant, MA_NOTOWNED);
-	mtx_lock_spin(&sched_lock);
+	TD_SLOCK(tp);
 	sched_prio(tp, PRIBIO);
-	mtx_unlock_spin(&sched_lock);
+	TD_SUNLOCK(tp);
 	for(;;) {
 		g_io_schedule_down(tp);
 	}
@@ -134,9 +134,9 @@
 	struct thread *tp = FIRST_THREAD_IN_PROC(p);
 
 	mtx_assert(&Giant, MA_NOTOWNED);
-	mtx_lock_spin(&sched_lock);
+	TD_SLOCK(tp);
 	sched_prio(tp, PRIBIO);
-	mtx_unlock_spin(&sched_lock);
+	TD_SUNLOCK(tp);
 	for(;;) {
 		g_run_events();
 		tsleep(&g_wait_event, PRIBIO, "-", hz/10);

==== //depot/projects/kmacy_sun4v/src/sys/geom/mirror/g_mirror.c#5 (text+ko) ====

@@ -1719,9 +1719,9 @@
 	int timeout;
 
 	sc = arg;
-	mtx_lock_spin(&sched_lock);
+	TD_SLOCK(curthread);
 	sched_prio(curthread, PRIBIO);
-	mtx_unlock_spin(&sched_lock);
+	TD_SUNLOCK(curthread);
 
 	sx_xlock(&sc->sc_lock);
 	for (;;) {

==== //depot/projects/kmacy_sun4v/src/sys/geom/raid3/g_raid3.c#5 (text+ko) ====

@@ -1936,9 +1936,10 @@
 	int timeout;
 
 	sc = arg;
-	mtx_lock_spin(&sched_lock);
+	TD_SLOCK(curthread);
 	sched_prio(curthread, PRIBIO);
-	mtx_unlock_spin(&sched_lock);
+	TD_SUNLOCK(curthread);
+
 
 	sx_xlock(&sc->sc_lock);
 	for (;;) {

==== //depot/projects/kmacy_sun4v/src/sys/kern/init_main.c#8 (text+ko) ====

@@ -715,6 +715,7 @@
 		if (error != ENOENT)
 			printf("exec %.*s: error %d\n", (int)(next - path), 
 			    path, error);
+		printf("init started\n");
 	}
 	printf("init: not found in path %s\n", init_path);
 	panic("no init");
@@ -767,9 +768,9 @@
 	struct thread *td;
 
 	td = FIRST_THREAD_IN_PROC(initproc);
-	mtx_lock_spin(&sched_lock);
+	TD_SLOCK(td);
 	TD_SET_CAN_RUN(td);
 	setrunqueue(td, SRQ_BORING);	/* XXXKSE */
-	mtx_unlock_spin(&sched_lock);
+	TD_SUNLOCK(td);
 }
 SYSINIT(kickinit, SI_SUB_KTHREAD_INIT, SI_ORDER_FIRST, kick_init, NULL)

==== //depot/projects/kmacy_sun4v/src/sys/kern/kern_acct.c#4 (text+ko) ====

@@ -506,9 +506,9 @@
 
 	/* This is a low-priority kernel thread. */
 	pri = PRI_MAX_KERN;
-	mtx_lock_spin(&sched_lock);
+	TD_SLOCK(curthread);
 	sched_prio(curthread, pri);
-	mtx_unlock_spin(&sched_lock);
+	TD_SUNLOCK(curthread);
 
 	/* If another accounting kthread is already running, just die. */
 	sx_xlock(&acct_sx);

==== //depot/projects/kmacy_sun4v/src/sys/kern/kern_clock.c#6 (text+ko) ====

@@ -156,7 +156,7 @@
 int	profprocs;
 int	ticks;
 int	psratio;
-
+struct mtx prof_lock;
 /*
  * Initialize clock frequencies and start both clocks running.
  */
@@ -173,6 +173,8 @@
 	 */
 	cpu_initclocks();
 
+	mtx_init(&prof_lock, "profiling lock", NULL, MTX_DEF);
+
 	/*
 	 * Compute profhz/stathz, and fix profhz if needed.
 	 */
@@ -201,7 +203,7 @@
 	/*
 	 * Run current process's virtual and profile time, as needed.
 	 */
-	mtx_lock_spin_flags(&timer_lock, MTX_QUIET);
+	PROC_SLOCK(p);
 	pstats = p->p_stats;
 	if (usermode &&
 	        timevalisset(&pstats->p_timer[ITIMER_VIRTUAL].it_value) &&
@@ -210,7 +212,7 @@
 	if (timevalisset(&pstats->p_timer[ITIMER_PROF].it_value) &&
 	    itimerdecr(&pstats->p_timer[ITIMER_PROF], tick) == 0) 
 		sflag = PS_PROFPEND;
-	mtx_unlock_spin_flags(&timer_lock, MTX_QUIET);
+	PROC_SUNLOCK(p);
 #ifdef	HWPMC_HOOKS
 	if (PMC_CPU_HAS_SAMPLES(PCPU_GET(cpuid)))
 		PMC_CALL_HOOK_UNLOCKED(curthread, PMC_FN_DO_SAMPLES, NULL);
@@ -351,11 +353,11 @@
 	if (p->p_flag & P_STOPPROF)
 		return;
 	if ((p->p_flag & P_PROFIL) == 0) {
-		mtx_lock_spin(&sched_lock);
 		p->p_flag |= P_PROFIL;
+		mtx_lock_spin(&prof_lock);
 		if (++profprocs == 1)
 			cpu_startprofclock();
-		mtx_unlock_spin(&sched_lock);
+		mtx_unlock_spin(&prof_lock);
 	}
 }
 
@@ -363,8 +365,7 @@
  * Stop profiling on a process.
  */
 void
-stopprofclock(p)
-	register struct proc *p;
+stopprofclock(struct proc *p)
 {
 
 	PROC_LOCK_ASSERT(p, MA_OWNED);
@@ -378,11 +379,11 @@
 		}
 		if ((p->p_flag & P_PROFIL) == 0)
 			return;
-		mtx_lock_spin(&sched_lock);
 		p->p_flag &= ~P_PROFIL;
+		mtx_lock_spin(&prof_lock);
 		if (--profprocs == 0)
 			cpu_stopprofclock();
-		mtx_unlock_spin(&sched_lock);
+		mtx_unlock_spin(&prof_lock);
 	}
 }
 

==== //depot/projects/kmacy_sun4v/src/sys/kern/kern_cpu.c#4 (text+ko) ====

@@ -300,17 +300,15 @@
 		cpu_id = PCPU_GET(cpuid);
 		pc = cpu_get_pcpu(set->dev);
 		if (cpu_id != pc->pc_cpuid) {
-			mtx_lock_spin(&sched_lock);
+			TD_SLOCK(curthread);
 			sched_bind(curthread, pc->pc_cpuid);
-			mtx_unlock_spin(&sched_lock);
+			TD_SUNLOCK(curthread);
 		}
 		CF_DEBUG("setting abs freq %d on %s (cpu %d)\n", set->freq,
 		    device_get_nameunit(set->dev), PCPU_GET(cpuid));
 		error = CPUFREQ_DRV_SET(set->dev, set);
 		if (cpu_id != pc->pc_cpuid) {
-			mtx_lock_spin(&sched_lock);
 			sched_unbind(curthread);
-			mtx_unlock_spin(&sched_lock);
 		}
 		if (error) {
 			goto out;
@@ -329,17 +327,15 @@
 		cpu_id = PCPU_GET(cpuid);
 		pc = cpu_get_pcpu(set->dev);
 		if (cpu_id != pc->pc_cpuid) {
-			mtx_lock_spin(&sched_lock);
+			TD_SLOCK(curthread);
 			sched_bind(curthread, pc->pc_cpuid);
-			mtx_unlock_spin(&sched_lock);
+			TD_SUNLOCK(curthread);
 		}
 		CF_DEBUG("setting rel freq %d on %s (cpu %d)\n", set->freq,
 		    device_get_nameunit(set->dev), PCPU_GET(cpuid));
 		error = CPUFREQ_DRV_SET(set->dev, set);
 		if (cpu_id != pc->pc_cpuid) {
-			mtx_lock_spin(&sched_lock);
 			sched_unbind(curthread);
-			mtx_unlock_spin(&sched_lock);
 		}
 		if (error) {
 			/* XXX Back out any successful setting? */

==== //depot/projects/kmacy_sun4v/src/sys/kern/kern_exit.c#7 (text+ko) ====

@@ -121,9 +121,12 @@
 	struct plimit *plim;
 	int locked;
 
+	p = td->td_proc;
 	mtx_assert(&Giant, MA_NOTOWNED);
+	PROC_LOCK_ASSERT(p, MA_NOTOWNED);
+	PROC_SLOCK_ASSERT(p, MA_NOTOWNED);
+	TD_SLOCK_ASSERT(td, MA_NOTOWNED);
 
-	p = td->td_proc;
 	if (p == initproc) {
 		printf("init died (signal %d, exit %d)\n",
 		    WTERMSIG(rv), WEXITSTATUS(rv));
@@ -522,7 +525,6 @@
 	 * proc lock.
 	 */
 	wakeup(p->p_pptr);
-	mtx_lock_spin(&sched_lock);
 	p->p_state = PRS_ZOMBIE;
 	PROC_UNLOCK(p->p_pptr);
 
@@ -533,7 +535,6 @@
 	 * late in the game.
 	 */
 	knlist_destroy(&p->p_klist);
-
 	/*
 	 * Make sure the scheduler takes this thread out of its tables etc.
 	 * This will also release this thread's reference to the ucred.
@@ -728,8 +729,8 @@
 			 * sched_lock once we will wait long enough for the
 			 * thread to exit in that case.
 			 */
-			mtx_lock_spin(&sched_lock);
-			mtx_unlock_spin(&sched_lock);
+			PROC_SLOCK(p);
+			PROC_SUNLOCK(p);
 			
 			td->td_retval[0] = p->p_pid;
 			if (status)
@@ -830,17 +831,17 @@
 			atomic_subtract_int(&nprocs, 1);
 			return (0);
 		}
-		mtx_lock_spin(&sched_lock);
+		PROC_SLOCK(p);
 		if ((p->p_flag & P_STOPPED_SIG) &&
 		    (p->p_suspcount == p->p_numthreads) &&
 		    (p->p_flag & P_WAITED) == 0 &&
 		    (p->p_flag & P_TRACED || options & WUNTRACED)) {
-			mtx_unlock_spin(&sched_lock);
 			p->p_flag |= P_WAITED;
 			sx_xunlock(&proctree_lock);
 			td->td_retval[0] = p->p_pid;
 			if (status)
 				*status = W_STOPCODE(p->p_xstat);
+			PROC_SUNLOCK(p);
 			PROC_UNLOCK(p);
 
 			PROC_LOCK(q);
@@ -849,7 +850,7 @@
 
 			return (0);
 		}
-		mtx_unlock_spin(&sched_lock);
+		PROC_SUNLOCK(p);
 		if (options & WCONTINUED && (p->p_flag & P_CONTINUED)) {
 			sx_xunlock(&proctree_lock);
 			td->td_retval[0] = p->p_pid;

==== //depot/projects/kmacy_sun4v/src/sys/kern/kern_fork.c#7 (text+ko) ====

@@ -340,7 +340,7 @@
 	 * If RFHIGHPID is set (used during system boot), do not allocate
 	 * low-numbered pids.
 	 */
-	mtx_lock(&pidalloc_lock);
+	sx_xlock(&pidalloc_lock);
 	trypid = lastpid + 1;
 	if (flags & RFHIGHPID) {
 		if (trypid < 10)
@@ -412,7 +412,7 @@
 			PCPU_PROC_RUNLOCK(pc);
 		}
 	}
-	mtx_unlock(&pidalloc_lock);
+	sx_xunlock(&pidalloc_lock);
 	sx_sunlock(&proctree_lock);
 
 	/*
@@ -514,15 +514,15 @@
 	p2->p_flag = 0;
 	if (p1->p_flag & P_PROFIL)
 		startprofclock(p2);
-	mtx_lock_spin(&sched_lock);
+	PROC_SLOCK_ORDERED(p1, p2);
 	p2->p_sflag = PS_INMEM;
 	/*
 	 * Allow the scheduler to adjust the priority of the child and
 	 * parent while we hold the sched_lock.
 	 */
 	sched_fork(td, td2);
-
-	mtx_unlock_spin(&sched_lock);
+	PROC_SUNLOCK_ORDERED(p1, p2);
+	
 	p2->p_ucred = crhold(td->td_ucred);
 	td2->td_ucred = crhold(p2->p_ucred);	/* XXXKSE */
 #ifdef AUDIT
@@ -707,7 +707,7 @@
 	 * Set the child start time and mark the process as being complete.
 	 */
 	microuptime(&p2->p_stats->p_start);
-	mtx_lock_spin(&sched_lock);
+	PROC_SLOCK(p2);
 	p2->p_state = PRS_NORMAL;
 
 	/*
@@ -716,9 +716,11 @@
 	 */
 	if ((flags & RFSTOPPED) == 0) {
 		TD_SET_CAN_RUN(td2);
+		TD_SLOCK(td2);
 		setrunqueue(td2, SRQ_BORING);
+		TD_SUNLOCK(td2);
 	}
-	mtx_unlock_spin(&sched_lock);
+	PROC_SUNLOCK(p2);
 
 	/*
 	 * Now can be swapped.
@@ -800,8 +802,6 @@
 	td->td_oncpu = PCPU_GET(cpuid);
 	KASSERT(p->p_state == PRS_NORMAL, ("executing process is still new"));
 
-	sched_lock.mtx_lock = (uintptr_t)td;
-	mtx_assert(&sched_lock, MA_OWNED | MA_NOTRECURSED);
 	KASSERT(p->p_pcpu != NULL, ("%s has null pcpu", p->p_comm));
 	CTR4(KTR_PROC, "fork_exit: new thread %p (kse %p, pid %d, %s)",
 		td, td->td_sched, p->p_pid, p->p_comm);
@@ -816,9 +816,43 @@
 		PCPU_SET(deadthread, NULL);
 		thread_stash(td);
 	}
+
 	td = curthread;
-	mtx_unlock_spin(&sched_lock);
+
+	PCPU_GET(preempted_thread)->td_running = 0;
+	td->td_running = 1;
+
+	td->td_spin_mtx.mtx_lock = (uintptr_t)td;
+	TD_SLOCK_ASSERT(td, MA_OWNED | MA_NOTRECURSED);
+	TD_SUNLOCK(td);
+
+
+	if (PCPU_GET(preempted_thread) != curthread) {
+		
+		if (curthread->td_critnest != 1) {
+			DELAY(1000000*curcpu);
+			printf("prev thread=%d curthread=%d\n", PCPU_GET(preempted_thread)->td_tid,
+			       curthread->td_tid);
+			panic("fork_exit: critnest should be 1 is %d", curthread->td_critnest);
+		}
 
+		PCPU_GET(preempted_thread)->td_spin_mtx.mtx_lock = (uintptr_t)td;
+		TD_SLOCK_ASSERT(PCPU_GET(preempted_thread), MA_OWNED | MA_NOTRECURSED);
+		TD_SUNLOCK(PCPU_GET(preempted_thread));
+	}
+	if (curthread->td_critnest != 0) {
+		DELAY(1000000*curcpu);
+		printf("prev thread=%d curthread=%d\n", PCPU_GET(preempted_thread)->td_tid,
+		       curthread->td_tid);
+		panic("fork_exit: critnest should be 0 is %d", curthread->td_critnest);
+	}
+	
+	if (rdpr(pil) != 0)
+		panic("pil in fork_exit not 0 - %ld", rdpr(pil));
+	if (curthread->td_md.md_spinlock_count != 0)
+		panic("fork_exit: spinlock_count not 0");
+	if (curthread->td_critnest != 0)
+		panic("fork_exit: critnest should be 0 is %d", curthread->td_critnest);
 	/*
 	 * cpu_set_fork_handler intercepts this function call to
 	 * have this call a non-return function to stay in kernel mode.

==== //depot/projects/kmacy_sun4v/src/sys/kern/kern_idle.c#7 (text+ko) ====

@@ -36,6 +36,7 @@
 #include <sys/resourcevar.h>
 #include <sys/sched.h>
 #include <sys/unistd.h>
+#include <sys/ktr.h>
 #ifdef SMP
 #include <sys/smp.h>
 #endif
@@ -75,13 +76,13 @@
 
 		PROC_LOCK(p);
 		p->p_flag |= P_NOLOAD;
-		mtx_lock_spin(&sched_lock);
 		td = FIRST_THREAD_IN_PROC(p);
+		TD_SLOCK(td);
 		TD_SET_CAN_RUN(td);
 		atomic_set_int(&td->td_flags, TDF_IDLETD);
 		sched_class(td, PRI_IDLE);
 		sched_prio(td, PRI_MAX_IDLE);
-		mtx_unlock_spin(&sched_lock);
+		TD_SUNLOCK(td);
 		PROC_UNLOCK(p);
 #ifdef SMP
 	}
@@ -109,14 +110,12 @@
 
 		while (sched_runnable() == 0 && (i++%10 != 0))
 			cpu_idle();
-
-
 #ifdef SMP
 		atomic_clear_int(&idle_cpus_mask, mycpu);
 #endif
-		mtx_lock_spin(&sched_lock);
+		TD_SLOCK(curthread);
 		mi_switch(SW_VOL, NULL);
-		mtx_unlock_spin(&sched_lock);
+		TD_SUNLOCK(curthread);
 #ifdef SMP
 		atomic_set_int(&idle_cpus_mask, mycpu);
 #endif

==== //depot/projects/kmacy_sun4v/src/sys/kern/kern_intr.c#6 (text+ko) ====

@@ -162,9 +162,9 @@
 	/* Update name and priority. */
 	strlcpy(td->td_proc->p_comm, ie->ie_fullname,
 	    sizeof(td->td_proc->p_comm));
-	mtx_lock_spin(&sched_lock);
+	TD_SLOCK(td);
 	sched_prio(td, pri);
-	mtx_unlock_spin(&sched_lock);
+	TD_SUNLOCK(td);
 }
 
 /*
@@ -295,12 +295,12 @@
 	if (error)
 		panic("kthread_create() failed with %d", error);
 	td = FIRST_THREAD_IN_PROC(p);	/* XXXKSE */
-	mtx_lock_spin(&sched_lock);
+	TD_SLOCK(td);
 	td->td_pri_class = PRI_ITHD;
 	TD_SET_IWAIT(td);
-	mtx_unlock_spin(&sched_lock);
 	td->td_pflags |= TDP_ITHREAD;
 	ithd->it_thread = td;
+	TD_SUNLOCK(td);
 	CTR2(KTR_INTR, "%s: created %s", __func__, name);
 	return (ithd);
 }
@@ -312,13 +312,13 @@
 
 	CTR2(KTR_INTR, "%s: killing %s", __func__, ithread->it_event->ie_name);
 	td = ithread->it_thread;
-	mtx_lock_spin(&sched_lock);
+	TD_SLOCK(td);
 	ithread->it_flags |= IT_DEAD;
 	if (TD_AWAITING_INTR(td)) {
 		TD_CLR_IWAIT(td);
 		setrunqueue(td, SRQ_INTR);
 	}
-	mtx_unlock_spin(&sched_lock);
+	TD_SUNLOCK(td);
 }
 
 int
@@ -445,7 +445,8 @@
 	 * so we have to remove the handler here rather than letting the
 	 * thread do it.
 	 */
-	mtx_lock_spin(&sched_lock);
+	
+	TD_SLOCK(ie->ie_thread->it_thread);
 	if (!TD_AWAITING_INTR(ie->ie_thread->it_thread) && !cold) {
 		handler->ih_flags |= IH_DEAD;
 
@@ -457,7 +458,7 @@
 		ie->ie_thread->it_need = 1;
 	} else
 		TAILQ_REMOVE(&ie->ie_handlers, handler, ih_next);
-	mtx_unlock_spin(&sched_lock);
+	TD_SUNLOCK(ie->ie_thread->it_thread);
 	while (handler->ih_flags & IH_DEAD)
 		msleep(handler, &ie->ie_lock, 0, "iev_rmh", 0);
 	intr_event_update(ie);
@@ -522,11 +523,11 @@
 
 	/*
 	 * Set it_need to tell the thread to keep running if it is already
-	 * running.  Then, grab sched_lock and see if we actually need to
+	 * running.  Then, grab process spin lock and see if we actually need to
 	 * put this thread on the runqueue.
 	 */
 	it->it_need = 1;
-	mtx_lock_spin(&sched_lock);
+	TD_SLOCK(td);
 	if (TD_AWAITING_INTR(td)) {
 		CTR3(KTR_INTR, "%s: schedule pid %d (%s)", __func__, p->p_pid,
 		    p->p_comm);
@@ -536,7 +537,7 @@
 		CTR5(KTR_INTR, "%s: pid %d (%s): it_need %d, state %d",
 		    __func__, p->p_pid, p->p_comm, it->it_need, td->td_state);
 	}
-	mtx_unlock_spin(&sched_lock);
+	TD_SUNLOCK(td);
 
 	return (0);
 }
@@ -707,7 +708,7 @@
 	struct proc *p;
 
 	td = curthread;
-	p = td->td_proc;
+	p = curproc;
 	ithd = (struct intr_thread *)arg;
 	KASSERT(ithd->it_thread == td,
 	    ("%s: ithread and proc linkage out of sync", __func__));
@@ -752,13 +753,13 @@
 		 * lock.  This may take a while and it_need may get
 		 * set again, so we have to check it again.
 		 */
-		mtx_lock_spin(&sched_lock);
+		TD_SLOCK(td);
 		if (!ithd->it_need && !(ithd->it_flags & IT_DEAD)) {
 			TD_SET_IWAIT(td);
 			ie->ie_count = 0;
 			mi_switch(SW_VOL, NULL);
 		}
-		mtx_unlock_spin(&sched_lock);
+		TD_SUNLOCK(td);
 	}
 }
 

==== //depot/projects/kmacy_sun4v/src/sys/kern/kern_kthread.c#3 (text+ko) ====

@@ -38,6 +38,7 @@
 #include <sys/sx.h>
 #include <sys/unistd.h>
 #include <sys/wait.h>
+#include <sys/ktr.h>
 
 #include <machine/stdarg.h>
 
@@ -107,15 +108,14 @@
 
 	/* call the processes' main()... */
 	td = FIRST_THREAD_IN_PROC(p2);
+	TD_SLOCK(td);
 	cpu_set_fork_handler(td, func, arg);
 	TD_SET_CAN_RUN(td);
-
 	/* Delay putting it on the run queue until now. */
 	if (!(flags & RFSTOPPED)) {
-		mtx_lock_spin(&sched_lock);
 		setrunqueue(td, SRQ_BORING); 
-		mtx_unlock_spin(&sched_lock);
 	}
+	TD_SUNLOCK(td);
 
 	return 0;
 }

==== //depot/projects/kmacy_sun4v/src/sys/kern/kern_lockf.c#3 (text+ko) ====

@@ -274,7 +274,7 @@
 			/* The block is waiting on something */
 			/* XXXKSE this is not complete under threads */
 			wproc = (struct proc *)block->lf_id;
-			mtx_lock_spin(&sched_lock);
+			PROC_SLOCK(wproc);
 			FOREACH_THREAD_IN_PROC(wproc, td) {
 				while (td->td_wchan &&
 				    (td->td_wmesg == lockstr) &&
@@ -286,13 +286,13 @@
 						break;
 					wproc = (struct proc *)waitblock->lf_id;
 					if (wproc == (struct proc *)lock->lf_id) {
-						mtx_unlock_spin(&sched_lock);
+						PROC_SUNLOCK(wproc);
 						free(lock, M_LOCKF);
 						return (EDEADLK);
 					}
 				}
 			}
-			mtx_unlock_spin(&sched_lock);
+			PROC_SUNLOCK(wproc);
 		}
 		/*
 		 * For flock type locks, we must first remove

==== //depot/projects/kmacy_sun4v/src/sys/kern/kern_mutex.c#16 (text+ko) ====

@@ -114,9 +114,7 @@
 /*
  * System-wide mutexes
  */
-struct mtx sched_lock;
 struct mtx Giant;
-struct mtx timer_lock;
 
 #ifdef SPIN_PROFILING
 SYSCTL_NODE(_debug, OID_AUTO, spinlock, CTLFLAG_RD, NULL, "spinlock debugging");
@@ -500,6 +498,51 @@
 }
 
 #ifdef SMP
+int
+_mtx_trylock_spin(struct mtx *m, uintptr_t tid, const char *file, int line)  
+{
+	uintptr_t _tid = (uintptr_t)(tid);				
+	int v;								
+	KASSERT(LOCK_CLASS(&m->mtx_object) == &lock_class_mtx_spin,
+		("mtx_lock_spin() of sleep mutex %s @ %s:%d",
+		 m->mtx_object.lo_name, file, line));
+	spinlock_enter();						
+	v = _obtain_lock((m), _tid);        
+	if (!v)                                                         
+		spinlock_exit();   
+	else {
+		WITNESS_LOCK(&m->mtx_object, LOP_EXCLUSIVE, file, line);
+	}
+                                  
+        return v;       
+}
+
+int
+_mtx_trylockn_spin(struct mtx *m, uintptr_t tid, int n, const char *file, int line)  
+{
+	uintptr_t _tid = (uintptr_t)(tid);
+	int i, v;
+	
+	KASSERT(LOCK_CLASS(&m->mtx_object) == &lock_class_mtx_spin,
+		("mtx_lock_spin() of sleep mutex %s @ %s:%d",
+		 m->mtx_object.lo_name, file, line));
+
+	for (i = 0, v = 0; i < n; i++) {
+		spinlock_enter();
+		v = _obtain_lock((m), _tid);
+		if (!v)
+			spinlock_exit();
+		else {
+			WITNESS_LOCK(&m->mtx_object, LOP_EXCLUSIVE, file, line);
+			break;
+		}
+	}
+        return v;
+}
+
+
+
+
 /*
  * _mtx_lock_spin: the tougher part of acquiring an MTX_SPIN lock.
  *
@@ -538,8 +581,10 @@
 			if (i < 60000000)
 				DELAY(1);
 			else if (!kdb_active && !panicstr) {
+				struct thread *locktd;
 				printf("spin lock %s held by %p for > 5 seconds\n",
 				    m->mtx_object.lo_name, (void *)m->mtx_lock);
+				locktd = (struct thread *)m->mtx_lock;
 #ifdef WITNESS
 				witness_display_spinlock(&m->mtx_object,
 				    mtx_owner(m));
@@ -630,7 +675,7 @@
 #endif
 	turnstile_unpend(ts, TS_EXCLUSIVE_LOCK);
 
-#ifndef PREEMPTION
+#if !defined(PREEMPTION)
 	/*
 	 * XXX: This is just a hack until preemption is done.  However,
 	 * once preemption is done we need to either wrap the
@@ -641,7 +686,7 @@
 	td = curthread;
 	if (td->td_critnest > 0 || td1->td_priority >= td->td_priority)
 		return;
-	mtx_lock_spin(&sched_lock);
+	TD_SLOCK(td1);
 	if (!TD_IS_RUNNING(td1)) {
 #ifdef notyet
 		if (td->td_ithd != NULL) {
@@ -666,7 +711,7 @@
 			CTR2(KTR_LOCK, "_mtx_unlock_sleep: %p resuming lock=%p",
 			    m, (void *)m->mtx_lock);
 	}
-	mtx_unlock_spin(&sched_lock);
+	TD_SUNLOCK(td1);
 #endif
 
 	return;
@@ -846,13 +891,15 @@
 	mutex_profile_init();
 	printf("called profile init\n");
 
+	bzero(&thread0.td_spin_mtx, sizeof(struct mtx));
+	bzero(&proc0.p_spin_mtx, sizeof(struct mtx));
 	/*
 	 * Initialize mutexes.
 	 */
 	mtx_init(&Giant, "Giant", NULL, MTX_DEF | MTX_RECURSE);
-	mtx_init(&sched_lock, "sched lock", NULL, MTX_SPIN | MTX_RECURSE);
-	mtx_init(&timer_lock, "timer lock", NULL, MTX_SPIN);
 	mtx_init(&proc0.p_mtx, "process lock", NULL, MTX_DEF | MTX_DUPOK);
+	mtx_init(&proc0.p_spin_mtx, "process spin lock", NULL, MTX_SPIN | MTX_DUPOK);
+	mtx_init(&thread0.td_spin_mtx, "thread spin lock", NULL, MTX_SPIN | MTX_DUPOK);
 	mtx_init(&devmtx, "cdev", NULL, MTX_DEF);
 	mtx_lock(&Giant);
 }

==== //depot/projects/kmacy_sun4v/src/sys/kern/kern_poll.c#5 (text+ko) ====

@@ -577,20 +577,20 @@
 {
 	struct thread *td = curthread;
 	struct rtprio rtp;
+	struct proc *p = curproc;
+
 
 	rtp.prio = RTP_PRIO_MAX;	/* lowest priority */
 	rtp.type = RTP_PRIO_IDLE;
-	mtx_lock_spin(&sched_lock);
+	TD_SLOCK(td);
 	rtp_to_pri(&rtp, td);
-	mtx_unlock_spin(&sched_lock);
+	TD_SUNLOCK(td);
 
 	for (;;) {
 		if (poll_in_idle_loop && poll_handlers > 0) {
 			idlepoll_sleeping = 0;
 			ether_poll(poll_each_burst);
-			mtx_lock_spin(&sched_lock);
 			mi_switch(SW_VOL, NULL);
-			mtx_unlock_spin(&sched_lock);
 		} else {
 			idlepoll_sleeping = 1;
 			tsleep(&idlepoll_sleeping, 0, "pollid", hz * 3);

==== //depot/projects/kmacy_sun4v/src/sys/kern/kern_proc.c#6 (text+ko) ====

@@ -94,7 +94,7 @@
 struct sx allpcpu_lock;
 struct sx proctree_lock;
 struct mtx pidhash_lock;
-struct mtx pidalloc_lock;
+struct sx pidalloc_lock;
 struct mtx ppeers_lock;
 uma_zone_t proc_zone;
 uma_zone_t ithread_zone;
@@ -115,7 +115,7 @@
 	sx_init(&proctree_lock, "proctree");
 	sx_init(&pcpu_find(0)->pc_allproc_lock, "cpu allproc");
 	mtx_init(&ppeers_lock, "p_peers", NULL, MTX_DEF);
-	mtx_init(&pidalloc_lock, "pidalloc", NULL, MTX_DEF);
+	sx_init(&pidalloc_lock, "pidalloc");
 	mtx_init(&pidhash_lock, "pidhash", NULL, MTX_DEF);
 	pidhashtbl = hashinit(maxproc / 4, M_PROC, &pidhash);
 	zpidhashtbl = hashinit(maxproc / 4, M_PROC, &zpidhash);
@@ -181,7 +181,9 @@
 	p->p_sched = (struct p_sched *)&p[1];
 	td = thread_alloc();
 	bzero(&p->p_mtx, sizeof(struct mtx));
+	bzero(&p->p_spin_mtx, sizeof(struct mtx));
 	mtx_init(&p->p_mtx, "process lock", NULL, MTX_DEF | MTX_DUPOK);
+	mtx_init(&p->p_spin_mtx, "process spin lock", NULL, MTX_SPIN | MTX_DUPOK);
 	p->p_stats = pstats_alloc();
 	proc_linkup(p, td);
 	return (0);
@@ -663,7 +665,7 @@
 		kp->ki_sigcatch = ps->ps_sigcatch;
 		mtx_unlock(&ps->ps_mtx);
 	}
-	mtx_lock_spin(&sched_lock);

>>> TRUNCATED FOR MAIL (1000 lines) <<<



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200606240223.k5O2NjJF087630>