Ignore:
Timestamp:
Oct 10, 2018, 3:11:53 PM (2 years ago)
Author:
alain
Message:

1) Improve the busylock debug infrastructure.
2) introduce a non-distributed, but portable implementation for the pthread_barrier.

File:
1 edited

Legend:

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

    r580 r581  
    190190    if( error )
    191191    {
    192         printk("\n[ERROR] in %s : cannot get TRDID\n", __FUNCTION__ );
     192        printk("\n[ERROR] in %s : thread %x in process %x cannot get TRDID in cluster %x\n"
     193        "    for thread %s in process %x / cycle %d\n",
     194        __FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid,
     195        local_cxy, thread_type_str(type), process->pid, (uint32_t)hal_get_cycles() );
    193196        return EINVAL;
    194197    }
     
    710713
    711714    assert( ( (type == THREAD_IDLE) || (type == THREAD_RPC) || (type == THREAD_DEV) ) ,
    712         "illegal thread type" );
     715    "illegal thread type" );
    713716
    714717    assert( (core_lid < LOCAL_CLUSTER->cores_nr) ,
    715             "illegal core_lid" );
     718    "illegal core_lid" );
    716719
    717720#if DEBUG_THREAD_KERNEL_CREATE
     
    725728    thread = thread_alloc();
    726729
    727     if( thread == NULL ) return ENOMEM;
     730    if( thread == NULL )
     731    {
     732        printk("\n[ERROR] in %s : thread %x in process %x\n"
     733        "   no memory for thread descriptor\n",
     734        __FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid );
     735        return ENOMEM;
     736    }
    728737
    729738    // initialize thread descriptor
     
    738747    if( error ) // release allocated memory for thread descriptor
    739748    {
     749        printk("\n[ERROR] in %s : thread %x in process %x\n"
     750        "   cannot initialize thread descriptor\n",
     751        __FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid );
    740752        thread_release( thread );
    741753        return ENOMEM;
     
    744756    // allocate & initialize CPU context
    745757        error = hal_cpu_context_alloc( thread );
     758
    746759    if( error )
    747760    {
     761        printk("\n[ERROR] in %s : thread %x in process %x\n"
     762        "   cannot cannot create CPU context\n",
     763        __FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid );
    748764        thread_release( thread );
    749765        return EINVAL;
    750766    }
     767
    751768    hal_cpu_context_init( thread );
    752769
     
    13641381void thread_display_busylocks( xptr_t  thread_xp )
    13651382{
    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 )
     1383    // get cluster and local pointer of target thread
     1384    cxy_t      thread_cxy = GET_CXY( thread_xp );
     1385    thread_t * thread_ptr = GET_PTR( thread_xp );
     1386
     1387#if( DEBUG_BUSYLOCK )
     1388
     1389    xptr_t    iter_xp;
     1390
     1391    // get target thread TRDID and busylocks
     1392    trdid_t  trdid = hal_remote_l32(XPTR( thread_cxy , &thread_ptr->trdid ));
     1393    uint32_t locks = hal_remote_l32(XPTR( thread_cxy , &thread_ptr->busylocks ));
     1394
     1395    // get target thread process and PID;
     1396    process_t * process = hal_remote_lpt(XPTR( thread_cxy , &thread_ptr->process ));
     1397    pid_t       pid     = hal_remote_l32(XPTR( thread_cxy , &process->pid ));
     1398
     1399    // get extended pointer on root of busylocks
     1400    xptr_t    root_xp = XPTR( thread_cxy , &thread_ptr->busylocks_root );
     1401
     1402    // get pointers on TXT0 chdev
     1403    xptr_t    txt0_xp  = chdev_dir.txt_tx[0];
     1404    cxy_t     txt0_cxy = GET_CXY( txt0_xp );
     1405    chdev_t * txt0_ptr = GET_PTR( txt0_xp );
     1406
     1407    // get extended pointer on remote TXT0 lock
     1408    xptr_t  txt0_lock_xp = XPTR( txt0_cxy , &txt0_ptr->wait_lock );
     1409
     1410    // get TXT0 lock
     1411    remote_busylock_acquire( txt0_lock_xp );
     1412
     1413    // display header
     1414    nolock_printk("\n***** thread %x in process %x : %d busylocks at cycle %d\n",
     1415    trdid, pid, locks, (uint32_t)hal_get_cycles() );
     1416
     1417    // scan the xlist of busylocks when required
     1418    if( locks )
     1419    {
     1420        XLIST_FOREACH( root_xp , iter_xp )
    14021421        {
    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             }
     1422            xptr_t       lock_xp   = XLIST_ELEMENT( iter_xp , busylock_t , xlist );
     1423            cxy_t        lock_cxy  = GET_CXY( lock_xp );
     1424            busylock_t * lock_ptr  = GET_PTR( lock_xp );
     1425            uint32_t     lock_type = hal_remote_l32(XPTR( lock_cxy , &lock_ptr->type ));
     1426            nolock_printk(" - %s in cluster %x\n", lock_type_str[lock_type] , lock_cxy );
    14111427        }
    1412 
    1413         // release TXT0 lock
    1414         remote_busylock_release( txt0_lock_xp );
    1415     }
    1416     else
    1417     {
    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     }
     1428    }
     1429
     1430    // release TXT0 lock
     1431    remote_busylock_release( txt0_lock_xp );
     1432
     1433    return;
     1434
     1435#endif
     1436
     1437    // display a warning
     1438    printk("\n[WARNING] set the DEBUG_BUSYLOCK parmeter in kernel_config.h"
     1439    " to display busylocks for thread %x/%x\n", thread_cxy, thread_ptr );
     1440
    14221441}  // end thread_display_busylock()
     1442
Note: See TracChangeset for help on using the changeset viewer.