Changeset 651 for trunk/kernel/kern


Ignore:
Timestamp:
Nov 14, 2019, 11:50:09 AM (5 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.

Location:
trunk/kernel/kern
Files:
6 edited

Legend:

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

    r647 r651  
    929929///////////////////////////////////////////////////////////////////////////////////////////
    930930// This function is the entry point for the kernel initialisation.
    931 // It is executed by all cores in all clusters, but only core[0] initializes
     931// It is executed by all cores in all clusters, but only core[cxy][0] initializes
    932932// the shared resources such as the cluster manager, or the local peripherals.
    933933// To comply with the multi-kernels paradigm, it accesses only local cluster memory, using
     
    10171017    /////////////////////////////////////////////////////////////////////////////////
    10181018
    1019     // core[0] initialises DQDT (only core[0] in cluster 0 build the quad-tree)
     1019    // core[0] initialises DQDT (only core[0][0] build the quad-tree)
    10201020    if( core_lid == 0 ) dqdt_init();
    10211021   
  • trunk/kernel/kern/process.c

    r637 r651  
    916916            {
    917917                // mark target thread for delete and block it
    918                 thread_delete( target_xp , process->pid , false );   // not forced
     918                thread_delete( target_xp , true );                   // forced
    919919            }
    920920        }
     
    18021802    // allocates memory for process descriptor from local cluster
    18031803        process = process_alloc();
    1804 
    1805 
    18061804    if( process == NULL )
    18071805    {
  • trunk/kernel/kern/process.h

    r635 r651  
    122122typedef struct process_s
    123123{
    124         vmm_t              vmm;              /*! embedded virtual memory manager                 */
    125 
    126         fd_array_t         fd_array;         /*! embedded open file descriptors array            */
    127 
    128         xptr_t             vfs_root_xp;      /*! extended pointer on VFS root inode              */
    129         xptr_t             vfs_bin_xp;       /*! extended pointer on .elf file descriptor        */
    130         pid_t              pid;              /*! process identifier                              */
     124    vmm_t              vmm;              /*! embedded virtual memory manager                 */
     125
     126    fd_array_t         fd_array;         /*! embedded open file descriptors array            */
     127
     128    xptr_t             vfs_root_xp;      /*! extended pointer on VFS root inode              */
     129    xptr_t             vfs_bin_xp;       /*! extended pointer on .elf file descriptor        */
     130    pid_t              pid;              /*! process identifier                              */
    131131    xptr_t             ref_xp;           /*! extended pointer on reference process           */
    132132    xptr_t             owner_xp;         /*! extended pointer on owner process               */
    133133    xptr_t             parent_xp;        /*! extended pointer on parent process              */
    134134
    135         xptr_t             cwd_xp;           /*! extended pointer on current working dir inode   */
    136         remote_busylock_t  cwd_lock;         /*! lock protecting working directory changes       */
    137 
    138         xlist_entry_t      children_root;    /*! root of the children process xlist              */
     135    xptr_t             cwd_xp;           /*! extended pointer on current working dir inode   */
     136    remote_busylock_t  cwd_lock;         /*! lock protecting working directory changes       */
     137
     138    xlist_entry_t      children_root;    /*! root of the children process xlist              */
    139139    remote_queuelock_t children_lock;    /*! lock protecting children process xlist          */
    140140    uint32_t           children_nr;      /*! number of children processes                    */
    141141
    142         xlist_entry_t      children_list;    /*! member of list of children of same parent       */
     142    xlist_entry_t      children_list;    /*! member of list of children of same parent       */
    143143    xlist_entry_t      local_list;       /*! member of list of process in same cluster       */
    144144    xlist_entry_t      copies_list;      /*! member of list of copies of same process        */
    145145    xlist_entry_t      txt_list;         /*! member of list of processes sharing same TXT    */
    146146
    147         struct thread_s  * th_tbl[CONFIG_THREADS_MAX_PER_CLUSTER];       /*! local threads       */
    148 
    149         uint32_t           th_nr;            /*! number of threads in this cluster               */
     147    struct thread_s  * th_tbl[CONFIG_THREADS_MAX_PER_CLUSTER];       /*! local threads       */
     148
     149    uint32_t           th_nr;            /*! number of threads in this cluster               */
    150150    rwlock_t           th_lock;          /*! lock protecting th_tbl[]  i                     */
    151151
  • trunk/kernel/kern/scheduler.c

    r641 r651  
    493493#endif
    494494
    495 // This assert should never be false, as this check has been
     495// This assert should always be true, as this check has been
    496496// done before, by any function that can possibly deschedule...
    497497assert( (current->busylocks == 0),
    498 "unexpected descheduling of thread holding %d busylocks = %d\n", current->busylocks );
     498"current thread hold %d busylocks\n", current->busylocks );
    499499
    500500    // activate or create an RPC thread if RPC_FIFO non empty
     
    514514"kernel stack overflow for thread %x on core[%x,%d]", next, local_cxy, lid );
    515515
    516 // check next thread attached to same core as the calling thread
     516// check next thread attached to same core as the current thread
    517517assert( (next->core == current->core),
    518 "next core %x != current core %x", next->core, current->core );
    519 
     518"next_core_lid %d / current_core_lid %d", current->core->lid, next->core->lid );
     519   
    520520// check next thread not blocked when type != IDLE
    521521assert( ((next->blocked == 0) || (next->type == THREAD_IDLE)) ,
  • 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
  • trunk/kernel/kern/thread.h

    r647 r651  
    153153    remote_busylock_t   join_lock;       /*! lock protecting the join/exit            */
    154154    xptr_t              join_xp;         /*! joining/killer thread extended pointer   */
     155    void              * exit_status;     /*! status returned to joiniy thread        */
    155156
    156157    uint32_t          * ack_rsp_count;   /*! pointer on acknowledge response counter  */
     
    392393 ***************************************************************************************
    393394 * @ thread_xp   : extended pointer on the target thread.
    394  * @ pid         : process identifier (to get the owner cluster identifier).
    395395 * @ is_forced   : the deletion does not depends on the attached mode.
    396396 **************************************************************************************/
    397397void thread_delete( xptr_t  thread_xp,
    398                     pid_t   pid,
    399398                    bool_t  is_forced );
    400399
Note: See TracChangeset for help on using the changeset viewer.