Index: kernel/arch/ppc32/include/interrupt.h
===================================================================
--- kernel/arch/ppc32/include/interrupt.h	(revision 3193c0558f847619377280b6f87fde226e0479e1)
+++ kernel/arch/ppc32/include/interrupt.h	(revision 538780736253a52c38332ffe3f75d60f64190f4e)
@@ -48,5 +48,5 @@
 extern void start_decrementer(void);
 extern void interrupt_init(void);
-extern void extint_handler(int, istate_t *);
+extern void extint_handler(unsigned int, istate_t *);
 
 #endif
Index: kernel/arch/ppc32/include/mm/tlb.h
===================================================================
--- kernel/arch/ppc32/include/mm/tlb.h	(revision 3193c0558f847619377280b6f87fde226e0479e1)
+++ kernel/arch/ppc32/include/mm/tlb.h	(revision 538780736253a52c38332ffe3f75d60f64190f4e)
@@ -76,10 +76,10 @@
 
 extern void pht_init(void);
-extern void pht_refill(int, istate_t *);
+extern void pht_refill(unsigned int, istate_t *);
 
-extern bool pht_refill_real(int, istate_t *)
+extern bool pht_refill_real(unsigned int, istate_t *)
     __attribute__ ((section("K_UNMAPPED_TEXT_START")));
-extern void tlb_refill_real(int, uint32_t, ptehi_t, ptelo_t, istate_t *)
-    __attribute__ ((section("K_UNMAPPED_TEXT_START")));
+extern void tlb_refill_real(unsigned int, uint32_t, ptehi_t, ptelo_t,
+    istate_t *) __attribute__ ((section("K_UNMAPPED_TEXT_START")));
 
 #endif
Index: kernel/arch/ppc32/src/interrupt.c
===================================================================
--- kernel/arch/ppc32/src/interrupt.c	(revision 3193c0558f847619377280b6f87fde226e0479e1)
+++ kernel/arch/ppc32/src/interrupt.c	(revision 538780736253a52c38332ffe3f75d60f64190f4e)
@@ -55,5 +55,5 @@
  *
  */
-static void exception_external(int n, istate_t *istate)
+static void exception_external(unsigned int n, istate_t *istate)
 {
 	uint8_t inum;
@@ -92,5 +92,5 @@
 }
 
