[1] | 1 | /* |
---|
| 2 | * page.h - physical page descriptor and related operations |
---|
| 3 | * |
---|
| 4 | * Authors Ghassan Almalles (2008,2009,2010,2011,2012) |
---|
[632] | 5 | * Alain Greiner (2016,2017,2018,2019) |
---|
[1] | 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 _PAGE_H_ |
---|
| 26 | #define _PAGE_H_ |
---|
| 27 | |
---|
[14] | 28 | #include <kernel_config.h> |
---|
[457] | 29 | #include <hal_kernel_types.h> |
---|
[567] | 30 | #include <remote_busylock.h> |
---|
[1] | 31 | #include <list.h> |
---|
| 32 | |
---|
| 33 | /*** Forward declarations ***/ |
---|
| 34 | |
---|
| 35 | struct mapper_s; |
---|
[18] | 36 | |
---|
[1] | 37 | /************************************************************************************* |
---|
| 38 | * This defines the flags that can be attached to a physical page. |
---|
| 39 | ************************************************************************************/ |
---|
| 40 | |
---|
| 41 | #define PG_INIT 0x0001 // page descriptor has been initialised |
---|
| 42 | #define PG_RESERVED 0x0002 // cannot be allocated by PPM |
---|
[623] | 43 | #define PG_FREE 0x0004 // page not yet allocated by PPM |
---|
[1] | 44 | #define PG_DIRTY 0x0040 // page has been written |
---|
[567] | 45 | #define PG_COW 0x0080 // page is copy-on-write |
---|
[1] | 46 | |
---|
| 47 | /************************************************************************************* |
---|
| 48 | * This structure defines a physical page descriptor. |
---|
[606] | 49 | * - The remote_busylock is used to allows any remote thread to atomically |
---|
[635] | 50 | * test/modify the forks counter or the flags. |
---|
[656] | 51 | * - The list field is used to register the page in a free list, or in dirty list, |
---|
| 52 | * as a given page cannot be simultaneously dirty and free. |
---|
| 53 | * - The refcount is used to release the page to the PPM. |
---|
[625] | 54 | * NOTE: the size is 48 bytes for a 32 bits core. |
---|
[1] | 55 | ************************************************************************************/ |
---|
| 56 | |
---|
| 57 | typedef struct page_s |
---|
| 58 | { |
---|
[23] | 59 | uint32_t flags; /*! flags defined above (4) */ |
---|
[68] | 60 | uint32_t order; /*! log2( number of small pages) (4) */ |
---|
[1] | 61 | struct mapper_s * mapper; /*! local pointer on associated mapper (4) */ |
---|
| 62 | uint32_t index; /*! page index in mapper (4) */ |
---|
[18] | 63 | list_entry_t list; /*! for both dirty pages and free pages (8) */ |
---|
[625] | 64 | int32_t refcount; /*! references counter for page release (4) */ |
---|
[433] | 65 | uint32_t forks; /*! number of pending forks (4) */ |
---|
[606] | 66 | remote_busylock_t lock; /*! protect forks or flags modifs (16) */ |
---|
[1] | 67 | } |
---|
| 68 | page_t; |
---|
| 69 | |
---|
| 70 | /************************************************************************************* |
---|
[632] | 71 | * This function must be called by a thread running in the local cluster. |
---|
| 72 | * It initializes the page descriptor. |
---|
[23] | 73 | ************************************************************************************* |
---|
[1] | 74 | * @ page : pointer to page descriptor |
---|
| 75 | ************************************************************************************/ |
---|
| 76 | inline void page_init( page_t * page ); |
---|
| 77 | |
---|
| 78 | /************************************************************************************* |
---|
[632] | 79 | * This function must be called by a thread running in the local cluster. |
---|
| 80 | * It atomically set one or several flags in page descriptor flags. |
---|
[23] | 81 | ************************************************************************************* |
---|
[1] | 82 | * @ page : pointer to page descriptor. |
---|
[18] | 83 | * @ value : all non zero bits in value will be set. |
---|
[1] | 84 | ************************************************************************************/ |
---|
| 85 | inline void page_set_flag( page_t * page, |
---|
[23] | 86 | uint32_t value ); |
---|
[1] | 87 | |
---|
| 88 | /************************************************************************************* |
---|
[632] | 89 | * This function must be called by a thread running in the local cluster. |
---|
| 90 | * It atomically reset one or several flags in page descriptor flags. |
---|
[23] | 91 | ************************************************************************************* |
---|
[1] | 92 | * @ page : pointer to page descriptor. |
---|
[18] | 93 | * @ value : all non zero bits in value will be cleared. |
---|
[1] | 94 | ************************************************************************************/ |
---|
| 95 | inline void page_clear_flag( page_t * page, |
---|
[23] | 96 | uint32_t value ); |
---|
[1] | 97 | |
---|
| 98 | /************************************************************************************* |
---|
[632] | 99 | * This function must be called by a thread running in the local cluster. |
---|
| 100 | * It tests the value of one or several flags in page descriptor flags. |
---|
[23] | 101 | ************************************************************************************* |
---|
[1] | 102 | * @ page : pointer to page descriptor. |
---|
| 103 | * @ value : all non zero bits will be tested. |
---|
[18] | 104 | * @ returns true if at least one non zero bit in value is set / false otherwise. |
---|
[1] | 105 | ************************************************************************************/ |
---|
| 106 | inline bool_t page_is_flag( page_t * page, |
---|
[23] | 107 | uint32_t value ); |
---|
[1] | 108 | |
---|
| 109 | /************************************************************************************* |
---|
[632] | 110 | * This function must be called by a thread running in the local cluster. |
---|
| 111 | * It resets to 0 all bytes in a given page. |
---|
[23] | 112 | ************************************************************************************* |
---|
[1] | 113 | * @ page : pointer on page descriptor. |
---|
| 114 | ************************************************************************************/ |
---|
| 115 | void page_zero( page_t * page ); |
---|
| 116 | |
---|
| 117 | /************************************************************************************* |
---|
[632] | 118 | * This function must be called by a thread running in the local cluster. |
---|
| 119 | * It atomically increments the page refcount. |
---|
[23] | 120 | ************************************************************************************* |
---|
[1] | 121 | * @ page : pointer on page descriptor. |
---|
| 122 | ************************************************************************************/ |
---|
| 123 | inline void page_refcount_up( page_t * page ); |
---|
| 124 | |
---|
| 125 | /************************************************************************************* |
---|
[632] | 126 | * This function must be called by a thread running in the local cluster. |
---|
| 127 | * It atomically decrements the page refcount. |
---|
[23] | 128 | ************************************************************************************* |
---|
[1] | 129 | * @ page : pointer on page descriptor. |
---|
| 130 | ************************************************************************************/ |
---|
| 131 | inline void page_refcount_down( page_t * page ); |
---|
| 132 | |
---|
[632] | 133 | |
---|
| 134 | |
---|
| 135 | |
---|
[635] | 136 | |
---|
[1] | 137 | /************************************************************************************* |
---|
[635] | 138 | * This function must be called by a thread running in the local cluster. |
---|
| 139 | * It initializes the page descriptor. |
---|
| 140 | ************************************************************************************* |
---|
| 141 | * @ page_xp : extended pointer to page descriptor. |
---|
| 142 | ************************************************************************************/ |
---|
| 143 | inline void page_remote_init( xptr_t page_xp ); |
---|
| 144 | |
---|
| 145 | /************************************************************************************* |
---|
[632] | 146 | * This function can be called by any thread running in any cluster. |
---|
| 147 | * It atomically set one or several flags in a remote page descriptor |
---|
| 148 | * identified by the <page_xp> argument. |
---|
[23] | 149 | ************************************************************************************* |
---|
[632] | 150 | * @ page_xp : extended pointer to page descriptor. |
---|
| 151 | * @ value : all non zero bits in value will be set. |
---|
[1] | 152 | ************************************************************************************/ |
---|
[632] | 153 | inline void page_remote_set_flag( xptr_t page_xp, |
---|
| 154 | uint32_t value ); |
---|
[1] | 155 | |
---|
[632] | 156 | /************************************************************************************* |
---|
| 157 | * This function can be called by any thread running in any cluster. |
---|
| 158 | * It atomically reset one or several flags in a remote page descriptor |
---|
| 159 | * identified by the <page_xp> argument. |
---|
| 160 | ************************************************************************************* |
---|
| 161 | * @ page_xp : extended pointer to page descriptor. |
---|
| 162 | * @ value : all non zero bits in value will be cleared. |
---|
| 163 | ************************************************************************************/ |
---|
| 164 | inline void page_remote_clear_flag( xptr_t page_xp, |
---|
| 165 | uint32_t value ); |
---|
[1] | 166 | |
---|
[632] | 167 | /************************************************************************************* |
---|
| 168 | * This function can be called by any thread running in any cluster. |
---|
| 169 | * It tests the value of one or several flags in a remote page descriptor |
---|
| 170 | * identified by the <page_xp> argument. |
---|
| 171 | ************************************************************************************* |
---|
| 172 | * @ page_xp : extended pointer to page descriptor. |
---|
| 173 | * @ value : all non zero bits will be tested. |
---|
| 174 | * @ returns true if at least one non zero bit in value is set / false otherwise. |
---|
| 175 | ************************************************************************************/ |
---|
| 176 | inline bool_t page_remote_is_flag( xptr_t page_xp, |
---|
| 177 | uint32_t value ); |
---|
| 178 | |
---|
| 179 | /************************************************************************************* |
---|
| 180 | * This function can be called by any thread running in any cluster. |
---|
| 181 | * It atomically increments the refcount for the remote page identified by |
---|
| 182 | * the <page_xp> argument. |
---|
| 183 | ************************************************************************************* |
---|
| 184 | * @ page_xp : extended pointer on page descriptor. |
---|
| 185 | ************************************************************************************/ |
---|
| 186 | inline void page_remote_refcount_up( xptr_t page_xp ); |
---|
| 187 | |
---|
| 188 | /************************************************************************************* |
---|
| 189 | * This function can be called by any thread running in any cluster. |
---|
| 190 | * It atomically decrements the refcount for the remote page identified by |
---|
| 191 | * the <page_xp> argument. |
---|
| 192 | ************************************************************************************* |
---|
| 193 | * @ page_xp : extended pointer on page descriptor. |
---|
| 194 | ************************************************************************************/ |
---|
| 195 | inline void page_remote_refcount_down( xptr_t page_xp ); |
---|
| 196 | |
---|
| 197 | /************************************************************************************* |
---|
| 198 | * This debug function can be called by any thread running in any cluster. |
---|
| 199 | * It displays the values contained in a page descriptor. |
---|
| 200 | ************************************************************************************* |
---|
| 201 | * @ page_xp : extended pointer on page descriptor. |
---|
| 202 | ************************************************************************************/ |
---|
| 203 | void page_remote_display( xptr_t page_xp ); |
---|
| 204 | |
---|
[1] | 205 | #endif /* _PAGE_H_ */ |
---|