Index: trunk/kernel/kernel_config.h
===================================================================
--- trunk/kernel/kernel_config.h	(revision 557)
+++ trunk/kernel/kernel_config.h	(revision 569)
@@ -24,6 +24,6 @@
  */
 
-#ifndef _ALMOS_CONFIG_H_
-#define _ALMOS_CONFIG_H_
+#ifndef _KERNEL_CONFIG_H_
+#define _KERNEL_CONFIG_H_
 
 #define CONFIG_ALMOS_VERSION           "Version 1.0 / August 2018"
@@ -36,4 +36,7 @@
 ////////////////////////////////////////////////////////////////////////////////////////////
 
+#define DEBUG_BUSYLOCK                 0
+#define DEBUG_BUSYLOCK_THREAD_XP       0x3A000ULL    // selected thread_xp
+                 
 #define DEBUG_CHDEV_CMD_RX             0
 #define DEBUG_CHDEV_CMD_TX             0
@@ -83,9 +86,10 @@
 
 #define DEBUG_KERNEL_INIT              0
-#define DEBUG_KMEM_ALLOC               0
 
 #define DEBUG_MAPPER_GET_PAGE          0
 #define DEBUG_MAPPER_MOVE_USER         0
 #define DEBUG_MAPPER_MOVE_KERNEL       0
+
+#define DEBUG_MUTEX                    0
 
 #define DEBUG_PPM_ALLOC_PAGES          0
@@ -103,11 +107,17 @@
 #define DEBUG_PROCESS_ZERO_CREATE      0
 
+#define DEBUG_QUEUELOCK                0
+
 #define DEBUG_RPC_CLIENT_GENERIC       0
 #define DEBUG_RPC_SERVER_GENERIC       0
 
+#define DEBUG_RPC_KCM_ALLOC            0
+#define DEBUG_RPC_KCM_FREE             0
 #define DEBUG_RPC_PMEM_GET_PAGES       0
 #define DEBUG_RPC_PMEM_RELEASE_PAGES   0
 #define DEBUG_RPC_PROCESS_MAKE_FORK    0
 #define DEBUG_RPC_PROCESS_SIGACTION    0
+#define DEBUG_RPC_THREAD_USER_CREATE   0
+#define DEBUG_RPC_THREAD_KERNEL_CREATE 0
 #define DEBUG_RPC_VFS_INODE_CREATE     0
 #define DEBUG_RPC_VFS_INODE_DESTROY    0
@@ -119,10 +129,16 @@
 #define DEBUG_RPC_VMM_GET_VSEG         0
 
-#define DEBUG_SCHED_HANDLE_SIGNALS     2
+#define DEBUG_RWLOCK                   0
+
+#define DEBUG_SCHED_HANDLE_SIGNALS     0
 #define DEBUG_SCHED_YIELD              2    // must be activated by the trace() syscall
+#define DEBUG_SCHED_RPC_CHECK          0
+
+#define DEBUG_SEM                      0
 
 #define DEBUG_SYSCALLS_ERROR           2
 
 #define DEBUG_SYS_CLOSE                0
+#define DEBUG_SYS_CONDVAR              0
 #define DEBUG_SYS_DISPLAY              0
 #define DEBUG_SYS_EXEC                 0
@@ -131,4 +147,5 @@
 #define DEBUG_SYS_FORK                 0
 #define DEBUG_SYS_GET_CONFIG           0
+#define DEBUG_SYS_GETPID               0
 #define DEBUG_SYS_ISATTY               0
 #define DEBUG_SYS_IS_FG                0
@@ -137,5 +154,7 @@
 #define DEBUG_SYS_MMAP                 0
 #define DEBUG_SYS_MUNMAP               0
+#define DEBUG_SYS_MUTEX                0
 #define DEBUG_SYS_READ                 0
+#define DEBUG_SYS_SEM                  0
 #define DEBUG_SYS_THREAD_CANCEL        0
 #define DEBUG_SYS_THREAD_CREATE        0
