Changeset 409 for trunk/kernel/mm
- Timestamp:
- Dec 20, 2017, 4:51:09 PM (7 years ago)
- Location:
- trunk/kernel/mm
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/mm/ppm.h
r407 r409 34 34 35 35 /***************************************************************************************** 36 * This structure defines the Physical MemoryManager in a cluster.37 * In all clusters, the physical memory bank starts at local physical address 0.38 * The size of this local physical memoryis defined by the <pages_nr> field in the36 * This structure defines the Physical Pages Manager in a cluster. 37 * In each cluster, the physical memory bank starts at local physical address 0 and 38 * contains an integer number of pages, is defined by the <pages_nr> field in the 39 39 * boot_info structure. It is split in three parts: 40 40 * - the "kernel_code" section contains the kernel code, loaded by the boot-loader. -
trunk/kernel/mm/vmm.c
r408 r409 28 28 #include <hal_special.h> 29 29 #include <hal_gpt.h> 30 #include <hal_vmm.h> 30 31 #include <printk.h> 31 32 #include <memcpy.h> … … 83 84 "STACK zone too small\n"); 84 85 85 // register kentry vseg in V MM86 // register kentry vseg in VSL 86 87 base = CONFIG_VMM_KENTRY_BASE << CONFIG_PPM_PAGE_SHIFT; 87 88 size = CONFIG_VMM_KENTRY_SIZE << CONFIG_PPM_PAGE_SHIFT; … … 100 101 vmm->kent_vpn_base = base; 101 102 102 // register args vseg in V MM103 // register args vseg in VSL 103 104 base = (CONFIG_VMM_KENTRY_BASE + 104 105 CONFIG_VMM_KENTRY_SIZE ) << CONFIG_PPM_PAGE_SHIFT; … … 118 119 vmm->args_vpn_base = base; 119 120 120 // register the envs vseg in V MM121 // register the envs vseg in VSL 121 122 base = (CONFIG_VMM_KENTRY_BASE + 122 123 CONFIG_VMM_KENTRY_SIZE + … … 137 138 vmm->envs_vpn_base = base; 138 139 139 // initialize generic page table140 // create GPT (empty) 140 141 error = hal_gpt_create( &vmm->gpt ); 141 142 142 assert( (error == 0) , __FUNCTION__ , "cannot initialize page table\n"); 143 assert( (error == 0) , __FUNCTION__ , "cannot create GPT\n"); 144 145 // architecture specific GPT initialization 146 // (For TSAR, identity map the kentry_vseg) 147 error = hal_vmm_init( vmm ); 148 149 assert( (error == 0) , __FUNCTION__ , "cannot initialize GPT\n"); 143 150 144 151 // initialize STACK allocator … … 154 161 155 162 // initialize instrumentation counters 156 vmm->pgfault_nr 163 vmm->pgfault_nr = 0; 157 164 158 165 hal_fence(); … … 534 541 vmm_t * vmm = &process->vmm; 535 542 543 // @@@ 544 vmm_display( process , true ); 545 // @@@ 546 536 547 // get extended pointer on VSL root and VSL lock 537 548 xptr_t root_xp = XPTR( local_cxy , &vmm->vsegs_root ); … … 541 552 remote_rwlock_wr_lock( lock_xp ); 542 553 543 // remove all vsegs registered in VSL554 // remove all user vsegs registered in VSL 544 555 while( !xlist_is_empty( root_xp ) ) 545 556 { 557 // get pointer on first vseg in VSL 546 558 vseg_xp = XLIST_FIRST_ELEMENT( root_xp , vseg_t , xlist ); 547 559 vseg = (vseg_t *)GET_PTR( vseg_xp ); 560 561 printk("\n@@@ %s : vseg %s\n", __FUNCTION__ , vseg_type_str( vseg->type ) ); 562 563 // unmap and release all pages 564 vmm_unmap_vseg( process , vseg ); 565 566 // remove vseg from VSL 548 567 vseg_detach( vmm , vseg ); 568 569 // release memory allocated to vseg descriptor 549 570 vseg_free( vseg ); 550 571 } … … 565 586 } 566 587 567 // release memory allocated to the local page table588 // release memory allocated to the GPT itself 568 589 hal_gpt_destroy( &vmm->gpt ); 569 590 … … 928 949 vpn_t vpn_min; // VPN of first PTE 929 950 vpn_t vpn_max; // VPN of last PTE (excluded) 930 931 // get pointer on process page table 951 ppn_t ppn; // current PTE ppn value 952 uint32_t attr; // current PTE attributes 953 kmem_req_t req; // request to release memory 954 xptr_t page_xp; // extended pointer on page descriptor 955 cxy_t page_cxy; // page descriptor cluster 956 page_t * page_ptr; // page descriptor pointer 957 958 vmm_dmsg("\n[DBG] %s : core[%x, %d] enter / process %x / vseg %s / base %x / cycle %d\n", 959 __FUNCTION__, local_cxy, CURRENT_THREAD->core->lid, process->pid , 960 vseg_type_str( vseg->type ), vseg->vpn_base, (uint32_t)hal_get_cycles() ); 961 962 // get pointer on process GPT 932 963 gpt_t * gpt = &process->vmm.gpt; 933 964 … … 937 968 for( vpn = vpn_min ; vpn < vpn_max ; vpn++ ) 938 969 { 939 hal_gpt_reset_pte( gpt , vpn ); 940 } 941 } 970 // get GPT entry 971 hal_gpt_get_pte( gpt , vpn , &attr , &ppn ); 972 973 if( attr & GPT_MAPPED ) // entry is mapped 974 { 975 // check small page 976 assert( (attr & GPT_SMALL) , __FUNCTION__ , 977 "an user vseg must use small pages" ); 978 979 // unmap GPT entry 980 hal_gpt_reset_pte( gpt , vpn ); 981 982 // release memory if not identity mapped 983 if( (vseg->flags & VSEG_IDENT) == 0 ) 984 { 985 // get extended pointer on page descriptor 986 page_xp = ppm_ppn2page( ppn ); 987 page_cxy = GET_CXY( page_xp ); 988 page_ptr = (page_t *)GET_PTR( page_xp ); 989 990 // release physical page to relevant cluster 991 if( page_cxy == local_cxy ) // local cluster 992 { 993 req.type = KMEM_PAGE; 994 req.ptr = page_ptr; 995 kmem_free( &req ); 996 } 997 else // remote cluster 998 { 999 rpc_pmem_release_pages_client( page_cxy , page_ptr ); 1000 } 1001 } 1002 } 1003 } 1004 } // end vmm_unmap_vseg() 942 1005 943 1006 ////////////////////////////////////////////////////////////////////////////////////////// -
trunk/kernel/mm/vmm.h
r408 r409 131 131 * - It initializes the STACK and MMAP allocators. 132 132 * - It registers the "kentry", "args", "envs" vsegs in the VSL. 133 * - It initializes the generic page table, calling the HAL specific hal_gpt_init() function. 134 * - For TSAR it map all pages for the "kentry" vseg, that must be identity mapping. 135 * Note: 133 136 * - The "code" and "data" vsegs are registered by the elf_load_process() function. 134 137 * - The "stack" vsegs are dynamically created by the thread_user_create() function. 135 * - The "file", "anon", "remote" vsegs are dynamically created by the mmap() syscalls. 136 * - It initializes the generic page table, calling the HAL specific hal_gpt_init() function. 137 * - For TSAR it map all pages for the "kentry" vseg, that must be identity mapping. 138 * - The "file", "anon", "remote" vsegs are dynamically created by the mmap() syscall. 138 139 * TODO : Any error in this function gives a kernel panic => improve error handling. 139 140 ********************************************************************************************* … … 206 207 207 208 /********************************************************************************************* 208 * This function removes all vsegs registered in in the virtual memory manager of the 209 * process identified by the <process> argument. 210 * It releases the memory allocated to the local generic page table. 209 * This function scan the list of vsegs registered in the VSL of the process 210 * identified by the <process> argument, and for each vseg: 211 * - it unmap from the GPT and releases all mapped pages in vseg. 212 * - it removes the vseg from the process VSL. 213 * - It releases the memory allocated to the vseg descriptor. 214 * Finally, it releases the memory allocated to the GPT itself. 211 215 ********************************************************************************************* 212 216 * @ process : pointer on process descriptor. … … 286 290 287 291 /********************************************************************************************* 288 * This function unmaps all PTEs of a given vseg, in the generic page table associated289 * to a given process descriptor, and releases the corresponding physical memory.290 * It can be used for any type of vseg.292 * This function unmaps all mapped PTEs of a given vseg, from the generic page table 293 * associated to a given process descriptor, and releases the physical memory allocated 294 * to all mapped GPT entries. It can be used for any type of vseg. 291 295 ********************************************************************************************* 292 296 * @ process : pointer on process descriptor. -
trunk/kernel/mm/vseg.h
r408 r409 35 35 struct vmm_s; 36 36 37 /******************************************************************************************* ***37 /******************************************************************************************* 38 38 * This enum defines the vseg types for an user process. 39 *********************************************************************************** **********/39 ***********************************************************************************VSEG*******/ 40 40 41 41 typedef enum 42 42 { 43 VSEG_TYPE_CODE = 0, /*! executable user code / private / localized 44 VSEG_TYPE_DATA = 1, /*! initialized user data / public / distributed 45 VSEG_TYPE_STACK = 2, /*! execution user stack / private / localized 46 VSEG_TYPE_ANON = 3, /*! anonymous mmap / public / localized 47 VSEG_TYPE_FILE = 4, /*! file mmap / public / localized 48 VSEG_TYPE_REMOTE = 5, /*! remote mmap / public / localized 43 VSEG_TYPE_CODE = 0, /*! executable user code / private / localized */ 44 VSEG_TYPE_DATA = 1, /*! initialized user data / public / distributed */ 45 VSEG_TYPE_STACK = 2, /*! execution user stack / private / localized */ 46 VSEG_TYPE_ANON = 3, /*! anonymous mmap / public / localized */ 47 VSEG_TYPE_FILE = 4, /*! file mmap / public / localized */ 48 VSEG_TYPE_REMOTE = 5, /*! remote mmap / public / localized */ 49 49 50 50 VSEG_TYPE_KDATA = 10, … … 55 55 56 56 57 /******************************************************************************************* ***57 /******************************************************************************************* 58 58 * These masks define the vseg generic (hardware independent) flags. 59 ****************************************************************************************** ***/59 ******************************************************************************************/ 60 60 61 #define VSEG_USER 0x0001 /*! user accessible */ 62 #define VSEG_WRITE 0x0002 /*! writeable */ 63 #define VSEG_EXEC 0x0004 /*! executable */ 64 #define VSEG_CACHE 0x0008 /*! cachable */ 65 #define VSEG_PRIVATE 0x0010 /*! should not be accessed from another cluster */ 66 #define VSEG_DISTRIB 0x0020 /*! physically distributed on all clusters */ 61 #define VSEG_USER 0x0001 /*! user accessible */ 62 #define VSEG_WRITE 0x0002 /*! writeable */ 63 #define VSEG_EXEC 0x0004 /*! executable */ 64 #define VSEG_CACHE 0x0008 /*! cachable */ 65 #define VSEG_PRIVATE 0x0010 /*! should not be accessed from another cluster */ 66 #define VSEG_DISTRIB 0x0020 /*! physically distributed on all clusters */ 67 #define VSEG_IDENT 0x0040 /*! identity mapping */ 67 68 68 /******************************************************************************************* ***69 /******************************************************************************************* 69 70 * This structure defines a virtual segment descriptor. 70 71 * - The VSL contains only local vsegs, but is implemented as an xlist, because it can be 71 72 * accessed by thread running in a remote cluster. 72 73 * - The zombi list is used by the local MMAP allocator. It is implemented as a local list. 73 ****************************************************************************************** ***/74 ******************************************************************************************/ 74 75 75 76 typedef struct vseg_s 76 77 { 77 xlist_entry_t xlist; /*! all vsegs in same VSL (or same zombi list) 78 list_entry_t zlist; /*! all vsegs in same zombi list 79 struct vmm_s * vmm; /*! pointer on associated VM manager 80 uint32_t type; /*! vseg type 81 intptr_t min; /*! segment min virtual address 82 intptr_t max; /*! segment max virtual address (excluded) 83 vpn_t vpn_base; /*! first page of vseg 84 vpn_t vpn_size; /*! number of pages occupied 85 uint32_t flags; /*! vseg attributes 86 xptr_t mapper_xp; /*! xptr on remote mapper (for types CODE/DATA/FILE) 87 intptr_t file_offset; /*! vseg offset in file (for types CODE/DATA/FILE 88 intptr_t file_size; /*! max segment size in mapper (for type CODE/DATA) 89 cxy_t cxy; /*! physical mapping (for non distributed vseg) 78 xlist_entry_t xlist; /*! all vsegs in same VSL (or same zombi list) */ 79 list_entry_t zlist; /*! all vsegs in same zombi list */ 80 struct vmm_s * vmm; /*! pointer on associated VM manager */ 81 uint32_t type; /*! vseg type */ 82 intptr_t min; /*! segment min virtual address */ 83 intptr_t max; /*! segment max virtual address (excluded) */ 84 vpn_t vpn_base; /*! first page of vseg */ 85 vpn_t vpn_size; /*! number of pages occupied */ 86 uint32_t flags; /*! vseg attributes */ 87 xptr_t mapper_xp; /*! xptr on remote mapper (for types CODE/DATA/FILE) */ 88 intptr_t file_offset; /*! vseg offset in file (for types CODE/DATA/FILE */ 89 intptr_t file_size; /*! max segment size in mapper (for type CODE/DATA) */ 90 cxy_t cxy; /*! physical mapping (for non distributed vseg) */ 90 91 } 91 92 vseg_t; 92 93 93 /******************************************************************************************* ***94 /******************************************************************************************* 94 95 * This function returns a printable string for the vseg type. 95 ******************************************************************************************* ***96 ******************************************************************************************* 96 97 * @ vseg_type : type of vseg 97 98 * @ return pointer on string 98 ****************************************************************************************** ***/99 ******************************************************************************************/ 99 100 char * vseg_type_str( uint32_t vseg_type ); 100 101 101 /******************************************************************************************* ***102 /******************************************************************************************* 102 103 * This function allocates physical memory for a new vseg descriptor from the local cluster 103 104 * physical memory allocator. 104 ******************************************************************************************* ***105 ******************************************************************************************* 105 106 * @ return pointer on allocated vseg descriptor if success / return NULL if failure. 106 ****************************************************************************************** ***/107 ******************************************************************************************/ 107 108 vseg_t * vseg_alloc(); 108 109 109 /******************************************************************************************* ***110 * This function releases physical memory allocated for a vseg descriptor to the local cluster111 * physical memory allocator.112 ******************************************************************************************* ***110 /******************************************************************************************* 111 * This function releases the physical memory allocated for a vseg descriptor 112 * to the local cluster physical memory allocator. 113 ******************************************************************************************* 113 114 * @ vseg : local pointer on released vseg descriptor. 114 ****************************************************************************************** ***/115 ******************************************************************************************/ 115 116 void vseg_free( vseg_t * vseg ); 116 117 117 /******************************************************************************************* ***118 /******************************************************************************************* 118 119 * This function initializes a local vseg descriptor, from the arguments values. 119 120 * It does NOT register the vseg in the local VMM. 120 ******************************************************************************************* ***121 ******************************************************************************************* 121 122 * @ vseg : pointer on the vseg descriptor. 122 123 * @ base : vseg base address. … … 126 127 * @ type : vseg type. 127 128 * @ cxy : target cluster for physical mapping. 128 ****************************************************************************************** ***/129 ******************************************************************************************/ 129 130 void vseg_init( vseg_t * vseg, 130 131 vseg_type_t type, … … 138 139 cxy_t cxy ); 139 140 140 /******************************************************************************************* ***141 /******************************************************************************************* 141 142 * This function initializes a local vseg descriptor from values contained in a reference 142 143 * remote vseg descriptor. It does NOT register the vseg in the local VMM. 143 ******************************************************************************************* ***144 ******************************************************************************************* 144 145 * @ vseg : pointer on the vseg descriptor. 145 146 * @ ref_xp : extended pointer on the reference vseg descriptor. 146 ****************************************************************************************** ***/147 ******************************************************************************************/ 147 148 void vseg_init_from_ref( vseg_t * vseg, 148 149 xptr_t ref_xp ); 149 150 150 /******************************************************************************************* ***151 /******************************************************************************************* 151 152 * This function adds a vseg descriptor in the set of vsegs controlled by a given VMM, 152 153 * and updates the vmm field in the vseg descriptor. 153 154 * The lock protecting the vsegs list in VMM must be taken by the caller. 154 ******************************************************************************************* ***155 ******************************************************************************************* 155 156 * @ vmm : pointer on the VMM 156 157 * @ vseg : pointer on the vseg descriptor 157 ****************************************************************************************** ***/158 ******************************************************************************************/ 158 159 void vseg_attach( struct vmm_s * vmm, 159 160 vseg_t * vseg ); 160 161 161 /******************************************************************************************* ***162 /******************************************************************************************* 162 163 * This function removes a vseg descriptor from the set of vsegs controlled by a given VMM, 163 164 * and updates the vmm field in the vseg descriptor. No memory is released. 164 165 * The lock protecting the vsegs list in VMM must be taken by the caller. 165 ******************************************************************************************* ***166 ******************************************************************************************* 166 167 * @ vmm : pointer on the VMM 167 168 * @ vseg : pointer on the vseg descriptor 168 ****************************************************************************************** ***/169 ******************************************************************************************/ 169 170 void vseg_detach( struct vmm_s * vmm, 170 171 vseg_t * vseg );
Note: See TracChangeset
for help on using the changeset viewer.