[1] | 1 | /* |
---|
| 2 | * dqdt.c - Distributed Quaternary Decision Tree implementation. |
---|
[19] | 3 | * |
---|
[437] | 4 | * Author : Alain Greiner (2016,2017,2018) |
---|
[1] | 5 | * |
---|
| 6 | * Copyright (c) UPMC Sorbonne Universites |
---|
| 7 | * |
---|
| 8 | * This file is part of ALMOS-MKH. |
---|
| 9 | * |
---|
| 10 | * ALMOS-MKH is free software; you can redistribute it and/or modify it |
---|
| 11 | * under the terms of the GNU General Public License as published by |
---|
| 12 | * the Free Software Foundation; version 2.0 of the License. |
---|
| 13 | * |
---|
| 14 | * ALMOS-MKH is distributed in the hope that it will be useful, but |
---|
| 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
| 17 | * General Public License for more details. |
---|
| 18 | * |
---|
| 19 | * You should have received a copy of the GNU General Public License |
---|
| 20 | * along with ALMOS-MKH; if not, write to the Free Software Foundation, |
---|
| 21 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
| 22 | */ |
---|
| 23 | |
---|
[14] | 24 | #include <kernel_config.h> |
---|
[457] | 25 | #include <hal_kernel_types.h> |
---|
[1] | 26 | #include <hal_special.h> |
---|
[582] | 27 | #include <hal_macros.h> |
---|
[1] | 28 | #include <hal_atomic.h> |
---|
| 29 | #include <hal_remote.h> |
---|
[583] | 30 | #include <thread.h> |
---|
[1] | 31 | #include <printk.h> |
---|
[438] | 32 | #include <chdev.h> |
---|
[1] | 33 | #include <cluster.h> |
---|
| 34 | #include <bits.h> |
---|
| 35 | #include <dqdt.h> |
---|
| 36 | |
---|
| 37 | |
---|
[438] | 38 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 39 | // Extern variables |
---|
| 40 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
[1] | 41 | |
---|
[438] | 42 | extern chdev_directory_t chdev_dir; // defined in chdev.h / allocated in kernel_init.c |
---|
| 43 | |
---|
| 44 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 45 | // This static recursive function traverse the DQDT quad-tree from root to bottom. |
---|
| 46 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 47 | static void dqdt_recursive_print( xptr_t node_xp ) |
---|
[1] | 48 | { |
---|
[582] | 49 | uint32_t x; |
---|
| 50 | uint32_t y; |
---|
[438] | 51 | dqdt_node_t node; |
---|
[1] | 52 | |
---|
[438] | 53 | // get node local copy |
---|
| 54 | hal_remote_memcpy( XPTR( local_cxy , &node ), node_xp , sizeof(dqdt_node_t) ); |
---|
[1] | 55 | |
---|
[438] | 56 | // display node content |
---|
[583] | 57 | nolock_printk("- level %d / cluster %x : threads = %x / pages = %x / clusters %d / cores %d\n", |
---|
| 58 | node.level, GET_CXY( node_xp ), node.threads, node.pages, node.clusters, node.cores ); |
---|
[1] | 59 | |
---|
| 60 | // recursive call on children if node is not terminal |
---|
[438] | 61 | if ( node.level > 0 ) |
---|
[1] | 62 | { |
---|
[582] | 63 | for ( x = 0 ; x < 2 ; x++ ) |
---|
[1] | 64 | { |
---|
[582] | 65 | for ( y = 0 ; y < 2 ; y++ ) |
---|
| 66 | { |
---|
| 67 | xptr_t iter_xp = node.children[x][y]; |
---|
| 68 | if ( iter_xp != XPTR_NULL ) dqdt_recursive_print( iter_xp ); |
---|
| 69 | } |
---|
[1] | 70 | } |
---|
| 71 | } |
---|
[19] | 72 | } |
---|
| 73 | |
---|
[564] | 74 | ///////////////////////// |
---|
[485] | 75 | void dqdt_display( void ) |
---|
[438] | 76 | { |
---|
[582] | 77 | // get extended pointer on DQDT root node |
---|
| 78 | cluster_t * cluster = &cluster_manager; |
---|
| 79 | xptr_t root_xp = cluster->dqdt_root_xp; |
---|
[438] | 80 | |
---|
| 81 | // get pointers on TXT0 chdev |
---|
| 82 | xptr_t txt0_xp = chdev_dir.txt_tx[0]; |
---|
| 83 | cxy_t txt0_cxy = GET_CXY( txt0_xp ); |
---|
| 84 | chdev_t * txt0_ptr = GET_PTR( txt0_xp ); |
---|
| 85 | |
---|
[564] | 86 | // get extended pointer on remote TXT0 lock |
---|
[438] | 87 | xptr_t lock_xp = XPTR( txt0_cxy , &txt0_ptr->wait_lock ); |
---|
| 88 | |
---|
[564] | 89 | // get TXT0 lock |
---|
| 90 | remote_busylock_acquire( lock_xp ); |
---|
[438] | 91 | |
---|
| 92 | // print header |
---|
| 93 | nolock_printk("\n***** DQDT state\n\n"); |
---|
| 94 | |
---|
| 95 | // call recursive function |
---|
| 96 | dqdt_recursive_print( root_xp ); |
---|
| 97 | |
---|
[582] | 98 | // release TXT0 lock |
---|
[564] | 99 | remote_busylock_release( lock_xp ); |
---|
[438] | 100 | } |
---|
| 101 | |
---|
[582] | 102 | /////////////////////////////////////////////////////////////////////////////////////// |
---|
| 103 | // This static function initializes recursively, from top to bottom, the quad-tree |
---|
| 104 | // infrastructure. The DQDT nodes are allocated as global variables in each local |
---|
[583] | 105 | // cluster manager. At each level in the quad-tree, this function initializes the |
---|
| 106 | // node identified by the <cxy> and <level> arguments, selects in each child |
---|
| 107 | // macro-cluster the precise cluster where will be placed the subtree root node, |
---|
| 108 | // and call recursively itself to initialize the child node in the selected cluster. |
---|
[582] | 109 | /////////////////////////////////////////////////////////////////////////////////////// |
---|
| 110 | // @ node cxy : cluster containing the node to initialize |
---|
| 111 | // @ level : level of node to be initialised |
---|
| 112 | // @ parent_xp : extended pointer on the parent node |
---|
| 113 | /////////////////////////////////////////////////////////////////////////////////////// |
---|
| 114 | static void dqdt_recursive_build( cxy_t node_cxy, |
---|
| 115 | uint32_t level, |
---|
| 116 | xptr_t parent_xp ) |
---|
[1] | 117 | { |
---|
[582] | 118 | assert( (level < 5) , __FUNCTION__, "illegal DQDT level %d\n", level ); |
---|
| 119 | |
---|
| 120 | uint32_t node_x; // node X coordinate |
---|
| 121 | uint32_t node_y; // node Y coordinate |
---|
| 122 | uint32_t mask; // to compute associated macro-cluster coordinates |
---|
| 123 | uint32_t node_base_x; // associated macro_cluster X coordinate |
---|
| 124 | uint32_t node_base_y; // associated macro_cluster y coordinate |
---|
| 125 | uint32_t half; // associated macro-cluster half size |
---|
[583] | 126 | uint32_t cores; // number of cores in macro cluster |
---|
| 127 | uint32_t clusters; // number of clusters in macro cluster |
---|
[1] | 128 | |
---|
[583] | 129 | // get node cluster coordinates |
---|
[582] | 130 | node_x = HAL_X_FROM_CXY( node_cxy ); |
---|
| 131 | node_y = HAL_Y_FROM_CXY( node_cxy ); |
---|
| 132 | |
---|
| 133 | // get macro-cluster mask and half-size |
---|
| 134 | mask = (1 << level) - 1; |
---|
| 135 | half = (level > 0) ? (1 << (level - 1)) : 0; |
---|
[564] | 136 | |
---|
[582] | 137 | // get macro-cluster coordinates |
---|
| 138 | node_base_x = node_x & ~mask; |
---|
| 139 | node_base_y = node_y & ~mask; |
---|
[1] | 140 | |
---|
[582] | 141 | // get pointer on local cluster manager |
---|
| 142 | cluster_t * cluster = LOCAL_CLUSTER; |
---|
[1] | 143 | |
---|
[583] | 144 | // build local and extended pointer on node to be initialized |
---|
| 145 | dqdt_node_t * node_ptr = &cluster->dqdt_tbl[level]; |
---|
| 146 | xptr_t node_xp = XPTR( node_cxy , node_ptr ); |
---|
[1] | 147 | |
---|
[582] | 148 | #if DEBUG_DQDT_INIT |
---|
| 149 | printk("\n[DBG] %s : cxy(%d,%d) / level %d / mask %x / half %d / ptr %x\n", |
---|
[583] | 150 | __FUNCTION__, node_x, node_y, level, mask, half, node_ptr ); |
---|
[582] | 151 | #endif |
---|
| 152 | |
---|
| 153 | // make remote node default initialisation |
---|
[583] | 154 | hal_remote_memset( node_xp , 0 , sizeof( dqdt_node_t ) ); |
---|
[582] | 155 | |
---|
[583] | 156 | // initialize <parent> field |
---|
| 157 | hal_remote_s64( XPTR( node_cxy , &node_ptr->parent ) , parent_xp ); |
---|
| 158 | |
---|
| 159 | // initialize <level> field |
---|
| 160 | hal_remote_s32( XPTR( node_cxy , &node_ptr->level ) , level ); |
---|
| 161 | |
---|
[582] | 162 | // recursive initialisation |
---|
[583] | 163 | if( level == 0 ) // terminal case : cluster |
---|
[1] | 164 | { |
---|
[583] | 165 | // initialize <clusters> field in node |
---|
| 166 | hal_remote_s32( XPTR( node_cxy , &node_ptr->clusters ) , 1 ); |
---|
| 167 | |
---|
| 168 | // initialize <cores> field in node |
---|
| 169 | cores = hal_remote_l32( XPTR ( node_cxy , &cluster->cores_nr ) ); |
---|
| 170 | hal_remote_s32( XPTR( node_cxy , &node_ptr->cores ) , cores ); |
---|
[582] | 171 | } |
---|
[583] | 172 | else // non terminal : macro-cluster |
---|
[582] | 173 | { |
---|
[583] | 174 | bool_t found; |
---|
| 175 | uint32_t x; |
---|
| 176 | uint32_t y; |
---|
| 177 | cxy_t child_cxy; |
---|
| 178 | xptr_t child_xp; |
---|
| 179 | dqdt_node_t * child_ptr = &cluster->dqdt_tbl[level-1]; |
---|
[1] | 180 | |
---|
[583] | 181 | // search an active cluster in child[0][0] macro-cluster |
---|
[582] | 182 | found = false; |
---|
| 183 | for( x = node_base_x ; |
---|
| 184 | (x < (node_base_x + half)) && (found == false) ; x++ ) |
---|
[1] | 185 | { |
---|
[582] | 186 | for( y = node_base_y ; |
---|
| 187 | (y < (node_base_y + half)) && (found == false) ; y++ ) |
---|
| 188 | { |
---|
[583] | 189 | child_cxy = HAL_CXY_FROM_XY( x , y ); |
---|
| 190 | |
---|
| 191 | if( cluster_is_active( child_cxy ) ) |
---|
[582] | 192 | { |
---|
[583] | 193 | // initialize recursively selected child[0][0] node |
---|
| 194 | dqdt_recursive_build( child_cxy , level-1 , node_xp ); |
---|
[1] | 195 | |
---|
[583] | 196 | // build extended pointer on child[0][0] node |
---|
| 197 | child_xp = XPTR( child_cxy , child_ptr ); |
---|
[582] | 198 | |
---|
[583] | 199 | // update <cores> field in node |
---|
| 200 | cores = hal_remote_l32( XPTR ( child_cxy , &child_ptr->cores ) ); |
---|
| 201 | hal_remote_atomic_add( XPTR( node_cxy , &node_ptr->cores ) , cores ); |
---|
| 202 | |
---|
| 203 | // update <clusters> field in node |
---|
| 204 | clusters = hal_remote_l32( XPTR ( child_cxy , &child_ptr->clusters ) ); |
---|
| 205 | hal_remote_atomic_add( XPTR( node_cxy , &node_ptr->clusters ) , clusters ); |
---|
| 206 | |
---|
| 207 | // update <child[0][0]> field in node |
---|
| 208 | hal_remote_s64( XPTR( node_cxy , &node_ptr->children[0][0] ), child_xp ); |
---|
| 209 | |
---|
| 210 | // udate <arity> field in node |
---|
| 211 | hal_remote_atomic_add( XPTR( node_cxy , &node_ptr->arity ) , 1 ); |
---|
[582] | 212 | |
---|
| 213 | // exit loops |
---|
| 214 | found = true; |
---|
| 215 | } |
---|
[1] | 216 | } |
---|
[582] | 217 | } |
---|
[1] | 218 | |
---|
[583] | 219 | // search an active cluster in child[0][1] macro-cluster |
---|
[582] | 220 | found = false; |
---|
| 221 | for( x = node_base_x ; |
---|
| 222 | (x < (node_base_x + half)) && (found == false) ; x++ ) |
---|
| 223 | { |
---|
| 224 | for( y = (node_base_y + half) ; |
---|
[583] | 225 | (y < (node_base_y + (half<<1))) && (found == false) ; y++ ) |
---|
[1] | 226 | { |
---|
[583] | 227 | child_cxy = HAL_CXY_FROM_XY( x , y ); |
---|
| 228 | |
---|
| 229 | if( cluster_is_active( child_cxy ) ) |
---|
[582] | 230 | { |
---|
[583] | 231 | // initialize recursively selected child[0][1] node |
---|
| 232 | dqdt_recursive_build( child_cxy , level-1 , node_xp ); |
---|
[582] | 233 | |
---|
[583] | 234 | // build extended pointer on child[0][1] node |
---|
| 235 | child_xp = XPTR( child_cxy , child_ptr ); |
---|
[582] | 236 | |
---|
[583] | 237 | // update <cores> field in node |
---|
| 238 | cores = hal_remote_l32( XPTR ( child_cxy , &child_ptr->cores ) ); |
---|
| 239 | hal_remote_atomic_add( XPTR( node_cxy , &node_ptr->cores ) , cores ); |
---|
| 240 | |
---|
| 241 | // update <clusters> field in node |
---|
| 242 | clusters = hal_remote_l32( XPTR ( child_cxy , &child_ptr->clusters ) ); |
---|
| 243 | hal_remote_atomic_add( XPTR( node_cxy , &node_ptr->clusters ) , clusters ); |
---|
| 244 | |
---|
| 245 | // update <child[0][1]> field in node |
---|
| 246 | hal_remote_s64( XPTR( node_cxy , &node_ptr->children[0][1] ), child_xp ); |
---|
| 247 | |
---|
| 248 | // udate <arity> field in node |
---|
| 249 | hal_remote_atomic_add( XPTR( node_cxy , &node_ptr->arity ) , 1 ); |
---|
[582] | 250 | |
---|
| 251 | // exit loops |
---|
| 252 | found = true; |
---|
| 253 | } |
---|
[1] | 254 | } |
---|
[582] | 255 | } |
---|
[583] | 256 | |
---|
| 257 | // search an active cluster in child[1][0] macro-cluster |
---|
[582] | 258 | found = false; |
---|
[583] | 259 | for( x = (node_base_x +half) ; |
---|
[582] | 260 | (x < (node_base_x + (half<<1))) && (found == false) ; x++ ) |
---|
| 261 | { |
---|
| 262 | for( y = node_base_y ; |
---|
| 263 | (y < (node_base_y + half)) && (found == false) ; y++ ) |
---|
| 264 | { |
---|
[583] | 265 | child_cxy = HAL_CXY_FROM_XY( x , y ); |
---|
| 266 | |
---|
| 267 | if( cluster_is_active( child_cxy ) ) |
---|
[582] | 268 | { |
---|
[583] | 269 | // initialize recursively selected child[1][0] node |
---|
| 270 | dqdt_recursive_build( child_cxy , level-1 , node_xp ); |
---|
[1] | 271 | |
---|
[583] | 272 | // build extended pointer on child[1][0] node |
---|
| 273 | child_xp = XPTR( child_cxy , child_ptr ); |
---|
[582] | 274 | |
---|
[583] | 275 | // update <cores> field in node |
---|
| 276 | cores = hal_remote_l32( XPTR ( child_cxy , &child_ptr->cores ) ); |
---|
| 277 | hal_remote_atomic_add( XPTR( node_cxy , &node_ptr->cores ) , cores ); |
---|
| 278 | |
---|
| 279 | // update <clusters> field in node |
---|
| 280 | clusters = hal_remote_l32( XPTR ( child_cxy , &child_ptr->clusters ) ); |
---|
| 281 | hal_remote_atomic_add( XPTR( node_cxy , &node_ptr->clusters ) , clusters ); |
---|
| 282 | |
---|
| 283 | // update <child[1][0]> field in node |
---|
| 284 | hal_remote_s64( XPTR( node_cxy , &node_ptr->children[1][0] ), child_xp ); |
---|
| 285 | |
---|
| 286 | // udate <arity> field in node |
---|
| 287 | hal_remote_atomic_add( XPTR( node_cxy , &node_ptr->arity ) , 1 ); |
---|
[582] | 288 | |
---|
| 289 | // exit loops |
---|
| 290 | found = true; |
---|
| 291 | } |
---|
[1] | 292 | } |
---|
[582] | 293 | } |
---|
[1] | 294 | |
---|
[583] | 295 | // search an active cluster in child[1][1] macro-cluster |
---|
[582] | 296 | found = false; |
---|
| 297 | for( x = (node_base_x + half) ; |
---|
| 298 | (x < (node_base_x + (half<<1))) && (found == false) ; x++ ) |
---|
| 299 | { |
---|
| 300 | for( y = (node_base_y + half) ; |
---|
[583] | 301 | (y < (node_base_y + (half<<1))) && (found == false) ; y++ ) |
---|
[1] | 302 | { |
---|
[583] | 303 | child_cxy = HAL_CXY_FROM_XY( x , y ); |
---|
| 304 | |
---|
| 305 | if( cluster_is_active( child_cxy ) ) |
---|
[582] | 306 | { |
---|
[583] | 307 | // initialize recursively selected child[1][1] node |
---|
| 308 | dqdt_recursive_build( child_cxy , level-1 , node_xp ); |
---|
[582] | 309 | |
---|
[583] | 310 | // build extended pointer on child[1][1] node |
---|
| 311 | child_xp = XPTR( child_cxy , child_ptr ); |
---|
[582] | 312 | |
---|
[583] | 313 | // update <cores> field in node |
---|
| 314 | cores = hal_remote_l32( XPTR ( child_cxy , &child_ptr->cores ) ); |
---|
| 315 | hal_remote_atomic_add( XPTR( node_cxy , &node_ptr->cores ) , cores ); |
---|
| 316 | |
---|
| 317 | // update <clusters> field in node |
---|
| 318 | clusters = hal_remote_l32( XPTR ( child_cxy , &child_ptr->clusters ) ); |
---|
| 319 | hal_remote_atomic_add( XPTR( node_cxy , &node_ptr->clusters ) , clusters ); |
---|
| 320 | |
---|
| 321 | // update <child[1][1]> field in node |
---|
| 322 | hal_remote_s64( XPTR( node_cxy , &node_ptr->children[1][1] ), child_xp ); |
---|
| 323 | |
---|
| 324 | // udate <arity> field in node |
---|
| 325 | hal_remote_atomic_add( XPTR( node_cxy , &node_ptr->arity ) , 1 ); |
---|
[582] | 326 | |
---|
| 327 | // exit loops |
---|
| 328 | found = true; |
---|
| 329 | } |
---|
[1] | 330 | } |
---|
[582] | 331 | } |
---|
| 332 | } |
---|
| 333 | } // end dqdt_recursive_build() |
---|
[1] | 334 | |
---|
[582] | 335 | ////////////////////// |
---|
| 336 | void dqdt_init( void ) |
---|
| 337 | { |
---|
| 338 | // get x_size & y_size from cluster manager |
---|
| 339 | cluster_t * cluster = &cluster_manager; |
---|
| 340 | uint32_t x_size = cluster->x_size; |
---|
| 341 | uint32_t y_size = cluster->y_size; |
---|
[1] | 342 | |
---|
[582] | 343 | assert( ((x_size <= 16) && (y_size <= 16)) , "illegal mesh size\n"); |
---|
| 344 | |
---|
| 345 | // compute level_max |
---|
| 346 | uint32_t x_size_ext = POW2_ROUNDUP( x_size ); |
---|
| 347 | uint32_t y_size_ext = POW2_ROUNDUP( y_size ); |
---|
| 348 | uint32_t size_ext = MAX( x_size_ext , y_size_ext ); |
---|
| 349 | uint32_t level_max = bits_log2( size_ext ); |
---|
[1] | 350 | |
---|
[582] | 351 | // each CP0 register the DQDT root in local cluster manager |
---|
| 352 | cluster->dqdt_root_xp = XPTR( 0 , &cluster->dqdt_tbl[level_max] ); |
---|
| 353 | |
---|
| 354 | #if DEBUG_DQDT_INIT |
---|
| 355 | if( local_cxy == 0 ) |
---|
| 356 | printk("\n[DBG] %s : x_size = %d / y_size = %d / level_max = %d\n", |
---|
| 357 | __FUNCTION__, x_size, y_size, level_max ); |
---|
| 358 | #endif |
---|
| 359 | |
---|
| 360 | // only CP0 in cluster 0 call the recursive function to build the quad-tree |
---|
| 361 | if (local_cxy == 0) dqdt_recursive_build( local_cxy , level_max , XPTR_NULL ); |
---|
| 362 | |
---|
| 363 | #if DEBUG_DQDT_INIT |
---|
| 364 | if( local_cxy == 0 ) dqdt_display(); |
---|
| 365 | #endif |
---|
| 366 | |
---|
| 367 | } // end dqdt_init() |
---|
| 368 | |
---|
[583] | 369 | |
---|
[1] | 370 | /////////////////////////////////////////////////////////////////////////// |
---|
[583] | 371 | // This recursive function is called by both the dqdt_increment_pages() |
---|
| 372 | // and by the dqdt_decrement_pages() functions. |
---|
[1] | 373 | // It traverses the quad tree from clusters to root. |
---|
| 374 | /////////////////////////////////////////////////////////////////////////// |
---|
[632] | 375 | // @ node_xp : extended pointer on current node |
---|
[583] | 376 | // @ increment : number of pages variation |
---|
[438] | 377 | /////////////////////////////////////////////////////////////////////////// |
---|
[632] | 378 | static void dqdt_propagate_pages( xptr_t node_xp, |
---|
[583] | 379 | int32_t increment ) |
---|
[1] | 380 | { |
---|
| 381 | // get current node cluster identifier and local pointer |
---|
[632] | 382 | cxy_t node_cxy = GET_CXY( node_xp ); |
---|
| 383 | dqdt_node_t * node_ptr = GET_PTR( node_xp ); |
---|
[1] | 384 | |
---|
[583] | 385 | // update current node pages number |
---|
[632] | 386 | hal_remote_atomic_add( XPTR( node_cxy , &node_ptr->pages ) , increment ); |
---|
[1] | 387 | |
---|
| 388 | // get extended pointer on parent node |
---|
[632] | 389 | xptr_t parent_xp = (xptr_t)hal_remote_l64( XPTR( node_cxy , &node_ptr->parent ) ); |
---|
[1] | 390 | |
---|
| 391 | // propagate if required |
---|
[632] | 392 | if ( parent_xp != XPTR_NULL ) dqdt_propagate_pages( parent_xp, increment ); |
---|
[1] | 393 | } |
---|
| 394 | |
---|
[632] | 395 | //////////////////////////////////////// |
---|
| 396 | void dqdt_increment_pages( cxy_t cxy, |
---|
| 397 | uint32_t order ) |
---|
[583] | 398 | { |
---|
[632] | 399 | // get local pointer on node[0] (same in all clusters) |
---|
| 400 | dqdt_node_t * node_ptr = &LOCAL_CLUSTER->dqdt_tbl[0]; |
---|
[583] | 401 | |
---|
[632] | 402 | // update DQDT node[0] in remote cluster cxy |
---|
| 403 | hal_remote_atomic_add( XPTR( cxy , &node_ptr->pages ) , (1 << order) ); |
---|
[583] | 404 | |
---|
[632] | 405 | // get extended pointer on parent node in remote cluster cxy |
---|
| 406 | xptr_t parent_xp = hal_remote_l64( XPTR( cxy , &node_ptr->parent ) ); |
---|
[583] | 407 | |
---|
[632] | 408 | // propagate to DQDT upper levels |
---|
| 409 | if( parent_xp != XPTR_NULL ) dqdt_propagate_pages( parent_xp , (1 << order) ); |
---|
| 410 | |
---|
[583] | 411 | #if DEBUG_DQDT_UPDATE_PAGES |
---|
| 412 | uint32_t cycle = hal_get_cycles(); |
---|
| 413 | if( cycle > DEBUG_DQDT_UPDATE_PAGES ) |
---|
| 414 | printk("\n[DBG] %s : thread %x in process %x / %x pages in cluster %x / cycle %d\n", |
---|
[632] | 415 | __FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, |
---|
| 416 | hal_remote_l32( XPTR( cxy , &node_ptr->pages ), cxy, cycle ); |
---|
[583] | 417 | #endif |
---|
| 418 | |
---|
| 419 | } |
---|
| 420 | |
---|
[632] | 421 | //////////////////////////////////////// |
---|
| 422 | void dqdt_decrement_pages( cxy_t cxy, |
---|
| 423 | uint32_t order ) |
---|
[583] | 424 | { |
---|
[632] | 425 | // get local pointer on node[0] (same in all clusters) |
---|
| 426 | dqdt_node_t * node_ptr = &LOCAL_CLUSTER->dqdt_tbl[0]; |
---|
[583] | 427 | |
---|
[632] | 428 | // update DQDT node[0] in remote cluster cxy |
---|
| 429 | hal_remote_atomic_add( XPTR( cxy , &node_ptr->pages ) , -(1 << order) ); |
---|
[583] | 430 | |
---|
[632] | 431 | // get extended pointer on parent node in remote cluster cxy |
---|
| 432 | xptr_t parent_xp = hal_remote_l64( XPTR( cxy , &node_ptr->parent ) ); |
---|
[583] | 433 | |
---|
[632] | 434 | // propagate to DQDT upper levels |
---|
| 435 | if( parent_xp != XPTR_NULL ) dqdt_propagate_pages( parent_xp , -(1 << order) ); |
---|
| 436 | |
---|
[583] | 437 | #if DEBUG_DQDT_UPDATE_PAGES |
---|
| 438 | uint32_t cycle = hal_get_cycles(); |
---|
| 439 | if( cycle > DEBUG_DQDT_UPDATE_PAGES ) |
---|
| 440 | printk("\n[DBG] %s : thread %x in process %x / %x pages in cluster %x / cycle %d\n", |
---|
[632] | 441 | __FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, |
---|
| 442 | hal_remote_l32( XPTR( cxy , &node_ptr->pages ), cxy, cycle ); |
---|
[583] | 443 | #endif |
---|
| 444 | |
---|
| 445 | } |
---|
| 446 | |
---|
| 447 | |
---|
| 448 | |
---|
[438] | 449 | /////////////////////////////////////////////////////////////////////////// |
---|
[583] | 450 | // This recursive function is called by both the dqdt_increment_threads() |
---|
| 451 | // and by the dqdt_decrement_threads functions. |
---|
[438] | 452 | // It traverses the quad tree from clusters to root. |
---|
| 453 | /////////////////////////////////////////////////////////////////////////// |
---|
| 454 | // @ node : extended pointer on current node |
---|
| 455 | // @ increment : number of pages variation |
---|
| 456 | /////////////////////////////////////////////////////////////////////////// |
---|
[583] | 457 | static void dqdt_propagate_threads( xptr_t node, |
---|
| 458 | int32_t increment ) |
---|
[1] | 459 | { |
---|
[438] | 460 | // get current node cluster identifier and local pointer |
---|
| 461 | cxy_t cxy = GET_CXY( node ); |
---|
| 462 | dqdt_node_t * ptr = GET_PTR( node ); |
---|
[1] | 463 | |
---|
[438] | 464 | // update current node threads number |
---|
[583] | 465 | hal_remote_atomic_add( XPTR( cxy , &ptr->threads ) , increment ); |
---|
[1] | 466 | |
---|
[438] | 467 | // get extended pointer on parent node |
---|
[564] | 468 | xptr_t parent = (xptr_t)hal_remote_l64( XPTR( cxy , &ptr->parent ) ); |
---|
[1] | 469 | |
---|
[438] | 470 | // propagate if required |
---|
[583] | 471 | if ( parent != XPTR_NULL ) dqdt_propagate_threads( parent, increment ); |
---|
[1] | 472 | } |
---|
| 473 | |
---|
[583] | 474 | /////////////////////////////////// |
---|
| 475 | void dqdt_increment_threads( void ) |
---|
[1] | 476 | { |
---|
[438] | 477 | cluster_t * cluster = LOCAL_CLUSTER; |
---|
| 478 | dqdt_node_t * node = &cluster->dqdt_tbl[0]; |
---|
[19] | 479 | |
---|
[438] | 480 | // update DQDT node level 0 |
---|
[583] | 481 | hal_atomic_add( &node->threads , 1 ); |
---|
[1] | 482 | |
---|
[438] | 483 | // propagate to DQDT upper levels |
---|
[583] | 484 | if( node->parent != XPTR_NULL ) dqdt_propagate_threads( node->parent , 1 ); |
---|
| 485 | |
---|
| 486 | #if DEBUG_DQDT_UPDATE_THREADS |
---|
| 487 | uint32_t cycle = hal_get_cycles(); |
---|
| 488 | if( cycle > DEBUG_DQDT_UPDATE_THREADS ) |
---|
| 489 | printk("\n[DBG] %s : thread %x in process %x / %d threads in cluster %x / cycle %d\n", |
---|
[632] | 490 | __FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, |
---|
| 491 | node->threads, local_cxy, cycle ); |
---|
[583] | 492 | #endif |
---|
| 493 | |
---|
[1] | 494 | } |
---|
| 495 | |
---|
[583] | 496 | /////////////////////////////////// |
---|
| 497 | void dqdt_decrement_threads( void ) |
---|
[1] | 498 | { |
---|
[438] | 499 | cluster_t * cluster = LOCAL_CLUSTER; |
---|
| 500 | dqdt_node_t * node = &cluster->dqdt_tbl[0]; |
---|
[19] | 501 | |
---|
[438] | 502 | // update DQDT node level 0 |
---|
[583] | 503 | hal_atomic_add( &node->threads , -1 ); |
---|
[1] | 504 | |
---|
[438] | 505 | // propagate to DQDT upper levels |
---|
[583] | 506 | if( node->parent != XPTR_NULL ) dqdt_propagate_threads( node->parent , -1 ); |
---|
| 507 | |
---|
| 508 | #if DEBUG_DQDT_UPDATE_THREADS |
---|
| 509 | uint32_t cycle = hal_get_cycles(); |
---|
| 510 | if( cycle > DEBUG_DQDT_UPDATE_THREADS ) |
---|
| 511 | printk("\n[DBG] %s : thread %x in process %x / %d threads in cluster %x / cycle %d\n", |
---|
[632] | 512 | __FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, |
---|
| 513 | node->threads, local_cxy, cycle ); |
---|
[583] | 514 | #endif |
---|
| 515 | |
---|
[1] | 516 | } |
---|
| 517 | |
---|
[583] | 518 | |
---|
| 519 | ///////////////////////////////////////////////////////////////////////////////////// |
---|
[1] | 520 | // This recursive function is called by both the dqdt_get_cluster_for_process() |
---|
[583] | 521 | // and by the dqdt_get_cluster_for_memory() functions to select the cluster with the |
---|
| 522 | // smallest number of threads per core, or the smallest number of pages per cluster. |
---|
[1] | 523 | // It traverses the quad tree from root to clusters. |
---|
[583] | 524 | ///////////////////////////////////////////////////////////////////////////////////// |
---|
[1] | 525 | static cxy_t dqdt_select_cluster( xptr_t node, |
---|
| 526 | bool_t for_memory ) |
---|
| 527 | { |
---|
| 528 | dqdt_node_t node_copy; // local copy of the current DQDT node |
---|
[582] | 529 | xptr_t child_xp; // extended pointer on a DQDT child node |
---|
| 530 | uint32_t x; // child node X coordinate |
---|
| 531 | uint32_t y; // child node Y coordinate |
---|
| 532 | uint32_t select_x; // selected child X coordinate |
---|
| 533 | uint32_t select_y; // selected child Y coordinate |
---|
[1] | 534 | uint32_t load; // load of the child (threads or pages) |
---|
| 535 | uint32_t load_min; // current value of the minimal load |
---|
| 536 | |
---|
| 537 | // get DQDT node local copy |
---|
| 538 | hal_remote_memcpy( XPTR( local_cxy , &node_copy ), node , sizeof(dqdt_node_t) ); |
---|
| 539 | |
---|
| 540 | // return cluster identifier for a terminal mode |
---|
| 541 | if( node_copy.level == 0 ) return GET_CXY(node); |
---|
| 542 | |
---|
| 543 | // analyse load for all children in non terminal node |
---|
| 544 | load_min = 0xFFFFFFFF; |
---|
[582] | 545 | select_x = 0; |
---|
| 546 | select_y = 0; |
---|
| 547 | for( x = 0 ; x < 2 ; x++ ) |
---|
[1] | 548 | { |
---|
[582] | 549 | for( y = 0 ; y < 2 ; y++ ) |
---|
[1] | 550 | { |
---|
[582] | 551 | child_xp = node_copy.children[x][y]; |
---|
| 552 | if( child_xp != XPTR_NULL ) |
---|
[1] | 553 | { |
---|
[582] | 554 | cxy_t cxy = GET_CXY( child_xp ); |
---|
| 555 | dqdt_node_t * ptr = GET_PTR( child_xp ); |
---|
[583] | 556 | |
---|
| 557 | // compute average load for each child |
---|
| 558 | if( for_memory ) |
---|
[582] | 559 | { |
---|
[583] | 560 | load = hal_remote_l32( XPTR( cxy , &ptr->pages ) ) / |
---|
| 561 | hal_remote_l32( XPTR( cxy , &ptr->clusters ) ); |
---|
| 562 | } |
---|
| 563 | else |
---|
| 564 | { |
---|
| 565 | load = hal_remote_l32( XPTR( cxy , &ptr->threads ) ) / |
---|
| 566 | hal_remote_l32( XPTR( cxy , &ptr->cores ) ); |
---|
| 567 | } |
---|
| 568 | |
---|
| 569 | // select children with smallest load |
---|
| 570 | if( load <= load_min ) |
---|
| 571 | { |
---|
[582] | 572 | load_min = load; |
---|
| 573 | select_x = x; |
---|
| 574 | select_y = y; |
---|
| 575 | } |
---|
[19] | 576 | } |
---|
[1] | 577 | } |
---|
| 578 | } |
---|
| 579 | |
---|
| 580 | // select the child with the lowest load |
---|
[582] | 581 | return dqdt_select_cluster( node_copy.children[select_x][select_y], for_memory ); |
---|
[1] | 582 | |
---|
[583] | 583 | } // end dqdt_select_cluster() |
---|
| 584 | |
---|
| 585 | |
---|
[564] | 586 | ////////////////////////////////////////// |
---|
[485] | 587 | cxy_t dqdt_get_cluster_for_process( void ) |
---|
[1] | 588 | { |
---|
| 589 | // call recursive function |
---|
[583] | 590 | cxy_t cxy = dqdt_select_cluster( LOCAL_CLUSTER->dqdt_root_xp , false ); |
---|
| 591 | |
---|
| 592 | #if DEBUG_DQDT_SELECT_FOR_PROCESS |
---|
| 593 | uint32_t cycle = hal_get_cycles(); |
---|
| 594 | if( cycle > DEBUG_DQDT_SELECT_FOR_PROCESS ) |
---|
| 595 | printk("\n[DBG] %s : thread %x in process %x select cluster %x / cycle %d\n", |
---|
| 596 | __FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, cxy, cycle ); |
---|
| 597 | #endif |
---|
| 598 | |
---|
| 599 | return cxy; |
---|
[1] | 600 | } |
---|
| 601 | |
---|
[564] | 602 | ///////////////////////////////////////// |
---|
[485] | 603 | cxy_t dqdt_get_cluster_for_memory( void ) |
---|
[1] | 604 | { |
---|
| 605 | // call recursive function |
---|
[583] | 606 | cxy_t cxy = dqdt_select_cluster( LOCAL_CLUSTER->dqdt_root_xp , true ); |
---|
| 607 | |
---|
| 608 | #if DEBUG_DQDT_SELECT_FOR_MEMORY |
---|
| 609 | uint32_t cycle = hal_get_cycles(); |
---|
| 610 | if( cycle > DEBUG_DQDT_SELECT_FOR_MEMORY ) |
---|
| 611 | printk("\n[DBG] %s : thread %x in process %x select cluster %x / cycle %d\n", |
---|
| 612 | __FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, cxy, cycle ); |
---|
| 613 | #endif |
---|
| 614 | |
---|
| 615 | return cxy; |
---|
[1] | 616 | } |
---|
| 617 | |
---|