Index: kernel/generic/src/proc/scheduler.c
===================================================================
--- kernel/generic/src/proc/scheduler.c	(revision b2e121ad525328882607c97cdba1a9ded6137d13)
+++ kernel/generic/src/proc/scheduler.c	(revision 34e1206ec4dc79f0592077e3ee270fba91d1eb9d)
@@ -90,5 +90,5 @@
 	before_thread_runs_arch();
 	rcu_before_thread_runs();
-	
+
 #ifdef CONFIG_FPU_LAZY
 	if (THREAD == CPU->fpu_owner)
@@ -105,5 +105,5 @@
 	}
 #endif
-	
+
 #ifdef CONFIG_UDEBUG
 	if (THREAD->btrace) {
@@ -113,5 +113,5 @@
 			stack_trace_istate(istate);
 		}
-		
+
 		THREAD->btrace = false;
 	}
@@ -141,10 +141,10 @@
 	fpu_enable();
 	irq_spinlock_lock(&CPU->lock, false);
-	
+
 	/* Save old context */
 	if (CPU->fpu_owner != NULL) {
 		irq_spinlock_lock(&CPU->fpu_owner->lock, false);
 		fpu_context_save(CPU->fpu_owner->saved_fpu_context);
-		
+
 		/* Don't prevent migration */
 		CPU->fpu_owner->fpu_context_engaged = false;
@@ -152,5 +152,5 @@
 		CPU->fpu_owner = NULL;
 	}
-	
+
 	irq_spinlock_lock(&THREAD->lock, false);
 	if (THREAD->fpu_context_exists) {
@@ -164,5 +164,5 @@
 			THREAD->saved_fpu_context =
 			    (fpu_context_t *) slab_alloc(fpu_context_cache, 0);
-			
+
 			/* We may have switched CPUs during slab_alloc */
 			goto restart;
@@ -171,9 +171,9 @@
 		THREAD->fpu_context_exists = true;
 	}
-	
+
 	CPU->fpu_owner = THREAD;
 	THREAD->fpu_context_engaged = true;
 	irq_spinlock_unlock(&THREAD->lock, false);
-	
+
 	irq_spinlock_unlock(&CPU->lock, false);
 }
@@ -201,7 +201,7 @@
 {
 	assert(CPU != NULL);
-	
+
 loop:
-	
+
 	if (atomic_get(&CPU->nrdy) == 0) {
 		/*
@@ -214,5 +214,5 @@
 		irq_spinlock_unlock(&CPU->lock, false);
 		interrupts_enable();
-		
+
 		/*
 		 * An interrupt might occur right now and wake up a thread.
@@ -226,5 +226,5 @@
 
 	assert(!CPU->idle);
-	
+
 	unsigned int i;
 	for (i = 0; i < RQ_COUNT; i++) {
@@ -237,9 +237,9 @@
 			continue;
 		}
-		
+
 		atomic_dec(&CPU->nrdy);
 		atomic_dec(&nrdy);
 		CPU->rq[i].n--;
-		
+
 		/*
 		 * Take the first thread from the queue.
@@ -248,11 +248,11 @@
 		    list_first(&CPU->rq[i].rq), thread_t, rq_link);
 		list_remove(&thread->rq_link);
-		
+
 		irq_spinlock_pass(&(CPU->rq[i].lock), &thread->lock);
-		
+
 		thread->cpu = CPU;
 		thread->ticks = us2ticks((i + 1) * 10000);
 		thread->priority = i;  /* Correct rq index */
-		
+
 		/*
 		 * Clear the stolen flag so that it can be migrated
@@ -261,8 +261,8 @@
 		thread->stolen = false;
 		irq_spinlock_unlock(&thread->lock, false);
-		
+
 		return thread;
 	}
-	
+
 	goto loop;
 }
@@ -282,13 +282,13 @@
 {
 	list_t list;
-	
+
 	list_initialize(&list);
 	irq_spinlock_lock(&CPU->lock, false);
-	
+
 	if (CPU->needs_relink > NEEDS_RELINK_MAX) {
 		int i;
 		for (i = start; i < RQ_COUNT - 1; i++) {
 			/* Remember and empty rq[i + 1] */
-			
+
 			irq_spinlock_lock(&CPU->rq[i + 1].lock, false);
 			list_concat(&list, &CPU->rq[i + 1].rq);
@@ -296,7 +296,7 @@
 			CPU->rq[i + 1].n = 0;
 			irq_spinlock_unlock(&CPU->rq[i + 1].lock, false);
-			
+
 			/* Append rq[i + 1] to rq[i] */
-			
+
 			irq_spinlock_lock(&CPU->rq[i].lock, false);
 			list_concat(&CPU->rq[i].rq, &list);
@@ -304,8 +304,8 @@
 			irq_spinlock_unlock(&CPU->rq[i].lock, false);
 		}
-		
+
 		CPU->needs_relink = 0;
 	}
-	
+
 	irq_spinlock_unlock(&CPU->lock, false);
 }
