Changeset 407 for trunk/kernel/libk/remote_fifo.c
- Timestamp:
- Nov 7, 2017, 3:08:12 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/libk/remote_fifo.c
r296 r407 39 39 uint32_t slot; 40 40 41 fifo->owner = 0; 41 42 fifo->wr_id = 0; 42 43 fifo->rd_id = 0; … … 47 48 } 48 49 49 ////////////////////////////////////////////// 50 error_t remote_fifo_put_item( xptr_t fifo, 51 uint64_t item, 52 bool_t * first ) 50 ///////////////////////////////////////////////// 51 error_t remote_fifo_put_item( xptr_t fifo_xp, 52 uint64_t item ) 53 53 { 54 54 uint32_t wr_id; … … 56 56 uint32_t ptw; 57 57 uint32_t watchdog; 58 reg_t save_sr;59 58 uint32_t nslots; 60 59 61 60 // get remote cluster identifier and pointer on FIFO 62 cxy_t cxy = (cxy_t)GET_CXY( fifo);63 remote_fifo_t * ptr = (remote_fifo_t *)GET_PTR( fifo);61 cxy_t fifo_cxy = (cxy_t)GET_CXY( fifo_xp ); 62 remote_fifo_t * fifo_ptr = (remote_fifo_t *)GET_PTR( fifo_xp ); 64 63 65 64 // initialise watchdog for contention detection 66 65 watchdog = 0; 67 66 68 // no descheduling during put access 69 hal_disable_irq( &save_sr ); 70 71 // get write slot index and atomic increment 72 wr_id = hal_remote_atomic_add( XPTR( cxy , &ptr->wr_id ) , 1 ); 67 // get write slot index with atomic increment 68 wr_id = hal_remote_atomic_add( XPTR( fifo_cxy , &fifo_ptr->wr_id ) , 1 ); 73 69 74 // check fifo state 70 // wait until allocated slot is empty in remote FIFO 71 // max retry = CONFIG_REMOTE_FIFO_MAX_ITERATIONS 72 // return error if watchdog is reached 75 73 while( 1 ) 76 74 { 77 75 // return error if contention detected by watchdog 78 if( watchdog > CONFIG_REMOTE_FIFO_MAX_ITERATIONS ) 79 { 80 // restore scheduling 81 hal_restore_irq( save_sr ); 82 83 // return error 84 return EBUSY; 85 } 76 if( watchdog > CONFIG_REMOTE_FIFO_MAX_ITERATIONS ) return EBUSY; 86 77 87 78 // read remote rd_id value 88 rd_id = hal_remote_lw( XPTR( cxy , &ptr->rd_id ) );79 rd_id = hal_remote_lw( XPTR( fifo_cxy , &fifo_ptr->rd_id ) ); 89 80 90 81 // compute number of full slots … … 92 83 else nslots = (0xFFFFFFFF - rd_id) + wr_id; 93 84 94 // exit iffifo not full85 // exit waiting loop as soon as fifo not full 95 86 if ( nslots < CONFIG_REMOTE_FIFO_SLOTS ) break; 96 87 97 // restore interrupts 98 hal_restore_irq( save_sr ); 99 100 // deschedule without blocking 101 if( thread_can_yield() ) sched_yield( NULL ); 102 103 // disable interrupts 104 hal_disable_irq( &save_sr ); 88 // retry later if fifo full: 89 // - deschedule without blocking if possible 90 // - wait ~1000 cycles otherwise 91 if( thread_can_yield() ) sched_yield(); 92 else hal_fixed_delay( 1000 ); 105 93 106 94 // increment watchdog … … 112 100 113 101 // copy item to fifo 114 hal_remote_swd( XPTR( cxy , &ptr->data[ptw] ), item ); 115 102 hal_remote_swd( XPTR( fifo_cxy , &fifo_ptr->data[ptw] ), item ); 116 103 hal_fence(); 117 104 118 105 // set the slot valid flag 119 hal_remote_sw( XPTR( cxy , &ptr->valid[ptw] ) , 1 );106 hal_remote_sw( XPTR( fifo_cxy , &fifo_ptr->valid[ptw] ) , 1 ); 120 107 hal_fence(); 121 122 // return the first RPC flag123 *first = ( wr_id == rd_id );124 125 // restore scheduling126 hal_restore_irq( save_sr );127 108 128 109 return 0;
Note: See TracChangeset
for help on using the changeset viewer.