Changeset 165 for soft/giet_vm/libs/mwmr_channel.c
- Timestamp:
- Jul 4, 2012, 2:51:18 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/libs/mwmr_channel.c
r159 r165 12 12 // The mwmr_read() and mwmr_write() functions do not require a system call. 13 13 // The channel itself must have been allocated in a non cacheable segment, 14 // if the platform does not provide hardwa te cache coherence.14 // if the platform does not provide hardware cache coherence. 15 15 // 16 16 // ALL MWMR channels must be defined in the mapping_info data structure, … … 37 37 // mwmr_lock_aquire() 38 38 // This blocking function returns only when the lock has been taken. 39 // If the lock is already taken a randomdelay is introduced before retry.40 ////////////////////////////////////////////////////////////////////////////// 41 void mwmr_lock_acquire(unsigned int* plock)39 // If the lock is already taken a fixed delay is introduced before retry. 40 ////////////////////////////////////////////////////////////////////////////// 41 void mwmr_lock_acquire(unsigned int* lock_address) 42 42 { 43 register unsigned int* plock = lock_address; 44 register unsigned int delay = 100; 43 45 asm volatile ( 44 46 "mwmr_lock_try: \n" 45 47 "ll $2, 0(%0) \n" /* $2 <= lock current value */ 46 "bnez $2, mwmr_lock_delay \n" /* retry if lock already taken*/48 "bnez $2, mwmr_lock_delay \n" /* retry after delay if lock busy */ 47 49 "li $3, 1 \n" /* $3 <= argument for sc */ 48 50 "sc $3, 0(%0) \n" /* try to get lock */ 49 51 "bnez $3, mwmr_lock_ok \n" /* exit if atomic */ 50 51 52 "mwmr_lock_delay: \n" 52 "jal rand \n" /* rand() system call */ 53 "nop \n" 54 "andi $4, $2, 0xFF \n" /* $4 <= random delay < 256 cycles */ 55 56 "mwmr_lock_loop: \n" 53 "move $4, %1 \n" /* $4 <= delay */ 54 "mwmr_lock_loop: \n" 55 "beqz $4, mwmr_lock_loop \n" /* test end delay */ 57 56 "addi $4, $4, -1 \n" /* $4 <= $4 - 1 */ 58 "beqz $4, mwmr_lock_loop \n" /* test end delay */ 59 "nop \n" 60 "j mwmr_lock_try \n" /* retry */ 57 "j mwmr_lock_try \n" /* retry ll */ 61 58 "nop \n" 62 59 "mwmr_lock_ok: \n" 63 60 : 64 :"r"(plock) 61 :"r"(plock), "r"(delay) 65 62 :"$2", "$3", "$4"); 66 63 } … … 117 114 { 118 115 mwmr->lock = 0; 119 for ( x = rand()>>8 ; x > 0 ; x-- ) asm volatile ( "nop" );116 for ( x = giet_rand()>>8 ; x > 0 ; x-- ) asm volatile ( "nop" ); 120 117 } 121 118 else // write as many items as possible, release lock and retry after delay … … 135 132 } 136 133 // random delay before retry 137 for ( x = rand()>>6 ; x > 0 ; x-- ) asm volatile ( "nop" );134 for ( x = giet_rand()>>6 ; x > 0 ; x-- ) asm volatile ( "nop" ); 138 135 } 139 136 } … … 188 185 { 189 186 mwmr->lock = 0; 190 for ( x = rand()>>8 ; x > 0 ; x-- ) asm volatile ( "nop" );187 for ( x = giet_rand()>>8 ; x > 0 ; x-- ) asm volatile ( "nop" ); 191 188 } 192 189 else // read as many items as possible, release lock and retry after delay … … 206 203 } 207 204 // random delay before retry 208 for ( x = rand()>>6 ; x > 0 ; x-- ) asm volatile ( "nop" );205 for ( x = giet_rand()>>6 ; x > 0 ; x-- ) asm volatile ( "nop" ); 209 206 } 210 207 }
Note: See TracChangeset
for help on using the changeset viewer.