- Timestamp:
- Jun 19, 2018, 5:12:57 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 17 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) -
trunk/kernel/kern/chdev.c
r440 r446 198 198 hal_disable_irq( &save_sr ); 199 199 200 // take the lock 200 // take the lock protecting chdev waiting queue 201 201 remote_spinlock_lock( lock_xp ); 202 202 … … 204 204 thread_block( XPTR( local_cxy , CURRENT_THREAD ) , THREAD_BLOCKED_IO ); 205 205 206 // unblock server thread if required 206 207 if( hal_remote_lw( blocked_xp ) & THREAD_BLOCKED_IDLE ) 207 208 thread_unblock( server_xp , THREAD_BLOCKED_IDLE ); -
trunk/kernel/kern/printk.c
r445 r446 28 28 #include <remote_spinlock.h> 29 29 #include <cluster.h> 30 #include <thread.h> 30 31 #include <chdev.h> 31 32 #include <printk.h> … … 399 400 chdev_t * txt0_ptr = GET_PTR( txt0_xp ); 400 401 401 // get extended pointer on remote TXT0 chdevlock402 // get extended pointer on remote TXT0 lock 402 403 xptr_t lock_xp = XPTR( txt0_cxy , &txt0_ptr->wait_lock ); 403 404 … … 406 407 407 408 // call nolock_printk to print function_name 408 nolock_printk("\n[PANIC] in %s : " , function_name ); 409 nolock_printk("\n[PANIC] on core[%x,%d] in %s : " , 410 local_cxy , CURRENT_THREAD->core->lid , function_name ); 409 411 410 412 // call kernel_printf on TXT0, in busy waiting to print format … … 417 419 418 420 // suicide 419 sys_exit( EXIT_FAILURE);421 while( 1 ) asm volatile ("nop"); 420 422 } 421 423 } -
trunk/kernel/kern/process.c
r445 r446 392 392 cxy_t parent_cxy; 393 393 xptr_t children_lock_xp; 394 xptr_t children_nr_xp; 394 395 395 396 pid_t pid = process->pid; … … 421 422 // get extended pointer on children_lock in parent process 422 423 children_lock_xp = XPTR( parent_cxy , &parent_ptr->children_lock ); 424 children_nr_xp = XPTR( parent_cxy , &parent_ptr->children_nr ); 423 425 424 426 // remove process from children_list 425 427 remote_spinlock_lock( children_lock_xp ); 426 428 xlist_unlink( XPTR( local_cxy , &process->children_list ) ); 429 hal_remote_atomic_add( children_nr_xp , -1 ); 427 430 remote_spinlock_unlock( children_lock_xp ); 428 431 } … … 1237 1240 thread_t * new_thread; // local pointer on new thread 1238 1241 xptr_t parent_xp; // extended pointer on parent process 1242 process_t * parent_ptr; // local pointer on parent process 1243 cxy_t parent_cxy; // parent process cluster identifier 1244 xptr_t children_lock_xp; // extended pointer on children lock in parent 1245 xptr_t children_root_xp; // extended pointer on children root in parent 1246 xptr_t children_nr_xp; // extended pointer on children number in parent 1247 thread_t * parent_main_ptr; // local pointer on parent main thread 1248 xptr_t parent_main_xp; // extended pointer on parent main thread 1239 1249 pthread_attr_t attr; // new thread attributes 1240 1250 lid_t lid; // selected core local index 1241 1251 error_t error; // value returned by called functions 1242 1252 1243 // get old_thread / old_process / PID / parent_xp1253 // get old_thread, old_process & PID 1244 1254 old_thread = CURRENT_THREAD; 1245 1255 old_process = old_thread->process; 1246 1256 pid = old_process->pid; 1247 parent_xp = old_process->parent_xp; 1248 1257 1249 1258 // get .elf pathname from exec_info 1250 path 1259 path = exec_info->path; 1251 1260 1252 1261 // this function must be executed by a thread running in owner cluster … … 1260 1269 uint32_t cycle = (uint32_t)hal_get_cycles(); 1261 1270 if( DEBUG_PROCESS_MAKE_EXEC < cycle ) 1262 printk("\n[DBG] %s : thread %x enters for process %x / %s / cycle %d\n", 1263 __FUNCTION__, old_thread, pid, path, cycle ); 1264 #endif 1271 printk("\n[DBG] %s : thread %x in process %x enters / path %s / cycle %d\n", 1272 __FUNCTION__, old_thread->trdid, pid, path, cycle ); 1273 #endif 1274 1275 // get parent process pointers 1276 parent_xp = old_process->parent_xp; 1277 parent_cxy = GET_CXY( parent_xp ); 1278 parent_ptr = GET_PTR( parent_xp ); 1279 1280 #if (DEBUG_PROCESS_MAKE_EXEC & 1) 1281 if( DEBUG_PROCESS_MAKE_EXEC < cycle ) 1282 printk("\n[DBG] %s : thread %x in process %x get parent process %x in cluster %x\n", 1283 __FUNCTION__, old_thread->trdid, pid, parent_ptr, parent_cxy ); 1284 #endif 1285 1286 // get extended pointers on parent children_root, children_lock and children_nr 1287 children_root_xp = XPTR( parent_cxy , &parent_ptr->children_root ); 1288 children_lock_xp = XPTR( parent_cxy , &parent_ptr->children_lock ); 1289 children_nr_xp = XPTR( parent_cxy , &parent_ptr->children_nr ); 1290 1291 // get pointers on the parent process main thread 1292 parent_main_ptr = hal_remote_lpt( XPTR( parent_cxy , &parent_ptr->th_tbl[0] ) ); 1293 parent_main_xp = XPTR( parent_cxy , parent_main_ptr ); 1265 1294 1266 1295 // allocate memory for new_process descriptor … … 1298 1327 cycle = (uint32_t)hal_get_cycles(); 1299 1328 if( DEBUG_PROCESS_MAKE_EXEC < cycle ) 1300 printk("\n[DBG] %s : thread %x created new process %x / cycle %d\n",1301 __FUNCTION__ , old_thread , new_process , cycle);1329 printk("\n[DBG] %s : thread %x in process %x created new process %x\n", 1330 __FUNCTION__ , old_thread->trdid, pid, new_process ); 1302 1331 #endif 1303 1332 … … 1358 1387 #endif 1359 1388 1360 // get cluster and local pointer on parent process1361 process_t * parent_ptr = GET_PTR( parent_xp );1362 cxy_t parent_cxy = GET_CXY( parent_xp );1363 1364 // get extended pointers on parent children_root, children_lock and children_nr1365 xptr_t root_xp = XPTR( parent_cxy , &parent_ptr->children_root );1366 xptr_t lock_xp = XPTR( parent_cxy , &parent_ptr->children_lock );1367 xptr_t nr_xp = XPTR( parent_cxy , &parent_ptr->children_nr );1368 1369 1389 // register new_process in parent children list 1370 remote_spinlock_lock( lock_xp );1371 xlist_add_last( root_xp , XPTR( local_cxy , &new_process->children_list ) );1372 hal_remote_atomic_add( nr_xp , 1 );1373 remote_spinlock_unlock( lock_xp );1390 remote_spinlock_lock( children_lock_xp ); 1391 xlist_add_last( children_root_xp , XPTR( local_cxy , &new_process->children_list ) ); 1392 hal_remote_atomic_add( children_nr_xp , 1 ); 1393 remote_spinlock_unlock( children_lock_xp ); 1374 1394 1375 1395 // activate new thread … … 1379 1399 process_txt_detach( XPTR( local_cxy , old_process ) ); 1380 1400 1381 // block thisold_thread1401 // block old_thread 1382 1402 thread_block( XPTR( local_cxy , old_thread ) , THREAD_BLOCKED_GLOBAL ); 1383 1403 1384 // atomically update old_process descriptor term_state to ask 1385 // the parent process (wait() function) to delete this old_thread 1404 // atomically update old_process termination state 1386 1405 hal_atomic_or( &old_process->term_state , PROCESS_TERM_EXIT ); 1406 1407 // take the children lock and unblock the parent process main thread 1408 remote_spinlock_lock( children_lock_xp ); 1409 thread_unblock( parent_main_xp , THREAD_BLOCKED_WAIT ); 1410 remote_spinlock_unlock( children_lock_xp ); 1387 1411 1388 1412 hal_fence(); … … 1621 1645 if( txt_owner_xp == process_xp ) 1622 1646 { 1623 nolock_printk("PID %X | PPID %X | STS %X | %s (FG) | %X | %d | %s\n",1647 nolock_printk("PID %X | PPID %X | TS %X | %s (FG) | %X | %d | %s\n", 1624 1648 pid, ppid, state, txt_name, process_ptr, th_nr, elf_name ); 1625 1649 } 1626 1650 else 1627 1651 { 1628 nolock_printk("PID %X | PPID %X | STS %X | %s (BG) | %X | %d | %s\n",1652 nolock_printk("PID %X | PPID %X | TS %X | %s (BG) | %X | %d | %s\n", 1629 1653 pid, ppid, state, txt_name, process_ptr, th_nr, elf_name ); 1630 1654 } … … 1676 1700 xptr_t lock_xp; // extended pointer on list lock in chdev 1677 1701 1678 #if DEBUG_PROCESS_TXT _ATTACH1702 #if DEBUG_PROCESS_TXT 1679 1703 uint32_t cycle = (uint32_t)hal_get_cycles(); 1680 if( DEBUG_PROCESS_TXT _ATTACH< cycle )1704 if( DEBUG_PROCESS_TXT < cycle ) 1681 1705 printk("\n[DBG] %s : thread %x enter for process %x / txt_id = %d / cycle %d\n", 1682 1706 __FUNCTION__, CURRENT_THREAD, process->pid, txt_id, cycle ); … … 1705 1729 remote_spinlock_unlock( lock_xp ); 1706 1730 1707 #if DEBUG_PROCESS_TXT _ATTACH1708 cycle = (uint32_t)hal_get_cycles(); 1709 if( DEBUG_PROCESS_TXT _ATTACH< cycle )1731 #if DEBUG_PROCESS_TXT 1732 cycle = (uint32_t)hal_get_cycles(); 1733 if( DEBUG_PROCESS_TXT < cycle ) 1710 1734 printk("\n[DBG] %s : thread %x exit for process %x / txt_id = %d / cycle %d\n", 1711 1735 __FUNCTION__, CURRENT_THREAD, process->pid, txt_id , cycle ); … … 1735 1759 "process descriptor not in owner cluster" ); 1736 1760 1737 #if DEBUG_PROCESS_TXT _ATTACH1761 #if DEBUG_PROCESS_TXT 1738 1762 uint32_t cycle = (uint32_t)hal_get_cycles(); 1739 if( DEBUG_PROCESS_TXT _ATTACH< cycle )1763 if( DEBUG_PROCESS_TXT < cycle ) 1740 1764 printk("\n[DBG] %s : thread %x enter for process %x / cycle %d\n", 1741 1765 __FUNCTION__, CURRENT_THREAD, process_pid, cycle ); … … 1761 1785 remote_spinlock_unlock( lock_xp ); 1762 1786 1763 #if DEBUG_PROCESS_TXT _ATTACH1787 #if DEBUG_PROCESS_TXT 1764 1788 cycle = (uint32_t)hal_get_cycles(); 1765 1789 uint32_t txt_id = hal_remote_lw( XPTR( chdev_cxy , &chdev_ptr->channel ) ); 1766 if( DEBUG_PROCESS_TXT _ATTACH< cycle )1790 if( DEBUG_PROCESS_TXT < cycle ) 1767 1791 printk("\n[DBG] %s : thread %x exit / process %x detached from TXT %d / cycle %d\n", 1768 1792 __FUNCTION__, CURRENT_THREAD, process_pid, txt_id, cycle ); … … 1793 1817 "process descriptor not in owner cluster\n" ); 1794 1818 1795 #if DEBUG_PROCESS_TXT _ATTACH1819 #if DEBUG_PROCESS_TXT 1796 1820 uint32_t cycle = (uint32_t)hal_get_cycles(); 1797 if( DEBUG_PROCESS_TXT _ATTACH< cycle )1821 if( DEBUG_PROCESS_TXT < cycle ) 1798 1822 printk("\n[DBG] %s : thread %x enter for process %x / cycle %d\n", 1799 1823 __FUNCTION__, CURRENT_THREAD, process_pid, cycle ); … … 1811 1835 hal_remote_swd( XPTR( txt_cxy , &txt_ptr->ext.txt.owner_xp ) , process_xp ); 1812 1836 1813 #if DEBUG_PROCESS_TXT _ATTACH1814 cycle = (uint32_t)hal_get_cycles(); 1815 if( DEBUG_PROCESS_TXT _ATTACH< cycle )1837 #if DEBUG_PROCESS_TXT 1838 cycle = (uint32_t)hal_get_cycles(); 1839 if( DEBUG_PROCESS_TXT < cycle ) 1816 1840 printk("\n[DBG] %s : thread %x exit for process %x / cycle %d\n", 1817 1841 __FUNCTION__, CURRENT_THREAD, process_pid, cycle ); … … 1850 1874 "process descriptor not in owner cluster\n" ); 1851 1875 1852 #if DEBUG_PROCESS_TXT _ATTACH1876 #if DEBUG_PROCESS_TXT 1853 1877 uint32_t cycle = (uint32_t)hal_get_cycles(); 1854 if( DEBUG_PROCESS_TXT _ATTACH< cycle )1878 if( DEBUG_PROCESS_TXT < cycle ) 1855 1879 printk("\n[DBG] %s : thread %x enter / process %x / cycle %d\n", 1856 1880 __FUNCTION__, CURRENT_THREAD, process_pid, cycle ); … … 1869 1893 txt_id = hal_remote_lw ( XPTR( txt_cxy , &txt_ptr->channel ) ); 1870 1894 1871 #if( DEBUG_PROCESS_TXT _ATTACH& 1 )1872 if( DEBUG_PROCESS_TXT _ATTACH< cycle )1895 #if( DEBUG_PROCESS_TXT & 1 ) 1896 if( DEBUG_PROCESS_TXT < cycle ) 1873 1897 printk("\n[DBG] %s : file_ptr %x / txt_ptr %x / txt_id %d / owner_ptr = %x\n", 1874 1898 __FUNCTION__, GET_PTR(file_xp), txt_ptr, txt_id, GET_PTR(owner_xp) ); … … 1888 1912 { 1889 1913 1890 #if( DEBUG_PROCESS_TXT _ATTACH& 1 )1891 if( DEBUG_PROCESS_TXT _ATTACH< cycle )1914 #if( DEBUG_PROCESS_TXT & 1 ) 1915 if( DEBUG_PROCESS_TXT < cycle ) 1892 1916 printk("\n[DBG] %s : process is not the KSH process => search the KSH\n", __FUNCTION__ ); 1893 1917 #endif … … 1907 1931 hal_remote_swd( XPTR( txt_cxy , &txt_ptr->ext.txt.owner_xp ) , current_xp ); 1908 1932 1909 #if DEBUG_PROCESS_TXT _ATTACH1910 cycle = (uint32_t)hal_get_cycles(); 1911 if( DEBUG_PROCESS_TXT _ATTACH< cycle )1933 #if DEBUG_PROCESS_TXT 1934 cycle = (uint32_t)hal_get_cycles(); 1935 if( DEBUG_PROCESS_TXT < cycle ) 1912 1936 printk("\n[DBG] %s : thread %x exit / process %x to KSH process %x / cycle %d\n", 1913 1937 __FUNCTION__, CURRENT_THREAD, process_pid, … … 1929 1953 { 1930 1954 1931 #if( DEBUG_PROCESS_TXT _ATTACH& 1 )1932 if( DEBUG_PROCESS_TXT _ATTACH< cycle )1955 #if( DEBUG_PROCESS_TXT & 1 ) 1956 if( DEBUG_PROCESS_TXT < cycle ) 1933 1957 printk("\n[DBG] %s : process is the KSH process => search another\n", __FUNCTION__ ); 1934 1958 #endif … … 1949 1973 hal_remote_swd( XPTR( txt_cxy , &txt_ptr->ext.txt.owner_xp ) , current_xp ); 1950 1974 1951 #if DEBUG_PROCESS_TXT _ATTACH1952 cycle = (uint32_t)hal_get_cycles(); 1953 if( DEBUG_PROCESS_TXT _ATTACH< cycle )1975 #if DEBUG_PROCESS_TXT 1976 cycle = (uint32_t)hal_get_cycles(); 1977 if( DEBUG_PROCESS_TXT < cycle ) 1954 1978 printk("\n[DBG] %s : thread %x exit / KSH process %x to process %x / cycle %d\n", 1955 1979 __FUNCTION__, CURRENT_THREAD, process_pid, … … 1966 1990 hal_remote_swd( XPTR( txt_cxy , &txt_ptr->ext.txt.owner_xp ) , XPTR_NULL ); 1967 1991 1968 #if DEBUG_PROCESS_TXT _ATTACH1969 cycle = (uint32_t)hal_get_cycles(); 1970 if( DEBUG_PROCESS_TXT _ATTACH< cycle )1992 #if DEBUG_PROCESS_TXT 1993 cycle = (uint32_t)hal_get_cycles(); 1994 if( DEBUG_PROCESS_TXT < cycle ) 1971 1995 printk("\n[DBG] %s : thread %x exit / KSH process %x to nobody / cycle %d\n", 1972 1996 __FUNCTION__, CURRENT_THREAD, process_pid, cycle ); … … 1978 2002 { 1979 2003 1980 #if DEBUG_PROCESS_TXT _ATTACH1981 cycle = (uint32_t)hal_get_cycles(); 1982 if( DEBUG_PROCESS_TXT _ATTACH< cycle )2004 #if DEBUG_PROCESS_TXT 2005 cycle = (uint32_t)hal_get_cycles(); 2006 if( DEBUG_PROCESS_TXT < cycle ) 1983 2007 printk("\n[DBG] %s : thread %x exit / process %x is not TXT owner / cycle %d\n", 1984 2008 __FUNCTION__, CURRENT_THREAD, process_pid, cycle ); -
trunk/kernel/kern/process.h
r445 r446 405 405 struct thread_s ** child_thread_ptr ); 406 406 407 407 408 /******************** File Management Operations ****************************************/ 408 409 … … 535 536 /********************************************************************************************* 536 537 * This function detach a process, identified by the <process_xp> argument, 537 * from the list of process attached to a given TXT terminal. It transfer the TXT ownership ,538 * if the detached process is the TXT owner.539 * The target process descriptor must be in the owner cluster, but the calling thread can540 * be running in any cluster.538 * from the list of process attached to a given TXT terminal. It transfer the TXT ownership 539 * to another process, if the detached process is the TXT owner. 540 * The process descriptor identified by the <process_xp> argument must be in the owner 541 * cluster, but the calling thread can be running in any cluster. 541 542 ********************************************************************************************* 542 543 * @ process_xp : extended pointer on process descriptor. -
trunk/kernel/kern/thread.c
r443 r446 42 42 #include <ppm.h> 43 43 #include <thread.h> 44 #include <rpc.h> 44 45 45 46 ////////////////////////////////////////////////////////////////////////////////////// … … 799 800 uint32_t cycle = (uint32_t)hal_get_cycles(); 800 801 if( DEBUG_THREAD_BLOCK < cycle ) 801 printk("\n[ DBG] %s : thread %x blocked thread%x / cause %x / cycle %d\n",802 __FUNCTION__ , CURRENT_THREAD , ptr, cause , cycle );802 printk("\n[@@@] %s : thread %x in cxy %x blocked thread %x in cxy %x / cause %x / cycle %d\n", 803 __FUNCTION__ , CURRENT_THREAD , local_cxy , ptr , cxy , cause , cycle ); 803 804 #endif 804 805 805 806 #if (DEBUG_THREAD_BLOCK & 1) 806 807 if( DEBUG_THREAD_BLOCK < cycle ) 807 sched_display( ptr->core->lid ); 808 { 809 if( cxy == local_cxy) 810 { 811 sched_display( ptr->core->lid ); 812 } 813 else 814 { 815 core_t * core = hal_remote_lpt( XPTR( cxy , &ptr->core ) ); 816 lid_t lid = hal_remote_lw ( XPTR( cxy , &core->lid ) ); 817 rpc_sched_display_client( cxy , lid ); 818 } 819 } 808 820 #endif 809 821 … … 825 837 uint32_t cycle = (uint32_t)hal_get_cycles(); 826 838 if( DEBUG_THREAD_BLOCK < cycle ) 827 printk("\n[ DBG] %s : thread %x unblocked thread%x / cause %x / cycle %d\n",828 __FUNCTION__ , CURRENT_THREAD , ptr, cause , cycle );839 printk("\n[@@@] %s : thread %x in cxy %x unblocked thread %x in cxy %x / cause %x / cycle %d\n", 840 __FUNCTION__ , CURRENT_THREAD , local_cxy , ptr , cxy , cause , cycle ); 829 841 #endif 830 842 831 843 #if (DEBUG_THREAD_BLOCK & 1) 832 844 if( DEBUG_THREAD_BLOCK < cycle ) 833 sched_display( ptr->core->lid ); 845 { 846 if( cxy == local_cxy) 847 { 848 sched_display( ptr->core->lid ); 849 } 850 else 851 { 852 core_t * core = hal_remote_lpt( XPTR( cxy , &ptr->core ) ); 853 lid_t lid = hal_remote_lw ( XPTR( cxy , &core->lid ) ); 854 rpc_sched_display_client( cxy , lid ); 855 } 856 } 834 857 #endif 835 858 … … 838 861 839 862 } // end thread_unblock() 840 841 /*842 843 ////////////////////////////////////844 void thread_kill( xptr_t target_xp,845 bool_t is_exit,846 bool_t is_forced )847 {848 reg_t save_sr; // for critical section849 bool_t attached; // target thread in attached mode850 bool_t join_done; // joining thread arrived first851 xptr_t killer_xp; // extended pointer on killer thread (this)852 thread_t * killer_ptr; // pointer on killer thread (this)853 cxy_t target_cxy; // target thread cluster854 thread_t * target_ptr; // pointer on target thread855 xptr_t joining_xp; // extended pointer on joining thread856 thread_t * joining_ptr; // pointer on joining thread857 cxy_t joining_cxy; // joining thread cluster858 pid_t target_pid; // target process PID859 cxy_t owner_cxy; // target process owner cluster860 trdid_t target_trdid; // target thread identifier861 ltid_t target_ltid; // target thread local index862 xptr_t process_state_xp; // extended pointer on <term_state> in process863 864 xptr_t target_flags_xp; // extended pointer on target thread <flags>865 xptr_t target_join_lock_xp; // extended pointer on target thread <join_lock>866 xptr_t target_join_xp_xp; // extended pointer on target thread <join_xp>867 xptr_t target_process_xp; // extended pointer on target thread <process>868 869 process_t * target_process; // pointer on target thread process870 871 // get target thread pointer and cluster872 target_cxy = GET_CXY( target_xp );873 target_ptr = GET_PTR( target_xp );874 875 // get killer thread pointers876 killer_ptr = CURRENT_THREAD;877 killer_xp = XPTR( local_cxy , killer_ptr );878 879 #if DEBUG_THREAD_DELETE880 uint32_t cycle = (uint32_t)hal_get_cycles;881 if( DEBUG_THREAD_DELETE < cycle )882 printk("\n[DBG] %s : thread %x enter for target thread %x / cycle %d\n",883 __FUNCTION__, killer_ptr, target_ptr, cycle );884 #endif885 886 // block the target thread887 thread_block( target_xp , THREAD_BLOCKED_GLOBAL );888 889 // get target thread attached mode890 target_flags_xp = XPTR( target_cxy , &target_ptr->flags );891 attached = ((hal_remote_lw( target_flags_xp ) & THREAD_FLAG_DETACHED) == 0);892 893 // synchronize with the joining thread894 // if the target thread is attached && not forced895 896 if( attached && (is_forced == false) )897 {898 // build extended pointers on target thread join fields899 target_join_lock_xp = XPTR( target_cxy , &target_ptr->join_lock );900 target_join_xp_xp = XPTR( target_cxy , &target_ptr->join_xp );901 902 // enter critical section903 hal_disable_irq( &save_sr );904 905 // take the join_lock in target thread descriptor906 remote_spinlock_lock( target_join_lock_xp );907 908 // get join_done from target thread descriptor909 join_done = ((hal_remote_lw( target_flags_xp ) & THREAD_FLAG_JOIN_DONE) != 0);910 911 if( join_done ) // joining thread arrived first912 {913 // get extended pointer on joining thread914 joining_xp = (xptr_t)hal_remote_lwd( target_join_xp_xp );915 joining_ptr = GET_PTR( joining_xp );916 joining_cxy = GET_CXY( joining_xp );917 918 // reset the join_done flag in target thread919 hal_remote_atomic_and( target_flags_xp , ~THREAD_FLAG_JOIN_DONE );920 921 // unblock the joining thread922 thread_unblock( joining_xp , THREAD_BLOCKED_JOIN );923 924 // release the join_lock in target thread descriptor925 remote_spinlock_unlock( target_join_lock_xp );926 927 // restore IRQs928 hal_restore_irq( save_sr );929 }930 else // this thread arrived first931 {932 // set the kill_done flag in target thread933 hal_remote_atomic_or( target_flags_xp , THREAD_FLAG_KILL_DONE );934 935 // block this thread on BLOCKED_JOIN936 thread_block( killer_xp , THREAD_BLOCKED_JOIN );937 938 // set extended pointer on killer thread in target thread939 hal_remote_swd( target_join_xp_xp , killer_xp );940 941 // release the join_lock in target thread descriptor942 remote_spinlock_unlock( target_join_lock_xp );943 944 // deschedule945 sched_yield( "killer thread wait joining thread" );946 947 // restore IRQs948 hal_restore_irq( save_sr );949 }950 } // end if attached951 952 // - if the target thread is the main thread953 // => synchronize with the parent process main thread954 // - if the target thread is not the main thread955 // => simply mark the target thread for delete956 957 // get pointer on target thread process958 target_process_xp = XPTR( target_cxy , &target_ptr->process );959 target_process = (process_t *)hal_remote_lpt( target_process_xp );960 961 // get target process owner cluster962 target_pid = hal_remote_lw( XPTR( target_cxy , &target_process->pid ) );963 owner_cxy = CXY_FROM_PID( target_pid );964 965 // get target thread local index966 target_trdid = hal_remote_lw( XPTR( target_cxy , &target_ptr->trdid ) );967 target_ltid = LTID_FROM_TRDID( target_trdid );968 969 if( (owner_cxy == target_cxy) && (target_ltid == 0) ) // main thread970 {971 // get extended pointer on term_state in target process owner cluster972 process_state_xp = XPTR( owner_cxy , &target_process->term_state );973 974 // set termination info in target process owner975 if( is_exit ) hal_remote_atomic_or( process_state_xp , PROCESS_TERM_EXIT );976 else hal_remote_atomic_or( process_state_xp , PROCESS_TERM_KILL );977 978 #if DEBUG_THREAD_DELETE979 cycle = (uint32_t)hal_get_cycles;980 if( DEBUG_THREAD_DELETE < cycle )981 printk("\n[DBG] %s : thread %x exit for thread %x / main thread / cycle %d\n",982 __FUNCTION__, killer_ptr, target_ptr, cycle );983 #endif984 985 }986 else // main thread987 {988 // set the REQ_DELETE flag in target thread descriptor989 hal_remote_atomic_or( target_flags_xp , THREAD_FLAG_REQ_DELETE );990 991 #if DEBUG_THREAD_DELETE992 cycle = (uint32_t)hal_get_cycles;993 if( DEBUG_THREAD_DELETE < cycle )994 printk("\n[DBG] %s : thread %x exit for thread %x / not the main thread / cycle %d\n",995 __FUNCTION__, killer_ptr, target_ptr, cycle );996 #endif997 998 }999 1000 } // end thread_kill()1001 1002 */1003 863 1004 864 ////////////////////////////////////// … … 1131 991 void thread_idle_func() 1132 992 { 993 994 #if DEBUG_THREAD_IDLE 995 uint32_t cycle; 996 #endif 997 1133 998 while( 1 ) 1134 999 { … … 1140 1005 { 1141 1006 1142 #if DEBUG_THREAD_IDLE 1143 uint32_t cycle = (uint32_t)hal_get_cycles; 1144 thread_t * this = CURRENT_THREAD; 1145 if( DEBUG_THREAD_IDLE < cycle ) 1146 printk("\n[DBG] %s : idle thread %x on core[%x,%d] goes to sleep / cycle %d\n", 1147 __FUNCTION__, this, local_cxy, this->core->lid, cycle ); 1148 #endif 1149 1150 hal_core_sleep(); 1151 1152 #if DEBUG_THREAD_IDLE 1007 #if (DEBUG_THREAD_IDLE & 1) 1153 1008 cycle = (uint32_t)hal_get_cycles; 1154 1009 if( DEBUG_THREAD_IDLE < cycle ) 1155 printk("\n[DBG] %s : idle thread %x on core[%x,%d] wake up / cycle %d\n", 1010 printk("\n[DBG] %s : idle thread on core[%x,%d] goes to sleep / cycle %d\n", 1011 __FUNCTION__, local_cxy, CURRENT_THREAD->core->lid, cycle ); 1012 #endif 1013 1014 hal_core_sleep(); 1015 1016 #if (DEBUG_THREAD_IDLE & 1) 1017 cycle = (uint32_t)hal_get_cycles; 1018 if( DEBUG_THREAD_IDLE < cycle ) 1019 printk("\n[DBG] %s : idle thread on core[%x,%d] wake up / cycle %d\n", 1156 1020 __FUNCTION__, this, local_cxy, this->core->lid, cycle ); 1157 1021 #endif 1158 1022 1159 1023 } 1024 1025 #if DEBUG_THREAD_IDLE 1026 sched_display( CURRENT_THREAD->core->lid ); 1027 #endif 1160 1028 1161 1029 // search a runable thread -
trunk/kernel/kern/thread.h
r443 r446 91 91 #define THREAD_BLOCKED_RPC 0x0200 /*! thread wait RPC completion */ 92 92 #define THREAD_BLOCKED_ISR 0x0400 /*! thread DEV wait ISR */ 93 #define THREAD_BLOCKED_WAIT 0x0800 /*! thread parent wait child termination*/93 #define THREAD_BLOCKED_WAIT 0x0800 /*! thread wait child process termination */ 94 94 95 95 /*************************************************************************************** -
trunk/kernel/kernel_config.h
r445 r446 36 36 //////////////////////////////////////////////////////////////////////////////////////////// 37 37 38 39 40 38 #define DEBUG_CHDEV_CMD_RX 0 41 39 #define DEBUG_CHDEV_CMD_TX 0 … … 97 95 #define DEBUG_PROCESS_GET_LOCAL_COPY 0 98 96 #define DEBUG_PROCESS_INIT_CREATE 0 99 #define DEBUG_PROCESS_MAKE_EXEC 197 #define DEBUG_PROCESS_MAKE_EXEC 0 100 98 #define DEBUG_PROCESS_MAKE_FORK 0 101 99 #define DEBUG_PROCESS_REFERENCE_INIT 0 … … 118 116 #define DEBUG_RPC_VMM_GET_VSEG 0 119 117 120 #define DEBUG_SCHED_HANDLE_SIGNALS 2121 #define DEBUG_SCHED_YIELD 2 // dynamicallyactivated by the trace() syscall118 #define DEBUG_SCHED_HANDLE_SIGNALS 1 119 #define DEBUG_SCHED_YIELD 1 // must be activated by the trace() syscall 122 120 123 121 #define DEBUG_SYSCALLS_ERROR 2 … … 127 125 #define DEBUG_SYS_EXIT 1 128 126 #define DEBUG_SYS_FG 0 129 #define DEBUG_SYS_FORK 0127 #define DEBUG_SYS_FORK 1 130 128 #define DEBUG_SYS_GET_CONFIG 0 131 129 #define DEBUG_SYS_ISATTY 0 132 #define DEBUG_SYS_KILL 2130 #define DEBUG_SYS_KILL 1 133 131 #define DEBUG_SYS_MMAP 0 134 #define DEBUG_SYS_READ 0132 #define DEBUG_SYS_READ 2 135 133 #define DEBUG_SYS_THREAD_CANCEL 0 136 134 #define DEBUG_SYS_THREAD_CREATE 0 … … 139 137 #define DEBUG_SYS_THREAD_SLEEP 0 140 138 #define DEBUG_SYS_THREAD_WAKEUP 0 141 #define DEBUG_SYS_THREAD_YIELD 2139 #define DEBUG_SYS_THREAD_YIELD 0 142 140 #define DEBUG_SYS_TRACE 0 143 141 #define DEBUG_SYS_WAIT 0 144 #define DEBUG_SYS_WRITE 0142 #define DEBUG_SYS_WRITE 2 145 143 146 144 #define DEBUG_SPINLOCKS 0 … … 154 152 #define DEBUG_THREAD_KERNEL_CREATE 0 155 153 #define DEBUG_THREAD_KILL 0 156 #define DEBUG_THREAD_USER_CREATE 2154 #define DEBUG_THREAD_USER_CREATE 0 157 155 #define DEBUG_THREAD_USER_FORK 0 158 #define DEBUG_THREAD_BLOCK 0156 #define DEBUG_THREAD_BLOCK 15000001 159 157 160 158 #define DEBUG_VFS_INODE_CREATE 0 -
trunk/kernel/syscalls/sys_exit.c
r445 r446 36 36 int sys_exit( uint32_t status ) 37 37 { 38 reg_t save_sr; // required to enable IRQs 38 reg_t save_sr; // required to enable IRQs 39 40 xptr_t owner_xp; // extended pointer on owner process 41 cxy_t owner_cxy; // owner process cluster 42 process_t * owner_ptr; // local pointer on owner process 43 thread_t * main_ptr; // local pointer on process main thread 44 xptr_t parent_xp; // extended pointer on parent process 45 cxy_t parent_cxy; // parent process cluster 46 process_t * parent_ptr; // local pointer on parent process 47 xptr_t children_lock_xp; // extended pointer on children locki 48 thread_t * parent_main_ptr; // local pointer on parent main thread 49 xptr_t parent_main_xp; // extended pointer on parent main thread 50 uint32_t term_state; // termination status for owner process 39 51 40 52 thread_t * this = CURRENT_THREAD; … … 52 64 53 65 // get owner process descriptor pointers 54 xptr_towner_xp = process->owner_xp;55 cxy_towner_cxy = GET_CXY( owner_xp );56 process_t *owner_ptr = GET_PTR( owner_xp );66 owner_xp = process->owner_xp; 67 owner_cxy = GET_CXY( owner_xp ); 68 owner_ptr = GET_PTR( owner_xp ); 57 69 58 // get pointers on the process main thread 59 thread_t * main = hal_remote_lpt( XPTR( owner_cxy , &owner_ptr->th_tbl[0] ) ); 60 61 // enable IRQs 62 hal_enable_irq( &save_sr ); 63 64 // mark for delete all process threads in all clusters, 65 // but the main thread and this calling thread 66 process_sigaction( pid , DELETE_ALL_THREADS ); 67 68 // disable IRQs 69 hal_restore_irq( save_sr ); 70 71 #if( DEBUG_SYS_EXIT & 1) 72 if( tm_start > DEBUG_SYS_EXIT ) 73 printk("\n[DBG] %s : thread %x deleted threads / process %x\n", 74 __FUNCTION__ , this, pid ); 70 #if (DEBUG_SYS_EXIT & 1) 71 if( DEBUG_SYS_EXIT < tm_start ) 72 printk("\n[DBG] %s : thread %x get owner process %x in cluster %x\n", 73 __FUNCTION__ , this, owner_ptr, owner_cxy ); 75 74 #endif 76 75 77 // mark for delete this calling thread when it is not the main 78 if( (owner_cxy != local_cxy) || (main != this) ) 79 { 76 // get pointer on the process main thread 77 main_ptr = hal_remote_lpt( XPTR( owner_cxy , &owner_ptr->th_tbl[0] ) ); 80 78 81 #if( DEBUG_SYS_EXIT & 1) 82 if( tm_start > DEBUG_SYS_EXIT ) 83 printk("\n[DBG] %s : calling thread %x marked iself for delete / process %x\n", 84 __FUNCTION__ , this, pid ); 79 // get parent process descriptor pointers 80 parent_xp = process->parent_xp; 81 parent_cxy = GET_CXY( parent_xp ); 82 parent_ptr = GET_PTR( parent_xp ); 83 84 #if (DEBUG_SYS_EXIT & 1) 85 if( DEBUG_SYS_EXIT < tm_start ) 86 printk("\n[DBG] %s : thread %x get parent process %x in cluster %x\n", 87 __FUNCTION__ , this, parent_ptr, parent_cxy ); 85 88 #endif 86 thread_delete( XPTR( local_cxy , this ) , pid , true ); 87 } 89 90 // get extended pointer on lock protecting children list in parent process 91 children_lock_xp = XPTR( parent_cxy , &parent_ptr->children_lock ); 92 93 // get pointers on the parent process main thread 94 parent_main_ptr = hal_remote_lpt( XPTR( parent_cxy , &parent_ptr->th_tbl[0] ) ); 95 parent_main_xp = XPTR( parent_cxy , parent_main_ptr ); 88 96 89 97 // remove process from TXT list … … 96 104 #endif 97 105 98 // block the main thread 99 thread_block( XPTR( owner_cxy , main ) , THREAD_BLOCKED_GLOBAL ); 106 // mark for delete all process threads in all clusters, 107 // but the main thread and this calling thread 108 hal_enable_irq( &save_sr ); 109 process_sigaction( pid , DELETE_ALL_THREADS ); 110 hal_restore_irq( save_sr ); 111 112 #if( DEBUG_SYS_EXIT & 1) 113 if( tm_start > DEBUG_SYS_EXIT ) 114 printk("\n[DBG] %s : thread %x deleted threads for process %x\n", 115 __FUNCTION__ , this, pid ); 116 #endif 117 118 // mark for delete this calling thread when it is not the main 119 if( (owner_cxy != local_cxy) || (main_ptr != this) ) 120 { 121 122 #if( DEBUG_SYS_EXIT & 1) 123 if( tm_start > DEBUG_SYS_EXIT ) 124 printk("\n[DBG] %s : calling thread %x marked iself for delete in process %x\n", 125 __FUNCTION__ , this, pid ); 126 #endif 127 thread_delete( XPTR( local_cxy , this ) , pid , true ); 128 } 129 130 // block this main thread 131 thread_block( XPTR( owner_cxy , main_ptr ) , THREAD_BLOCKED_GLOBAL ); 100 132 101 133 #if( DEBUG_SYS_EXIT & 1) … … 107 139 // atomically update owner process descriptor term_state to ask 108 140 // the parent process sys_wait() function to delete the main thread 109 hal_remote_atomic_or( XPTR( owner_cxy , &process->term_state ) ,110 PROCESS_TERM_EXIT | (status & 0xFF));141 term_state = (status & 0xFF) | PROCESS_TERM_EXIT; 142 hal_remote_atomic_or( XPTR( owner_cxy , &owner_ptr->term_state ) , term_state ); 111 143 112 144 #if( DEBUG_SYS_EXIT & 1) 113 145 if( tm_start > DEBUG_SYS_EXIT ) 114 printk("\n[DBG] %s : thread %x set exit status in process %x term_state\n", 115 __FUNCTION__ , this, pid ); 146 printk("\n[DBG] %s : thread %x set exit status in process %x / term_state %x\n", 147 __FUNCTION__ , this, pid, term_state ); 148 #endif 149 150 // take the children lock and unblock the parent process main thread 151 remote_spinlock_lock( children_lock_xp ); 152 thread_unblock( parent_main_xp , THREAD_BLOCKED_WAIT ); 153 remote_spinlock_unlock( children_lock_xp ); 154 155 #if( DEBUG_SYS_EXIT & 1) 156 if( tm_start > DEBUG_SYS_EXIT ) 157 printk("\n[DBG] %s : thread %x in cluster %x unblock parent main thread %x in cluster %x\n", 158 __FUNCTION__ , this, local_cxy, parent_main_ptr, parent_cxy ); 116 159 #endif 117 160 -
trunk/kernel/syscalls/sys_fg.c
r443 r446 33 33 #include <rpc.h> 34 34 35 /////////////////////// ///36 int sys_fg( pid_t 35 /////////////////////// 36 int sys_fg( pid_t pid ) 37 37 { 38 38 xptr_t process_xp; // extended pointer on reference process descriptor … … 85 85 hal_remote_swd( XPTR( chdev_cxy , &chdev_ptr->ext.txt.owner_xp ) , process_xp ); 86 86 87 // reset PROCESS_TERM_WAIT and PROCESS_TERM_STOP flags in process term_state 88 hal_remote_atomic_and( XPTR( process_cxy , &process_ptr->term_state ), 89 ~(PROCESS_TERM_WAIT | PROCESS_TERM_STOP) ); 90 87 91 hal_fence(); 88 92 -
trunk/kernel/syscalls/sys_kill.c
r440 r446 37 37 uint32_t sig_id ) 38 38 { 39 xptr_t owner_xp; // extended pointer on target process in owner cluster 40 cxy_t owner_cxy; // target process in owner cluster 41 process_t * owner_ptr; // local pointer on target process in owner cluster 42 uint32_t retval; // return value for the switch 39 reg_t save_sr; // required to enable IRQs 40 xptr_t owner_xp; // extended pointer on process in owner cluster 41 cxy_t owner_cxy; // process owner cluster 42 process_t * owner_ptr; // local pointer on process in owner cluster 43 uint32_t retval; // return value for the switch 44 xptr_t parent_xp; // extended pointer on parent process 45 cxy_t parent_cxy; // parent process cluster 46 process_t * parent_ptr; // local pointer on parent process 47 xptr_t children_lock_xp; // extended pointer on children lock in parent 48 thread_t * parent_main_ptr; // local pointer on parent main thread 49 xptr_t parent_main_xp; // extended pointer on parent main thread 43 50 44 51 thread_t * this = CURRENT_THREAD; … … 59 66 owner_ptr = GET_PTR( owner_xp ); 60 67 68 #if (DEBUG_SYS_KILL & 1) 69 if( DEBUG_SYS_KILL < tm_start ) 70 printk("\n[DBG] %s : thread %x found process %x in cluster %x\n", 71 __FUNCTION__ , this, owner_ptr, owner_cxy ); 72 #endif 73 61 74 // check process found 62 75 if( owner_xp == XPTR_NULL) … … 92 105 } 93 106 107 // get parent process descriptor pointers 108 parent_xp = (xptr_t)hal_remote_lwd( XPTR( owner_cxy , &owner_ptr->parent_xp ) ); 109 parent_cxy = GET_CXY( parent_xp ); 110 parent_ptr = GET_PTR( parent_xp ); 111 112 #if (DEBUG_SYS_KILL & 1) 113 if( DEBUG_SYS_KILL < tm_start ) 114 printk("\n[DBG] %s : thread %x get parent process %x in cluster %x\n", 115 __FUNCTION__ , this, parent_ptr, parent_cxy ); 116 #endif 117 118 // get extended pointer on lock protecting children list in parent process 119 children_lock_xp = XPTR( parent_cxy , &parent_ptr->children_lock ); 120 121 // get pointers on the parent process main thread 122 parent_main_ptr = hal_remote_lpt( XPTR( parent_cxy , &parent_ptr->th_tbl[0] ) ); 123 parent_main_xp = XPTR( parent_cxy , parent_main_ptr ); 124 94 125 // analyse signal type / supported values are : 0, SIGSTOP, SIGCONT, SIGKILL 95 126 switch( sig_id ) … … 108 139 process_sigaction( pid , BLOCK_ALL_THREADS ); 109 140 110 // get pointer on target processmain thread141 // block the main thread 111 142 xptr_t main_xp = XPTR( owner_cxy , &owner_ptr->th_tbl[0] ); 112 113 // block main thread114 143 thread_block( main_xp , THREAD_BLOCKED_GLOBAL ); 115 144 … … 117 146 hal_remote_atomic_or( XPTR( owner_cxy , &owner_ptr->term_state ) , 118 147 PROCESS_TERM_STOP ); 148 149 // take the children lock and unblock the parent process main thread 150 remote_spinlock_lock( children_lock_xp ); 151 thread_unblock( parent_main_xp , THREAD_BLOCKED_WAIT ); 152 remote_spinlock_unlock( children_lock_xp ); 153 119 154 retval = 0; 120 155 break; … … 137 172 process_txt_detach( owner_xp ); 138 173 139 // mark for delete all process threads in all clusters, but the main 174 // mark for delete all threads in all clusters, but the main 175 hal_enable_irq( &save_sr ); 140 176 process_sigaction( pid , DELETE_ALL_THREADS ); 141 142 // get pointer on target process main thread 177 hal_restore_irq( save_sr ); 178 179 // block main thread 143 180 xptr_t main_xp = XPTR( owner_cxy , &owner_ptr->th_tbl[0] ); 144 145 // block main thread146 181 thread_block( main_xp , THREAD_BLOCKED_GLOBAL ); 147 182 … … 150 185 hal_remote_atomic_or( XPTR( owner_cxy , &owner_ptr->term_state ) , 151 186 PROCESS_TERM_KILL ); 187 188 // take the children lock and unblock the parent process main thread 189 remote_spinlock_lock( children_lock_xp ); 190 thread_unblock( parent_main_xp , THREAD_BLOCKED_WAIT ); 191 remote_spinlock_unlock( children_lock_xp ); 192 152 193 retval = 0; 153 194 break; -
trunk/kernel/syscalls/sys_read.c
r443 r446 63 63 reg_t save_sr; // required to enable IRQs during syscall 64 64 65 thread_t * this = CURRENT_THREAD; 66 process_t * process = this->process; 65 thread_t * this = CURRENT_THREAD; 66 process_t * process = this->process; 67 xptr_t process_owner_xp = process->owner_xp; 67 68 68 69 #if DEBUG_SYS_READ … … 165 166 count ); 166 167 } 167 else if( type == INODE_TYPE_DEV ) // check ownership & read from fromdevice168 else if( type == INODE_TYPE_DEV ) // check ownership & read from device 168 169 { 169 170 // get cluster and pointers on TXT_RX chdev … … 172 173 chdev_t * chdev_ptr = GET_PTR( chdev_xp ); 173 174 174 volatile xptr_t owner_xp; 175 volatile xptr_t txt_owner_xp; 176 uint32_t iter = 0; 175 177 176 178 while( 1 ) 177 179 { 178 // extended pointer on owner process179 owner_xp = hal_remote_lwd( XPTR( chdev_cxy , &chdev_ptr->ext.txt.owner_xp ) );180 // extended pointer on TXT owner process 181 txt_owner_xp = hal_remote_lwd( XPTR( chdev_cxy , &chdev_ptr->ext.txt.owner_xp ) ); 180 182 181 183 // check TXT_RX ownership 182 if ( XPTR( local_cxy , process ) !=owner_xp )184 if ( process_owner_xp != txt_owner_xp ) 183 185 { 186 if( (iter & 0xFFF) == 0 ) 187 printk("\n[WARNING] in %s : thread %x in process %x wait TXT_RX / cycle %d\n", 188 __FUNCTION__, this->trdid, process->pid, (uint32_t)hal_get_cycles() ); 189 184 190 // deschedule without blocking 185 sched_yield( "wait TXT ownership" ); 191 sched_yield( "wait TXT_RX ownership" ); 192 193 iter++; 186 194 } 187 195 else … … 191 199 } 192 200 201 printk("\n###### in %s : thread %x in process %x got TXT_RX ownership\n", 202 __FUNCTION__, this->trdid, process->pid ); 203 193 204 // move count bytes from device 194 205 nbytes = devfs_user_move( true, // from device to buffer -
trunk/kernel/syscalls/sys_wait.c
r443 r446 41 41 cxy_t child_cxy; 42 42 pid_t child_pid; 43 intchild_state;43 uint32_t child_state; 44 44 thread_t * child_thread; 45 45 reg_t save_sr; … … 50 50 51 51 #if DEBUG_SYS_WAIT 52 uint64_t tm_start; 53 uint64_t tm_end; 54 tm_start = hal_get_cycles(); 55 if( DEBUG_SYS_WAIT < tm_start ) 56 printk("\n[DBG] %s : thread %x enter / process %x / cycle %d\n", 57 __FUNCTION__, this, process->pid, (uint32_t)tm_start ); 52 uint64_t cycle = hal_get_cycles(); 53 if( DEBUG_SYS_WAIT < cycle ) 54 printk("\n[DBG] %s : thread %x in process %x enter / cycle %d\n", 55 __FUNCTION__, this, process->pid, (uint32_t)cycle ); 58 56 #endif 59 57 … … 83 81 { 84 82 85 #if DEBUG_SYSCALL _ERROR83 #if DEBUG_SYSCALLS_ERROR 86 84 printk("\n[ERROR] in %s : calling thread %x is not thread 0 in owner cluster %x\n", 87 85 __FUNCTION__ , trdid , owner_cxy ); … … 112 110 child_cxy = GET_CXY( child_xp ); 113 111 114 // get term_state from child owner process 115 child_state = (int)hal_remote_lw ( XPTR(child_cxy,&child_ptr->term_state)); 112 // get PID, term_state, and main thread from child process 113 child_pid = hal_remote_lw (XPTR( child_cxy , &child_ptr->pid )); 114 child_state = hal_remote_lw ( XPTR(child_cxy , &child_ptr->term_state ) ); 115 child_thread = hal_remote_lpt(XPTR( child_cxy , &child_ptr->th_tbl[0] )); 116 116 117 #if (DEBUG_SYS_WAIT &1) 118 cycle = hal_get_cycles(); 119 if( DEBUG_SYS_WAIT < cycle ) 120 printk("\n[DBG] %s : thread %x in process %x check child %x / state %x\n", 121 __FUNCTION__, this, process->pid, child_pid, child_state ); 122 #endif 117 123 // test if this child process is terminated, 118 124 // but termination not yet reported to parent process … … 122 128 ((child_state & PROCESS_TERM_WAIT) == 0) ) 123 129 { 124 // get pointer on child main thread and PID from child owner process 125 child_pid = (pid_t) hal_remote_lw (XPTR( child_cxy , &child_ptr->pid )); 126 child_thread = (thread_t *)hal_remote_lpt(XPTR( child_cxy , 127 &child_ptr->th_tbl[0] )); 128 129 // set the PROCESS_FLAG_WAIT in owner child process descriptor 130 // set the PROCESS_FLAG_WAIT in child process descriptor 130 131 hal_remote_atomic_or( XPTR( child_cxy , &child_ptr->term_state ), 131 132 PROCESS_TERM_WAIT ); 132 133 133 // set the THREAD_FLAG_REQ_DELETE in child main thread 134 // set the THREAD_FLAG_REQ_DELETE in main thread if kill or exit 135 if((child_state & PROCESS_TERM_EXIT) || (child_state & PROCESS_TERM_KILL)) 134 136 hal_remote_atomic_or( XPTR( child_cxy , &child_thread->flags ) , 135 137 THREAD_FLAG_REQ_DELETE ); … … 139 141 140 142 #if DEBUG_SYS_WAIT 141 tm_end = hal_get_cycles(); 142 if( DEBUG_SYS_WAIT < tm_end ) 143 printk("\n[DBG] %s : thread %x exit / parent %x / child %x / cycle %d\n", 144 __FUNCTION__, this, process->pid, child_pid, (uint32_t)tm_end ); 143 cycle = hal_get_cycles(); 144 if( DEBUG_SYS_WAIT < cycle ) 145 { 146 if ( child_state & PROCESS_TERM_EXIT ) 147 printk("\n[DBG] %s : thread %x in process %x exit / child %x exit / cycle %d\n", 148 __FUNCTION__, this, process->pid, child_pid, (uint32_t)cycle ); 149 if( child_state & PROCESS_TERM_KILL ) 150 printk("\n[DBG] %s : thread %x in process %x exit / child %x killed / cycle %d\n", 151 __FUNCTION__, this, process->pid, child_pid, (uint32_t)cycle ); 152 if( child_state & PROCESS_TERM_STOP ) 153 printk("\n[DBG] %s : thread %x in process %x exit / child %x stopped / cycle %d\n", 154 __FUNCTION__, this, process->pid, child_pid, (uint32_t)cycle ); 155 } 145 156 #endif 146 157 // return child termination state to parent process … … 150 161 } // end loop on children 151 162 163 // block on WAIT condition 164 thread_block( XPTR( local_cxy , this ) , THREAD_BLOCKED_WAIT ); 165 152 166 // release lock protecting children list 153 167 remote_spinlock_unlock( children_lock_xp ); 154 168 155 // deschedule without blocking 156 sched_yield( "parent wait children termination" ); 169 #if (DEBUG_SYS_WAIT & 1) 170 cycle = hal_get_cycles(); 171 if( DEBUG_SYS_WAIT < cycle ) 172 printk("\n[DBG] %s : thread %x in process %x block & deschedule / cycle %d\n", 173 __FUNCTION__, this, process->pid, (uint32_t)cycle ); 174 #endif 175 176 // deschedule 177 sched_yield( "parent process wait children processes termination" ); 178 179 #if (DEBUG_SYS_WAIT & 1) 180 cycle = hal_get_cycles(); 181 if( DEBUG_SYS_WAIT < cycle ) 182 printk("\n[DBG] %s : thread %x in process %x unblock & resume / cycle %d\n", 183 __FUNCTION__, this, process->pid, (uint32_t)cycle ); 184 #endif 157 185 158 186 } // end while -
trunk/params-hard.mk
r445 r446 2 2 3 3 ARCH = /users/alain/soc/tsar-trunk-svn-2013/platforms/tsar_generic_iob 4 X_SIZE = 24 X_SIZE = 1 5 5 Y_SIZE = 2 6 6 NB_PROCS = 1 7 NB_TTYS = 47 NB_TTYS = 2 8 8 FBF_WIDTH = 128 9 9 IOC_TYPE = IOC_BDV -
trunk/user/idbg/idbg.c
r445 r446 20 20 printf( "\n[IDBG] starts at cycle %d\n", (unsigned int)cycle ); 21 21 22 while (1) 23 { 24 25 /////// 26 idbg(); 27 /////// 28 } 22 /////// 23 idbg(); 24 /////// 29 25 30 26 get_cycle( &cycle ); -
trunk/user/ksh/ksh.c
r445 r446 4 4 // Author : Alain Greiner 5 5 /////////////////////////////////////////////////////////////////////////////// 6 // This single thread application implement a simple shell for ALMOS-MKH. 6 // This applications implement a minimal shell for ALMOS-MKH. 7 // This user process contains two POSIX threads: 8 // - the "main" thread contains the infinite loop implementing 9 // the children processes termination monitoring (children processes 10 // are created by the <load> command and attached to the KSH TXT terminal). 11 // - the "interactive" thread contains the infinite loop implementing 12 // the command interpreter attached to the TXT terminal. 7 13 /////////////////////////////////////////////////////////////////////////////// 8 14 … … 53 59 unsigned int ptr; // read pointer in log_entries[] 54 60 61 pthread_attr_t attr; // monitor thread attributes 62 55 63 //////////////////////////////////////////////////////////////////////////////// 56 64 // Shell Commands … … 100 108 } 101 109 102 // set terminating '0' XXX110 // set terminating '0' 103 111 buf[size-1] = 0; 104 112 … … 449 457 else // it is the parent KSH : ret_fork is the new process PID 450 458 { 451 // give back terminal ownership to KSH if new process created in background /452 // w ait new process completion before returning to command interpreter otherwise459 // give back terminal ownership to KSH 460 // when new process created in background 453 461 if( background ) fg( ksh_pid ); 454 else wait( &status );455 462 456 463 // return to command interpreter … … 715 722 } 716 723 } 717 } 718 719 ///////////////////////// //////////720 int main( int argc , char *argv[])724 } // end parse() 725 726 ///////////////////////// 727 static void interactive() 721 728 { 722 729 char c; // read character 723 730 char buf[CMD_MAX_SIZE]; // buffer for one command 724 unsigned int count = 0;// pointer in buf731 unsigned int count; // pointer in buf 725 732 unsigned int i; // index for loops 726 733 … … 732 739 }; 733 740 734 // log buffer initialisation 735 memset( &log_entries , 0, sizeof(log_entries)); 736 ptw = 0; 737 ptr = 0; 738 739 printf( "\n\n~~~ shell ~~~\n\n" ); 740 741 // command buffer initialisation 741 // initialize command buffer 742 742 memset( buf, 0x20 , sizeof(buf) ); 743 743 count = 0; … … 760 760 761 761 // @@@ 762 // parse("load /bin/user/hello.elf");762 parse("load /bin/user/idbg.elf"); 763 763 // @@@ 764 764 … … 814 814 state = ESCAPE; 815 815 } 816 else if (c == 0x03) // ^C => cancel current command817 {818 for (i = 0; i < count; i++) printf("\b \b");819 for (i = 0; i < sizeof(buf); i++) buf[i] = 0x20;820 count = 0;821 }822 816 else // register character in command buffer 823 817 { … … 910 904 } 911 905 } 906 } // end interactive() 907 908 /////////////////////////////////// 909 int main( int argc , char *argv[] ) 910 { 911 unsigned int cxy; // owner cluster identifier for this KSH process 912 unsigned int lid; // core identifier for this KSH main thread 913 int status; // child process termination status 914 int pid; // chils process identifier 915 pthread_t trdid; // kernel allocated index for interactive thread 916 917 // initialize log buffer 918 memset( &log_entries , 0, sizeof(log_entries)); 919 ptw = 0; 920 ptr = 0; 921 922 get_core( &cxy , & lid ); 923 printf( "\n\n~~~ KSH on core[%x,%d] ~~~\n\n", cxy , lid ); 924 925 // initialize interactive thread attributes 926 attr.attributes = PT_ATTR_DETACH | PT_ATTR_CLUSTER_DEFINED; 927 attr.cxy = cxy; 928 929 // lauch the interactive thread 930 pthread_create( &trdid, 931 &attr, 932 &interactive, // entry function 933 NULL ); 934 935 // enter infinite loop monitoring children processes termination 936 while( 1 ) 937 { 938 pid = wait( &status ); 939 940 #if 0 941 if ( WIFEXITED (status) ) printf("\n[KSH] process %x exited\n" , pid ); 942 else if( WIFSIGNALED(status) ) printf("\n[KSH] process %x killed\n" , pid ); 943 else if( WIFSTOPPED (status) ) printf("\n[KSH] process %x stopped\n", pid ); 944 else printf("\n[KSH] process %x strange\n", pid ); 945 #endif 946 947 } 912 948 } // end main() 913 949 950 -
trunk/user/pgcd/pgcd.c
r445 r446 33 33 if( (opx == 0) || (opy == 0) ) 34 34 { 35 printf("operands must be positive and larger than 0\n"); 35 printf("operands must be positive and larger than 0 => exit\n"); 36 exit( 0 ); 36 37 } 37 38 else
Note: See TracChangeset
for help on using the changeset viewer.