- Timestamp:
- Dec 3, 2018, 12:17:35 PM (6 years ago)
- Location:
- trunk/kernel/libk
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/libk/elf.c
r457 r603 198 198 uint32_t cycle = (uint32_t)hal_get_cycles(); 199 199 if( DEBUG_ELF_LOAD < cycle ) 200 printk("\n[ DBG] %s :found %s vseg / base %x / size %x\n"200 printk("\n[%s] found %s vseg / base %x / size %x\n" 201 201 " file_size %x / file_offset %x / mapper_xp %l / cycle %d\n", 202 202 __FUNCTION__ , vseg_type_str(vseg->type) , vseg->min , vseg->max - vseg->min , … … 228 228 229 229 #if DEBUG_ELF_LOAD 230 uint32_t cycle = (uint32_t)hal_get_cycles(); 231 if( DEBUG_ELF_LOAD < cycle ) 232 printk("\n[DBG] %s : thread %d in process %x enter for <%s> / cycle %d\n", 233 __FUNCTION__, CURRENT_THREAD->trdid, process->pid, name, cycle ); 230 uint32_t cycle = (uint32_t)hal_get_cycles(); 231 thread_t * this = CURRENT_THREAD; 232 if( DEBUG_ELF_LOAD < cycle ) 233 printk("\n[%s] thread[%x,%x] enter for <%s> / cycle %d\n", 234 __FUNCTION__, this->process->pid, this->trdid, name, cycle ); 234 235 #endif 235 236 … … 246 247 #if (DEBUG_ELF_LOAD & 1) 247 248 if( DEBUG_ELF_LOAD < cycle ) 248 printk("\n[ DBG] %s :loaded elf header for <%s>\n", __FUNCTION__ , name );249 printk("\n[%s] loaded elf header for <%s>\n", __FUNCTION__ , name ); 249 250 #endif 250 251 … … 283 284 #if (DEBUG_ELF_LOAD & 1) 284 285 if( DEBUG_ELF_LOAD < cycle ) 285 printk("\n[ DBG] %s :segments array allocated for <%s>\n", __FUNCTION__ , name );286 printk("\n[%s] segments array allocated for <%s>\n", __FUNCTION__ , name ); 286 287 #endif 287 288 … … 302 303 #if (DEBUG_ELF_LOAD & 1) 303 304 if( DEBUG_ELF_LOAD < cycle ) 304 printk("\n[ DBG] %sloaded segments descriptors for <%s>\n", __FUNCTION__ , name );305 printk("\n[%s] loaded segments descriptors for <%s>\n", __FUNCTION__ , name ); 305 306 #endif 306 307 … … 330 331 cycle = (uint32_t)hal_get_cycles(); 331 332 if( DEBUG_ELF_LOAD < cycle ) 332 printk("\n[ DBG] %s : thread %x in process %xexit for <%s> / entry_point %x / cycle %d\n",333 __FUNCTION__, CURRENT_THREAD->trdid, process->pid, name, header.e_entry, cycle );333 printk("\n[%s] thread[%x,%x] exit for <%s> / entry_point %x / cycle %d\n", 334 __FUNCTION__, this->process->pid, this->trdid, name, header.e_entry, cycle ); 334 335 #endif 335 336 -
trunk/kernel/libk/grdxt.c
r492 r603 24 24 #include <hal_kernel_types.h> 25 25 #include <hal_special.h> 26 #include <hal_remote.h> 26 27 #include <errno.h> 27 28 #include <printk.h> 28 #include <vseg.h>29 29 #include <kmem.h> 30 30 #include <grdxt.h> … … 53 53 54 54 return 0; 55 } 55 56 } // end grdxt_init() 56 57 57 58 ////////////////////////////////// … … 70 71 uint32_t ix1; 71 72 uint32_t ix2; 73 74 // check rt 75 assert( (rt != NULL) , "pointer on radix tree is NULL\n" ); 72 76 73 77 req.type = KMEM_GENERIC; … … 107 111 } // end grdxt_destroy() 108 112 109 /////////////////////////////// 110 void grdxt_print( grdxt_t * rt, 111 char * name ) 112 { 113 uint32_t ix1; 114 uint32_t ix2; 115 uint32_t ix3; 116 117 uint32_t w1 = rt->ix1_width; 118 uint32_t w2 = rt->ix2_width; 119 uint32_t w3 = rt->ix3_width; 120 121 void ** ptr1 = rt->root; 122 void ** ptr2; 123 void ** ptr3; 124 125 intptr_t key; 126 intptr_t value; 127 128 printk("\n***** Generic Radix tree %s : n1 = %d / n2 = %d / n3 = %d\n\n", 129 name, 1<<w1 , 1<<w2 , 1<<w3 ); 113 //////////////////////////////////// 114 void grdxt_display( xptr_t rt_xp, 115 char * name ) 116 { 117 uint32_t ix1; 118 uint32_t ix2; 119 uint32_t ix3; 120 121 // check rt_xp 122 assert( (rt_xp != XPTR_NULL) , "pointer on radix tree is NULL\n" ); 123 124 // get cluster and local pointer on remote rt descriptor 125 grdxt_t * rt_ptr = GET_PTR( rt_xp ); 126 cxy_t rt_cxy = GET_CXY( rt_xp ); 127 128 // get widths 129 uint32_t w1 = hal_remote_l32( XPTR( rt_cxy , &rt_ptr->ix1_width ) ); 130 uint32_t w2 = hal_remote_l32( XPTR( rt_cxy , &rt_ptr->ix2_width ) ); 131 uint32_t w3 = hal_remote_l32( XPTR( rt_cxy , &rt_ptr->ix3_width ) ); 132 133 void ** ptr1 = hal_remote_lpt( XPTR( rt_cxy , &rt_ptr->root ) ); 134 135 printk("\n***** Generic Radix Tree for <%s> : %d / %d / %d\n", 136 name, 1<<w1 , 1<<w2 , 1<<w3 ); 130 137 131 138 for( ix1=0 ; ix1 < (uint32_t)(1<<w1) ; ix1++ ) 132 139 { 133 ptr2 = ptr1[ix1];140 void ** ptr2 = hal_remote_lpt( XPTR( rt_cxy , &ptr1[ix1] ) ); 134 141 if( ptr2 == NULL ) continue; 135 142 136 143 for( ix2=0 ; ix2 < (uint32_t)(1<<w2) ; ix2++ ) 137 144 { 138 ptr3 = ptr2[ix2];145 void ** ptr3 = hal_remote_lpt( XPTR( rt_cxy , &ptr2[ix2] ) ); 139 146 if( ptr3 == NULL ) continue; 140 147 141 148 for( ix3=0 ; ix3 < (uint32_t)(1<<w3) ; ix3++ ) 142 149 { 143 v alue = (intptr_t)ptr3[ix3];144 if( value == 0) continue;145 146 key = (ix1<<(w2+w3)) + (ix2<<w3) + ix3;147 printk(" - key = %x / value = %x\n", key , value );150 void * value = hal_remote_lpt( XPTR( rt_cxy , &ptr3[ix3] ) ); 151 if( value == NULL ) continue; 152 153 uint32_t key = (ix1<<(w2+w3)) + (ix2<<w3) + ix3; 154 printk(" - key = %x / value = %x\n", key , (intptr_t)value ); 148 155 } 149 156 } 150 157 } 151 } // end grdxt_print() 158 159 } // end grdxt_display() 152 160 153 161 //////////////////////////////////// … … 162 170 uint32_t w3 = rt->ix3_width; 163 171 164 // Check key 165 if( (key >> (w1 + w2 + w3)) != 0 ) 166 { 167 assert( false , 168 "key value %x exceed (%d + %d + %d) bits", key , w1 , w2 , w3 ); 169 } 172 // Check key value 173 assert( ((key >> (w1 + w2 + w3)) == 0 ), "illegal key value %x\n", key ); 170 174 171 175 // compute indexes … … 179 183 180 184 // If required, we must allocate memory for the selected level 2 array, 181 // and atomicallyupdate the level 1 array.185 // and update the level 1 array. 182 186 if( ptr1[ix1] == NULL ) 183 187 { … … 198 202 199 203 // If required, we must allocate memory for the selected level 3 array, 200 // and atomicallyupdate the level 2 array.204 // and update the level 2 array. 201 205 if( ptr2[ix2] == NULL ) 202 206 { … … 224 228 225 229 return 0; 226 } 230 231 } // end grdxt_insert() 227 232 228 233 /////////////////////////////////// … … 234 239 uint32_t w3 = rt->ix3_width; 235 240 236 // Check key 237 if( (key >> (w1 + w2 + w3)) != 0 ) 238 { 239 assert( false , 240 "key value %x exceed (%d + %d + %d) bits", key , w1 , w2 , w3 ); 241 } 241 // Check key value 242 assert( ((key >> (w1 + w2 + w3)) == 0 ), "illegal key value %x\n", key ); 242 243 243 244 // compute indexes … … 266 267 267 268 return value; 268 } 269 270 } // end grdxt_remove() 269 271 270 272 /////////////////////////////////// … … 276 278 uint32_t w3 = rt->ix3_width; 277 279 278 // Check key 279 if( (key >> (w1 + w2 + w3)) != 0 ) 280 { 281 assert( false , 282 "key value %x exceed (%d + %d + %d) bits", key , w1 , w2 , w3 ); 283 } 280 // Check key value 281 assert( ((key >> (w1 + w2 + w3)) == 0 ), "illegal key value %x\n", key ); 284 282 285 283 void ** ptr1 = rt->root; … … 304 302 305 303 return value; 306 } 304 305 } // end grdxt_lookup() 306 307 //////////////////////////////////////////// 308 xptr_t grdxt_remote_lookup( xptr_t rt_xp, 309 uint32_t key ) 310 { 311 // get cluster and local pointer on remote rt descriptor 312 grdxt_t * rt_ptr = GET_PTR( rt_xp ); 313 cxy_t rt_cxy = GET_CXY( rt_xp ); 314 315 // get widths 316 uint32_t w1 = hal_remote_l32( XPTR( rt_cxy , &rt_ptr->ix1_width ) ); 317 uint32_t w2 = hal_remote_l32( XPTR( rt_cxy , &rt_ptr->ix2_width ) ); 318 uint32_t w3 = hal_remote_l32( XPTR( rt_cxy , &rt_ptr->ix3_width ) ); 319 320 // Check key value 321 assert( ((key >> (w1 + w2 + w3)) == 0 ), "illegal key value %x\n", key ); 322 323 // compute indexes 324 uint32_t ix1 = key >> (w2 + w3); // index in level 1 array 325 uint32_t ix2 = (key >> w3) & ((1 << w2) -1); // index in level 2 array 326 uint32_t ix3 = key & ((1 << w3) - 1); // index in level 3 array 327 328 // get ptr1 329 void ** ptr1 = hal_remote_lpt( XPTR( rt_cxy , &rt_ptr->root ) ); 330 331 // get ptr2 332 void ** ptr2 = hal_remote_lpt( XPTR( rt_cxy , &ptr1[ix1] ) ); 333 if( ptr2 == NULL ) return XPTR_NULL; 334 335 // get ptr3 336 void ** ptr3 = hal_remote_lpt( XPTR( rt_cxy , &ptr2[ix2] ) ); 337 if( ptr3 == NULL ) return XPTR_NULL; 338 339 // get value 340 xptr_t value = XPTR( rt_cxy , ptr3[ix3] ); 341 342 return value; 343 344 } // end grdxt_remote_lookup() 307 345 308 346 ////////////////////////////////////// … … 319 357 uint32_t w3 = rt->ix3_width; 320 358 321 // Check start_key 322 if( (start_key >> (w1 + w2 + w3)) != 0 ) 323 { 324 assert( false , 325 "start_key value %x exceed (%d + %d + %d) bits", start_key , w1 , w2 , w3 ); 326 } 359 // Check key value 360 assert( ((start_key >> (w1 + w2 + w3)) == 0 ), "illegal key value %x\n", start_key ); 327 361 328 362 // compute max indexes … … 363 397 364 398 return NULL; 365 } 399 400 } // end grdxt_get_first() -
trunk/kernel/libk/grdxt.h
r457 r603 36 36 * Memory for the second and third levels arrays is dynamically allocated by the 37 37 * grdxt_insert() function and is only released by grdxt_destroy(). 38 * It is used by the MAPPER to implement the file cache: key is the page index in file. 38 * - This structure is entirely contained in one single cluster. 39 * - All modifications (insert / remove) must be done by a thread running in local cluster. 40 * - Lookup can be done by a thread running in any cluster (local or remote). 41 ****************************************************************************************** 42 * It is used by the mapper implementing the file cache: 43 * - the key is the page index in file. 44 * - the registered value is a local pointer on the page descriptor. 39 45 ******************************************************************************************/ 40 46 … … 96 102 97 103 /******************************************************************************************* 98 * This function returns the pointer on the item identified by its key. 104 * This function returns to a local client, a local pointer on the item identified 105 * by the <key> argument, from the radix tree identified by the <rt> local pointer. 99 106 ******************************************************************************************* 100 * @ rt : pointer on the radix-tree descriptor.107 * @ rt : local pointer on the radix-tree descriptor. 101 108 * @ key : key value. 102 * @ returns pointer on found item if success / returns NULL if failure.109 * @ returns a local pointer on found item if success / returns NULL if failure. 103 110 ******************************************************************************************/ 104 111 void * grdxt_lookup( grdxt_t * rt, 105 112 uint32_t key ); 113 114 /******************************************************************************************* 115 * This function returns to a - possibly remote - remote client, an extended pointer 116 * on the item identified by the <key> argument, from the radix tree identified by 117 * the <rt_xp> remote pointer. 118 ******************************************************************************************* 119 * @ rt_xp : extended pointer on the radix-tree descriptor. 120 * @ key : key value. 121 * @ returns an extended pointer on found item if success / returns XPTR_NULL if failure. 122 ******************************************************************************************/ 123 xptr_t grdxt_remote_lookup( xptr_t rt_xp, 124 uint32_t key ); 106 125 107 126 /******************************************************************************************* … … 120 139 121 140 /******************************************************************************************* 122 * This function displays the current content of a radix_tree.141 * This function displays the current content of a possibly remote radix_tree. 123 142 ******************************************************************************************* 124 * @ rt : pointer on the radix-tree descriptor.143 * @ rt : extended pointer on the radix-tree descriptor. 125 144 * @ string : radix tree identifier. 126 145 ******************************************************************************************/ 127 void grdxt_ print( grdxt_t * rt,128 char * string );146 void grdxt_display( xptr_t rt_xp, 147 char * string ); 129 148 130 149 -
trunk/kernel/libk/queuelock.c
r600 r603 44 44 list_root_init( &lock->root ); 45 45 busylock_init( &lock->lock , type ); 46 47 #if DEBUG_QUEUELOCK 48 thread_t * this = CURRENT_THREAD; 49 if( DEBUG_QUEUELOCK < (uint32_t)hal_get_cycles() ) 50 printk("\n[%s] thread[%x,%x] initialise lock %s [%x,%x]\n", 51 __FUNCTION__, this->process->pid, this->trdid, 52 lock_type_str[type], local_cxy, lock ); 53 #endif 54 46 55 } 47 56 … … 64 73 if( DEBUG_QUEUELOCK < (uint32_t)hal_get_cycles() ) 65 74 printk("\n[%s ] thread[%x,%x] BLOCK on q_lock %s [%x,%x]\n", 66 __FUNCTION__, this->process->pid, this->trdid, lock_type_str[lock->lock.type], local_cxy, lock ); 75 __FUNCTION__, this->process->pid, this->trdid, 76 lock_type_str[lock->lock.type], local_cxy, lock ); 67 77 #endif 68 78 // get pointer on calling thread … … 88 98 if( DEBUG_QUEUELOCK < (uint32_t)hal_get_cycles() ) 89 99 printk("\n[%s] thread[%x,%x] ACQUIRE q_lock %s [%x,%x]\n", 90 __FUNCTION__, this->process->pid, this->trdid, lock_type_str[lock->lock.type], local_cxy, lock ); 100 __FUNCTION__, this->process->pid, this->trdid, 101 lock_type_str[lock->lock.type], local_cxy, lock ); 91 102 #endif 92 103 … … 112 123 if( DEBUG_QUEUELOCK < (uint32_t)hal_get_cycles() ) 113 124 printk("\n[%s] thread[%x,%x] RELEASE q_lock %s [%x,%x]\n", 114 __FUNCTION__, this->process->pid, this->trdid, lock_type_str[lock->lock.type], local_cxy, lock ); 125 __FUNCTION__, this->process->pid, this->trdid, 126 lock_type_str[lock->lock.type], local_cxy, lock ); 115 127 #endif 116 128 -
trunk/kernel/libk/remote_busylock.h
r563 r603 1 1 /* 2 * remote_busylock.h: remote kernel busy 2 * remote_busylock.h: remote kernel busy-waiting lock definition. 3 3 * 4 4 * Authors Alain Greiner (2016,2017,2018) … … 33 33 * This synchronisation object sequencializes all concurrent read or write accesses to a 34 34 * shared object located in any cluster, made by any thread(s) running in any cluster. 35 * It uses a busy waiting policy when the tock is taken by another thread, and should35 * It uses a busy waiting policy when the lock is taken by another thread, and should 36 36 * be used ro execute very short actions, such as basic allocators, or to protect 37 37 * higher level synchronisation objects, such as remote_queuelock and remote_rwlock. 38 * 38 39 * WARNING: a thread cannot yield when it is owning a busylock (local or remote). 39 40 * … … 45 46 * decrements its busylocks counter. 46 47 * 47 :w* - When a thread takes a busylock, it enters a critical section: the busylock_acquire()48 * - When a thread takes a busylock, it enters a critical section: the busylock_acquire() 48 49 * function disables the IRQs, takes the lock, increments the thread busylocks counter, 49 * and save the SR inlock descriptor and returns.50 * save the SR in the lock descriptor and returns. 50 51 * 51 * - The busylock_release() function releases the lock, decrements the thread busylock52 * counter,restores the SR to exit the critical section, and returns52 * - The busylock_release() function decrements the thread busylock counter, 53 * restores the SR to exit the critical section, and returns 53 54 * 54 55 * - If a thread owning a busylock (local or remote) tries to deschedule, the scheduler … … 58 59 /******************************************************************************************* 59 60 * This structure defines a remote_busylock. 60 * The <type> and <xlist> fields are used for debug. 61 * The type defines the lock usage as detailed in the kernel_config.h file. 61 * - The <ticket> and <current> fields implement the ticket policy described above. 62 * - The <type> and <xlist> fields are used for debug. The type defines the lock usage, 63 * as detailed in the kernel_config.h file. 64 * - The <save_sr> field is used to implement the critical section as decribed above. 62 65 ******************************************************************************************/ 63 66 -
trunk/kernel/libk/remote_queuelock.c
r600 r603 53 53 // initialise busylock field 54 54 remote_busylock_init( XPTR( lock_cxy , &lock_ptr->lock ) , type ); 55 } 55 56 #if DEBUG_QUEUELOCK 57 thread_t * this = CURRENT_THREAD; 58 if( DEBUG_QUEUELOCK < (uint32_t)hal_get_cycles() ) 59 printk("\n[%s] thread[%x,%x] initialise lock %s [%x,%x]\n", 60 __FUNCTION__, this->process->pid, this->trdid, 61 lock_type_str[type], lock_cxy, lock_ptr ); 62 #endif 63 64 } // end remote_queuelock_init() 56 65 57 66 /////////////////////////////////////////////// -
trunk/kernel/libk/remote_rwlock.c
r600 r603 52 52 53 53 remote_busylock_init( XPTR( lock_cxy , &lock_ptr->lock ) , type ); 54 55 #if DEBUG_RWLOCK 56 thread_t * this = CURRENT_THREAD; 57 if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() ) 58 printk("\n[%s] thread[%x,%x] initialise lock %s [%x,%x]\n", 59 __FUNCTION__, this->process->pid, this->trdid, 60 lock_type_str[type], local_cxy, lock_ptr ); 61 #endif 62 54 63 } 55 64 … … 85 94 #if DEBUG_RWLOCK 86 95 if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() ) 87 printk("\n[%s] thread[%x,%x] READ BLOCK on rwlock %s [%x,%x] \n",96 printk("\n[%s] thread[%x,%x] READ BLOCK on rwlock %s [%x,%x] / taken %d / count %d\n", 88 97 __FUNCTION__, this->process->pid, this->trdid, 89 lock_type_str[lock_type], lock_cxy, lock_ptr ); 98 lock_type_str[lock_type], lock_cxy, lock_ptr, 99 hal_remote_l32( taken_xp ), hal_remote_l32( count_xp ) ); 90 100 #endif 91 101 // get pointer on calling thread … … 108 118 } 109 119 110 #if DEBUG_RWLOCK111 if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() )112 printk("\n[%s] thread[%x,%x] READ ACQUIRE rwlock %s [%x,%x]\n",113 __FUNCTION__, this->process->pid, this->trdid,114 lock_type_str[lock_type], lock_cxy, lock_ptr );115 #endif116 117 120 // increment number of readers 118 121 hal_remote_atomic_add( count_xp , 1 ); 122 123 hal_fence(); 124 125 #if DEBUG_RWLOCK 126 if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() ) 127 printk("\n[%s] thread[%x,%x] READ ACQUIRE rwlock %s [%x,%x] / taken = %d / count = %d\n", 128 __FUNCTION__, this->process->pid, this->trdid, 129 lock_type_str[lock_type], lock_cxy, lock_ptr, 130 hal_remote_l32( taken_xp ), hal_remote_l32( count_xp ) ); 131 #endif 119 132 120 133 // release busylock … … 154 167 #if DEBUG_RWLOCK 155 168 if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() ) 156 printk("\n[%s] thread[%x,%x] WRITE BLOCK on rwlock %s [%x,%x] \n",169 printk("\n[%s] thread[%x,%x] WRITE BLOCK on rwlock %s [%x,%x] / taken %d / count %d\n", 157 170 __FUNCTION__, this->process->pid, this->trdid, 158 lock_type_str[lock_type], lock_cxy, lock_ptr ); 159 #endif 171 lock_type_str[lock_type], lock_cxy, lock_ptr, 172 hal_remote_l32( taken_xp ), hal_remote_l32( count_xp ) ); 173 #endif 174 160 175 // get local pointer on calling thread 161 176 thread_t * this = CURRENT_THREAD; … … 177 192 } 178 193 179 #if DEBUG_RWLOCK 180 if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() ) 181 printk("\n[%s] thread[%x,%x] WRITE ACQUIRE rwlock %s [%x,%x]\n", 194 // take rwlock for write 195 hal_remote_s32( taken_xp , 1 ); 196 197 #if DEBUG_RWLOCK 198 if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() ) 199 printk("\n[%s] thread[%x,%x] WRITE ACQUIRE rwlock %s [%x,%x] / taken %d / count %d\n", 182 200 __FUNCTION__, this->process->pid, this->trdid, 183 lock_type_str[lock_type], lock_cxy, lock_ptr ); 184 #endif 185 186 // take rwlock 187 hal_remote_s32( taken_xp , 1 ); 201 lock_type_str[lock_type], lock_cxy, lock_ptr, 202 hal_remote_l32( taken_xp ), hal_remote_l32( count_xp ) ); 203 #endif 188 204 189 205 // release busylock … … 212 228 remote_busylock_acquire( busylock_xp ); 213 229 230 // decrement number of readers 231 hal_remote_atomic_add( count_xp , -1 ); 232 214 233 #if DEBUG_RWLOCK 215 234 thread_t * this = CURRENT_THREAD; 216 235 uint32_t lock_type = hal_remote_l32( XPTR( lock_cxy , &lock_ptr->lock.type ) ); 217 if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() ) 218 printk("\n[%s] thread[%x,%x] READ RELEASE rwlock %s [%x,%x]\n", 236 xptr_t taken_xp = XPTR( lock_cxy , &lock_ptr->taken ); 237 if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() ) 238 printk("\n[%s] thread[%x,%x] READ RELEASE rwlock %s [%x,%x] / taken %d / count %d\n", 219 239 __FUNCTION__, this->process->pid, this->trdid, 220 lock_type_str[lock_type], lock_cxy, lock_ptr ); 221 #endif 222 223 // decrement number of readers 224 hal_remote_atomic_add( count_xp , -1 ); 240 lock_type_str[lock_type], lock_cxy, lock_ptr, 241 hal_remote_l32( taken_xp ), hal_remote_l32( count_xp ) ); 242 #endif 225 243 226 244 // release first writer in waiting queue if no current readers … … 309 327 remote_busylock_acquire( busylock_xp ); 310 328 329 // release rwlock 330 hal_remote_s32( taken_xp , 0 ); 331 311 332 #if DEBUG_RWLOCK 312 333 thread_t * this = CURRENT_THREAD; 313 334 uint32_t lock_type = hal_remote_l32( XPTR( lock_cxy , &lock_ptr->lock.type ) ); 314 if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() ) 315 printk("\n[%s] thread[%x,%x] WRITE RELEASE rwlock %s [%x,%x]\n", 335 xptr_t count_xp = XPTR( lock_cxy , &lock_ptr->count ); 336 if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() ) 337 printk("\n[%s] thread[%x,%x] WRITE RELEASE rwlock %s [%x,%x] / taken %d / count %d\n", 316 338 __FUNCTION__, this->process->pid, this->trdid, 317 lock_type_str[lock_type], lock_cxy, lock_ptr ); 318 #endif 319 320 // release rwlock 321 hal_remote_s32( taken_xp , 0 ); 339 lock_type_str[lock_type], lock_cxy, lock_ptr, 340 hal_remote_l32( taken_xp ), hal_remote_l32( count_xp ) ); 341 #endif 322 342 323 343 // unblock first waiting writer thread if writers waiting queue non empty -
trunk/kernel/libk/rwlock.c
r600 r603 49 49 50 50 busylock_init( &lock->lock , type ); 51 52 #if DEBUG_RWLOCK 53 thread_t * this = CURRENT_THREAD; 54 if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() ) 55 printk("\n[%s] thread[%x,%x] initialise lock %s [%x,%x]\n", 56 __FUNCTION__, this->process->pid, this->trdid, 57 lock_type_str[type], local_cxy, lock ); 58 #endif 59 51 60 } 52 61 … … 68 77 #if DEBUG_RWLOCK 69 78 if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() ) 70 printk("\n[%s] thread[%x,%x] READ BLOCK on rwlock %s [%x,%x] \n",71 __FUNCTION__, this->process->pid, this->trdid, 72 lock_type_str[lock->lock.type], local_cxy, lock );79 printk("\n[%s] thread[%x,%x] READ BLOCK on rwlock %s [%x,%x] / taken %d / count %d\n", 80 __FUNCTION__, this->process->pid, this->trdid, 81 lock_type_str[lock->lock.type], local_cxy, lock, lock->taken, lock->count ); 73 82 #endif 74 83 // register reader thread in waiting queue … … 88 97 } 89 98 90 #if DEBUG_RWLOCK91 if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() )92 printk("\n[%s] thread[%x,%x] READ ACQUIRE rwlock %s [%x,%x]\n",93 __FUNCTION__, this->process->pid, this->trdid,94 lock_type_str[lock->lock.type], local_cxy, lock );95 #endif96 97 99 // increment number of readers 98 100 lock->count++; 101 102 #if DEBUG_RWLOCK 103 if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() ) 104 printk("\n[%s] thread[%x,%x] READ ACQUIRE rwlock %s [%x,%x] / taken %d / count %d\n", 105 __FUNCTION__, this->process->pid, this->trdid, 106 lock_type_str[lock->lock.type], local_cxy, lock, lock->taken, lock->count ); 107 #endif 99 108 100 109 // release busylock … … 120 129 #if DEBUG_RWLOCK 121 130 if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() ) 122 printk("\n[%s] thread[%x,%x] WRITE BLOCK on rwlock %s [%x,%x] \n",123 __FUNCTION__, this->process->pid, this->trdid, 124 lock_type_str[lock->lock.type], local_cxy, lock );131 printk("\n[%s] thread[%x,%x] WRITE BLOCK on rwlock %s [%x,%x] / taken %d / count %d\n", 132 __FUNCTION__, this->process->pid, this->trdid, 133 lock_type_str[lock->lock.type], local_cxy, lock, lock->taken, lock->count ); 125 134 #endif 126 135 // register writer in waiting queue 127 136 list_add_last( &lock->wr_root , &this->wait_list ); 128 137 129 // block reader thread138 // block writer thread 130 139 thread_block( XPTR( local_cxy , this ) , THREAD_BLOCKED_LOCK ); 131 140 … … 140 149 } 141 150 142 #if DEBUG_RWLOCK143 if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() )144 printk("\n[%s] thread[%x,%x] WRITE ACQUIRE rwlock %s [%x,%x]\n",145 __FUNCTION__, this->process->pid, this->trdid,146 lock_type_str[lock->lock.type], local_cxy, lock );147 #endif148 149 151 // take the rwlock 150 152 lock->taken = 1; 153 154 #if DEBUG_RWLOCK 155 if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() ) 156 printk("\n[%s] thread[%x,%x] WRITE ACQUIRE rwlock %s [%x,%x] / taken %d / count %d\n", 157 __FUNCTION__, this->process->pid, this->trdid, 158 lock_type_str[lock->lock.type], local_cxy, lock, lock->taken, lock->count ); 159 #endif 151 160 152 161 // release busylock … … 164 173 busylock_acquire( &lock->lock ); 165 174 166 #if DEBUG_RWLOCK167 thread_t * this = CURRENT_THREAD;168 if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() )169 printk("\n[%s] thread[%x,%x] READ RELEASE rwlock %s [%x,%x]\n",170 __FUNCTION__, this->process->pid, this->trdid,171 lock_type_str[lock->lock.type], local_cxy, lock );172 #endif173 174 175 // decrement number of readers 175 176 lock->count--; 177 178 #if DEBUG_RWLOCK 179 thread_t * this = CURRENT_THREAD; 180 if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() ) 181 printk("\n[%s] thread[%x,%x] READ RELEASE rwlock %s [%x,%x] / taken %d / count %d\n", 182 __FUNCTION__, this->process->pid, this->trdid, 183 lock_type_str[lock->lock.type], local_cxy, lock, lock->taken, lock->count ); 184 #endif 176 185 177 186 // release first writer in waiting queue if no current readers … … 233 242 busylock_acquire( &lock->lock ); 234 243 235 #if DEBUG_RWLOCK236 thread_t * this = CURRENT_THREAD;237 if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() )238 printk("\n[%s] thread[%x,%x] WRITE RELEASE rwlock %s [%x,%x]\n",239 __FUNCTION__, this->process->pid, this->trdid,240 lock_type_str[lock->lock.type], local_cxy, lock );241 #endif242 243 244 // release the rwlock 244 245 lock->taken = 0; 246 247 #if DEBUG_RWLOCK 248 thread_t * this = CURRENT_THREAD; 249 if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() ) 250 printk("\n[%s] thread[%x,%x] WRITE RELEASE rwlock %s [%x,%x] / taken %d / count %d\n", 251 __FUNCTION__, this->process->pid, this->trdid, 252 lock_type_str[lock->lock.type], local_cxy, lock, lock->taken, lock->count ); 253 #endif 245 254 246 255 // release first waiting writer thread if writers waiting queue non empty -
trunk/kernel/libk/xhtab.c
r563 r603 203 203 204 204 #if DEBUG_XHTAB 205 printk("\n[ DBG] %s : enter /%s\n", __FUNCTION__, key );205 printk("\n[%s] enter / key %s\n", __FUNCTION__, key ); 206 206 #endif 207 207 … … 241 241 242 242 #if DEBUG_XHTAB 243 printk("\n[ DBG] %s :success / %s\n", __FUNCTION__, key );243 printk("\n[%s] success / %s\n", __FUNCTION__, key ); 244 244 #endif 245 245 … … 248 248 } // end xhtab_insert() 249 249 250 ///////////////////////////////////// 251 error_t xhtab_remove( xptr_t xhtab_xp,252 253 250 /////////////////////////////////////// 251 bool_t xhtab_remove( xptr_t xhtab_xp, 252 void * key, 253 xptr_t xlist_entry_xp ) 254 254 { 255 255 xptr_t item_xp; … … 275 275 item_xp = xhtab_scan( xhtab_xp , index , key ); 276 276 277 if( item_xp == XPTR_NULL ) // error if not found277 if( item_xp == XPTR_NULL ) // return error if not found 278 278 { 279 279 // release the lock protecting hash table 280 280 remote_busylock_release( XPTR( xhtab_cxy , &xhtab_ptr->lock ) ); 281 281 282 return EINVAL;282 return false; 283 283 } 284 284 else // remove item if found … … 293 293 remote_busylock_release( XPTR( xhtab_cxy , &xhtab_ptr->lock ) ); 294 294 295 return 0;295 return true; 296 296 } 297 297 } // end xhtab_remove() … … 318 318 319 319 #if DEBUG_XHTAB 320 printk("\n[ DBG] %s :enter / %s\n", __FUNCTION__, key );320 printk("\n[%s] enter / %s\n", __FUNCTION__, key ); 321 321 #endif 322 322 … … 325 325 326 326 #if DEBUG_XHTAB 327 printk("\n[ DBG] %s :after lock acquire / %s\n", __FUNCTION__, key );327 printk("\n[%s] after lock acquire / %s\n", __FUNCTION__, key ); 328 328 #endif 329 329 … … 332 332 333 333 #if DEBUG_XHTAB 334 printk("\n[ DBG] %s :after xhtab scan / %s\n", __FUNCTION__, key );334 printk("\n[%s] after xhtab scan / %s\n", __FUNCTION__, key ); 335 335 #endif 336 336 … … 339 339 340 340 #if DEBUG_XHTAB 341 printk("\n[ DBG] %s :after lock release / %s\n", __FUNCTION__, key );341 printk("\n[%s] after lock release / %s\n", __FUNCTION__, key ); 342 342 #endif 343 343 -
trunk/kernel/libk/xhtab.h
r563 r603 127 127 * @ key : local pointer on item identifier. 128 128 * @ xlist_xp : extended pointer on xlist_entry embedded in item to be removed. 129 * @ return 0 if success / return EINVALif item not found.129 * @ return 0 if item found / return false if item not found. 130 130 *****************************************************************************************/ 131 error_t xhtab_remove( xptr_t xhtab_xp,132 133 131 bool_t xhtab_remove( xptr_t xhtab_xp, 132 void * key, 133 xptr_t xlist_entry_xp ); 134 134 135 135 /****************************************************************************************** -
trunk/kernel/libk/xlist.h
r563 r603 25 25 */ 26 26 27 #ifndef _ ALMOS_XLIST_H_28 #define _ ALMOS_XLIST_H_27 #ifndef _XLIST_H_ 28 #define _XLIST_H_ 29 29 30 30 #include <kernel_config.h> … … 81 81 **************************************************************************/ 82 82 83 #define XLIST_FIRST( root_xp , type , member ) \84 ({ xptr_t __first = hal_remote_l64( root_xp ); 83 #define XLIST_FIRST( root_xp , type , member ) \ 84 ({ xptr_t __first = hal_remote_l64( root_xp ); \ 85 85 XLIST_ELEMENT( __first , type , member ); }) 86 86 … … 95 95 **************************************************************************/ 96 96 97 #define XLIST_LAST( root_xp , type , member ) \98 ({ xptr_t __last = hal_remote_l64( root_xp + 8); \97 #define XLIST_LAST( root_xp , type , member ) \ 98 ({ xptr_t __last = hal_remote_l64( root_xp + sizeof(xptr_t) ); \ 99 99 XLIST_ELEMENT( __last , type , member ); }) 100 100 … … 118 118 **************************************************************************/ 119 119 120 #define XLIST_FOREACH_BACKWARD( root_xp , iter_xp ) \121 for( (iter_xp) = hal_remote_l64( (root_xp) + 8 ) ;\122 (iter_xp) != (root_xp) ; \123 (iter_xp) = hal_remote_l64( (iter_xp) + 8) )120 #define XLIST_FOREACH_BACKWARD( root_xp , iter_xp ) \ 121 for( (iter_xp) = hal_remote_l64( (root_xp) + sizeof(xptr_t) ) ; \ 122 (iter_xp) != (root_xp) ; \ 123 (iter_xp) = hal_remote_l64( (iter_xp) + sizeof(xptr_t) ) ) 124 124 125 125 /*************************************************************************** … … 156 156 157 157 // get ref->pred 158 xptr_t ref_pred = (xptr_t)hal_remote_l64( ref + 8);158 xptr_t ref_pred = (xptr_t)hal_remote_l64( ref + sizeof(xptr_t) ); 159 159 160 160 // test if list is empty or ref is the first element … … 171 171 static inline void xlist_root_init( xptr_t root_xp ) 172 172 { 173 hal_remote_s64( root_xp, root_xp );174 hal_remote_s64( root_xp+8, root_xp );173 hal_remote_s64( root_xp , root_xp ); 174 hal_remote_s64( root_xp + sizeof(xptr_t) , root_xp ); 175 175 } 176 176 … … 182 182 static inline void xlist_entry_init( xptr_t entry_xp ) 183 183 { 184 hal_remote_s64( entry_xp, 0 );185 hal_remote_s64( entry_xp+8, 0 );184 hal_remote_s64( entry_xp , 0 ); 185 hal_remote_s64( entry_xp + sizeof(xptr_t) , 0 ); 186 186 } 187 187 … … 206 206 207 207 // entry.pred <= root 208 hal_remote_s64( entry + 8, (uint64_t)root );208 hal_remote_s64( entry + sizeof(xptr_t) , (uint64_t)root ); 209 209 210 210 // first.pred <= new 211 hal_remote_s64( first + 8, (uint64_t)entry );211 hal_remote_s64( first + sizeof(xptr_t) , (uint64_t)entry ); 212 212 } 213 213 … … 223 223 { 224 224 // get the extended pointer on the last element in list 225 xptr_t last = (xptr_t)hal_remote_l64( root + 8);225 xptr_t last = (xptr_t)hal_remote_l64( root + sizeof(xptr_t) ); 226 226 227 227 // update root.pred <= entry 228 hal_remote_s64( root + 8, (uint64_t)entry );228 hal_remote_s64( root + sizeof(xptr_t) , (uint64_t)entry ); 229 229 230 230 // update entry.pred <= last 231 hal_remote_s64( entry + 8, (uint64_t)last );231 hal_remote_s64( entry + sizeof(xptr_t) , (uint64_t)last ); 232 232 233 233 // entry.next <= root … … 262 262 xlist_entry_t entry; 263 263 hal_remote_memcpy( XPTR( local_cxy , &entry ) , 264 265 264 xp , 265 sizeof(xlist_entry_t) ); 266 266 267 267 xptr_t next = entry.next; … … 272 272 273 273 // update next.pred <= pred 274 hal_remote_s64( next + 8, (uint64_t)pred );274 hal_remote_s64( next + sizeof(xptr_t) , (uint64_t)pred ); 275 275 } 276 276 … … 298 298 299 299 // update new.pred <= pred 300 hal_remote_s64( new + 8, (uint64_t)pred );300 hal_remote_s64( new + sizeof(xptr_t) , (uint64_t)pred ); 301 301 302 302 // update pred.next <= new … … 304 304 305 305 // update next.pred <= new 306 hal_remote_s64( next + 8, (uint64_t)new );307 } 308 309 #endif /* _ ALMOS_LIST_H_ */306 hal_remote_s64( next + sizeof(xptr_t) , (uint64_t)new ); 307 } 308 309 #endif /* _XLIST_H_ */
Note: See TracChangeset
for help on using the changeset viewer.