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