Index: trunk/kernel/kern/rpc.h
===================================================================
--- trunk/kernel/kern/rpc.h	(revision 401)
+++ trunk/kernel/kern/rpc.h	(revision 407)
@@ -30,4 +30,5 @@
 #include <bits.h>
 #include <spinlock.h>
+#include <vseg.h>
 #include <remote_fifo.h>
 
@@ -82,4 +83,6 @@
     RPC_MAPPER_MOVE_BUFFER     = 24,
     RPC_MAPPER_GET_PAGE        = 25,
+    RPC_VMM_CREATE_VSEG        = 26,
+    RPC_SCHED_DISPLAY          = 27,
 
     RPC_MAX_INDEX              = 30,
@@ -100,27 +103,11 @@
 typedef struct rpc_desc_s
 {
-	rpc_index_t       index;       // index of requested RPC service
-	volatile uint32_t response;    // response valid when 0
-    uint64_t          args[10];    // input/output arguments buffer
+	rpc_index_t         index;       /*! index of requested RPC service           */
+	volatile uint32_t   response;    /*! response valid when 0                    */
+    struct thread_s   * thread;      /*! local pointer on client thread           */
+    uint32_t            lid;         /*! index of core running the calling thread */ 
+    uint64_t            args[10];    /*! input/output arguments buffer            */
 } 
 rpc_desc_t;
-
-/***********************************************************************************
- * This structure defines the RPC fifo, containing a remote_fifo, the owner RPC
- * thread TRDID (used as a light lock), and the intrumentation counter.
- *
- * Implementation note: the TRDID is a good owner identifier, because all
- * RPC threads in a given cluster belong to the same process_zero kernel process,
- * and RPC threads cannot have local index LTID = 0.
- **********************************************************************************/
-
-typedef struct rpc_fifo_s
-{
-	trdid_t           owner;       // owner thread / 0 if no owner
-	uint64_t          count;       // total number of received RPCs (instrumentation) 
-	remote_fifo_t     fifo;        // embedded remote fifo
-} 
-rpc_fifo_t;
-
 
 /**********************************************************************************/
@@ -149,44 +136,24 @@
 
 /***********************************************************************************
- * This function initialises the local RPC fifo and the lock protecting readers.
- * The number of slots is defined by the CONFIG_REMOTE_FIFO_SLOTS parameter.
- * Each slot contains an extended pointer on the RPC descriptor.
- ***********************************************************************************
- * @ rf     : pointer on the local RPC fifo.
- **********************************************************************************/ 
-void rpc_fifo_init( rpc_fifo_t * rf );
-
-/***********************************************************************************
  * This function is the entry point for RPC handling on the server side.
- * It is executed by a core receiving an IPI.
- * It checks the RPC fifo, try to take the light-lock and activates (or creates)
- * an RPC thread in case of success.
- ***********************************************************************************
- * @ returns true if success / false otherwise.
- **********************************************************************************/
-bool_t rpc_check();
+ * It is executed by a core receiving an IPI, and each time the core enters,
+ * or exit the kernel to handle .
+ * It does nothing and return if the RPC_FIFO is empty.
+ * The calling thread checks if it exist at least one non-blocked RPC thread,
+ * creates a new RPC if required, and deschedule to allow the RPC thead to execute.
+ **********************************************************************************/
+void rpc_check();
 
 /***********************************************************************************
  * This function contains the loop to execute all pending RPCs on the server side.
- * It should be called with irq disabled and after light lock acquisition.
+ * It is called by the rpc_thread_func() function with irq disabled, and after
+ * RPC_FIFO ownership acquisition.
  ***********************************************************************************
  * @ rpc_fifo  : pointer on the local RPC fifo
  **********************************************************************************/
-void rpc_execute_all( rpc_fifo_t * rpc_fifo );
-
-/**********************************************************************************
- * This function is called by any thread running on any core in any cluster,
- * that detected a non-empty RPC_FIFO and got the RPC_FIFO ownership.
- * It activates one RPC thread, and immediately switches to the RPC thread.
- * It gets the first free RPC thread from the core free-list, or creates a new one
- * when the core free-list is empty. 
- ***********************************************************************************
- * @ rpc_fifo : pointer on the non-empty RPC fifo.
- * @ return 0 if success / return ENOMEM if error.
- **********************************************************************************/
-error_t rpc_activate_thread( rpc_fifo_t * rpc_fifo );
-
-/***********************************************************************************
- * This function contains the infinite loop executed by each RPC thread.
+void rpc_execute_all( remote_fifo_t * rpc_fifo );
+
+/***********************************************************************************
+ * This function contains the infinite loop executed by a RPC thread.
  **********************************************************************************/
 void rpc_thread_func();
