Index: trunk/kernel/kern/rpc.c
===================================================================
--- trunk/kernel/kern/rpc.c	(revision 610)
+++ trunk/kernel/kern/rpc.c	(revision 611)
@@ -77,5 +77,5 @@
     &rpc_undefined,                        // 24   unused slot
     &rpc_mapper_handle_miss_server,        // 25
-    &rpc_undefined,                        // 26   unused slot
+    &rpc_vmm_delete_vseg_server,           // 26 
     &rpc_vmm_create_vseg_server,           // 27
     &rpc_vmm_set_cow_server,               // 28
@@ -113,5 +113,5 @@
     "undefined",                 // 24
     "MAPPER_HANDLE_MISS",        // 25
-    "undefined",                 // 26
+    "VMM_DELETE_VSEG",           // 26
     "VMM_CREATE_VSEG",           // 27
     "VMM_SET_COW",               // 28
@@ -283,4 +283,5 @@
     bool_t          blocking;           // blocking RPC when true
 	remote_fifo_t * rpc_fifo;           // local pointer on RPC fifo
+    uint32_t        count;              // current number of expected responses
  
     // makes RPC thread not preemptable
@@ -302,6 +303,6 @@
 uint32_t cycle = (uint32_t)hal_get_cycles();
 if( DEBUG_RPC_SERVER_GENERIC < cycle ) 
-printk("\n[%s] RPC thread %x on core[%d] takes RPC_FIFO ownership / cycle %d\n",
-__FUNCTION__, server_ptr->trdid, server_core_lid, cycle );
+printk("\n[%s] RPC thread[%x,%x] on core[%d] takes RPC_FIFO ownership / cycle %d\n",
+__FUNCTION__, server_ptr->process->pid, server_ptr->trdid, server_core_lid, cycle );
 #endif
 	        // try to consume one RPC request  
@@ -326,6 +327,6 @@
 uint32_t items = remote_fifo_items( XPTR( local_cxy , rpc_fifo ) );
 if( DEBUG_RPC_SERVER_GENERIC < cycle ) 
-printk("\n[%s] RPC thread %x got rpc %s / client_cxy %x / items %d / cycle %d\n",
-__FUNCTION__, server_ptr->trdid, rpc_str[index], desc_cxy, items, cycle );
+printk("\n[%s] RPC thread[%x,%x] got rpc %s / client_cxy %x / items %d / cycle %d\n",
+__FUNCTION__, server_ptr->process->pid, server_ptr->trdid, rpc_str[index], desc_cxy, items, cycle );
 #endif
                 // register client thread in RPC thread descriptor
@@ -338,13 +339,13 @@
 cycle = (uint32_t)hal_get_cycles();
 if( DEBUG_RPC_SERVER_GENERIC < cycle ) 
-printk("\n[%s] RPC thread %x completes rpc %s / client_cxy %x / cycle %d\n",
-__FUNCTION__, server_ptr->trdid, rpc_str[index], desc_cxy, cycle );
-#endif
-                // decrement response counter in RPC descriptor if blocking RPC
-                if( blocking )
+printk("\n[%s] RPC thread[%x,%x] completes rpc %s / client_cxy %x / cycle %d\n",
+__FUNCTION__, server_ptr->process->pid, server_ptr->trdid, rpc_str[index], desc_cxy, cycle );
+#endif
+                // decrement expected responses counter in RPC descriptor
+                count = hal_remote_atomic_add( XPTR( desc_cxy, &desc_ptr->responses ), -1 );
+
+                // decrement response counter in RPC descriptor if last response
+                if( count == 1 ) 
                 {
-                    // decrement responses counter in RPC descriptor
-                    hal_remote_atomic_add( XPTR( desc_cxy, &desc_ptr->responses ), -1 );
-
                     // get client thread pointer and client core lid from RPC descriptor
                     client_ptr      = hal_remote_lpt( XPTR( desc_cxy , &desc_ptr->thread ) );
@@ -359,11 +360,11 @@
 cycle = (uint32_t)hal_get_cycles();
 if( DEBUG_RPC_SERVER_GENERIC < cycle ) 
-printk("\n[%s] RPC thread %x unblocked client thread %x / cycle %d\n",
-__FUNCTION__, server_ptr->trdid, client_ptr->trdid, cycle );
+printk("\n[%s] RPC thread[%x,%x] unblocked client thread[%x,%x] / cycle %d\n",
+__FUNCTION__, server_ptr->process->pid, server_ptr->trdid,
+client_ptr->process->pid, client_ptr->trdid, cycle );
 #endif
                     // send IPI to client core
                     dev_pic_send_ipi( desc_cxy , client_core_lid );
-
-                }  // end if blocking RPC
+                }
             }  // end RPC handling if fifo non empty
         }  // end if RPC_fIFO ownership successfully taken and released
