Index: trunk/kernel/mm/kcm.h
===================================================================
--- trunk/kernel/mm/kcm.h	(revision 690)
+++ trunk/kernel/mm/kcm.h	(revision 1)
@@ -1,6 +1,7 @@
 /*
- * kcm.h - Kernel Cache Manager definition.
+ * kcm.h - Per-cluster Kernel Cache Manager Interface
  *
- * Authors    Alain Greiner (2016,2017,2018,2019,2020)
+ * Authors  Ghassan Almaless (2008,2009,2010,2011,2012)
+ *          Alain Greiner    (2016)
  *
  * Copyright (c) UPMC Sorbonne Universites
@@ -26,6 +27,6 @@
 
 #include <list.h>
-#include <hal_kernel_types.h>
-#include <busylock.h>
+#include <hal_types.h>
+#include <spinlock.h>
 #include <page.h>
 #include <bits.h>
@@ -33,41 +34,29 @@
 
 /****************************************************************************************
- * This structure defines a generic Kernel Cache Manager, a fixed size block allocator.
- * It returns an aligned block whose size is a power of 2, not smaller than a cache line,
- * but smaller than a small PPM page. It exists in each cluster a specific KCM allocator
- * for each possible block size. When the cache line contains 64 bytes and the page 
- * contains 4K bytes, the possible block sizes are 64, 128, 256, 512, 1024, 2048 bytes.
- * These KCM allocators are initialized by the cluster_init() function.
- *
- * Each KCM cache is implemented as a set of "kcm_pages": a "kcm_page" is an aligned
- * buffer in physical memory (allocated by the PPM allocator) such as :
- *       buffer_size = block_size * 64  <=>  buffer_order = block_order + 6.
- * 
- * A kcm_page contains always 64 kcm_blocks, but the first block (that cannot be smaller
- * than 64 bytes) is used to store the kcm_page descriptor defining the page allocation
- * status, and cannot be allocated to store data.
- *
- * A KCM cache is extensible, as new kcm_pages are dynamically allocated from the PPM
- * allocator when required. For a given KCM cache the set of kcm_pages is split in two
- * lists: the list of "full" pages (containing 63 allocated blocks), and the list of
- * "active" pages (containing at least one free block). An "empty" page (containing
- * only free blocks) is considered active, and is not released to PPM.
- * 
- * To allow any thread running in any cluster to directly access the KCM of any cluster,
- * ALMOS-MKH defines two sets of access functions, for local or remote access.
+ * This structure defines a generic Kernel Cache Manager, that is a block allocator,
+ * for fixed size objects. It exists a specific KCM allocator for each object type.
+ * The actual allocated block size is the smallest multiple of 64 bytes that can
+ * contain one single object.
+ * The various KCM allocators themselves are not statically allocated in the cluster
+ * manager, but are dynamically allocated when required, using the specific KCM 
+ * allocator defined in the cluster manager, to allocate the other ones...
  ***************************************************************************************/
 
-typedef struct kcm_s
+typedef struct kcm_s                      
 {
-	remote_busylock_t    lock;             /*! protect KCM allocator                   */
+	spinlock_t           lock;             /*! protect exclusive access to allocator   */
+	uint32_t             block_size;       /*! actual block size (bytes)               */
+	uint32_t             blocks_nr;        /*! number of blocks per page               */
 
-	list_entry_t         full_root;        /*! root of full pages list                 */
 	list_entry_t         active_root;      /*! root of active pages list               */
+	list_entry_t         busy_root;        /*! root of busy pages list                 */
+	list_entry_t         free_root;        /*! root of free pages list                 */
 
-	uint32_t             full_pages_nr;    /*! number of full pages                    */
+	uint32_t             free_pages_nr;    /*! number of free pages                    */
+	uint32_t             busy_pages_nr;    /*! number of busy pages                    */
 	uint32_t             active_pages_nr;  /*! number of active pages                  */
 
-	uint32_t             order;            /*! ln( block_size )                        */
-}
+    uint32_t             type;             /*! KCM type                                */
+} 
 kcm_t;
 
