Ignore:
Timestamp:
Dec 5, 2017, 4:20:07 PM (6 years ago)
Author:
alain
Message:

Fix several bugs in the fork() syscall.

File:
1 edited

Legend:

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

    r407 r408  
    128128}  // end sched_remove()
    129129
    130 ////////////////////////////////////////
    131 thread_t * sched_select( core_t * core )
    132 {
    133     thread_t    * thread;
    134 
    135     scheduler_t * sched = &core->scheduler;
     130//////////////////////////////////////////////
     131thread_t * sched_select( scheduler_t * sched )
     132{
     133    thread_t     * thread;
     134    list_entry_t * current;
     135    list_entry_t * last;
    136136
    137137    // take lock protecting sheduler lists
    138138    spinlock_lock( &sched->lock );
    139 
    140     list_entry_t * current;
    141     list_entry_t * last;
    142139
    143140    // first loop : scan the kernel threads list if not empty
     
    172169                break;
    173170
    174                 default:          // DEV thread if non blocked
    175                 if( thread->blocked == 0 )
     171                default:          // DEV thread if non blocked and waiting queue non empty
     172                if( (thread->blocked == 0) &&
     173                    (xlist_is_empty( XPTR( local_cxy , &thread->chdev->wait_root)) == 0) )
    176174                {
    177175                    spinlock_unlock( &sched->lock );
     
    253251    scheduler_t  * sched = &core->scheduler;
    254252
     253// signal_dmsg("\n@@@ %s enter at cycle %d\n",
     254// __FUNCTION__ , hal_time_stamp() );
     255
    255256    // take lock protecting threads lists
    256257    spinlock_lock( &sched->lock );
     
    260261    {
    261262        thread = LIST_ELEMENT( iter , thread_t , sched_list );
    262         if( thread->signals ) sched_kill_thread( thread );
     263        if( thread->signals ) // sched_kill_thread( thread );
     264        {
     265            printk("\n[WARNING] %s : thread %x has signal %x at cycle %d\n",
     266            __FUNCTION__, thread, thread->signals, hal_time_stamp() );
     267        }
    263268    }
    264269
     
    267272    {
    268273        thread = LIST_ELEMENT( iter , thread_t , sched_list );
    269         if( thread->signals ) sched_kill_thread( thread );
     274        if( thread->signals )  // sched_kill_thread( thread );
     275        {
     276            printk("\n[WARNING] %s : thread %x has signal %x at cycle %d\n",
     277            __FUNCTION__, thread, thread->signals, hal_time_stamp() );
     278
     279        }
    270280    }
    271281
     
    273283    spinlock_unlock( &sched->lock );
    274284
     285// signal_dmsg("\n@@@ %s exit at cycle %d\n",
     286// __FUNCTION__ , hal_time_stamp() );
     287
    275288} // end sched_handle_signals()
    276289
    277 //////////////////////////////////////
    278 void sched_update( thread_t * current,
    279                    thread_t * next )
    280 {
    281     scheduler_t * sched = &current->core->scheduler;
    282 
    283     if( current->type == THREAD_USER ) sched->u_last = &current->sched_list;
    284     else                               sched->k_last = &current->sched_list;
    285 
    286     sched->current = next;
    287 }
    288 
    289 //////////////////
    290 void sched_yield()
     290////////////////////////////////
     291void sched_yield( char * cause )
    291292{
    292293    thread_t    * next;
    293294    thread_t    * current = CURRENT_THREAD;
     295    scheduler_t * sched   = &current->core->scheduler;
    294296 
    295297#if( CONFIG_SCHED_DEBUG & 0x1 )
     
    304306    }
    305307
     308    // enter critical section / save SR in current thread context
     309    hal_disable_irq( &current->save_sr );
     310
    306311    // loop on threads to select next thread
    307     next = sched_select( current->core );
     312    next = sched_select( sched );
    308313
    309314    // check next thread attached to same core as the calling thread
     
    319324        if( next != current )
    320325    {
    321         // current thread desactivate IRQs
    322         hal_disable_irq( &switch_save_sr[CURRENT_THREAD->core->lid] );
    323 
    324 sched_dmsg("\n[DBG] %s : core[%x,%d] / trd %x (%s) (%x,%x) => trd %x (%s) (%x,%x) / cycle %d\n",
    325 __FUNCTION__, local_cxy, current->core->lid,
     326
     327sched_dmsg("\n[DBG] %s : core[%x,%d] / cause = %s\n"
     328"      thread %x (%s) (%x,%x) => thread %x (%s) (%x,%x) / cycle %d\n",
     329__FUNCTION__, local_cxy, current->core->lid, cause,
    326330current, thread_type_str(current->type), current->process->pid, current->trdid,
    327331next   , thread_type_str(next->type)   , next->process->pid   , next->trdid,
    328 hal_time_stamp() );
     332(uint32_t)hal_get_cycles() );
    329333
    330334        // update scheduler
    331         sched_update( current , next );
     335        sched->current = next;
     336        if( next->type == THREAD_USER ) sched->u_last = &next->sched_list;
     337        else                            sched->k_last = &next->sched_list;
    332338
    333339        // handle FPU ownership
     
    340346        // switch CPU from calling thread context to new thread context
    341347        hal_do_cpu_switch( current->cpu_context, next->cpu_context );
    342 
    343         // restore IRQs when next thread resume
    344         hal_restore_irq( switch_save_sr[CURRENT_THREAD->core->lid] );
    345348    }
    346349    else
    347350    {
    348351
    349 sched_dmsg("\n[DBG] %s : core[%x,%d] / thread %x (%s) continue / cycle %d\n",
    350 __FUNCTION__, local_cxy, current->core->lid, current->trdid,
    351 thread_type_str(current->type) ,hal_time_stamp() );
    352 
    353     }
     352sched_dmsg("\n[DBG] %s : core[%x,%d] / cause = %s\n"
     353"      thread %x (%s) (%x,%x) continue / cycle %d\n",
     354__FUNCTION__, local_cxy, current->core->lid, cause,
     355current, thread_type_str(current->type), current->process->pid, current->trdid,
     356(uint32_t)hal_get_cycles() );
     357
     358    }
     359
     360    // exit critical section / restore SR from next thread context
     361    hal_restore_irq( next->save_sr );
     362
    354363}  // end sched_yield()
    355364
     
    384393
    385394    nolock_printk("\n***** scheduler state for core[%x,%d] at cycle %d\n"
    386            "kernel_threads = %d / user_threads = %d / current = %x / idle = %x\n",
     395           "kernel_threads = %d / user_threads = %d / current = (%x,%x)\n",
    387396            local_cxy , core->lid, hal_time_stamp(),
    388397            sched->k_threads_nr, sched->u_threads_nr,
    389             sched->current->trdid , sched->idle->trdid );
     398            sched->current->process->pid , sched->current->trdid );
    390399
    391400    // display kernel threads
     
    393402    {
    394403        thread = LIST_ELEMENT( iter , thread_t , sched_list );
    395         nolock_printk(" - type = %s / trdid = %X / pid = %X / func = %X / blocked = %X\n",
    396         thread_type_str( thread->type ), thread->trdid, thread->process->pid,
    397         thread->entry_func, thread->blocked );
     404        if (thread->type == THREAD_DEV)
     405        {
     406            nolock_printk(" - %s / pid %X / trdid %X / desc %X / blocked %X / %s\n",
     407            thread_type_str( thread->type ), thread->process->pid, thread->trdid,
     408            thread, thread->blocked , thread->chdev->name );
     409        }
     410        else
     411        {
     412            nolock_printk(" - %s / pid %X / trdid %X / desc %X / blocked %X\n",
     413            thread_type_str( thread->type ), thread->process->pid, thread->trdid,
     414            thread, thread->blocked );
     415        }
    398416    }
    399417
     
    402420    {
    403421        thread = LIST_ELEMENT( iter , thread_t , sched_list );
    404         nolock_printk(" - type = %s / trdid = %X / pid = %X / func = %X / blocked = %X\n",
    405         thread_type_str( thread->type ), thread->trdid, thread->process->pid,
    406         thread->entry_func, thread->blocked );
     422        nolock_printk(" - %s / pid %X / trdid %X / desc %X / blocked %X\n",
     423        thread_type_str( thread->type ), thread->process->pid, thread->trdid,
     424        thread, thread->blocked );
    407425    }
    408426
Note: See TracChangeset for help on using the changeset viewer.