Index: trunk/kernel/kern/thread.c
===================================================================
--- trunk/kernel/kern/thread.c	(revision 443)
+++ trunk/kernel/kern/thread.c	(revision 446)
@@ -42,4 +42,5 @@
 #include <ppm.h>
 #include <thread.h>
+#include <rpc.h>
 
 //////////////////////////////////////////////////////////////////////////////////////
@@ -799,11 +800,22 @@
 uint32_t cycle = (uint32_t)hal_get_cycles();
 if( DEBUG_THREAD_BLOCK < cycle )
-printk("\n[DBG] %s : thread %x blocked thread %x / cause %x / cycle %d\n",
-__FUNCTION__ , CURRENT_THREAD , ptr , cause , cycle );
+printk("\n[@@@] %s : thread %x  in cxy %x blocked thread %x in cxy %x / cause %x / cycle %d\n",
+__FUNCTION__ , CURRENT_THREAD , local_cxy , ptr , cxy , cause , cycle );
 #endif
 
 #if (DEBUG_THREAD_BLOCK & 1)
 if( DEBUG_THREAD_BLOCK < cycle )
-sched_display( ptr->core->lid );
+{
+    if( cxy == local_cxy) 
+    {
+        sched_display( ptr->core->lid );
+    }
+    else
+    {
+        core_t * core = hal_remote_lpt( XPTR( cxy , &ptr->core ) );
+        lid_t    lid  = hal_remote_lw ( XPTR( cxy , &core->lid ) );
+        rpc_sched_display_client( cxy , lid );
+    }
+}
 #endif
 
@@ -825,11 +837,22 @@
 uint32_t cycle = (uint32_t)hal_get_cycles();
 if( DEBUG_THREAD_BLOCK < cycle )
-printk("\n[DBG] %s : thread %x unblocked thread %x / cause %x / cycle %d\n",
-__FUNCTION__ , CURRENT_THREAD , ptr , cause , cycle );
+printk("\n[@@@] %s : thread %x  in cxy %x unblocked thread %x in cxy %x / cause %x / cycle %d\n",
+__FUNCTION__ , CURRENT_THREAD , local_cxy , ptr , cxy , cause , cycle );
 #endif
 
 #if (DEBUG_THREAD_BLOCK & 1)
 if( DEBUG_THREAD_BLOCK < cycle )
-sched_display( ptr->core->lid );
+{
+    if( cxy == local_cxy) 
+    {
+        sched_display( ptr->core->lid );
+    }
+    else
+    {
+        core_t * core = hal_remote_lpt( XPTR( cxy , &ptr->core ) );
+        lid_t    lid  = hal_remote_lw ( XPTR( cxy , &core->lid ) );
+        rpc_sched_display_client( cxy , lid );
+    }
+}
 #endif
 
@@ -838,167 +861,4 @@
 
 }  // end thread_unblock()