@@ -75,95 +64,61 @@
 /****************************************************************************************
  * This structure defines a KCM-page descriptor.
- * A KCM-page contains (CONFIG_PPM_PAGE_SIZE / block_size) slots. 
- * Each slot contains one block, but the kcm page descriptor is stored in first slot.
- * The current allocation status is defined by the 64 bits "status" bit vector: each
- * non zero bit defines an allocated block / "count" is the number of allocated blocks. 
- * Each kcm_page is registered in one of the two following lists, rooted in the kcm:
- * - full   : when count == max
- * - active : count < max 
+ * A KCM-page can contain several blocks.
+ * This descriptor is stored in the first block slot.
  ***************************************************************************************/
 
 typedef struct kcm_page_s
 {
-	uint64_t            status;            /*! bit vector: non-zero == allocated       */
-	uint32_t            count;             /*! number of allocated blocks in page      */
-	list_entry_t        list;              /*! [active / busy / free] list member      */
-	kcm_t             * kcm;               /*! pointer on kcm allocator                */
-	page_t            * page;              /*! pointer on physical page descriptor     */
-}
+	BITMAP          ( bitmap , 16 );       /*! at most 16 blocks in a page (1 if free) */
+	uint8_t       * blk_tbl;               /*! pointer on first free block in page     */
+	kcm_t         * kcm;                   /*! owner KCM allocator                     */
+	uint8_t         unused;                /*! first free block index in page          */
+	uint8_t         refcount;              /*! number of allocated blocks              */
+	uint8_t         busy;                  /*! page busy if non zero                   */
+	uint8_t         active;                /*! page active if non zero                 */
+	list_entry_t    list;                  /*! [active / busy / free] list member      */
+	page_t        * page;                  /*! pointer on the physical page descriptor */
+} 
 kcm_page_t;
 
 /****************************************************************************************
- * This function must be called by a local thread. 
- * It initializes a Kernel Cache Manager, depending on block size.
+ * This function initializes a generic Kernel Cache Manager. 
  ****************************************************************************************
- * @ kcm      : pointer on KCM to be initialized.
- * @ order    : ln(block_size).
+ * @ kcm      : pointer on KCM manager to initialize.
+ * @ type     : KCM allocator type.
  ***************************************************************************************/
-void kcm_init( kcm_t    * kcm,
-               uint32_t   order );
+error_t kcm_init( kcm_t       * kcm,
+		          uint32_t      type );
 
 /****************************************************************************************
- * This function must be called by a local thread. 
- * It releases all memory allocated to a Kernel Cache Manager.
+ * This function releases all memory allocated to a generic Kernel Cache Manager. 
  ****************************************************************************************
  * @ kcm      : pointer on KCM manager to destroy.
  ***************************************************************************************/
-void kcm_destroy( kcm_t  * kcm );
+void kcm_destroy( kcm_t       * kcm );
 
 /****************************************************************************************
- * This function must be called by a local thread. 
- * It allocates one block from the local Kernel Cache Manager.
+ * This function allocates one single object in a Kernel Cache Manager 
+ * The object size must be smaller than one page size.
  ****************************************************************************************
- * @ order     :  ln( block-size ) == KCM allocator identifier.
- * @ return pointer on allocated block if success / return NULL if failure
+ * @ kcm     :  pointer on the selected KCM allocator
  ***************************************************************************************/
-void * kcm_alloc( uint32_t order );
+void * kcm_alloc( kcm_t * kcm );
 
 /****************************************************************************************
- * This function must be called by a local thread. 
- * It releases a previouly allocated block to the local Kernel Cache Manager.
+ * This function releases a previouly allocated block containing one object.
  ****************************************************************************************
- * @ block_ptr   : local pointer on the released block.
- * @ order       : log2( block_size in bytes ).
+ * @ ptr   : local pointer on the allocated buffer.
  ***************************************************************************************/
-void kcm_free( void    * block_ptr,
-               uint32_t  order );
+void  kcm_free( void * ptr );
+
+/****************************************************************************************
+ * This function prints KCM allocator state (for debug only).
+ ****************************************************************************************
+ * @ kcm   : local pointer on the selected KCM allocator.
+ ***************************************************************************************/
+void kcm_print( kcm_t * kcm );
 
 
 
-
-/****************************************************************************************
- * This function can be called by any thread running in any cluster. 
- * It allocates one fixed size block from a remote Kernel Cache Manager.
- ****************************************************************************************
- * @ kcm_cxy   : remote KCM cluster identifier.
- * @ order     :  ln( block-size ) == KCM allocator identifier.
- * @ return a local pointer on allocated block if success / return NULL if failure
- ***************************************************************************************/
-void * kcm_remote_alloc( cxy_t    kcm_cxy,
-                         uint32_t order );
-
-/****************************************************************************************
- * This function can be called by any thread running in any cluster. 
- * It releases a previouly allocated block to a remote Kernel Cache Manager.
- ****************************************************************************************
- * @ kcm_cxy     : remote KCM cluster identifier.
- * @ block_ptr   : local pointer on the released buffer in remote cluster.
- * @ order       : log2( block_size in bytes ).
- ***************************************************************************************/
-void kcm_remote_free( cxy_t     kcm_cxy,
-                      void    * block_ptr,
-                      uint32_t  order );
-
-/****************************************************************************************
- * This debug function can be called by any thread running in any cluster. It displays
- * on TXT0 the state of a KCM, identified by the <kcm_cxy> & <kcm_ptr> arguments.
- ****************************************************************************************
- * @ kcm_cxy : remote KCM cluster identifier.
- * @ kcm_ptr : local pointer on remote KCM.
- ***************************************************************************************/
-void kcm_remote_display( cxy_t   kcm_cxy,
-                         kcm_t * kcm_ptr );
-
 #endif	/* _KCM_H_ */