@@ -376,6 +377,6 @@
 uint32_t cycle = (uint32_t)hal_get_cycles();
 if( DEBUG_RPC_SERVER_GENERIC < cycle ) 
-printk("\n[%s] RPC thread %x suicides / cycle %d\n",
-__FUNCTION__, server_ptr->trdid, cycle );
+printk("\n[%s] RPC thread[%x,%x] suicides / cycle %d\n",
+__FUNCTION__, server_ptr->process->pid, server_ptr->trdid, cycle );
 #endif
             // update RPC threads counter
@@ -395,6 +396,6 @@
 uint32_t cycle = (uint32_t)hal_get_cycles();
 if( DEBUG_RPC_SERVER_GENERIC < cycle ) 
-printk("\n[%s] RPC thread %x block IDLE & deschedules / cycle %d\n",
-__FUNCTION__, server_ptr->trdid, cycle );
+printk("\n[%s] RPC thread[%x,%x] block IDLE & deschedules / cycle %d\n",
+__FUNCTION__, server_ptr->process->pid, server_ptr->trdid, cycle );
 #endif
             // RPC thread blocks on IDLE 
@@ -425,5 +426,5 @@
 #endif
 
-    assert( (cxy != local_cxy) , "target cluster is not remote\n");
+    assert( (cxy != local_cxy) , "server cluster is not remote\n");
 
     // initialise RPC descriptor header 
@@ -498,5 +499,5 @@
 #endif
 
-    assert( (cxy != local_cxy) , "target cluster is not remote\n");
+    assert( (cxy != local_cxy) , "server cluster is not remote\n");
 
     // initialise RPC descriptor header 
@@ -576,5 +577,5 @@
 #endif
 
-    assert( (cxy != local_cxy) , "target cluster is not remote\n");
+    assert( (cxy != local_cxy) , "server cluster is not remote\n");
 
     // initialise RPC descriptor header 
@@ -677,5 +678,5 @@
 #endif
 
-    assert( (cxy != local_cxy) , "target cluster is not remote\n");
+    assert( (cxy != local_cxy) , "server cluster is not remote\n");
 
     // initialise RPC descriptor header 
@@ -784,5 +785,5 @@
 #endif
 
-    assert( (cxy != local_cxy) , "target cluster is not remote\n");
+    assert( (cxy != local_cxy) , "server cluster is not remote\n");
 
     // initialise RPC descriptor header 
@@ -862,5 +863,5 @@
 
 /////////////////////////////////////////////////////////////////////////////////////////
-// [9] Marshaling functions attached to RPC_PROCESS_SIGACTION (multicast / non blocking)
+// [9]   Marshaling functions attached to RPC_PROCESS_SIGACTION (non blocking)
 /////////////////////////////////////////////////////////////////////////////////////////
 