-
-/*
-
-////////////////////////////////////
-void thread_kill( xptr_t  target_xp,
-                  bool_t  is_exit,
-                  bool_t  is_forced )
-{
-    reg_t       save_sr;                // for critical section
-    bool_t      attached;               // target thread in attached mode
-    bool_t      join_done;              // joining thread arrived first
-    xptr_t      killer_xp;              // extended pointer on killer thread (this)
-    thread_t  * killer_ptr;             // pointer on killer thread (this)
-    cxy_t       target_cxy;             // target thread cluster     
-    thread_t  * target_ptr;             // pointer on target thread
-    xptr_t      joining_xp;             // extended pointer on joining thread
-    thread_t  * joining_ptr;            // pointer on joining thread
-    cxy_t       joining_cxy;            // joining thread cluster
-    pid_t       target_pid;             // target process PID
-    cxy_t       owner_cxy;              // target process owner cluster
-    trdid_t     target_trdid;           // target thread identifier
-    ltid_t      target_ltid;            // target thread local index
-    xptr_t      process_state_xp;       // extended pointer on <term_state> in process
-
-    xptr_t      target_flags_xp;        // extended pointer on target thread <flags>
-    xptr_t      target_join_lock_xp;    // extended pointer on target thread <join_lock>
-    xptr_t      target_join_xp_xp;      // extended pointer on target thread <join_xp>
-    xptr_t      target_process_xp;      // extended pointer on target thread <process>
-
-    process_t * target_process;         // pointer on target thread process
-
-    // get target thread pointer and cluster
-    target_cxy = GET_CXY( target_xp );
-    target_ptr = GET_PTR( target_xp );
-
-    // get killer thread pointers
-    killer_ptr = CURRENT_THREAD;
-    killer_xp  = XPTR( local_cxy , killer_ptr );
-
-#if DEBUG_THREAD_DELETE
-uint32_t cycle  = (uint32_t)hal_get_cycles;
-if( DEBUG_THREAD_DELETE < cycle )
-printk("\n[DBG] %s : thread %x enter for target thread %x / cycle %d\n",
-__FUNCTION__, killer_ptr, target_ptr, cycle );
-#endif
-
-    // block the target thread 
-    thread_block( target_xp , THREAD_BLOCKED_GLOBAL );
-
-    // get target thread attached mode
-    target_flags_xp = XPTR( target_cxy , &target_ptr->flags );
-    attached = ((hal_remote_lw( target_flags_xp ) & THREAD_FLAG_DETACHED) == 0);
-
-    // synchronize with the joining thread 
-    // if the target thread is attached && not forced
-
-    if( attached  && (is_forced == false) )
-    {
-        // build extended pointers on target thread join fields
-        target_join_lock_xp  = XPTR( target_cxy , &target_ptr->join_lock );
-        target_join_xp_xp    = XPTR( target_cxy , &target_ptr->join_xp );
-
-        // enter critical section
-        hal_disable_irq( &save_sr );
-
-        // take the join_lock in target thread descriptor
-        remote_spinlock_lock( target_join_lock_xp );
-
-        // get join_done from target thread descriptor
-        join_done = ((hal_remote_lw( target_flags_xp ) & THREAD_FLAG_JOIN_DONE) != 0);
-    
-        if( join_done )     // joining thread arrived first
-        {
-            // get extended pointer on joining thread
-            joining_xp  = (xptr_t)hal_remote_lwd( target_join_xp_xp );
-            joining_ptr = GET_PTR( joining_xp );
-            joining_cxy = GET_CXY( joining_xp );
-            
-            // reset the join_done flag in target thread
-            hal_remote_atomic_and( target_flags_xp , ~THREAD_FLAG_JOIN_DONE );
-
-            // unblock the joining thread
-            thread_unblock( joining_xp , THREAD_BLOCKED_JOIN );
-
-            // release the join_lock in target thread descriptor
-            remote_spinlock_unlock( target_join_lock_xp );
-
-            // restore IRQs
-            hal_restore_irq( save_sr );
-        }
-        else                // this thread arrived first
-        {
-            // set the kill_done flag in target thread
-            hal_remote_atomic_or( target_flags_xp , THREAD_FLAG_KILL_DONE );
-
-            // block this thread on BLOCKED_JOIN
-            thread_block( killer_xp , THREAD_BLOCKED_JOIN );
-
-            // set extended pointer on killer thread in target thread
-            hal_remote_swd( target_join_xp_xp , killer_xp );
-
-            // release the join_lock in target thread descriptor
-            remote_spinlock_unlock( target_join_lock_xp );
-
-            // deschedule
-            sched_yield( "killer thread wait joining thread" );
-
-            // restore IRQs
-            hal_restore_irq( save_sr );
-        }
-    }  // end if attached
-
-    // - if the target thread is the main thread
-    //   => synchronize with the parent process main thread
-    // - if the target thread is not the main thread
-    //   => simply mark the target thread for delete
-
-    // get pointer on target thread process
-    target_process_xp  = XPTR( target_cxy , &target_ptr->process );
-    target_process     = (process_t *)hal_remote_lpt( target_process_xp ); 
-
-	// get target process owner cluster
-	target_pid = hal_remote_lw( XPTR( target_cxy , &target_process->pid ) );
-    owner_cxy = CXY_FROM_PID( target_pid );
-
-    // get target thread local index
-    target_trdid = hal_remote_lw( XPTR( target_cxy , &target_ptr->trdid ) );
-    target_ltid  = LTID_FROM_TRDID( target_trdid );
-
-    if( (owner_cxy == target_cxy) && (target_ltid == 0) )     // main thread
-    {
-        // get extended pointer on term_state in target process owner cluster
-        process_state_xp = XPTR( owner_cxy , &target_process->term_state );
-
-        // set termination info in target process owner  
-        if( is_exit ) hal_remote_atomic_or( process_state_xp , PROCESS_TERM_EXIT );
-        else          hal_remote_atomic_or( process_state_xp , PROCESS_TERM_KILL );
-
-#if DEBUG_THREAD_DELETE
-cycle  = (uint32_t)hal_get_cycles;
-if( DEBUG_THREAD_DELETE < cycle )
-printk("\n[DBG] %s : thread %x exit for thread %x / main thread / cycle %d\n",
-__FUNCTION__, killer_ptr, target_ptr, cycle );
-#endif
-
-    }
-    else                                                      // main thread
-    {
-        // set the REQ_DELETE flag in target thread descriptor
-        hal_remote_atomic_or( target_flags_xp , THREAD_FLAG_REQ_DELETE );
-
-#if DEBUG_THREAD_DELETE
-cycle  = (uint32_t)hal_get_cycles;
-if( DEBUG_THREAD_DELETE < cycle )
-printk("\n[DBG] %s : thread %x exit for thread %x / not the main thread / cycle %d\n",
-__FUNCTION__, killer_ptr, target_ptr, cycle );
-#endif
-
-    }
-
-}  // end thread_kill()
-
-*/
 
 //////////////////////////////////////
