Index: trunk/kernel/kern/cluster.h
===================================================================
--- trunk/kernel/kern/cluster.h	(revision 562)
+++ trunk/kernel/kern/cluster.h	(revision 564)
@@ -30,7 +30,6 @@
 #include <hal_kernel_types.h>
 #include <bits.h>
-#include <spinlock.h>
-#include <readlock.h>
-#include <remote_barrier.h>
+#include <queuelock.h>
+#include <remote_queuelock.h>
 #include <list.h>
 #include <xlist.h>
@@ -68,22 +67,24 @@
  * 2) The local_root is the root of the local list of all process descriptors in cluster K.
  *    A process descriptor P is present in K, as soon as P has a thread in cluster K.
+ *    We use an xlist, because this list can be traversed by remote threads.
  *
  * 3) The copies_root[] array is indexed by lpid. There is one entry per owned process,
  *    and each each entry contains the root of the xlist of copies for this process.
+ $    We use an xlist, because process copies are distributed in all clusters. 
  ******************************************************************************************/
 
 typedef struct process_manager_s
 {
-	xptr_t            pref_tbl[CONFIG_MAX_PROCESS_PER_CLUSTER];  /*! reference  process   */
-	spinlock_t        pref_lock;              /*! lock protecting lpid allocation/release */
-    uint32_t          pref_nr;                /*! number of processes owned by cluster    */
-
-    xlist_entry_t     local_root;             /*! root of list of process in cluster      */
-    remote_spinlock_t local_lock;             /*! lock protecting access to local list    */
-    uint32_t          local_nr;               /*! number of process in cluster            */
-
-    xlist_entry_t     copies_root[CONFIG_MAX_PROCESS_PER_CLUSTER];  /*! roots of lists    */
-    remote_spinlock_t copies_lock[CONFIG_MAX_PROCESS_PER_CLUSTER];  /*! one lock per list */
-    uint32_t          copies_nr[CONFIG_MAX_PROCESS_PER_CLUSTER];    /*! number of copies  */
+	xptr_t             pref_tbl[CONFIG_MAX_PROCESS_PER_CLUSTER];  /*! owned  processes    */
+	queuelock_t        pref_lock;              /*! lock protecting pref_tbl               */
+    uint32_t           pref_nr;                /*! number of processes owned by cluster   */
+
+    xlist_entry_t      local_root;            /*! root of list of process in cluster      */
+    remote_queuelock_t local_lock;            /*! lock protecting local list              */
+    uint32_t           local_nr;              /*! number of process in cluster            */
+
+    xlist_entry_t      copies_root[CONFIG_MAX_PROCESS_PER_CLUSTER];  /*! roots of lists   */
+    remote_queuelock_t copies_lock[CONFIG_MAX_PROCESS_PER_CLUSTER];  /*! one  per list    */
+    uint32_t           copies_nr[CONFIG_MAX_PROCESS_PER_CLUSTER];    /*! number of copie  */
 }
 pmgr_t;
