Index: trunk/kernel/mm/kcm.c
===================================================================
--- trunk/kernel/mm/kcm.c	(revision 656)
+++ trunk/kernel/mm/kcm.c	(revision 657)
@@ -43,10 +43,10 @@
 //////////////////////////////////////////////////////////////////////////////////////
 // This static function must be called by a local thread.
-// It returns a pointer on a block allocated from a non-full kcm_page.
-// It makes a panic if no block is available in selected page.
+// It returns a pointer on a block allocated from an active kcm_page.
+// It makes a panic if no block is available in the selected page.
 // It changes the page status as required.
 //////////////////////////////////////////////////////////////////////////////////////
 // @ kcm      : pointer on KCM allocator.
-// @ kcm_page : pointer on a non-full kcm_page.
+// @ kcm_page : pointer on an active kcm_page.
 // @ return pointer on allocated block.
 /////////////////////////////////////////////////////////////////////////////////////
@@ -64,5 +64,4 @@
     uint32_t index  = 1;
     uint64_t mask   = (uint64_t)0x2;
-    uint32_t found  = 0;
 
 	// allocate first free block in kcm_page, update status,
@@ -70,10 +69,9 @@
     while( index <= max )
     {
-        if( (status & mask) == 0 )   // block non allocated
+        if( (status & mask) == 0 )   // block found
         {
+            // update page count and status
             kcm_page->status = status | mask;
             kcm_page->count  = count + 1;
-            found  = 1;
-
             break;      
         }
@@ -83,5 +81,5 @@
     }
 
-    // change the page list if almost full
+    // change the page list if found block is the last
     if( count == max-1 )
     {
@@ -162,9 +160,9 @@
 
 /////////////////////////////////////////////////////////////////////////////////////
-// This private static function must be called by a local thread.
-// It returns one non-full kcm_page with te following policy :
+// This static function must be called by a local thread.
+// It returns one non-full kcm_page with the following policy :
 // - if the "active_list" is non empty, it returns the first "active" page,
 //   without modifying the KCM state.
-// - if the "active_list" is empty, it allocates a new page fromm PPM, inserts
+// - if the "active_list" is empty, it allocates a new page from PPM, inserts
 //   this page in the active_list, and returns it. 
 /////////////////////////////////////////////////////////////////////////////////////
@@ -275,5 +273,6 @@
 	// release KCM lock
 	remote_busylock_release( lock_xp );
-}
+
+}  // end kcm_destroy()
 
 //////////////////////////////////
@@ -284,5 +283,5 @@
 	void       * block_ptr;
 
-    // min block size is 64 bytes
+   // min block size is 64 bytes
     if( order < 6 ) order = 6;
 
@@ -301,4 +300,16 @@
     kcm_page = kcm_get_page( kcm_ptr );
 
+#if DEBUG_KCM
+thread_t * this  = CURRENT_THREAD;
+uint32_t   cycle = (uint32_t)hal_get_cycles();
+if( (DEBUG_KCM < cycle) && (local_cxy == 1) )
+{
+printk("\n[%s] thread[%x,%x] enters / order %d / page %x / kcm %x / page_status (%x|%x)\n",
+__FUNCTION__, this->process->pid, this->trdid, order, kcm_page, kcm_ptr,
+GET_CXY( kcm_page->status ), GET_PTR( kcm_page->status ) );
+kcm_remote_display( local_cxy , kcm_ptr );
+}
+#endif
+
     if( kcm_page == NULL )
 	{
@@ -314,10 +325,11 @@
 
 #if DEBUG_KCM
-thread_t * this  = CURRENT_THREAD;
-uint32_t   cycle = (uint32_t)hal_get_cycles();
-if( DEBUG_KCM < cycle )
-printk("\n[%s] thread[%x,%x] allocated block %x / order %d / kcm %x / status[%x,%x] / count %d\n",
-__FUNCTION__, this->process->pid, this->trdid, block_ptr, order, kcm_ptr,
-GET_CXY(kcm_page->status), GET_PTR(kcm_page->status), kcm_page->count );
+if( (DEBUG_KCM < cycle) && (local_cxy == 1) )
+{
+printk("\n[%s] thread[%x,%x] exit / order %d / block %x / kcm %x / page_status (%x|%x)\n",
+__FUNCTION__, this->process->pid, this->trdid, order, block_ptr, kcm_ptr,
+GET_CXY( kcm_page->status ), GET_PTR( kcm_page->status ) );
+kcm_remote_display( local_cxy , kcm_ptr );
+}
 #endif
 
@@ -344,8 +356,11 @@
 thread_t * this  = CURRENT_THREAD;
 uint32_t   cycle = (uint32_t)hal_get_cycles();
-if( DEBUG_KCM < cycle )
-printk("\n[%s] thread[%x,%x] release block %x / order %d / kcm %x / status [%x,%x] / count %d\n",
-__FUNCTION__, this->process->pid, this->trdid, block_ptr, kcm_ptr->order, kcm_ptr,
-GET_CXY(kcm_page->status), GET_PTR(kcm_page->status), kcm_page->count );
+if( (DEBUG_KCM < cycle) && (local_cxy == 1) )
+{
+printk("\n[%s] thread[%x,%x] enters / order %d / block %x / page %x / kcm %x / status [%x,%x]\n",
+__FUNCTION__, this->process->pid, this->trdid, kcm_ptr->order, block_ptr, kcm_page, kcm_ptr,
+GET_CXY(kcm_page->status), GET_PTR(kcm_page->status) );
+kcm_remote_display( local_cxy , kcm_ptr );
+}
 #endif
 
@@ -361,5 +376,16 @@
 	// release lock
 	remote_busylock_release( lock_xp );
+
+#if DEBUG_KCM
+if( (DEBUG_KCM < cycle) && (local_cxy == 1) )
+{
+printk("\n[%s] thread[%x,%x] exit / order %d / page %x / status [%x,%x]\n",
+__FUNCTION__, this->process->pid, this->trdid, kcm_ptr->order, kcm_ptr,
+GET_CXY(kcm_page->status), GET_PTR(kcm_page->status) );
+kcm_remote_display( local_cxy , kcm_ptr );
 }
+#endif
+
+}  // end kcm_free() 
 
 /////////////////////////////////////////////////////////////////////////////////////
