Ignore:
Timestamp:
Oct 8, 2018, 11:31:42 AM (6 years ago)
Author:
alain
Message:

1) Register the kernel process in the cluster manager local list.
2) Introduce a new service in idbg : display the set of busylocks taken by a given thread.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/kern/thread.c

    r564 r580  
    12161216    xptr_t        lock_xp;             // extended pointer on lock protecting  this list
    12171217
     1218#if DEBUG_THREAD_GET_XPTR
     1219uint32_t cycle  = (uint32_t)hal_get_cycles();
     1220thread_t * this = CURRENT_THREAD;
     1221if( DEBUG_THREAD_GET_XPTR < cycle )
     1222printk("\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
    12181226    // get target cluster identifier and local thread identifier
    12191227    target_cxy         = CXY_FROM_TRDID( trdid );
     
    12351243    remote_queuelock_acquire( lock_xp );
    12361244
     1245#if( DEBUG_THREAD_GET_XPTR & 1 )
     1246if( DEBUG_THREAD_GET_XPTR < cycle )
     1247printk("\n[DBG]  %s : scan processes in cluster %x :\n", __FUNCTION__, target_cxy );
     1248#endif
     1249
    12371250    // scan the list of local processes in target cluster
    12381251    xptr_t  iter;
     
    12431256        target_process_ptr = GET_PTR( target_process_xp );
    12441257        target_process_pid = hal_remote_l32( XPTR( target_cxy , &target_process_ptr->pid ) );
     1258
     1259#if( DEBUG_THREAD_GET_XPTR & 1 )
     1260if( DEBUG_THREAD_GET_XPTR < cycle )
     1261printk(" - process %x\n", target_process_pid );
     1262#endif
     1263
    12451264        if( target_process_pid == pid )
    12461265        {
     
    12541273
    12551274    // check PID found
    1256     if( found == false ) return XPTR_NULL;
     1275    if( found == false )
     1276    {
     1277
     1278#if( DEBUG_THREAD_GET_XPTR & 1 )
     1279if( DEBUG_THREAD_GET_XPTR < cycle )
     1280printk("\n[DBG] %s : pid %x not found in cluster %x\n",
     1281__FUNCTION__, pid, target_cxy );
     1282#endif
     1283        return XPTR_NULL;
     1284    }
    12571285
    12581286    // get target thread local pointer
     
    12601288    target_thread_ptr = (thread_t *)hal_remote_lpt( xp );
    12611289
    1262     if( target_thread_ptr == NULL )  return XPTR_NULL;
     1290    if( target_thread_ptr == NULL )
     1291    {
     1292
     1293#if( DEBUG_THREAD_GET_XPTR & 1 )
     1294if( DEBUG_THREAD_GET_XPTR < cycle )
     1295printk("\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
     1302cycle  = (uint32_t)hal_get_cycles();
     1303if( DEBUG_THREAD_GET_XPTR < cycle )
     1304printk("\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
    12631307
    12641308    return XPTR( target_cxy , target_thread_ptr );
     
    12871331        // display error message on TXT0
    12881332        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",
    12901334        func_str, thread->trdid, thread->process->pid, thread,
    12911335        thread->busylocks, (uint32_t)hal_get_cycles() );
    12921336
    12931337#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
     1340xptr_t    root_xp  = XPTR( local_cxy , &thread->busylocks_root );
     1341xptr_t    iter_xp;
     1342
     1343// scan list of busylocks
     1344XLIST_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 );
    13091351}
     1352
    13101353#endif
    13111354
     
    13181361}  // end thread_assert_can yield()
    13191362
    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//////////////////////////////////////////////////
     1364void 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 );
    13501415    }
    13511416    else
    13521417    {
    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.