-static void exception_decrementer(int n, istate_t *istate)
+static void exception_decrementer(unsigned int n, istate_t *istate)
 {
 	start_decrementer();
Index: kernel/arch/ppc32/src/mm/tlb.c
===================================================================
--- kernel/arch/ppc32/src/mm/tlb.c	(revision 3193c0558f847619377280b6f87fde226e0479e1)
+++ kernel/arch/ppc32/src/mm/tlb.c	(revision 538780736253a52c38332ffe3f75d60f64190f4e)
@@ -209,5 +209,5 @@
  *
  */
-void pht_refill(int n, istate_t *istate)
+void pht_refill(unsigned int n, istate_t *istate)
 {
 	as_t *as = (AS == NULL) ? AS_KERNEL : AS;
@@ -260,5 +260,5 @@
  *
  */
-bool pht_refill_real(int n, istate_t *istate)
+bool pht_refill_real(unsigned int n, istate_t *istate)
 {
 	uintptr_t badvaddr;
@@ -366,5 +366,6 @@
  *
  */
-void tlb_refill_real(int n, uint32_t tlbmiss, ptehi_t ptehi, ptelo_t ptelo, istate_t *istate)
+void tlb_refill_real(unsigned int n, uint32_t tlbmiss, ptehi_t ptehi,
+    ptelo_t ptelo, istate_t *istate)
 {
 	uint32_t badvaddr = tlbmiss & 0xfffffffc;
Index: kernel/arch/sparc64/include/drivers/tick.h
===================================================================
--- kernel/arch/sparc64/include/drivers/tick.h	(revision 3193c0558f847619377280b6f87fde226e0479e1)
+++ kernel/arch/sparc64/include/drivers/tick.h	(revision 538780736253a52c38332ffe3f75d60f64190f4e)
@@ -27,5 +27,5 @@
  */
 
-/** @addtogroup sparc64	
+/** @addtogroup sparc64
  * @{
  */
@@ -40,8 +40,8 @@
 
 /* mask of the "counter" field of the Tick register */
-#define TICK_COUNTER_MASK	(~(1l << 63))
+#define TICK_COUNTER_MASK  (~(1l << 63))
 
 extern void tick_init(void);
-extern void tick_interrupt(int n, istate_t *istate);
+extern void tick_interrupt(unsigned int, istate_t *);
 
 /**
Index: kernel/arch/sparc64/src/drivers/tick.c
===================================================================
--- kernel/arch/sparc64/src/drivers/tick.c	(revision 3193c0558f847619377280b6f87fde226e0479e1)
+++ kernel/arch/sparc64/src/drivers/tick.c	(revision 538780736253a52c38332ffe3f75d60f64190f4e)
@@ -27,5 +27,5 @@
  */
 
-/** @addtogroup sparc64	
+/** @addtogroup sparc64
  * @{
  */
@@ -77,8 +77,9 @@
 /** Process tick interrupt.
  *
- * @param n Interrupt Level, 14,  (can be ignored)
+ * @param n      Interrupt Level (14, can be ignored)
  * @param istate Interrupted state.
+ *
  */
-void tick_interrupt(int n, istate_t *istate)
+void tick_interrupt(unsigned int n, istate_t *istate)
 {
 	softint_reg_t softint, clear;
Index: kernel/generic/include/cpu.h
===================================================================
--- kernel/generic/include/cpu.h	(revision 3193c0558f847619377280b6f87fde226e0479e1)
+++ kernel/generic/include/cpu.h	(revision 538780736253a52c38332ffe3f75d60f64190f4e)
@@ -72,7 +72,11 @@
 	size_t missed_clock_ticks;
 	
+	/**
+	 * Processor cycle accounting.
+	 */
 	bool idle;
-	uint64_t idle_ticks;
-	uint64_t busy_ticks;
+	uint64_t last_cycle;
+	uint64_t idle_cycles;
+	uint64_t busy_cycles;
 	
 	/**
Index: kernel/generic/include/sysinfo/abi.h
===================================================================
--- kernel/generic/include/sysinfo/abi.h	(revision 3193c0558f847619377280b6f87fde226e0479e1)
+++ kernel/generic/include/sysinfo/abi.h	(revision 538780736253a52c38332ffe3f75d60f64190f4e)
@@ -69,6 +69,6 @@
 	bool active;             /**< CPU is activate */
 	uint16_t frequency_mhz;  /**< Frequency in MHz */
-	uint64_t idle_ticks;     /**< Number of idle kernel quanta */
-	uint64_t busy_ticks;     /**< Number of busy kernel quanta */
+	uint64_t idle_cycles;    /**< Number of idle cycles */
+	uint64_t busy_cycles;    /**< Number of busy cycles */
 } stats_cpu_t;
 
Index: kernel/generic/src/cpu/cpu.c
===================================================================
--- kernel/generic/src/cpu/cpu.c	(revision 3193c0558f847619377280b6f87fde226e0479e1)
+++ kernel/generic/src/cpu/cpu.c	(revision 538780736253a52c38332ffe3f75d60f64190f4e)
@@ -49,4 +49,5 @@
 #include <print.h>
 #include <sysinfo/sysinfo.h>
+#include <arch/cycle.h>
 
 cpu_t *cpus;
@@ -94,4 +95,9 @@
 	CPU->tlb_active = true;
 	
+	CPU->idle = false;
+	CPU->last_cycle = get_cycle();
+	CPU->idle_cycles = 0;
+	CPU->busy_cycles = 0;
+	
 	cpu_identify();
 	cpu_arch_init();
Index: kernel/generic/src/interrupt/interrupt.c
===================================================================
--- kernel/generic/src/interrupt/interrupt.c	(revision 3193c0558f847619377280b6f87fde226e0479e1)
+++ kernel/generic/src/interrupt/interrupt.c	(revision 538780736253a52c38332ffe3f75d60f64190f4e)
@@ -99,4 +99,6 @@
 void exc_dispatch(unsigned int n, istate_t *istate)
 {
+	ASSERT(CPU);
+	
 #if (IVT_ITEMS > 0)
 	ASSERT(n < IVT_ITEMS);
@@ -109,4 +111,14 @@
 		irq_spinlock_unlock(&THREAD->lock, false);
 	}
+	
+	/* Account CPU usage if it has waked up from sleep */
+	irq_spinlock_lock(&CPU->lock, false);
+	if (CPU->idle) {
+		uint64_t now = get_cycle();
+		CPU->idle_cycles += now - CPU->last_cycle;
+		CPU->last_cycle = now;
+		CPU->idle = false;
+	}
+	irq_spinlock_unlock(&CPU->lock, false);
 	
 	uint64_t begin_cycle = get_cycle();
Index: kernel/generic/src/main/kinit.c
===================================================================
--- kernel/generic/src/main/kinit.c	(revision 3193c0558f847619377280b6f87fde226e0479e1)
+++ kernel/generic/src/main/kinit.c	(revision 538780736253a52c38332ffe3f75d60f64190f4e)
@@ -181,4 +181,5 @@
 		if (init.tasks[i].addr % FRAME_SIZE) {
 			printf("init[%" PRIs "].addr is not frame aligned\n", i);
+			programs[i].task = NULL;
 			continue;
 		}
Index: kernel/generic/src/proc/scheduler.c
===================================================================
--- kernel/generic/src/proc/scheduler.c	(revision 3193c0558f847619377280b6f87fde226e0479e1)
+++ kernel/generic/src/proc/scheduler.c	(revision 538780736253a52c38332ffe3f75d60f64190f4e)
@@ -193,11 +193,9 @@
 		 * This improves energy saving and hyperthreading.
 		 */
-		
-		 /* Mark CPU as it was idle this clock tick */
 		irq_spinlock_lock(&CPU->lock, false);
 		CPU->idle = true;
 		irq_spinlock_unlock(&CPU->lock, false);
-		
 		interrupts_enable();
+		
 		/*
 		 * An interrupt might occur right now and wake up a thread.
@@ -386,5 +384,5 @@
 	as_t *old_as = AS;
 	
-	ASSERT(!THREAD || irq_spinlock_locked(&THREAD->lock));
+	ASSERT((!THREAD) || (irq_spinlock_locked(&THREAD->lock)));
 	ASSERT(CPU != NULL);
 	
Index: kernel/generic/src/sysinfo/stats.c
===================================================================
--- kernel/generic/src/sysinfo/stats.c	(revision 3193c0558f847619377280b6f87fde226e0479e1)
+++ kernel/generic/src/sysinfo/stats.c	(revision 538780736253a52c38332ffe3f75d60f64190f4e)
@@ -124,6 +124,6 @@
 		stats_cpus[i].active = cpus[i].active;
 		stats_cpus[i].frequency_mhz = cpus[i].frequency_mhz;
-		stats_cpus[i].busy_ticks = cpus[i].busy_ticks;
-		stats_cpus[i].idle_ticks = cpus[i].idle_ticks;
+		stats_cpus[i].busy_cycles = cpus[i].busy_cycles;
+		stats_cpus[i].idle_cycles = cpus[i].idle_cycles;
 		
 		irq_spinlock_unlock(&cpus[i].lock, true);
Index: kernel/generic/src/time/clock.c
===================================================================
--- kernel/generic/src/time/clock.c	(revision 3193c0558f847619377280b6f87fde226e0479e1)
+++ kernel/generic/src/time/clock.c	(revision 538780736253a52c38332ffe3f75d60f64190f4e)
@@ -57,4 +57,5 @@
 #include <mm/frame.h>
 #include <ddi/ddi.h>
+#include <arch/cycle.h>
 
 /* Pointer to variable with uptime */
@@ -125,4 +126,13 @@
 }
 
+static void cpu_update_accounting(void)
+{
+	irq_spinlock_lock(&CPU->lock, false);
+	uint64_t now = get_cycle();
+	CPU->busy_cycles += now - CPU->last_cycle;
+	CPU->last_cycle = now;
+	irq_spinlock_unlock(&CPU->lock, false);
+}
+
 /** Clock routine
  *
@@ -136,11 +146,6 @@
 	size_t missed_clock_ticks = CPU->missed_clock_ticks;
 	
-	/* Account lost ticks to CPU usage */
-	if (CPU->idle)
-		CPU->idle_ticks += missed_clock_ticks + 1;
-	else
-		CPU->busy_ticks += missed_clock_ticks + 1;
-	
-	CPU->idle = false;
+	/* Account CPU usage */
+	cpu_update_accounting();
 	
 	/*
@@ -151,5 +156,8 @@
 	size_t i;
 	for (i = 0; i <= missed_clock_ticks; i++) {
+		/* Update counters and accounting */
 		clock_update_counters();
+		cpu_update_accounting();
+		
 		irq_spinlock_lock(&CPU->timeoutlock, false);
 		