@@ -148,5 +167,4 @@
 #define DEBUG_SYS_WAIT                 0
 #define DEBUG_SYS_WRITE                0
-#define DEBUG_SYS_SEM                  0
 
 #define DEBUG_SPINLOCKS                0
@@ -155,9 +173,9 @@
 #define DEBUG_REMOTE_RWLOCKS           0
 
+#define DEBUG_THREAD_DELETE            0
 #define DEBUG_THREAD_DESTROY           0
 #define DEBUG_THREAD_IDLE              0
 #define DEBUG_THREAD_INIT              0
 #define DEBUG_THREAD_KERNEL_CREATE     0
-#define DEBUG_THREAD_KILL              0
 #define DEBUG_THREAD_USER_CREATE       0
 #define DEBUG_THREAD_USER_FORK         0
@@ -165,13 +183,13 @@
 #define DEBUG_THREAD_BLOCK             0
 
+#define DEBUG_VFS_ADD_CHILD            0
 #define DEBUG_VFS_CLOSE                0
+#define DEBUG_VFS_DENTRY_CREATE        0
 #define DEBUG_VFS_INODE_CREATE         0
 #define DEBUG_VFS_INODE_LOAD           0
-#define DEBUG_VFS_DENTRY_CREATE        0
-#define DEBUG_VFS_OPEN                 0
 #define DEBUG_VFS_LOOKUP               0
-#define DEBUG_VFS_ADD_CHILD            0
 #define DEBUG_VFS_MAPPER_MOVE          0
 #define DEBUG_VFS_MAPPER_LOAD          0
+#define DEBUG_VFS_OPEN                 0
 
 #define DEBUG_VMM_CREATE_VSEG          0
@@ -187,4 +205,52 @@
 #define DEBUG_VMM_UPDATE_PTE           0
 
+#define DEBUG_XHTAB                    0
+
+
+////////////////////////////////////////////////////////////////////////////////////////////
+//                KERNEL LOCKS TYPES MNEMONICS (for debug)
+// It must be kept consistent with the lock_name[] array defined in kernel_init.c file.
+////////////////////////////////////////////////////////////////////////////////////////////
+
+#define LOCK_CLUSTER_KCM       1   // local  (B)  protect dynamic KCM creation in cluster
+#define LOCK_PPM_FREE          2   // local  (B)  protect PPM allocator free_pages lists
+#define LOCK_SCHED_STATE       3   // local  (B)  protect scheduler state for given core
+#define LOCK_VMM_STACK         4   // local  (B)  protect VMM stack vseg allocator   
+#define LOCK_VMM_MMAP          5   // local  (B)  protect VMM mmap vseg allocator
+#define LOCK_VFS_CTX           6   // local  (B)  protect vfs context state
+#define LOCK_KCM_STATE         7   // local  (B)  protect KCM allocator state
+#define LOCK_KHM_STATE         8   // local  (B)  protect KHM allocator state
+#define LOCK_HTAB_STATE        9   // local  (B)  protect a local htab state
+
+#define LOCK_THREAD_JOIN      10   // remote (B)  protect join/exit between two threads
+#define LOCK_VFS_MAIN         11   // remote (B)  protect vfs traversal (one per inode)
+#define LOCK_CHDEV_QUEUE      12   // remote (B)  protect chdev threads waiting queue
+#define LOCK_CHDEV_TXT0       13   // remote (B)  protect access to kernel terminal TXT0
+#define LOCK_CHDEV_TXTLIST    14   // remote (B)  protect xlist of processes using same TXT
+#define LOCK_PAGE_STATE       15   // remote (B)  protect physical page descriptor state
+#define LOCK_MUTEX_STATE      16   // remote (B)  protect user mutex state
+#define LOCK_CONDVAR_STATE    17   // remote (B)  protect user condvar state
+#define LOCK_SEM_STATE        18   // remote (B)  protect user semaphore state
+#define LOCK_XHTAB_STATE      19   // remote (B)  protect a distributed xhatb state
+
+#define BUSYLOCK_TYPE_MAX     20
+
+#define LOCK_CLUSTER_PREFTBL  21   // local  (Q)  protect array of ref. processes in cluster
+#define LOCK_PPM_DIRTY        22   // local  (Q)  protect PPM dirty_pages list
+
+#define LOCK_CLUSTER_LOCALS   23   // remote (Q)  protect xlist of local processes in cluster
+#define LOCK_CLUSTER_COPIES   24   // remote (Q)  protect xlist of process copies in cluster
+#define LOCK_PROCESS_CHILDREN 25   // remote (Q)  protect xlist of chidren process in process
+#define LOCK_PROCESS_USERSYNC 26   // remote (Q)  protect all lists of user synchros in  process
+#define LOCK_PROCESS_FDARRAY  27   // remote (Q)  protect array of open files in owner process 
+
+#define LOCK_MAPPER_STATE     28   // local  (RW) protect mapper state
+#define LOCK_PROCESS_THTBL    29   // local  (RW) protect local array of threads in a process 
+
+#define LOCK_PROCESS_CWD      30   // remote (RW) protect current working directory in process
+#define LOCK_VFS_INODE        31   // remote (RW) protect inode state and associated mapper
+#define LOCK_VFS_FILE         32   // remote (RW) protect file descriptor state
+#define LOCK_VMM_VSL          33   // remote (RW) protect VSL (local list of vsegs)
+
 ////////////////////////////////////////////////////////////////////////////////////////////
 //                          HARDWARE CONFIGURATION     