@@ -869,18 +870,15 @@
                                    rpc_desc_t * rpc )
 {
-
 #if DEBUG_RPC_PROCESS_SIGACTION
-uint32_t  cycle  = (uint32_t)hal_get_cycles();
-uint32_t  action = rpc->args[0];
-pid_t     pid    = rpc->args[1];
+uint32_t  cycle = (uint32_t)hal_get_cycles();
 thread_t * this = CURRENT_THREAD;
 if( DEBUG_RPC_PROCESS_SIGACTION < cycle )
-printk("\n[%s] thread[%x,%x] enter to request %s of process %x in cluster %x / cycle %d\n",
-__FUNCTION__, this->process->pid, this->trdid, process_action_str(action), pid, cxy, cycle );
-#endif
-
-    // check some RPC arguments
-    assert( (rpc->blocking == false) , "must be non-blocking\n");
-    assert( (rpc->index == RPC_PROCESS_SIGACTION ) , "bad RPC index\n" );
+printk("\n[%s] thread[%x,%x] on core %d enter / cycle %d\n",
+__FUNCTION__, this->process->pid, this->trdid, this->core->lid, cycle );
+#endif
+
+// check RPC "index" and "blocking" arguments
+assert( (rpc->blocking == false) , "must be non-blocking\n");
+assert( (rpc->index == RPC_PROCESS_SIGACTION ) , "bad RPC index\n" );
 
     // register RPC request in remote RPC fifo and return
@@ -890,8 +888,7 @@
 cycle = (uint32_t)hal_get_cycles();
 if( DEBUG_RPC_PROCESS_SIGACTION < cycle )
-printk("\n[%s] thread[%x,%x] requested %s of process %x in cluster %x / cycle %d\n",
-__FUNCTION__, this->process->pid, this->trdid, process_action_str(action), pid, cxy, cycle );
-#endif
-
+printk("\n[%s] thread[%x,%x] on core %d exit / cycle %d\n",
+__FUNCTION__, this->process->pid, this->trdid, this->core->lid, cycle );
+#endif
 }  // end rpc_process_sigaction_client() 
 
@@ -899,38 +896,26 @@
 void rpc_process_sigaction_server( xptr_t xp )
 {
-    pid_t        pid;             // target process identifier
-    process_t  * process;         // pointer on local target process descriptor
-    uint32_t     action;          // sigaction index
-    thread_t   * client_ptr;      // pointer on client thread in client cluster
-    xptr_t       client_xp;       // extended pointer client thread
-    cxy_t        client_cxy;      // client cluster identifier
-    rpc_desc_t * rpc;             // pointer on rpc descriptor in client cluster
-    xptr_t       count_xp;        // extended pointer on responses counter
-    uint32_t     count_value;     // responses counter value
-    lid_t        client_lid;      // client core local index
+#if DEBUG_RPC_PROCESS_SIGACTION
+uint32_t cycle = (uint32_t)hal_get_cycles();
+thread_t * this = CURRENT_THREAD;
+if( DEBUG_RPC_PROCESS_SIGACTION < cycle )
+printk("\n[%s] thread[%x,%x] on core %d enter / cycle %d\n",
+__FUNCTION__, this->process->pid, this->trdid, this->core->lid, cycle );
+#endif
 
     // get client cluster identifier and pointer on RPC descriptor
-    client_cxy = GET_CXY( xp );
-    rpc        = GET_PTR( xp );
+    cxy_t        client_cxy = GET_CXY( xp );
+    rpc_desc_t * desc       = GET_PTR( xp );
 
     // get arguments from RPC descriptor
-    action   = (uint32_t)hal_remote_l64( XPTR(client_cxy , &rpc->args[0]) );
-    pid      = (pid_t)   hal_remote_l64( XPTR(client_cxy , &rpc->args[1]) );
-
-#if DEBUG_RPC_PROCESS_SIGACTION
-uint32_t cycle = (uint32_t)hal_get_cycles();
-thread_t * this = CURRENT_THREAD;
-if( DEBUG_RPC_PROCESS_SIGACTION < cycle )
-printk("\n[%s] thread[%x,%x] enter to %s process %x in cluster %x / cycle %d\n",
-__FUNCTION__, this->process->pid, this->trdid,
-process_action_str( action ), pid, local_cxy, cycle );
-#endif
+    pid_t    pid    = (pid_t)   hal_remote_l64( XPTR(client_cxy , &desc->args[0]) );
+    uint32_t action = (uint32_t)hal_remote_l64( XPTR(client_cxy , &desc->args[1]) );
 
     // get client thread pointers
-    client_ptr = (thread_t *)hal_remote_lpt( XPTR( client_cxy , &rpc->thread ) );
-    client_xp  = XPTR( client_cxy , client_ptr );
+    thread_t * client_ptr = hal_remote_lpt( XPTR( client_cxy , &desc->thread ) );
+    xptr_t     client_xp  = XPTR( client_cxy , client_ptr );
 
     // get local process descriptor
-    process = cluster_get_local_process_from_pid( pid );
+    process_t * process = cluster_get_local_process_from_pid( pid );
 
     // call relevant kernel function
@@ -939,31 +924,10 @@
     else if ( action == UNBLOCK_ALL_THREADS ) process_unblock_threads( process );
 
-    // build extended pointer on response counter in RPC
-    count_xp = XPTR( client_cxy , &rpc->responses );
-
-    // decrement the responses counter in RPC descriptor,
-    count_value = hal_remote_atomic_add( count_xp , -1 );
-
-    // unblock the client thread only if it is the last response.
-    if( count_value == 1 )
-    {
-        // get client core lid
-        client_lid    = (lid_t)     hal_remote_l32 ( XPTR( client_cxy , &rpc->lid    ) );
-
-        // unblock client thread
-        thread_unblock( client_xp , THREAD_BLOCKED_RPC );
-
-        // send an IPI to client core
-        // dev_pic_send_ipi( client_cxy , client_lid );
-    }
-
 #if DEBUG_RPC_PROCESS_SIGACTION
 cycle = (uint32_t)hal_get_cycles();
 if( DEBUG_RPC_PROCESS_SIGACTION < cycle )
-printk("\n[%s] thread[%x,%x] exit after %s process %x in cluster %x / cycle %d\n",
-__FUNCTION__, this->process->pid, this->trdid,
-process_action_str( action ), pid, local_cxy, cycle );
-#endif
-
+printk("\n[%s] thread[%x,%x] on core %d exit / cycle %d\n",
+__FUNCTION__, this->process->pid, this->trdid, this->core->lid, cycle );
+#endif
 } // end rpc_process_sigaction_server() 
 
