Changeset 619 for trunk/kernel/mm/vmm.c


Ignore:
Timestamp:
Feb 12, 2019, 1:15:47 PM (6 years ago)
Author:
alain
Message:

1) Fix a bug in KSH : after the "load" command,

the [ksh] prompt is now printed after completion
of the loaded application.

2) Fix a bug in vmm_handle_cow() : the copy-on-write

use now a hal_remote_memcpy() to replicate the page content.


File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/mm/vmm.c

    r617 r619  
    800800    // scan the VSL to delete all registered vsegs
    801801    // (don't use a FOREACH for item deletion in xlist)
    802         while( !xlist_is_empty( root_xp ) )
     802
     803uint32_t count = 0;
     804
     805        while( !xlist_is_empty( root_xp ) && (count < 10 ) )
    803806        {
    804807        // get pointer on first vseg in VSL
     
    814817__FUNCTION__ , vseg_type_str( vseg->type ), vseg->vpn_base, vseg->vpn_size );
    815818#endif
     819
     820count++;
    816821
    817822        }
     
    14631468
    14641469#if DEBUG_VMM_ALLOCATE_PAGE
    1465 uint32_t   cycle = (uint32_t)hal_get_cycles();
    1466 thread_t * this  = CURRENT_THREAD;
     1470uint32_t   cycle   = (uint32_t)hal_get_cycles();
     1471thread_t * this    = CURRENT_THREAD;
     1472xptr_t     this_xp = XPTR( local_cxy , this );
    14671473if( DEBUG_VMM_ALLOCATE_PAGE < (uint32_t)hal_get_cycles() )
    14681474printk("\n[%s] thread[%x,%x] enter for vpn %x / cycle %d\n",
     
    19501956
    19511957#if DEBUG_VMM_HANDLE_COW
    1952 uint32_t   cycle = (uint32_t)hal_get_cycles();
    1953 thread_t * this  = CURRENT_THREAD;
     1958uint32_t   cycle   = (uint32_t)hal_get_cycles();
     1959thread_t * this    = CURRENT_THREAD;
     1960xptr_t     this_xp = XPTR( local_cxy , this );
    19541961if( DEBUG_VMM_HANDLE_COW < cycle )
    19551962printk("\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 );
    19571964#endif
    19581965
     
    19741981    }
    19751982
     1983#if( DEBUG_VMM_HANDLE_COW & 1)
     1984if( DEBUG_VMM_HANDLE_COW < cycle )
     1985printk("\n[%s] thread[%x,%x] get vseg for vpn %x\n",
     1986__FUNCTION__, this->process->pid, this->trdid, vpn );
     1987#endif
     1988
    19761989    // get reference GPT cluster and local pointer
    19771990    ref_cxy = GET_CXY( process->ref_xp );
     
    20012014                     &old_ppn );
    20022015
     2016#if( DEBUG_VMM_HANDLE_COW & 1)
     2017if( DEBUG_VMM_HANDLE_COW < cycle )
     2018printk("\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
    20032022    // the PTE must be mapped for a COW
    20042023    if( (old_attr & GPT_MAPPED) == 0 )
     
    20082027
    20092028        // release GPT lock in write mode
    2010         remote_rwlock_wr_acquire( gpt_lock_xp );
     2029        remote_rwlock_wr_release( gpt_lock_xp );
    20112030
    20122031        return EXCP_KERNEL_PANIC;
    20132032    }
    20142033
    2015     // get extended pointer, cluster and local pointer on physical page descriptor
     2034    // get pointers on physical page descriptor
    20162035    xptr_t   page_xp  = ppm_ppn2page( old_ppn );
    20172036    cxy_t    page_cxy = GET_CXY( page_xp );
     
    20282047    uint32_t forks = hal_remote_l32( forks_xp );
    20292048
     2049#if( DEBUG_VMM_HANDLE_COW & 1)
     2050if( DEBUG_VMM_HANDLE_COW < cycle )
     2051printk("\n[%s] thread[%x,%x] get forks = %d for vpn %x\n",
     2052__FUNCTION__, this->process->pid, this->trdid, forks, vpn );
     2053#endif
     2054
    20302055    if( forks )        // pending fork => allocate a new page, and copy old to new
    20312056    {
    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
    20332064        page_xp = vmm_page_allocate( vseg , vpn );
     2065
    20342066        if( page_xp == XPTR_NULL )
    20352067        {
     
    20402072            remote_rwlock_wr_acquire( gpt_lock_xp );
    20412073
    2042             // release lock protecting "forks" counter
    2043             remote_busylock_release( forks_lock_xp );
    2044 
    20452074            return EXCP_KERNEL_PANIC;
    20462075        }
     
    20492078        new_ppn = ppm_page2ppn( page_xp );
    20502079
     2080#if( DEBUG_VMM_HANDLE_COW & 1)
     2081if( DEBUG_VMM_HANDLE_COW < cycle )
     2082printk("\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
    20512086        // 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 );
    20602090
    20612091#if(DEBUG_VMM_HANDLE_COW & 1)
    20622092if( 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 );
     2093printk("\n[%s] thread[%x,%x] copied old page to new page\n",
     2094__FUNCTION__, this->process->pid, this->trdid );
    20652095#endif
    20662096
     
    20682098    else               // no pending fork => keep the existing page
    20692099    {
     2100        // release lock protecting "forks" counter
     2101        remote_busylock_release( forks_lock_xp );
    20702102
    20712103#if(DEBUG_VMM_HANDLE_COW & 1)
    20722104if( 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 );
     2105printk("\n[%s] thread[%x,%x]  no pending forks / keep existing PPN %x\n",
     2106__FUNCTION__, this->process->pid, this->trdid, old_ppn );
    20752107#endif
    20762108        new_ppn = old_ppn;
    20772109    }
    2078 
    2079     // release lock protecting "forks" counter
    2080     remote_busylock_release( forks_lock_xp );
    20812110
    20822111    // build new_attr : reset COW and set WRITABLE,
    20832112    new_attr = (old_attr | GPT_WRITABLE) & (~GPT_COW);
    20842113
    2085     // update the relevan GPT
     2114    // update the relevant GPT
    20862115    // - private vseg => update local GPT
    20872116    // - public vseg => update all GPT copies
     
    21192148if( DEBUG_VMM_HANDLE_COW < cycle )
    21202149printk("\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 );
    21222151#endif
    21232152
Note: See TracChangeset for help on using the changeset viewer.