@@ -266,6 +233,6 @@
  ***********************************************************************************
  * @ cxy       : server cluster identifier.
- * @ attr      : [in]  pointer on pthread_attr_t in client cluster.
- * @ thread_xp : [out] pointer on buffer for thread extended pointer. 
+ * @ attr      : [in]  local pointer on pthread_attr_t in client cluster.
+ * @ thread_xp : [out] buffer for thread extended pointer. 
  * @ error     : [out] error status (0 if success).
  **********************************************************************************/
@@ -274,5 +241,5 @@
                                     void                  * start_func,
                                     void                  * start_arg,
-                                    struct pthread_attr_s * attr,
+                                    pthread_attr_t        * attr,
                                     xptr_t                * thread_xp,
                                     error_t               * error );
@@ -499,9 +466,9 @@
 
 /***********************************************************************************
- * [21] The RPC_VMM_GET_PTE returns in the "ppn" and "attr" arguments the PTE value
- * for a given VPN in a given process.
+ * [21] The RPC_VMM_GET_PTE returns in the <ppn> and <attr> arguments the PTE value
+ * for a given <vpn> in a given <process> (page_fault or copy_on_write event).
  * The server cluster is supposed to be the reference cluster, and the vseg
  * containing the VPN must be registered in the reference VMM.
- * It returns an error if physical memory cannot be allocated for the PTE2, 
+ * It returns an error if physical memory cannot be allocated for the missing PTE2, 
  * or for the missing page itself.
  ***********************************************************************************
@@ -509,4 +476,5 @@
  * @ process : [in]   pointer on process descriptor in server cluster. 
  * @ vaddr   : [in]   virtual address to be searched.
+ * @ cow     : [in]   "copy_on_write" event if true / "page_fault" event if false.
  * @ attr    : [out]  address of buffer for attributes.
  * @ ppn     : [out]  address of buffer for PPN.
@@ -516,4 +484,5 @@
                              struct process_s * process,
                              vpn_t              vpn,
+                             bool_t             cow,
                              uint32_t         * attr,
                              ppn_t            * ppn,
@@ -601,3 +570,46 @@
 void rpc_mapper_get_page_server( xptr_t xp );
 
+/***********************************************************************************
+ * [26] The RPC_VMM_CREATE_VSEG allows a client thread to request the remote 
+ * reference cluster of a given process to allocate and register in the reference
+ * process VMM a new vseg descriptor.
+ * On the server side, this RPC uses the vmm_create_vseg() function, and returns
+ * to the client the local pointer on the created vseg descriptor.
+ ***********************************************************************************
+ * @ cxy         : server cluster identifier.
+ * @ process     : [in]  local pointer on process descriptor in server.
+ * @ type        : [in]  vseg type.
+ * @ base        : [in]  base address (unused for dynamically allocated vsegs).
+ * @ size        : [in]  number of bytes.
+ * @ file_offset : [in]  offset in file (for CODE, DATA, FILE types).
+ * @ file_size   : [in]  can be smaller than size for DATA type.
+ * @ mapper_xp   : [in]  extended pointer on mapper (for CODE, DATA, FILE types).
+ * @ vseg_cxy    : [in]  target cluster for mapping (if not data type).
+ * @ vseg        : [out] local pointer on vseg descriptor / NULL if failure.
+ **********************************************************************************/
+void rpc_vmm_create_vseg_client( cxy_t              cxy,
+                                 struct process_s * process,
+                                 vseg_type_t        type,
+                                 intptr_t           base,
+                                 uint32_t           size,
+                                 uint32_t           file_offset,
+                                 uint32_t           file_size,
+                                 xptr_t             mapper_xp,
+                                 cxy_t              vseg_cxy,
+                                 struct vseg_s   ** vseg );
+
+void rpc_vmm_create_vseg_server( xptr_t xp );
+
+/***********************************************************************************
+ * [27] The RPC_SCHED_DISPLAY allows a client thread to request the display
+ * of a remote scheduler, identified by the <lid> argument.
+ ***********************************************************************************
+ * @ cxy         : server cluster identifier.
+ * @ lid         : [in]  local index of target core in client cluster.
+ **********************************************************************************/
+void rpc_sched_display_client( cxy_t              cxy,
+                               lid_t              lid );
+
+void rpc_sched_display_server( xptr_t xp );
+
 #endif
