Ignore:
Timestamp:
May 16, 2018, 4:15:22 PM (7 years ago)
Author:
alain
Message:

Fix few bugs whike debugging the sort multi-thread application.

File:
1 edited

Legend:

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

    r440 r443  
    3434#include <scheduler.h>
    3535
     36
    3637///////////////////////////////////////////////////////////////////////////////////////////
    3738// Extern global variables
    3839///////////////////////////////////////////////////////////////////////////////////////////
    3940
    40 extern chdev_directory_t    chdev_dir;            // allocated in kernel_init.c file
    41 extern uint32_t             switch_save_sr[];     // allocated in kernel_init.c file
     41uint32_t   idle_thread_count;
     42uint32_t   idle_thread_count_active;
     43
     44extern chdev_directory_t    chdev_dir;          // allocated in kernel_init.c file
     45extern uint32_t             switch_save_sr[];   // allocated in kernel_init.c file
    4246
    4347////////////////////////////////
     
    5054
    5155    sched->current        = CURRENT_THREAD;
    52     sched->idle           = NULL;             // initialized in kernel_init()
    53     sched->u_last         = NULL;             // initialized in sched_register_thread()
    54     sched->k_last         = NULL;             // initialized in sched_register_thread()
     56    sched->idle           = NULL;               // initialized in kernel_init()
     57    sched->u_last         = NULL;               // initialized in sched_register_thread()
     58    sched->k_last         = NULL;               // initialized in sched_register_thread()
    5559
    5660    // initialise threads lists
     
    5862    list_root_init( &sched->k_root );
    5963
    60     sched->req_ack_pending = false;           // no pending request
     64    sched->req_ack_pending = false;             // no pending request
     65    sched->trace           = false;             // context switches trace desactivated
    6166
    6267}  // end sched_init()
     
    179184    thread_t     * thread;
    180185    process_t    * process;
     186    bool_t         last_thread;
    181187
    182188    // get pointer on scheduler
     
    237243
    238244            // delete thread
    239             thread_destroy( thread );
     245            last_thread = thread_destroy( thread );
    240246
    241247#if DEBUG_SCHED_HANDLE_SIGNALS
    242248uint32_t cycle = (uint32_t)hal_get_cycles();
    243249if( DEBUG_SCHED_HANDLE_SIGNALS < cycle )
    244 printk("\n[DBG] %s : thread %x in proces %x (%x) deleted / cycle %d\n",
    245 __FUNCTION__ , thread , process->pid , process , cycle );
     250printk("\n[DBG] %s : thread %x in proces %x on core[%x,%d] deleted / cycle %d\n",
     251__FUNCTION__ , thread->trdid , process->pid , local_cxy , thread->core->lid , cycle );
    246252#endif
    247253            // destroy process descriptor if no more threads
    248             if( process->th_nr == 0 )
     254            if( last_thread )
    249255            {
    250256                // delete process   
     
    254260cycle = (uint32_t)hal_get_cycles();
    255261if( DEBUG_SCHED_HANDLE_SIGNALS < cycle )
    256 printk("\n[DBG] %s : process %x has been deleted / cycle %d\n",
    257 __FUNCTION__ , process->pid , cycle );
     262printk("\n[DBG] %s : process %x in cluster %x deleted / cycle %d\n",
     263__FUNCTION__ , process->pid , local_cxy , cycle );
    258264#endif
    259265
     
    277283 
    278284#if (DEBUG_SCHED_YIELD & 0x1)
    279 if( DEBUG_SCHED_YIELD < (uint32_t)hal_get_cycles() )
     285if( sched->trace )
    280286sched_display( core->lid );
    281287#endif
     
    295301
    296302    // check next thread kernel_stack overflow
    297     assert( (next->signature == THREAD_SIGNATURE),
    298     __FUNCTION__ , "kernel stack overflow for thread %x\n", next );
     303    assert( (next->signature == THREAD_SIGNATURE), __FUNCTION__ ,
     304    "kernel stack overflow for thread %x on core[%x,%d] \n", next, local_cxy, core->lid );
    299305
    300306    // check next thread attached to same core as the calling thread
    301     assert( (next->core == current->core),
    302     __FUNCTION__ , "next core %x != current core %x\n", next->core, current->core );
     307    assert( (next->core == current->core), __FUNCTION__ ,
     308    "next core %x != current core %x\n", next->core, current->core );
    303309
    304310    // check next thread not blocked when type != IDLE
     
    311317    {
    312318
    313 if( (local_cxy == 0X1) && (core->lid == 1) && ((uint32_t)current == 0xcc000) )
    314 printk("\n@@@@@ cc000 exit at cycle %d\n", (uint32_t)hal_get_cycles() );
    315 
    316 if( (local_cxy == 0X1) && (core->lid == 1) && ((uint32_t)next == 0xcc000) )
    317 printk("\n@@@@@ cc000 enter at cycle %d\n", (uint32_t)hal_get_cycles() );
    318 
    319319#if DEBUG_SCHED_YIELD
    320 uint32_t cycle = (uint32_t)hal_get_cycles();
    321 if( DEBUG_SCHED_YIELD < cycle )
     320if( sched->trace )
    322321printk("\n[DBG] %s : core[%x,%d] / cause = %s\n"
    323322"      thread %x (%s) (%x,%x) => thread %x (%s) (%x,%x) / cycle %d\n",
    324323__FUNCTION__, local_cxy, core->lid, cause,
    325 current, thread_type_str(current->type), current->process->pid, current->trdid,
    326 next , thread_type_str(next->type) , next->process->pid , next->trdid , cycle );
     324current, thread_type_str(current->type), current->process->pid, current->trdid,next ,
     325thread_type_str(next->type) , next->process->pid , next->trdid , (uint32_t)hal_get_cycles() );
    327326#endif
    328327
     
    345344    {
    346345
    347 #if (DEBUG_SCHED_YIELD & 1)
    348 uint32_t cycle = (uint32_t)hal_get_cycles();
    349 if( DEBUG_SCHED_YIELD < cycle )
     346#if DEBUG_SCHED_YIELD
     347if( sched->trace )
    350348printk("\n[DBG] %s : core[%x,%d] / cause = %s\n"
    351349"      thread %x (%s) (%x,%x) continue / cycle %d\n",
    352 __FUNCTION__, local_cxy, core->lid, cause,
    353 current, thread_type_str(current->type), current->process->pid, current->trdid, cycle );
     350__FUNCTION__, local_cxy, core->lid, cause, current, thread_type_str(current->type),
     351current->process->pid, current->trdid, (uint32_t)hal_get_cycles() );
    354352#endif
    355353
     
    389387
    390388    nolock_printk("\n***** threads on core[%x,%d] / current %x / cycle %d\n",
    391             local_cxy , core->lid, sched->current, (uint32_t)hal_get_cycles() );
     389    local_cxy , core->lid, sched->current, (uint32_t)hal_get_cycles() );
    392390
    393391    // display kernel threads
Note: See TracChangeset for help on using the changeset viewer.