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

Complete restructuration of kernel spinlocks.

File:
1 edited

Legend:

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

    r457 r563  
    11/*
    2  * remote_barrier.c - Access a POSIX barrier.
    3  *
    4  * Author   Alain Greiner (2016,2017)
     2 * remote_barrier.c -  POSIX barrier implementation.
     3 *
     4 * Author   Alain Greiner (2016,2017,2018)
    55 *
    66 * Copyright (c) UPMC Sorbonne Universites
     
    2525#include <hal_remote.h>
    2626#include <hal_irqmask.h>
    27 #include <remote_spinlock.h>
     27#include <remote_busylock.h>
    2828#include <thread.h>
    2929#include <kmem.h>
     
    3333#include <remote_barrier.h>
    3434
    35 /////////////////////////////////////////////////
    36 inline void remote_barrier( xptr_t    barrier_xp,
    37                             uint32_t  count )
    38 {
    39     uint32_t  expected;
    40 
    41     remote_barrier_t * ptr = (remote_barrier_t *)GET_PTR( barrier_xp );
    42     cxy_t              cxy = GET_CXY( barrier_xp );
    43 
    44     // get barrier sense value
    45     uint32_t sense = hal_remote_lw( XPTR( cxy , &ptr->sense ) );
    46 
    47     // compute expected value
    48     if ( sense == 0 ) expected = 1;
    49     else              expected = 0;
    50 
    51     // atomically increment current
    52     uint32_t current = hal_remote_atomic_add( XPTR( cxy , &ptr->current ) , 1 );
    53 
    54     // 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
    61     {
    62         while( hal_remote_lw( XPTR( cxy , &ptr->sense ) ) != expected ) asm volatile ("nop");
    63     }
    64 }
    6535
    6636///////////////////////////////////////////////////
     
    12090    // get reference process cluster and local pointer
    12191    cxy_t       ref_cxy = GET_CXY( ref_xp );
    122     process_t * ref_ptr = (process_t *)GET_PTR( ref_xp );
     92    process_t * ref_ptr = GET_PTR( ref_xp );
    12393
    12494    // allocate memory for barrier descriptor
     
    140110
    141111    // initialise barrier
    142     hal_remote_sw ( XPTR( ref_cxy , &barrier_ptr->nb_threads ) , count );
    143     hal_remote_sw ( XPTR( ref_cxy , &barrier_ptr->current    ) , 0 );
    144     hal_remote_sw ( XPTR( ref_cxy , &barrier_ptr->sense      ) , 0 );
     112    hal_remote_s32 ( XPTR( ref_cxy , &barrier_ptr->nb_threads ) , count );
     113    hal_remote_s32 ( XPTR( ref_cxy , &barrier_ptr->current    ) , 0 );
     114    hal_remote_s32 ( XPTR( ref_cxy , &barrier_ptr->sense      ) , 0 );
    145115    hal_remote_spt( XPTR( ref_cxy , &barrier_ptr->ident      ) , (void*)ident );
    146116
     
    151121    xptr_t entry_xp = XPTR( ref_cxy , &barrier_ptr->list );
    152122
    153     remote_spinlock_lock( XPTR( ref_cxy , &ref_ptr->sync_lock ) );
     123    remote_busylock_acquire( XPTR( ref_cxy , &ref_ptr->sync_lock ) );
    154124    xlist_add_first( root_xp , entry_xp );
    155     remote_spinlock_unlock( XPTR( ref_cxy , &ref_ptr->sync_lock ) );
     125    remote_busylock_release( XPTR( ref_cxy , &ref_ptr->sync_lock ) );
    156126
    157127    return 0;
     
    176146
    177147    // remove barrier from reference process xlist
    178     remote_spinlock_lock( XPTR( ref_cxy , &ref_ptr->sync_lock ) );
     148    remote_busylock_acquire( XPTR( ref_cxy , &ref_ptr->sync_lock ) );
    179149    xlist_unlink( XPTR( barrier_cxy , &barrier_ptr->list ) );
    180     remote_spinlock_unlock( XPTR( ref_cxy , &ref_ptr->sync_lock ) );
     150    remote_busylock_release( XPTR( ref_cxy , &ref_ptr->sync_lock ) );
    181151
    182152    // release memory allocated for barrier descriptor
     
    208178    thread_t         * thread_ptr = CURRENT_THREAD;
    209179
     180// check calling thread can yield
     181assert( (thread_ptr->busylocks == 0),
     182"cannot yield : busylocks = %d\n", thread_ptr->busylocks );
     183
    210184    // get cluster and local pointer on remote barrier
    211185    remote_barrier_t * barrier_ptr = (remote_barrier_t *)GET_PTR( barrier_xp );
     
    213187
    214188    // get count and root fields from barrier descriptor
    215     count   = hal_remote_lw ( XPTR( barrier_cxy , &barrier_ptr->nb_threads ) );
    216     root_xp = hal_remote_lwd( XPTR( barrier_cxy , &barrier_ptr->root ) );
     189    count   = hal_remote_l32 ( XPTR( barrier_cxy , &barrier_ptr->nb_threads ) );
     190    root_xp = hal_remote_l64( XPTR( barrier_cxy , &barrier_ptr->root ) );
    217191
    218192    // get barrier sense value
    219     sense = hal_remote_lw( XPTR( barrier_cxy , &barrier_ptr->sense ) );
     193    sense = hal_remote_l32( XPTR( barrier_cxy , &barrier_ptr->sense ) );
    220194
    221195    // compute expected value
     
    231205    if( current == (count-1) )                       // last thread
    232206    {
    233         hal_remote_sw( XPTR( barrier_cxy , &barrier_ptr->current) , 0 );
    234         hal_remote_sw( XPTR( barrier_cxy , &barrier_ptr->sense  ) , expected );
     207        hal_remote_s32( XPTR( barrier_cxy , &barrier_ptr->current) , 0 );
     208        hal_remote_s32( XPTR( barrier_cxy , &barrier_ptr->sense  ) , expected );
    235209
    236210        // activate waiting threads if required
     
    248222
    249223                // remove waiting thread from queue
    250                 remote_spinlock_lock( XPTR( barrier_cxy , &barrier_ptr->lock ) );
     224                remote_busylock_acquire( XPTR( barrier_cxy , &barrier_ptr->lock ) );
    251225                xlist_unlink( XPTR( barrier_cxy , &barrier_ptr->list ) );
    252                 remote_spinlock_unlock( XPTR( barrier_cxy , &barrier_ptr->lock ) );
     226                remote_busylock_release( XPTR( barrier_cxy , &barrier_ptr->lock ) );
    253227
    254228                // unblock waiting thread
     
    268242        xptr_t entry_xp = XPTR( thread_cxy , &thread_ptr->wait_list );
    269243
    270         remote_spinlock_lock( XPTR( barrier_cxy , &barrier_ptr->lock ) );
     244        remote_busylock_acquire( XPTR( barrier_cxy , &barrier_ptr->lock ) );
    271245        xlist_add_last( root_xp , entry_xp );
    272         remote_spinlock_unlock( XPTR( barrier_cxy , &barrier_ptr->lock ) );
     246        remote_busylock_release( XPTR( barrier_cxy , &barrier_ptr->lock ) );
    273247
    274248        // block & deschedule the calling thread
Note: See TracChangeset for help on using the changeset viewer.