@@ -991,5 +955,5 @@
 #endif
 
-    assert( (cxy != local_cxy) , "target cluster is not remote\n");
+    assert( (cxy != local_cxy) , "server cluster is not remote\n");
 
     // initialise RPC descriptor header 
@@ -1091,5 +1055,5 @@
 #endif
 
-    assert( (cxy != local_cxy) , "target cluster is not remote\n");
+    assert( (cxy != local_cxy) , "server cluster is not remote\n");
 
     // initialise RPC descriptor header 
@@ -1163,5 +1127,5 @@
 #endif
 
-    assert( (cxy != local_cxy) , "target cluster is not remote\n");
+    assert( (cxy != local_cxy) , "server cluster is not remote\n");
 
     // initialise RPC descriptor header 
@@ -1251,5 +1215,5 @@
 #endif
 
-    assert( (cxy != local_cxy) , "target cluster is not remote\n");
+    assert( (cxy != local_cxy) , "server cluster is not remote\n");
 
     // initialise RPC descriptor header 
@@ -1324,5 +1288,5 @@
 #endif
 
-    assert( (cxy != local_cxy) , "target cluster is not remote\n");
+    assert( (cxy != local_cxy) , "server cluster is not remote\n");
 
     // initialise RPC descriptor header 
@@ -1408,5 +1372,5 @@
 #endif
 
-    assert( (cxy != local_cxy) , "target cluster is not remote\n");
+    assert( (cxy != local_cxy) , "server cluster is not remote\n");
 
     // initialise RPC descriptor header 
@@ -1480,5 +1444,5 @@
 #endif
 
-    assert( (cxy != local_cxy) , "target cluster is not remote\n");
+    assert( (cxy != local_cxy) , "server cluster is not remote\n");
 
     // initialise RPC descriptor header 
@@ -1569,5 +1533,5 @@
 #endif
 
-    assert( (cxy != local_cxy) , "target cluster is not remote\n");
+    assert( (cxy != local_cxy) , "server cluster is not remote\n");
 
     // initialise RPC descriptor header 
@@ -1649,5 +1613,5 @@
 #endif
 
-    assert( (cxy != local_cxy) , "target cluster is not remote\n");
+    assert( (cxy != local_cxy) , "server cluster is not remote\n");
 
     // initialise RPC descriptor header 
@@ -1729,5 +1693,5 @@
 #endif
 
-    assert( (cxy != local_cxy) , "target cluster is not remote\n");
+    assert( (cxy != local_cxy) , "server cluster is not remote\n");
 
     // initialise RPC descriptor header 
