Changeset 619 for trunk/kernel/mm/vmm.c
- Timestamp:
- Feb 12, 2019, 1:15:47 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/mm/vmm.c
r617 r619 800 800 // scan the VSL to delete all registered vsegs 801 801 // (don't use a FOREACH for item deletion in xlist) 802 while( !xlist_is_empty( root_xp ) ) 802 803 uint32_t count = 0; 804 805 while( !xlist_is_empty( root_xp ) && (count < 10 ) ) 803 806 { 804 807 // get pointer on first vseg in VSL … … 814 817 __FUNCTION__ , vseg_type_str( vseg->type ), vseg->vpn_base, vseg->vpn_size ); 815 818 #endif 819 820 count++; 816 821 817 822 } … … 1463 1468 1464 1469 #if DEBUG_VMM_ALLOCATE_PAGE 1465 uint32_t cycle = (uint32_t)hal_get_cycles(); 1466 thread_t * this = CURRENT_THREAD; 1470 uint32_t cycle = (uint32_t)hal_get_cycles(); 1471 thread_t * this = CURRENT_THREAD; 1472 xptr_t this_xp = XPTR( local_cxy , this ); 1467 1473 if( DEBUG_VMM_ALLOCATE_PAGE < (uint32_t)hal_get_cycles() ) 1468 1474 printk("\n[%s] thread[%x,%x] enter for vpn %x / cycle %d\n", … … 1950 1956 1951 1957 #if DEBUG_VMM_HANDLE_COW 1952 uint32_t cycle = (uint32_t)hal_get_cycles(); 1953 thread_t * this = CURRENT_THREAD; 1958 uint32_t cycle = (uint32_t)hal_get_cycles(); 1959 thread_t * this = CURRENT_THREAD; 1960 xptr_t this_xp = XPTR( local_cxy , this ); 1954 1961 if( DEBUG_VMM_HANDLE_COW < cycle ) 1955 1962 printk("\n[%s] thread[%x,%x] enter for vpn %x / core[%x,%d] / cycle %d\n", 1956 __FUNCTION__, process->pid, this->trdid, vpn, local_cxy, this->core->lid, cycle );1963 __FUNCTION__, this->process->pid, this->trdid, vpn, local_cxy, this->core->lid, cycle ); 1957 1964 #endif 1958 1965 … … 1974 1981 } 1975 1982 1983 #if( DEBUG_VMM_HANDLE_COW & 1) 1984 if( DEBUG_VMM_HANDLE_COW < cycle ) 1985 printk("\n[%s] thread[%x,%x] get vseg for vpn %x\n", 1986 __FUNCTION__, this->process->pid, this->trdid, vpn ); 1987 #endif 1988 1976 1989 // get reference GPT cluster and local pointer 1977 1990 ref_cxy = GET_CXY( process->ref_xp ); … … 2001 2014 &old_ppn ); 2002 2015 2016 #if( DEBUG_VMM_HANDLE_COW & 1) 2017 if( DEBUG_VMM_HANDLE_COW < cycle ) 2018 printk("\n[%s] thread[%x,%x] get pte for vpn %x : ppn %x / attr %x\n", 2019 __FUNCTION__, this->process->pid, this->trdid, vpn, old_ppn, old_attr ); 2020 #endif 2021 2003 2022 // the PTE must be mapped for a COW 2004 2023 if( (old_attr & GPT_MAPPED) == 0 ) … … 2008 2027 2009 2028 // release GPT lock in write mode 2010 remote_rwlock_wr_ acquire( gpt_lock_xp );2029 remote_rwlock_wr_release( gpt_lock_xp ); 2011 2030 2012 2031 return EXCP_KERNEL_PANIC; 2013 2032 } 2014 2033 2015 // get extended pointer, cluster and local pointeron physical page descriptor2034 // get pointers on physical page descriptor 2016 2035 xptr_t page_xp = ppm_ppn2page( old_ppn ); 2017 2036 cxy_t page_cxy = GET_CXY( page_xp ); … … 2028 2047 uint32_t forks = hal_remote_l32( forks_xp ); 2029 2048 2049 #if( DEBUG_VMM_HANDLE_COW & 1) 2050 if( DEBUG_VMM_HANDLE_COW < cycle ) 2051 printk("\n[%s] thread[%x,%x] get forks = %d for vpn %x\n", 2052 __FUNCTION__, this->process->pid, this->trdid, forks, vpn ); 2053 #endif 2054 2030 2055 if( forks ) // pending fork => allocate a new page, and copy old to new 2031 2056 { 2032 // allocate a new physical page 2057 // decrement pending forks counter in page descriptor 2058 hal_remote_atomic_add( forks_xp , -1 ); 2059 2060 // release lock protecting "forks" counter 2061 remote_busylock_release( forks_lock_xp ); 2062 2063 // allocate a new page 2033 2064 page_xp = vmm_page_allocate( vseg , vpn ); 2065 2034 2066 if( page_xp == XPTR_NULL ) 2035 2067 { … … 2040 2072 remote_rwlock_wr_acquire( gpt_lock_xp ); 2041 2073 2042 // release lock protecting "forks" counter2043 remote_busylock_release( forks_lock_xp );2044 2045 2074 return EXCP_KERNEL_PANIC; 2046 2075 } … … 2049 2078 new_ppn = ppm_page2ppn( page_xp ); 2050 2079 2080 #if( DEBUG_VMM_HANDLE_COW & 1) 2081 if( DEBUG_VMM_HANDLE_COW < cycle ) 2082 printk("\n[%s] thread[%x,%x] get new ppn %x for vpn %x\n", 2083 __FUNCTION__, this->process->pid, this->trdid, new_ppn, vpn ); 2084 #endif 2085 2051 2086 // copy old page content to new page 2052 xptr_t old_base_xp = ppm_ppn2base( old_ppn ); 2053 xptr_t new_base_xp = ppm_ppn2base( new_ppn ); 2054 memcpy( GET_PTR( new_base_xp ), 2055 GET_PTR( old_base_xp ), 2056 CONFIG_PPM_PAGE_SIZE ); 2057 2058 // decrement pending forks counter in page descriptor 2059 hal_remote_atomic_add( forks_xp , -1 ); 2087 hal_remote_memcpy( ppm_ppn2base( new_ppn ), 2088 ppm_ppn2base( old_ppn ), 2089 CONFIG_PPM_PAGE_SIZE ); 2060 2090 2061 2091 #if(DEBUG_VMM_HANDLE_COW & 1) 2062 2092 if( DEBUG_VMM_HANDLE_COW < cycle ) 2063 printk("\n[%s] thread[%x,%x] : pending forks => allocate a new PPN %x\n",2064 __FUNCTION__, process->pid, this->trdid, new_ppn);2093 printk("\n[%s] thread[%x,%x] copied old page to new page\n", 2094 __FUNCTION__, this->process->pid, this->trdid ); 2065 2095 #endif 2066 2096 … … 2068 2098 else // no pending fork => keep the existing page 2069 2099 { 2100 // release lock protecting "forks" counter 2101 remote_busylock_release( forks_lock_xp ); 2070 2102 2071 2103 #if(DEBUG_VMM_HANDLE_COW & 1) 2072 2104 if( DEBUG_VMM_HANDLE_COW < cycle ) 2073 printk("\n[%s] thread[%x,%x] no pending forks =>keep existing PPN %x\n",2074 __FUNCTION__, process->pid, this->trdid, new_ppn );2105 printk("\n[%s] thread[%x,%x] no pending forks / keep existing PPN %x\n", 2106 __FUNCTION__, this->process->pid, this->trdid, old_ppn ); 2075 2107 #endif 2076 2108 new_ppn = old_ppn; 2077 2109 } 2078 2079 // release lock protecting "forks" counter2080 remote_busylock_release( forks_lock_xp );2081 2110 2082 2111 // build new_attr : reset COW and set WRITABLE, 2083 2112 new_attr = (old_attr | GPT_WRITABLE) & (~GPT_COW); 2084 2113 2085 // update the relevan GPT2114 // update the relevant GPT 2086 2115 // - private vseg => update local GPT 2087 2116 // - public vseg => update all GPT copies … … 2119 2148 if( DEBUG_VMM_HANDLE_COW < cycle ) 2120 2149 printk("\n[%s] thread[%x,%x] exit for vpn %x / core[%x,%d] / cycle %d\n", 2121 __FUNCTION__, process->pid, this->trdid, vpn, local_cxy, this->core->lid, cycle );2150 __FUNCTION__, this->process->pid, this->trdid, vpn, local_cxy, this->core->lid, cycle ); 2122 2151 #endif 2123 2152
Note: See TracChangeset
for help on using the changeset viewer.