source: trunk/hal/generic/hal_gpt.h @ 635

Last change on this file since 635 was 635, checked in by alain, 5 years ago

This version is a major evolution: The physical memory allocators,
defined in the kmem.c, ppm.c, and kcm.c files have been modified
to support remote accesses. The RPCs that were previously user
to allocate physical memory in a remote cluster have been removed.
This has been done to cure a dead-lock in case of concurrent page-faults.

This version 2.2 has been tested on a (4 clusters / 2 cores per cluster)
TSAR architecture, for both the "sort" and the "fft" applications.

File size: 12.6 KB
Line 
1/*
2 * hal_gpt.h - Generic Page Table API definition.
3 *
4 * Authors  Alain Greiner (2016)
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 _GPT_H_
25#define _GPT_H_
26
27#include <hal_kernel_types.h>
28
29/////////////////////////////////////////////////////////////////////////////////////////
30//           Generic Page Table Definition (implementation in hal_gpt.c)
31//
32// It is specified as a simple (one dimensional) array indexed by the VPN (vpn_t type),
33// even if implementations can use a more sophisticated organisation (two-levels or more).
34// - The number of entries (number of pages in a virtual space) is architecture
35//   dependent, and is defined as (CONFIG_USER_SPACE_SIZE / CONFIG_PPM_PAGE_SIZE).
36// - Each entry contains a Physical Page Number (ppn_t type), and a set of attributes,
37//   defined as a 32 bits-vector.
38//
39// Any arch-specific implementation must implement this API.
40/////////////////////////////////////////////////////////////////////////////////////////
41
42/****  Forward declarations  ****/
43
44struct page_s;
45struct process_s;
46
47/****************************************************************************************
48 * These macros define the masks for the Generic Page Table Entry attributes.
49 ***************************************************************************************/
50
51#define GPT_MAPPED      0x0001       /*! PTE is mapped                                 */
52#define GPT_SMALL       0x0002       /*! PTE is a small page                           */
53#define GPT_READABLE    0x0004       /*! PTE is readable                               */
54#define GPT_WRITABLE    0x0008       /*! PTE is writable                               */
55#define GPT_EXECUTABLE  0x0010       /*! PTE is executable                             */
56#define GPT_CACHABLE    0x0020       /*! PTE can be cached                             */
57#define GPT_USER        0x0040       /*! PTE is user accessible                        */
58#define GPT_DIRTY       0x0080       /*! PTE has been written                          */
59#define GPT_ACCESSED    0x0100       /*! PTE has been "recently" accessed              */
60#define GPT_GLOBAL      0x0200       /*! PTE is kept in TLB at context switch          */
61#define GPT_COW         0x0400       /*! PTE must be copied on write                   */
62#define GPT_SWAP        0x0800       /*! PTE swapped on disk (not implemented yet)     */
63#define GPT_LOCKED      0x1000       /*! PTE is currently accessed by a thread         */
64
65/****************************************************************************************
66 * This structure defines the Generic Page Table descriptor.
67 ***************************************************************************************/
68
69typedef struct gpt_s
70{
71        void           * ptr;    /*! local pointer on GPT root                             */
72        ppn_t            ppn;    /*! PPN of GPT root                                       */
73}
74gpt_t;
75
76
77/****************************************************************************************
78 * This function allocates physical memory for a local GPT,
79 * and initializes the GPT descriptor, creating an empty GPT.
80 ****************************************************************************************
81 * @ gpt     : pointer on generic page table descriptor.
82 * @ returns 0 if success / returns ENOMEM if error.
83 ***************************************************************************************/
84error_t hal_gpt_create( gpt_t * gpt );
85
86/****************************************************************************************
87 * This function releases all memory dynamically allocated for a generic page table.
88 * For a multi-levels radix tree implementation, it includes all nodes in the tree.
89 ****************************************************************************************
90 * @ gpt     : pointer on generic page table descriptor.
91 ***************************************************************************************/
92void hal_gpt_destroy( gpt_t * gpt);
93
94/****************************************************************************************
95 * This blocking function atomically set the GPT_LOCKED attribute in a target PTE
96 * of a remote GPT identified by the <gpt_xp> and <vpn> arguments, after checking
97 * (in a busy waiting loop) that this attribute has been reset.
98 * It returns in the <attr> and <ppn> buffers the value of the PTE before modification.
99 * It atomically allocates memory  to register this attribute in the PTE when
100 * required by a specific GPT implementation (example : allocate a PT2 in the TSAR GPT).
101 * WARNING : Only small pages can be locked.
102 ****************************************************************************************
103 * @ gpt_xp  : [in]  extended pointer on the generic page table.
104 * @ vpn     : [in]  virtual page number of the target PTE.
105 * @ attr    : [out] local buffer for GPT attributes.
106 * @ ppn     : [out] local buffer for physical page number.
107 * @ returns 0 if success / return -1 if error (no memory or big page).
108 ***************************************************************************************/
109error_t hal_gpt_lock_pte( xptr_t     gpt_xp,
110                          vpn_t      vpn,
111                          uint32_t * attr,
112                          ppn_t    * ppn );
113
114/****************************************************************************************
115 * This function atomically reset the GPT_LOCKED attribute in a target PTE in a
116 * remote GPT identified by the <gpt_xp> and <vpn> arguments.
117 ****************************************************************************************
118 * @ gpt_xp  : pointer on the generic page table
119 * @ vpn     : virtual page number of the target PTE.
120 ***************************************************************************************/
121void hal_gpt_unlock_pte( xptr_t  gpt_xp,
122                         vpn_t   vpn );
123
124/****************************************************************************************
125 * This low level function maps a new PTE or modifies an existing PTE in a remote GPT
126 * identified by the <gpt_xp> and <vpn> arguments, as defined by <ppn> and <attr> args.
127 * This function can be used for both a small page (PTE2), and a big page (PTE1).
128 *
129 * WARNING : For a small page, it checks that the GPT_LOCKED attribute has been
130 *           previously set, to prevent concurrent mapping accesses.
131 ****************************************************************************************
132 * @ gpt_xp    : [in] extended pointer on the page table
133 * @ vpn       : [in] virtual page number
134 * @ attr      : [in] GPT attributes
135 * @ ppn       : [in] physical page number
136 ***************************************************************************************/
137void hal_gpt_set_pte( xptr_t     gpt_xp,
138                      vpn_t      vpn,
139                      uint32_t   attr,
140                      ppn_t      ppn );
141
142/****************************************************************************************
143 * This low level function unmaps and unlocks a PTE from a remote GPT identified by the
144 * <gpt_xp> and <vpn> arguments. It does NOT release the allocated physical memory.
145 * This function can be used for both a small page (PTE2), and a big page (PTE1).
146 ****************************************************************************************
147 * @ gpt_xp   : [in] extended pointer on the page table
148 * @ vpn      : [in] virtual page number.
149 ***************************************************************************************/
150void hal_gpt_reset_pte( xptr_t  gpt_xp,
151                        vpn_t   vpn );
152
153/****************************************************************************************
154 * This low level function returns in the <attr> and <ppn> arguments the current values
155 * of a PTE in a a remote GPT, identified by the <gpt> and <vpn> arguments.
156 * This function can be used for both a small page (PTE2), and a big page (PTE1).
157 ****************************************************************************************
158 * @ gpt_xp    : [in]  extended pointer on the page table.
159 * @ vpn       : [in]  virtual page number.
160 * @ attr      : [out] local buffer for generic attributes.
161 * @ ppn       : [out] local buffer for physical page number.
162 ***************************************************************************************/
163void hal_gpt_get_pte( xptr_t     gpt_xp,
164                      vpn_t      vpn,
165                      uint32_t * attr,
166                      ppn_t    * ppn );
167
168/****************************************************************************************
169 * This function is used to implement the "fork" system call: It copies a remote
170 * source PTE, identified by the <src_gpt_xp> and <src_vpn> arguments, to a local
171 * destination PTE, identified by the <dst_gpt> and <dst_vpn> arguments.
172 * It does nothing if the source PTE is not MAPPED and SMALL.
173 * It optionnally activates the "Copy on Write" mechanism: when the <cow> argument is
174 * true: the GPT_WRITABLE flag is reset, and the GPT_COW flag is set.
175 * A new second level PT2 is allocated for the destination GPT if required.
176 * It returns in the <ppn> and <mapped> arguments the PPN value for the copied PTE,
177 * and a boolean indicating if the PTE is mapped and small, and was actually copied.
178 ****************************************************************************************
179 * @ dst_gpt      : [in]  local pointer on local destination GPT.
180 * @ dst_vpn      : [in]  vpn defining the PTE in the desination GPT.
181 * @ src_gpt_xp   : [in]  extended pointer on remote source GPT.
182 * @ src_vpn      : [in]  vpn defining the PTE in the source GPT.
183 * @ cow          : [in]  set COW flag & reset WRITABLE flag if true.
184 * @ ppn          : [out] PPN value (only if mapped is true).
185 * @ mapped       : [out] true if src_gpt[vpn] actually copied to dst_gpt[vpn].
186 * @ return 0 if success / return -1 if no memory for a new PT2.
187 ***************************************************************************************/
188error_t hal_gpt_pte_copy( gpt_t    * dst_gpt,
189                          vpn_t      dst_vpn,
190                          xptr_t     src_gpt_xp,
191                          vpn_t      src_vpn,
192                          bool_t     cow,
193                          ppn_t    * ppn,
194                          bool_t   * mapped );
195
196/****************************************************************************************
197 * This function atomically set the COW flag and reset the WRITABLE flag for all PTEs
198 * of a remote GPT identified by the <gpt_xp>, <vpn_base>, and <vpn_size arguments.
199 * It does NOT require the GPT_LOCKED attribute to be set in the target PTE.
200 * It does nothing if the PTE is not MAPPED and SMALL.
201 ****************************************************************************************
202 * @ gpt_xp    : [in]  extended pointer on the remote GPT.
203 * @ vpn_base  : [in]  first virtual page.
204 * @ vpn_size  : [in]  number of pages.
205 ***************************************************************************************/
206void hal_gpt_set_cow( xptr_t  gpt_xp,
207                      vpn_t   vpn_base,
208                      vpn_t   vpn_size );
209
210/****************************************************************************************
211 * This function is used to maintain coherence amongst the multiple GPT copies.
212 * It modifies an existing entry identified by the <vpn> argument in a remote GPT
213 * identified by the <gpt_xp> argument, using remote accesses.
214 * - The MAPPED and SMALL attributes must be set, and the LOCKED attibute must be reset
215 *   in the <attr> argument.
216 * - The MAPPED and SMALL attributes must be set in the target PTE.
217 ****************************************************************************************
218 * @ gpt_xp    : [in] extended pointer on the page table
219 * @ vpn       : [in] virtual page number
220 * @ attr      : [in] generic attributes
221 * @ ppn       : [in] physical page number
222 ***************************************************************************************/
223void hal_gpt_update_pte( xptr_t     gpt_xp,
224                         vpn_t      vpn,
225                         uint32_t   attr,
226                         ppn_t      ppn );
227
228
229#endif  /* _GPT_H_ */
230
Note: See TracBrowser for help on using the repository browser.