Ignore:
Timestamp:
May 16, 2018, 4:15:22 PM (4 years ago)
Author:
alain
Message:

Fix few bugs whike debugging the sort multi-thread application.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/kern/cluster.c

    r440 r443  
    3434#include <spinlock.h>
    3535#include <core.h>
     36#include <chdev.h>
    3637#include <scheduler.h>
    3738#include <list.h>
     
    4950/////////////////////////////////////////////////////////////////////////////////////
    5051
    51 extern process_t process_zero;     // allocated in kernel_init.c file
    52 
    53 
    54 /////////////////////////////////////////////////
     52extern process_t           process_zero;     // allocated in kernel_init.c file
     53extern chdev_directory_t   chdev_dir;        // allocated in kernel_init.c file
     54
     55///////////////////////////////////////////////n
    5556error_t cluster_init( struct boot_info_s * info )
    5657{
     
    252253
    253254//////////////////////////////////////////////////////
     255xptr_t cluster_get_process_from_pid_in_cxy( cxy_t cxy,
     256                                            pid_t pid )
     257{
     258    xptr_t      root_xp;       // xptr on root of list of processes in owner cluster
     259    xptr_t      lock_xp;       // xptr on lock protecting this list
     260    xptr_t      iter_xp;       // iterator
     261    xptr_t      current_xp;    // xptr on current process descriptor
     262    bool_t      found;
     263
     264    cluster_t * cluster = LOCAL_CLUSTER;
     265
     266    // get owner cluster and lpid
     267    cxy_t   owner_cxy = CXY_FROM_PID( pid );
     268    lpid_t  lpid      = LPID_FROM_PID( pid );
     269
     270    // get lock & root of list of copies from owner cluster
     271    root_xp = XPTR( owner_cxy , &cluster->pmgr.copies_root[lpid] );
     272    lock_xp = XPTR( owner_cxy , &cluster->pmgr.copies_lock[lpid] );
     273
     274    // take the lock protecting the list of processes
     275    remote_spinlock_lock( lock_xp );
     276
     277    // scan list of processes
     278    found = false;
     279    XLIST_FOREACH( root_xp , iter_xp )
     280    {
     281        current_xp  = XLIST_ELEMENT( iter_xp , process_t , copies_list );
     282
     283        if( GET_CXY( current_xp ) == cxy )
     284        {
     285            found = true;
     286            break;
     287        }
     288    }
     289
     290    // release the lock protecting the list of processes
     291    remote_spinlock_unlock( lock_xp );
     292
     293    // return extended pointer on process descriptor in owner cluster
     294    if( found ) return current_xp;
     295    else        return XPTR_NULL;
     296
     297}  // end cluster_get_process_from_pid_in_cxy()
     298
     299
     300//////////////////////////////////////////////////////
    254301xptr_t cluster_get_owner_process_from_pid( pid_t pid )
    255302{
     
    298345}  // end cluster_get_owner_process_from_pid()
    299346
     347
    300348//////////////////////////////////////////////////////////
    301349xptr_t cluster_get_reference_process_from_pid( pid_t pid )
     
    459507void cluster_process_local_link( process_t * process )
    460508{
    461     uint32_t irq_state;
     509    reg_t    save_sr;
     510
    462511    pmgr_t * pm = &LOCAL_CLUSTER->pmgr;
    463512
     513    // get extended pointers on local process list root & lock
     514    xptr_t root_xp = XPTR( local_cxy , &pm->local_root );
     515    xptr_t lock_xp = XPTR( local_cxy , &pm->local_lock );
     516
    464517    // get lock protecting the process manager local list
    465     remote_spinlock_lock_busy( XPTR( local_cxy , &pm->local_lock ) , & irq_state );
    466 
    467     xlist_add_last( XPTR( local_cxy , &pm->local_root ),
    468                     XPTR( local_cxy , &process->local_list ) );
     518    remote_spinlock_lock_busy( lock_xp , &save_sr );
     519
     520    // register process in local list
     521    xlist_add_last( root_xp , XPTR( local_cxy , &process->local_list ) );
    469522    pm->local_nr++;
    470523
    471524    // release lock protecting the process manager local list
    472     remote_spinlock_unlock_busy( XPTR( local_cxy , &pm->local_lock ) , irq_state );
     525    remote_spinlock_unlock_busy( lock_xp , save_sr );
    473526}
    474527
     
    476529void cluster_process_local_unlink( process_t * process )
    477530{
    478     uint32_t irq_state;
     531    reg_t save_sr;
     532
    479533    pmgr_t * pm = &LOCAL_CLUSTER->pmgr;
    480534
     535    // get extended pointers on local process list lock
     536    xptr_t lock_xp = XPTR( local_cxy , &pm->local_lock );
     537
    481538    // get lock protecting the process manager local list
    482     remote_spinlock_lock_busy( XPTR( local_cxy , &pm->local_lock ) , &irq_state );
    483 
     539    remote_spinlock_lock_busy( lock_xp , &save_sr );
     540
     541    // remove process from local list
    484542    xlist_unlink( XPTR( local_cxy , &process->local_list ) );
    485543    pm->local_nr--;
    486544
    487545    // release lock protecting the process manager local list
    488     remote_spinlock_unlock_busy( XPTR( local_cxy , &pm->local_lock ) , irq_state );
     546    remote_spinlock_unlock_busy( lock_xp , save_sr );
    489547}
    490548
     
    582640{
    583641    xptr_t        root_xp;
     642    xptr_t        lock_xp;
    584643    xptr_t        iter_xp;
    585     xptr_t        process_xp;     
    586 
    587     // get extended pointer on root of process in cluster cxy
     644    xptr_t        process_xp;
     645    cxy_t         txt0_cxy;
     646    chdev_t     * txt0_ptr;
     647    xptr_t        txt0_xp;
     648    xptr_t        txt0_lock_xp;
     649    reg_t         txt0_save_sr;     // save SR to take TXT0 lock in busy mode     
     650
     651    assert( (cluster_is_undefined( cxy ) == false),
     652    __FUNCTION__, "illegal cluster index" );
     653
     654    // get extended pointer on root and lock for local process list in cluster
    588655    root_xp = XPTR( cxy , &LOCAL_CLUSTER->pmgr.local_root );
    589 
    590     // skip one line
    591     printk("\n***** processes in cluster %x / cycle %d\n", cxy , (uint32_t)hal_get_cycles() );
    592 
    593     // loop on all reference processes in cluster cxy
     656    lock_xp = XPTR( cxy , &LOCAL_CLUSTER->pmgr.local_lock );
     657
     658    // get pointers on TXT0 chdev
     659    txt0_xp  = chdev_dir.txt_tx[0];
     660    txt0_cxy = GET_CXY( txt0_xp );
     661    txt0_ptr = GET_PTR( txt0_xp );
     662
     663    // get extended pointer on TXT0 lock
     664    txt0_lock_xp = XPTR( txt0_cxy , &txt0_ptr->wait_lock );
     665
     666    // get lock on local process list
     667    remote_spinlock_lock( lock_xp );
     668
     669    // get TXT0 lock in busy waiting mode
     670    remote_spinlock_lock_busy( txt0_lock_xp , &txt0_save_sr );
     671     
     672    // display header
     673    nolock_printk("\n***** processes in cluster %x / cycle %d\n",
     674    cxy , (uint32_t)hal_get_cycles() );
     675
     676    // loop on all processes in cluster cxy
    594677    XLIST_FOREACH( root_xp , iter_xp )
    595678    {
     
    597680        process_display( process_xp );
    598681    }
     682
     683    // release TXT0 lock in busy waiting mode
     684    remote_spinlock_unlock_busy( txt0_lock_xp , txt0_save_sr );
     685
     686    // release lock on local process list
     687    remote_spinlock_unlock( lock_xp );
     688
    599689}  // end cluster_processes_display()
    600690
Note: See TracChangeset for help on using the changeset viewer.