Changeset 635 for trunk/kernel/mm/kcm.h
- Timestamp:
- Jun 26, 2019, 11:42:37 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/mm/kcm.h
r619 r635 1 1 /* 2 * kcm.h - Per-clusterKernel Cache Manager definition.2 * kcm.h - Kernel Cache Manager definition. 3 3 * 4 * Authors Ghassan Almaless (2008,2009,2010,2011,2012) 5 * Alain Greiner (2016,2017,2018) 4 * Authors Alain Greiner (2016,2017,2018,2019) 6 5 * 7 6 * Copyright (c) UPMC Sorbonne Universites … … 33 32 #include <kmem.h> 34 33 34 35 #define KCM_PAGE_FULL 0 36 #define KCM_PAGE_EMPTY 1 37 #define KCM_PAGE_ACTIVE 2 38 35 39 /**************************************************************************************** 36 40 * This structure defines a generic Kernel Cache Manager, that is a block allocator, 37 * for fixed size objects. It exists a specific KCM allocator for each object type. 38 * The actual allocated block size is the smallest multiple of the KCM slot, that 39 * contain one single object. The KCM slot is 64 bytes, as it must be large enough 40 * to store the kcm_page descriptor, defined below. 41 * The various KCM allocators themselves are not statically allocated in the cluster 42 * manager, but are dynamically allocated when required, using the embedded KCM 43 * allocator defined in the cluster manager, to allocate the other ones... 41 * for fixed size objects. It exists in each cluster a specific KCM allocator for 42 * the following block sizes: 64, 128, 256, 512, 1024, 2048 bytes. 43 * These six KCM allocators are initialized by the cluster_init() function. 44 * 45 * Each KCM cache is implemented as a set o 4 Kbytes pages. A kcm_page is split in slots, 46 * where each slot can contain one block. in each kcm_page, the first slot (that cannot 47 * be smaller than 64 bytes) contains the kcm page descriptor, defined below 48 * 49 * To allow any thread running in any cluster to directly access the KCM of any cluster, 50 * ALMOS-MKH defines two sets of access functions, for local or remote access. 44 51 ***************************************************************************************/ 45 52 46 53 typedef struct kcm_s 47 54 { 48 busylock_t lock; /*! protect KCM ammocator */ 49 uint32_t block_size; /*! rounded block size (bytes) */ 50 uint32_t blocks_nr; /*! max number of blocks per page */ 55 remote_busylock_t lock; /*! protect KCM allocator */ 51 56 57 list_entry_t full_root; /*! root of full pages list */ 52 58 list_entry_t active_root; /*! root of active pages list */ 53 list_entry_t busy_root; /*! root of busy pages list */54 list_entry_t free_root; /*! root of free pages list */55 59 56 uint32_t free_pages_nr; /*! number of free pages */ 57 uint32_t busy_pages_nr; /*! number of busy pages */ 60 uint32_t full_pages_nr; /*! number of busy pages */ 58 61 uint32_t active_pages_nr; /*! number of active pages */ 59 62 60 uint32_t type; /*! KCM type */ 63 uint32_t order; /*! ln( block_size ) */ 64 uint32_t max_blocks; /*! max number of blocks per page */ 61 65 } 62 66 kcm_t; … … 65 69 /**************************************************************************************** 66 70 * This structure defines a KCM-page descriptor. 67 * A KCM-page contains at most (CONFIG_PPM_PAGE_SIZE / CONFIG_KCM_SLOT_SIZE) blocks. 68 * This kcm page descriptor is stored in the first slot of the page. 71 * A KCM-page contains at most (CONFIG_PPM_PAGE_SIZE / CONFIG_KCM_SLOT_SIZE) slots, 72 * and each slot contains one block. The kcm page descriptor is stored in first slot. 73 * The current allocation status is defined by the 64 bits "status" bit vector: each 74 * non zero bit defines an allocated block / "counts is the number of allocated blocks. 75 * Each kcm_page is registered in one of the two following page_list: 76 * - full : when count == max 77 * - active : count < max 69 78 ***************************************************************************************/ 70 79 71 80 typedef struct kcm_page_s 72 81 { 73 uint32_t bitmap[2]; /*! at most 64 blocks in a single page */ 74 list_entry_t list; /*! [active / busy / free] list member */ 75 kcm_t * kcm; /*! pointer on kcm allocator */ 76 page_t * page; /*! pointer on the physical page descriptor */ 77 uint32_t count; /*! number of allocated blocks */ 78 uint32_t busy; /*! page busy if non zero */ 79 uint32_t active; /*! page active if non zero */ 82 uint64_t status; /*! bit vector: non-zero == allocated */ 83 uint32_t count; /*! number of allocated blocks in page */ 84 list_entry_t list; /*! [active / busy / free] list member */ 85 kcm_t * kcm; /*! pointer on kcm allocator */ 86 page_t * page; /*! pointer on the physical page descriptor */ 80 87 } 81 88 kcm_page_t; 82 89 83 90 /**************************************************************************************** 84 * This function initializes a generic Kernel Cache Manager. 91 * This function must be called by a local thread. 92 * It initializes a Kernel Cache Manager, depending on block size. 85 93 **************************************************************************************** 86 94 * @ kcm : pointer on KCM manager to initialize. 87 * @ type : KCM allocator type.95 * @ order : ln(block_size). 88 96 ***************************************************************************************/ 89 97 void kcm_init( kcm_t * kcm, 90 uint32_t type);98 uint32_t order ); 91 99 92 100 /**************************************************************************************** 93 * This function releases all memory allocated to a generic Kernel Cache Manager. 101 * This function must be called by a local thread. 102 * It releases all memory allocated to a Kernel Cache Manager. 94 103 **************************************************************************************** 95 104 * @ kcm : pointer on KCM manager to destroy. … … 98 107 99 108 /**************************************************************************************** 100 * This function allocates one single object from a Kernel Cache Manager101 * The object size must be smaller than one page size.109 * This function must be called by a local thread. 110 * It allocates one block from the local Kernel Cache Manager. 102 111 **************************************************************************************** 103 * @ kcm : pointer on the selected KCM allocator112 * @ order : ln( block-size ) == KCM allocator identifier. 104 113 * @ return pointer on allocated block if success / return NULL if failure 105 114 ***************************************************************************************/ 106 void * kcm_alloc( kcm_t * kcm);115 void * kcm_alloc( uint32_t order ); 107 116 108 117 /**************************************************************************************** 109 * This function releases a previouly allocated block containing one object. 118 * This function must be called by a local thread. 119 * It releases a previouly allocated block to the local Kernel Cache Manager. 110 120 **************************************************************************************** 111 * @ ptr : local pointer on the allocated buffer.121 * @ block_ptr : local pointer on the released block. 112 122 ***************************************************************************************/ 113 void kcm_free( void *ptr );123 void kcm_free( void * block_ptr ); 114 124 115 125 /**************************************************************************************** 116 * This function prints KCM allocator state (for debug only). 126 * This function can be called by any thread running in any cluster. 127 * It allocates one fixed size block from a remote Kernel Cache Manager. 117 128 **************************************************************************************** 118 * @ kcm : local pointer on the selected KCM allocator. 129 * @ kcm_cxy : remote KCM cluster identifier. 130 * @ order : ln( block-size ) == KCM allocator identifier. 131 * @ return a local pointer on allocated block if success / return NULL if failure 119 132 ***************************************************************************************/ 120 void kcm_print( kcm_t * kcm ); 133 void * kcm_remote_alloc( cxy_t kcm_cxy, 134 uint32_t order ); 135 136 /**************************************************************************************** 137 * This function can be called by any thread running in any cluster. 138 * It releases a previouly allocated block to a remote Kernel Cache Manager. 139 **************************************************************************************** 140 * @ kcm_cxy : remote KCM cluster identifier. 141 * @ block_ptr : local pointer on the released buffer in remote cluster. 142 ***************************************************************************************/ 143 void kcm_remote_free( cxy_t kcm_cxy, 144 void * block_ptr ); 145 146 /**************************************************************************************** 147 * This debug function can be called by any thread running in any cluster. 148 * It diplays on TXT0 the current state of a local KCM allocator. 149 **************************************************************************************** 150 * @ kcm_cxy : remote KCM cluster identifier. 151 * @ kcm_ptr : local pointer on remote KCM. 152 ***************************************************************************************/ 153 void kcm_remote_display( cxy_t kcm_cxy, 154 kcm_t * kcm_ptr ); 121 155 122 156 #endif /* _KCM_H_ */
Note: See TracChangeset
for help on using the changeset viewer.