Ignore:
Timestamp:
Jan 29, 2018, 6:08:07 PM (6 years ago)
Author:
alain
Message:

blip

File:
1 edited

Legend:

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

    r416 r428  
    8686
    8787    // release lock
     88    hal_fence();
    8889    spinlock_unlock( &sched->lock );
    8990
     
    181182    list_entry_t * iter;
    182183    thread_t     * thread;
    183 
    184 // printk("\n@@@ %s : current thread %x enter at cycle %d\n",
    185 // __FUNCTION__ , CURRENT_THREAD , hal_time_stamp() );
     184    process_t    * process;
    186185
    187186    scheduler_t  * sched = &core->scheduler;
     
    212211        if( thread->flags & THREAD_FLAG_REQ_DELETE )
    213212        {
    214 
    215 sched_dmsg("\n[DBG] %s : current thread %x delete thread %x at cycle %d\n",
    216 __FUNCTION__ , CURRENT_THREAD , thread , hal_time_stamp() );
     213            // get thread process descriptor
     214            process = thread->process;
    217215
    218216                // release FPU if required
     
    223221            thread_child_parent_unlink( thread->parent , XPTR( local_cxy , thread ) );
    224222
    225             // detach thread from process
    226             process_remove_thread( thread );
    227 
    228             // remove thread from scheduler
     223            // remove thread from scheduler (scheduler lock already taken)
     224            uint32_t threads_nr = sched->u_threads_nr;
     225            assert( (threads_nr != 0) , __FUNCTION__ , "u_threads_nr cannot be 0\n" );
     226            sched->u_threads_nr = threads_nr - 1;
    229227            list_unlink( &thread->sched_list );
    230             sched->u_threads_nr--;
    231             if( sched->u_threads_nr == 0 ) sched->u_last = NULL;
    232 
    233             // release memory allocated to thread
     228            if( threads_nr == 1 ) sched->u_last = NULL;
     229
     230            // delete thread
    234231            thread_destroy( thread );
    235232
     233sched_dmsg("\n[DBG] %s : thread %x deleted thread %x / cycle %d\n",
     234__FUNCTION__ , CURRENT_THREAD , thread , (uint32_t)hal_get_cycles() );
     235
    236236            // destroy process descriptor if no more threads
    237             if (thread->process->th_nr == 0) process_destroy( thread->process );
     237            if( process->th_nr == 0 )
     238            {
     239                // delete process   
     240                process_destroy( process );
     241
     242sched_dmsg("\n[DBG] %s : thread %x deleted process %x / cycle %d\n",
     243__FUNCTION__ , CURRENT_THREAD , process , (uint32_t)hal_get_cycles() );
     244
     245            }
    238246        }
    239247    }
    240248
    241249    // release lock
     250    hal_fence();
    242251    spinlock_unlock( &sched->lock );
    243 
    244 // printk("\n@@@ %s : current thread %x exit at cycle %d\n",
    245 // __FUNCTION__ , CURRENT_THREAD , hal_time_stamp() );
    246252
    247253} // end sched_handle_requests()
     
    277283
    278284    // check next thread not blocked when type != IDLE
    279     assert( (next->blocked == 0) || (next->type = THREAD_IDLE) , __FUNCTION__ ,
     285    assert( ((next->blocked == 0) || (next->type == THREAD_IDLE)) , __FUNCTION__ ,
    280286    "next thread %x (%s) is blocked on core[%x,%d]\n",
    281287    next->trdid , thread_type_str(next->type) , local_cxy , core->lid );
     
    310316    {
    311317
    312 sched_dmsg("\n[DBG] %s : core[%x,%d] / cause = %s\n"
     318#if( CONFIG_SCHED_DEBUG & 0x1 )
     319if( hal_time_stamp() > CONFIG_SCHED_DEBUG )
     320printk("\n[DBG] %s : core[%x,%d] / cause = %s\n"
    313321"      thread %x (%s) (%x,%x) continue / cycle %d\n",
    314322__FUNCTION__, local_cxy, core->lid, cause,
    315323current, thread_type_str(current->type), current->process->pid, current->trdid,
    316324(uint32_t)hal_get_cycles() );
     325#endif
    317326
    318327    }
     
    355364    remote_spinlock_lock_busy( lock_xp , &save_sr );
    356365
    357     nolock_printk("\n***** scheduler state for core[%x,%d] at cycle %d\n"
    358            "kernel_threads = %d / user_threads = %d / current = (%x,%x)\n",
    359             local_cxy , core->lid, hal_time_stamp(),
    360             sched->k_threads_nr, sched->u_threads_nr,
     366    nolock_printk("\n***** scheduler state for core[%x,%d] / cycle %d / current = (%x,%x)\n",
     367            local_cxy , core->lid, (uint32_t)hal_get_cycles(),
    361368            sched->current->process->pid , sched->current->trdid );
    362369
Note: See TracChangeset for help on using the changeset viewer.