Changeset 446 for trunk/hal/tsar_mips32/drivers
- Timestamp:
- Jun 19, 2018, 5:12:57 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/hal/tsar_mips32/drivers/soclib_tty.c
r440 r446 124 124 125 125 #if DEBUG_HAL_TXT_RX 126 uint32_t cycle = (uint32_t)hal_get_cycles();127 if( (DEBUG_HAL_TXT_RX < cycle) && (type == TXT_READ) )126 uint32_t rx_cycle = (uint32_t)hal_get_cycles(); 127 if( (DEBUG_HAL_TXT_RX < rx_cycle) && (type == TXT_READ) ) 128 128 printk("\n[DBG] %s : thread %x enter for RX / cycle %d\n", 129 __FUNCTION__ , CURRENT_THREAD , cycle );129 __FUNCTION__ , CURRENT_THREAD , rx_cycle ); 130 130 #endif 131 131 132 132 #if DEBUG_HAL_TXT_TX 133 uint32_t cycle = (uint32_t)hal_get_cycles();134 if( (DEBUG_HAL_TXT_TX < cycle) && (type == TXT_WRITE) )133 uint32_t tx_cycle = (uint32_t)hal_get_cycles(); 134 if( (DEBUG_HAL_TXT_TX < tx_cycle) && (type == TXT_WRITE) ) 135 135 printk("\n[DBG] %s : thread %x enter for TX / cycle %d\n", 136 __FUNCTION__ , CURRENT_THREAD , cycle );136 __FUNCTION__ , CURRENT_THREAD , tx_cycle ); 137 137 #endif 138 138 … … 224 224 225 225 // deschedule 226 sched_yield( "TTY_ TX_FIFO_RXempty" );226 sched_yield( "TTY_RX_FIFO empty" ); 227 227 } 228 228 } // end while … … 237 237 238 238 #if DEBUG_HAL_TXT_RX 239 cycle = (uint32_t)hal_get_cycles();240 if( (DEBUG_HAL_TXT_RX < cycle) && (type == TXT_READ) )239 rx_cycle = (uint32_t)hal_get_cycles(); 240 if( (DEBUG_HAL_TXT_RX < rx_cycle) && (type == TXT_READ) ) 241 241 printk("\n[DBG] %s : thread %x exit after RX / cycle %d\n", 242 __FUNCTION__ , CURRENT_THREAD , cycle );242 __FUNCTION__ , CURRENT_THREAD , rx_cycle ); 243 243 #endif 244 244 245 245 #if DEBUG_HAL_TXT_TX 246 cycle = (uint32_t)hal_get_cycles();247 if( (DEBUG_HAL_TXT_TX < cycle) && (type == TXT_WRITE) )246 tx_cycle = (uint32_t)hal_get_cycles(); 247 if( (DEBUG_HAL_TXT_TX < tx_cycle) && (type == TXT_WRITE) ) 248 248 printk("\n[DBG] %s : thread %x exit after TX / cycle %d\n", 249 __FUNCTION__ , CURRENT_THREAD , cycle );249 __FUNCTION__ , CURRENT_THREAD , tx_cycle ); 250 250 #endif 251 251 … … 263 263 void __attribute__ ((noinline)) soclib_tty_isr( chdev_t * chdev ) 264 264 { 265 thread_t * server; // pointer on TXT chdev server thread 266 lid_t server_lid; // local index of core running the server thread 267 uint32_t channel; // TXT chdev channel 268 bool_t is_rx; // TXT chdev direction 269 char byte; // byte value 270 xptr_t owner_xp; // extended pointer on foreground process in owner cluster 271 cxy_t owner_cxy; 272 process_t * owner_ptr; 273 pid_t owner_pid; 274 tty_fifo_t * fifo; // pointer on TTY_TX or TTY_RX FIFO 275 cxy_t tty_cxy; // soclib_tty cluster 276 uint32_t * tty_ptr; // soclib_tty segment base address 277 uint32_t * base; // soclib_tty channel base address 278 xptr_t status_xp; // extended pointer on TTY_STATUS register 279 xptr_t write_xp; // extended pointer on TTY_WRITE register 280 xptr_t read_xp; // extended pointer on TTY_READ register 265 thread_t * server; // pointer on TXT chdev server thread 266 lid_t server_lid; // local index of core running the server thread 267 uint32_t channel; // TXT chdev channel 268 bool_t is_rx; // TXT chdev direction 269 char byte; // byte value 270 xptr_t owner_xp; // extended pointer on TXT owner process 271 cxy_t owner_cxy; // TXT owner process cluster 272 process_t * owner_ptr; // local pointer on TXT owner process 273 pid_t owner_pid; // TXT owner process identifier 274 tty_fifo_t * fifo; // pointer on TTY_TX or TTY_RX FIFO 275 cxy_t tty_cxy; // soclib_tty cluster 276 uint32_t * tty_ptr; // soclib_tty segment base address 277 uint32_t * base; // soclib_tty channel base address 278 xptr_t status_xp; // extended pointer on TTY_STATUS register 279 xptr_t write_xp; // extended pointer on TTY_WRITE register 280 xptr_t read_xp; // extended pointer on TTY_READ register 281 xptr_t parent_xp; // extended pointer on parent process 282 cxy_t parent_cxy; // parent process cluster 283 process_t * parent_ptr; // local pointer on parent process 284 xptr_t children_lock_xp; // extended pointer on children processes lock 285 thread_t * parent_main_ptr; // extended pointer on parent process main thread 286 xptr_t parent_main_xp; // local pointer on parent process main thread 281 287 282 288 // get TXT chdev channel, direction and server thread … … 295 301 296 302 #if DEBUG_HAL_TXT_RX 297 uint32_t cycle = (uint32_t)hal_get_cycles(); 298 if( (DEBUG_HAL_TXT_RX < cycle) && is_rx ) 299 printk("\n[DBG] %s : enter for RX / cycle %d\n", __FUNCTION__ , cycle ); 303 uint32_t rx_cycle = (uint32_t)hal_get_cycles(); 300 304 #endif 301 305 302 306 #if DEBUG_HAL_TXT_TX 303 uint32_t cycle = (uint32_t)hal_get_cycles(); 304 if( (DEBUG_HAL_TXT_TX < cycle) && (is_rx == 0) ) 305 printk("\n[DBG] %s : enter for TX / cycle %d\n", __FUNCTION__ , cycle ); 307 uint32_t tx_cycle = (uint32_t)hal_get_cycles(); 306 308 #endif 307 309 … … 329 331 byte = (char)hal_remote_lb( read_xp ); 330 332 331 // filter special character ^Z 333 // filter special character ^Z => block TXT owner process 332 334 if( byte == 0x1A ) 333 335 { 336 337 #if DEBUG_HAL_TXT_RX 338 if( DEBUG_HAL_TXT_RX < rx_cycle ) 339 printk("\n[DBG] %s : read ^Z character from TXT%d\n", __FUNCTION__, channel ); 340 #endif 334 341 // get pointers on TXT owner process in owner cluster 335 342 owner_xp = process_txt_get_owner( channel ); … … 339 346 "TXT owner process not found\n" ); 340 347 341 // get relevant infos on owner process342 owner_cxy = GET_CXY( owner_xp );343 owner_ptr = GET_PTR( owner_xp );344 owner_pid = hal_remote_lw( XPTR( owner_cxy , &owner_ptr->pid ) );345 346 // block owner process only if it is not INIT or KSH347 if( process_get_ppid( owner_xp ) > 1 )348 {349 // send stop signal to owner process350 process_sigaction( owner_pid , BLOCK_ALL_THREADS );351 352 // atomically update owner process termination state353 hal_remote_atomic_or( XPTR( owner_cxy , &owner_ptr->term_state ) ,354 PROCESS_TERM_STOP );355 return;356 }357 }358 359 // filter special character ^C360 if( byte == 0x03 )361 {362 // get pointer on TXT owner process in owner cluster363 owner_xp = process_txt_get_owner( channel );364 365 // check process exist366 assert( (owner_xp != XPTR_NULL) , __FUNCTION__,367 "TXT owner process not found\n" );368 369 348 // get relevant infos on TXT owner process 370 349 owner_cxy = GET_CXY( owner_xp ); … … 372 351 owner_pid = hal_remote_lw( XPTR( owner_cxy , &owner_ptr->pid ) ); 373 352 374 // kill TXT owner process only if it is not INIT353 // block TXT owner process only if it is not the INIT process 375 354 if( owner_pid != 1 ) 376 355 { 356 // get parent process descriptor pointers 357 parent_xp = hal_remote_lwd( XPTR( owner_cxy , &owner_ptr->parent_xp ) ); 358 parent_cxy = GET_CXY( parent_xp ); 359 parent_ptr = GET_PTR( parent_xp ); 360 361 // get extended pointer on lock protecting children list in parent process 362 children_lock_xp = XPTR( parent_cxy , &parent_ptr->children_lock ); 363 364 // get pointers on the parent process main thread 365 parent_main_ptr = hal_remote_lpt(XPTR(parent_cxy,&parent_ptr->th_tbl[0])); 366 parent_main_xp = XPTR( parent_cxy , parent_main_ptr ); 367 368 // transfer TXT ownership 369 process_txt_transfer_ownership( owner_xp ); 370 371 // block all threads in all clusters, but the main thread 372 process_sigaction( owner_pid , BLOCK_ALL_THREADS ); 373 374 // block the main thread 375 xptr_t main_xp = XPTR( owner_cxy , &owner_ptr->th_tbl[0] ); 376 thread_block( main_xp , THREAD_BLOCKED_GLOBAL ); 377 378 // atomically update owner process termination state 379 hal_remote_atomic_or( XPTR( owner_cxy , &owner_ptr->term_state ) , 380 PROCESS_TERM_STOP ); 381 382 // take the children lock and unblock the parent process main thread 383 remote_spinlock_lock( children_lock_xp ); 384 thread_unblock( parent_main_xp , THREAD_BLOCKED_WAIT ); 385 remote_spinlock_unlock( children_lock_xp ); 386 387 return; 388 } 389 } 390 391 // filter special character ^C => kill TXT owner process 392 if( byte == 0x03 ) 393 { 394 395 #if DEBUG_HAL_TXT_RX 396 if( DEBUG_HAL_TXT_RX < rx_cycle ) 397 printk("\n[DBG] %s : read ^C character from TXT%d\n", __FUNCTION__, channel ); 398 #endif 399 // get pointer on TXT owner process in owner cluster 400 owner_xp = process_txt_get_owner( channel ); 401 402 // check process exist 403 assert( (owner_xp != XPTR_NULL) , __FUNCTION__, 404 "TXT owner process not found\n" ); 405 406 // get relevant infos on TXT owner process 407 owner_cxy = GET_CXY( owner_xp ); 408 owner_ptr = GET_PTR( owner_xp ); 409 owner_pid = hal_remote_lw( XPTR( owner_cxy , &owner_ptr->pid ) ); 410 411 // kill TXT owner process only if it is not the INIT process 412 if( owner_pid != 1 ) 413 { 414 // get parent process descriptor pointers 415 parent_xp = hal_remote_lwd( XPTR( owner_cxy , &owner_ptr->parent_xp ) ); 416 parent_cxy = GET_CXY( parent_xp ); 417 parent_ptr = GET_PTR( parent_xp ); 418 419 // get extended pointer on lock protecting children list in parent process 420 children_lock_xp = XPTR( parent_cxy , &parent_ptr->children_lock ); 421 422 // get pointers on the parent process main thread 423 parent_main_ptr = hal_remote_lpt(XPTR(parent_cxy,&parent_ptr->th_tbl[0])); 424 parent_main_xp = XPTR( parent_cxy , parent_main_ptr ); 425 377 426 // remove process from TXT list 378 427 process_txt_detach( owner_xp ); … … 381 430 process_sigaction( owner_pid , DELETE_ALL_THREADS ); 382 431 383 // get pointer on target processmain thread432 // block main thread 384 433 xptr_t main_xp = XPTR( owner_cxy , &owner_ptr->th_tbl[0] ); 385 386 // block main thread387 434 thread_block( main_xp , THREAD_BLOCKED_GLOBAL ); 388 435 … … 390 437 hal_remote_atomic_or( XPTR( owner_cxy , &owner_ptr->term_state ) , 391 438 PROCESS_TERM_KILL ); 439 440 // take the children lock and unblock the parent process main thread 441 remote_spinlock_lock( children_lock_xp ); 442 thread_unblock( parent_main_xp , THREAD_BLOCKED_WAIT ); 443 remote_spinlock_unlock( children_lock_xp ); 444 392 445 return; 393 446 } … … 397 450 if ( fifo->sts < TTY_FIFO_DEPTH ) 398 451 { 452 453 #if DEBUG_HAL_TXT_RX 454 if( DEBUG_HAL_TXT_RX < rx_cycle ) 455 printk("\n[DBG] %s : read character %c from TXT%d\n", __FUNCTION__, byte, channel ); 456 #endif 399 457 // store byte into FIFO 400 458 fifo->data[fifo->ptw] = (char)byte; … … 430 488 while( fifo->sts > 0 ) 431 489 { 432 // write one byte to TTY_WRITE register if empty / exit whileif full490 // write one byte to TTY_WRITE register if empty / exit loop if full 433 491 if( (hal_remote_lw( status_xp ) & TTY_STATUS_TX_FULL) == 0 ) 434 492 { … … 436 494 byte = fifo->data[fifo->ptr]; 437 495 496 #if DEBUG_HAL_TXT_TX 497 if( DEBUG_HAL_TXT_TX < tx_cycle ) 498 printk("\n[DBG] %s : write character %c to TXT%d\n", __FUNCTION__, byte, channel ); 499 #endif 438 500 // update TX_FIFO state 439 501 fifo->ptr = (fifo->ptr + 1) % TTY_FIFO_DEPTH; … … 453 515 // send IPI to core running server thread 454 516 dev_pic_send_ipi( local_cxy , server_lid ); 517 455 518 } // end TX 456 519 457 520 hal_fence(); 458 459 #if DEBUG_HAL_TXT_RX460 cycle = (uint32_t)hal_get_cycles();461 if( (DEBUG_HAL_TXT_RX < cycle) && is_rx )462 printk("\n[DBG] %s : exit after RX / cycle %d\n", __FUNCTION__, cycle );463 #endif464 465 #if DEBUG_HAL_TXT_TX466 cycle = (uint32_t)hal_get_cycles();467 if( (DEBUG_HAL_TXT_TX < cycle) && (is_rx == 0) )468 printk("\n[DBG] %s : exit after TX / cycle %d\n", __FUNCTION__, cycle );469 #endif470 521 471 522 #if (DEBUG_SYS_READ & 1)
Note: See TracChangeset
for help on using the changeset viewer.