@@ -192,12 +258,12 @@
 
 #define CONFIG_KERNEL_IDENTITY_MAP          true       // True for 32 bits cores             
-#define CONFIG_MAX_CLUSTERS_X               16         // max number of cluster columns
-#define CONFIG_MAX_CLUSTERS_Y               16         // max number of cluster rows
-#define CONFIG_MAX_CLUSTERS                 (CONFIG_MAX_CLUSTERS_X * CONFIG_MAX_CLUSTERS_Y)
+#define CONFIG_MAX_CLUSTERS_X               16         // max number of clusters in row
+#define CONFIG_MAX_CLUSTERS_Y               16         // max number of clusters in column
+#define CONFIG_MAX_CLUSTERS                 (CONFIG_MAX_CLUSTERS_X * CONFIG_MAX_CLUSTERS_Y) 
 #define CONFIG_MAX_LOCAL_CORES              4          // max number of cores per cluster
 #define CONFIG_MAX_INT_DEV                  4          // max number of internal peripherals
 #define CONFIG_MAX_EXT_DEV                  8          // max number of external peripherals
-#define CONFIG_MAX_INTERNAL_IRQS            32         // max number of HWI per ICU
-#define CONFIG_MAX_EXTERNAL_IRQS            32         // max number of PTI per ICU
+#define CONFIG_MAX_INTERNAL_IRQS            32         // max number of internal IRQs
+#define CONFIG_MAX_EXTERNAL_IRQS            32         // max number of external IRQs
 #define CONFIG_IRQS_PER_CORE                4          // number of input IRQs per core
 #define CONFIG_CLUSTER_SPAN                 32         // ln(phys. address space per cluster)
@@ -245,10 +311,4 @@
 
 ////////////////////////////////////////////////////////////////////////////////////////////
-//                                 LOCKS          
-////////////////////////////////////////////////////////////////////////////////////////////
-
-#define CONFIG_RWLOCK_DELAY                 50       // iterations number ( ~ 200 cycles )
-
-////////////////////////////////////////////////////////////////////////////////////////////
 //                                  DQDT        
 ////////////////////////////////////////////////////////////////////////////////////////////
@@ -276,5 +336,5 @@
 ////////////////////////////////////////////////////////////////////////////////////////////
 
