Ignore:
Timestamp:
Jun 19, 2018, 5:12:57 PM (6 years ago)
Author:
alain
Message:

miscelaneous...

File:
1 edited

Legend:

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

    r443 r446  
    4242#include <ppm.h>
    4343#include <thread.h>
     44#include <rpc.h>
    4445
    4546//////////////////////////////////////////////////////////////////////////////////////
     
    799800uint32_t cycle = (uint32_t)hal_get_cycles();
    800801if( 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 );
     802printk("\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 );
    803804#endif
    804805
    805806#if (DEBUG_THREAD_BLOCK & 1)
    806807if( 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}
    808820#endif
    809821
     
    825837uint32_t cycle = (uint32_t)hal_get_cycles();
    826838if( 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 );
     839printk("\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 );
    829841#endif
    830842
    831843#if (DEBUG_THREAD_BLOCK & 1)
    832844if( 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}
    834857#endif
    835858
     
    838861
    839862}  // 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 section
    849     bool_t      attached;               // target thread in attached mode
    850     bool_t      join_done;              // joining thread arrived first
    851     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 cluster     
    854     thread_t  * target_ptr;             // pointer on target thread
    855     xptr_t      joining_xp;             // extended pointer on joining thread
    856     thread_t  * joining_ptr;            // pointer on joining thread
    857     cxy_t       joining_cxy;            // joining thread cluster
    858     pid_t       target_pid;             // target process PID
    859     cxy_t       owner_cxy;              // target process owner cluster
    860     trdid_t     target_trdid;           // target thread identifier
    861     ltid_t      target_ltid;            // target thread local index
    862     xptr_t      process_state_xp;       // extended pointer on <term_state> in process
    863 
    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 process
    870 
    871     // get target thread pointer and cluster
    872     target_cxy = GET_CXY( target_xp );
    873     target_ptr = GET_PTR( target_xp );
    874 
    875     // get killer thread pointers
    876     killer_ptr = CURRENT_THREAD;
    877     killer_xp  = XPTR( local_cxy , killer_ptr );
    878 
    879 #if DEBUG_THREAD_DELETE
    880 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 #endif
    885 
    886     // block the target thread
    887     thread_block( target_xp , THREAD_BLOCKED_GLOBAL );
    888 
    889     // get target thread attached mode
    890     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 thread
    894     // if the target thread is attached && not forced
    895 
    896     if( attached  && (is_forced == false) )
    897     {
    898         // build extended pointers on target thread join fields
    899         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 section
    903         hal_disable_irq( &save_sr );
    904 
    905         // take the join_lock in target thread descriptor
    906         remote_spinlock_lock( target_join_lock_xp );
    907 
    908         // get join_done from target thread descriptor
    909         join_done = ((hal_remote_lw( target_flags_xp ) & THREAD_FLAG_JOIN_DONE) != 0);
    910    
    911         if( join_done )     // joining thread arrived first
    912         {
    913             // get extended pointer on joining thread
    914             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 thread
    919             hal_remote_atomic_and( target_flags_xp , ~THREAD_FLAG_JOIN_DONE );
    920 
    921             // unblock the joining thread
    922             thread_unblock( joining_xp , THREAD_BLOCKED_JOIN );
    923 
    924             // release the join_lock in target thread descriptor
    925             remote_spinlock_unlock( target_join_lock_xp );
    926 
    927             // restore IRQs
    928             hal_restore_irq( save_sr );
    929         }
    930         else                // this thread arrived first
    931         {
    932             // set the kill_done flag in target thread
    933             hal_remote_atomic_or( target_flags_xp , THREAD_FLAG_KILL_DONE );
    934 
    935             // block this thread on BLOCKED_JOIN
    936             thread_block( killer_xp , THREAD_BLOCKED_JOIN );
    937 
    938             // set extended pointer on killer thread in target thread
    939             hal_remote_swd( target_join_xp_xp , killer_xp );
    940 
    941             // release the join_lock in target thread descriptor
    942             remote_spinlock_unlock( target_join_lock_xp );
    943 
    944             // deschedule
    945             sched_yield( "killer thread wait joining thread" );
    946 
    947             // restore IRQs
    948             hal_restore_irq( save_sr );
    949         }
    950     }  // end if attached
    951 
    952     // - if the target thread is the main thread
    953     //   => synchronize with the parent process main thread
    954     // - if the target thread is not the main thread
    955     //   => simply mark the target thread for delete
    956 
    957     // get pointer on target thread process
    958     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 cluster
    962         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 index
    966     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 thread
    970     {
    971         // get extended pointer on term_state in target process owner cluster
    972         process_state_xp = XPTR( owner_cxy , &target_process->term_state );
    973 
    974         // set termination info in target process owner 
    975         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_DELETE
    979 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 #endif
    984 
    985     }
    986     else                                                      // main thread
    987     {
    988         // set the REQ_DELETE flag in target thread descriptor
    989         hal_remote_atomic_or( target_flags_xp , THREAD_FLAG_REQ_DELETE );
    990 
    991 #if DEBUG_THREAD_DELETE
    992 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 #endif
    997 
    998     }
    999 
    1000 }  // end thread_kill()
    1001 
    1002 */
    1003863
    1004864//////////////////////////////////////
     
    1131991void thread_idle_func()
    1132992{
     993
     994#if DEBUG_THREAD_IDLE
     995uint32_t cycle;
     996#endif
     997
    1133998    while( 1 )
    1134999    {
     
    11401005        {
    11411006
    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)
    11531008cycle  = (uint32_t)hal_get_cycles;
    11541009if( DEBUG_THREAD_IDLE < cycle )
    1155 printk("\n[DBG] %s : idle thread %x on core[%x,%d] wake up / cycle %d\n",
     1010printk("\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)
     1017cycle  = (uint32_t)hal_get_cycles;
     1018if( DEBUG_THREAD_IDLE < cycle )
     1019printk("\n[DBG] %s : idle thread on core[%x,%d] wake up / cycle %d\n",
    11561020__FUNCTION__, this, local_cxy, this->core->lid, cycle );
    11571021#endif
    11581022
    11591023        }
     1024
     1025#if DEBUG_THREAD_IDLE
     1026sched_display( CURRENT_THREAD->core->lid );
     1027#endif     
    11601028
    11611029        // search a runable thread
Note: See TracChangeset for help on using the changeset viewer.