[1] | 1 | /* |
---|
| 2 | * kcm.h - Per-cluster Kernel Cache Manager Interface |
---|
| 3 | * |
---|
| 4 | * Authors Ghassan Almaless (2008,2009,2010,2011,2012) |
---|
| 5 | * Alain Greiner (2016) |
---|
| 6 | * |
---|
| 7 | * Copyright (c) UPMC Sorbonne Universites |
---|
| 8 | * |
---|
| 9 | * This file is part of ALMOS-MKH. |
---|
| 10 | * |
---|
| 11 | * ALMOS-MKH is free software; you can redistribute it and/or modify it |
---|
| 12 | * under the terms of the GNU General Public License as published by |
---|
| 13 | * the Free Software Foundation; version 2.0 of the License. |
---|
| 14 | * |
---|
| 15 | * ALMOS-MKH is distributed in the hope that it will be useful, but |
---|
| 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
| 18 | * General Public License for more details. |
---|
| 19 | * |
---|
| 20 | * You should have received a copy of the GNU General Public License |
---|
| 21 | * along with ALMOS-MKH; if not, write to the Free Software Foundation, |
---|
| 22 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
| 23 | */ |
---|
| 24 | |
---|
| 25 | #ifndef _KCM_H_ |
---|
| 26 | #define _KCM_H_ |
---|
| 27 | |
---|
| 28 | #include <list.h> |
---|
| 29 | #include <hal_types.h> |
---|
| 30 | #include <spinlock.h> |
---|
| 31 | #include <page.h> |
---|
| 32 | #include <bits.h> |
---|
| 33 | #include <kmem.h> |
---|
| 34 | |
---|
| 35 | /**************************************************************************************** |
---|
| 36 | * 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 64 bytes that can |
---|
| 39 | * contain one single object. |
---|
| 40 | * The various KCM allocators themselves are not statically allocated in the cluster |
---|
[18] | 41 | * manager, but are dynamically allocated when required, using the embedded KCM |
---|
[1] | 42 | * allocator defined in the cluster manager, to allocate the other ones... |
---|
| 43 | ***************************************************************************************/ |
---|
| 44 | |
---|
[18] | 45 | typedef struct kcm_s |
---|
[1] | 46 | { |
---|
| 47 | spinlock_t lock; /*! protect exclusive access to allocator */ |
---|
| 48 | uint32_t block_size; /*! actual block size (bytes) */ |
---|
| 49 | uint32_t blocks_nr; /*! number of blocks per page */ |
---|
| 50 | |
---|
| 51 | list_entry_t active_root; /*! root of active pages list */ |
---|
| 52 | list_entry_t busy_root; /*! root of busy pages list */ |
---|
| 53 | list_entry_t free_root; /*! root of free pages list */ |
---|
| 54 | |
---|
| 55 | uint32_t free_pages_nr; /*! number of free pages */ |
---|
| 56 | uint32_t busy_pages_nr; /*! number of busy pages */ |
---|
| 57 | uint32_t active_pages_nr; /*! number of active pages */ |
---|
| 58 | |
---|
| 59 | uint32_t type; /*! KCM type */ |
---|
[18] | 60 | } |
---|
[1] | 61 | kcm_t; |
---|
| 62 | |
---|
| 63 | |
---|
| 64 | /**************************************************************************************** |
---|
| 65 | * This structure defines a KCM-page descriptor. |
---|
[7] | 66 | * A KCM-page can contain up to (CONFIG_PPM_PAGE_SIZE / CONFIG_CACHE_LINE_SIZE) blocks. |
---|
| 67 | * This kcm page descriptor is stored in the first slot of the page. |
---|
[1] | 68 | ***************************************************************************************/ |
---|
| 69 | |
---|
| 70 | typedef struct kcm_page_s |
---|
| 71 | { |
---|
[23] | 72 | uint32_t bitmap[BITMAP_SIZE(CONFIG_KCM_BLOCKS_MAX)]; |
---|
[7] | 73 | uint8_t * base; /*! pointer on first block in page */ |
---|
[1] | 74 | kcm_t * kcm; /*! owner KCM allocator */ |
---|
[7] | 75 | list_entry_t list; /*! [active / busy / free] list member */ |
---|
| 76 | page_t * page; /*! pointer on the physical page descriptor */ |
---|
[1] | 77 | uint8_t refcount; /*! number of allocated blocks */ |
---|
| 78 | uint8_t busy; /*! page busy if non zero */ |
---|
| 79 | uint8_t active; /*! page active if non zero */ |
---|
[7] | 80 | uint8_t unused; /*! */ |
---|
[18] | 81 | } |
---|
[1] | 82 | kcm_page_t; |
---|
| 83 | |
---|
| 84 | /**************************************************************************************** |
---|
[18] | 85 | * This function initializes a generic Kernel Cache Manager. |
---|
[1] | 86 | **************************************************************************************** |
---|
| 87 | * @ kcm : pointer on KCM manager to initialize. |
---|
| 88 | * @ type : KCM allocator type. |
---|
| 89 | ***************************************************************************************/ |
---|
[7] | 90 | void kcm_init( kcm_t * kcm, |
---|
| 91 | uint32_t type ); |
---|
[1] | 92 | |
---|
| 93 | /**************************************************************************************** |
---|
[18] | 94 | * This function releases all memory allocated to a generic Kernel Cache Manager. |
---|
[1] | 95 | **************************************************************************************** |
---|
| 96 | * @ kcm : pointer on KCM manager to destroy. |
---|
| 97 | ***************************************************************************************/ |
---|
[7] | 98 | void kcm_destroy( kcm_t * kcm ); |
---|
[1] | 99 | |
---|
| 100 | /**************************************************************************************** |
---|
[18] | 101 | * This function allocates one single object in a Kernel Cache Manager |
---|
[1] | 102 | * The object size must be smaller than one page size. |
---|
| 103 | **************************************************************************************** |
---|
[7] | 104 | * @ kcm : pointer on the selected KCM allocator |
---|
| 105 | * @ return pointer on allocated block if success / return NULL if failure |
---|
[1] | 106 | ***************************************************************************************/ |
---|
| 107 | void * kcm_alloc( kcm_t * kcm ); |
---|
| 108 | |
---|
| 109 | /**************************************************************************************** |
---|
| 110 | * This function releases a previouly allocated block containing one object. |
---|
| 111 | **************************************************************************************** |
---|
| 112 | * @ ptr : local pointer on the allocated buffer. |
---|
| 113 | ***************************************************************************************/ |
---|
| 114 | void kcm_free( void * ptr ); |
---|
| 115 | |
---|
| 116 | /**************************************************************************************** |
---|
| 117 | * This function prints KCM allocator state (for debug only). |
---|
| 118 | **************************************************************************************** |
---|
| 119 | * @ kcm : local pointer on the selected KCM allocator. |
---|
| 120 | ***************************************************************************************/ |
---|
| 121 | void kcm_print( kcm_t * kcm ); |
---|
| 122 | |
---|
| 123 | |
---|
| 124 | |
---|
| 125 | #endif /* _KCM_H_ */ |
---|