Changeset 407 for trunk/kernel/libk
- Timestamp:
- Nov 7, 2017, 3:08:12 PM (7 years ago)
- Location:
- trunk/kernel/libk
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/libk/elf.c
r406 r407 175 175 } 176 176 177 // get .elf file descriptor cluster and local pointer 178 cxy_t file_cxy = GET_CXY( file_xp ); 179 vfs_file_t * file_ptr = (vfs_file_t *)GET_PTR( file_xp ); 180 181 // get local pointer on .elf file mapper 182 mapper_t * mapper_ptr = (mapper_t *)hal_remote_lpt( XPTR( file_cxy , 183 &file_ptr->mapper ) ); 177 184 // register vseg in VMM 178 185 vseg = (vseg_t *)vmm_create_vseg( process, 186 type, 179 187 vbase, 180 188 mem_size, 181 type ); 189 file_offset, 190 file_size, 191 XPTR( file_cxy , mapper_ptr ), 192 local_cxy ); 182 193 if( vseg == NULL ) 183 194 { … … 187 198 } 188 199 189 // get .elf file descriptor cluster and local pointer190 cxy_t file_cxy = GET_CXY( file_xp );191 vfs_file_t * file_ptr = (vfs_file_t *)GET_PTR( file_xp );192 193 // get local pointer on .elf file mapper194 mapper_t * mapper_ptr = (mapper_t *)hal_remote_lpt( XPTR( file_cxy ,195 &file_ptr->mapper ) );196 197 // initialize "file_mapper", "file_offset", "file_size" fields in vseg198 vseg->mapper_xp = XPTR( file_cxy , mapper_ptr );199 vseg->file_offset = file_offset;200 vseg->file_size = file_size;201 202 200 // update reference counter in file descriptor 203 201 vfs_file_count_up( file_xp ); 204 202 205 elf_dmsg("\n[D MSG] %s : found %s vseg / base = %x / size = %x\n"203 elf_dmsg("\n[DBG] %s : found %s vseg / base = %x / size = %x\n" 206 204 " file_size = %x / file_offset = %x / mapper_xp = %l\n", 207 205 __FUNCTION__ , vseg_type_str(vseg->type) , vseg->min , vseg->max - vseg->min , … … 225 223 error_t error; 226 224 227 elf_dmsg("\n[D MSG] %s : core[%x,%d] enter for <%s>\n",225 elf_dmsg("\n[DBG] %s : core[%x,%d] enter for <%s>\n", 228 226 __FUNCTION__ , local_cxy , CURRENT_THREAD->core->lid , pathname ); 229 227 … … 233 231 234 232 // open file 235 error = vfs_open( process ->vfs_cwd_xp,233 error = vfs_open( process, 236 234 pathname, 237 235 O_RDONLY, … … 245 243 } 246 244 247 elf_dmsg("\n[D MSG] %s : open file <%s>\n", __FUNCTION__ , pathname );245 elf_dmsg("\n[DBG] %s : open file <%s>\n", __FUNCTION__ , pathname ); 248 246 249 247 // load header in local buffer … … 258 256 } 259 257 260 elf_dmsg("\n[D MSG] %s : loaded elf header for %s\n", __FUNCTION__ , pathname );258 elf_dmsg("\n[DBG] %s : loaded elf header for %s\n", __FUNCTION__ , pathname ); 261 259 262 260 if( header.e_phnum == 0 ) … … 295 293 } 296 294 297 elf_dmsg("\n[D MSG] %s : segments array allocated for %s\n", __FUNCTION__ , pathname );295 elf_dmsg("\n[DBG] %s : segments array allocated for %s\n", __FUNCTION__ , pathname ); 298 296 299 297 // load seg descriptors array to local buffer … … 312 310 } 313 311 314 elf_dmsg("\n[D MSG] %s loaded segments descriptors for %s \n", __FUNCTION__ , pathname );312 elf_dmsg("\n[DBG] %s loaded segments descriptors for %s \n", __FUNCTION__ , pathname ); 315 313 316 314 // register loadable segments in process VMM … … 337 335 kmem_free(&req); 338 336 339 elf_dmsg("\n[D MSG] %s : core[%x,%d] exit for <%s> / entry_point = %x\n",337 elf_dmsg("\n[DBG] %s : core[%x,%d] exit for <%s> / entry_point = %x\n", 340 338 __FUNCTION__ , local_cxy , CURRENT_THREAD->core->lid , pathname , header.e_entry ); 341 339 -
trunk/kernel/libk/remote_barrier.c
r296 r407 274 274 // block & deschedule the calling thread 275 275 thread_block( thread_ptr , THREAD_BLOCKED_USERSYNC ); 276 sched_yield( NULL);276 sched_yield(); 277 277 278 278 // restore interrupts -
trunk/kernel/libk/remote_condvar.c
r296 r407 189 189 // block the calling thread 190 190 thread_block( CURRENT_THREAD , THREAD_BLOCKED_USERSYNC ); 191 sched_yield( NULL);191 sched_yield(); 192 192 193 193 // lock the mutex before return -
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; -
trunk/kernel/libk/remote_fifo.h
r279 r407 28 28 #include <kernel_config.h> 29 29 #include <hal_types.h> 30 #include <printk.h> 30 31 #include <errno.h> 31 32 #include <hal_remote.h> 32 33 33 34 /************************************************************************************ 34 * This structure defines a generic, single reader, multiple writers 35 * remote FIFO, that is used by the RPCs for inter cluster communications. 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. 39 * In case of FIFO full, the writer deschedule without blocking, to retry later. 40 * 41 * WARNING : the number of slots is statically defined by the global 42 * configuration parameter CONFIG_REMOTE_FIFO_SLOTS for all fifos. requiring 43 * Each FIFO requires 8 + (12 * CONFIG_REMOTE_FIFO_SLOTS) bytes. 35 * This structure defines a generic, single reader, multiple writers FIFO, 36 * that is used for - RPC based - inter cluster communications. 37 * Each FIF0 slot can contain one 64 bits integer (or one extended pointer). 38 * The number of slots is defined by the CONFIG_REMOTE_FIFO_SLOTS parameter. 39 * - The write accesses are implemented using a lock-free algorithm, as it uses 40 * a ticket based mechanism to handle concurrent access between multiple writers. 41 * In case of FIFO full, the writer deschedule without blocking, to retry later. 42 * - The reader must take the try_lock implemented by the "owner" field, using 43 * an atomic_add(). The TRDID is a good owner identifier, because all 44 * RPC threads in a given cluster belong to the same kernel process, 45 * and RPC threads cannot have local index LTID = 0. 46 * 47 * WARNING : Each FIFO requires 12 + (12 * CONFIG_REMOTE_FIFO_SLOTS) bytes. 44 48 ***********************************************************************************/ 45 49 46 50 typedef struct remote_fifo_s 47 51 { 52 uint32_t owner; /*! owner thread trdid */ 48 53 volatile uint32_t wr_id; /*! write slot index */ 49 54 volatile uint32_t rd_id; /*! read slot index */ … … 63 68 /************************************************************************************ 64 69 * This non blocking function tries to get one item from the local fifo. 65 * The reader must get exclusive access before calling this function.70 * The reader must get exclusive access for read before calling this function. 66 71 * The read slot index is incremented. 67 72 ************************************************************************************ … … 75 80 /************************************************************************************ 76 81 * This blocking function puts one item to a remote fifo identified 77 * by an extended pointer. 78 * This function gets a write ticket using a remote_atomic_increment on the 79 * write slot. Then, it waits until the slot is empty, using a descheduling 80 * policy without blocking. 82 * by an extended pointer. It gets a write ticket on the slot to be written, 83 * using a remote_atomic_add() on the write slot index. Then, it waits until 84 * the slot is empty, using a descheduling policy without blocking if required. 85 * It implements a watchdog, returning when the item has been successfully 86 * registered, or after CONFIG_REMOTE_FIFO_MAX_ITERATIONS failures. 81 87 ************************************************************************************ 82 88 * @ fifo : extended pointer to the fifo in remote cluster. 83 89 * @ item : item to be stored. 84 * @ first : [out] true if first item registered in remote fifo.85 90 * @ return 0 on success / EBUSY if a contention has been detected. 86 91 ***********************************************************************************/ 87 92 error_t remote_fifo_put_item( xptr_t fifo, 88 uint64_t item, 89 bool_t * first ); 93 uint64_t item ); 90 94 91 95 /************************************************************************************ -
trunk/kernel/libk/remote_mutex.c
r296 r407 208 208 // block & deschedule the calling thread 209 209 thread_block( thread_ptr , THREAD_BLOCKED_USERSYNC ); 210 sched_yield( NULL);210 sched_yield(); 211 211 212 212 // restore interrupts -
trunk/kernel/libk/remote_sem.c
r296 r407 219 219 // block and deschedule 220 220 thread_block( this , THREAD_BLOCKED_SEM ); 221 sched_yield( NULL);221 sched_yield(); 222 222 } 223 223 } // end remote_sem_wait() -
trunk/kernel/libk/remote_spinlock.c
r337 r407 179 179 { 180 180 hal_restore_irq( mode ); 181 if( thread_can_yield() ) sched_yield( NULL);181 if( thread_can_yield() ) sched_yield(); 182 182 hal_disable_irq( &mode ); 183 183 continue; -
trunk/kernel/libk/spinlock.c
r337 r407 111 111 { 112 112 hal_restore_irq( mode ); 113 if( thread_can_yield() ) sched_yield( NULL);113 if( thread_can_yield() ) sched_yield(); 114 114 hal_disable_irq( &mode ); 115 115 continue;
Note: See TracChangeset
for help on using the changeset viewer.