Changeset 657 for trunk/kernel/libk
- Timestamp:
- Mar 18, 2020, 11:16:59 PM (5 years ago)
- Location:
- trunk/kernel/libk
- Files:
-
- 2 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/libk/bits.c
r635 r657 1 1 /* 2 * bits.c - bit s manipulation functionsimplementation2 * bits.c - bitmap API implementation 3 3 * 4 4 * Author Ghassan Almaless (2008,2009,2010,2011,2012) 5 * Alain Greiner (2016,2017,2018,2019 )5 * Alain Greiner (2016,2017,2018,2019,2020) 6 6 * 7 7 * Copyright (c) UPMC Sorbonne Universites … … 26 26 #include <bits.h> 27 27 28 ////////////////////////////////////////////////////////////////////////////// 29 ////////////// local access functions /////////////////////////////// 30 ////////////////////////////////////////////////////////////////////////////// 31 28 32 //////////////////////////////////// 29 33 void bitmap_init( bitmap_t * bitmap, … … 42 46 uint32_t index ) 43 47 { 44 uint32_t word = index / 32;45 uint32_t bit = index % 32;48 uint32_t word = index >> 5; 49 uint32_t bit = index & 0x1F; 46 50 47 51 bitmap[word] |= ( 1 << bit ); … … 52 56 uint32_t index ) 53 57 { 54 uint32_t word = index / 32;55 uint32_t bit = index % 32;58 uint32_t word = index >> 5; 59 uint32_t bit = index & 0x1F; 56 60 57 61 bitmap[word] &= ~( 1 << bit ); … … 62 66 uint32_t index ) 63 67 { 64 uint32_t word = index / 32;65 uint32_t bit = index % 32;68 uint32_t word = index >> 5; 69 uint32_t bit = index & 0x1F; 66 70 67 71 return (bitmap[word] & ( 1 << bit )) != 0; 68 72 } 73 74 ///////////////////////////////////////// 75 uint32_t bitmap_alloc( bitmap_t * bitmap, 76 uint32_t size ) 77 { 78 uint32_t max_word; 79 uint32_t max_bit; 80 uint32_t word; 81 uint32_t bit; 82 83 if( size ) 84 { 85 max_word = ( (size-1) >>5 ) + 1; 86 87 for( word = 0 ; word < max_word ; word++ ) 88 { 89 max_bit = (word == (max_word - 1)) ? (size & 0x1F) : 32; 90 91 if(bitmap[word] != 0XFFFFFFFF) 92 { 93 for(bit = 0 ; bit < max_bit ; bit++) 94 { 95 if( (bitmap[word] & (1 << bit)) == 0 ) 96 { 97 bitmap[word] |= (1 << bit); 98 return (word*32 + bit); 99 } 100 } 101 } 102 } 103 } 104 105 return -1; 106 107 } // end bitmap_alloc() 69 108 70 109 ////////////////////////////////////////// … … 207 246 { 208 247 uint32_t max_word; 248 uint32_t max_bit; 209 249 uint32_t word; 210 250 uint32_t bit; … … 216 256 for( word = 0 ; word < max_word ; word++ ) 217 257 { 258 max_bit = (word == (max_word - 1)) ? (size & 0x1F) : 32; 259 218 260 if(bitmap[word] != 0) 219 261 { 220 for(bit = 0 ; bit < 32; bit++)262 for(bit = 0 ; bit < max_bit ; bit++) 221 263 { 222 264 if( bitmap[word] & (1 << bit) ) return (word*32 + bit); … … 235 277 { 236 278 uint32_t max_word; 279 uint32_t max_bit; 237 280 uint32_t word; 238 281 uint32_t bit; … … 244 287 for( word = 0 ; word < max_word ; word++ ) 245 288 { 289 max_bit = (word == (max_word - 1)) ? (size & 0x1F) : 32; 290 246 291 if(bitmap[word] != 0XFFFFFFFF) 247 292 { 248 for(bit = 0 ; bit < 32; bit++)293 for(bit = 0 ; bit < max_bit ; bit++) 249 294 { 250 295 if( (bitmap[word] & (1 << bit)) == 0 ) return (word*32 + bit); … … 258 303 } // bitmap_ffc() 259 304 305 306 ////////////////////////////////////////////////////////////////////////////// 307 ////////////// remote access functions /////////////////////////////// 308 ////////////////////////////////////////////////////////////////////////////// 309 310 //////////////////////////////////////////// 311 void bitmap_remote_init( xptr_t bitmap_xp, 312 uint32_t len ) 313 { 314 bitmap_t * bitmap_ptr = GET_PTR( bitmap_xp ); 315 cxy_t bitmap_cxy = GET_CXY( bitmap_xp ); 316 317 uint32_t word; 318 uint32_t nwords = BITMAP_SIZE( len ); 319 320 for( word = 0 ; word < nwords ; word++ ) 321 { 322 hal_remote_s32( XPTR( bitmap_cxy , &bitmap_ptr[word] ) , 0 ); 323 } 324 } 325 326 //////////////////////////////////////////////////// 327 inline void bitmap_remote_set( xptr_t bitmap_xp, 328 uint32_t index ) 329 { 330 bitmap_t * bitmap_ptr = GET_PTR( bitmap_xp ); 331 cxy_t bitmap_cxy = GET_CXY( bitmap_xp ); 332 333 uint32_t word = index / 32; 334 uint32_t bit = index % 32; 335 336 hal_remote_atomic_or( XPTR( bitmap_cxy , &bitmap_ptr[word] ) , (1 <<bit) ); 337 } 338 339 ////////////////////////////////////////////////////// 340 inline void bitmap_remote_clear( xptr_t bitmap_xp, 341 uint32_t index ) 342 { 343 bitmap_t * bitmap_ptr = GET_PTR( bitmap_xp ); 344 cxy_t bitmap_cxy = GET_CXY( bitmap_xp ); 345 346 uint32_t word = index / 32; 347 uint32_t bit = index % 32; 348 349 hal_remote_atomic_and( XPTR( bitmap_cxy , &bitmap_ptr[word] ) , ~(1 <<bit) ); 350 } 351 352 /////////////////////////////////////////////////// 353 uint32_t bitmap_remote_alloc( xptr_t bitmap_xp, 354 uint32_t size ) 355 { 356 uint32_t max_word; 357 uint32_t max_bit; 358 uint32_t word; 359 uint32_t bit; 360 xptr_t word_xp; 361 uint32_t value; 362 363 bitmap_t * bitmap_ptr = GET_PTR( bitmap_xp ); 364 cxy_t bitmap_cxy = GET_CXY( bitmap_xp ); 365 366 if( size ) 367 { 368 max_word = ( (size-1) >>5 ) + 1; 369 370 for( word = 0 ; word < max_word ; word++ ) 371 { 372 max_bit = (word == (max_word - 1)) ? (size & 0x1F) : 32; 373 374 word_xp = XPTR( bitmap_cxy , &bitmap_ptr[word] ); 375 376 value = hal_remote_l32( word_xp ); 377 378 if( value != 0XFFFFFFFF ) 379 { 380 for(bit = 0 ; bit < max_bit ; bit++) 381 { 382 if( (value & (1 << bit)) == 0 ) 383 { 384 hal_remote_s32( word_xp , value | (1 << bit) ); 385 return (word*32 + bit); 386 } 387 } 388 } 389 } 390 } 391 392 return -1; 393 394 } // end bitmap_alloc() 395 396 /////////////////////////////////////////////// 397 uint32_t bitmap_remote_ffc( xptr_t bitmap_xp, 398 uint32_t size ) 399 { 400 uint32_t max_word; 401 uint32_t max_bit; 402 uint32_t word; 403 uint32_t bit; 404 uint32_t value; 405 406 bitmap_t * bitmap_ptr = GET_PTR( bitmap_xp ); 407 cxy_t bitmap_cxy = GET_CXY( bitmap_xp ); 408 409 if( size ) 410 { 411 max_word = ( (size-1) >>5 ) + 1; 412 413 for( word = 0 ; word < max_word ; word++ ) 414 { 415 max_bit = (word == (max_word - 1)) ? (size & 0x1F) : 32; 416 417 value = hal_remote_l32( XPTR( bitmap_cxy , &bitmap_ptr[word] ) ); 418 419 if( value != 0xFFFFFFFF ) 420 { 421 for(bit = 0 ; bit < max_bit ; bit++) 422 { 423 if( (value & (1 << bit)) == 0 ) return (word*32 + bit); 424 } 425 } 426 } 427 } 428 429 return -1; 430 431 } // bitmap_remote_ffc() 432 433 -
trunk/kernel/libk/bits.h
r635 r657 1 1 /* 2 * bits.h - bit s manipulation helper functions2 * bits.h - bitmap API definition 3 3 * 4 4 * Author Ghassan Almaless (2008,2009,2010,2011,2012) 5 * Alain Greiner (2016,2017,2018,2019 )5 * Alain Greiner (2016,2017,2018,2019,2020) 6 6 * 7 7 * Copyright (c) UPMC Sorbonne Universites … … 28 28 #include <kernel_config.h> 29 29 #include <hal_kernel_types.h> 30 31 /********************************************************************************************* 32 * These macros are NOT used by the bitmap, but can be useful in other contexts... [AG] 33 *********************************************************************************************/ 34 35 #define ARROUND_UP(val, size) (((val) & ((size) -1)) ? ((val) & ~((size)-1)) + (size) : (val)) 36 #define ARROUND_DOWN(val, size) ((val) & ~((size) - 1)) 37 38 #define ABS(x) (((x) < 0) ? -(x) : (x)) 39 #define MIN(x,y) (((x) < (y)) ? (x) : (y)) 40 #define MAX(x,y) (((x) < (y)) ? (y) : (x)) 30 #include <hal_remote.h> 31 32 /********************************************************************************************** 33 * This file defines the API to access a generic bitmap, that can be local or remote. 34 * It is implemented as an array of uint32_t words. 35 * The number of entries in this array is statically defined at compile time 36 * and defines the max number of items that can be registered in the bitmap. 37 * The remote accesses are used in the VFS by the inum allocator. 38 *********************************************************************************************/ 39 40 typedef uint32_t bitmap_t; 41 42 /********************************************************************************************** 43 * This macro returns the number of 32 bits words required to register <size> entries. 44 *********************************************************************************************/ 45 46 #define BITMAP_SIZE(size) ( ((size) & 31) ? (((size)>>5) + 1) : ((size)>>5) ) 41 47 42 48 /********************************************************************************************** … … 44 50 * It returns 0xFFFFFFFF if data is larger than 0x80000000. 45 51 *********************************************************************************************/ 52 46 53 #define POW2_ROUNDUP(data) ( (data <= 0x00000001) ? 0x00000001 : \ 47 54 (data <= 0x00000002) ? 0x00000002 : \ … … 77 84 (data <= 0x80000000) ? 0x80000000 : 0xFFFFFFFF ) 78 85 79 /********************************************************************************************** 80 * This macro returns the number of 32 bits words required to register <size> entries. 81 *********************************************************************************************/ 82 83 #define BITMAP_SIZE(size) ( ((size) & 31) ? (((size)>>5) + 1) : ((size)>>5) ) 84 85 typedef uint32_t bitmap_t; 86 87 /********************************************************************************************* 88 * This function reset all bits in a bitmap. (array ot 32 bits words). 86 /********************************************************************************************* 87 * These macros are NOT used by the bitmap, but are useful in other contexts... [AG] 88 *********************************************************************************************/ 89 90 #define ARROUND_UP(val, size) (((val) & ((size) -1)) ? ((val) & ~((size)-1)) + (size) : (val)) 91 #define ARROUND_DOWN(val, size) ((val) & ~((size) - 1)) 92 93 #define ABS(x) (((x) < 0) ? -(x) : (x)) 94 #define MIN(x,y) (((x) < (y)) ? (x) : (y)) 95 #define MAX(x,y) (((x) < (y)) ? (y) : (x)) 96 97 /********************************************************************************************* 98 * This function reset all bits in a local or remote bitmap. 89 99 ********************************************************************************************* 90 100 * @ bitmap : pointer on first word in the bitmap. 91 * @ len : number of bits to reset. 92 ********************************************************************************************/ 93 void bitmap_init( bitmap_t * bitmap, 94 uint32_t len ); 95 96 /********************************************************************************************* 97 * This function set a specific bit in a bitmap. 101 * @ size : number of bits in bitmap. 102 ********************************************************************************************/ 103 extern void bitmap_init( bitmap_t * bitmap, 104 uint32_t size ); 105 106 extern void bitmap_remote_init( xptr_t bitmap_xp, 107 uint32_t size ); 108 109 /********************************************************************************************* 110 * These functions set a specific bit in a local or remote bitmap. 98 111 ********************************************************************************************* 99 112 * @ bitmap : pointer on the bitmap … … 103 116 uint32_t index ); 104 117 105 /********************************************************************************************* 106 * This function clear a specific bit in a bitmap. 118 extern inline void bitmap_remote_set( xptr_t bitmap_xp, 119 uint32_t index ); 120 121 /********************************************************************************************* 122 * These functions clear a specific bit in a local or remote bitmap. 107 123 ********************************************************************************************* 108 124 * @ bitmap : pointer on the bitmap … … 112 128 uint32_t index ); 113 129 114 /********************************************************************************************* 115 * This function returns a specific bit in a bitmap. 130 extern inline void bitmap_remote_clear( xptr_t bitmap_xp, 131 uint32_t index ); 132 133 /********************************************************************************************* 134 * These functions search the first bit non-set in a local or remote bitmap, in the 135 * range [0 , size-1], set this bit, and return the index of the found bit. 136 * The lock protecting the bitmap must be taken by the caller. 137 ********************************************************************************************* 138 * @ bitmap : pointer on the bitmap. 139 * @ size : number of bits to scan. 140 * @ returns index of found bit / returns 0xFFFFFFFF if not found. 141 ********************************************************************************************/ 142 extern uint32_t bitmap_alloc( bitmap_t * bitmap, 143 uint32_t size ); 144 145 extern uint32_t bitmap_remote_alloc( xptr_t bitmap_xp, 146 uint32_t size ); 147 148 /********************************************************************************************* 149 * This function returns the index of aa specific bit in a bitmap. 116 150 ********************************************************************************************* 117 151 * @ bitmap : pointer on the bitmap … … 179 213 180 214 /********************************************************************************************* 181 * This function returns the index of first bit cleared in a bitmap, starting from bit 0. 215 * These functions return the index of first bit cleared in a local or remote bitmap, 216 * starting from bit 0. 182 217 ********************************************************************************************* 183 218 * @ bitmap : pointer on the bitmap … … 187 222 extern uint32_t bitmap_ffc( bitmap_t * bitmap, 188 223 uint32_t size ); 224 225 extern uint32_t bitmap_remote_ffc( xptr_t bitmap_xp, 226 uint32_t size ); 189 227 190 228 /********************************************************************************************* -
trunk/kernel/libk/elf.c
r651 r657 224 224 error_t error; 225 225 226 // get file name for error reporting and debug226 // get file cluster and local pointer 227 227 cxy_t file_cxy = GET_CXY( file_xp ); 228 228 vfs_file_t * file_ptr = GET_PTR( file_xp ); 229 230 // get file name for error reporting and debug 229 231 vfs_inode_t * inode = hal_remote_lpt( XPTR( file_cxy , &file_ptr->inode ) ); 230 232 vfs_inode_get_name( XPTR( file_cxy , inode ) , name ); -
trunk/kernel/libk/grdxt.c
r656 r657 332 332 //////////////////////////////////////////////////////////////////////////////////////// 333 333 334 //////////////////////////////////////////// 335 error_t grdxt_remote_init( xptr_t rt_xp, 336 uint32_t ix1_width, 337 uint32_t ix2_width, 338 uint32_t ix3_width ) 339 { 340 void ** root; 341 kmem_req_t req; 342 343 // get cluster and local pointer 344 cxy_t rt_cxy = GET_CXY( rt_xp ); 345 grdxt_t * rt_ptr = GET_PTR( rt_xp ); 346 347 // initialize widths 348 hal_remote_s32( XPTR( rt_cxy , &rt_ptr->ix1_width ) , ix1_width ); 349 hal_remote_s32( XPTR( rt_cxy , &rt_ptr->ix2_width ) , ix2_width ); 350 hal_remote_s32( XPTR( rt_cxy , &rt_ptr->ix3_width ) , ix3_width ); 351 352 // allocates first level array 353 req.type = KMEM_KCM; 354 req.order = ix1_width + ( (sizeof(void*) == 4) ? 2 : 3 ); 355 req.flags = AF_KERNEL | AF_ZERO; 356 root = kmem_remote_alloc( rt_cxy , &req ); 357 358 if( root == NULL ) 359 { 360 printk("\n[ERROR] in %s : cannot allocate first level array\n", __FUNCTION__); 361 return -1; 362 } 363 364 // register first level array in rt descriptor 365 hal_remote_spt( XPTR( rt_cxy , &rt_ptr->root ) , root ); 366 367 return 0; 368 369 } // end grdxt_remote_init() 370 371 ////////////////////////////////////////// 372 void grdxt_remote_destroy( xptr_t rt_xp ) 373 { 374 kmem_req_t req; 375 376 uint32_t w1; 377 uint32_t w2; 378 uint32_t w3; 379 380 uint32_t ix1; 381 uint32_t ix2; 382 uint32_t ix3; 383 384 void ** ptr1; 385 void ** ptr2; 386 void ** ptr3; 387 388 // get cluster and local pointer 389 cxy_t rt_cxy = GET_CXY( rt_xp ); 390 grdxt_t * rt_ptr = GET_PTR( rt_xp ); 391 392 // get widths 393 w1 = hal_remote_l32( XPTR( rt_cxy , &rt_ptr->ix1_width ) ); 394 w2 = hal_remote_l32( XPTR( rt_cxy , &rt_ptr->ix2_width ) ); 395 w3 = hal_remote_l32( XPTR( rt_cxy , &rt_ptr->ix3_width ) ); 396 397 // get ptr1 398 ptr1 = hal_remote_lpt( XPTR( rt_cxy , &rt_ptr->root ) ); 399 400 for( ix1=0 ; ix1 < (uint32_t)(1 << w1) ; ix1++ ) 401 { 402 // get ptr2 403 ptr2 = hal_remote_lpt( XPTR( rt_cxy , &ptr1[ix1] ) ); 404 405 if( ptr2 == NULL ) continue; 406 407 for( ix2=0 ; ix2 < (uint32_t)(1 << w2) ; ix2++ ) 408 { 409 // get ptr2 410 ptr3 = hal_remote_lpt( XPTR( rt_cxy , &ptr2[ix2] ) ); 411 412 if( ptr3 == NULL ) continue; 413 414 for( ix3=0 ; ix3 < (uint32_t)(1 << w3) ; ix3++ ) 415 { 416 if( ptr3[ix3] != NULL ) 417 { 418 printk("\n[WARNING] in %s : ptr3[%d][%d][%d] non empty\n", 419 __FUNCTION__, ix1, ix2, ix3 ); 420 } 421 } 422 423 // release level 3 array 424 req.type = KMEM_KCM; 425 req.ptr = ptr3; 426 kmem_remote_free( rt_cxy , &req ); 427 } 428 429 // release level 2 array 430 req.type = KMEM_KCM; 431 req.ptr = ptr2; 432 kmem_remote_free( rt_cxy , &req ); 433 } 434 435 // release level 1 array 436 req.type = KMEM_KCM; 437 req.ptr = ptr1; 438 kmem_remote_free( rt_cxy , &req ); 439 440 } // end grdxt_remote_destroy() 441 334 442 ////////////////////////////////////////////// 335 443 error_t grdxt_remote_insert( xptr_t rt_xp, … … 464 572 465 573 //////////////////////////////////////////// 466 void *grdxt_remote_remove( xptr_t rt_xp,574 xptr_t grdxt_remote_remove( xptr_t rt_xp, 467 575 uint32_t key ) 468 576 { … … 489 597 // get ptr2 490 598 void ** ptr2 = hal_remote_lpt( XPTR( rt_cxy , &ptr1[ix1] ) ); 491 if( ptr2 == NULL ) return NULL;599 if( ptr2 == NULL ) return XPTR_NULL; 492 600 493 601 // get ptr3 494 602 void ** ptr3 = hal_remote_lpt( XPTR( rt_cxy , &ptr2[ix2] ) ); 495 if( ptr3 == NULL ) return NULL;603 if( ptr3 == NULL ) return XPTR_NULL; 496 604 497 605 // get value … … 502 610 hal_fence(); 503 611 504 return value;612 return XPTR( rt_cxy , value ); 505 613 506 614 } // end grdxt_remote_remove() … … 523 631 524 632 // compute indexes 525 uint32_t 526 uint32_t 527 uint32_t 633 uint32_t ix1 = key >> (w2 + w3); // index in level 1 array 634 uint32_t ix2 = (key >> w3) & ((1 << w2) -1); // index in level 2 array 635 uint32_t ix3 = key & ((1 << w3) - 1); // index in level 3 array 528 636 529 637 // get ptr1 … … 546 654 547 655 } // end grdxt_remote_lookup() 656 657 //////////////////////////////////////////////// 658 xptr_t grdxt_remote_get_first( xptr_t rt_xp, 659 uint32_t start_key, 660 uint32_t * found_key ) 661 { 662 uint32_t ix1; 663 uint32_t ix2; 664 uint32_t ix3; 665 666 void ** ptr1; // local base address of remote first level array 667 void ** ptr2; // local base address of remote second level array 668 void ** ptr3; // local base address of remote third level array 669 670 // get cluster and local pointer on remote rt descriptor 671 grdxt_t * rt_ptr = GET_PTR( rt_xp ); 672 cxy_t rt_cxy = GET_CXY( rt_xp ); 673 674 // get widths 675 uint32_t w1 = hal_remote_l32( XPTR( rt_cxy , &rt_ptr->ix1_width ) ); 676 uint32_t w2 = hal_remote_l32( XPTR( rt_cxy , &rt_ptr->ix2_width ) ); 677 uint32_t w3 = hal_remote_l32( XPTR( rt_cxy , &rt_ptr->ix3_width ) ); 678 679 // Check key value 680 assert( ((start_key >> (w1 + w2 + w3)) == 0 ), "illegal key value %x\n", start_key ); 681 682 // compute min indexes 683 uint32_t min1 = start_key >> (w2 + w3); 684 uint32_t min2 = (start_key >> w3) & ((1 << w2) -1); 685 uint32_t min3 = start_key & ((1 << w3) - 1); 686 687 // compute max indexes 688 uint32_t max1 = 1 << w1; 689 uint32_t max2 = 1 << w2; 690 uint32_t max3 = 1 << w3; 691 692 // get ptr1 693 ptr1 = hal_remote_lpt( XPTR( rt_cxy , &rt_ptr->root ) ); 694 695 for( ix1 = min1 ; ix1 < max1 ; ix1++ ) 696 { 697 ptr2 = hal_remote_lpt( XPTR( rt_cxy , &ptr1[ix1] ) ); 698 if( ptr2 == NULL ) continue; 699 700 for( ix2 = min2 ; ix2 < max2 ; ix2++ ) 701 { 702 ptr3 = hal_remote_lpt( XPTR( rt_cxy , &ptr2[ix2] ) ); 703 if( ptr3 == NULL ) continue; 704 705 for( ix3 = min3 ; ix3 < max3 ; ix3++ ) 706 { 707 void * item = hal_remote_lpt( XPTR( rt_cxy , &ptr3[ix3] ) ); 708 709 if( item == NULL ) continue; 710 else 711 { 712 *found_key = (ix1 << (w2+w3)) | (ix2 << w3) | ix3; 713 return XPTR( rt_cxy , item ); 714 } 715 } 716 } 717 } 718 719 return XPTR_NULL; 720 721 } // end grdxt_remote_get_first() 548 722 549 723 /////////////////////////i///////////////// -
trunk/kernel/libk/grdxt.h
r656 r657 2 2 * grdxt.h - Three-levels Generic Radix-tree definition. 3 3 * 4 * Authors Alain Greiner (2016,2017,2018,2019 )4 * Authors Alain Greiner (2016,2017,2018,2019,2019) 5 5 * 6 6 * Copyright UPMC Sorbonne Universites … … 124 124 /******************************************************************************************* 125 125 * This function scan all radix-tree entries in increasing key order, starting from 126 * the value defined by the <start_key> argument, and returna pointer on the first valid127 * registered item, and the found item key value.126 * the key defined by the <start_key> argument. It returns a pointer on the first valid 127 * registered item, and returns in the <found_key> buffer the found item key value. 128 128 * It must be called by a local thread. 129 129 ******************************************************************************************* … … 142 142 143 143 /******************************************************************************************* 144 * This function initialises the radix-tree descriptor, 145 * and allocates memory for the first level array of pointers. 146 * It can be called by any thread running in any cluster 147 ******************************************************************************************* 148 * @ rt_xp : extended pointer on the radix-tree descriptor. 149 * @ ix1_width : number of bits in ix1 field 150 * @ ix2_width : number of bits in ix2 field 151 * @ ix3_width : number of bits in ix3 field 152 * @ returns 0 if success / returns ENOMEM if no more memory. 153 ******************************************************************************************/ 154 error_t grdxt_remote_init( xptr_t rt_xp, 155 uint32_t ix1_width, 156 uint32_t ix2_width, 157 uint32_t ix3_width ); 158 159 /******************************************************************************************* 160 * This function releases all memory allocated to the radix-tree infrastructure. 161 * A warning message is printed on the kernel TXT0 if the radix tree is not empty. 162 * It can be called by any thread running in any cluster 163 ******************************************************************************************* 164 * @ rt_xp : extended pointer on the radix-tree descriptor. 165 ******************************************************************************************/ 166 void grdxt_remote_destroy( xptr_t rt_xp ); 167 168 /******************************************************************************************* 144 169 * This function insert a new item in a - possibly remote - radix tree. 145 170 * It dynamically allocates memory for new second and third level arrays if required. 171 * It can be called by any thread running in any cluster 146 172 ******************************************************************************************* 147 173 * @ rt_xp : extended pointer on the radix-tree descriptor. … … 157 183 * This function removes an item identified by its key from a - possibly remote - radix 158 184 * tree, and returns a local pointer on the removed item. No memory is released. 185 * It can be called by a thread running in any cluster 159 186 ******************************************************************************************* 160 187 * @ rt_xp : pointer on the radix-tree descriptor. 161 188 * @ key : key value. 162 * @ returns local pointer on removed item if success / returnsNULL if failure.163 ******************************************************************************************/ 164 void *grdxt_remote_remove( xptr_t rt_xp,189 * @ returns extended pointer on removed item if success / returns XPTR_NULL if failure. 190 ******************************************************************************************/ 191 xptr_t grdxt_remote_remove( xptr_t rt_xp, 165 192 uint32_t key ); 166 193 … … 169 196 * on the item identified by the <key> argument, from the radix tree identified by 170 197 * the <rt_xp> remote pointer. 198 * It can be called by a thread running in any cluster 171 199 ******************************************************************************************* 172 200 * @ rt_xp : extended pointer on the radix-tree descriptor. 173 201 * @ key : key value. 174 * @ returns an extended pointer on found item if success / returns XPTR_NULL if failure.202 * @ returns extended pointer on found item if success / returns XPTR_NULL if not found. 175 203 ******************************************************************************************/ 176 204 xptr_t grdxt_remote_lookup( xptr_t rt_xp, … … 178 206 179 207 /******************************************************************************************* 208 * This function scan all radix-tree entries of a - possibly remote - radix tree <rt_xp>, 209 * in increasing key order, starting from the key defined by the <start_key> argument. 210 * It returns an extended pointer on the first valid registered item, and returns in the 211 * <found_key> buffer the found item key value. 212 * It can be called by a thread running in any cluster 213 ******************************************************************************************* 214 * @ rt_xp : extended pointer on the radix-tree descriptor. 215 * @ start_key : key starting value for the scan. 216 * @ found_key : [out] buffer for found key value. 217 * @ return xptr on first valid item if found / return XPTR_NULL if no item found. 218 ******************************************************************************************/ 219 xptr_t grdxt_remote_get_first( xptr_t rt_xp, 220 uint32_t start_key, 221 uint32_t * found_key ); 222 223 /******************************************************************************************* 180 224 * This function displays the current content of a possibly remote radix_tree. 225 * It can be called by a thread running in any cluster 181 226 ******************************************************************************************* 182 227 * @ rt : extended pointer on the radix-tree descriptor. -
trunk/kernel/libk/remote_fifo.c
r563 r657 65 65 watchdog = 0; 66 66 67 // get write slot index with atomic increment 67 // get write slot index with atomic increment QQQQQQQQQQ 68 68 wr_id = hal_remote_atomic_add( XPTR( fifo_cxy , &fifo_ptr->wr_id ) , 1 ); 69 69 -
trunk/kernel/libk/remote_rwlock.h
r629 r657 1 1 /* 2 * remote_rwlock.h - kernel remote read/write lock definition.2 * remote_rwlock.h - kernel remote read/write lock definition. 3 3 * 4 * Authors Alain Greiner (2016,2017,2018,20 19)4 * Authors Alain Greiner (2016,2017,2018,2020) 5 5 * 6 6 * Copyright (c) UPMC Sorbonne Universites -
trunk/kernel/libk/xhtab.c
r635 r657 53 53 54 54 return (name[0] % XHASHTAB_SIZE); 55 /*56 uint32_t index = 0;57 while( *name )58 {59 index = index + (*(name++) ^ index);60 }61 return index % XHASHTAB_SIZE;62 */63 64 55 } 65 56 … … 128 119 //////////////////////////////////////////////////////////////////////////////////////// 129 120 130 ////////////////////////////////////////// 131 void xhtab_init( x htab_t * xhtab,121 ///////////////////////////////////////////// 122 void xhtab_init( xptr_t xhtab_xp, 132 123 xhtab_item_type_t type ) 133 124 { 134 uint32_t i; 125 uint32_t i; 126 127 // get cluster and local pointer 128 xhtab_t * ptr = GET_PTR( xhtab_xp ); 129 cxy_t cxy = GET_CXY( xhtab_xp ); 135 130 136 131 // initialize lock 137 remote_busylock_init( XPTR( local_cxy , &xhtab->lock), LOCK_XHTAB_STATE ); 138 139 xhtab->items = 0; 140 xhtab->current_index = 0; 141 xhtab->current_xlist_xp = XPTR_NULL; 142 132 remote_busylock_init( XPTR( cxy , &ptr->lock), LOCK_XHTAB_STATE ); 133 134 // initialise various fiels 135 hal_remote_s32( XPTR( cxy , &ptr->items ) , 0 ); 136 hal_remote_s32( XPTR( cxy , &ptr->current_index ) , 0 ); 137 hal_remote_s64( XPTR( cxy , &ptr->current_xlist_xp ) , XPTR_NULL ); 138 139 // initialize functions pointers 143 140 if( type == XHTAB_DENTRY_TYPE ) 144 141 { 145 xhtab->item_match_key = &xhtab_dentry_item_match_key;146 xhtab->index_from_key = &xhtab_dentry_index_from_key;147 xhtab->item_from_xlist = &xhtab_dentry_item_from_xlist;148 xhtab->item_print_key = &xhtab_dentry_item_print_key;142 hal_remote_spt( XPTR( cxy , &ptr->item_match_key ) , &xhtab_dentry_item_match_key ); 143 hal_remote_spt( XPTR( cxy , &ptr->index_from_key ) , &xhtab_dentry_index_from_key ); 144 hal_remote_spt( XPTR( cxy , &ptr->item_from_xlist ) , &xhtab_dentry_item_from_xlist ); 145 hal_remote_spt( XPTR( cxy , &ptr->item_print_key ) , &xhtab_dentry_item_print_key ); 149 146 } 150 147 else … … 153 150 } 154 151 152 // initialize all lists 153 for( i=0 ; i < XHASHTAB_SIZE ; i++ ) 154 { 155 xlist_root_init( XPTR( cxy , &ptr->roots[i] ) ); 156 } 157 155 158 #if DEBUG_XHTAB 156 159 printk("\n[%s] for xhtab (%x,%x)\n" 157 " - index_from_key = %x (@ %x)\n" 158 " - item_match_key = %x (@ %x)\n" 159 " - item_from_xlist = %x (@ %x)\n", 160 __FUNCTION__, local_cxy, xhtab, 161 xhtab->index_from_key , &xhtab->index_from_key, 162 xhtab->item_match_key , &xhtab->item_match_key, 163 xhtab->item_from_xlist, &xhtab->item_from_xlist ); 164 #endif 165 166 for( i=0 ; i < XHASHTAB_SIZE ; i++ ) 167 { 168 xlist_root_init( XPTR( local_cxy , &xhtab->roots[i] ) ); 169 170 #if (DEBUG_XHTAB & 1) 171 printk("\n - initialize root[%d] / %x\n", i , &xhtab->roots[i] ); 172 #endif 173 174 } 160 " - index_from_key = %x\n" 161 " - item_match_key = %x\n" 162 " - item_from_xlist = %x\n", 163 __FUNCTION__, cxy, ptr, 164 hal_remote_lpt( XPTR( cxy , &ptr->index_from_key ) ), 165 hal_remote_lpt( XPTR( cxy , &ptr->item_match_key ) ), 166 hal_remote_lpt( XPTR( cxy , &ptr->item_from_xlist ) ) ); 167 #endif 175 168 176 169 } // end xhtab_init() … … 200 193 xhtab_ptr = GET_PTR( xhtab_xp ); 201 194 195 #if DEBUG_XHTAB 196 printk("\n[%s] enter : index = %d / key = %s\n", __FUNCTION__ , index , key ); 197 #endif 198 202 199 // get pointer on "item_from_xlist" function 203 200 item_from_xlist = (item_from_xlist_t *)hal_remote_lpt( XPTR( xhtab_cxy , … … 206 203 item_match_key = (item_match_key_t *)hal_remote_lpt( XPTR( xhtab_cxy , 207 204 &xhtab_ptr->item_match_key ) ); 208 209 205 // scan sub-list[index] 210 206 XLIST_FOREACH( XPTR( xhtab_cxy , &xhtab_ptr->roots[index] ) , xlist_xp ) … … 216 212 if( item_match_key( item_xp , key ) ) return item_xp; 217 213 } 214 215 #if DEBUG_XHTAB 216 printk("\n[%s] exit\n", __FUNCTION__ ); 217 #endif 218 218 219 219 220 // No matching item found … … 248 249 index_from_key = (index_from_key_t *)hal_remote_lpt( XPTR( xhtab_cxy , 249 250 &xhtab_ptr->index_from_key ) ); 250 #if DEBUG_XHTAB251 printk("\n[%s] remote = %x / direct = %x / @ = %x\n",252 __FUNCTION__, index_from_key, xhtab_ptr->index_from_key, &xhtab_ptr->index_from_key );253 #endif254 255 251 // compute index from key 256 252 index = index_from_key( key ); 257 258 #if DEBUG_XHTAB259 printk("\n[%s] index = %x\n", __FUNCTION__, index );260 #endif261 253 262 254 // take the lock protecting hash table … … 285 277 286 278 #if DEBUG_XHTAB 287 printk("\n[%s] success /<%s>\n", __FUNCTION__, key );279 printk("\n[%s] success for <%s>\n", __FUNCTION__, key ); 288 280 #endif 289 281 … … 362 354 363 355 #if DEBUG_XHTAB 364 printk("\n[%s] enter / %s\n", __FUNCTION__, key);356 printk("\n[%s] enter\n", __FUNCTION__ ); 365 357 #endif 366 358 … … 368 360 remote_busylock_acquire( XPTR( xhtab_cxy , &xhtab_ptr->lock ) ); 369 361 370 #if DEBUG_XHTAB371 printk("\n[%s] after lock acquire / %s\n", __FUNCTION__, key );372 #endif373 374 362 // scan sub-list 375 363 item_xp = xhtab_scan( xhtab_xp , index , key ); 376 364 377 #if DEBUG_XHTAB378 printk("\n[%s] after xhtab scan / %s\n", __FUNCTION__, key );379 #endif380 381 365 // release the lock protecting hash table 382 366 remote_busylock_release( XPTR( xhtab_cxy , &xhtab_ptr->lock ) ); 383 367 384 368 #if DEBUG_XHTAB 385 printk("\n[%s] after lock release / %s\n", __FUNCTION__, key);369 printk("\n[%s] exit\n", __FUNCTION__ ); 386 370 #endif 387 371 -
trunk/kernel/libk/xhtab.h
r635 r657 105 105 /****************************************************************************************** 106 106 * This function initializes an empty hash table (zero registered item). 107 * The initialisation must be done by a thread running in cluster containing the table.108 107 ****************************************************************************************** 109 * @ xhtab : local pointer on local xhtab to be initialized.110 * @ type : item type (see above).108 * @ xhtab_xp : extended pointer on xhtab. 109 * @ type : item type (see above). 111 110 *****************************************************************************************/ 112 void xhtab_init( x htab_t * xhtab,111 void xhtab_init( xptr_t xhtab_xp, 113 112 xhtab_item_type_t type ); 114 113 -
trunk/kernel/libk/xlist.h
r656 r657 2 2 * xlist.h - Trans-cluster double circular linked list, using extended pointers. 3 3 * 4 * Author : Alain Greiner (2016,2017,2018,2019 )4 * Author : Alain Greiner (2016,2017,2018,2019,2020) 5 5 * 6 6 * Copyright (c) UPMC Sorbonne Universites … … 50 50 /*************************************************************************** 51 51 * This macro returns the offset (in bytes) of a field in a structure. 52 *************************************************************************** 52 53 * @ type : structure type 53 54 * @ member : name of the field … … 61 62 * This macro returns an extended pointer on the structure containing an 62 63 * embedded xlist_entry_t field. 64 *************************************************************************** 63 65 * @ xlist_xp : extended pointer on the xlist_entry_t field 64 66 * @ type : type of the structure containing the xlist_entry_t … … 74 76 * the root xlist_entry_t. 75 77 * WARNING : check list non empty before using this macro. 78 *************************************************************************** 76 79 * @ root_xp : extended pointer on the root xlist_entry_t 77 80 * @ type : type of the linked elements … … 88 91 * the root xlist_entry_t. 89 92 * WARNING : check list non empty before using this macro. 93 *************************************************************************** 90 94 * @ root_xp : extended pointer on the root xlist_entry_t 91 95 * @ type : type of the linked elements … … 100 104 * This macro traverses an extended double linked list in forward order. 101 105 * WARNING : the iter variable should NOT be deleted during traversal. 106 *************************************************************************** 102 107 * @ root_xp : extended pointer on the root xlist_entry_t 103 108 * @ iter_xp : current extended pointer on a xlist_entry_t … … 112 117 * This macro traverses an extended double linked list in backward order. 113 118 * WARNING : the iter variable should NOT be deleted during traversal. 119 *************************************************************************** 114 120 * @ root_xp : extended pointer on the root xlist_entry_t 115 121 * @ iter_xp : current extended pointer on a xlist_entry_t … … 124 130 * This function returns an extended pointer on the next xlist_entry_t, 125 131 * from an extended pointer on a reference xlist_entry_t. 132 *************************************************************************** 126 133 * @ root : extended pointer on the root xlist_entry_t 127 134 * @ ref : extended pointer on the reference xlist_entry_t … … 144 151 /*************************************************************************** 145 152 * This function returns an extended pointer on the previous xlist_entry_t. 153 *************************************************************************** 146 154 * @ root : extended pointer on the root xlist_entry_t 147 155 * @ ref : extended pointer on the reference xlist_entry_t … … 165 173 * This function initialises the root of an extended double linked list. 166 174 * The root can be located in any cluster. 175 *************************************************************************** 167 176 * @ root_xp : extended pointer on the root xlist_entry_t 168 177 xixi **************************************************************************/ … … 176 185 * This function initialises an entry of an extended double linked list. 177 186 * The entry can be located in any cluster. 187 *************************************************************************** 178 188 * @ entry_xp : extended pointer on the xlist_entry_t 179 189 **************************************************************************/ … … 188 198 * double linked list. Four extended pointers must be modified. 189 199 * The lock protecting the list should have been previously taken. 200 *************************************************************************** 190 201 * @ root_xp : extended pointer on the root xlist_entry_t 191 202 * @ entry_xp : extended pointer on the xlist_entry_t to be inserted … … 214 225 * double linked list. Four extended pointers must be modified. 215 226 * The lock protecting the list should have been previously taken. 227 *************************************************************************** 216 228 * @ root_xp : extended pointer on the root xlist_entry_t 217 229 * @ entry_xp : extended pointer on the xlist_entry_t to be inserted … … 239 251 /*************************************************************************** 240 252 * This function returns true if the list is empty. 253 *************************************************************************** 241 254 * @ root_xp : extended pointer on the root xlist_entry_t. 242 255 **************************************************************************/ … … 253 266 * Two extended pointers must be modified. 254 267 * The memory allocated to the removed entry is not released. 268 *************************************************************************** 255 269 * @ xp : extended pointer on the xlist_entry_t to be removed. 256 270 **************************************************************************/ … … 277 291 * Four extended pointers must be modified. 278 292 * The memory allocated to the removed entry is not released. 293 *************************************************************************** 279 294 * @ old : extended pointer on the xlist_entry_t to be removed. 280 295 * @ new : extended pointer on the xlist_entry_t to be inserted. … … 307 322 /*************************************************************************** 308 323 * This debug function displays all entries of an xlist. 324 *************************************************************************** 309 325 * @ root_xp : extended pointer on the root xlist_entry_t. 310 326 * @ string : list identifier displayed in header.
Note: See TracChangeset
for help on using the changeset viewer.