@@ -97,14 +98,12 @@
 typedef struct cluster_s
 {
-	spinlock_t      kcm_lock;          /*! local, protect creation of KCM allocators      */
 
     // global parameters
-	uint32_t        paddr_width;       /*! numer of bits in physical address              */
+    uint32_t        paddr_width;       /*! numer of bits in physical address              */
     uint32_t        x_width;           /*! number of bits to code x_size  (can be 0)      */
     uint32_t        y_width;           /*! number of bits to code y_size  (can be 0)      */
-	uint32_t        x_size;            /*! number of clusters in a row    (can be 1)      */
-	uint32_t        y_size;            /*! number of clusters in a column (can be 1)      */
-    uint32_t        cluster_info[CONFIG_MAX_CLUSTERS_X][CONFIG_MAX_CLUSTERS_Y];
-	cxy_t           io_cxy;            /*! io cluster identifier                          */
+    uint32_t        x_size;            /*! number of clusters in a row    (can be 1)      */
+    uint32_t        y_size;            /*! number of clusters in a column (can be 1)      */
+    cxy_t           io_cxy;            /*! io cluster identifier                          */
     uint32_t        dqdt_root_level;   /*! index of root node in dqdt_tbl[]               */
     uint32_t        nb_txt_channels;   /*! number of TXT channels                         */
@@ -113,6 +112,8 @@
     uint32_t        nb_fbf_channels;   /*! number of FBF channels                         */
 
+    char            cluster_info[CONFIG_MAX_CLUSTERS_X][CONFIG_MAX_CLUSTERS_Y];
+
     // local parameters
-	uint32_t        cores_nr;          /*! actual number of cores in cluster              */
+    uint32_t        cores_nr;          /*! actual number of cores in cluster              */
     uint32_t        ram_size;          /*! physical memory size                           */
     uint32_t        ram_base;          /*! physical memory base (local address)           */
@@ -120,19 +121,20 @@
 	core_t          core_tbl[CONFIG_MAX_LOCAL_CORES];    /*! embedded cores               */
 
-	list_entry_t    dev_root;          /*! root of list of devices in cluster             */
+    list_entry_t    dev_root;          /*! root of list of devices in cluster             */
 
     // memory allocators
-	ppm_t           ppm;               /*! embedded kernel page manager                   */
-	khm_t           khm;               /*! embedded kernel heap manager                   */
-	kcm_t           kcm;               /*! embedded kernel KCMs manager                   */
+    ppm_t           ppm;               /*! embedded kernel page manager                   */
+    khm_t           khm;               /*! embedded kernel heap manager                   */
+    kcm_t           kcm;               /*! embedded kernel KCMs manager                   */
 
     kcm_t         * kcm_tbl[KMEM_TYPES_NR];              /*! pointers on allocated KCMs   */
+    busylock_t      kcm_lock;                            /*! protect kcm_tbl[] updates    */
 
     // RPC
-	remote_fifo_t   rpc_fifo[CONFIG_MAX_LOCAL_CORES];    /*! one RPC FIFO per core        */
+    remote_fifo_t   rpc_fifo[CONFIG_MAX_LOCAL_CORES];    /*! one RPC FIFO per core        */
     uint32_t        rpc_threads[CONFIG_MAX_LOCAL_CORES]; /*! RPC threads per core         */
 
     // DQDT
-	dqdt_node_t     dqdt_tbl[CONFIG_DQDT_LEVELS_NR];     /*! embedded DQDT nodes          */
+    dqdt_node_t     dqdt_tbl[CONFIG_DQDT_LEVELS_NR];     /*! embedded DQDT nodes          */
 
     // Local process manager
@@ -158,26 +160,21 @@
 
 /******************************************************************************************
- * This generic function initialises the local cluster manager from information found
- * in the local boot-info structure. It initializes the following local resources:
- * - the global platform parameters,
- * - the specific cluster parameters,
- * - the lock protecting KCM creation,
- * - the local DQDT nodes,
- * - the PPM, KHM, and KCM allocators,
- * - the local core descriptors,
- * - the local RPC FIFO,
- * - the process manager.
- * It does NOT initialise the local device descriptors.
+ * These two functions initialise the local cluster manager from information found
+ * in the local boot-info structure <info> build by the boot-loader.
+ * 1) the cluster_info_init() function is called first, to initialize the structural
+ *    constants, and cannot use the TXT0 kernel terminal.
+ * 2) the cluster_manager_init() function initialize various complex structures:
+ *    - the local DQDT nodes,
+ *    - the PPM, KHM, and KCM allocators,
+ *    - the local core descriptors,
+ *    - the local RPC FIFO,
+ *    - the process manager.
+ *    It does NOT initialise the local device descriptors.
+ *    It can use the TXT0 kernel terminal.
  ******************************************************************************************
  * @ info : pointer on the local boot_info_t structure build by the bootloader.
  *****************************************************************************************/
-error_t cluster_init( boot_info_t * info );
-
-/****************************************************************************************** 
- * This function randomly selects a cluster.
- ******************************************************************************************
- * @ returns the selected cluster identifier.
- *****************************************************************************************/
-cxy_t cluster_random_select( void );
+void    cluster_info_init( boot_info_t * info );
+error_t cluster_manager_init( boot_info_t * info );
 
 /******************************************************************************************
@@ -189,8 +186,21 @@
 bool_t cluster_is_undefined( cxy_t cxy );
 
-
-/*****************************************************************************************/
-/***************   Process Management Operations   ***************************************/
-/*****************************************************************************************/
+/******************************************************************************************
+ * This function uses the local cluster_info[][] array in cluster descriptor,
+ * and returns true when the cluster identified by the <cxy> argument is active.
+ ******************************************************************************************
+ * @ cxy   : cluster identifier.
+ * @ return true if cluster contains a kernel instance.
+ *****************************************************************************************/
+bool_t cluster_is_active( cxy_t  cxy );
+
+/****************************************************************************************** 
+ * This function (pseudo) randomly selects a valid cluster.
+ * It is called by the vfs_cluster_lookup() function to place a new (missing) inode.
+ * It is called by the vmm_page_allocate() function to place a distributed vseg page.
+ ******************************************************************************************
+ * @ returns the selected cluster identifier.
+ *****************************************************************************************/
+cxy_t cluster_random_select( void );
 
 /******************************************************************************************
@@ -290,24 +300,20 @@
 void cluster_process_copies_unlink( struct process_s * process );
 
-/*********************************************************************************************
+/******************************************************************************************
  * This function displays on the kernel terminal TXT0 all user processes registered
  * in the cluster defined by the <cxy> argument.
  * It can be called by a thread running in any cluster, because is use remote accesses
  * to scan the xlist of registered processes.
- *********************************************************************************************
+ ******************************************************************************************
  * @ cxy   : cluster identifier.
- ********************************************************************************************/
+ *****************************************************************************************/
 void cluster_processes_display( cxy_t cxy );
 
-
-
-/*****************************************************************************************/
-/***************   Cores Management Operations   *****************************************/
-/*****************************************************************************************/
-
-/******************************************************************************************
- * This function returns the core local index that has the lowest usage in local cluster.
+/******************************************************************************************
+ * This function uses the local boot_inforeturns the core local index that has the lowest usage in local cluster.
  *****************************************************************************************/
 lid_t cluster_select_local_core( void );
 
+             
 #endif	/* _CLUSTER_H_ */
+
