Index: trunk/kernel/mm/vmm.c
===================================================================
--- trunk/kernel/mm/vmm.c	(revision 585)
+++ trunk/kernel/mm/vmm.c	(revision 595)
@@ -4,5 +4,5 @@
  * Authors   Ghassan Almaless (2008,2009,2010,2011, 2012)
  *           Mohamed Lamine Karaoui (2015)
- *           Alain Greiner (2016)
+ *           Alain Greiner (2016,2017,2018)
  *
  * Copyright (c) UPMC Sorbonne Universites
@@ -69,6 +69,6 @@
 uint32_t cycle = (uint32_t)hal_get_cycles();
 if( DEBUG_VMM_INIT )
-printk("\n[DBG] %s : thread %x in process %x enter for process %x / cycle %d\n", 
-__FUNCTION__ , this->trdid, this->process->pid, process->pid , cycle );
+printk("\n[%s] thread[%x,%x] enter for process %x / cycle %d\n", 
+__FUNCTION__ , this->process->pid, this->trdid, process->pid , cycle );
 #endif
 
@@ -195,6 +195,6 @@
 cycle = (uint32_t)hal_get_cycles();
 if( DEBUG_VMM_INIT )
-printk("\n[DBG] %s : thread %x in process %x exit / process %x / entry_point = %x / cycle %d\n", 
-__FUNCTION__, this->trdid, this->process->pid, process->pid , process->vmm.entry_point , cycle );
+printk("\n[%s] thread[%x,%x] exit / process %x / entry_point %x / cycle %d\n", 
+__FUNCTION__, this->process->pid, this->trdid, process->pid, process->vmm.entry_point, cycle );
 #endif
 
@@ -295,5 +295,5 @@
 }
 
