Changeset 564 for trunk/kernel/kern/chdev.c
- Timestamp:
- Oct 4, 2018, 11:47:36 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/kern/chdev.c
r545 r564 37 37 #include <devfs.h> 38 38 39 40 extern chdev_directory_t chdev_dir; // allocated in kernel_init.c 39 ////////////////////////////////////////////////////////////////////////////////////// 40 // Extern global variables 41 ////////////////////////////////////////////////////////////////////////////////////// 42 43 extern chdev_directory_t chdev_dir; // allocated in kernel_init.c 44 41 45 42 46 #if (DEBUG_SYS_READ & 1) … … 57 61 char * chdev_func_str( uint32_t func_type ) 58 62 { 59 switch ( func_type ) { 63 switch ( func_type ) 64 { 60 65 case DEV_FUNC_RAM: return "RAM"; 61 66 case DEV_FUNC_ROM: return "ROM"; … … 91 96 if( chdev == NULL ) return NULL; 92 97 93 // initialize waiting threads queue and associated lock 94 remote_spinlock_init( XPTR( local_cxy , &chdev->wait_lock ) ); 98 // initialize lock 99 remote_busylock_init( XPTR( local_cxy , &chdev->wait_lock ), LOCK_CHDEV_QUEUE ); 100 101 // initialise waiting queue 95 102 xlist_root_init( XPTR( local_cxy , &chdev->wait_root ) ); 96 103 … … 130 137 core_t * core_ptr; // local pointer on core running the server thread 131 138 uint32_t server_lid; // core running the server thread local index 132 xptr_t lock_xp; // extended pointer on lock protecting the chdev queue139 xptr_t lock_xp; // extended pointer on lock protecting the chdev state 133 140 uint32_t save_sr; // for critical section 134 141 … … 147 154 chdev_t * chdev_ptr = GET_PTR( chdev_xp ); 148 155 156 // check calling thread can yield 157 assert( (this->busylocks == 0), 158 "cannot yield : busylocks = %d\n", this->busylocks ); 159 149 160 // get local and extended pointers on server thread 150 161 server_ptr = (thread_t *)hal_remote_lpt( XPTR( chdev_cxy , &chdev_ptr->server) ); … … 155 166 156 167 // get server core local index 157 server_lid = hal_remote_l w( XPTR( chdev_cxy , &core_ptr->lid ) );168 server_lid = hal_remote_l32( XPTR( chdev_cxy , &core_ptr->lid ) ); 158 169 159 170 #if (DEBUG_CHDEV_CMD_RX || DEBUG_CHDEV_CMD_TX) 160 bool_t is_rx = hal_remote_l w( XPTR( chdev_cxy , &chdev_ptr->is_rx ) );171 bool_t is_rx = hal_remote_l32( XPTR( chdev_cxy , &chdev_ptr->is_rx ) ); 161 172 #endif 162 173 … … 185 196 186 197 // build extended pointer on lock protecting chdev waiting queue 187 lock_xp = XPTR( chdev_cxy , &chdev_ptr->wait_lock );198 lock_xp = XPTR( chdev_cxy , &chdev_ptr->wait_lock ); 188 199 189 200 // critical section for the following sequence: 190 // (1) take the lock protecting waiting queue201 // (1) take the lock protecting the chdev state 191 202 // (2) block the client thread 192 203 // (3) unblock the server thread if required … … 200 211 hal_disable_irq( &save_sr ); 201 212 202 // take the lock protecting chdev waitingqueue203 remote_ spinlock_lock( lock_xp );213 // take the lock protecting chdev queue 214 remote_busylock_acquire( lock_xp ); 204 215 205 216 // block current thread … … 217 228 218 229 // unblock server thread if required 219 if( hal_remote_l w( blocked_xp ) & THREAD_BLOCKED_IDLE )230 if( hal_remote_l32( blocked_xp ) & THREAD_BLOCKED_IDLE ) 220 231 thread_unblock( server_xp , THREAD_BLOCKED_IDLE ); 221 232 … … 243 254 #endif 244 255 245 // send IPI to core running the server thread when server != client256 // send IPI to core running the server thread when server core != client core 246 257 if( (server_lid != this->core->lid) || (local_cxy != chdev_cxy) ) 247 258 { … … 262 273 } 263 274 264 // release lock 265 remote_ spinlock_unlock( lock_xp );275 // release lock protecting chdev queue 276 remote_busylock_release( lock_xp ); 266 277 267 278 // deschedule 268 assert( thread_can_yield() , "illegal sched_yield\n" );269 279 sched_yield("blocked on I/O"); 270 280 … … 308 318 server = CURRENT_THREAD; 309 319 310 // get root and lock on commandqueue320 // build extended pointer on root of client threads queue 311 321 root_xp = XPTR( local_cxy , &chdev->wait_root ); 322 323 // build extended pointer on lock protecting client threads queue 312 324 lock_xp = XPTR( local_cxy , &chdev->wait_lock ); 313 325 … … 316 328 while( 1 ) 317 329 { 330 331 #if DEBUG_CHDEV_SERVER_RX 332 uint32_t rx_cycle = (uint32_t)hal_get_cycles(); 333 if( (chdev->is_rx) && (DEBUG_CHDEV_SERVER_RX < rx_cycle) ) 334 printk("\n[DBG] %s : dev_thread %x start RX / cycle %d\n", 335 __FUNCTION__ , server->trdid , rx_cycle ); 336 #endif 337 338 #if DEBUG_CHDEV_SERVER_TX 339 uint32_t tx_cycle = (uint32_t)hal_get_cycles(); 340 if( (chdev->is_rx == 0) && (DEBUG_CHDEV_SERVER_TX < tx_cycle) ) 341 printk("\n[DBG] %s : dev_thread %x start TX / cycle %d\n", 342 __FUNCTION__ , server->trdid , tx_cycle ); 343 #endif 344 318 345 // get the lock protecting the waiting queue 319 remote_ spinlock_lock( lock_xp );346 remote_busylock_acquire( lock_xp ); 320 347 321 348 // check waiting queue state 322 349 if( xlist_is_empty( root_xp ) ) // waiting queue empty 323 350 { 351 352 #if DEBUG_CHDEV_SERVER_RX 353 rx_cycle = (uint32_t)hal_get_cycles(); 354 if( (chdev->is_rx) && (DEBUG_CHDEV_SERVER_RX < rx_cycle) ) 355 printk("\n[DBG] %s : dev_thread %x found RX queue empty => blocks / cycle %d\n", 356 __FUNCTION__ , server->trdid , rx_cycle ); 357 #endif 358 359 #if DEBUG_CHDEV_SERVER_TX 360 tx_cycle = (uint32_t)hal_get_cycles(); 361 if( (chdev->is_rx == 0) && (DEBUG_CHDEV_SERVER_TX < tx_cycle) ) 362 printk("\n[DBG] %s : dev_thread %x found TX queue empty => blocks / cycle %d\n", 363 __FUNCTION__ , server->trdid , tx_cycle ); 364 #endif 365 324 366 // release lock 325 remote_ spinlock_unlock( lock_xp );367 remote_busylock_release( lock_xp ); 326 368 327 369 // block 328 370 thread_block( XPTR( local_cxy , server ) , THREAD_BLOCKED_IDLE ); 329 371 372 // check server thread can yield 373 assert( (server->busylocks == 0), 374 "cannot yield : busylocks = %d\n", server->busylocks ); 375 330 376 // deschedule 331 assert( thread_can_yield() , "illegal sched_yield\n" );332 377 sched_yield("I/O queue empty"); 333 378 } … … 335 380 { 336 381 // get extended pointer on first client thread 337 client_xp = XLIST_FIRST _ELEMENT( root_xp , thread_t , wait_list );382 client_xp = XLIST_FIRST( root_xp , thread_t , wait_list ); 338 383 339 384 // get client thread cluster and local pointer … … 345 390 346 391 // release lock 347 remote_ spinlock_unlock( lock_xp );392 remote_busylock_release( lock_xp ); 348 393 349 394 #if DEBUG_CHDEV_SERVER_RX 350 uint32_trx_cycle = (uint32_t)hal_get_cycles();395 rx_cycle = (uint32_t)hal_get_cycles(); 351 396 if( (chdev->is_rx) && (DEBUG_CHDEV_SERVER_RX < rx_cycle) ) 352 printk("\n[DBG] %s : server_thread %x start RX / client%x / cycle %d\n",353 __FUNCTION__ , server , client_ptr, rx_cycle );397 printk("\n[DBG] %s : dev_thread %x for RX found client thread %x in process %x / cycle %d\n", 398 __FUNCTION__, server->trdid ,client_ptr->trdid ,client_ptr->process->pid, rx_cycle ); 354 399 #endif 355 400 356 401 #if DEBUG_CHDEV_SERVER_TX 357 uint32_ttx_cycle = (uint32_t)hal_get_cycles();402 tx_cycle = (uint32_t)hal_get_cycles(); 358 403 if( (chdev->is_rx == 0) && (DEBUG_CHDEV_SERVER_TX < tx_cycle) ) 359 printk("\n[DBG] %s : server_thread %x start TX / client%x / cycle %d\n",360 __FUNCTION__ , server , client_ptr, tx_cycle );404 printk("\n[DBG] %s : dev_thread %x for TX found client thread %x in process %x / cycle %d\n", 405 __FUNCTION__, server->trdid ,client_ptr->trdid ,client_ptr->process->pid, tx_cycle ); 361 406 #endif 362 407 … … 378 423 rx_cycle = (uint32_t)hal_get_cycles(); 379 424 if( (chdev->is_rx) && (DEBUG_CHDEV_SERVER_RX < rx_cycle) ) 380 printk("\n[DBG] %s : server_thread %x completes RX / client%x / cycle %d\n",381 __FUNCTION__ , server , client_ptr, rx_cycle );425 printk("\n[DBG] %s : dev_thread %x completes RX for client %x in process %x / cycle %d\n", 426 __FUNCTION__, server->trdid, client_ptr->trdid, client_ptr->process->pid, rx_cycle ); 382 427 #endif 383 428 … … 385 430 tx_cycle = (uint32_t)hal_get_cycles(); 386 431 if( (chdev->is_rx == 0) && (DEBUG_CHDEV_SERVER_TX < tx_cycle) ) 387 printk("\n[DBG] %s : server_thread %x completes TX / client%x / cycle %d\n",388 __FUNCTION__ , server , client_ptr, tx_cycle );432 printk("\n[DBG] %s : dev_thread %x completes TX for client %x in process %x / cycle %d\n", 433 __FUNCTION__, server->trdid, client_ptr->trdid, client_ptr->process->pid, tx_cycle ); 389 434 #endif 390 435 … … 419 464 420 465 // get inode type from file descriptor 421 inode_type = hal_remote_l w( XPTR( file_cxy , &file_ptr->type ) );466 inode_type = hal_remote_l32( XPTR( file_cxy , &file_ptr->type ) ); 422 467 inode_ptr = (vfs_inode_t *)hal_remote_lpt( XPTR( file_cxy , &file_ptr->inode ) ); 423 468 … … 432 477 } // end chdev_from_file() 433 478 434 //////////////////////// 479 ////////////////////////////// 435 480 void chdev_dir_display( void ) 436 481 { … … 439 484 chdev_t * ptr; 440 485 uint32_t base; 441 reg_t save_sr;442 486 443 487 // get pointers on TXT0 chdev … … 446 490 chdev_t * txt0_ptr = GET_PTR( txt0_xp ); 447 491 448 // get extended pointer on remote TXT0 chdevlock492 // get extended pointer on TXT0 lock 449 493 xptr_t lock_xp = XPTR( txt0_cxy , &txt0_ptr->wait_lock ); 450 494 451 // get TXT0 lock in busy waiting mode452 remote_ spinlock_lock_busy( lock_xp , &save_sr);495 // get TXT0 lock 496 remote_busylock_acquire( lock_xp ); 453 497 454 498 // header … … 456 500 457 501 // IOB 458 if (chdev_dir.iob != NULL )502 if (chdev_dir.iob != XPTR_NULL ) 459 503 { 460 504 cxy = GET_CXY( chdev_dir.iob ); 461 505 ptr = GET_PTR( chdev_dir.iob ); 462 base = (uint32_t)hal_remote_l wd( XPTR( cxy , &ptr->base ) );506 base = (uint32_t)hal_remote_l64( XPTR( cxy , &ptr->base ) ); 463 507 nolock_printk(" - iob : cxy = %X / ptr = %X / base = %X\n", cxy, ptr, base); 464 508 } … … 467 511 cxy = GET_CXY( chdev_dir.pic ); 468 512 ptr = GET_PTR( chdev_dir.pic ); 469 base = (uint32_t)hal_remote_l wd( XPTR( cxy , &ptr->base ) );513 base = (uint32_t)hal_remote_l64( XPTR( cxy , &ptr->base ) ); 470 514 nolock_printk(" - pic : cxy = %X / ptr = %X / base = %X\n", cxy, ptr, base); 471 515 … … 475 519 cxy = GET_CXY( chdev_dir.txt_rx[i] ); 476 520 ptr = GET_PTR( chdev_dir.txt_rx[i] ); 477 base = (uint32_t)hal_remote_l wd( XPTR( cxy , &ptr->base ) );521 base = (uint32_t)hal_remote_l64( XPTR( cxy , &ptr->base ) ); 478 522 nolock_printk(" - txt_rx[%d] : cxy = %X / ptr = %X / base = %X\n", i, cxy, ptr, base); 479 523 480 524 cxy = GET_CXY( chdev_dir.txt_tx[i] ); 481 525 ptr = GET_PTR( chdev_dir.txt_tx[i] ); 482 base = (uint32_t)hal_remote_l wd( XPTR( cxy , &ptr->base ) );526 base = (uint32_t)hal_remote_l64( XPTR( cxy , &ptr->base ) ); 483 527 nolock_printk(" - txt_tx[%d] : cxy = %X / ptr = %X / base = %X\n", i, cxy, ptr, base); 484 528 } … … 489 533 cxy = GET_CXY( chdev_dir.ioc[i] ); 490 534 ptr = GET_PTR( chdev_dir.ioc[i] ); 491 base = (uint32_t)hal_remote_l wd( XPTR( cxy , &ptr->base ) );535 base = (uint32_t)hal_remote_l64( XPTR( cxy , &ptr->base ) ); 492 536 nolock_printk(" - ioc[%d] : cxy = %X / ptr = %X / base = %X\n", i, cxy, ptr, base); 493 537 } … … 498 542 cxy = GET_CXY( chdev_dir.fbf[i] ); 499 543 ptr = GET_PTR( chdev_dir.fbf[i] ); 500 base = (uint32_t)hal_remote_l wd( XPTR( cxy , &ptr->base ) );544 base = (uint32_t)hal_remote_l64( XPTR( cxy , &ptr->base ) ); 501 545 nolock_printk(" - fbf[%d] : cxy = %X / ptr = %X / base = %X\n", i, cxy, ptr, base); 502 546 } … … 507 551 cxy = GET_CXY( chdev_dir.nic_rx[i] ); 508 552 ptr = GET_PTR( chdev_dir.nic_rx[i] ); 509 base = (uint32_t)hal_remote_l wd( XPTR( cxy , &ptr->base ) );553 base = (uint32_t)hal_remote_l64( XPTR( cxy , &ptr->base ) ); 510 554 nolock_printk(" - nic_rx[%d] : cxy = %X / ptr = %X / base = %X\n", i, cxy, ptr, base); 511 555 512 556 cxy = GET_CXY( chdev_dir.nic_tx[i] ); 513 557 ptr = GET_PTR( chdev_dir.nic_tx[i] ); 514 base = (uint32_t)hal_remote_l wd( XPTR( cxy , &ptr->base ) );558 base = (uint32_t)hal_remote_l64( XPTR( cxy , &ptr->base ) ); 515 559 nolock_printk(" - nic_tx[%d] : cxy = %X / ptr = %X / base = %X\n", i, cxy, ptr, base); 516 560 } 517 561 518 562 // release lock 519 remote_ spinlock_unlock_busy( lock_xp , save_sr);563 remote_busylock_release( lock_xp ); 520 564 521 565 } // end chdev_dir_display() … … 546 590 hal_remote_strcpy( XPTR( local_cxy , name ), XPTR( chdev_cxy , chdev_ptr->name ) ); 547 591 592 // get pointers on TXT0 chdev 593 xptr_t txt0_xp = chdev_dir.txt_tx[0]; 594 cxy_t txt0_cxy = GET_CXY( txt0_xp ); 595 chdev_t * txt0_ptr = GET_PTR( txt0_xp ); 596 597 // get extended pointer on TXT0 lock 598 xptr_t lock_xp = XPTR( txt0_cxy , &txt0_ptr->wait_lock ); 599 600 // get TXT0 lock 601 remote_busylock_acquire( lock_xp ); 602 548 603 // check queue empty 549 604 if( xlist_is_empty( root_xp ) ) 550 605 { 551 printk("\n***** Waiting queue empty for chdev %s\n", name );606 nolock_printk("\n***** Waiting queue empty for chdev %s\n", name ); 552 607 } 553 608 else 554 609 { 555 printk("\n***** Waiting queue for chdev %s\n", name );610 nolock_printk("\n***** Waiting queue for chdev %s\n", name ); 556 611 557 612 // scan the waiting queue … … 561 616 thread_cxy = GET_CXY( thread_xp ); 562 617 thread_ptr = GET_PTR( thread_xp ); 563 trdid = hal_remote_l w( XPTR( thread_cxy , &thread_ptr->trdid ) );618 trdid = hal_remote_l32 ( XPTR( thread_cxy , &thread_ptr->trdid ) ); 564 619 process = hal_remote_lpt( XPTR( thread_cxy , &thread_ptr->process ) ); 565 pid = hal_remote_l w( XPTR( thread_cxy , &process->pid ) );566 567 printk("- thread %X / cluster %X / trdid %X / pid %X\n",620 pid = hal_remote_l32 ( XPTR( thread_cxy , &process->pid ) ); 621 622 nolock_printk("- thread %X / cluster %X / trdid %X / pid %X\n", 568 623 thread_ptr, thread_cxy, trdid, pid ); 569 624 } 570 625 } 626 627 // release TXT0 lock 628 remote_busylock_release( lock_xp ); 629 571 630 } // end chdev_queue_display() 572 631
Note: See TracChangeset
for help on using the changeset viewer.