Index: kernel/generic/src/console/cmd.c
===================================================================
--- kernel/generic/src/console/cmd.c	(revision 34db7fa828e4d10ee2a902fb4143704b3feda184)
+++ kernel/generic/src/console/cmd.c	(revision e9db6f9e50ba52202778e3452d8cdfe5176e84b6)
@@ -68,8 +68,4 @@
 #ifdef CONFIG_TEST
 #include <test.h>
-#endif
-
-#ifdef CONFIG_BENCH
-#include <arch/cycle.h>
 #endif
 
@@ -866,12 +862,26 @@
 {
 	printf("%s\t\t%s\n", test->name, test->desc);
-#ifdef CONFIG_BENCH
-	uint64_t t0 = get_cycle();
-#endif
+	
+	/* Update and read thread accounting
+	   for benchmarking */
+	ipl_t ipl = interrupts_disable();
+	spinlock_lock(&THREAD->lock);
+	thread_update_accounting();
+	uint64_t t0 = THREAD->cycles;
+	spinlock_unlock(&THREAD->lock);
+	interrupts_restore(ipl);
+	
+	/* Execute the test */
 	char * ret = test->entry();
-#ifdef CONFIG_BENCH
-	uint64_t dt = get_cycle() - t0;
+	
+	/* Update and read thread accounting */
+	ipl = interrupts_disable();
+	spinlock_lock(&THREAD->lock);
+	thread_update_accounting();
+	uint64_t dt = THREAD->cycles - t0;
+	spinlock_unlock(&THREAD->lock);
+	interrupts_restore(ipl);
+	
 	printf("Time: %llu cycles\n", dt);
-#endif
 	
 	if (ret == NULL) {
Index: kernel/generic/src/proc/scheduler.c
===================================================================
--- kernel/generic/src/proc/scheduler.c	(revision 34db7fa828e4d10ee2a902fb4143704b3feda184)
+++ kernel/generic/src/proc/scheduler.c	(revision e9db6f9e50ba52202778e3452d8cdfe5176e84b6)
@@ -48,4 +48,5 @@
 #include <arch/asm.h>
 #include <arch/faddr.h>
+#include <arch/cycle.h>
 #include <atomic.h>
 #include <synch/spinlock.h>
@@ -309,4 +310,8 @@
 	if (THREAD) {
 		spinlock_lock(&THREAD->lock);
+		
+		/* Update thread accounting */
+		THREAD->cycles += get_cycle() - THREAD->last_cycle;
+		
 #ifndef CONFIG_FPU_LAZY
 		fpu_context_save(THREAD->saved_fpu_context);
@@ -316,4 +321,8 @@
 			 * This is the place where threads leave scheduler();
 			 */
+			
+			/* Save current CPU cycle */
+			THREAD->last_cycle = get_cycle();
+			
 			spinlock_unlock(&THREAD->lock);
 			interrupts_restore(THREAD->saved_context.ipl);
Index: kernel/generic/src/proc/thread.c
===================================================================
--- kernel/generic/src/proc/thread.c	(revision 34db7fa828e4d10ee2a902fb4143704b3feda184)
+++ kernel/generic/src/proc/thread.c	(revision e9db6f9e50ba52202778e3452d8cdfe5176e84b6)
@@ -43,4 +43,5 @@
 #include <mm/page.h>
 #include <arch/asm.h>
+#include <arch/cycle.h>
 #include <arch.h>
 #include <synch/synch.h>
@@ -326,4 +327,5 @@
 	t->thread_arg = arg;
 	t->ticks = -1;
+	t->cycles = 0;
 	t->priority = -1;		/* start in rq[0] */
 	t->cpu = NULL;
@@ -530,4 +532,7 @@
 	ipl = interrupts_disable();
 	spinlock_lock(&threads_lock);
+	
+	printf("tid    name       address    state    task       ctx code       stack      cycles     cpu  kst        wq\n");
+	printf("------ ---------- ---------- -------- ---------- --- ---------- ---------- ---------- ---- ---------- ----------\n");
 
 	for (cur = threads_btree.leaf_head.next; cur != &threads_btree.leaf_head; cur = cur->next) {
@@ -540,14 +545,32 @@
 		
 			t = (thread_t *) node->value[i];
-			printf("%s: address=%#zx, tid=%zd, state=%s, task=%#zx, context=%ld, code=%#zx, stack=%#zx, cpu=",
-				t->name, t, t->tid, thread_states[t->state], t->task, t->task->context, t->thread_code, t->kstack);
+			
+			uint64_t cycles;
+			char suffix;
+			
+			if (t->cycles > 1000000000000000000LL) {
+				cycles = t->cycles / 1000000000000000000LL;
+				suffix = 'E';
+			} else if (t->cycles > 1000000000000LL) {
+				cycles = t->cycles / 1000000000000LL;
+				suffix = 'T';
+			} else if (t->cycles > 1000000LL) {
+				cycles = t->cycles / 1000000LL;
+				suffix = 'M';
+			} else {
+				cycles = t->cycles;
+				suffix = ' ';
+			}
+			
+			printf("%-6zd %-10s %#10zx %-8s %#10zx %-3ld %#10zx %#10zx %9llu%c ", t->tid, t->name, t, thread_states[t->state], t->task, t->task->context, t->thread_code, t->kstack, cycles, suffix);
+			
 			if (t->cpu)
-				printf("cpu%zd", t->cpu->id);
+				printf("%-4zd", t->cpu->id);
 			else
 				printf("none");
-			if (t->state == Sleeping) {
-				printf(", kst=%#zx", t->kstack);
-				printf(", wq=%#zx", t->sleep_queue);
-			}
+			
+			if (t->state == Sleeping)
+				printf(" %#10zx %#10zx", t->kstack, t->sleep_queue);
+			
 			printf("\n");
 		}
@@ -572,4 +595,20 @@
 	
 	return btree_search(&threads_btree, (btree_key_t) ((uintptr_t) t), &leaf) != NULL;
+}
+
+
+/** Update accounting of current thread.
+ *
+ * Note that thread_lock on THREAD must be already held and
+ * interrupts must be already disabled.
+ *
+ * @param t Pointer to thread.
+ *
+ */
+void thread_update_accounting(void)
+{
+	uint64_t time = get_cycle();
+	THREAD->cycles += time - THREAD->last_cycle;
+	THREAD->last_cycle = time;
 }
 
