Changeset 603 for trunk/kernel/libk/grdxt.c
- Timestamp:
- Dec 3, 2018, 12:17:35 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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()
Note: See TracChangeset
for help on using the changeset viewer.