@@ -321,18 +321,18 @@
 {
 	volatile ipl_t ipl;
-	
+
 	assert(CPU != NULL);
-	
+
 	ipl = interrupts_disable();
-	
+
 	if (atomic_get(&haltstate))
 		halt();
-	
+
 	if (THREAD) {
 		irq_spinlock_lock(&THREAD->lock, false);
-		
+
 		/* Update thread kernel accounting */
 		THREAD->kcycles += get_cycle() - THREAD->last_cycle;
-		
+
 #if (defined CONFIG_FPU) && (!defined CONFIG_FPU_LAZY)
 		fpu_context_save(THREAD->saved_fpu_context);
@@ -342,14 +342,14 @@
 			 * This is the place where threads leave scheduler();
 			 */
-			
+
 			/* Save current CPU cycle */
 			THREAD->last_cycle = get_cycle();
-			
+
 			irq_spinlock_unlock(&THREAD->lock, false);
 			interrupts_restore(THREAD->saved_context.ipl);
-			
+
 			return;
 		}
-		
+
 		/*
 		 * Interrupt priority level of preempted thread is recorded
@@ -360,5 +360,5 @@
 		THREAD->saved_context.ipl = ipl;
 	}
-	
+
 	/*
 	 * Through the 'THE' structure, we keep track of THREAD, TASK, CPU, AS
@@ -368,5 +368,5 @@
 	 */
 	the_copy(THE, (the_t *) CPU->stack);
-	
+
 	/*
 	 * We may not keep the old stack.
@@ -386,5 +386,5 @@
 	    (uintptr_t) CPU->stack, STACK_SIZE);
 	context_restore(&CPU->saved_context);
-	
+
 	/* Not reached */
 }
@@ -402,9 +402,9 @@
 	task_t *old_task = TASK;
 	as_t *old_as = AS;
-	
+
 	assert((!THREAD) || (irq_spinlock_locked(&THREAD->lock)));
 	assert(CPU != NULL);
 	assert(interrupts_disabled());
-	
+
 	/*
 	 * Hold the current task and the address space to prevent their
@@ -414,12 +414,12 @@
 	if (old_task)
 		task_hold(old_task);
-	
+
 	if (old_as)
 		as_hold(old_as);
-	
+
 	if (THREAD) {
 		/* Must be run after the switch to scheduler stack */
 		after_thread_ran();
-		
+
 		switch (THREAD->state) {
 		case Running:
@@ -427,5 +427,5 @@
 			thread_ready(THREAD);
 			break;
-		
+
 		case Exiting:
 			rcu_thread_exiting();
@@ -452,10 +452,10 @@
 				    WAKEUP_FIRST);
 				irq_spinlock_unlock(&THREAD->join_wq.lock, false);
-				
+
 				THREAD->state = Lingering;
 				irq_spinlock_unlock(&THREAD->lock, false);
 			}
 			break;
-			
+
 		case Sleeping:
 			/*
@@ -463,5 +463,5 @@
 			 */
 			THREAD->priority = -1;
-			
+
 			/*
 			 * We need to release wq->lock which we locked in
@@ -470,8 +470,8 @@
 			 */
 			irq_spinlock_unlock(&THREAD->sleep_queue->lock, false);
-			
+
 			irq_spinlock_unlock(&THREAD->lock, false);
 			break;
-		
+
 		default:
 			/*
@@ -482,16 +482,16 @@
 			break;
 		}
-		
+
 		THREAD = NULL;
 	}
-	
+
 	THREAD = find_best_thread();
-	
+
 	irq_spinlock_lock(&THREAD->lock, false);
 	int priority = THREAD->priority;
 	irq_spinlock_unlock(&THREAD->lock, false);
-	
+
 	relink_rq(priority);
-	
+
 	/*
 	 * If both the old and the new task are the same,
@@ -500,5 +500,5 @@
 	if (TASK != THREAD->task) {
 		as_t *new_as = THREAD->task->as;
-		
+
 		/*
 		 * Note that it is possible for two tasks
@@ -512,18 +512,18 @@
 			as_switch(old_as, new_as);
 		}
-		
+
 		TASK = THREAD->task;
 		before_task_runs();
 	}
-	
+
 	if (old_task)
 		task_release(old_task);
-	
+
 	if (old_as)
 		as_release(old_as);
-	
+
 	irq_spinlock_lock(&THREAD->lock, false);
 	THREAD->state = Running;
-	
+
 #ifdef SCHEDULER_VERBOSE
 	log(LF_OTHER, LVL_DEBUG,
@@ -532,5 +532,5 @@
 	    THREAD->ticks, atomic_get(&CPU->nrdy));
 #endif
-	
+
 	/*
 	 * Some architectures provide late kernel PA2KA(identity)
@@ -542,5 +542,5 @@
 	 */
 	before_thread_runs();
-	
+
 	/*
 	 * Copy the knowledge of CPU, TASK, THREAD and preemption counter to
@@ -548,7 +548,7 @@
 	 */
 	the_copy(THE, (the_t *) THREAD->kstack);
-	
+
 	context_restore(&THREAD->saved_context);
-	
+
 	/* Not reached */
 }