@@ -369,11 +395,11 @@
 /////////////////////////////////////////////////////////////////////////////////////
 // This static function can be called by any thread running in any cluster.
-// It returns a local pointer on a block allocated from an non-full kcm_page.
-// It makes a panic if no block available in selected page.
+// It returns a local pointer on a block allocated from an active kcm_page.
+// It makes a panic if no block available in the selected kcm_page.
 // It changes the page status as required.
 /////////////////////////////////////////////////////////////////////////////////////
-// @ kcm_cxy  : remote KCM cluster identidfier.
+// @ kcm_cxy  : remote KCM cluster identifier.
 // @ kcm_ptr  : local pointer on remote KCM allocator.
-// @ kcm_page : pointer on active kcm page to use.
+// @ kcm_page : local pointer on remote active kcm_page to use.
 // @ return a local pointer on the allocated block. 
 /////////////////////////////////////////////////////////////////////////////////////
@@ -392,5 +418,4 @@
     uint32_t index  = 1;
     uint64_t mask   = (uint64_t)0x2;
-    uint32_t found  = 0;
     
 	// allocate first free block in kcm_page, update status,
@@ -398,9 +423,8 @@
     while( index <= max )
     {
-        if( (status & mask) == 0 )   // block non allocated
+        if( (status & mask) == 0 )   // block found
         {
             hal_remote_s64( XPTR( kcm_cxy , &kcm_page->status ) , status | mask );
-            hal_remote_s64( XPTR( kcm_cxy , &kcm_page->count  ) , count + 1 );
-            found  = 1; 
+            hal_remote_s32( XPTR( kcm_cxy , &kcm_page->count  ) , count + 1 );
             break;      
         }
@@ -410,5 +434,5 @@
     }
 
-	// change the page list if almost full
+	// change the page list if found block is the last
 	if( count == max-1 )
 	{
@@ -631,9 +655,40 @@
                          kcm_t * kcm_ptr )
 {
+    list_entry_t * iter;
+    kcm_page_t   * kcm_page;
+    uint64_t       status;
+    uint32_t       count;
+
     uint32_t order           = hal_remote_l32( XPTR( kcm_cxy , &kcm_ptr->order) );
     uint32_t full_pages_nr   = hal_remote_l32( XPTR( kcm_cxy , &kcm_ptr->full_pages_nr ) );
     uint32_t active_pages_nr = hal_remote_l32( XPTR( kcm_cxy , &kcm_ptr->active_pages_nr ) );
 
-	printk("*** KCM / cxy %x / order %d / full_pages %d / empty_pages %d / active_pages %d\n",
+	printk("*** KCM : cxy %x / order %d / full_pages_nr %d / active_pages_nr %d\n",
 	kcm_cxy, order, full_pages_nr, active_pages_nr );
-}
+
+    if( active_pages_nr )
+    {
+        LIST_REMOTE_FOREACH( kcm_cxy , &kcm_ptr->active_root , iter )
+        {
+            kcm_page = LIST_ELEMENT( iter , kcm_page_t , list );
+            status   = hal_remote_l64( XPTR( kcm_cxy , &kcm_page->status ) );
+            count    = hal_remote_l32( XPTR( kcm_cxy , &kcm_page->count ) );
+
+            printk("- active page %x / status (%x,%x) / count %d\n",
+            kcm_page, GET_CXY( status ), GET_PTR( status ), count );
+        }
+    }
+
+    if( full_pages_nr )
+    {
+        LIST_REMOTE_FOREACH( kcm_cxy , &kcm_ptr->full_root , iter )
+        {
+            kcm_page = LIST_ELEMENT( iter , kcm_page_t , list );
+            status   = hal_remote_l64( XPTR( kcm_cxy , &kcm_page->status ) );
+            count    = hal_remote_l32( XPTR( kcm_cxy , &kcm_page->count ) );
+
+            printk("- full page %x / status (%x,%x) / count %d\n",
+            kcm_page, GET_CXY( status ), GET_PTR( status ), count );
+        }
+    }
+}  // end kcm remote_display()
