Index: generic/src/proc/scheduler.c
===================================================================
--- generic/src/proc/scheduler.c	(revision 248fc1a1ef6f72435b9060ec67dc80bfe4a24fdc)
+++ generic/src/proc/scheduler.c	(revision 444ec64e8e2332fc99ef4845e8a6838d5afdb5f4)
@@ -132,4 +132,7 @@
 		 * until a hardware interrupt or an IPI comes.
 		 * This improves energy saving and hyperthreading.
+		 *
+		 * - we might get an interrupt here that makes some thread runnable,
+		 *   in such a case we must wait for the next quantum to come
 		 */
 		 cpu_sleep();
@@ -220,5 +223,5 @@
 		CPU->needs_relink = 0;
 	}
-	spinlock_unlock(&CPU->lock);				
+	spinlock_unlock(&CPU->lock);
 
 }
@@ -463,14 +466,9 @@
 	 * passes. Each time get the most up to date counts.
 	 */
-	average = atomic_get(&nrdy) / config.cpu_active;
+	average = atomic_get(&nrdy) / config.cpu_active + 1;
 	count = average - atomic_get(&CPU->nrdy);
 
-	if (count < 0)
+	if (count <= 0)
 		goto satisfied;
-
-	if (!count) { /* Try to steal threads from CPU's that have more then average count */
-		count = 1;
-		average += 1;
-	}
 
 	/*
@@ -494,5 +492,5 @@
 				continue;
 
-restart:		ipl = interrupts_disable();
+			ipl = interrupts_disable();
 			r = &cpu->rq[j];
 			spinlock_lock(&r->lock);
@@ -514,24 +512,10 @@
 				spinlock_lock(&t->lock);
 				if ( (!(t->flags & (X_WIRED | X_STOLEN))) && (!(t->fpu_context_engaged)) ) {
-				
 					/*
 					 * Remove t from r.
 					 */
-
 					spinlock_unlock(&t->lock);
 					
-					/*
-					 * Here we have to avoid deadlock with relink_rq(),
-					 * because it locks cpu and r in a different order than we do.
-					 */
-					if (!spinlock_trylock(&cpu->lock)) {
-						/* Release all locks and try again. */ 
-						spinlock_unlock(&r->lock);
-						interrupts_restore(ipl);
-						goto restart;
-					}
 					atomic_dec(&cpu->nrdy);
-					spinlock_unlock(&cpu->lock);
-
 					atomic_dec(&nrdy);
 
