Ignore:
Timestamp:
Oct 4, 2018, 11:47:36 PM (3 years ago)
Author:
alain
Message:

Complete restructuration of kernel locks.

File:
1 edited

Legend:

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

    r527 r564  
    11/*
    2  * process.c - process related management
     2 * process.c - process related functions definition.
    33 *
    44 * Authors  Ghassan Almaless (2008,2009,2010,2011,2012)
     
    4343#include <string.h>
    4444#include <scheduler.h>
    45 #include <remote_spinlock.h>
     45#include <busylock.h>
     46#include <queuelock.h>
     47#include <remote_queuelock.h>
     48#include <rwlock.h>
     49#include <remote_rwlock.h>
    4650#include <dqdt.h>
    4751#include <cluster.h>
     
    114118
    115119    // get parent_pid
    116     parent_pid = hal_remote_lw( XPTR( parent_cxy , &parent_ptr->pid ) );
     120    parent_pid = hal_remote_l32( XPTR( parent_cxy , &parent_ptr->pid ) );
    117121
    118122#if DEBUG_PROCESS_REFERENCE_INIT
     
    132136    // initialize vmm as empty
    133137    error = vmm_init( process );
    134     assert( (error == 0) , "cannot initialize VMM\n" );
     138
     139assert( (error == 0) , "cannot initialize VMM\n" );
    135140 
    136141#if (DEBUG_PROCESS_REFERENCE_INIT & 1)
     
    138143if( DEBUG_PROCESS_REFERENCE_INIT )
    139144printk("\n[DBG] %s : thread %x in process %x / vmm empty for process %x / cycle %d\n",
    140 __FUNCTION__, CURRENT_THREAD->trdid, parent_pid , cycle );
     145__FUNCTION__, CURRENT_THREAD->trdid, parent_pid , pid, cycle );
    141146#endif
    142147
     
    160165__FUNCTION__, CURRENT_THREAD->trdid, parent_pid, pid, txt_id, cycle );
    161166#endif
    162 
    163 
    164 
    165167        // build path to TXT_RX[i] and TXT_TX[i] chdevs
    166168        snprintf( rx_path , 40 , "/dev/external/txt%d_rx", txt_id );
     
    175177                           &stdin_id );
    176178
    177         assert( (error == 0) , "cannot open stdin pseudo file" );
    178         assert( (stdin_id == 0) , "stdin index must be 0" );
     179assert( (error == 0) , "cannot open stdin pseudo file" );
     180assert( (stdin_id == 0) , "stdin index must be 0" );
    179181
    180182#if (DEBUG_PROCESS_REFERENCE_INIT & 1)
     
    225227    {
    226228        // get extended pointer on stdin pseudo file in parent process
    227         file_xp = (xptr_t)hal_remote_lwd( XPTR( parent_cxy , &parent_ptr->fd_array.array[0] ) );
     229        file_xp = (xptr_t)hal_remote_l64( XPTR( parent_cxy , &parent_ptr->fd_array.array[0] ) );
    228230
    229231        // get extended pointer on parent process TXT chdev
     
    234236        chdev_ptr = GET_PTR( chdev_xp );
    235237 
    236         // get TXT terminal index
    237         txt_id = hal_remote_lw( XPTR( chdev_cxy , &chdev_ptr->channel ) );
    238 
    239         // attach process to TXT[txt_id]
     238        // get parent process TXT terminal index
     239        txt_id = hal_remote_l32( XPTR( chdev_cxy , &chdev_ptr->channel ) );
     240
     241        // attach child process to parent process TXT terminal
    240242        process_txt_attach( process , txt_id );
    241243
     
    246248
    247249    // initialize specific inodes root and cwd
    248     process->vfs_root_xp = (xptr_t)hal_remote_lwd( XPTR( parent_cxy,
     250    process->vfs_root_xp = (xptr_t)hal_remote_l64( XPTR( parent_cxy,
    249251                                                         &parent_ptr->vfs_root_xp ) );
    250     process->vfs_cwd_xp  = (xptr_t)hal_remote_lwd( XPTR( parent_cxy,
     252    process->vfs_cwd_xp  = (xptr_t)hal_remote_l64( XPTR( parent_cxy,
    251253                                                         &parent_ptr->vfs_cwd_xp ) );
    252254    vfs_inode_remote_up( process->vfs_root_xp );
    253255    vfs_inode_remote_up( process->vfs_cwd_xp );
    254256
    255     remote_rwlock_init( XPTR( local_cxy , &process->cwd_lock ) );
     257    remote_rwlock_init( XPTR( local_cxy , &process->cwd_lock ), LOCK_PROCESS_CWD );
    256258
    257259#if (DEBUG_PROCESS_REFERENCE_INIT & 1)
    258260cycle = (uint32_t)hal_get_cycles();
    259261if( DEBUG_PROCESS_REFERENCE_INIT )
    260 printk("\n[DBG] %s : thread %x / fd_array for process %x / cycle %d\n",
    261 __FUNCTION__ , CURRENT_THREAD , pid , cycle );
     262printk("\n[DBG] %s : thread %x in process %x / set fd_array for process %x / cycle %d\n",
     263__FUNCTION__, CURRENT_THREAD->trdid, parent_pid, pid , cycle );
    262264#endif
    263265
     
    265267    xlist_root_init( XPTR( local_cxy , &process->children_root ) );
    266268    process->children_nr     = 0;
    267     remote_spinlock_init( XPTR( local_cxy , &process->children_lock ) );
     269    remote_queuelock_init( XPTR( local_cxy , &process->children_lock ), LOCK_PROCESS_CHILDREN );
    268270
    269271    // reset semaphore / mutex / barrier / condvar list roots
     
    272274    xlist_root_init( XPTR( local_cxy , &process->barrier_root ) );
    273275    xlist_root_init( XPTR( local_cxy , &process->condvar_root ) );
    274     remote_spinlock_init( XPTR( local_cxy , &process->sync_lock ) );
     276    remote_queuelock_init( XPTR( local_cxy , &process->sync_lock ), LOCK_PROCESS_USERSYNC );
    275277
    276278    // register new process in the local cluster manager pref_tbl[]
     
    284286    cluster_process_copies_link( process );
    285287
    286     // reset th_tbl[] array as empty in process descriptor
     288    // initialize th_tbl[] array and associated threads
    287289    uint32_t i;
    288     for( i = 0 ; i < CONFIG_THREAD_MAX_PER_CLUSTER ; i++ )
     290
     291    for( i = 0 ; i < CONFIG_THREADS_MAX_PER_CLUSTER ; i++ )
    289292        {
    290293        process->th_tbl[i] = NULL;
    291294    }
    292295    process->th_nr  = 0;
    293     spinlock_init( &process->th_lock );
     296    rwlock_init( &process->th_lock , LOCK_PROCESS_THTBL );
    294297
    295298        hal_fence();
     
    298301cycle = (uint32_t)hal_get_cycles();
    299302if( DEBUG_PROCESS_REFERENCE_INIT )
    300 printk("\n[DBG] %s : thread %x exit / process %x / cycle %d\n",
    301 __FUNCTION__ , CURRENT_THREAD , pid , cycle );
     303printk("\n[DBG] %s : thread %x in process %x exit for process %x / cycle %d\n",
     304__FUNCTION__, CURRENT_THREAD->trdid, parent_pid, pid, cycle );
    302305#endif
    303306
     
    315318
    316319    // initialize PID, REF_XP, PARENT_XP, and STATE
    317     local_process->pid        = hal_remote_lw(  XPTR( ref_cxy , &ref_ptr->pid ) );
    318     local_process->parent_xp  = hal_remote_lwd( XPTR( ref_cxy , &ref_ptr->parent_xp ) );
     320    local_process->pid        = hal_remote_l32(  XPTR( ref_cxy , &ref_ptr->pid ) );
     321    local_process->parent_xp  = hal_remote_l64( XPTR( ref_cxy , &ref_ptr->parent_xp ) );
    319322    local_process->ref_xp     = reference_process_xp;
    320323    local_process->owner_xp   = reference_process_xp;
    321324    local_process->term_state = 0;
    322325
    323 #if DEBUG_PROCESS_COPY_INIT
     326#if DEBUG_PROCESS_COPY_INIT
     327thread_t * this = CURRET_THREAD; 
    324328uint32_t cycle = (uint32_t)hal_get_cycles();
    325329if( DEBUG_PROCESS_COPY_INIT )
    326 printk("\n[DBG] %s : thread %x enter for process %x\n",
    327 __FUNCTION__ , CURRENT_THREAD , local_process->pid );
    328 #endif
     330printk("\n[DBG] %s : thread %x in process %x enter for process %x / cycle %d\n",
     331__FUNCTION__, this->trdid, this->process->pid, local_process->pid, cycle );
     332#endif
     333
     334// check user process
     335assert( (local_process->pid != 0), "PID cannot be 0" );
    329336
    330337    // reset local process vmm
     
    336343
    337344    // reset vfs_root_xp / vfs_bin_xp / vfs_cwd_xp fields
    338     local_process->vfs_root_xp = hal_remote_lwd( XPTR( ref_cxy , &ref_ptr->vfs_root_xp ) );
    339     local_process->vfs_bin_xp  = hal_remote_lwd( XPTR( ref_cxy , &ref_ptr->vfs_bin_xp ) );
     345    local_process->vfs_root_xp = hal_remote_l64( XPTR( ref_cxy , &ref_ptr->vfs_root_xp ) );
     346    local_process->vfs_bin_xp  = hal_remote_l64( XPTR( ref_cxy , &ref_ptr->vfs_bin_xp ) );
    340347    local_process->vfs_cwd_xp  = XPTR_NULL;
    341348
     
    343350    xlist_root_init( XPTR( local_cxy , &local_process->children_root ) );
    344351    local_process->children_nr   = 0;
    345     remote_spinlock_init( XPTR( local_cxy , &local_process->children_lock ) );
     352    remote_queuelock_init( XPTR( local_cxy , &local_process->children_lock ),
     353                           LOCK_PROCESS_CHILDREN );
    346354
    347355    // reset children_list (not used in a process descriptor copy)
     
    354362    xlist_root_init( XPTR( local_cxy , &local_process->condvar_root ) );
    355363
    356     // reset th_tbl[] array as empty
     364    // initialize th_tbl[] array and associated fields
    357365    uint32_t i;
    358     for( i = 0 ; i < CONFIG_THREAD_MAX_PER_CLUSTER ; i++ )
     366    for( i = 0 ; i < CONFIG_THREADS_MAX_PER_CLUSTER ; i++ )
    359367        {
    360368        local_process->th_tbl[i] = NULL;
    361369    }
    362370    local_process->th_nr  = 0;
    363     spinlock_init( &local_process->th_lock );
     371    rwlock_init( &local_process->th_lock , LOCK_PROCESS_THTBL );
     372
    364373
    365374    // register new process descriptor in local cluster manager local_list
     
    374383cycle = (uint32_t)hal_get_cycles();
    375384if( DEBUG_PROCESS_COPY_INIT )
    376 printk("\n[DBG] %s : thread %x exit for process %x\n",
    377 __FUNCTION__ , CURRENT_THREAD , local_process->pid );
     385printk("\n[DBG] %s : thread %x in process %x exit for process %x / cycle %d\n",
     386__FUNCTION__, this->trdid, this->process->pid, local_process->pid, cycle );
    378387#endif
    379388
     
    399408uint32_t cycle = (uint32_t)hal_get_cycles();
    400409if( DEBUG_PROCESS_DESTROY )
    401 printk("\n[DBG] %s : thread %x enter for process %x in cluster %x / cycle %d\n",
    402 __FUNCTION__ , CURRENT_THREAD , pid , local_cxy , cycle );
     410printk("\n[DBG] %s : thread %x in process %x enter for process %x in cluster %x / cycle %d\n",
     411__FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, pid, local_cxy, cycle );
    403412#endif
    404413
     
    423432
    424433        // remove process from children_list
    425         remote_spinlock_lock( children_lock_xp );
     434        remote_queuelock_acquire( children_lock_xp );
    426435        xlist_unlink( XPTR( local_cxy , &process->children_list ) );
    427436            hal_remote_atomic_add( children_nr_xp , -1 );
    428         remote_spinlock_unlock( children_lock_xp );
    429 
    430     // release the process PID to cluster manager
    431     cluster_pid_release( pid );
    432 
    433     }
    434 
    435     // FIXME close all open files and update dirty [AG]
     437        remote_queuelock_release( children_lock_xp );
     438
     439        // release the process PID to cluster manager
     440        cluster_pid_release( pid );
     441    }
     442
     443    // FIXME close all open files and synchronize dirty [AG]
    436444
    437445    // decrease refcount for bin file, root file and cwd file
     
    449457cycle = (uint32_t)hal_get_cycles();
    450458if( DEBUG_PROCESS_DESTROY )
    451 printk("\n[DBG] %s : thread %x exit / destroyed process %x in cluster %x / cycle %d\n",
    452 __FUNCTION__ , CURRENT_THREAD , pid, local_cxy, cycle );
     459printk("\n[DBG] %s : thread %x in process %x exit / process %x in cluster %x / cycle %d\n",
     460__FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, pid, local_cxy, cycle );
    453461#endif
    454462
     
    491499    remote_nr = 0;
    492500
     501// check calling thread can yield
     502assert( (client->busylocks == 0),
     503"cannot yield : busylocks = %d\n", client->busylocks );
     504
    493505#if DEBUG_PROCESS_SIGACTION
    494506uint32_t cycle = (uint32_t)hal_get_cycles();
     
    517529
    518530    // The client thread send parallel RPCs to all remote clusters containing
    519     // target process copies, wait all responses, and then handles directly the
    520     // threads in local cluster, when required.
     531    // target process copies, wait all responses, and then handles directly
     532    // the threads in local cluster, when required.
    521533    // The client thread allocates a - shared - RPC descriptor in the stack,
    522534    // because all parallel, non-blocking, server threads use the same input
     
    529541    thread_block( client_xp , THREAD_BLOCKED_RPC );
    530542
    531     // take the lock protecting the copies
    532     remote_spinlock_lock( lock_xp );
     543    // take the lock protecting process copies
     544    remote_queuelock_acquire( lock_xp );
    533545
    534546    // initialize shared RPC descriptor
     
    573585
    574586    // release the lock protecting process copies
    575     remote_spinlock_unlock( lock_xp );
     587    remote_queuelock_release( lock_xp );
    576588
    577589    // restore IRQs
     
    620632    thread_t          * target;         // pointer on target thread
    621633    thread_t          * this;           // pointer on calling thread
    622     uint32_t            ltid;           // index in process th_tbl
     634    uint32_t            ltid;           // index in process th_tbl[]
    623635    cxy_t               owner_cxy;      // target process owner cluster
    624636    uint32_t            count;          // requests counter
     
    628640    this = CURRENT_THREAD;
    629641
     642#if DEBUG_PROCESS_SIGACTION
     643pid_t pid = process->pid;
     644uint32_t cycle = (uint32_t)hal_get_cycles();
     645if( DEBUG_PROCESS_SIGACTION < cycle )
     646printk("\n[DBG] %s : thread %x in process %x enter for process %x in cluster %x / cycle %d\n",
     647__FUNCTION__, this->trdid, this->process->pid, pid, local_cxy , cycle );
     648#endif
     649
     650// check target process is an user process
     651assert( ( process->pid != 0 ),
     652"target process must be an user process" );
     653
    630654    // get target process owner cluster
    631655    owner_cxy = CXY_FROM_PID( process->pid );
    632656
    633 #if DEBUG_PROCESS_SIGACTION
    634 uint32_t cycle = (uint32_t)hal_get_cycles();
    635 if( DEBUG_PROCESS_SIGACTION < cycle )
    636 printk("\n[DBG] %s : thread %x enter for process %x in cluster %x / cycle %d\n",
    637 __FUNCTION__ , this , process->pid , local_cxy , cycle );
    638 #endif
    639 
    640657    // get lock protecting process th_tbl[]
    641     spinlock_lock( &process->th_lock );
     658    rwlock_rd_acquire( &process->th_lock );
    642659
    643660    // loop on target process local threads
     
    680697
    681698    // release lock protecting process th_tbl[]
    682     spinlock_unlock( &process->th_lock );
    683 
    684     // wait acknowledges
     699    rwlock_rd_release( &process->th_lock );
     700
     701    // busy waiting acknowledges
     702    // TODO this could be improved...
    685703    while( 1 )
    686704    {
     
    695713cycle = (uint32_t)hal_get_cycles();
    696714if( DEBUG_PROCESS_SIGACTION < cycle )
    697 printk("\n[DBG] %s : thread %x exit for process %x in cluster %x / cycle %d\n",
    698 __FUNCTION__ , this , process->pid , local_cxy , cycle );
     715printk("\n[DBG] %s : thread %x in process %x exit for process %x in cluster %x / cycle %d\n",
     716__FUNCTION__, this, this->process->pid, pid, local_cxy , cycle );
    699717#endif
    700718
     
    719737
    720738#if DEBUG_PROCESS_SIGACTION
     739pid_t pid = process->pid;
    721740uint32_t cycle = (uint32_t)hal_get_cycles();
    722741if( DEBUG_PROCESS_SIGACTION < cycle )
    723 printk("\n[DBG] %s : thread %x enter for process %x in cluster %x / cycle %d\n",
    724 __FUNCTION__ , this , process->pid , local_cxy , cycle );
    725 #endif
     742printk("\n[DBG] %s : thread %x n process %x enter for process %x in cluster %x / cycle %d\n",
     743__FUNCTION__, this->trdid, this->process->pid, pid, local_cxy , cycle );
     744#endif
     745
     746// check target process is an user process
     747assert( ( process->pid != 0 ),
     748"target process must be an user process" );
    726749
    727750    // get lock protecting process th_tbl[]
    728     spinlock_lock( &process->th_lock );
     751    rwlock_rd_acquire( &process->th_lock );
    729752
    730753    // loop on target process local threads                       
     
    739762            target_xp = XPTR( local_cxy , target );
    740763
    741             // main thread and client thread should not be blocked
     764            // main thread and client thread should not be deleted
    742765            if( ((ltid != 0) || (owner_cxy != local_cxy)) &&         // not main thread
    743766                (client_xp) != target_xp )                           // not client thread
     
    750773
    751774    // release lock protecting process th_tbl[]
    752     spinlock_unlock( &process->th_lock );
     775    rwlock_rd_release( &process->th_lock );
    753776
    754777#if DEBUG_PROCESS_SIGACTION
    755778cycle = (uint32_t)hal_get_cycles();
    756779if( DEBUG_PROCESS_SIGACTION < cycle )
    757 printk("\n[DBG] %s : thread %x exit for process %x in cluster %x / cycle %d\n",
    758 __FUNCTION__ , this , process->pid , local_cxy , cycle );
     780printk("\n[DBG] %s : thread %x in process %x exit for process %x in cluster %x / cycle %d\n",
     781__FUNCTION__, this->trdid, this->process->pid, pid, local_cxy , cycle );
    759782#endif
    760783
     
    773796
    774797#if DEBUG_PROCESS_SIGACTION
     798pid_t pid = process->pid;
    775799uint32_t cycle = (uint32_t)hal_get_cycles();
    776800if( DEBUG_PROCESS_SIGACTION < cycle )
    777 printk("\n[DBG] %s : thread %x enter for process %x in cluster %x / cycle %d\n",
    778 __FUNCTION__ , this , process->pid , local_cxy , cycle );
    779 #endif
     801printk("\n[DBG] %s : thread %x in process %x enter for process %x in cluster %x / cycle %d\n",
     802__FUNCTION__, this->trdid, this->process->pid, pid, local_cxy , cycle );
     803#endif
     804
     805// check target process is an user process
     806assert( ( process->pid != 0 ),
     807"target process must be an user process" );
    780808
    781809    // get lock protecting process th_tbl[]
    782     spinlock_lock( &process->th_lock );
     810    rwlock_rd_acquire( &process->th_lock );
    783811
    784812    // loop on process threads to unblock all threads
     
    798826
    799827    // release lock protecting process th_tbl[]
    800     spinlock_unlock( &process->th_lock );
     828    rwlock_rd_release( &process->th_lock );
    801829
    802830#if DEBUG_PROCESS_SIGACTION
    803831cycle = (uint32_t)hal_get_cycles();
    804832if( DEBUG_PROCESS_SIGACTION < cycle )
    805 printk("\n[DBG] %s : thread %x exit for process %x in cluster %x / cycle %d\n",
    806 __FUNCTION__ , this , process->pid , local_cxy , cycle );
     833printk("\n[DBG] %s : thread %x in process %x exit for process %x in cluster %x / cycle %d\n",
     834__FUNCTION__, this->trdid, this->process->pid, pid, local_cxy, cycle );
    807835#endif
    808836
     
    818846    cluster_t * cluster = LOCAL_CLUSTER;
    819847
     848#if DEBUG_PROCESS_GET_LOCAL_COPY
     849thread_t * this = CURRENT_THREAD;
     850uint32_t cycle = (uint32_t)hal_get_cycles();
     851if( DEBUG_PROCESS_GET_LOCAL_COPY < cycle )
     852printk("\n[DBG] %s : thread %x in cluster %x enter for process %x in cluster %x / cycle %d\n",
     853__FUNCTION__, this->trdid, this->process->pid, pid, local_cxy, cycle );
     854#endif
     855
    820856    // get lock protecting local list of processes
    821     remote_spinlock_lock( XPTR( local_cxy , &cluster->pmgr.local_lock ) );
     857    remote_queuelock_acquire( XPTR( local_cxy , &cluster->pmgr.local_lock ) );
    822858
    823859    // scan the local list of process descriptors to find the process
     
    836872
    837873    // release lock protecting local list of processes
    838     remote_spinlock_unlock( XPTR( local_cxy , &cluster->pmgr.local_lock ) );
     874    remote_queuelock_release( XPTR( local_cxy , &cluster->pmgr.local_lock ) );
    839875
    840876    // allocate memory for a new local process descriptor
     
    859895
    860896#if DEBUG_PROCESS_GET_LOCAL_COPY
    861 uint32_t cycle = (uint32_t)hal_get_cycles();
     897cycle = (uint32_t)hal_get_cycles();
    862898if( DEBUG_PROCESS_GET_LOCAL_COPY < cycle )
    863 printk("\n[DBG] %s : enter in cluster %x / pid %x / process %x / cycle %d\n",
    864 __FUNCTION__ , local_cxy , pid , process_ptr , cycle );
     899printk("\n[DBG] %s : thread %x in cluster %x exit in cluster %x / process %x / cycle %d\n",
     900__FUNCTION__, this->trdid, this->process->pid, local_cxy, process_ptr, cycle );
    865901#endif
    866902
     
    883919
    884920    // get pointers on parent process
    885     parent_xp  = (xptr_t)hal_remote_lwd( XPTR( process_cxy , &process_ptr->parent_xp ) );
     921    parent_xp  = (xptr_t)hal_remote_l64( XPTR( process_cxy , &process_ptr->parent_xp ) );
    886922    parent_cxy = GET_CXY( parent_xp );
    887923    parent_ptr = GET_PTR( parent_xp );
    888924
    889     return hal_remote_lw( XPTR( parent_cxy , &parent_ptr->pid ) );
     925    return hal_remote_l32( XPTR( parent_cxy , &parent_ptr->pid ) );
    890926}
    891927
     
    899935    uint32_t fd;
    900936
    901     remote_spinlock_init( XPTR( local_cxy , &process->fd_array.lock ) );
     937    remote_queuelock_init( XPTR( local_cxy , &process->fd_array.lock ), LOCK_PROCESS_FDARRAY );
    902938
    903939    process->fd_array.current = 0;
     
    909945    }
    910946}
    911 
    912 //////////////////////////////
    913 bool_t process_fd_array_full( void )
    914 {
    915     // get extended pointer on reference process
    916     xptr_t ref_xp = CURRENT_THREAD->process->ref_xp;
    917 
    918     // get reference process cluster and local pointer
    919     process_t * ref_ptr = GET_PTR( ref_xp );
    920     cxy_t       ref_cxy = GET_CXY( ref_xp );
    921 
    922     // get number of open file descriptors from reference fd_array
    923     uint32_t current = hal_remote_lw( XPTR( ref_cxy , &ref_ptr->fd_array.current ) );
    924 
    925         return ( current >= CONFIG_PROCESS_FILE_MAX_NR );
    926 }
    927 
    928947/////////////////////////////////////////////////
    929948error_t process_fd_register( process_t * process,
     
    933952    bool_t    found;
    934953    uint32_t  id;
     954    uint32_t  count;
    935955    xptr_t    xp;
    936956
     
    941961
    942962    // take lock protecting reference fd_array
    943         remote_spinlock_lock( XPTR( ref_cxy , &ref_ptr->fd_array.lock ) );
     963        remote_queuelock_acquire( XPTR( ref_cxy , &ref_ptr->fd_array.lock ) );
    944964
    945965    found   = false;
     
    947967    for ( id = 0; id < CONFIG_PROCESS_FILE_MAX_NR ; id++ )
    948968    {
    949         xp = hal_remote_lwd( XPTR( ref_cxy , &ref_ptr->fd_array.array[id] ) );
     969        xp = hal_remote_l64( XPTR( ref_cxy , &ref_ptr->fd_array.array[id] ) );
    950970        if ( xp == XPTR_NULL )
    951971        {
     972            // update reference fd_array
     973            hal_remote_s64( XPTR( ref_cxy , &ref_ptr->fd_array.array[id] ) , file_xp );
     974                count = hal_remote_l32( XPTR( ref_cxy , &ref_ptr->fd_array.current ) ) + 1;
     975            hal_remote_s32( XPTR( ref_cxy , &ref_ptr->fd_array.current ) , count );
     976
     977            // update local fd_array copy if required
     978            if( ref_cxy != local_cxy )
     979            {
     980                process->fd_array.array[id] = file_xp;
     981                process->fd_array.current   = count;
     982            }
     983
     984            // exit
     985                        *fdid = id;
    952986            found = true;
    953             hal_remote_swd( XPTR( ref_cxy , &ref_ptr->fd_array.array[id] ) , file_xp );
    954                 hal_remote_atomic_add( XPTR( ref_cxy , &ref_ptr->fd_array.current ) , 1 );
    955                         *fdid = id;
    956987            break;
    957988        }
     
    959990
    960991    // release lock protecting reference fd_array
    961         remote_spinlock_unlock( XPTR( ref_cxy , &ref_ptr->fd_array.lock ) );
     992        remote_queuelock_release( XPTR( ref_cxy , &ref_ptr->fd_array.lock ) );
    962993
    963994    if ( !found ) return -1;
     
    9701001{
    9711002    xptr_t  file_xp;
     1003    xptr_t  lock_xp;
    9721004
    9731005    // access local copy of process descriptor
     
    9811013        process_t * ref_ptr = GET_PTR( ref_xp );
    9821014
     1015        // build extended pointer on lock protecting reference fd_array
     1016        lock_xp = XPTR( ref_cxy , &ref_ptr->fd_array.lock );
     1017
     1018        // take lock protecting reference fd_array
     1019            remote_queuelock_acquire( lock_xp );
     1020
    9831021        // access reference process descriptor
    984         file_xp = hal_remote_lwd( XPTR( ref_cxy , &ref_ptr->fd_array.array[fdid] ) );
     1022        file_xp = hal_remote_l64( XPTR( ref_cxy , &ref_ptr->fd_array.array[fdid] ) );
    9851023
    9861024        // update local fd_array if found
    987         if( file_xp != XPTR_NULL )
    988         {
    989             process->fd_array.array[fdid] = file_xp;
    990         }
     1025        if( file_xp != XPTR_NULL )  process->fd_array.array[fdid] = file_xp;
     1026       
     1027        // release lock protecting reference fd_array
     1028            remote_queuelock_release( lock_xp );
    9911029    }
    9921030
     
    10111049
    10121050    // get the remote lock protecting the src fd_array
    1013         remote_spinlock_lock( XPTR( src_cxy , &src_ptr->lock ) );
     1051        remote_queuelock_acquire( XPTR( src_cxy , &src_ptr->lock ) );
    10141052
    10151053    // loop on all fd_array entries
    10161054    for( fd = 0 ; fd < CONFIG_PROCESS_FILE_MAX_NR ; fd++ )
    10171055        {
    1018                 entry = (xptr_t)hal_remote_lwd( XPTR( src_cxy , &src_ptr->array[fd] ) );
     1056                entry = (xptr_t)hal_remote_l64( XPTR( src_cxy , &src_ptr->array[fd] ) );
    10191057
    10201058                if( entry != XPTR_NULL )
     
    10241062
    10251063                        // copy entry in destination process fd_array
    1026                         hal_remote_swd( XPTR( dst_cxy , &dst_ptr->array[fd] ) , entry );
     1064                        hal_remote_s64( XPTR( dst_cxy , &dst_ptr->array[fd] ) , entry );
    10271065                }
    10281066        }
    10291067
    10301068    // release lock on source process fd_array
    1031         remote_spinlock_unlock( XPTR( src_cxy , &src_ptr->lock ) );
     1069        remote_queuelock_release( XPTR( src_cxy , &src_ptr->lock ) );
    10321070
    10331071}  // end process_fd_remote_copy()
     1072
     1073
     1074////////////////////////////////////
     1075bool_t process_fd_array_full( void )
     1076{
     1077    // get extended pointer on reference process
     1078    xptr_t ref_xp = CURRENT_THREAD->process->ref_xp;
     1079
     1080    // get reference process cluster and local pointer
     1081    process_t * ref_ptr = GET_PTR( ref_xp );
     1082    cxy_t       ref_cxy = GET_CXY( ref_xp );
     1083
     1084    // get number of open file descriptors from reference fd_array
     1085    uint32_t current = hal_remote_l32( XPTR( ref_cxy , &ref_ptr->fd_array.current ) );
     1086
     1087        return ( current >= CONFIG_PROCESS_FILE_MAX_NR );
     1088}
     1089
    10341090
    10351091////////////////////////////////////////////////////////////////////////////////////
     
    10431099{
    10441100    ltid_t         ltid;
    1045     reg_t          save_sr;
    10461101    bool_t         found = false;
    10471102 
    1048 
    1049     assert( (process != NULL) , "process argument is NULL" );
    1050 
    1051     assert( (thread != NULL) , "thread argument is NULL" );
    1052 
    1053     // take lock protecting th_tbl, depending on thread type:
    1054     // we don't want to use a descheduling policy for idle thread initialisation
    1055     if ( thread->type == THREAD_IDLE ) {
    1056         spinlock_lock_busy( &process->th_lock , &save_sr );
    1057     } else {
    1058         spinlock_lock( &process->th_lock );
    1059     }
    1060 
    1061     // search a free slot in th_tbl[]
    1062     for( ltid = 0 ; ltid < CONFIG_THREAD_MAX_PER_CLUSTER ; ltid++ )
     1103// check arguments
     1104assert( (process != NULL) , "process argument is NULL" );
     1105assert( (thread != NULL) , "thread argument is NULL" );
     1106
     1107    // get the lock protecting th_tbl for all threads
     1108    // but the idle thread executing kernel_init (cannot yield)
     1109    if( thread->type != THREAD_IDLE ) rwlock_wr_acquire( &process->th_lock );
     1110
     1111    // scan kth_tbl
     1112    for( ltid = 0 ; ltid < CONFIG_THREADS_MAX_PER_CLUSTER ; ltid++ )
    10631113    {
    10641114        if( process->th_tbl[ltid] == NULL )
     
    10791129    }
    10801130
    1081     // release lock protecting th_tbl
    1082     hal_fence();
    1083     if( thread->type == THREAD_IDLE ) {
    1084         spinlock_unlock_busy( &process->th_lock , save_sr );
    1085     } else {
    1086         spinlock_unlock( &process->th_lock );
    1087     }
    1088 
    1089     return (found) ? 0 : ENOMEM;
     1131    // get the lock protecting th_tbl for all threads
     1132    // but the idle thread executing kernel_init (cannot yield)
     1133    if( thread->type != THREAD_IDLE ) rwlock_wr_release( &process->th_lock );
     1134
     1135    return (found) ? 0 : 0xFFFFFFFF;
    10901136
    10911137}  // end process_register_thread()
     
    10961142    uint32_t count;  // number of threads in local process descriptor
    10971143
    1098     assert( (thread != NULL) , "thread argument is NULL" );
     1144// check argument
     1145assert( (thread != NULL) , "thread argument is NULL" );
    10991146
    11001147    process_t * process = thread->process;
     
    11021149    // get thread local index
    11031150    ltid_t  ltid = LTID_FROM_TRDID( thread->trdid );
    1104 
    1105     // take lock protecting th_tbl
    1106     spinlock_lock( &process->th_lock );
    1107 
     1151   
     1152    // the lock depends on thread user/kernel type, because we cannot
     1153    // use a descheduling policy for the lock protecting the kth_tbl
     1154
     1155    // get the lock protecting th_tbl[]
     1156    rwlock_wr_acquire( &process->th_lock );
     1157
     1158    // get number of kernel threads
    11081159    count = process->th_nr;
    11091160
    1110     assert( (count > 0) , "process th_nr cannot be 0\n" );
     1161// check th_nr value
     1162assert( (count > 0) , "process kth_nr cannot be 0\n" );
    11111163
    11121164    // remove thread from th_tbl[]
     
    11141166    process->th_nr = count-1;
    11151167
    1116     // release lock protecting th_tbl
    1117     hal_fence();
    1118     spinlock_unlock( &process->th_lock );
     1168    // release lock protecting kth_tbl
     1169    rwlock_wr_release( &process->th_lock );
    11191170
    11201171    return (count == 1);
     
    11411192
    11421193    // get parent process PID and extended pointer on .elf file
    1143     parent_pid = hal_remote_lw (XPTR( parent_process_cxy , &parent_process_ptr->pid));
    1144     vfs_bin_xp = hal_remote_lwd(XPTR( parent_process_cxy , &parent_process_ptr->vfs_bin_xp));
    1145 
    1146     // check parent process is the reference process
    1147     ref_xp = hal_remote_lwd( XPTR( parent_process_cxy , &parent_process_ptr->ref_xp ) );
    1148 
    1149     assert( (parent_process_xp == ref_xp ) ,
    1150     "parent process must be the reference process\n" );
     1194    parent_pid = hal_remote_l32 (XPTR( parent_process_cxy , &parent_process_ptr->pid));
     1195    vfs_bin_xp = hal_remote_l64(XPTR( parent_process_cxy , &parent_process_ptr->vfs_bin_xp));
     1196
     1197    // get extended pointer on reference process
     1198    ref_xp = hal_remote_l64( XPTR( parent_process_cxy , &parent_process_ptr->ref_xp ) );
     1199
     1200// check parent process is the reference process
     1201assert( (parent_process_xp == ref_xp ) ,
     1202"parent process must be the reference process\n" );
    11511203
    11521204#if DEBUG_PROCESS_MAKE_FORK
     
    11951247#endif
    11961248
    1197     // give TXT ownership to child process
    1198     process_txt_set_ownership( XPTR( local_cxy , process ) );
    11991249
    12001250    // copy VMM from parent descriptor to child descriptor
     
    12181268#endif
    12191269
    1220     // parent process gives TXT ownership to child process if required
    1221     if( process_txt_is_owner(parent_process_xp) )
     1270    // if parent_process is INIT, or if parent_process is the TXT owner,
     1271    // the child_process becomes the owner of its TXT terminal
     1272    if( (parent_pid == 1) || process_txt_is_owner( parent_process_xp ) )
    12221273    {
    12231274        process_txt_set_ownership( XPTR( local_cxy , process ) );
     
    12261277cycle = (uint32_t)hal_get_cycles();
    12271278if( DEBUG_PROCESS_MAKE_EXEC < cycle )
    1228 printk("\n[DBG] %s : thread %x in process %x gives TXT from parent %x to child %x / cycle %d\n",
    1229 __FUNCTION__ , CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid,
    1230 parent_pid, new_pid, cycle );
     1279printk("\n[DBG] %s : thread %x in process %x / child takes TXT ownership / cycle %d\n",
     1280__FUNCTION__ , CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, cycle );
    12311281#endif
    12321282
     
    12491299    }
    12501300
    1251     // check main thread LTID
    1252     assert( (LTID_FROM_TRDID(thread->trdid) == 0) ,
    1253     "main thread must have LTID == 0\n" );
    1254 
    1255 //#if( DEBUG_PROCESS_MAKE_FORK & 1 )
    1256 #if DEBUG_PROCESS_MAKE_FORK
     1301// check main thread LTID
     1302assert( (LTID_FROM_TRDID(thread->trdid) == 0) ,
     1303"main thread must have LTID == 0\n" );
     1304
     1305#if( DEBUG_PROCESS_MAKE_FORK & 1 )
    12571306cycle = (uint32_t)hal_get_cycles();
    12581307if( DEBUG_PROCESS_MAKE_FORK < cycle )
     
    12891338
    12901339    // register process in parent children list
    1291     remote_spinlock_lock( children_lock_xp );
     1340    remote_queuelock_acquire( children_lock_xp );
    12921341        xlist_add_last( children_root_xp , XPTR( local_cxy , &process->children_list ) );
    12931342        hal_remote_atomic_add( children_nr_xp , 1 );
    1294     remote_spinlock_unlock( children_lock_xp );
     1343    remote_queuelock_release( children_lock_xp );
    12951344
    12961345    // return success
     
    13411390    // open the file identified by <path>
    13421391    file_xp = XPTR_NULL;
    1343     file_id = -1;
     1392    file_id = 0xFFFFFFFF;
    13441393        error   = vfs_open( process,
    13451394                            path,
     
    14421491uint32_t cycle = (uint32_t)hal_get_cycles();
    14431492if( DEBUG_PROCESS_ZERO_CREATE < cycle )
    1444 printk("\n[DBG] %s : thread %x enter / cycle %d\n", __FUNCTION__, CURRENT_THREAD, cycle );
     1493printk("\n[DBG] %s : enter / cluster %x / cycle %d\n",
     1494__FUNCTION__, local_cxy, cycle );
    14451495#endif
    14461496
     
    14521502    process->term_state = 0;
    14531503
    1454     // reset th_tbl[] array as empty
     1504    // reset th_tbl[] array and associated fields
    14551505    uint32_t i;
    1456     for( i = 0 ; i < CONFIG_THREAD_MAX_PER_CLUSTER ; i++ )
     1506    for( i = 0 ; i < CONFIG_THREADS_MAX_PER_CLUSTER ; i++ )
    14571507        {
    14581508        process->th_tbl[i] = NULL;
    14591509    }
    14601510    process->th_nr  = 0;
    1461     spinlock_init( &process->th_lock );
     1511    rwlock_init( &process->th_lock , LOCK_PROCESS_THTBL );
     1512
    14621513
    14631514    // reset children list as empty
    14641515    xlist_root_init( XPTR( local_cxy , &process->children_root ) );
    1465     remote_spinlock_init( XPTR( local_cxy , &process->children_lock ) );
    14661516    process->children_nr = 0;
     1517    remote_queuelock_init( XPTR( local_cxy , &process->children_lock ),
     1518                           LOCK_PROCESS_CHILDREN );
    14671519
    14681520        hal_fence();
     
    14711523cycle = (uint32_t)hal_get_cycles();
    14721524if( DEBUG_PROCESS_ZERO_CREATE < cycle )
    1473 printk("\n[DBG] %s : thread %x exit / cycle %d\n", __FUNCTION__, CURRENT_THREAD, cycle );
     1525printk("\n[DBG] %s : exit / cluster %x / cycle %d\n",
     1526__FUNCTION__, local_cxy, cycle );
    14741527#endif
    14751528
    14761529}  // end process_zero_init()
    14771530
    1478 //////////////////////////
     1531////////////////////////////////
    14791532void process_init_create( void )
    14801533{
     
    14981551        process = process_alloc();
    14991552       
    1500     assert( (process != NULL),
    1501     "no memory for process descriptor in cluster %x\n", local_cxy  );
     1553// check memory allocator
     1554assert( (process != NULL),
     1555"no memory for process descriptor in cluster %x\n", local_cxy  );
    15021556
    15031557    // get PID from local cluster
    15041558    error = cluster_pid_alloc( process , &pid );
    15051559
    1506     assert( (error == 0),
    1507     "cannot allocate PID in cluster %x\n", local_cxy );
    1508 
    1509     assert( (pid == 1) ,
    1510     "process INIT must be first process in cluster 0\n" );
     1560// check PID allocator
     1561assert( (error == 0),
     1562"cannot allocate PID in cluster %x\n", local_cxy );
     1563
     1564// check PID value
     1565assert( (pid == 1) ,
     1566"process INIT must be first process in cluster 0\n" );
    15111567
    15121568    // initialize process descriptor / parent is local process_zero
     
    15141570                            pid,
    15151571                            XPTR( local_cxy , &process_zero ) ); 
     1572
     1573#if(DEBUG_PROCESS_INIT_CREATE & 1)
     1574if( DEBUG_PROCESS_INIT_CREATE < cycle )
     1575printk("\n[DBG] %s : thread %x in process %x initialized process descriptor\n",
     1576__FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid );
     1577#endif
    15161578
    15171579    // open the file identified by CONFIG_PROCESS_INIT_PATH
     
    15251587                            &file_id );
    15261588
    1527         assert( (error == 0),
    1528     "failed to open file <%s>\n", CONFIG_PROCESS_INIT_PATH );
    1529 
    1530     // register "code" and "data" vsegs as well as entry-point
     1589assert( (error == 0),
     1590"failed to open file <%s>\n", CONFIG_PROCESS_INIT_PATH );
     1591
     1592#if(DEBUG_PROCESS_INIT_CREATE & 1)
     1593if( DEBUG_PROCESS_INIT_CREATE < cycle )
     1594printk("\n[DBG] %s : thread %x in process %x open .elf file decriptor\n",
     1595__FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid );
     1596#endif
     1597
     1598   // register "code" and "data" vsegs as well as entry-point
    15311599    // in process VMM, using information contained in the elf file.
    15321600        error = elf_load_process( file_xp , process );
    15331601
    1534         assert( (error == 0),
    1535     "cannot access .elf file <%s>\n", CONFIG_PROCESS_INIT_PATH );
     1602assert( (error == 0),
     1603"cannot access .elf file <%s>\n", CONFIG_PROCESS_INIT_PATH );
     1604
     1605#if(DEBUG_PROCESS_INIT_CREATE & 1)
     1606if( DEBUG_PROCESS_INIT_CREATE < cycle )
     1607printk("\n[DBG] %s : thread %x in process %x registered code/data vsegs in VMM\n",
     1608__FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid );
     1609#endif
    15361610
    15371611    // get extended pointers on process_zero children_root, children_lock
     
    15391613    xptr_t children_lock_xp = XPTR( local_cxy , &process_zero.children_lock );
    15401614
     1615    // take lock protecting kernel process children list
     1616    remote_queuelock_acquire( children_lock_xp );
     1617
    15411618    // register process INIT in parent local process_zero
    1542     remote_spinlock_lock( children_lock_xp );
    15431619        xlist_add_last( children_root_xp , XPTR( local_cxy , &process->children_list ) );
    15441620        hal_atomic_add( &process_zero.children_nr , 1 );
    1545     remote_spinlock_unlock( children_lock_xp );
     1621
     1622    // release lock protecting kernel process children list
     1623    remote_queuelock_release( children_lock_xp );
     1624
     1625#if(DEBUG_PROCESS_INIT_CREATE & 1)
     1626if( DEBUG_PROCESS_INIT_CREATE < cycle )
     1627printk("\n[DBG] %s : thread %x in process %x registered init process in parent\n",
     1628__FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid );
     1629#endif
    15461630
    15471631    // select a core in local cluster to execute the main thread
     
    15601644                                &thread );
    15611645
    1562         assert( (error == 0),
    1563     "cannot create main thread for <%s>\n", CONFIG_PROCESS_INIT_PATH );
    1564 
    1565     assert( (thread->trdid == 0),
    1566     "main thread must have index 0 for <%s>\n", CONFIG_PROCESS_INIT_PATH );
     1646assert( (error == 0),
     1647"cannot create main thread for <%s>\n", CONFIG_PROCESS_INIT_PATH );
     1648
     1649assert( (thread->trdid == 0),
     1650"main thread must have index 0 for <%s>\n", CONFIG_PROCESS_INIT_PATH );
     1651
     1652#if(DEBUG_PROCESS_INIT_CREATE & 1)
     1653if( DEBUG_PROCESS_INIT_CREATE < cycle )
     1654printk("\n[DBG] %s : thread %x in process %x created main thread\n",
     1655__FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid );
     1656#endif
    15671657
    15681658    // activate thread
     
    16181708
    16191709    // get PID and state
    1620     pid   = hal_remote_lw( XPTR( process_cxy , &process_ptr->pid ) );
    1621     state = hal_remote_lw( XPTR( process_cxy , &process_ptr->term_state ) );
     1710    pid   = hal_remote_l32( XPTR( process_cxy , &process_ptr->pid ) );
     1711    state = hal_remote_l32( XPTR( process_cxy , &process_ptr->term_state ) );
    16221712
    16231713    // get PPID
    1624     parent_xp  = hal_remote_lwd( XPTR( process_cxy , &process_ptr->parent_xp ) );
     1714    parent_xp  = hal_remote_l64( XPTR( process_cxy , &process_ptr->parent_xp ) );
    16251715    parent_cxy = GET_CXY( parent_xp );
    16261716    parent_ptr = GET_PTR( parent_xp );
    1627     ppid       = hal_remote_lw( XPTR( parent_cxy , &parent_ptr->pid ) );
     1717    ppid       = hal_remote_l32( XPTR( parent_cxy , &parent_ptr->pid ) );
    16281718
    16291719    // get number of threads
    1630     th_nr      = hal_remote_lw( XPTR( process_cxy , &process_ptr->th_nr ) );
     1720    th_nr      = hal_remote_l32( XPTR( process_cxy , &process_ptr->th_nr ) );
    16311721
    16321722    // get pointers on owner process descriptor
    1633     owner_xp  = hal_remote_lwd( XPTR( process_cxy , &process_ptr->owner_xp ) );
     1723    owner_xp  = hal_remote_l64( XPTR( process_cxy , &process_ptr->owner_xp ) );
    16341724    owner_cxy = GET_CXY( owner_xp );
    16351725    owner_ptr = GET_PTR( owner_xp );
    16361726
    16371727    // get extended pointer on TXT_RX file descriptor attached to process
    1638     txt_file_xp = hal_remote_lwd( XPTR( owner_cxy , &owner_ptr->fd_array.array[0] ) );
     1728    txt_file_xp = hal_remote_l64( XPTR( owner_cxy , &owner_ptr->fd_array.array[0] ) );
    16391729
    16401730    assert( (txt_file_xp != XPTR_NULL) ,
     
    16501740                       XPTR( txt_chdev_cxy , txt_chdev_ptr->name ) );
    16511741   
    1652     txt_owner_xp = (xptr_t)hal_remote_lwd( XPTR( txt_chdev_cxy,
     1742    txt_owner_xp = (xptr_t)hal_remote_l64( XPTR( txt_chdev_cxy,
    16531743                                                 &txt_chdev_ptr->ext.txt.owner_xp ) );
    16541744   
    16551745    // get process .elf name
    1656     elf_file_xp   = hal_remote_lwd( XPTR( process_cxy , &process_ptr->vfs_bin_xp ) );
     1746    elf_file_xp   = hal_remote_l64( XPTR( process_cxy , &process_ptr->vfs_bin_xp ) );
    16571747    elf_file_cxy  = GET_CXY( elf_file_xp );
    16581748    elf_file_ptr  = (vfs_file_t *)GET_PTR( elf_file_xp );
     
    17181808    xptr_t      lock_xp;      // extended pointer on list lock in chdev
    17191809
    1720     // check process is in owner cluster
    1721     assert( (CXY_FROM_PID( process->pid ) == local_cxy) ,
    1722     "process descriptor not in owner cluster" );
    1723 
    1724     // check terminal index
    1725     assert( (txt_id < LOCAL_CLUSTER->nb_txt_channels) ,
    1726     "illegal TXT terminal index" );
     1810// check process is in owner cluster
     1811assert( (CXY_FROM_PID( process->pid ) == local_cxy) ,
     1812"process descriptor not in owner cluster" );
     1813
     1814// check terminal index
     1815assert( (txt_id < LOCAL_CLUSTER->nb_txt_channels) ,
     1816"illegal TXT terminal index" );
    17271817
    17281818    // get pointers on TXT_RX[txt_id] chdev
     
    17351825    lock_xp = XPTR( chdev_cxy , &chdev_ptr->ext.txt.lock );
    17361826
     1827    // get lock protecting list of processes attached to TXT
     1828    remote_busylock_acquire( lock_xp );
     1829
    17371830    // insert process in attached process list
    1738     remote_spinlock_lock( lock_xp );
    17391831    xlist_add_last( root_xp , XPTR( local_cxy , &process->txt_list ) );
    1740     remote_spinlock_unlock( lock_xp );
     1832
     1833    // release lock protecting list of processes attached to TXT
     1834    remote_busylock_release( lock_xp );
    17411835
    17421836#if DEBUG_PROCESS_TXT
     
    17651859    process_cxy = GET_CXY( process_xp );
    17661860    process_ptr = GET_PTR( process_xp );
    1767 
    1768     // check process descriptor in owner cluster
    1769     process_pid = hal_remote_lw( XPTR( process_cxy , &process_ptr->pid ) );
    1770     assert( (CXY_FROM_PID( process_pid ) == process_cxy ) ,
    1771     "process descriptor not in owner cluster" );
     1861    process_pid = hal_remote_l32( XPTR( process_cxy , &process_ptr->pid ) );
     1862
     1863// check process descriptor in owner cluster
     1864assert( (CXY_FROM_PID( process_pid ) == process_cxy ) ,
     1865"process descriptor not in owner cluster" );
    17721866
    17731867    // release TXT ownership (does nothing if not TXT owner)
     
    17751869
    17761870    // get extended pointer on process stdin file
    1777     file_xp = (xptr_t)hal_remote_lwd( XPTR( process_cxy , &process_ptr->fd_array.array[0] ) );
     1871    file_xp = (xptr_t)hal_remote_l64( XPTR( process_cxy , &process_ptr->fd_array.array[0] ) );
    17781872
    17791873    // get pointers on TXT_RX chdev
     
    17851879    lock_xp = XPTR( chdev_cxy , &chdev_ptr->ext.txt.lock );
    17861880
     1881    // get lock protecting list of processes attached to TXT
     1882    remote_busylock_acquire( lock_xp );
     1883
    17871884    // unlink process from attached process list
    1788     remote_spinlock_lock( lock_xp );
    17891885    xlist_unlink( XPTR( process_cxy , &process_ptr->txt_list ) );
    1790     remote_spinlock_unlock( lock_xp );
     1886
     1887    // release lock protecting list of processes attached to TXT
     1888    remote_busylock_release( lock_xp );
    17911889
    17921890#if DEBUG_PROCESS_TXT
    17931891uint32_t cycle  = (uint32_t)hal_get_cycles();
    1794 uint32_t txt_id = hal_remote_lw( XPTR( chdev_cxy , &chdev_ptr->channel ) );
     1892uint32_t txt_id = hal_remote_l32( XPTR( chdev_cxy , &chdev_ptr->channel ) );
    17951893if( DEBUG_PROCESS_TXT < cycle )
    17961894printk("\n[DBG] %s : thread %x in process %x detached process %x from TXT %d / cycle %d\n",
     
    18151913    process_cxy = GET_CXY( process_xp );
    18161914    process_ptr = GET_PTR( process_xp );
    1817     process_pid = hal_remote_lw( XPTR( process_cxy , &process_ptr->pid ) );
     1915    process_pid = hal_remote_l32( XPTR( process_cxy , &process_ptr->pid ) );
    18181916
    18191917    // check owner cluster
     
    18221920
    18231921    // get extended pointer on stdin pseudo file
    1824     file_xp = hal_remote_lwd( XPTR( process_cxy , &process_ptr->fd_array.array[0] ) );
     1922    file_xp = hal_remote_l64( XPTR( process_cxy , &process_ptr->fd_array.array[0] ) );
    18251923
    18261924    // get pointers on TXT chdev
     
    18301928
    18311929    // set owner field in TXT chdev
    1832     hal_remote_swd( XPTR( txt_cxy , &txt_ptr->ext.txt.owner_xp ) , process_xp );
     1930    hal_remote_s64( XPTR( txt_cxy , &txt_ptr->ext.txt.owner_xp ) , process_xp );
    18331931
    18341932#if DEBUG_PROCESS_TXT
    18351933uint32_t cycle  = (uint32_t)hal_get_cycles();
    1836 uint32_t txt_id = hal_remote_lw( XPTR( txt_cxy , &txt_ptr->channel ) );
     1934uint32_t txt_id = hal_remote_l32( XPTR( txt_cxy , &txt_ptr->channel ) );
    18371935if( DEBUG_PROCESS_TXT < cycle )
    18381936printk("\n[DBG] %s : thread %x in process %x give TXT %d to process %x / cycle %d\n",
     
    18681966    process_cxy = GET_CXY( process_xp );
    18691967    process_ptr = GET_PTR( process_xp );
    1870     process_pid = hal_remote_lw( XPTR( process_cxy , &process_ptr->pid ) );
     1968    process_pid = hal_remote_l32( XPTR( process_cxy , &process_ptr->pid ) );
    18711969
    18721970    // check owner cluster
     
    18751973
    18761974    // get extended pointer on stdin pseudo file
    1877     file_xp = hal_remote_lwd( XPTR( process_cxy , &process_ptr->fd_array.array[0] ) );
     1975    file_xp = hal_remote_l64( XPTR( process_cxy , &process_ptr->fd_array.array[0] ) );
    18781976
    18791977    // get pointers on TXT chdev
     
    18831981
    18841982    // get extended pointer on TXT_RX owner and TXT channel
    1885     owner_xp = hal_remote_lwd( XPTR( txt_cxy , &txt_ptr->ext.txt.owner_xp ) );
    1886     txt_id   = hal_remote_lw ( XPTR( txt_cxy , &txt_ptr->channel ) );
     1983    owner_xp = hal_remote_l64( XPTR( txt_cxy , &txt_ptr->ext.txt.owner_xp ) );
     1984    txt_id   = hal_remote_l32 ( XPTR( txt_cxy , &txt_ptr->channel ) );
    18871985
    18881986    // transfer ownership only if process is the TXT owner
     
    18941992
    18951993        // get lock
    1896         remote_spinlock_lock( lock_xp );
     1994        remote_busylock_acquire( lock_xp );
    18971995
    18981996        if( process_get_ppid( process_xp ) != 1 )           // process is not KSH
     
    19082006                {
    19092007                    // release lock
    1910                     remote_spinlock_unlock( lock_xp );
     2008                    remote_busylock_release( lock_xp );
    19112009
    19122010                    // set owner field in TXT chdev
    1913                     hal_remote_swd( XPTR( txt_cxy , &txt_ptr->ext.txt.owner_xp ) , current_xp );
     2011                    hal_remote_s64( XPTR( txt_cxy , &txt_ptr->ext.txt.owner_xp ) , current_xp );
    19142012
    19152013#if DEBUG_PROCESS_TXT
    19162014cycle   = (uint32_t)hal_get_cycles();
    1917 uint32_t ksh_pid = hal_remote_lw( XPTR( current_cxy , &current_ptr->pid ) );
     2015uint32_t ksh_pid = hal_remote_l32( XPTR( current_cxy , &current_ptr->pid ) );
    19182016if( DEBUG_PROCESS_TXT < cycle )
    19192017printk("\n[DBG] %s : thread %x in process %x release TXT %d to KSH %x / cycle %d\n",
     
    19262024 
    19272025            // release lock
    1928             remote_spinlock_unlock( lock_xp );
     2026            remote_busylock_release( lock_xp );
    19292027
    19302028            // PANIC if KSH not found
     
    19452043                {
    19462044                    // release lock
    1947                     remote_spinlock_unlock( lock_xp );
     2045                    remote_busylock_release( lock_xp );
    19482046
    19492047                    // set owner field in TXT chdev
    1950                     hal_remote_swd( XPTR( txt_cxy , &txt_ptr->ext.txt.owner_xp ) , current_xp );
     2048                    hal_remote_s64( XPTR( txt_cxy , &txt_ptr->ext.txt.owner_xp ) , current_xp );
    19512049
    19522050#if DEBUG_PROCESS_TXT
    19532051cycle   = (uint32_t)hal_get_cycles();
    1954 uint32_t new_pid = hal_remote_lw( XPTR( current_cxy , &current_ptr->pid ) );
     2052uint32_t new_pid = hal_remote_l32( XPTR( current_cxy , &current_ptr->pid ) );
    19552053if( DEBUG_PROCESS_TXT < cycle )
    19562054printk("\n[DBG] %s : thread %x in process %x release TXT %d to process %x / cycle %d\n",
     
    19632061
    19642062            // release lock
    1965             remote_spinlock_unlock( lock_xp );
     2063            remote_busylock_release( lock_xp );
    19662064
    19672065            // no more owner for TXT if no other process found
    1968             hal_remote_swd( XPTR( txt_cxy , &txt_ptr->ext.txt.owner_xp ) , XPTR_NULL );
     2066            hal_remote_s64( XPTR( txt_cxy , &txt_ptr->ext.txt.owner_xp ) , XPTR_NULL );
    19692067
    19702068#if DEBUG_PROCESS_TXT
     
    19932091
    19942092
    1995 //////////////////////////////////////////////////
    1996 uint32_t process_txt_is_owner( xptr_t process_xp )
     2093////////////////////////////////////////////////
     2094bool_t process_txt_is_owner( xptr_t process_xp )
    19972095{
    19982096    // get local pointer and cluster of process in owner cluster
     
    20002098    process_t * process_ptr = GET_PTR( process_xp );
    20012099
    2002     // check owner cluster
    2003     pid_t process_pid = hal_remote_lw( XPTR( process_cxy , &process_ptr->pid ) );
    2004     assert( (process_cxy == CXY_FROM_PID( process_pid )) ,
    2005     "process descriptor not in owner cluster\n" );
     2100// check calling thread execute in target process owner cluster
     2101pid_t process_pid = hal_remote_l32( XPTR( process_cxy , &process_ptr->pid ) );
     2102assert( (process_cxy == CXY_FROM_PID( process_pid )) ,
     2103"process descriptor not in owner cluster\n" );
    20062104
    20072105    // get extended pointer on stdin pseudo file
    2008     xptr_t file_xp = hal_remote_lwd( XPTR( process_cxy , &process_ptr->fd_array.array[0] ) );
     2106    xptr_t file_xp = hal_remote_l64( XPTR( process_cxy , &process_ptr->fd_array.array[0] ) );
    20092107
    20102108    // get pointers on TXT chdev
     
    20142112
    20152113    // get extended pointer on TXT_RX owner process
    2016     xptr_t owner_xp = hal_remote_lwd( XPTR( txt_cxy , &txt_ptr->ext.txt.owner_xp ) );
     2114    xptr_t owner_xp = hal_remote_l64( XPTR( txt_cxy , &txt_ptr->ext.txt.owner_xp ) );
    20172115
    20182116    return (process_xp == owner_xp);
     
    20272125    chdev_t *   txt_rx_ptr = GET_PTR( txt_rx_xp );
    20282126
    2029     return (xptr_t)hal_remote_lwd( XPTR( txt_rx_cxy , &txt_rx_ptr->ext.txt.owner_xp ) );
     2127    return (xptr_t)hal_remote_l64( XPTR( txt_rx_cxy , &txt_rx_ptr->ext.txt.owner_xp ) );
    20302128
    20312129}  // end process_txt_get_owner()
     
    20452143    xptr_t      txt0_xp;
    20462144    xptr_t      txt0_lock_xp;
    2047     reg_t       txt0_save_sr;    // save SR to take TXT0 lock in busy mode
    20482145   
    20492146    assert( (txt_id < LOCAL_CLUSTER->nb_txt_channels) ,
     
    20682165
    20692166    // get lock on attached process list
    2070     remote_spinlock_lock( lock_xp );
     2167    remote_busylock_acquire( lock_xp );
    20712168
    20722169    // get TXT0 lock in busy waiting mode
    2073     remote_spinlock_lock_busy( txt0_lock_xp , &txt0_save_sr );
     2170    remote_busylock_acquire( txt0_lock_xp );
    20742171
    20752172    // display header
     
    20852182
    20862183    // release TXT0 lock in busy waiting mode
    2087     remote_spinlock_unlock_busy( txt0_lock_xp , txt0_save_sr );
     2184    remote_busylock_release( txt0_lock_xp );
    20882185
    20892186    // release lock on attached process list
    2090     remote_spinlock_unlock( lock_xp );
     2187    remote_busylock_release( lock_xp );
    20912188
    20922189}  // end process_txt_display
Note: See TracChangeset for help on using the changeset viewer.