Ignore:
Timestamp:
Nov 14, 2019, 11:50:09 AM (4 years ago)
Author:
alain
Message:

1) Improve the VMM MMAP allocator: implement the "buddy" algorithm
to allocate only aligned blocks.
2) fix a bug in the pthread_join() / pthread_exit() mmechanism.

File:
1 edited

Legend:

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

    r647 r651  
    673673uint32_t cycle = (uint32_t)hal_get_cycles();
    674674if( DEBUG_THREAD_USER_EXEC < cycle )
    675 printk("\n[%s] thread[%x,%x] enter / cycle %d\n",
    676 __FUNCTION__, process->pid, thread->trdid, cycle );
     675printk("\n[%s] thread[%x,%x] enter / entry %x / cycle %d\n",
     676__FUNCTION__, process->pid, thread->trdid, entry_func , cycle );
    677677#endif
    678678
     
    11051105//////////////////////////////////////
    11061106void thread_delete( xptr_t  target_xp,
    1107                     pid_t   pid,
    11081107                    bool_t  is_forced )
    11091108{
     
    11151114    cxy_t       target_cxy;             // target thread cluster     
    11161115    thread_t  * target_ptr;             // pointer on target thread
    1117     process_t * target_process;         // pointer on arget process
     1116    process_t * target_process;         // pointer on target process
    11181117    pid_t       target_pid;             // target process identifier
    11191118    xptr_t      target_flags_xp;        // extended pointer on target thread <flags>
     
    11221121    trdid_t     target_trdid;           // target thread identifier
    11231122    ltid_t      target_ltid;            // target thread local index
     1123    uint32_t    target_flags;           // target thread flags
    11241124    xptr_t      joining_xp;             // extended pointer on joining thread
     1125    thread_t  * joining_ptr;            // local pointer on joining thread
     1126    cxy_t       joining_cxy;            // joining thread cluster
    11251127
    11261128    // get target thread cluster and local pointer
     
    11281130    target_ptr      = GET_PTR( target_xp );
    11291131
    1130     // get target thread identifier, attached flag, and process PID
     1132    // get target thread trdid, ltid, flags, and process PID
    11311133    target_trdid    = hal_remote_l32( XPTR( target_cxy , &target_ptr->trdid ) );
    11321134    target_ltid     = LTID_FROM_TRDID( target_trdid );
    1133     target_flags_xp = XPTR( target_cxy , &target_ptr->flags ); 
    1134     target_attached = ( (hal_remote_l32( target_flags_xp ) & THREAD_FLAG_DETACHED) == 0 );
     1135    target_flags_xp = XPTR( target_cxy , &target_ptr->flags );
     1136    target_flags    = hal_remote_l32( target_flags_xp );
    11351137    target_process  = hal_remote_lpt( XPTR( target_cxy , &target_ptr->process ) );
    11361138    target_pid      = hal_remote_l32( XPTR( target_cxy , &target_process->pid ) );
    1137 
    1138 // check target PID
    1139 assert( (pid == target_pid),
    1140 "unconsistent pid and target_xp arguments" );
     1139    target_attached = ((target_flags & THREAD_FLAG_DETACHED) == 0);
    11411140
    11421141    // get killer thread pointers
     
    11471146uint32_t cycle  = (uint32_t)hal_get_cycles();
    11481147if( DEBUG_THREAD_DELETE < cycle )
    1149 printk("\n[%s] killer[%x,%x] enters / target[%x,%x] / cycle %d\n",
     1148printk("\n[%s] killer[%x,%x] enters / target[%x,%x] / forced %d / flags %x / cycle %d\n",
    11501149__FUNCTION__, killer_ptr->process->pid, killer_ptr->trdid, 
    1151 target_ptr->process->pid, target_ptr->trdid, cycle );
     1150target_pid, target_trdid, is_forced, target_flags, cycle );
    11521151#endif
    11531152
    11541153// check target thread is not the main thread, because the main thread
    11551154// must be deleted by the parent process sys_wait() function
    1156 assert( ((CXY_FROM_PID( pid ) != target_cxy) || (target_ltid != 0)),
     1155assert( ((CXY_FROM_PID( target_pid ) != target_cxy) || (target_ltid != 0)),
    11571156"target thread cannot be the main thread" );
    11581157
     
    11821181            // get extended pointer on joining thread
    11831182            joining_xp  = (xptr_t)hal_remote_l64( target_join_xp_xp );
     1183
     1184            // get cluster and local pointer on joining thread
     1185            joining_ptr = GET_PTR( joining_xp );
     1186            joining_cxy = GET_CXY( joining_xp );
     1187
     1188            // copy exit_status from target thread to joining thread, because
     1189            // target thread may be deleted before joining thread resume
     1190            void * status = hal_remote_lpt( XPTR( target_cxy , &target_ptr->exit_status ) );
     1191            hal_remote_spt( XPTR( joining_cxy , &joining_ptr->exit_status ) , status );
    11841192           
    11851193            // reset the join_done flag in target thread
     
    12021210
    12031211#if DEBUG_THREAD_DELETE
    1204 cycle  = (uint32_t)hal_get_cycles;
     1212cycle  = (uint32_t)hal_get_cycles();
    12051213if( DEBUG_THREAD_DELETE < cycle )
    12061214printk("\n[%s] killer[%x,%x] exit / target[%x,%x] marked after join / cycle %d\n",
    12071215__FUNCTION__, killer_ptr->process->pid, killer_ptr->trdid,
    1208 target_ptr->process->pid, target_ptr->trdid, cycle );
     1216target_pid, target_trdid, cycle );
    12091217#endif
    12101218
     
    12151223            hal_remote_atomic_or( target_flags_xp , THREAD_FLAG_KILL_DONE );
    12161224
    1217             // block this thread on BLOCKED_JOIN
     1225            // block target thread on BLOCKED_JOIN
    12181226            thread_block( killer_xp , THREAD_BLOCKED_JOIN );
    12191227
     
    12251233
    12261234#if DEBUG_THREAD_DELETE
    1227 cycle  = (uint32_t)hal_get_cycles;
     1235cycle  = (uint32_t)hal_get_cycles();
    12281236if( DEBUG_THREAD_DELETE < cycle )
    12291237printk("\n[%s] killer[%x,%x] deschedules / target[%x,%x] not completed / cycle %d\n",
    12301238__FUNCTION__, killer_ptr->process->pid, killer_ptr->trdid,
    1231 target_ptr->process->pid, target_ptr->trdid, cycle );
     1239target_pid, target_trdid, cycle );
    12321240#endif
    12331241            // deschedule
     
    12441252
    12451253#if DEBUG_THREAD_DELETE
    1246 cycle  = (uint32_t)hal_get_cycles;
     1254cycle  = (uint32_t)hal_get_cycles();
    12471255if( DEBUG_THREAD_DELETE < cycle )
    12481256printk("\n[%s] killer[%x,%x] exit / target[%x,%x] marked after join / cycle %d\n",
    12491257__FUNCTION__, killer_ptr->process->pid, killer_ptr->trdid,
    1250 target_ptr->process->pid, target_ptr->trdid, cycle );
     1258target_pid, target_trdid, cycle );
    12511259#endif
    12521260
     
    12621270
    12631271#if DEBUG_THREAD_DELETE
    1264 cycle  = (uint32_t)hal_get_cycles;
     1272cycle  = (uint32_t)hal_get_cycles();
    12651273if( DEBUG_THREAD_DELETE < cycle )
    12661274printk("\n[%s] killer[%x,%x] exit / target [%x,%x] marked / no join / cycle %d\n",
    12671275__FUNCTION__, killer_ptr->process->pid, killer_ptr->trdid,
    1268 target_ptr->process->pid, target_ptr->trdid, cycle );
     1276target_pid, target_trdid, cycle );
    12691277#endif
    12701278
Note: See TracChangeset for help on using the changeset viewer.