Changeset 641 for trunk/kernel/mm


Ignore:
Timestamp:
Oct 10, 2019, 1:42:04 PM (5 years ago)
Author:
alain
Message:
  • Fix several bugs.
  • Introduce the "stat" command in KSH.

This almos-mkh version sucessfully executed the FFT application
(65536 complex points) on the TSAR architecture from 1 to 64 cores.

File:
1 edited

Legend:

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

    r640 r641  
    33 *
    44 * Authors   Ghassan Almaless (2008,2009,2010,2011, 2012)
    5  *           Mohamed Lamine Karaoui (2015)
    65 *           Alain Greiner (2016,2017,2018,2019)
    76 *
     
    2928#include <hal_gpt.h>
    3029#include <hal_vmm.h>
     30#include <hal_irqmask.h>
    3131#include <hal_macros.h>
    3232#include <printk.h>
     
    217217
    218218////////////////////////////////////////////////////////////////////////////////////////////
    219 // This static function is called by the vmm_remove_vseg() function, and implements
    220 // the VMM MMAP specific desallocator.
     219// This static function implements the VMM MMAP specific desallocator.
     220// It is called by the vmm_remove_vseg() function.
    221221////////////////////////////////////////////////////////////////////////////////////////////
    222222// @ vmm      : [in] pointer on VMM.
     
    495495                             intptr_t    base )
    496496{
    497     pid_t           pid;
    498497    cxy_t           owner_cxy;
    499498    lpid_t          owner_lpid;
    500 
    501     xlist_entry_t * process_root_ptr;
     499    reg_t           save_sr;
     500
     501    xptr_t          process_lock_xp;
    502502    xptr_t          process_root_xp;
    503503    xptr_t          process_iter_xp;
     
    511511    xptr_t          vsl_iter_xp;
    512512
     513    rpc_desc_t      rpc;                  // shared rpc descriptor for parallel RPCs
     514    uint32_t        responses;            // RPC responses counter
     515
     516    thread_t      * this    = CURRENT_THREAD;
     517    pid_t           pid     = process->pid;
     518    cluster_t     * cluster = LOCAL_CLUSTER;
     519
    513520#if DEBUG_VMM_GLOBAL_DELETE_VSEG
    514521uint32_t cycle = (uint32_t)hal_get_cycles();
    515 thread_t * this = CURRENT_THREAD;
    516522#endif
    517523
    518524#if (DEBUG_VMM_GLOBAL_DELETE_VSEG & 1)
    519525if( DEBUG_VMM_GLOBAL_DELETE_VSEG < cycle )
    520 printk("\n[%s] thread[%x,%x] : process %x / base %x / cycle %d\n",
     526printk("\n[%s] thread[%x,%x] enters / process %x / base %x / cycle %d\n",
    521527__FUNCTION__, this->process->pid, this->trdid, process->pid, base, cycle );
    522528#endif
    523529
     530    // initialize a shared RPC descriptor
     531    rpc.rsp       = &responses;
     532    rpc.blocking  = false;                  // non blocking behaviour for rpc_send()
     533    rpc.index     = RPC_VMM_REMOVE_VSEG;
     534    rpc.thread    = this;
     535    rpc.lid       = this->core->lid;
     536    rpc.args[0]   = this->process->pid;
     537    rpc.args[1]   = base;
     538
    524539    // get owner process cluster and local index
    525     pid              = process->pid;
    526540    owner_cxy        = CXY_FROM_PID( pid );
    527541    owner_lpid       = LPID_FROM_PID( pid );
    528542
    529     // get extended pointer on root of process copies xlist in owner cluster
    530     process_root_ptr = &LOCAL_CLUSTER->pmgr.copies_root[owner_lpid];
    531     process_root_xp  = XPTR( owner_cxy , process_root_ptr );
     543    // get extended pointer on root and lock of process copies xlist in owner cluster
     544    process_root_xp  = XPTR( owner_cxy , &cluster->pmgr.copies_root[owner_lpid] );
     545    process_lock_xp  = XPTR( owner_cxy , &cluster->pmgr.copies_lock[owner_lpid] );
     546
     547    // mask IRQs
     548    hal_disable_irq( &save_sr );
     549
     550    // client thread blocks itself
     551    thread_block( XPTR( local_cxy , this ) , THREAD_BLOCKED_RPC );
     552
     553    // take the lock protecting process copies
     554    remote_queuelock_acquire( process_lock_xp );
     555
     556    // initialize responses counter
     557    responses = 0;
    532558
    533559    // loop on process copies
     
    559585            if( vseg_base == base )   // found searched vseg
    560586            {
    561                 if( remote_process_cxy == local_cxy )
    562                 {
    563                     vmm_remove_vseg( process,
    564                                      vseg_ptr );
    565                 }
    566                 else
    567                 {
    568                     rpc_vmm_remove_vseg_client( remote_process_cxy,
    569                                                 remote_process_ptr,
    570                                                 vseg_ptr );
    571                 }
     587                // atomically increment responses counter
     588                hal_atomic_add( &responses , 1 );
    572589
    573590#if (DEBUG_VMM_GLOBAL_DELETE_VSEG & 1)
    574591if( DEBUG_VMM_GLOBAL_DELETE_VSEG < cycle )
    575 printk("\n[%s] thread[%x,%x] deleted vseg %x for process %x in cluster %x\n",
    576 __FUNCTION__, this->process->pid, this->trdid, base, process->pid, remote_process_cxy );
    577 #endif
    578 
     592printk("\n[%s] thread[%x,%x] register RPC request in cluster %x\n",
     593__FUNCTION__, this->process->pid, this->trdid, remote_process_cxy );
     594#endif
     595                // send RPC to remote cluster
     596                rpc_send( remote_process_cxy , &rpc );
     597
     598                // exit loop on vsegs
     599                break;
    579600            }
    580601        }  // end of loop on vsegs
    581602
     603        // release lock on remote VSL
     604        remote_queuelock_release( vsl_lock_xp );
     605
     606    }  // end of loop on process copies
     607
     608    // release the lock protecting process copies
     609    remote_queuelock_release( process_lock_xp );
     610
    582611#if (DEBUG_VMM_GLOBAL_DELETE_VSEG & 1)
    583612if( DEBUG_VMM_GLOBAL_DELETE_VSEG < cycle )
    584 hal_vmm_display( remote_process_xp , false );
    585 #endif
    586 
    587         // release lock on remote VSL
    588         remote_queuelock_release( vsl_lock_xp );
    589 
    590     }  // end of loop on process copies
     613printk("\n[%s] thread[%x,%x] deschedule / process %x / base %x\n",
     614__FUNCTION__, this->process->pid, this->trdid, process->pid, base );
     615#endif
     616
     617    // client thread deschedule
     618    sched_yield("blocked on rpc_vmm_delete_vseg");
     619 
     620    // restore IRQs
     621    hal_restore_irq( save_sr );
    591622
    592623#if DEBUG_VMM_GLOBAL_DELETE_VSEG
    593624cycle = (uint32_t)hal_get_cycles();
    594625if( DEBUG_VMM_GLOBAL_DELETE_VSEG < cycle )
    595 printk("\n[%s] thread[%x,%x] exit for process %x / base %x / cycle %d\n",
    596 __FUNCTION__, this->process->pid, this->trdid, process->pid , base, cycle );
     626printk("\n[%s] thread[%x,%x] exit / process %x / base %x / cycle %d\n",
     627__FUNCTION__, this->process->pid, this->trdid, process->pid, base, cycle );
    597628#endif
    598629
     
    605636                             intptr_t    new_size )
    606637{
    607     pid_t           pid;
    608638    cxy_t           owner_cxy;
    609639    lpid_t          owner_lpid;
    610 
    611     xlist_entry_t * process_root_ptr;
     640    reg_t           save_sr;
     641
     642    xptr_t          process_lock_xp;
    612643    xptr_t          process_root_xp;
    613644    xptr_t          process_iter_xp;
     
    621652    xptr_t          vsl_iter_xp;
    622653
     654    rpc_desc_t      rpc;                  // shared rpc descriptor for parallel RPCs
     655    uint32_t        responses;            // RPC responses counter
     656
     657    thread_t      * this    = CURRENT_THREAD;
     658    pid_t           pid     = process->pid;
     659    cluster_t     * cluster = LOCAL_CLUSTER;
     660
    623661#if DEBUG_VMM_GLOBAL_RESIZE_VSEG
    624662uint32_t cycle = (uint32_t)hal_get_cycles();
    625 thread_t * this = CURRENT_THREAD;
    626663#endif
    627664
     
    632669#endif
    633670
    634     // get owner process cluster and local index
    635     pid              = process->pid;
     671    // initialize a shared RPC descriptor
     672    rpc.rsp       = &responses;
     673    rpc.blocking  = false;                  // non blocking behaviour for rpc_send()
     674    rpc.index     = RPC_VMM_REMOVE_VSEG;
     675    rpc.thread    = this;
     676    rpc.lid       = this->core->lid;
     677    rpc.args[0]   = this->process->pid;
     678    rpc.args[1]   = base;
     679    rpc.args[2]   = new_base;
     680    rpc.args[3]   = new_size;
     681
     682    // get owner process cluster and local index
    636683    owner_cxy        = CXY_FROM_PID( pid );
    637684    owner_lpid       = LPID_FROM_PID( pid );
    638685
    639     // get extended pointer on root of process copies xlist in owner cluster
    640     process_root_ptr = &LOCAL_CLUSTER->pmgr.copies_root[owner_lpid];
    641     process_root_xp  = XPTR( owner_cxy , process_root_ptr );
     686    // get extended pointer on root and lock of process copies xlist in owner cluster
     687    process_root_xp  = XPTR( owner_cxy , &cluster->pmgr.copies_root[owner_lpid] );
     688    process_lock_xp  = XPTR( owner_cxy , &cluster->pmgr.copies_lock[owner_lpid] );
     689
     690    // mask IRQs
     691    hal_disable_irq( &save_sr );
     692
     693    // client thread blocks itself
     694    thread_block( XPTR( local_cxy , this ) , THREAD_BLOCKED_RPC );
     695
     696    // take the lock protecting process copies
     697    remote_queuelock_acquire( process_lock_xp );
     698
     699    // initialize responses counter
     700    responses = 0;
    642701
    643702    // loop on process copies
     
    669728            if( vseg_base == base )   // found searched vseg
    670729            {
    671                 if( remote_process_cxy == local_cxy )
    672                 {
    673                     vmm_resize_vseg( remote_process_ptr,
    674                                      vseg_ptr,
    675                                      new_base,
    676                                      new_size );
    677                 }
    678                 else
    679                 {
    680                     rpc_vmm_resize_vseg_client( remote_process_cxy,
    681                                                 remote_process_ptr,
    682                                                 vseg_ptr,
    683                                                 new_base,
    684                                                 new_size );
    685                 }
    686  
     730                // atomically increment responses counter
     731                hal_atomic_add( &responses , 1 );
     732
    687733#if (DEBUG_VMM_GLOBAL_RESIZE_VSEG & 1)
    688734if( DEBUG_VMM_GLOBAL_RESIZE_VSEG < cycle )
    689 printk("\n[%s] thread[%x,%x] resized vseg %x for process %x in cluster %x\n",
    690 __FUNCTION__, this->process->pid, this->trdid, base, process->pid, remote_process_cxy );
    691 #endif
    692 
     735printk("\n[%s] thread[%x,%x] register RPC request in cluster %x\n",
     736__FUNCTION__, this->process->pid, this->trdid, remote_process_cxy );
     737#endif
     738                // send RPC to remote cluster
     739                rpc_send( remote_process_cxy , & rpc );
     740
     741                // exit loop on vsegs
     742                break;
    693743            }
     744
    694745        }  // end of loop on vsegs
    695746
     
    701752        // release lock on remote VSL
    702753        remote_queuelock_release( vsl_lock_xp );
     754
    703755    }  // end of loop on process copies
     756
     757    // release the lock protecting process copies
     758    remote_queuelock_release( process_lock_xp );
     759
     760#if (DEBUG_VMM_GLOBAL_RESIZE_VSEG & 1)
     761if( DEBUG_VMM_GLOBAL_RESIZE_VSEG < cycle )
     762printk("\n[%s] thread[%x,%x] deschedule / process %x / base %x\n",
     763__FUNCTION__, this->process->pid, this->trdid, process->pid, base );
     764#endif
     765
     766    // client thread deschedule
     767    sched_yield("blocked on rpc_vmm_delete_vseg");
     768
     769    // restore IRQs
     770    hal_restore_irq( save_sr );
    704771
    705772#if DEBUG_VMM_GLOBAL_RESIZE_VSEG
     
    15521619#if (DEBUG_VMM_REMOVE_VSEG & 1 )
    15531620if( DEBUG_VMM_REMOVE_VSEG < cycle )
    1554 printk("\n[%s] thread[%x,%x] enter / process %x / %s / base %x / cycle %d\n",
     1621printk("\n[%s] thread[%x,%x] enters / process %x / type %s / base %x / cycle %d\n",
    15551622__FUNCTION__, this->process->pid, this->trdid,
    15561623process->pid, vseg_type_str(vseg->type), vseg->min, cycle );
     
    15681635#if( DEBUG_VMM_REMOVE_VSEG & 1 )
    15691636if( DEBUG_VMM_REMOVE_VSEG < cycle )
    1570 printk("\n[%s] thread[%x,%x] unmap vpn %x / ppn %x / %s",
     1637printk("\n[%s] thread[%x,%x] unmap vpn %x / ppn %x / type %s\n",
    15711638__FUNCTION__, this->process->pid, this->trdid, vpn , ppn, vseg_type_str(vseg_type) );
    15721639#endif
     
    16071674cycle = (uint32_t)hal_get_cycles();
    16081675if( DEBUG_VMM_REMOVE_VSEG < cycle )
    1609 printk("[%s] thread[%x,%x] exit / process %x / %s / base %x / cycle %d\n",
     1676printk("\n[%s] thread[%x,%x] exit / process %x / type %s / base %x / cycle %d\n",
    16101677__FUNCTION__, this->process->pid, this->trdid,
    16111678process->pid, vseg_type_str(vseg->type), vseg->min, cycle );
     
    16841751        {
    16851752
    1686 #if( DEBUG_VMM_REMOVE_VSEG & 1 )
     1753#if( DEBUG_VMM_RESIZE_VSEG & 1 )
    16871754if( DEBUG_VMM_RESIZE_VSEG < cycle )
    16881755printk("\n[%s] thread[%x,%x] unmap vpn %x / ppn %x / %s",
     
    21892256#if (CONFIG_INSTRUMENTATION_PGFAULTS || DEBUG_VMM_HANDLE_PAGE_FAULT)
    21902257uint32_t end_cycle = (uint32_t)hal_get_cycles();
     2258uint32_t cost      = end_cycle - start_cycle;
    21912259#endif
    21922260
     
    21992267#if CONFIG_INSTRUMENTATION_PGFAULTS
    22002268this->info.local_pgfault_nr++;
    2201 this->info.local_pgfault_cost += (end_cycle - start_cycle);
     2269this->info.local_pgfault_cost += cost;
     2270if( cost > this->info.local_pgfault_max ) this->info.local_pgfault_max = cost;
    22022271#endif
    22032272            return EXCP_NON_FATAL;
     
    22672336#if (CONFIG_INSTRUMENTATION_PGFAULTS || DEBUG_VMM_HANDLE_PAGE_FAULT)
    22682337uint32_t end_cycle = (uint32_t)hal_get_cycles();
     2338uint32_t cost      = end_cycle - start_cycle;
    22692339#endif
    22702340
     
    22772347#if CONFIG_INSTRUMENTATION_PGFAULTS
    22782348this->info.false_pgfault_nr++;
    2279 this->info.false_pgfault_cost += (end_cycle - start_cycle);
     2349this->info.false_pgfault_cost += cost;
     2350if( cost > this->info.false_pgfault_max ) this->info.false_pgfault_max = cost;
    22802351#endif
    22812352                return EXCP_NON_FATAL;
     
    23322403#if (CONFIG_INSTRUMENTATION_PGFAULTS || DEBUG_VMM_HANDLE_PAGE_FAULT)
    23332404uint32_t end_cycle = (uint32_t)hal_get_cycles();
     2405uint32_t cost      = end_cycle - start_cycle;
    23342406#endif
    23352407
     
    23422414#if CONFIG_INSTRUMENTATION_PGFAULTS
    23432415this->info.global_pgfault_nr++;
    2344 this->info.global_pgfault_cost += (end_cycle - start_cycle);
     2416this->info.global_pgfault_cost += cost;
     2417if( cost > this->info.global_pgfault_max ) this->info.global_pgfault_max = cost;
    23452418#endif
    23462419                return EXCP_NON_FATAL;
     
    23552428#if (CONFIG_INSTRUMENTATION_PGFAULTS || DEBUG_VMM_HANDLE_PAGE_FAULT)
    23562429uint32_t end_cycle = (uint32_t)hal_get_cycles();
     2430uint32_t cost      = end_cycle - start_cycle;
    23572431#endif
    23582432
     
    23652439#if CONFIG_INSTRUMENTATION_PGFAULTS
    23662440this->info.false_pgfault_nr++;
    2367 this->info.false_pgfault_cost += (end_cycle - start_cycle);
     2441this->info.false_pgfault_cost += cost;
     2442if( cost > this->info.false_pgfault_max ) this->info.false_pgfault_max = cost;
    23682443#endif
    23692444        return EXCP_NON_FATAL;
Note: See TracChangeset for help on using the changeset viewer.