-/////////////////////i//////////////////////////
+////////////////////////////////////////////////
 void vmm_global_update_pte( process_t * process,
                             vpn_t       vpn,
@@ -316,7 +316,8 @@
 #if DEBUG_VMM_UPDATE_PTE
 uint32_t cycle = (uint32_t)hal_get_cycles();
+thread_t * this = CURRENT_THREAD;
 if( DEBUG_VMM_UPDATE_PTE < cycle )
-printk("\n[DBG] %s : thread %x enter for process %x / vpn %x / cycle %d\n",
-__FUNCTION__ , CURRENT_THREAD , process->pid , vpn , cycle );
+printk("\n[%s] thread[%x,%x] enter for process %x / vpn %x / cycle %d\n",
+__FUNCTION__, this->process->pid, this->trdid, process->pid , vpn , cycle );
 #endif
 
@@ -341,6 +342,6 @@
 #if (DEBUG_VMM_UPDATE_PTE & 0x1)
 if( DEBUG_VMM_UPDATE_PTE < cycle )
-printk("\n[DBG] %s : thread %x handling process %x in cluster %x\n",
-__FUNCTION__ , CURRENT_THREAD , process->pid , remote_process_cxy );
+printk("\n[%s] threadr[%x,%x] handling vpn %x for process %x in cluster %x\n",
+__FUNCTION__, this->process->pid, this->trdid, vpn, process->pid, remote_process_cxy );
 #endif
 
@@ -355,6 +356,6 @@
 cycle = (uint32_t)hal_get_cycles();
 if( DEBUG_VMM_UPDATE_PTE < cycle )
-printk("\n[DBG] %s : thread %x exit for process %x / vpn %x / cycle %d\n",
-__FUNCTION__ , CURRENT_THREAD , process->pid , vpn , cycle );
+printk("\n[%s] thread[%x,%x] exit for process %x / vpn %x / cycle %d\n",
+__FUNCTION__, this->process->pid, this->trdid, process->pid , vpn , cycle );
 #endif
 
@@ -386,8 +387,9 @@
 
 #if DEBUG_VMM_SET_COW
-uint32_t cycle = (uint32_t)hal_get_cycles();
+uint32_t   cycle = (uint32_t)hal_get_cycles();
+thread_t * this  = CURRENT_THREAD;
 if( DEBUG_VMM_SET_COW < cycle )
-printk("\n[DBG] %s : thread %x enter for process %x / cycle %d\n",
-__FUNCTION__ , CURRENT_THREAD , process->pid , cycle );
+printk("\n[%s] thread[%x,%x] enter for process %x / cycle %d\n",
+__FUNCTION__, this->process->pid, this->trdid, process->pid , cycle );
 #endif
 
@@ -417,8 +419,8 @@
         remote_process_cxy = GET_CXY( remote_process_xp );
 
-#if (DEBUG_VMM_SET_COW &0x1)
+#if (DEBUG_VMM_SET_COW & 1)
 if( DEBUG_VMM_SET_COW < cycle )
-printk("\n[DBG] %s : thread %x handling process %x in cluster %x\n",
-__FUNCTION__ , CURRENT_THREAD , process->pid , remote_process_cxy );
+printk("\n[%s] thread[%x,%x] handling process %x in cluster %x\n",
+__FUNCTION__, this->process->pid, this->trdid, process->pid , remote_process_cxy );
 #endif
 
@@ -441,8 +443,8 @@
             vpn_t    vpn_size = vseg->vpn_size;
 
-#if (DEBUG_VMM_SET_COW & 0x1)
+#if (DEBUG_VMM_SET_COW & 1)
 if( DEBUG_VMM_SET_COW < cycle )
-printk("\n[DBG] %s : thread %x handling vseg %s / vpn_base = %x / vpn_size = %x\n",
-__FUNCTION__, CURRENT_THREAD , vseg_type_str(type), vpn_base, vpn_size );
+printk("\n[%s] thread[%x,%x] handling vseg %s / vpn_base = %x / vpn_size = %x\n",
+__FUNCTION__, this->process->pid, this->trdid, vseg_type_str(type), vpn_base, vpn_size );
 #endif
             // only DATA, ANON and REMOTE vsegs
@@ -505,6 +507,6 @@
 cycle = (uint32_t)hal_get_cycles();
 if( DEBUG_VMM_SET_COW < cycle )
-printk("\n[DBG] %s : thread %x exit for process %x / cycle %d\n",
-__FUNCTION__ , CURRENT_THREAD , process->pid , cycle );
+printk("\n[%s] thread[%x,%x] exit for process %x / cycle %d\n",
+__FUNCTION__, this->process->pid, this->trdid, process->pid , cycle );
 #endif
 
@@ -541,7 +543,8 @@
 #if DEBUG_VMM_FORK_COPY
 uint32_t cycle = (uint32_t)hal_get_cycles();
+thread_t * this = CURRENT_THREAD;
 if( DEBUG_VMM_FORK_COPY < cycle )
-printk("\n[DBG] %s : thread %x enter / cycle %d\n",
-__FUNCTION__ , CURRENT_THREAD, cycle );
+printk("\n[%s] thread %x enter / cycle %d\n",
+__FUNCTION__ , this->process->pid, this->trdid, cycle );
 #endif
 
@@ -592,6 +595,6 @@
 cycle = (uint32_t)hal_get_cycles();
 if( DEBUG_VMM_FORK_COPY < cycle )
-printk("\n[DBG] %s : thread %x found parent vseg %s / vpn_base = %x / cycle %d\n",
-__FUNCTION__ , CURRENT_THREAD, vseg_type_str(type),
+printk("\n[%s] thread[%x,%x] found parent vseg %s / vpn_base = %x / cycle %d\n",
+__FUNCTION__ , this->process->pid, this->trdid, vseg_type_str(type),
 hal_remote_l32( XPTR( parent_cxy , &parent_vseg->vpn_base ) ) , cycle );
 #endif
@@ -618,6 +621,6 @@
 cycle = (uint32_t)hal_get_cycles();
 if( DEBUG_VMM_FORK_COPY < cycle )
-printk("\n[DBG] %s : thread %x copied vseg %s / vpn_base = %x to child VSL / cycle %d\n",
-__FUNCTION__ , CURRENT_THREAD , vseg_type_str(type),
+printk("\n[%s] thread[%x,%x] copied vseg %s / vpn_base = %x to child VSL / cycle %d\n",
+__FUNCTION__ , this->process->pid, this->trdid, vseg_type_str(type),
 hal_remote_l32( XPTR( parent_cxy , &parent_vseg->vpn_base ) ) , cycle );
 #endif
@@ -672,6 +675,6 @@
 cycle = (uint32_t)hal_get_cycles();
 if( DEBUG_VMM_FORK_COPY < cycle )
-printk("\n[DBG] %s : thread %x copied vpn %x to child GPT / cycle %d\n",
-__FUNCTION__ , CURRENT_THREAD , vpn , cycle );
+printk("\n[%s] thread[%x,%x] copied vpn %x to child GPT / cycle %d\n",
+__FUNCTION__ , this->process->pid, this->trdid , vpn , cycle );
 #endif
                     }
@@ -723,6 +726,6 @@
 cycle = (uint32_t)hal_get_cycles();
 if( DEBUG_VMM_FORK_COPY < cycle )
-printk("\n[DBG] %s : thread %x exit successfully / cycle %d\n",
-__FUNCTION__ , CURRENT_THREAD , cycle );
+printk("\n[%s] thread[%x,%x] exit successfully / cycle %d\n",
+__FUNCTION__ , this->process->pid, this->trdid , cycle );
 #endif
 
@@ -739,7 +742,8 @@
 #if DEBUG_VMM_DESTROY
 uint32_t cycle = (uint32_t)hal_get_cycles();
+thread_t * this = CURRENT_THREAD;
 if( DEBUG_VMM_DESTROY < cycle )
-printk("\n[DBG] %s : thread %x enter for process %x in cluster %x / cycle %d\n",
-__FUNCTION__, CURRENT_THREAD->trdid, process->pid, local_cxy, cycle );
+printk("\n[%s] thread[%x,%x] enter for process %x in cluster %x / cycle %d\n",
+__FUNCTION__, this->process->pid, this->trdid, process->pid, local_cxy, cycle );
 #endif
 
@@ -773,5 +777,5 @@
 #if( DEBUG_VMM_DESTROY & 1 )
 if( DEBUG_VMM_DESTROY < cycle )
-printk("\n[DBG] %s : %s vseg released / vpn_base %x / vpn_size %d\n",
+printk("\n[%s] %s vseg released / vpn_base %x / vpn_size %d\n",
 __FUNCTION__ , vseg_type_str( vseg->type ), vseg->vpn_base, vseg->vpn_size );
 #endif
@@ -789,5 +793,5 @@
 #if( DEBUG_VMM_DESTROY & 1 )
 if( DEBUG_VMM_DESTROY < cycle )
-printk("\n[DBG] %s : found zombi vseg / vpn_base %x / vpn_size %d\n",
+printk("\n[%s] found zombi vseg / vpn_base %x / vpn_size %d\n",
 __FUNCTION__ , vseg_type_str( vseg->type ), vseg->vpn_base, vseg->vpn_size );
 #endif
@@ -797,5 +801,5 @@
 #if( DEBUG_VMM_DESTROY & 1 )
 if( DEBUG_VMM_DESTROY < cycle )
-printk("\n[DBG] %s : zombi vseg released / vpn_base %x / vpn_size %d\n",
+printk("\n[%s] zombi vseg released / vpn_base %x / vpn_size %d\n",
 __FUNCTION__ , vseg_type_str( vseg->type ), vseg->vpn_base, vseg->vpn_size );
 #endif
@@ -809,6 +813,6 @@
 cycle = (uint32_t)hal_get_cycles();
 if( DEBUG_VMM_DESTROY < cycle )
-printk("\n[DBG] %s : thread %x exit for process %x in cluster %x / cycle %d\n",
-__FUNCTION__, CURRENT_THREAD->trdid, process->pid, local_cxy , cycle );
+printk("\n[%s] thread[%x,%x] exit for process %x in cluster %x / cycle %d\n",
+__FUNCTION__, this->process->pid, this->trdid, process->pid, local_cxy , cycle );
 #endif
 
@@ -957,12 +961,13 @@
     vseg_t     * vseg;          // created vseg pointer
     vpn_t        vpn_base;      // first page index
-    vpn_t        vpn_size;      // number of pages
+    vpn_t        vpn_size;      // number of pages covered by vseg
 	error_t      error;
 
 #if DEBUG_VMM_CREATE_VSEG
-uint32_t cycle = (uint32_t)hal_get_cycles();
+thread_t * this  = CURRENT_THREAD;
+uint32_t   cycle = (uint32_t)hal_get_cycles();
 if( DEBUG_VMM_CREATE_VSEG < cycle )
-printk("\n[DBG] %s : thread %x enter / process %x / base %x / size %x / %s / cxy %x / cycle %d\n",
-__FUNCTION__, CURRENT_THREAD, process->pid, base, size, vseg_type_str(type), cxy, cycle );
+printk("\n[%s] thread[%x,%x] enter / %s / cxy %x / cycle %d\n",
+__FUNCTION__, this->process->pid, this->trdid, vseg_type_str(type), cxy, cycle );
 #endif
 
@@ -972,4 +977,5 @@
     // compute base, size, vpn_base, vpn_size, depending on vseg type
     // we use the VMM specific allocators for "stack", "file", "anon", & "remote" vsegs
+
     if( type == VSEG_TYPE_STACK )
     {
@@ -987,10 +993,19 @@
         size = vpn_size << CONFIG_PPM_PAGE_SHIFT;
     }
-    else if( (type == VSEG_TYPE_ANON) ||
-             (type == VSEG_TYPE_FILE) ||
-             (type == VSEG_TYPE_REMOTE) )
-    {
+    else if( type == VSEG_TYPE_FILE )
+    {
+        // compute page index (in mapper) for first byte
+        vpn_t    vpn_min    = file_offset >> CONFIG_PPM_PAGE_SHIFT;
+
+        // compute page index (in mapper) for last byte
+        vpn_t    vpn_max    = (file_offset + size - 1) >> CONFIG_PPM_PAGE_SHIFT;
+
+        // compute offset in first page
+        uint32_t offset = file_offset & CONFIG_PPM_PAGE_MASK;
+
+        // compute number of pages required in virtual space
+        vpn_t    npages      = vpn_max - vpn_min + 1;
+
         // get vpn_base and vpn_size from MMAP allocator
-        vpn_t npages = size >> CONFIG_PPM_PAGE_SHIFT;
         error = vmm_mmap_alloc( vmm , npages , &vpn_base , &vpn_size );
         if( error )
@@ -1001,9 +1016,27 @@
         }
 
-        // compute vseg base and size from vpn_base and vpn_size
+        // set the vseg base (not always aligned for FILE)
+        base = (vpn_base << CONFIG_PPM_PAGE_SHIFT) + offset; 
+    }
+    else if( (type == VSEG_TYPE_ANON) ||
+             (type == VSEG_TYPE_REMOTE) )
+    {
+        // compute number of required pages in virtual space
+        vpn_t npages = size >> CONFIG_PPM_PAGE_SHIFT;
+        if( size & CONFIG_PPM_PAGE_MASK) npages++;
+        
+        // get vpn_base and vpn_size from MMAP allocator
+        error = vmm_mmap_alloc( vmm , npages , &vpn_base , &vpn_size );
+        if( error )
+        {
+            printk("\n[ERROR] in %s : no vspace for mmap vseg / process %x in cluster %x\n",
+                   __FUNCTION__ , process->pid , local_cxy );
+            return NULL;
+        }
+
+        // set vseg base (always aligned for ANON or REMOTE)
         base = vpn_base << CONFIG_PPM_PAGE_SHIFT;
-        size = vpn_size << CONFIG_PPM_PAGE_SHIFT;
-    }
-    else
+    }
+    else    // VSEG_TYPE_DATA or VSEG_TYPE_CODE
     {
         uint32_t vpn_min = base >> CONFIG_PPM_PAGE_SHIFT;
@@ -1051,6 +1084,6 @@
 cycle = (uint32_t)hal_get_cycles();
 if( DEBUG_VMM_CREATE_VSEG < cycle )
-printk("\n[DBG] %s : thread %x exit / process %x / %s / cxy %x / cycle %d\n",
-__FUNCTION__, CURRENT_THREAD, process->pid, vseg_type_str(type), cxy, cycle );
+printk("\n[%s] thread[%x,%x] exit / %s / cxy %x / cycle %d\n",
+__FUNCTION__, this->process->pid, this->trdid, vseg_type_str(type), cxy, cycle );
 #endif
 
@@ -1125,8 +1158,10 @@
 
 #if DEBUG_VMM_UNMAP_VSEG
-uint32_t cycle = (uint32_t)hal_get_cycles();
+uint32_t   cycle = (uint32_t)hal_get_cycles();
+thread_t * this  = CURRENT_THREAD;
 if( DEBUG_VMM_UNMAP_VSEG < cycle )
-printk("\n[DBG] %s : thread %x enter / process %x / vseg %s / base %x / cycle %d\n",
-__FUNCTION__, CURRENT_THREAD, process->pid, vseg_type_str( vseg->type ), vseg->vpn_base, cycle );
+printk("\n[%s] thread[%x,%x] enter / process %x / vseg %s / base %x / cycle %d\n",
+__FUNCTION__, this->process->pid, this->trdid, process->pid,
+vseg_type_str( vseg->type ), vseg->vpn_base, cycle );
 #endif
 
@@ -1198,6 +1233,7 @@
 cycle = (uint32_t)hal_get_cycles();
 if( DEBUG_VMM_UNMAP_VSEG < cycle )
-printk("\n[DBG] %s : thread %x exit / process %x / vseg %s / base %x / cycle %d\n",
-__FUNCTION__, CURRENT_THREAD, process->pid, vseg_type_str( vseg->type ), vseg->vpn_base, cycle );
+printk("\n[%s] thread[%x,%x] exit / process %x / vseg %s / base %x / cycle %d\n",
+__FUNCTION__, this->process->pid, this->trdid, process->pid, 
+vseg_type_str( vseg->type ), vseg->vpn_base, cycle );
 #endif
 
@@ -1213,6 +1249,6 @@
 // @ return vseg pointer if success / return NULL if not found.
 //////////////////////////////////////////////////////////////////////////////////////////
-static vseg_t * vseg_from_vaddr( vmm_t    * vmm,
-                                 intptr_t   vaddr )
+static vseg_t * vmm_vseg_from_vaddr( vmm_t    * vmm,
+                                     intptr_t   vaddr )
 {
     xptr_t   iter_xp;
@@ -1232,6 +1268,7 @@
         vseg_xp = XLIST_ELEMENT( iter_xp , vseg_t , xlist );
         vseg    = GET_PTR( vseg_xp );
+
         if( (vaddr >= vseg->min) && (vaddr < vseg->max) )
-        {
+        { 
             // return success
             remote_rwlock_rd_release( lock_xp );
@@ -1244,5 +1281,5 @@
     return NULL;
 
-}  // end vseg_from_vaddr()
+}  // end vmm_vseg_from_vaddr()
 
 /////////////////////////////////////////////
@@ -1263,5 +1300,5 @@
 
     // get pointer on vseg
-	vseg_t * vseg = vseg_from_vaddr( vmm , base );
+	vseg_t * vseg = vmm_vseg_from_vaddr( vmm , base );
 
 	if( vseg == NULL)  return EINVAL;
@@ -1343,8 +1380,8 @@
                        vseg_t   ** found_vseg )
 {
-    xptr_t   vseg_xp;
-    error_t  error;
-    vseg_t * vseg;
-    vmm_t  * vmm;
+    xptr_t    vseg_xp;
+    vseg_t  * vseg;
+    vmm_t   * vmm;
+    error_t   error;
 
     // get pointer on local VMM
@@ -1352,5 +1389,5 @@
 
     // try to get vseg from local VMM
-    vseg = vseg_from_vaddr( vmm , vaddr );
+    vseg = vmm_vseg_from_vaddr( vmm , vaddr );
 
     if( vseg == NULL )   // vseg not found in local cluster => try to get it from ref
@@ -1379,7 +1416,7 @@
 
         // register local vseg in local VMM
-        vmm_vseg_attach( &process->vmm , vseg );
+        vmm_vseg_attach( vmm , vseg );
     }   
-    
+
     // success
     *found_vseg = vseg;
@@ -1400,7 +1437,9 @@
 
 #if DEBUG_VMM_ALLOCATE_PAGE
+uint32_t   cycle = (uint32_t)hal_get_cycles();
+thread_t * this  = CURRENT_THREAD;
 if( DEBUG_VMM_ALLOCATE_PAGE < (uint32_t)hal_get_cycles() )
-printk("\n[DBG] in %s : thread %x enter for vpn %x\n",
-__FUNCTION__ , CURRENT_THREAD, vpn );
+printk("\n[%s] thread[%x,%x] enter for vpn %x / cycle %d\n",
+__FUNCTION__ , this->process->pid, this->trdid, vpn, cycle );
 #endif
 
@@ -1449,7 +1488,9 @@
 
 #if DEBUG_VMM_ALLOCATE_PAGE
+cycle = (uint32_t)hal_get_cycles();
 if( DEBUG_VMM_ALLOCATE_PAGE < (uint32_t)hal_get_cycles() )
-printk("\n[DBG] in %s : thread %x exit for vpn = %d / ppn = %x\n",
-__FUNCTION__ , CURRENT_THREAD, vpn, ppm_page2ppn( XPTR( page_cxy , page_ptr ) ) );
+printk("\n[%s] thread[%x,%x] exit for vpn %x / ppn %x / cycle %d\n",
+__FUNCTION__ , this->process->pid, this->trdid, vpn,
+ppm_page2ppn( XPTR( page_cxy , page_ptr ) , cycle );
 #endif
 
@@ -1474,8 +1515,9 @@
 
 #if DEBUG_VMM_GET_ONE_PPN 
-thread_t * this = CURRENT_THREAD;
-if( DEBUG_VMM_GET_ONE_PPN < (uint32_t)hal_get_cycles() )
-printk("\n[DBG] %s : thread %x enter for vpn = %x / type = %s / index = %d\n",
-__FUNCTION__, this, vpn, vseg_type_str(type), index );
+uint32_t   cycle = (uint32_t)hal_get_cycles();
+thread_t * this  = CURRENT_THREAD;
+if( DEBUG_VMM_GET_ONE_PPN < cycle )
+printk("\n[%s] thread[%x,%x] enter for vpn %x / type %s / index  %d / cycle %d\n",
+__FUNCTION__, this->process->pid, this->trdid, vpn, vseg_type_str(type), index, cycle );
 #endif
 
@@ -1539,6 +1581,6 @@
 #if (DEBUG_VMM_GET_ONE_PPN & 0x1)
 if( DEBUG_VMM_GET_ONE_PPN < (uint32_t)hal_get_cycles() )
-printk("\n[DBG] %s : thread %x for vpn = %x / elf_offset = %x\n",
-__FUNCTION__, this, vpn, elf_offset );
+printk("\n[%s] thread[%x,%x] for vpn = %x / elf_offset = %x\n",
+__FUNCTION__, this->process->pid, this->trdid, vpn, elf_offset );
 #endif
             // compute extended pointer on page base 
@@ -1553,6 +1595,6 @@
 #if (DEBUG_VMM_GET_ONE_PPN & 0x1)
 if( DEBUG_VMM_GET_ONE_PPN < (uint32_t)hal_get_cycles() )
-printk("\n[DBG] %s : thread%x for vpn = %x / fully in BSS\n",
-__FUNCTION__, this, vpn );
+printk("\n[%s] thread[%x,%x] for vpn  %x / fully in BSS\n",
+__FUNCTION__, this->process->pid, this->trdid, vpn );
 #endif
                 if( GET_CXY( page_xp ) == local_cxy )
@@ -1570,6 +1612,6 @@
 #if (DEBUG_VMM_GET_ONE_PPN & 0x1)
 if( DEBUG_VMM_GET_ONE_PPN < (uint32_t)hal_get_cycles() )
-printk("\n[DBG] %s : thread %x, for vpn = %x / fully in mapper\n",
-__FUNCTION__, this, vpn );
+printk("\n[%s] thread[%x,%x] for vpn  %x / fully in mapper\n",
+__FUNCTION__, this->process->pid, this->trdid, vpn );
 #endif
                 if( mapper_cxy == local_cxy ) 
@@ -1601,7 +1643,7 @@
 #if (DEBUG_VMM_GET_ONE_PPN & 0x1)
 if( DEBUG_VMM_GET_ONE_PPN < (uint32_t)hal_get_cycles() )
-printk("\n[DBG] %s : thread %x for vpn = %x / both mapper & BSS\n"
+printk("\n[%s] thread[%x,%x] for vpn  %x / both mapper & BSS\n",
 "      %d bytes from mapper / %d bytes from BSS\n",
-__FUNCTION__, this, vpn,
+__FUNCTION__, this->process->pid, this->trdid, vpn,
 file_size - offset , offset + CONFIG_PPM_PAGE_SIZE - file_size  );
 #endif
@@ -1647,7 +1689,8 @@
 
 #if DEBUG_VMM_GET_ONE_PPN
-if( DEBUG_VMM_GET_ONE_PPN < (uint32_t)hal_get_cycles() )
-printk("\n[DBG] %s : thread %x exit for vpn = %x / ppn = %x\n",
-__FUNCTION__ , this , vpn , *ppn );
+cycle = (uint32_t)hal_get_cycles();
+if( DEBUG_VMM_GET_ONE_PPN < cycle )
+printk("\n[%s] thread[%x,%x] exit for vpn %x / ppn %x / cycle\n",
+__FUNCTION__ , this->process->pid, this->trdid , vpn , *ppn, cycle );
 #endif
 
@@ -1680,5 +1723,5 @@
     if( error )
     {
-        printk("\n[ERROR] in %s : illegal VPN %x in process %x\n",
+        printk("\n[ERROR] in %s : vpn %x in process %x not in a registered vseg\n",
         __FUNCTION__ , vpn , process->pid );
         
@@ -1690,5 +1733,5 @@
 thread_t * this  = CURRENT_THREAD;
 if( DEBUG_VMM_HANDLE_PAGE_FAULT < cycle )
-printk("\n[DBG] %s : threadr[%x,%x] enter for vpn %x / %s / cycle %d\n",
+printk("\n[%s] threadr[%x,%x] enter for vpn %x / %s / cycle %d\n",
 __FUNCTION__, this->process->pid, this->trdid, vpn, vseg_type_str(vseg->type), cycle );
 #endif
@@ -1705,4 +1748,5 @@
 
         // check VPN still unmapped in local GPT
+
         // do nothing if VPN has been mapped by a a concurrent page_fault
         hal_gpt_get_pte( local_gpt_xp,
@@ -1757,5 +1801,5 @@
 cycle = (uint32_t)hal_get_cycles();
 if( DEBUG_VMM_HANDLE_PAGE_FAULT < cycle )
-printk("\n[DBG] %s : private page fault handled / vpn %x / ppn %x / attr %x / cycle %d\n",
+printk("\n[%s] private page fault handled / vpn %x / ppn %x / attr %x / cycle %d\n",
 __FUNCTION__, vpn, new_ppn, new_attr, cycle );
 #endif
@@ -1812,5 +1856,5 @@
                 if( error )
                 {
-                    printk("\n[ERROR] in %s : cannot update local GPT / process %x / vpn = %x\n",
+                    printk("\n[ERROR] in %s : cannot update local GPT / process %x / vpn %x\n",
                     __FUNCTION__ , process->pid , vpn );
 
@@ -1834,5 +1878,5 @@
 cycle = (uint32_t)hal_get_cycles();
 if( DEBUG_VMM_HANDLE_PAGE_FAULT < cycle )
-printk("\n[DBG] %s : false page fault handled / vpn %x / ppn %x / attr %x / cycle %d\n",
+printk("\n[%s] false page fault handled / vpn %x / ppn %x / attr %x / cycle %d\n",
 __FUNCTION__, vpn, ref_ppn, ref_attr, cycle );
 #endif
@@ -1904,5 +1948,5 @@
 cycle = (uint32_t)hal_get_cycles();
 if( DEBUG_VMM_HANDLE_PAGE_FAULT < cycle )
-printk("\n[DBG] %s : true page fault handled / vpn %x / ppn %x / attr %x / cycle %d\n",
+printk("\n[%s] true page fault handled / vpn %x / ppn %x / attr %x / cycle %d\n",
 __FUNCTION__, vpn, new_ppn, new_attr, cycle );
 #endif
@@ -1931,5 +1975,5 @@
 thread_t * this  = CURRENT_THREAD;
 if( DEBUG_VMM_HANDLE_COW < cycle )
-printk("\n[DBG] %s : thread[%x,%x] enter for vpn %x / core[%x,%d] / cycle %d\n",
+printk("\n[%s] thread[%x,%x] enter for vpn %x / core[%x,%d] / cycle %d\n",
 __FUNCTION__, process->pid, this->trdid, vpn, local_cxy, this->core->lid, cycle );
 #endif
@@ -1942,5 +1986,5 @@
     if( error )
     {
-        printk("\n[PANIC] in %s : VPN %x in process %x not in registered vseg\n",
+        printk("\n[PANIC] in %s : vpn %x in process %x not in a registered vseg\n",
         __FUNCTION__, vpn, process->pid );
 
@@ -2035,5 +2079,5 @@
 #if(DEBUG_VMM_HANDLE_COW & 1)
 if( DEBUG_VMM_HANDLE_COW < cycle )
-printk("\n[DBG] %s : thread[%x,%x] : pending forks => allocate a new PPN %x\n",
+printk("\n[%s] thread[%x,%x] : pending forks => allocate a new PPN %x\n",
 __FUNCTION__, process->pid, this->trdid, new_ppn );
 #endif
@@ -2045,5 +2089,5 @@
 #if(DEBUG_VMM_HANDLE_COW & 1)
 if( DEBUG_VMM_HANDLE_COW < cycle )
-printk("\n[DBG] %s : thread[%x,%x]  no pending forks => keep existing PPN %x\n",
+printk("\n[%s] thread[%x,%x]  no pending forks => keep existing PPN %x\n",
 __FUNCTION__, process->pid, this->trdid, new_ppn );
 #endif
@@ -2092,5 +2136,5 @@
 cycle = (uint32_t)hal_get_cycles();
 if( DEBUG_VMM_HANDLE_COW < cycle )
-printk("\n[DBG] %s : thread[%x,%x] exit for vpn %x / core[%x,%d] / cycle %d\n",
+printk("\n[%s] thread[%x,%x] exit for vpn %x / core[%x,%d] / cycle %d\n",
 __FUNCTION__, process->pid, this->trdid, vpn, local_cxy, this->core->lid, cycle );
 #endif