@@ -567,10 +567,10 @@
 	atomic_count_t average;
 	atomic_count_t rdy;
-	
+
 	/*
 	 * Detach kcpulb as nobody will call thread_join_timeout() on it.
 	 */
 	thread_detach(THREAD);
-	
+
 loop:
 	/*
@@ -578,5 +578,5 @@
 	 */
 	thread_sleep(1);
-	
+
 not_satisfied:
 	/*
@@ -588,10 +588,10 @@
 	average = atomic_get(&nrdy) / config.cpu_active + 1;
 	rdy = atomic_get(&CPU->nrdy);
-	
+
 	if (average <= rdy)
 		goto satisfied;
-	
+
 	atomic_count_t count = average - rdy;
-	
+
 	/*
 	 * Searching least priority queues on all CPU's first and most priority
@@ -601,9 +601,9 @@
 	size_t acpu_bias = 0;
 	int rq;
-	
+
 	for (rq = RQ_COUNT - 1; rq >= 0; rq--) {
 		for (acpu = 0; acpu < config.cpu_active; acpu++) {
 			cpu_t *cpu = &cpus[(acpu + acpu_bias) % config.cpu_active];
-			
+
 			/*
 			 * Not interested in ourselves.
@@ -614,8 +614,8 @@
 			if (CPU == cpu)
 				continue;
-			
+
 			if (atomic_get(&cpu->nrdy) <= average)
 				continue;
-			
+
 			irq_spinlock_lock(&(cpu->rq[rq].lock), true);
 			if (cpu->rq[rq].n == 0) {
@@ -623,14 +623,14 @@
 				continue;
 			}
-			
+
 			thread_t *thread = NULL;
-			
+
 			/* Search rq from the back */
 			link_t *link = cpu->rq[rq].rq.head.prev;
-			
+
 			while (link != &(cpu->rq[rq].rq.head)) {
 				thread = (thread_t *) list_get_instance(link,
 				    thread_t, rq_link);
-				
+
 				/*
 				 * Do not steal CPU-wired threads, threads
@@ -640,5 +640,5 @@
 				 */
 				irq_spinlock_lock(&thread->lock, false);
-				
+
 				if ((!thread->wired) && (!thread->stolen) &&
 				    (!thread->nomigrate) &&
@@ -649,28 +649,28 @@
 					irq_spinlock_unlock(&thread->lock,
 					    false);
-					
+
 					atomic_dec(&cpu->nrdy);
 					atomic_dec(&nrdy);
-					
+
 					cpu->rq[rq].n--;
 					list_remove(&thread->rq_link);
-					
+
 					break;
 				}
-				
+
 				irq_spinlock_unlock(&thread->lock, false);
-				
+
 				link = link->prev;
 				thread = NULL;
 			}
-			
+
 			if (thread) {
 				/*
 				 * Ready thread on local CPU
 				 */
-				
+
 				irq_spinlock_pass(&(cpu->rq[rq].lock),
 				    &thread->lock);
-				
+
 #ifdef KCPULB_VERBOSE
 				log(LF_OTHER, LVL_DEBUG,
@@ -680,14 +680,14 @@
 				    atomic_get(&nrdy) / config.cpu_active);
 #endif
-				
+
 				thread->stolen = true;
 				thread->state = Entering;
-				
+
 				irq_spinlock_unlock(&thread->lock, true);
 				thread_ready(thread);
-				
+
 				if (--count == 0)
 					goto satisfied;
-				
+
 				/*
 				 * We are not satisfied yet, focus on another
@@ -696,12 +696,12 @@
 				 */
 				acpu_bias++;
-				
+
 				continue;
 			} else
 				irq_spinlock_unlock(&(cpu->rq[rq].lock), true);
-			
-		}
-	}
-	
+
+		}
+	}
+
 	if (atomic_get(&CPU->nrdy)) {
 		/*
@@ -718,7 +718,7 @@
 		goto loop;
 	}
-	
+
 	goto not_satisfied;
-	
+
 satisfied:
 	goto loop;
@@ -735,11 +735,11 @@
 		if (!cpus[cpu].active)
 			continue;
-		
+
 		irq_spinlock_lock(&cpus[cpu].lock, true);
-		
+
 		printf("cpu%u: address=%p, nrdy=%" PRIua ", needs_relink=%zu\n",
 		    cpus[cpu].id, &cpus[cpu], atomic_get(&cpus[cpu].nrdy),
 		    cpus[cpu].needs_relink);
-		
+
 		unsigned int i;
 		for (i = 0; i < RQ_COUNT; i++) {
@@ -749,5 +749,5 @@
 				continue;
 			}
-			
+
 			printf("\trq[%u]: ", i);
 			list_foreach(cpus[cpu].rq[i].rq, rq_link, thread_t,
@@ -757,8 +757,8 @@
 			}
 			printf("\n");
-			
+
 			irq_spinlock_unlock(&(cpus[cpu].rq[i].lock), false);
 		}
-		
+
 		irq_spinlock_unlock(&cpus[cpu].lock, true);
 	}
