Changeset 564 for trunk/kernel/kern/cluster.c
- Timestamp:
- Oct 4, 2018, 11:47:36 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/kern/cluster.c
r562 r564 29 29 #include <hal_special.h> 30 30 #include <hal_ppm.h> 31 #include <hal_macros.h> 31 32 #include <remote_fifo.h> 32 33 #include <printk.h> 33 34 #include <errno.h> 34 #include < spinlock.h>35 #include <queuelock.h> 35 36 #include <core.h> 36 37 #include <chdev.h> … … 45 46 #include <process.h> 46 47 #include <dqdt.h> 47 #include <cluster_info.h>48 48 49 49 ///////////////////////////////////////////////////////////////////////////////////// … … 51 51 ///////////////////////////////////////////////////////////////////////////////////// 52 52 53 extern process_t process_zero; // allocated in kernel_init.c file 54 extern chdev_directory_t chdev_dir; // allocated in kernel_init.c file 55 56 ///////////////////////////////////////////////n 57 error_t cluster_init( struct boot_info_s * info ) 58 { 59 error_t error; 60 lpid_t lpid; // local process_index 61 lid_t lid; // local core index 62 uint32_t i; // index in loop on external peripherals 53 extern process_t process_zero; // allocated in kernel_init.c 54 extern chdev_directory_t chdev_dir; // allocated in kernel_init.c 55 56 57 58 /////////////////////////////////////////////////// 59 void cluster_info_init( struct boot_info_s * info ) 60 { 63 61 boot_device_t * dev; // pointer on external peripheral 64 62 uint32_t func; // external peripheral functionnal type 63 uint32_t x; 64 uint32_t y; 65 uint32_t i; 65 66 66 67 cluster_t * cluster = LOCAL_CLUSTER; … … 75 76 76 77 // initialize the cluster_info[][] array 77 int x;78 int y;79 for (x = 0; x < CONFIG_MAX_CLUSTERS_X; x++) {80 for (y = 0; y < CONFIG_MAX_CLUSTERS_Y;y++){78 for (x = 0; x < CONFIG_MAX_CLUSTERS_X; x++) 79 { 80 for (y = 0; y < CONFIG_MAX_CLUSTERS_Y;y++) 81 { 81 82 cluster->cluster_info[x][y] = info->cluster_info[x][y]; 82 83 } 83 84 } 85 84 86 // initialize external peripherals channels 85 87 for( i = 0 ; i < info->ext_dev_nr ; i++ ) … … 93 95 } 94 96 95 // initialize cluster local parameters 96 cluster->cores_nr = info->cores_nr; 97 // initialize number of cores 98 cluster->cores_nr = info->cores_nr; 99 100 } // end cluster_info_init() 101 102 ///////////////////////////////////////////////////////// 103 error_t cluster_manager_init( struct boot_info_s * info ) 104 { 105 error_t error; 106 lpid_t lpid; // local process_index 107 lid_t lid; // local core index 108 109 cluster_t * cluster = LOCAL_CLUSTER; 97 110 98 111 // initialize the lock protecting the embedded kcm allocator 99 spinlock_init( &cluster->kcm_lock);112 busylock_init( &cluster->kcm_lock , LOCK_CLUSTER_KCM ); 100 113 101 114 #if DEBUG_CLUSTER_INIT 102 115 uint32_t cycle = (uint32_t)hal_get_cycles(); 103 116 if( DEBUG_CLUSTER_INIT < cycle ) 104 printk("\n[DBG] %s : thread %x enters for cluster %x / cycle %d\n",105 __FUNCTION__ , CURRENT_THREAD, local_cxy , cycle );117 printk("\n[DBG] %s : thread %x in process %x enters for cluster %x / cycle %d\n", 118 __FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, local_cxy , cycle ); 106 119 #endif 107 120 108 121 // initialises DQDT 109 122 cluster->dqdt_root_level = dqdt_init( info->x_size, 110 info->y_size, 111 info->y_width ) - 1; 123 info->y_size ) - 1; 124 125 #if( DEBUG_CLUSTER_INIT & 1 ) 126 cycle = (uint32_t)hal_get_cycles(); 127 if( DEBUG_CLUSTER_INIT < cycle ) 128 printk("\n[DBG] %s : DQDT initialized in cluster %x / cycle %d\n", 129 __FUNCTION__ , local_cxy , cycle ); 130 #endif 112 131 113 132 // initialises embedded PPM … … 166 185 for( lid = 0 ; lid < cluster->cores_nr; lid++ ) 167 186 { 168 local_fifo_init( &cluster->rpc_fifo[lid] );187 remote_fifo_init( &cluster->rpc_fifo[lid] ); 169 188 cluster->rpc_threads[lid] = 0; 170 189 } … … 178 197 179 198 // initialise pref_tbl[] in process manager 180 spinlock_init( &cluster->pmgr.pref_lock);199 queuelock_init( &cluster->pmgr.pref_lock , LOCK_CLUSTER_PREFTBL ); 181 200 cluster->pmgr.pref_nr = 0; 182 201 cluster->pmgr.pref_tbl[0] = XPTR( local_cxy , &process_zero ); … … 187 206 188 207 // initialise local_list in process manager 189 remote_spinlock_init( XPTR( local_cxy , &cluster->pmgr.local_lock ) );190 208 xlist_root_init( XPTR( local_cxy , &cluster->pmgr.local_root ) ); 191 209 cluster->pmgr.local_nr = 0; 210 remote_queuelock_init( XPTR( local_cxy , &cluster->pmgr.local_lock ) , 211 LOCK_CLUSTER_LOCALS ); 192 212 193 213 // initialise copies_lists in process manager 194 214 for( lpid = 0 ; lpid < CONFIG_MAX_PROCESS_PER_CLUSTER ; lpid++ ) 195 215 { 196 remote_spinlock_init( XPTR( local_cxy , &cluster->pmgr.copies_lock[lpid] ) );197 216 cluster->pmgr.copies_nr[lpid] = 0; 198 217 xlist_root_init( XPTR( local_cxy , &cluster->pmgr.copies_root[lpid] ) ); 218 remote_queuelock_init( XPTR( local_cxy , &cluster->pmgr.copies_lock[lpid] ), 219 LOCK_CLUSTER_COPIES ); 199 220 } 200 221 … … 202 223 cycle = (uint32_t)hal_get_cycles(); 203 224 if( DEBUG_CLUSTER_INIT < cycle ) 204 printk("\n[DBG] %s , thread%x exit for cluster %x / cycle %d\n",205 __FUNCTION__ , CURRENT_THREAD, local_cxy , cycle );225 printk("\n[DBG] %s : thread %x in process %x exit for cluster %x / cycle %d\n", 226 __FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid , local_cxy , cycle ); 206 227 #endif 207 228 … … 209 230 210 231 return 0; 211 } // end cluster_ init()212 213 ///////////////////////////////// 232 } // end cluster_manager_init() 233 234 /////////////////////////////////// 214 235 cxy_t cluster_random_select( void ) 215 236 { 216 uint32_t x_size;217 uint32_t y_size;218 uint32_t y_width;219 237 uint32_t index; 220 uint32_t x; 238 uint32_t x; 221 239 uint32_t y; 222 223 do { 224 x_size = LOCAL_CLUSTER->x_size; 225 y_size = LOCAL_CLUSTER->y_size; 226 y_width = LOCAL_CLUSTER->y_width; 240 cxy_t cxy; 241 242 uint32_t x_size = LOCAL_CLUSTER->x_size; 243 uint32_t y_size = LOCAL_CLUSTER->y_size; 244 245 do 246 { 227 247 index = ( hal_get_cycles() + hal_get_gid() ) % (x_size * y_size); 228 248 x = index / y_size; 229 249 y = index % y_size; 230 } while ( cluster_info_is_active( LOCAL_CLUSTER->cluster_info[x][y] ) == 0 ); 231 232 return (x<<y_width) + y; 250 cxy = HAL_CXY_FROM_XY( x , y ); 251 } 252 while ( cluster_is_active( cxy ) == false ); 253 254 return ( cxy ); 233 255 } 234 256 … … 236 258 bool_t cluster_is_undefined( cxy_t cxy ) 237 259 { 238 cluster_t * cluster = LOCAL_CLUSTER; 239 240 uint32_t y_width = cluster->y_width; 241 242 uint32_t x = cxy >> y_width; 243 uint32_t y = cxy & ((1<<y_width)-1); 244 245 if( x >= cluster->x_size ) return true; 246 if( y >= cluster->y_size ) return true; 260 uint32_t x_size = LOCAL_CLUSTER->x_size; 261 uint32_t y_size = LOCAL_CLUSTER->y_size; 262 263 uint32_t x = HAL_X_FROM_CXY( cxy ); 264 uint32_t y = HAL_Y_FROM_CXY( cxy ); 265 266 if( x >= x_size ) return true; 267 if( y >= y_size ) return true; 247 268 248 269 return false; 270 } 271 272 ////////////////////////////////////// 273 bool_t cluster_is_active ( cxy_t cxy ) 274 { 275 uint32_t x = HAL_X_FROM_CXY( cxy ); 276 uint32_t y = HAL_Y_FROM_CXY( cxy ); 277 278 return ( LOCAL_CLUSTER->cluster_info[x][y] != 0 ); 249 279 } 250 280 … … 304 334 305 335 // take the lock protecting the list of processes 306 remote_ spinlock_lock( lock_xp );336 remote_queuelock_acquire( lock_xp ); 307 337 308 338 // scan list of processes … … 320 350 321 351 // release the lock protecting the list of processes 322 remote_ spinlock_unlock( lock_xp );352 remote_queuelock_release( lock_xp ); 323 353 324 354 // return extended pointer on process descriptor in owner cluster … … 350 380 351 381 // take the lock protecting the list of processes 352 remote_ spinlock_lock( lock_xp );382 remote_queuelock_acquire( lock_xp ); 353 383 354 384 // scan list of processes in owner cluster … … 358 388 current_xp = XLIST_ELEMENT( iter_xp , process_t , local_list ); 359 389 current_ptr = GET_PTR( current_xp ); 360 current_pid = hal_remote_l w( XPTR( owner_cxy , ¤t_ptr->pid ) );390 current_pid = hal_remote_l32( XPTR( owner_cxy , ¤t_ptr->pid ) ); 361 391 362 392 if( current_pid == pid ) … … 368 398 369 399 // release the lock protecting the list of processes 370 remote_ spinlock_unlock( lock_xp );400 remote_queuelock_release( lock_xp ); 371 401 372 402 // return extended pointer on process descriptor in owner cluster … … 397 427 else // use a remote_lwd to access owner cluster 398 428 { 399 ref_xp = (xptr_t)hal_remote_l wd( XPTR( owner_cxy , &cluster->pmgr.pref_tbl[lpid] ) );429 ref_xp = (xptr_t)hal_remote_l64( XPTR( owner_cxy , &cluster->pmgr.pref_tbl[lpid] ) ); 400 430 } 401 431 … … 419 449 pmgr_t * pm = &LOCAL_CLUSTER->pmgr; 420 450 421 // get the process manager lock422 spinlock_lock( &pm->pref_lock );451 // get the lock protecting pref_tbl 452 queuelock_acquire( &pm->pref_lock ); 423 453 424 454 // search an empty slot … … 443 473 444 474 // release the processs_manager lock 445 spinlock_unlock( &pm->pref_lock );475 queuelock_release( &pm->pref_lock ); 446 476 447 477 return 0; … … 449 479 else 450 480 { 451 // release the processs_managerlock452 spinlock_unlock( &pm->pref_lock );453 454 return -1;481 // release the lock 482 queuelock_release( &pm->pref_lock ); 483 484 return 0xFFFFFFFF; 455 485 } 456 486 … … 488 518 "local_cluster %x != owner_cluster %x" , local_cxy , owner_cxy ); 489 519 490 // get the process manager lock491 spinlock_lock( &pm->pref_lock );520 // get the lock protecting pref_tbl 521 queuelock_acquire( &pm->pref_lock ); 492 522 493 523 // remove process from pref_tbl[] … … 496 526 497 527 // release the processs_manager lock 498 spinlock_unlock( &pm->pref_lock );528 queuelock_release( &pm->pref_lock ); 499 529 500 530 #if DEBUG_CLUSTER_PID_RELEASE … … 538 568 void cluster_process_local_link( process_t * process ) 539 569 { 540 reg_t save_sr;541 542 570 pmgr_t * pm = &LOCAL_CLUSTER->pmgr; 543 571 … … 546 574 xptr_t lock_xp = XPTR( local_cxy , &pm->local_lock ); 547 575 548 // get lock protecting the process managerlocal list549 remote_ spinlock_lock_busy( lock_xp , &save_sr);576 // get lock protecting the local list 577 remote_queuelock_acquire( lock_xp ); 550 578 551 579 // register process in local list … … 553 581 pm->local_nr++; 554 582 555 // release lock protecting the process managerlocal list556 remote_ spinlock_unlock_busy( lock_xp , save_sr);583 // release lock protecting the local list 584 remote_queuelock_release( lock_xp ); 557 585 } 558 586 … … 560 588 void cluster_process_local_unlink( process_t * process ) 561 589 { 562 reg_t save_sr;563 564 590 pmgr_t * pm = &LOCAL_CLUSTER->pmgr; 565 591 … … 567 593 xptr_t lock_xp = XPTR( local_cxy , &pm->local_lock ); 568 594 569 // get lock protecting the process managerlocal list570 remote_ spinlock_lock_busy( lock_xp , &save_sr);595 // get lock protecting the local list 596 remote_queuelock_acquire( lock_xp ); 571 597 572 598 // remove process from local list … … 574 600 pm->local_nr--; 575 601 576 // release lock protecting the process managerlocal list577 remote_ spinlock_unlock_busy( lock_xp , save_sr);602 // release lock protecting the local list 603 remote_queuelock_release( lock_xp ); 578 604 } 579 605 … … 581 607 void cluster_process_copies_link( process_t * process ) 582 608 { 583 reg_t irq_state;584 609 pmgr_t * pm = &LOCAL_CLUSTER->pmgr; 585 610 … … 606 631 607 632 // get lock protecting copies_list[lpid] 608 remote_ spinlock_lock_busy( copies_lock , &irq_state);633 remote_queuelock_acquire( copies_lock ); 609 634 610 635 // add copy to copies_list … … 613 638 614 639 // release lock protecting copies_list[lpid] 615 remote_ spinlock_unlock_busy( copies_lock , irq_state);640 remote_queuelock_release( copies_lock ); 616 641 617 642 #if DEBUG_CLUSTER_PROCESS_COPIES … … 627 652 void cluster_process_copies_unlink( process_t * process ) 628 653 { 629 uint32_t irq_state;630 654 pmgr_t * pm = &LOCAL_CLUSTER->pmgr; 631 655 … … 649 673 650 674 // get lock protecting copies_list[lpid] 651 remote_ spinlock_lock_busy( copies_lock , &irq_state);675 remote_queuelock_acquire( copies_lock ); 652 676 653 677 // remove copy from copies_list … … 656 680 657 681 // release lock protecting copies_list[lpid] 658 remote_ spinlock_unlock_busy( copies_lock , irq_state);682 remote_queuelock_release( copies_lock ); 659 683 660 684 #if DEBUG_CLUSTER_PROCESS_COPIES … … 678 702 xptr_t txt0_xp; 679 703 xptr_t txt0_lock_xp; 680 reg_t txt0_save_sr; // save SR to take TXT0 lock in busy mode681 704 682 705 assert( (cluster_is_undefined( cxy ) == false), … … 696 719 697 720 // get lock on local process list 698 remote_ spinlock_lock( lock_xp );699 700 // get TXT0 lock in busy waiting mode701 remote_ spinlock_lock_busy( txt0_lock_xp , &txt0_save_sr);721 remote_queuelock_acquire( lock_xp ); 722 723 // get TXT0 lock 724 remote_busylock_acquire( txt0_lock_xp ); 702 725 703 726 // display header … … 712 735 } 713 736 714 // release TXT0 lock in busy waiting mode715 remote_ spinlock_unlock_busy( txt0_lock_xp , txt0_save_sr);737 // release TXT0 lock 738 remote_busylock_release( txt0_lock_xp ); 716 739 717 740 // release lock on local process list 718 remote_ spinlock_unlock( lock_xp );741 remote_queuelock_release( lock_xp ); 719 742 720 743 } // end cluster_processes_display()
Note: See TracChangeset
for help on using the changeset viewer.