-#define CONFIG_THREAD_MAX_PER_CLUSTER       16      // max threads per cluster & process
+#define CONFIG_THREADS_MAX_PER_CLUSTER      16      // max threads per cluster & process
 #define CONFIG_THREAD_DESC_SIZE             0x4000  // thread desc size (with kernel stack)
 #define CONFIG_THREAD_DESC_ORDER            2       // ln( number of 4K pages )
@@ -333,64 +393,11 @@
 
 
-
-////////////////////////////////////////////////////////////////////////////////////////////
-//    deprecated
-////////////////////////////////////////////////////////////////////////////////////////////
-
-#define CONFIG_DMA_RQ_KCM_MIN         2
-#define CONFIG_DMA_RQ_KCM_MAX         4
-#define CONFIG_TASK_KCM_MIN           2
-#define CONFIG_TASK_KCM_MAX           3
-#define CONFIG_FDINFO_KCM_MIN         2
-#define CONFIG_FDINFO_KCM_MAX         2
-#define CONFIG_DEVFS_CTX_MIN          1
-#define CONFIG_DEVFS_CTX_MAX          1
-#define CONFIG_DEVFS_FILE_MIN         2
-#define CONFIG_DEVFS_FILE_MAX         3
-#define CONFIG_DEVFS_NODE_MIN         1
-#define CONFIG_DEVFS_NODE_MAX         2
-#define CONFIG_VFAT_CTX_MIN           1
-#define CONFIG_VFAT_CTX_MAX           1
-
-#define CONFIG_RAMFS_FILE_MIN         3
-#define CONFIG_RAMFS_FILE_MAX	      3
-
-#define CONFIG_VFAT_FILE_MIN          3
-#define CONFIG_VFAT_FILE_MAX          3
-#define CONFIG_VFAT_NODE_MIN          2
-#define CONFIG_VFAT_NODE_MAX          2
-
-#define CONFIG_EXT2_CTX_MIN           1
-#define CONFIG_EXT2_CTX_MAX           1
-#define CONFIG_EXT2_FILE_MIN          3
-#define CONFIG_EXT2_FILE_MAX          3
-#define CONFIG_EXT2_NODE_MIN          2
-#define CONFIG_EXT2_NODE_MAX          2
-
-#define CONFIG_VFS_CTX_MIN            1
-#define CONFIG_VFS_CTX_MAX            1
-#define CONFIG_VFS_INODE_MIN          3
-#define CONFIG_VFS_INODE_MAX          6
-#define CONFIG_VFS_FILE_MIN           3
-#define CONFIG_VFS_FILE_MAX           5
-
-#define CONFIG_SEMAPHORE_MIN          2
-#define CONFIG_SEMAPHORE_MAX          2
-#define CONFIG_CONDTION_VAR_MIN       2
-#define CONFIG_CONDTION_VAR_MAX       2
-#define CONFIG_BARRIER_MIN            2
-#define CONFIG_BARRIER_MAX            2
-#define CONFIG_RWLOCK_MIN             2
-#define CONFIG_RWLOCK_MAX             2
-#define CONFIG_WAITQUEUEDB_MAX        2
-#define CONFIG_WAITQUEUEDB_MIN        2
-#define CONFIG_RADIX_NODE_MIN         10         
-#define CONFIG_RADIX_NODE_MAX         30
-#define CONFIG_VM_REGION_MIN          1
-#define CONFIG_VM_REGION_MAX          2
-#define CONFIG_BLKIO_MIN              4
-#define CONFIG_BLKIO_MAX              8
-#define CONFIG_KEYREC_MIN             2
-#define CONFIG_KEYREC_MAX             2
+////////////////////////////////////////////////////////////////////////////////////////////
+//                 INSTRUMENTATION
+////////////////////////////////////////////////////////////////////////////////////////////
+
+#define CONFIG_INTRUMENTATION_SYSCALLS  0
+
+
 
 
