Ignore:
Timestamp:
Apr 4, 2018, 2:49:02 PM (4 years ago)
Author:
alain
Message:

Fix a bug in scheduler related to RPC blocking.

File:
1 edited

Legend:

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

    r436 r438  
    112112/////////////////////////////////////////////////////////////////////////////////////
    113113// This static function initializes a thread descriptor (kernel or user).
    114 // It can be called by the three functions:
     114// It can be called by the four functions:
    115115// - thread_user_create()
    116116// - thread_user_fork()
    117117// - thread_kernel_create()
     118// - thread_idle_init()
     119// It updates the local DQDT.
    118120/////////////////////////////////////////////////////////////////////////////////////
    119121// @ thread       : pointer on thread descriptor
     
    202204    thread->save_sr = 0xFF13;
    203205
    204     // update local DQDT
    205     dqdt_local_update_threads( 1 );
    206 
    207206    // register new thread in core scheduler
    208207    sched_register_thread( thread->core , thread );
     208
     209        // update DQDT
     210    dqdt_update_threads( 1 );
    209211
    210212        return 0;
     
    227229    assert( (attr != NULL) , __FUNCTION__, "pthread attributes must be defined" );
    228230
    229 #if CONFIG_DEBUG_THREAD_USER_CREATE
     231#if DEBUG_THREAD_USER_CREATE
    230232uint32_t cycle = (uint32_t)hal_get_cycles();
    231 if( CONFIG_DEBUG_THREAD_USER_CREATE < cycle )
     233if( DEBUG_THREAD_USER_CREATE < cycle )
    232234printk("\n[DBG] %s : thread %x enter / process %x / cycle %d\n",
    233235__FUNCTION__, CURRENT_THREAD, pid , cycle );
     
    326328    }
    327329
    328         // update DQDT for new thread
    329     dqdt_local_update_threads( 1 );
    330 
    331 #if CONFIG_DEBUG_THREAD_USER_CREATE
     330#if DEBUG_THREAD_USER_CREATE
    332331cycle = (uint32_t)hal_get_cycles();
    333 if( CONFIG_DEBUG_THREAD_USER_CREATE < cycle )
     332if( DEBUG_THREAD_USER_CREATE < cycle )
    334333printk("\n[DBG] %s : thread %x exit / process %x / new_thread %x / core %d / cycle %d\n",
    335334__FUNCTION__, CURRENT_THREAD, pid, thread, core_lid, cycle );
     
    366365    vseg_t       * vseg;             // child thread STACK vseg
    367366
    368 #if CONFIG_DEBUG_THREAD_USER_FORK
     367#if DEBUG_THREAD_USER_FORK
    369368uint32_t cycle = (uint32_t)hal_get_cycles();
    370 if( CONFIG_DEBUG_THREAD_USER_FORK < cycle )
     369if( DEBUG_THREAD_USER_FORK < cycle )
    371370printk("\n[DBG] %s : thread %x enter / child_process %x / cycle %d\n",
    372371__FUNCTION__, CURRENT_THREAD, child_process->pid, cycle );
     
    493492            hal_remote_atomic_add( XPTR( page_cxy , &page_ptr->forks ) , 1 );
    494493
    495 #if (CONFIG_DEBUG_THREAD_USER_FORK & 1)
     494#if (DEBUG_THREAD_USER_FORK & 1)
    496495cycle = (uint32_t)hal_get_cycles();
    497 if( CONFIG_DEBUG_THREAD_USER_FORK < cycle )
     496if( DEBUG_THREAD_USER_FORK < cycle )
    498497printk("\n[DBG] %s : thread %x copied stack PTE to child GPT : vpn %x\n",
    499498__FUNCTION__, CURRENT_THREAD, vpn );
     
    508507                     vpn_size );
    509508 
    510         // update DQDT for child thread
    511     dqdt_local_update_threads( 1 );
    512 
    513 #if CONFIG_DEBUG_THREAD_USER_FORK
     509#if DEBUG_THREAD_USER_FORK
    514510cycle = (uint32_t)hal_get_cycles();
    515 if( CONFIG_DEBUG_THREAD_USER_FORK < cycle )
     511if( DEBUG_THREAD_USER_FORK < cycle )
    516512printk("\n[DBG] %s : thread %x exit / child_process %x / child_thread %x / cycle %d\n",
    517513__FUNCTION__, CURRENT_THREAD, child_process->pid, child_ptr, cycle );
     
    538534            __FUNCTION__ , "illegal core_lid" );
    539535
    540 #if CONFIG_DEBUG_THREAD_KERNEL_CREATE
     536#if DEBUG_THREAD_KERNEL_CREATE
    541537uint32_t cycle = (uint32_t)hal_get_cycles();
    542 if( CONFIG_DEBUG_THREAD_KERNEL_CREATE < cycle )
     538if( DEBUG_THREAD_KERNEL_CREATE < cycle )
    543539printk("\n[DBG] %s : thread %x enter / requested_type %s / cycle %d\n",
    544540__FUNCTION__, CURRENT_THREAD, thread, thread_type_str(type), cycle );
     
    568564        hal_cpu_context_create( thread );
    569565
    570         // update DQDT for kernel thread
    571     dqdt_local_update_threads( 1 );
    572 
    573 #if CONFIG_DEBUG_THREAD_KERNEL_CREATE
     566#if DEBUG_THREAD_KERNEL_CREATE
    574567cycle = (uint32_t)hal_get_cycles();
    575 if( CONFIG_DEBUG_THREAD_KERNEL_CREATE < cycle )
     568if( DEBUG_THREAD_KERNEL_CREATE < cycle )
    576569printk("\n[DBG] %s : thread %x exit / new_thread %x / type %s / cycle %d\n",
    577570__FUNCTION__, CURRENT_THREAD, thread, thread_type_str(type), cycle );
     
    583576} // end thread_kernel_create()
    584577
    585 ///////////////////////////////////////////////////
    586 error_t thread_kernel_init( thread_t      * thread,
    587                             thread_type_t   type,
    588                             void          * func,
    589                             void          * args,
    590                                             lid_t           core_lid )
     578/////////////////////////////////////////////////
     579error_t thread_idle_init( thread_t      * thread,
     580                          thread_type_t   type,
     581                          void          * func,
     582                          void          * args,
     583                                          lid_t           core_lid )
    591584{
    592585    assert( (type == THREAD_IDLE) , __FUNCTION__ , "illegal thread type" );
     
    607600    return error;
    608601
    609 }  // end thread_kernel_init()
     602}  // end thread_idle_init()
    610603
    611604///////////////////////////////////////////////////////////////////////////////////////
     
    620613    core_t     * core       = thread->core;
    621614
    622 #if CONFIG_DEBUG_THREAD_DESTROY
     615#if DEBUG_THREAD_DESTROY
    623616uint32_t cycle = (uint32_t)hal_get_cycles();
    624 if( CONFIG_DEBUG_THREAD_DESTROY < cycle )
     617if( DEBUG_THREAD_DESTROY < cycle )
    625618printk("\n[DBG] %s : thread %x enter to destroy thread %x in process %x / cycle %d\n",
    626619__FUNCTION__, CURRENT_THREAD, thread, process->pid, cycle );
     
    652645    process_remove_thread( thread );
    653646       
    654     // update local DQDT
    655     dqdt_local_update_threads( -1 );
     647    // update DQDT
     648    dqdt_update_threads( -1 );
    656649
    657650    // invalidate thread descriptor
     
    661654    thread_release( thread );
    662655
    663 #if CONFIG_DEBUG_THREAD_DESTROY
     656#if DEBUG_THREAD_DESTROY
    664657cycle = (uint32_t)hal_get_cycles();
    665 if( CONFIG_DEBUG_THREAD_DESTROY < cycle )
     658if( DEBUG_THREAD_DESTROY < cycle )
    666659printk("\n[DBG] %s : thread %x exit / destroyed thread %x in process %x / cycle %d\n",
    667660__FUNCTION__, CURRENT_THREAD, thread, process->pid, cycle );
     
    811804    hal_fence();
    812805
    813 #if CONFIG_DEBUG_THREAD_BLOCK
     806#if DEBUG_THREAD_BLOCK
    814807uint32_t cycle = (uint32_t)hal_get_cycles();
    815 if( CONFIG_DEBUG_THREAD_BLOCK < cycle )
     808if( DEBUG_THREAD_BLOCK < cycle )
    816809printk("\n[DBG] %s : thread %x blocked thread %x / cause %x / cycle %d\n",
    817810__FUNCTION__ , CURRENT_THREAD , ptr , cause , cycle );
    818811#endif
    819812
    820 #if (CONFIG_DEBUG_THREAD_BLOCK & 1)
    821 if( CONFIG_DEBUG_THREAD_BLOCK < cycle )
     813#if (DEBUG_THREAD_BLOCK & 1)
     814if( DEBUG_THREAD_BLOCK < cycle )
    822815sched_display( ptr->core->lid );
    823816#endif
     
    837830    hal_fence();
    838831
    839 #if CONFIG_DEBUG_THREAD_BLOCK
     832#if DEBUG_THREAD_BLOCK
    840833uint32_t cycle = (uint32_t)hal_get_cycles();
    841 if( CONFIG_DEBUG_THREAD_BLOCK < cycle )
     834if( DEBUG_THREAD_BLOCK < cycle )
    842835printk("\n[DBG] %s : thread %x unblocked thread %x / cause %x / cycle %d\n",
    843836__FUNCTION__ , CURRENT_THREAD , ptr , cause , cycle );
    844837#endif
    845838
    846 #if (CONFIG_DEBUG_THREAD_BLOCK & 1)
    847 if( CONFIG_DEBUG_THREAD_BLOCK < cycle )
     839#if (DEBUG_THREAD_BLOCK & 1)
     840if( DEBUG_THREAD_BLOCK < cycle )
    848841sched_display( ptr->core->lid );
    849842#endif
     
    890883    killer_xp  = XPTR( local_cxy , killer_ptr );
    891884
    892 #if CONFIG_DEBUG_THREAD_KILL
     885#if DEBUG_THREAD_KILL
    893886uint32_t cycle  = (uint32_t)hal_get_cycles;
    894 if( CONFIG_DEBUG_THREAD_KILL < cycle )
     887if( DEBUG_THREAD_KILL < cycle )
    895888printk("\n[DBG] %s : thread %x enter for target thread %x / cycle %d\n",
    896889__FUNCTION__, killer_ptr, target_ptr, cycle );
     
    989982        else          hal_remote_atomic_or( process_state_xp , PROCESS_TERM_KILL );
    990983
    991 #if CONFIG_DEBUG_THREAD_KILL
     984#if DEBUG_THREAD_KILL
    992985cycle  = (uint32_t)hal_get_cycles;
    993 if( CONFIG_DEBUG_THREAD_KILL < cycle )
     986if( DEBUG_THREAD_KILL < cycle )
    994987printk("\n[DBG] %s : thread %x exit for thread %x / main thread / cycle %d\n",
    995988__FUNCTION__, killer_ptr, target_ptr, cycle );
     
    1002995        hal_remote_atomic_or( target_flags_xp , THREAD_FLAG_REQ_DELETE );
    1003996
    1004 #if CONFIG_DEBUG_THREAD_KILL
     997#if DEBUG_THREAD_KILL
    1005998cycle  = (uint32_t)hal_get_cycles;
    1006 if( CONFIG_DEBUG_THREAD_KILL < cycle )
     999if( DEBUG_THREAD_KILL < cycle )
    10071000printk("\n[DBG] %s : thread %x exit for thread %x / not the main thread / cycle %d\n",
    10081001__FUNCTION__, killer_ptr, target_ptr, cycle );
     
    10241017        {
    10251018
    1026 #if CONFIG_DEBUG_THREAD_IDLE
     1019#if DEBUG_THREAD_IDLE
    10271020uint32_t cycle  = (uint32_t)hal_get_cycles;
    10281021thread_t * this = CURRENT_THREAD;
    1029 if( CONFIG_DEBUG_THREAD_IDLE < cycle )
     1022if( DEBUG_THREAD_IDLE < cycle )
    10301023printk("\n[DBG] %s : idle thread %x on core[%x,%d] goes to sleep / cycle %d\n",
    10311024__FUNCTION__, this, local_cxy, this->core->lid, cycle );
     
    10341027            hal_core_sleep();
    10351028
    1036 #if CONFIG_DEBUG_THREAD_IDLE
     1029#if DEBUG_THREAD_IDLE
    10371030cycle  = (uint32_t)hal_get_cycles;
    1038 if( CONFIG_DEBUG_THREAD_IDLE < cycle )
     1031if( DEBUG_THREAD_IDLE < cycle )
    10391032printk("\n[DBG] %s : idle thread %x on core[%x,%d] wake up / cycle %d\n",
    10401033__FUNCTION__, this, local_cxy, this->core->lid, cycle );
Note: See TracChangeset for help on using the changeset viewer.