Changeset 563 for trunk/kernel/libk/remote_barrier.c
- Timestamp:
- Oct 4, 2018, 11:16:13 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/libk/remote_barrier.c
r457 r563 1 1 /* 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) 5 5 * 6 6 * Copyright (c) UPMC Sorbonne Universites … … 25 25 #include <hal_remote.h> 26 26 #include <hal_irqmask.h> 27 #include <remote_ spinlock.h>27 #include <remote_busylock.h> 28 28 #include <thread.h> 29 29 #include <kmem.h> … … 33 33 #include <remote_barrier.h> 34 34 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 value45 uint32_t sense = hal_remote_lw( XPTR( cxy , &ptr->sense ) );46 47 // compute expected value48 if ( sense == 0 ) expected = 1;49 else expected = 0;50 51 // atomically increment current52 uint32_t current = hal_remote_atomic_add( XPTR( cxy , &ptr->current ) , 1 );53 54 // last task reset current and toggle sense55 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 sense61 {62 while( hal_remote_lw( XPTR( cxy , &ptr->sense ) ) != expected ) asm volatile ("nop");63 }64 }65 35 66 36 /////////////////////////////////////////////////// … … 120 90 // get reference process cluster and local pointer 121 91 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 ); 123 93 124 94 // allocate memory for barrier descriptor … … 140 110 141 111 // initialise barrier 142 hal_remote_s w( XPTR( ref_cxy , &barrier_ptr->nb_threads ) , count );143 hal_remote_s w( XPTR( ref_cxy , &barrier_ptr->current ) , 0 );144 hal_remote_s w( 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 ); 145 115 hal_remote_spt( XPTR( ref_cxy , &barrier_ptr->ident ) , (void*)ident ); 146 116 … … 151 121 xptr_t entry_xp = XPTR( ref_cxy , &barrier_ptr->list ); 152 122 153 remote_ spinlock_lock( XPTR( ref_cxy , &ref_ptr->sync_lock ) );123 remote_busylock_acquire( XPTR( ref_cxy , &ref_ptr->sync_lock ) ); 154 124 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 ) ); 156 126 157 127 return 0; … … 176 146 177 147 // 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 ) ); 179 149 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 ) ); 181 151 182 152 // release memory allocated for barrier descriptor … … 208 178 thread_t * thread_ptr = CURRENT_THREAD; 209 179 180 // check calling thread can yield 181 assert( (thread_ptr->busylocks == 0), 182 "cannot yield : busylocks = %d\n", thread_ptr->busylocks ); 183 210 184 // get cluster and local pointer on remote barrier 211 185 remote_barrier_t * barrier_ptr = (remote_barrier_t *)GET_PTR( barrier_xp ); … … 213 187 214 188 // get count and root fields from barrier descriptor 215 count = hal_remote_l w( XPTR( barrier_cxy , &barrier_ptr->nb_threads ) );216 root_xp = hal_remote_l wd( 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 ) ); 217 191 218 192 // get barrier sense value 219 sense = hal_remote_l w( XPTR( barrier_cxy , &barrier_ptr->sense ) );193 sense = hal_remote_l32( XPTR( barrier_cxy , &barrier_ptr->sense ) ); 220 194 221 195 // compute expected value … … 231 205 if( current == (count-1) ) // last thread 232 206 { 233 hal_remote_s w( XPTR( barrier_cxy , &barrier_ptr->current) , 0 );234 hal_remote_s w( 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 ); 235 209 236 210 // activate waiting threads if required … … 248 222 249 223 // 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 ) ); 251 225 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 ) ); 253 227 254 228 // unblock waiting thread … … 268 242 xptr_t entry_xp = XPTR( thread_cxy , &thread_ptr->wait_list ); 269 243 270 remote_ spinlock_lock( XPTR( barrier_cxy , &barrier_ptr->lock ) );244 remote_busylock_acquire( XPTR( barrier_cxy , &barrier_ptr->lock ) ); 271 245 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 ) ); 273 247 274 248 // block & deschedule the calling thread
Note: See TracChangeset
for help on using the changeset viewer.