Index: trunk/kernel/kern/thread.c
===================================================================
--- trunk/kernel/kern/thread.c	(revision 633)
+++ trunk/kernel/kern/thread.c	(revision 635)
@@ -78,18 +78,12 @@
 static thread_t * thread_alloc( void )
 {
-	page_t       * page;   // pointer on page descriptor containing thread descriptor
 	kmem_req_t     req;    // kmem request
 
 	// allocates memory for thread descriptor + kernel stack
-	req.type  = KMEM_PAGE;
-	req.size  = CONFIG_THREAD_DESC_ORDER;
+	req.type  = KMEM_PPM;
+	req.order = CONFIG_THREAD_DESC_ORDER;
 	req.flags = AF_KERNEL | AF_ZERO;
-	page      = kmem_alloc( &req );
-
-	if( page == NULL ) return NULL;
-
-    // return pointer on new thread descriptor
-    xptr_t base_xp = ppm_page2base( XPTR(local_cxy , page ) );
-    return GET_PTR( base_xp );
+
+    return kmem_alloc( &req );
 
 }  // end thread_alloc()
@@ -125,5 +119,5 @@
 {
 
-// check type and trdid fields initialized
+// check type and trdid fields are initialized
 assert( (thread->type == type)   , "bad type argument" );
 assert( (thread->trdid == trdid) , "bad trdid argument" );
@@ -133,6 +127,6 @@
 thread_t * this  = CURRENT_THREAD;
 if( DEBUG_THREAD_INIT < cycle )
-printk("\n[%s] thread[%x,%x] enter for thread %x in process %x / cycle %d\n",
-__FUNCTION__, this->process->pid, this->trdid, thread->trdid, process->pid , cycle );
+printk("\n[%s] thread[%x,%x] enter for thread[%x,%x] / cycle %d\n",
+__FUNCTION__, this->process->pid, this->trdid, process->pid, thread->trdid, cycle );
 #endif
 
@@ -192,6 +186,6 @@
 cycle = (uint32_t)hal_get_cycles();
 if( DEBUG_THREAD_INIT < cycle )
-printk("\n[%s] thread[%x,%x] exit for thread %x in process %x / cycle %d\n",
-__FUNCTION__, this->process->pid, this->trdid, thread, process->pid, cycle );
+printk("\n[%s] thread[%x,%x] exit for thread[%x,%x] / cycle %d\n",
+__FUNCTION__, this->process->pid, this->trdid, process->pid, thread->trdid, cycle );
 #endif
 
@@ -580,4 +574,5 @@
     vpn_t  parent_vpn_size = hal_remote_l32( XPTR( parent_cxy, &parent_us_vseg->vpn_size ) );
     vpn_t  child_vpn_base  = child_us_vseg->vpn_base;
+
     for( parent_vpn = parent_vpn_base , child_vpn = child_vpn_base ; 
          parent_vpn < (parent_vpn_base + parent_vpn_size) ;
@@ -625,5 +620,5 @@
 #if (DEBUG_THREAD_USER_FORK & 1)
 if( DEBUG_THREAD_USER_FORK < cycle )
-printk("\n[%s] thread[%x,%x] copied all stack vseg PTEs to child GPT\n",
+printk("\n[%s] thread[%x,%x] copied STACK vseg PTEs & set COW in child GPT\n",
 __FUNCTION__, this->process->pid, this->trdid );
 #endif
@@ -636,5 +631,5 @@
 #if (DEBUG_THREAD_USER_FORK & 1)
 if( DEBUG_THREAD_USER_FORK < cycle )
-printk("\n[%s] thread[%x,%x] set the COW flag for stack vseg in parent GPT\n",
+printk("\n[%s] thread[%x,%x] set COW for STACK vseg in parent GPT\n",
 __FUNCTION__, this->process->pid, this->trdid );
 #endif
@@ -906,11 +901,17 @@
     thread_assert_can_yield( thread , __FUNCTION__ );
 
-    // update target process instrumentation counter
-	// process->vmm.pgfault_nr += thread->info.pgfault_nr;
+#if CONFIG_INSTRUMENTATION_PGFAULTS
+	process->vmm.false_pgfault_nr    += thread->info.false_pgfault_nr;
+	process->vmm.local_pgfault_nr    += thread->info.local_pgfault_nr;
+	process->vmm.global_pgfault_nr   += thread->info.global_pgfault_nr;
+	process->vmm.false_pgfault_cost  += thread->info.false_pgfault_cost;
+	process->vmm.local_pgfault_cost  += thread->info.local_pgfault_cost;
+	process->vmm.global_pgfault_cost += thread->info.global_pgfault_cost;
+#endif
 
     // remove thread from process th_tbl[]
     count = process_remove_thread( thread );
 
-    // release memory allocated for CPU context and FPU context if required
+    // release memory allocated for CPU context and FPU context
 	hal_cpu_context_destroy( thread );
 	hal_fpu_context_destroy( thread );
@@ -933,8 +934,6 @@
     // release memory for thread descriptor (including kernel stack)
     kmem_req_t   req;
-    xptr_t       base_xp = ppm_base2page( XPTR(local_cxy , thread ) );
-
-    req.type  = KMEM_PAGE;
-    req.ptr   = GET_PTR( base_xp );
+    req.type  = KMEM_PPM;
+    req.ptr   = thread;
     kmem_free( &req );
 
