Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 30 Jun 2008 23:16:13 +0000 (UTC)
From:      Stef <stef@memberwebs.com>
To:        John Baldwin <jhb@freebsd.org>
Cc:        freebsd-hackers@freebsd.org, freebsd-stable@freebsd.org
Subject:   Re: FreeBSD 6.3 deadlock (vm_map?) with DDB output
Message-ID:  <20080630231611.F0245F1817C@mx.npubs.com>
References:  <20080615112318.146C1F18512@mx.npubs.com> <200806180917.05689.jhb@freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format.
--------------040406060900030904060601
Content-Type: text/plain; charset=iso-8859-15
Content-Transfer-Encoding: 7bit

John Baldwin wrote:
> On Sunday 15 June 2008 07:23:19 am Stef Walter wrote:
>> I've been trying to track down a deadlock on some newish production
>> servers running FreeBSD 6.3-RELEASE-p2. The deadlock occurs on a
>> specific (although mundane) hardware configuration, and each of several
>> servers running this hardware deadlock about once per week.
> 
> Try this change:
> 
<snip>
> We use it at work on 6.x.  W/o this fix, round-robin stops working on 4BSD 
> when softclock() (swi4: clock) blocks on a lock like Giant.

Just wanted to confirm: That patch did the trick. All the SMP machines
that had this problem have been stable for 11 days now, longer than any
of them were up previously.

I changed the patch slightly to work with FreeBSD 6.3-RELEASE. That's
attached, in case anyone needs this later.

Cheers,
Stef

--------------040406060900030904060601
Content-Type: text/x-patch;
 name="kern_sched4bsd_deadlock.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="kern_sched4bsd_deadlock.patch"

--- sys/kern/sched_4bsd.c.orig	2006-06-16 22:11:55.000000000 +0000
+++ sys/kern/sched_4bsd.c	2008-06-18 17:04:34.000000000 +0000
@@ -157,13 +157,10 @@
 static int	sched_quantum;	/* Roundrobin scheduling quantum in ticks. */
 #define	SCHED_QUANTUM	(hz / 10)	/* Default sched quantum */
 
-static struct callout roundrobin_callout;
-
 static void	slot_fill(struct ksegrp *kg);
 static struct kse *sched_choose(void);		/* XXX Should be thread * */
 
 static void	setup_runqs(void);
-static void	roundrobin(void *arg);
 static void	schedcpu(void);
 static void	schedcpu_thread(void);
 static void	sched_priority(struct thread *td, u_char prio);
@@ -316,27 +313,6 @@
 }
 
 /*
- * Force switch among equal priority processes every 100ms.
- * We don't actually need to force a context switch of the current process.
- * The act of firing the event triggers a context switch to softclock() and
- * then switching back out again which is equivalent to a preemption, thus
- * no further work is needed on the local CPU.
- */
-/* ARGSUSED */
-static void
-roundrobin(void *arg)
-{
-
-#ifdef SMP
-	mtx_lock_spin(&sched_lock);
-	forward_roundrobin();
-	mtx_unlock_spin(&sched_lock);
-#endif
-
-	callout_reset(&roundrobin_callout, sched_quantum, roundrobin, NULL);
-}
-
-/*
  * Constants for digital decay and forget:
  *	90% of (kg_estcpu) usage in 5 * loadav time
  *	95% of (ke_pctcpu) usage in 60 seconds (load insensitive)
@@ -618,11 +594,6 @@
 		sched_quantum = SCHED_QUANTUM;
 	hogticks = 2 * sched_quantum;
 
-	callout_init(&roundrobin_callout, CALLOUT_MPSAFE);
-
-	/* Kick off timeout driven events by calling first time. */
-	roundrobin(NULL);
-
 	/* Account for thread0. */
 	sched_load_add();
 }
@@ -697,6 +668,14 @@
 		resetpriority(kg);
 		resetpriority_thread(td, kg);
 	}
+
+	/*
+	 * Force a context switch if the current thread has used up a full
+	 * quantum (default quantum is 100ms).
+	 */
+	if (!((td)->td_flags & TDF_IDLETD) &&
+	    ticks - PCPU_GET(switchticks) >= sched_quantum)
+		td->td_flags |= TDF_NEEDRESCHED;
 }
 
 /*

--------------040406060900030904060601--




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