Ignore:
Timestamp:
May 17, 2019, 9:27:04 AM (5 years ago)
Author:
alain
Message:

Remove the "giant" rwlock protecting the GPT, and
use the GPT_LOCKED attribute in each PTE to prevent
concurrent modifications of one GPT entry.
The version number has been incremented to 2.1.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/hal/generic/hal_gpt.h

    r625 r629  
    6161#define GPT_COW         0x0400       /*! PTE must be copied on write                   */
    6262#define GPT_SWAP        0x0800       /*! PTE swapped on disk (not implemented yet)     */
    63 #define GPT_LOCKED      0x1000       /*! PTE is protected against concurrent access    */
     63#define GPT_LOCKED      0x1000       /*! PTE is currently accessed by a thread         */
    6464
    6565/****************************************************************************************
     
    7676
    7777/****************************************************************************************
    78  * This function allocates physical memory for first level page table (PT1),
     78 * This function allocates physical memory for a local GPT,
    7979 * and initializes the GPT descriptor, creating an empty GPT.
    8080 ****************************************************************************************
     
    8787 * This function releases all memory dynamically allocated for a generic page table.
    8888 * For a multi-levels radix tree implementation, it includes all nodes in the tree.
    89  * If the calling thread is running in the reference cluster, it checks that user PTE
    90  * entries are unmapped, and releases the mapped physical pages.
    91  * The kernel pages are not released.
    9289 ****************************************************************************************
    9390 * @ gpt     : pointer on generic page table descriptor.
     
    9693
    9794/****************************************************************************************
    98  * This function prints on the kernel terminal the content of a generic page table.
    99  ****************************************************************************************
    100  * @ process : pointer on local process descriptor.
    101  ***************************************************************************************/
    102 void hal_gpt_display( struct process_s * process );
    103 
    104 /****************************************************************************************
    105  * This blocking function gets a lock on a PTE (Page Table Entry) identified
    106  * by its VPN, and returns only when the PTE has been successfully locked.
    107  * If the target PTE is not present, it allocates and maps a physical page.
    108  * A big page cannot be locked.
    109  ****************************************************************************************
    110  * @ gpt     : pointer on the generic page table
     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 * Then, it returns in the <attr> and <ppn> buffers the current value of the PTE.
     99 * It allocates memory required by the GPT implementation to register this lock
     100 * in the PTE when required.
     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
    111119 * @ vpn     : virtual page number of the target PTE.
    112  * @ returns 0 if success / return ENOMEM or EINVAL if error.
    113  ***************************************************************************************/
    114 error_t hal_gpt_lock_pte( gpt_t * gpt,
    115                           vpn_t   vpn );
    116 
    117 /****************************************************************************************
    118  * This function releases the lock on a PTE identified by its VPN.
    119  ****************************************************************************************
    120  * @ gpt     : pointer on the generic page table
    121  * @ vpn     : virtual page number of the target PTE.
    122  * @ returns 0 if success / returns EINVAL if error.
    123  ***************************************************************************************/
    124 error_t hal_gpt_unlock_pte( gpt_t * gpt,
    125                             vpn_t   vpn );
    126 
    127 /****************************************************************************************
    128  * This function maps in a - local or remote - GPT identified by the <gpt_xp> argument
    129  * an entry identified by the <vpn> argument, as defined by <ppn> and <attr> arguments.
    130  * It allocates physical memory for the GPT PT2, using a RPC_PMEM_GET_PAGES if required.
    131  ****************************************************************************************
    132  * @ gpt_xp    : [in] pointer on the page table
     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 accesses.
     131 ****************************************************************************************
     132 * @ gpt_xp    : [in] extended pointer on the page table
    133133 * @ vpn       : [in] virtual page number
    134  * @ attr      : [in] generic attributes
     134 * @ attr      : [in] GPT attributes
    135135 * @ ppn       : [in] physical page number
    136  * @ returns 0 if success / returns ENOMEM if error
    137  ***************************************************************************************/
    138 error_t hal_gpt_set_pte( xptr_t     gpt_xp,
    139                          vpn_t      vpn,
    140                          uint32_t   attr,
    141                          ppn_t      ppn );
    142 
    143 /****************************************************************************************
    144  * This function unmaps all pages identified by the <vpn> argument from the local GPT
    145  * identified by the <gpt> argument.
    146  * It does NOT release the physical memory allocated for the unmapped pages.
    147  ****************************************************************************************
    148  * @ gpt      : [in] pointer on the local page table
    149  * @ vpn      : [in] page index in virtual space
    150  ***************************************************************************************/
    151 void hal_gpt_reset_pte( gpt_t * gpt,
     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,
    152151                        vpn_t   vpn );
    153152
    154153/****************************************************************************************
    155  * This function returns in the <attr> and <ppn> arguments the current values stored
    156  * in a - local or remote - GPT entry, identified by the <gpt> and <vpn> arguments.
    157  ****************************************************************************************
    158  * @ gpt_xp    : [in]  extended pointer on the page table
    159  * @ vpn       : [in]  virtual page number
    160  * @ attr      : [out] generic attributes
    161  * @ ppn       : [out] physical page number
     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.
    162162 ***************************************************************************************/
    163163void hal_gpt_get_pte( xptr_t     gpt_xp,
     
    195195
    196196/****************************************************************************************
    197  * This function returns true if the MAPPED and SMALL flags are both set
    198  * for a PTE defined by <gpt> and <vpn> arguments.
    199  ****************************************************************************************
    200  * @ gpt       : [in]  pointer on the page table
    201  * @ vpn       : [in]  virtual page number
    202  * @ returns true if MAPPED is set.
    203  ***************************************************************************************/
    204 bool_t hal_gpt_pte_is_mapped( gpt_t * gpt,
    205                               vpn_t   vpn );
    206 
    207 /****************************************************************************************
    208  * This function returns true if the MAPPED, SMALL, and COW flags are all set
    209  * for a PTE defined by <gpt> and <vpn> arguments.
    210  ****************************************************************************************
    211  * @ gpt       : [in]  pointer on the page table
    212  * @ vpn       : [in]  virtual page number
    213  * @ returns true if COW is set.
    214  ***************************************************************************************/
    215 bool_t hal_gpt_pte_is_cow( gpt_t * gpt,
    216                            vpn_t   vpn );
    217 
    218 /****************************************************************************************
    219197 * This function atomically set the COW flag and reset the WRITABLE flag for all PTEs
    220198 * of a remote GPT identified by the <gpt_xp>, <vpn_base>, and <vpn_size arguments.
    221  * It does nothing if the remote PTE is not MAPPED and SMALL.
     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.
    222201 ****************************************************************************************
    223202 * @ gpt_xp    : [in]  extended pointer on the remote GPT.
     
    233212 * It modifies an existing entry identified by the <vpn> argument in a remote GPT
    234213 * identified by the <gpt_xp> argument, using remote accesses.
     214 * It does NOT require the GPT_LOCKED attribute to be set in the target PTE.
    235215 * It cannot fail, because only MAPPED & SMALL entries are modified.
    236216 ****************************************************************************************
Note: See TracChangeset for help on using the changeset viewer.