@@ -1808,5 +1772,5 @@
 #endif
 
-    assert( (cxy != local_cxy) , "target cluster is not remote\n");
+    assert( (cxy != local_cxy) , "server cluster is not remote\n");
 
     // initialise RPC descriptor header 
@@ -1896,5 +1860,5 @@
 #endif
 
-    assert( (cxy != local_cxy) , "target cluster is not remote\n");
+    assert( (cxy != local_cxy) , "server cluster is not remote\n");
 
     // initialise RPC descriptor header 
@@ -1975,5 +1939,5 @@
 #endif
 
-    assert( (cxy != local_cxy) , "target cluster is not remote\n");
+    assert( (cxy != local_cxy) , "server cluster is not remote\n");
 
     // initialise RPC descriptor header 
@@ -2053,5 +2017,5 @@
 #endif
 
-    assert( (cxy != local_cxy) , "target cluster is not remote\n");
+    assert( (cxy != local_cxy) , "server cluster is not remote\n");
 
     // initialise RPC descriptor header 
@@ -2125,4 +2089,5 @@
 {
 #if DEBUG_RPC_MAPPER_HANDLE_MISS
+thread_t * this = CURRENT_THREAD;
 uint32_t cycle = (uint32_t)hal_get_cycles();
 if( cycle > DEBUG_RPC_MAPPER_HANDLE_MISS )
@@ -2131,5 +2096,5 @@
 #endif
 
-    assert( (cxy != local_cxy) , "target cluster is not remote\n");
+    assert( (cxy != local_cxy) , "server cluster is not remote\n");
 
     // initialise RPC descriptor header 
@@ -2162,4 +2127,5 @@
 {
 #if DEBUG_RPC_MAPPER_HANDLE_MISS
+thread_t * this = CURRENT_THREAD;
 uint32_t cycle = (uint32_t)hal_get_cycles();
 if( cycle > DEBUG_RPC_MAPPER_HANDLE_MISS )
@@ -2199,6 +2165,63 @@
 
 /////////////////////////////////////////////////////////////////////////////////////////
-// [26]         undefined slot
-/////////////////////////////////////////////////////////////////////////////////////////
+// [26]  Marshaling functions attached to RPC_VMM_DELETE_VSEG (parallel / non blocking)
+/////////////////////////////////////////////////////////////////////////////////////////
+
+//////////////////////////////////////////////////
+void rpc_vmm_delete_vseg_client( cxy_t        cxy,
+                                 rpc_desc_t * rpc )
+{
+#if DEBUG_RPC_VMM_DELETE_VSEG
+thread_t * this  = CURRENT_THREAD;
+uint32_t   cycle = (uint32_t)hal_get_cycles();
+if( cycle > DEBUG_RPC_VMM_DELETE_VSEG )
+printk("\n[%s] thread[%x,%x] on core %d enter / cycle %d\n",
+__FUNCTION__, this->process->pid, this->trdid, this->core->lid, cycle );
+#endif
+
+// check RPC "index" and "blocking" arguments
+assert( (rpc->blocking == false) , "must be non-blocking\n");
+assert( (rpc->index == RPC_VMM_DELETE_VSEG ) , "bad RPC index\n" );
+
+    // register RPC request in remote RPC fifo
+    rpc_send( cxy , rpc );
+
+#if DEBUG_RPC_VMM_DELETE_VSEG
+cycle = (uint32_t)hal_get_cycles();
+if( cycle > DEBUG_RPC_VMM_DELETE_VSEG )
+printk("\n[%s] thread[%x,%x] on core %d exit / cycle %d\n",
+__FUNCTION__, this->process->pid, this->trdid, this->core->lid, cycle );
+#endif
+}
+
+////////////////////////////////////////////
+void rpc_vmm_delete_vseg_server( xptr_t xp )
+{
+#if DEBUG_RPC_VMM_DELETE_VSEG
+uint32_t cycle = (uint32_t)hal_get_cycles();
+thread_t * this = CURRENT_THREAD;
+if( DEBUG_RPC_VMM_DELETE_VSEG < cycle )
+printk("\n[%s] thread[%x,%x] on core %d enter / cycle %d\n",
+__FUNCTION__, this->process->pid, this->trdid, this->core->lid, cycle );
+#endif
+
+    // get client cluster identifier and pointer on RPC descriptor
+    cxy_t        client_cxy = GET_CXY( xp );
+    rpc_desc_t * desc       = GET_PTR( xp );
+
+    // get arguments from RPC descriptor
+    pid_t    pid   = (pid_t)   hal_remote_l64( XPTR(client_cxy , &desc->args[0]) );
+    intptr_t vaddr = (intptr_t)hal_remote_l64( XPTR(client_cxy , &desc->args[1]) );
+
+    // call relevant kernel function
+    vmm_delete_vseg( pid , vaddr );
+
+#if DEBUG_RPC_VMM_DELETE_VSEG
+cycle = (uint32_t)hal_get_cycles();
+if( DEBUG_RPC_VMM_DELETE_VSEG < cycle )
+printk("\n[%s] thread[%x,%x] on core %d exit / cycle %d\n",
+__FUNCTION__, this->process->pid, this->trdid, this->core->lid, cycle );
+#endif
+} 
 
 /////////////////////////////////////////////////////////////////////////////////////////
@@ -2218,5 +2241,13 @@
                                  struct vseg_s   ** vseg )
 {
-    assert( (cxy != local_cxy) , "target cluster is not remote\n");
+#if DEBUG_RPC_VMM_CREATE_VSEG
+thread_t * this = CURRENT_THREAD;
+uint32_t cycle = (uint32_t)hal_get_cycles();
+if( cycle > DEBUG_RPC_VMM_CREATE_VSEG )
+printk("\n[%s] thread[%x,%x] on core %d enter / cycle %d\n",
+__FUNCTION__, this->process->pid, this->trdid, this->core->lid , cycle );
+#endif
+
+    assert( (cxy != local_cxy) , "server cluster is not remote\n");
 
     // initialise RPC descriptor header 
@@ -2242,4 +2273,10 @@
     *vseg = (vseg_t *)(intptr_t)rpc.args[8];
 
+#if DEBUG_RPC_VMM_CREATE_VSEG
+cycle = (uint32_t)hal_get_cycles();
+if( cycle > DEBUG_RPC_VMM_CREATE_VSEG )
+printk("\n[%s] thread[%x,%x] on core %d exit / cycle %d\n",
+__FUNCTION__, this->process->pid, this->trdid, this->core->lid , cycle );
+#endif
 }
 
@@ -2247,4 +2284,12 @@
 void rpc_vmm_create_vseg_server( xptr_t xp )
 {
+#if DEBUG_RPC_VMM_CREATE_VSEG
+thread_t * this = CURRENT_THREAD;
+uint32_t cycle = (uint32_t)hal_get_cycles();
+if( cycle > DEBUG_RPC_VMM_CREATE_VSEG )
+printk("\n[%s] thread[%x,%x] on core %d enter / cycle %d\n",
+__FUNCTION__, this->process->pid, this->trdid, this->core->lid , cycle );
+#endif
+
     // get client cluster identifier and pointer on RPC descriptor
     cxy_t        cxy  = GET_CXY( xp );
@@ -2274,4 +2319,10 @@
     hal_remote_s64( XPTR( cxy , &desc->args[8] ) , (uint64_t)(intptr_t)vseg );
 
+#if DEBUG_RPC_VMM_CREATE_VSEG
+cycle = (uint32_t)hal_get_cycles();
+if( cycle > DEBUG_RPC_VMM_CREATE_VSEG )
+printk("\n[%s] thread[%x,%x] on core %d exit / cycle %d\n",
+__FUNCTION__, this->process->pid, this->trdid, this->core->lid , cycle );
+#endif
 }
 
@@ -2284,5 +2335,5 @@
                              process_t * process )
 {
-    assert( (cxy != local_cxy) , "target cluster is not remote\n");
+    assert( (cxy != local_cxy) , "server cluster is not remote\n");
 
     // initialise RPC descriptor header 
@@ -2326,5 +2377,5 @@
                              bool_t      detailed )
 {
-    assert( (cxy != local_cxy) , "target cluster is not remote\n");
+    assert( (cxy != local_cxy) , "server cluster is not remote\n");
 
     // initialise RPC descriptor header 
