Changeset 580 for trunk/kernel/kern/thread.c
- Timestamp:
- Oct 8, 2018, 11:31:42 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/kern/thread.c
r564 r580 1216 1216 xptr_t lock_xp; // extended pointer on lock protecting this list 1217 1217 1218 #if DEBUG_THREAD_GET_XPTR 1219 uint32_t cycle = (uint32_t)hal_get_cycles(); 1220 thread_t * this = CURRENT_THREAD; 1221 if( DEBUG_THREAD_GET_XPTR < cycle ) 1222 printk("\n[DBG] %s : thread %x in process %x enters / pid %x / trdid %x / cycle %d\n", 1223 __FUNCTION__, this->trdid, this->process->pid, pid, trdid, cycle ); 1224 #endif 1225 1218 1226 // get target cluster identifier and local thread identifier 1219 1227 target_cxy = CXY_FROM_TRDID( trdid ); … … 1235 1243 remote_queuelock_acquire( lock_xp ); 1236 1244 1245 #if( DEBUG_THREAD_GET_XPTR & 1 ) 1246 if( DEBUG_THREAD_GET_XPTR < cycle ) 1247 printk("\n[DBG] %s : scan processes in cluster %x :\n", __FUNCTION__, target_cxy ); 1248 #endif 1249 1237 1250 // scan the list of local processes in target cluster 1238 1251 xptr_t iter; … … 1243 1256 target_process_ptr = GET_PTR( target_process_xp ); 1244 1257 target_process_pid = hal_remote_l32( XPTR( target_cxy , &target_process_ptr->pid ) ); 1258 1259 #if( DEBUG_THREAD_GET_XPTR & 1 ) 1260 if( DEBUG_THREAD_GET_XPTR < cycle ) 1261 printk(" - process %x\n", target_process_pid ); 1262 #endif 1263 1245 1264 if( target_process_pid == pid ) 1246 1265 { … … 1254 1273 1255 1274 // check PID found 1256 if( found == false ) return XPTR_NULL; 1275 if( found == false ) 1276 { 1277 1278 #if( DEBUG_THREAD_GET_XPTR & 1 ) 1279 if( DEBUG_THREAD_GET_XPTR < cycle ) 1280 printk("\n[DBG] %s : pid %x not found in cluster %x\n", 1281 __FUNCTION__, pid, target_cxy ); 1282 #endif 1283 return XPTR_NULL; 1284 } 1257 1285 1258 1286 // get target thread local pointer … … 1260 1288 target_thread_ptr = (thread_t *)hal_remote_lpt( xp ); 1261 1289 1262 if( target_thread_ptr == NULL ) return XPTR_NULL; 1290 if( target_thread_ptr == NULL ) 1291 { 1292 1293 #if( DEBUG_THREAD_GET_XPTR & 1 ) 1294 if( DEBUG_THREAD_GET_XPTR < cycle ) 1295 printk("\n[DBG] %s : thread %x not registered in process %x in cluster %x\n", 1296 __FUNCTION__, trdid, pid, target_cxy ); 1297 #endif 1298 return XPTR_NULL; 1299 } 1300 1301 #if DEBUG_THREAD_GET_XPTR 1302 cycle = (uint32_t)hal_get_cycles(); 1303 if( DEBUG_THREAD_GET_XPTR < cycle ) 1304 printk("\n[DBG] %s : thread %x in process %x exit / pid %x / trdid %x / cycle %d\n", 1305 __FUNCTION__, this->trdid, this->process->pid, pid, trdid, cycle ); 1306 #endif 1263 1307 1264 1308 return XPTR( target_cxy , target_thread_ptr ); … … 1287 1331 // display error message on TXT0 1288 1332 nolock_printk("\n[PANIC] in %s / thread %x in process %x [%x] cannot yield : " 1289 " %d busylock(s) / cycle %d\n",1333 "hold %d busylock(s) / cycle %d\n", 1290 1334 func_str, thread->trdid, thread->process->pid, thread, 1291 1335 thread->busylocks, (uint32_t)hal_get_cycles() ); 1292 1336 1293 1337 #if DEBUG_BUSYLOCK 1294 if( XPTR( local_cxy , thread ) == DEBUG_BUSYLOCK_THREAD_XP ) 1295 { 1296 // get root of list of taken busylocks 1297 xptr_t root_xp = XPTR( local_cxy , &thread->busylocks_root ); 1298 xptr_t iter_xp; 1299 1300 // scan list of busylocks 1301 XLIST_FOREACH( root_xp , iter_xp ) 1302 { 1303 xptr_t lock_xp = XLIST_ELEMENT( iter_xp , busylock_t , xlist ); 1304 cxy_t lock_cxy = GET_CXY( lock_xp ); 1305 busylock_t * lock_ptr = GET_PTR( lock_xp ); 1306 uint32_t lock_type = hal_remote_l32( XPTR( lock_cxy , &lock_ptr->type ) ); 1307 nolock_printk(" - %s in cluster %x\n", lock_type_str[lock_type] , lock_cxy ); 1308 } 1338 1339 // get root of list of taken busylocks 1340 xptr_t root_xp = XPTR( local_cxy , &thread->busylocks_root ); 1341 xptr_t iter_xp; 1342 1343 // scan list of busylocks 1344 XLIST_FOREACH( root_xp , iter_xp ) 1345 { 1346 xptr_t lock_xp = XLIST_ELEMENT( iter_xp , busylock_t , xlist ); 1347 cxy_t lock_cxy = GET_CXY( lock_xp ); 1348 busylock_t * lock_ptr = GET_PTR( lock_xp ); 1349 uint32_t lock_type = hal_remote_l32( XPTR( lock_cxy , &lock_ptr->type ) ); 1350 nolock_printk(" - %s in cluster %x\n", lock_type_str[lock_type] , lock_cxy ); 1309 1351 } 1352 1310 1353 #endif 1311 1354 … … 1318 1361 } // end thread_assert_can yield() 1319 1362 1320 #if DEBUG_BUSYLOCK 1321 1322 //////////////////////////////////////////////////// 1323 void thread_display_busylocks( uint32_t lock_type, 1324 bool_t is_acquire ) 1325 { 1326 xptr_t iter_xp; 1327 1328 // get cluster and local pointer of target thread 1329 cxy_t thread_cxy = GET_CXY( DEBUG_BUSYLOCK_THREAD_XP ); 1330 thread_t * thread_ptr = GET_PTR( DEBUG_BUSYLOCK_THREAD_XP ); 1331 1332 // get extended pointer on root of busylocks 1333 xptr_t root_xp = XPTR( thread_cxy , &thread_ptr->busylocks_root ); 1334 1335 // get pointers on TXT0 chdev 1336 xptr_t txt0_xp = chdev_dir.txt_tx[0]; 1337 cxy_t txt0_cxy = GET_CXY( txt0_xp ); 1338 chdev_t * txt0_ptr = GET_PTR( txt0_xp ); 1339 1340 // get extended pointer on remote TXT0 lock 1341 xptr_t txt0_lock_xp = XPTR( txt0_cxy , &txt0_ptr->wait_lock ); 1342 1343 // get TXT0 lock 1344 remote_busylock_acquire( txt0_lock_xp ); 1345 1346 if( is_acquire ) 1347 { 1348 nolock_printk("\n### thread [%x,%x] ACQUIRE lock %s / root %x / locks :\n", 1349 thread_cxy, thread_ptr, lock_type_str[lock_type], GET_PTR(root_xp) ); 1363 ////////////////////////////////////////////////// 1364 void thread_display_busylocks( xptr_t thread_xp ) 1365 { 1366 if( DEBUG_BUSYLOCK ) 1367 { 1368 xptr_t iter_xp; 1369 1370 // get cluster and local pointer of target thread 1371 cxy_t thread_cxy = GET_CXY( thread_xp ); 1372 thread_t * thread_ptr = GET_PTR( thread_xp ); 1373 1374 // get target thread TRDID and busylocks 1375 trdid_t trdid = hal_remote_l32(XPTR( thread_cxy , &thread_ptr->trdid )); 1376 uint32_t locks = hal_remote_l32(XPTR( thread_cxy , &thread_ptr->busylocks )); 1377 1378 // get target thread process and PID; 1379 process_t * process = hal_remote_lpt(XPTR( thread_cxy , &thread_ptr->process )); 1380 pid_t pid = hal_remote_l32(XPTR( thread_cxy , &process->pid )); 1381 1382 // get extended pointer on root of busylocks 1383 xptr_t root_xp = XPTR( thread_cxy , &thread_ptr->busylocks_root ); 1384 1385 // get pointers on TXT0 chdev 1386 xptr_t txt0_xp = chdev_dir.txt_tx[0]; 1387 cxy_t txt0_cxy = GET_CXY( txt0_xp ); 1388 chdev_t * txt0_ptr = GET_PTR( txt0_xp ); 1389 1390 // get extended pointer on remote TXT0 lock 1391 xptr_t txt0_lock_xp = XPTR( txt0_cxy , &txt0_ptr->wait_lock ); 1392 1393 // get TXT0 lock 1394 remote_busylock_acquire( txt0_lock_xp ); 1395 1396 // display header 1397 nolock_printk("\n***** thread %x in process %x : %d busylocks at cycle %d\n", 1398 trdid, pid, locks, (uint32_t)hal_get_cycles() ); 1399 1400 // scan the xlist of busylocks when required 1401 if( locks ) 1402 { 1403 XLIST_FOREACH( root_xp , iter_xp ) 1404 { 1405 xptr_t lock_xp = XLIST_ELEMENT( iter_xp , busylock_t , xlist ); 1406 cxy_t lock_cxy = GET_CXY( lock_xp ); 1407 busylock_t * lock_ptr = GET_PTR( lock_xp ); 1408 uint32_t lock_type = hal_remote_l32(XPTR( lock_cxy , &lock_ptr->type )); 1409 nolock_printk(" - %s in cluster %x\n", lock_type_str[lock_type] , lock_cxy ); 1410 } 1411 } 1412 1413 // release TXT0 lock 1414 remote_busylock_release( txt0_lock_xp ); 1350 1415 } 1351 1416 else 1352 1417 { 1353 nolock_printk("\n### thread [%x,%x] RELEASE lock %s / root %x / locks :\n", 1354 thread_cxy, thread_ptr, lock_type_str[lock_type], GET_PTR(root_xp) ); 1355 } 1356 1357 int i; 1358 1359 XLIST_FOREACH( root_xp , iter_xp ) 1360 { 1361 xptr_t ilock_xp = XLIST_ELEMENT( iter_xp , busylock_t , xlist ); 1362 cxy_t ilock_cxy = GET_CXY( ilock_xp ); 1363 busylock_t * ilock_ptr = GET_PTR( ilock_xp ); 1364 uint32_t ilock_type = hal_remote_l32( XPTR( ilock_cxy , &ilock_ptr->type ) ); 1365 nolock_printk(" - %s in cluster %x\n", lock_type_str[ilock_type] , ilock_cxy ); 1366 } 1367 1368 // release TXT0 lock 1369 remote_busylock_release( txt0_lock_xp ); 1370 } 1371 #endif 1418 // display a warning 1419 printk("\n[WARNING] set the DEBUG_BUSYLOCK parmeter in kernel_config.h" 1420 " to use the %s function\n", __FUNCTION__ ); 1421 } 1422 } // end thread_display_busylock()
Note: See TracChangeset
for help on using the changeset viewer.