[1] | 1 | /* |
---|
[635] | 2 | * kcm.h - Kernel Cache Manager definition. |
---|
[1] | 3 | * |
---|
[635] | 4 | * Authors Alain Greiner (2016,2017,2018,2019) |
---|
[1] | 5 | * |
---|
| 6 | * Copyright (c) UPMC Sorbonne Universites |
---|
| 7 | * |
---|
| 8 | * This file is part of ALMOS-MKH. |
---|
| 9 | * |
---|
| 10 | * ALMOS-MKH is free software; you can redistribute it and/or modify it |
---|
| 11 | * under the terms of the GNU General Public License as published by |
---|
| 12 | * the Free Software Foundation; version 2.0 of the License. |
---|
| 13 | * |
---|
| 14 | * ALMOS-MKH is distributed in the hope that it will be useful, but |
---|
| 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
| 17 | * General Public License for more details. |
---|
| 18 | * |
---|
| 19 | * You should have received a copy of the GNU General Public License |
---|
| 20 | * along with ALMOS-MKH; if not, write to the Free Software Foundation, |
---|
| 21 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
| 22 | */ |
---|
| 23 | |
---|
| 24 | #ifndef _KCM_H_ |
---|
| 25 | #define _KCM_H_ |
---|
| 26 | |
---|
| 27 | #include <list.h> |
---|
[457] | 28 | #include <hal_kernel_types.h> |
---|
[567] | 29 | #include <busylock.h> |
---|
[1] | 30 | #include <page.h> |
---|
| 31 | #include <bits.h> |
---|
| 32 | #include <kmem.h> |
---|
| 33 | |
---|
[635] | 34 | |
---|
| 35 | #define KCM_PAGE_FULL 0 |
---|
| 36 | #define KCM_PAGE_EMPTY 1 |
---|
| 37 | #define KCM_PAGE_ACTIVE 2 |
---|
| 38 | |
---|
[1] | 39 | /**************************************************************************************** |
---|
| 40 | * This structure defines a generic Kernel Cache Manager, that is a block allocator, |
---|
[635] | 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. |
---|
[1] | 51 | ***************************************************************************************/ |
---|
| 52 | |
---|
[18] | 53 | typedef struct kcm_s |
---|
[1] | 54 | { |
---|
[635] | 55 | remote_busylock_t lock; /*! protect KCM allocator */ |
---|
[1] | 56 | |
---|
[635] | 57 | list_entry_t full_root; /*! root of full pages list */ |
---|
[1] | 58 | list_entry_t active_root; /*! root of active pages list */ |
---|
| 59 | |
---|
[635] | 60 | uint32_t full_pages_nr; /*! number of busy pages */ |
---|
[1] | 61 | uint32_t active_pages_nr; /*! number of active pages */ |
---|
| 62 | |
---|
[635] | 63 | uint32_t order; /*! ln( block_size ) */ |
---|
| 64 | uint32_t max_blocks; /*! max number of blocks per page */ |
---|
[18] | 65 | } |
---|
[1] | 66 | kcm_t; |
---|
| 67 | |
---|
| 68 | |
---|
| 69 | /**************************************************************************************** |
---|
| 70 | * This structure defines a KCM-page descriptor. |
---|
[635] | 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 |
---|
[1] | 78 | ***************************************************************************************/ |
---|
| 79 | |
---|
| 80 | typedef struct kcm_page_s |
---|
| 81 | { |
---|
[635] | 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 */ |
---|
[18] | 87 | } |
---|
[1] | 88 | kcm_page_t; |
---|
| 89 | |
---|
| 90 | /**************************************************************************************** |
---|
[635] | 91 | * This function must be called by a local thread. |
---|
| 92 | * It initializes a Kernel Cache Manager, depending on block size. |
---|
[1] | 93 | **************************************************************************************** |
---|
| 94 | * @ kcm : pointer on KCM manager to initialize. |
---|
[635] | 95 | * @ order : ln(block_size). |
---|
[1] | 96 | ***************************************************************************************/ |
---|
[7] | 97 | void kcm_init( kcm_t * kcm, |
---|
[635] | 98 | uint32_t order ); |
---|
[1] | 99 | |
---|
| 100 | /**************************************************************************************** |
---|
[635] | 101 | * This function must be called by a local thread. |
---|
| 102 | * It releases all memory allocated to a Kernel Cache Manager. |
---|
[1] | 103 | **************************************************************************************** |
---|
| 104 | * @ kcm : pointer on KCM manager to destroy. |
---|
| 105 | ***************************************************************************************/ |
---|
[7] | 106 | void kcm_destroy( kcm_t * kcm ); |
---|
[1] | 107 | |
---|
| 108 | /**************************************************************************************** |
---|
[635] | 109 | * This function must be called by a local thread. |
---|
| 110 | * It allocates one block from the local Kernel Cache Manager. |
---|
[1] | 111 | **************************************************************************************** |
---|
[635] | 112 | * @ order : ln( block-size ) == KCM allocator identifier. |
---|
[7] | 113 | * @ return pointer on allocated block if success / return NULL if failure |
---|
[1] | 114 | ***************************************************************************************/ |
---|
[635] | 115 | void * kcm_alloc( uint32_t order ); |
---|
[1] | 116 | |
---|
| 117 | /**************************************************************************************** |
---|
[635] | 118 | * This function must be called by a local thread. |
---|
| 119 | * It releases a previouly allocated block to the local Kernel Cache Manager. |
---|
[1] | 120 | **************************************************************************************** |
---|
[635] | 121 | * @ block_ptr : local pointer on the released block. |
---|
[1] | 122 | ***************************************************************************************/ |
---|
[635] | 123 | void kcm_free( void * block_ptr ); |
---|
[1] | 124 | |
---|
| 125 | /**************************************************************************************** |
---|
[635] | 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. |
---|
[1] | 128 | **************************************************************************************** |
---|
[635] | 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 |
---|
[1] | 132 | ***************************************************************************************/ |
---|
[635] | 133 | void * kcm_remote_alloc( cxy_t kcm_cxy, |
---|
| 134 | uint32_t order ); |
---|
[1] | 135 | |
---|
[635] | 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 ); |
---|
| 155 | |
---|
[1] | 156 | #endif /* _KCM_H_ */ |
---|