Changeset 104 for trunk/kernel/libk


Ignore:
Timestamp:
Jun 30, 2017, 8:57:37 AM (8 years ago)
Author:
max@…
Message:

style

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/libk/remote_barrier.c

    r60 r104  
    11/*
    22 * remote_barrier.c - Access a POSIX barrier.
    3  * 
     3 *
    44 * Author   Alain Greiner (2016,2017)
    55 *
     
    3535/////////////////////////////////////////////////
    3636inline void remote_barrier( xptr_t    barrier_xp,
    37                             uint32_t  count ) 
     37                            uint32_t  count )
    3838{
    3939    uint32_t  expected;
     
    4545    uint32_t sense = hal_remote_lw( XPTR( cxy , &ptr->sense ) );
    4646
    47         // compute expected value
     47    // compute expected value
    4848    if ( sense == 0 ) expected = 1;
    4949    else              expected = 0;
    5050
    51     // atomically increment current 
     51    // atomically increment current
    5252    uint32_t current = hal_remote_atomic_add( XPTR( cxy , &ptr->current ) , 1 );
    5353
    5454    // last task reset current and toggle sense
    55     if( current == (count-1) ) 
    56     {
    57         hal_remote_sw( XPTR( cxy , &ptr->current) , 0 ); 
    58         hal_remote_sw( XPTR( cxy , &ptr->sense  ) , expected ); 
    59     }
    60     else   // other tasks poll the sense 
     55    if( current == (count-1) )
     56    {
     57        hal_remote_sw( XPTR( cxy , &ptr->current) , 0 );
     58        hal_remote_sw( XPTR( cxy , &ptr->sense  ) , expected );
     59    }
     60    else   // other tasks poll the sense
    6161    {
    6262        while( hal_remote_lw( XPTR( cxy , &ptr->sense ) ) != expected ) asm volatile ("nop");
     
    7373    xptr_t      ref_xp = process->ref_xp;
    7474
    75     // get cluster and local pointer on reference process 
     75    // get cluster and local pointer on reference process
    7676    cxy_t          ref_cxy = GET_CXY( ref_xp );
    7777    process_t    * ref_ptr = (process_t *)GET_PTR( ref_xp );
    7878
    79     // get extended pointer on root of barriers list 
     79    // get extended pointer on root of barriers list
    8080    xptr_t root_xp = XPTR( ref_cxy , &ref_ptr->barrier_root );
    81    
     81
    8282    // scan reference process barriers list
    8383    xptr_t             iter_xp;
     
    8787    intptr_t           current;
    8888    bool_t             found = false;
    89            
     89
    9090    XLIST_FOREACH( root_xp , iter_xp )
    9191    {
     
    9393        barrier_cxy = GET_CXY( barrier_xp );
    9494        barrier_ptr = (remote_barrier_t *)GET_PTR( barrier_xp );
    95         current     = (intptr_t)hal_remote_lpt( XPTR( barrier_cxy , &barrier_ptr->ident ) );   
     95        current     = (intptr_t)hal_remote_lpt( XPTR( barrier_cxy , &barrier_ptr->ident ) );
    9696        if( ident == current )
    9797        {
     
    103103    if( found == false )  return XPTR_NULL;
    104104    else                  return barrier_xp;
    105 
    106 }  // end remote_barrier_from_ident()
     105}
    107106
    108107//////////////////////////////////////////////
     
    124123
    125124    // allocate memory for barrier descriptor
    126     if( ref_cxy == local_cxy )                  // local cluster is the reference 
    127     {
    128         kmem_req_t req;   
     125    if( ref_cxy == local_cxy )                  // local cluster is the reference
     126    {
     127        kmem_req_t req;
    129128        req.type      = KMEM_BARRIER;
    130129        req.flags     = AF_ZERO;
     
    140139    if( barrier_ptr == NULL ) return ENOMEM;
    141140
    142     // initialise barrier 
     141    // initialise barrier
    143142    hal_remote_sw ( XPTR( ref_cxy , &barrier_ptr->nb_threads ) , count );
    144143    hal_remote_sw ( XPTR( ref_cxy , &barrier_ptr->current    ) , 0 );
     
    157156
    158157    return 0;
    159 
    160 }  // end remote_barrier_create()
     158}
    161159
    162160////////////////////////////////////////////////
     
    194192        rpc_kcm_free_client( barrier_cxy , barrier_ptr , KMEM_BARRIER );
    195193    }
    196 
    197 }  // end remote_barrier_destroy()
     194}
    198195
    199196/////////////////////////////////////////////
     
    222219    sense = hal_remote_lw( XPTR( barrier_cxy , &barrier_ptr->sense ) );
    223220
    224         // compute expected value
     221    // compute expected value
    225222    if ( sense == 0 ) expected = 1;
    226223    else              expected = 0;
    227224
    228     // atomically increment current 
     225    // atomically increment current
    229226    current = hal_remote_atomic_add( XPTR( barrier_cxy , &barrier_ptr->current ) , 1 );
    230227
    231228    // last thread reset current, toggle sense, and activate all waiting threads
    232     // other threads block, register in queue, and deschedule 
     229    // other threads block, register in queue, and deschedule
    233230
    234231    if( current == (count-1) )                       // last thread
    235232    {
    236         hal_remote_sw( XPTR( barrier_cxy , &barrier_ptr->current) , 0 ); 
    237         hal_remote_sw( XPTR( barrier_cxy , &barrier_ptr->sense  ) , expected ); 
     233        hal_remote_sw( XPTR( barrier_cxy , &barrier_ptr->current) , 0 );
     234        hal_remote_sw( XPTR( barrier_cxy , &barrier_ptr->sense  ) , expected );
    238235
    239236        // activate waiting threads if required
    240         if( xlist_is_empty( root_xp ) == false ) 
     237        if( xlist_is_empty( root_xp ) == false )
    241238        {
    242239            // disable interrupts
    243                 hal_disable_irq( &irq_state );
    244  
     240            hal_disable_irq( &irq_state );
     241
    245242            xptr_t  iter_xp;
    246243            xptr_t  thread_xp;
     
    249246                // get extended pointer on waiting thread
    250247                thread_xp = XLIST_ELEMENT( iter_xp , thread_t , wait_list );
    251        
     248
    252249                // remove waiting thread from queue
    253250                remote_spinlock_lock( XPTR( barrier_cxy , &barrier_ptr->lock ) );
     
    256253
    257254                // unblock waiting thread
    258                 thread_unblock( thread_xp , THREAD_BLOCKED_USERSYNC ); 
     255                thread_unblock( thread_xp , THREAD_BLOCKED_USERSYNC );
    259256            }
    260257
     
    263260        }
    264261    }
    265     else                                             // not the last thread 
     262    else                                             // not the last thread
    266263    {
    267264        // disable interrupts
    268             hal_disable_irq( &irq_state );
    269  
     265        hal_disable_irq( &irq_state );
     266
    270267        // register calling thread in barrier waiting queue
    271268        xptr_t entry_xp = XPTR( thread_cxy , &thread_ptr->wait_list );
    272269
    273         remote_spinlock_lock( XPTR( barrier_cxy , &barrier_ptr->lock ) ); 
     270        remote_spinlock_lock( XPTR( barrier_cxy , &barrier_ptr->lock ) );
    274271        xlist_add_last( root_xp , entry_xp );
    275         remote_spinlock_unlock( XPTR( barrier_cxy , &barrier_ptr->lock ) ); 
    276 
    277         // block & deschedule the calling thread   
     272        remote_spinlock_unlock( XPTR( barrier_cxy , &barrier_ptr->lock ) );
     273
     274        // block & deschedule the calling thread
    278275        thread_block( thread_ptr , THREAD_BLOCKED_USERSYNC );
    279276        sched_yield();
     
    282279        hal_restore_irq( irq_state );
    283280    }
    284 }  // end remote_barrier_wait()
     281}
Note: See TracChangeset for help on using the changeset viewer.