Changeset 68 for trunk/kernel/libk
- Timestamp:
- Jun 27, 2017, 10:24:13 AM (7 years ago)
- Location:
- trunk/kernel/libk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/libk/remote_fifo.c
r60 r68 1 1 /* 2 * remote_fifo.c Implement a lock-less FIFO, 3 multiple-remote-writers / single-local-reader 2 * remote_fifo.c Implement a lock-less FIFO, multiple-remote-writers / single-local-reader 4 3 * 5 4 * Authors : Mohamed Lamine Karaoui (2015) 6 * Alain Greiner (2016 )5 * Alain Greiner (2016,2017) 7 6 * 8 7 * Copyright (c) UPMC Sorbonne Universites … … 44 43 for( slot = 0 ; slot < CONFIG_REMOTE_FIFO_SLOTS ; slot++ ) 45 44 { 46 fifo->valid[slot] = false;45 fifo->valid[slot] = 0; 47 46 } 48 47 } 49 48 50 //////////////////////////////////////////// 51 error_t remote_fifo_put_item( xptr_t fifo, 52 void * item, 53 uint32_t size, 54 bool_t * first ) 49 ////////////////////////////////////////////// 50 error_t remote_fifo_put_item( xptr_t fifo, 51 uint64_t * item, 52 bool_t * first ) 55 53 { 56 54 uint32_t wr_id; … … 71 69 hal_disable_irq( &save_sr ); 72 70 73 // get write slot index and increment71 // get write slot index and atomic increment 74 72 wr_id = hal_remote_atomic_add( XPTR( cxy , &ptr->wr_id ) , 1 ); 75 73 … … 114 112 115 113 // copy item to fifo 116 hal_remote_memcpy( XPTR( cxy , &ptr->data[ptw] ), 117 XPTR( local_cxy , item ) , size ); 114 hal_remote_swd( XPTR( cxy , &ptr->data[ptw] ), *item ); 118 115 hal_wbflush(); 119 116 120 117 // set the slot valid flag 121 118 hal_remote_sw( XPTR( cxy , &ptr->valid[ptw] ) , 1 ); 122 123 119 hal_wbflush(); 124 120 … … 135 131 ////////////////////////////////////////////////// 136 132 error_t local_fifo_get_item( remote_fifo_t * fifo, 137 void * item, 138 uint32_t size ) 133 uint64_t * item ) 139 134 { 140 135 // get fifo state … … 152 147 153 148 // copy item from FIFO to local buffer 154 memcpy( item , &fifo->data[ptr] , size );149 *item = fifo->data[ptr]; 155 150 156 151 // reset valid slot flag -
trunk/kernel/libk/remote_fifo.h
r14 r68 1 1 /* 2 * remote_fifo.h - kernel generic SRMWFIFO2 * remote_fifo.h - Lock-less Single-Reader Multiple-Writers FIFO 3 3 * 4 * Authors : Mohamed Lamine Karaoui / Alain Greiner (2016) 4 * Authors : Mohamed Lamine Karaoui (2015) 5 * Alain Greiner (2016,2017) 5 6 * 6 7 * Copyright (c) UPMC Sorbonne Universites … … 33 34 * This structure defines a generic, single reader, multiple writers 34 35 * remote FIFO, that is used by the RPCs for inter cluster communications. 35 * The accesses are implemented using a lock-free algorithm, as it 36 * uses a ticket based mechanism to handle concurrent access between 37 * the multiple writers. 38 * Each FIF0 slot can contain one full cache line, even if RPCs store only 39 * an extended pointer on the RPC descriptor in each slot. 36 * The accesses are implemented using a lock-free algorithm, as it uses a ticket 37 * based mechanism to handle concurrent access between multiple writers. 38 * Each FIF0 slot can contain one 64 bits integer. 40 39 * In case of FIFO full, the writer deschedule without blocking, to retry later. 41 40 * 42 41 * WARNING : the number of slots is statically defined by the global 43 42 * configuration parameter CONFIG_REMOTE_FIFO_SLOTS for all fifos, requiring 44 * CACHE_LINE_SIZE * CONFIG_REMOTE_FIFO_SLOTS bytes for each FIFO...43 * 12 * CONFIG_REMOTE_FIFO_SLOTS bytes for each FIFO. 45 44 ***********************************************************************************/ 45 46 46 typedef struct remote_fifo_s 47 47 { 48 48 volatile uint32_t wr_id; /*! write slot index */ 49 49 volatile uint32_t rd_id; /*! read slot index */ 50 volatile bool_t valid[CONFIG_REMOTE_FIFO_SLOTS]; /*! empty slot if false*/51 cacheline_tdata[CONFIG_REMOTE_FIFO_SLOTS]; /*! fifo slot content */50 volatile uint32_t valid[CONFIG_REMOTE_FIFO_SLOTS]; /*! empty slot if 0 */ 51 uint64_t data[CONFIG_REMOTE_FIFO_SLOTS]; /*! fifo slot content */ 52 52 } 53 53 remote_fifo_t; … … 72 72 ***********************************************************************************/ 73 73 error_t local_fifo_get_item( remote_fifo_t * fifo, 74 void * item, 75 uint32_t size ); 74 uint64_t * item ); 76 75 77 76 /************************************************************************************ … … 84 83 * @ fifo : extended pointer to the fifo in remote cluster. 85 84 * @ item : pointer on a local buffer containing the item to be stored. 86 * @ size : actual number of bytes in one item. 87 * @ first : return value (true if first item registered in remote fifo) 85 * @ first : [out] true if first item registered in remote fifo. 88 86 * @ return 0 on success / EBUSY if a contention has been detected. 89 87 ***********************************************************************************/ 90 88 error_t remote_fifo_put_item( xptr_t fifo, 91 void * item, 92 uint32_t size, 89 uint64_t * item, 93 90 bool_t * first ); 94 91
Note: See TracChangeset
for help on using the changeset viewer.