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,2020) |
---|
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 flags. |
---|
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. |
---|
54 | * NOTE: the size is 48 bytes for a 32 bits core. |
---|
55 | ************************************************************************************/ |
---|
56 | |
---|
57 | typedef struct page_s |
---|
58 | { |
---|
59 | uint32_t flags; /*! flags defined above (4) */ |
---|
60 | uint32_t order; /*! log2( number of small pages) (4) */ |
---|
61 | struct mapper_s * mapper; /*! local pointer on associated mapper (4) */ |
---|
62 | uint32_t index; /*! page index in mapper (4) */ |
---|
63 | list_entry_t list; /*! for both dirty pages and free pages (8) */ |
---|
64 | int32_t refcount; /*! references counter for page release (4) */ |
---|
65 | uint32_t forks; /*! number of pending forks (4) */ |
---|
66 | remote_busylock_t lock; /*! protect forks or flags modifs (16) */ |
---|
67 | } |
---|
68 | page_t; |
---|
69 | |
---|
70 | /************************************************************************************* |
---|
71 | * This function must be called by a thread running in the local cluster. |
---|
72 | * It initializes the page descriptor. |
---|
73 | ************************************************************************************* |
---|
74 | * @ page : pointer to page descriptor |
---|
75 | ************************************************************************************/ |
---|
76 | inline void page_init( page_t * page ); |
---|
77 | |
---|
78 | /************************************************************************************* |
---|
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. |
---|
81 | ************************************************************************************* |
---|
82 | * @ page : pointer to page descriptor. |
---|
83 | * @ value : all non zero bits in value will be set. |
---|
84 | ************************************************************************************/ |
---|
85 | inline void page_set_flag( page_t * page, |
---|
86 | uint32_t value ); |
---|
87 | |
---|
88 | /************************************************************************************* |
---|
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. |
---|
91 | ************************************************************************************* |
---|
92 | * @ page : pointer to page descriptor. |
---|
93 | * @ value : all non zero bits in value will be cleared. |
---|
94 | ************************************************************************************/ |
---|
95 | inline void page_clear_flag( page_t * page, |
---|
96 | uint32_t value ); |
---|
97 | |
---|
98 | /************************************************************************************* |
---|
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. |
---|
101 | ************************************************************************************* |
---|
102 | * @ page : pointer to page descriptor. |
---|
103 | * @ value : all non zero bits will be tested. |
---|
104 | * @ returns true if at least one non zero bit in value is set / false otherwise. |
---|
105 | ************************************************************************************/ |
---|
106 | inline bool_t page_is_flag( page_t * page, |
---|
107 | uint32_t value ); |
---|
108 | |
---|
109 | /************************************************************************************* |
---|
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. |
---|
112 | ************************************************************************************* |
---|
113 | * @ page : pointer on page descriptor. |
---|
114 | ************************************************************************************/ |
---|
115 | void page_zero( page_t * page ); |
---|
116 | |
---|
117 | /************************************************************************************* |
---|
118 | * This function must be called by a thread running in the local cluster. |
---|
119 | * It atomically increments the page refcount. |
---|
120 | ************************************************************************************* |
---|
121 | * @ page : pointer on page descriptor. |
---|
122 | ************************************************************************************/ |
---|
123 | inline void page_refcount_up( page_t * page ); |
---|
124 | |
---|
125 | /************************************************************************************* |
---|
126 | * This function must be called by a thread running in the local cluster. |
---|
127 | * It atomically decrements the page refcount. |
---|
128 | ************************************************************************************* |
---|
129 | * @ page : pointer on page descriptor. |
---|
130 | ************************************************************************************/ |
---|
131 | inline void page_refcount_down( page_t * page ); |
---|
132 | |
---|
133 | |
---|
134 | |
---|
135 | |
---|
136 | |
---|
137 | /************************************************************************************* |
---|
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 | /************************************************************************************* |
---|
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. |
---|
149 | ************************************************************************************* |
---|
150 | * @ page_xp : extended pointer to page descriptor. |
---|
151 | * @ value : all non zero bits in value will be set. |
---|
152 | ************************************************************************************/ |
---|
153 | inline void page_remote_set_flag( xptr_t page_xp, |
---|
154 | uint32_t value ); |
---|
155 | |
---|
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 ); |
---|
166 | |
---|
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 | |
---|
205 | #endif /* _PAGE_H_ */ |
---|