@@ -1131,4 +991,9 @@
 void thread_idle_func()
 {
+
+#if DEBUG_THREAD_IDLE
+uint32_t cycle;
+#endif
+
     while( 1 )
     {
@@ -1140,22 +1005,25 @@
         {
 
-#if DEBUG_THREAD_IDLE
-uint32_t cycle  = (uint32_t)hal_get_cycles;
-thread_t * this = CURRENT_THREAD;
-if( DEBUG_THREAD_IDLE < cycle )
-printk("\n[DBG] %s : idle thread %x on core[%x,%d] goes to sleep / cycle %d\n",
-__FUNCTION__, this, local_cxy, this->core->lid, cycle );
-#endif
-
-            hal_core_sleep();
-
-#if DEBUG_THREAD_IDLE
+#if (DEBUG_THREAD_IDLE & 1)
 cycle  = (uint32_t)hal_get_cycles;
 if( DEBUG_THREAD_IDLE < cycle )
-printk("\n[DBG] %s : idle thread %x on core[%x,%d] wake up / cycle %d\n",
+printk("\n[DBG] %s : idle thread on core[%x,%d] goes to sleep / cycle %d\n",
+__FUNCTION__, local_cxy, CURRENT_THREAD->core->lid, cycle );
+#endif
+
+            hal_core_sleep();
+
+#if (DEBUG_THREAD_IDLE & 1)
+cycle  = (uint32_t)hal_get_cycles;
+if( DEBUG_THREAD_IDLE < cycle )
+printk("\n[DBG] %s : idle thread on core[%x,%d] wake up / cycle %d\n",
 __FUNCTION__, this, local_cxy, this->core->lid, cycle );
 #endif
 
         }
+
+#if DEBUG_THREAD_IDLE
+sched_display( CURRENT_THREAD->core->lid );
+#endif     
 
         // search a runable thread
