Changeset 443


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.

Location:
trunk
Files:
33 edited

Legend:

Unmodified
Added
Removed
  • trunk/Makefile

    r440 r443  
    4141                user/ksh/build/ksh.elf             \
    4242                user/pgdc/build/pgcd.elf           \
    43                 user/hello/build/hello.elf         \
     43                user/idbg/build/idbg.elf           \
    4444                user/sort/build/sort.elf
    4545
     
    6363         user/ksh/build/ksh.elf            \
    6464         user/pgcd/build/pgcd.elf          \
    65          user/hello/build/hello.elf        \
     65         user/idbg/build/idbg.elf          \
    6666         user/sort/build/sort.elf          \
    6767         list
     
    9494        $(MAKE) -C user/sort clean
    9595        $(MAKE) -C user/pgcd clean
    96         $(MAKE) -C user/hello clean
     96        $(MAKE) -C user/idbg clean
    9797        $(MAKE) -C $(HAL_ARCH) clean
    9898
     
    164164        $(MAKE) -C user/pgcd
    165165        mcopy -o -i $(DISK_IMAGE) $@ ::/bin/user
    166 user/hello/build/hello.elf: build_libs
    167         $(MAKE) -C user/hello
     166user/idbg/build/idbg.elf: build_libs
     167        $(MAKE) -C user/idbg
    168168        mcopy -o -i $(DISK_IMAGE) $@ ::/bin/user
    169169user/sort/build/sort.elf: build_libs
  • trunk/hal/tsar_mips32/core/hal_gpt.c

    r440 r443  
    132132    xptr_t     page_xp;
    133133
    134 #if DEBUG_GPT_ACCESS
     134#if DEBUG_HAL_GPT_CREATE
    135135uint32_t cycle = (uint32_t)hal_get_cycles;
    136 if( DEBUG_GPT_ACCESS < cycle )
     136if( DEBUG_HAL_GPT_CREATE < cycle )
    137137printk("\n[DBG] %s : thread %x enter / cycle %d\n",
    138138__FUNCTION__, CURRENT_THREAD, cycle );
     
    161161        gpt->ppn  = ppm_page2ppn( page_xp );
    162162
    163 #if DEBUG_GPT_ACCESS
     163#if DEBUG_HAL_GPT_CREATE
    164164cycle = (uint32_t)hal_get_cycles;
    165 if( DEBUG_GPT_ACCESS < cycle )
     165if( DEBUG_HAL_GPT_CREATE < cycle )
    166166printk("\n[DBG] %s : thread %x exit / cycle %d\n",
    167167__FUNCTION__, CURRENT_THREAD, cycle );
     
    186186        kmem_req_t   req;
    187187    bool_t       is_ref;
     188
     189#if DEBUG_HAL_GPT_DESTROY
     190uint32_t cycle = (uint32_t)hal_get_cycles;
     191if( DEBUG_HAL_GPT_DESTROY < cycle )
     192printk("\n[DBG] %s : thread %x enter / cycle %d\n",
     193__FUNCTION__, CURRENT_THREAD, cycle );
     194#endif
    188195
    189196    // get pointer on calling process
     
    252259    req.ptr  = GET_PTR( ppm_base2page( XPTR(local_cxy , pt1 ) ) );
    253260    kmem_free( &req );
     261
     262#if DEBUG_HAL_GPT_DESTROY
     263cycle = (uint32_t)hal_get_cycles;
     264if( DEBUG_HAL_GPT_DESTROY < cycle )
     265printk("\n[DBG] %s : thread %x exit / cycle %d\n",
     266__FUNCTION__, CURRENT_THREAD, cycle );
     267#endif
    254268
    255269} // end hal_gpt_destroy()
     
    340354    uint32_t            tsar_attr;           // PTE attributes for TSAR MMU
    341355
    342 #if DEBUG_GPT_ACCESS
     356#if DEBUG_HAL_GPT_ACCESS
    343357uint32_t cycle = (uint32_t)hal_get_cycles;
    344 if( DEBUG_GPT_ACCESS < cycle )
     358if( DEBUG_HAL_GPT_ACCESS < cycle )
    345359printk("\n[DBG] %s : thread %x enter / vpn %x / attr %x / ppn %x / cycle %d\n",
    346360__FUNCTION__, CURRENT_THREAD, vpn, attr, ppn, cycle );
     
    357371    tsar_attr = gpt2tsar( attr );
    358372
    359 #if (DEBUG_GPT_ACCESS & 1)
    360 if( DEBUG_GPT_ACCESS < cycle )
     373#if (DEBUG_HAL_GPT_ACCESS & 1)
     374if( DEBUG_HAL_GPT_ACCESS < cycle )
    361375printk("\n[DBG] %s : thread %x / vpn %x / &pt1 %x / tsar_attr %x\n",
    362376__FUNCTION__, CURRENT_THREAD, vpn, pt1, tsar_attr );
     
    392406        pte1 = *pte1_ptr;
    393407       
    394 #if (DEBUG_GPT_ACCESS & 1)
    395 if( DEBUG_GPT_ACCESS < cycle )
     408#if (DEBUG_HAL_GPT_ACCESS & 1)
     409if( DEBUG_HAL_GPT_ACCESS < cycle )
    396410printk("\n[DBG] %s : thread %x / vpn %x / current_pte1 %x\n",
    397411__FUNCTION__, CURRENT_THREAD, vpn, pte1 );
     
    437451            pt2     = (uint32_t *)GET_PTR( ppm_ppn2base( pt2_ppn ) );
    438452
    439 #if (DEBUG_GPT_ACCESS & 1)
    440 if( DEBUG_GPT_ACCESS < cycle )
     453#if (DEBUG_HAL_GPT_ACCESS & 1)
     454if( DEBUG_HAL_GPT_ACCESS < cycle )
    441455printk("\n[DBG] %s : thread %x / vpn %x / pte1 %x / &pt2 %x\n",
    442456__FUNCTION__, CURRENT_THREAD, vpn, pte1, pt2 );
     
    452466        hal_fence();
    453467
    454 #if DEBUG_GPT_ACCESS
     468#if DEBUG_HAL_GPT_ACCESS
    455469cycle = (uint32_t)hal_get_cycles;
    456 if( DEBUG_GPT_ACCESS < cycle )
     470if( DEBUG_HAL_GPT_ACCESS < cycle )
    457471printk("\n[DBG] %s : thread %x exit / vpn %x / pte2_attr %x / pte2_ppn %x / cycle %d\n",
    458472__FUNCTION__, CURRENT_THREAD, vpn, pt2[2 * ix2], pt2[2 * ix2 + 1], cycle );
     
    762776    ppn_t        dst_pt2_ppn;
    763777
    764 #if DEBUG_GPT_ACCESS
     778#if DEBUG_HAL_GPT_ACCESS
    765779uint32_t cycle = (uint32_t)hal_get_cycles;
    766 if( DEBUG_GPT_ACCESS < cycle )
     780if( DEBUG_HAL_GPT_ACCESS < cycle )
    767781printk("\n[DBG] %s : thread %x enter / vpn %x / cycle %d\n",
    768782__FUNCTION__, CURRENT_THREAD, vpn, cycle );
     
    853867            *ppn    = src_pte2_ppn;
    854868       
    855 #if DEBUG_GPT_ACCESS
     869#if DEBUG_HAL_GPT_ACCESS
    856870cycle = (uint32_t)hal_get_cycles;
    857 if( DEBUG_GPT_ACCESS < cycle )
     871if( DEBUG_HAL_GPT_ACCESS < cycle )
    858872printk("\n[DBG] %s : thread %x exit / copy done for vpn %x / cycle %d\n",
    859873__FUNCTION__, CURRENT_THREAD, vpn, cycle );
     
    870884    *ppn    = 0;
    871885   
    872 #if DEBUG_GPT_ACCESS
     886#if DEBUG_HAL_GPT_ACCESS
    873887cycle = (uint32_t)hal_get_cycles;
    874 if( DEBUG_GPT_ACCESS < cycle )
     888if( DEBUG_HAL_GPT_ACCESS < cycle )
    875889printk("\n[DBG] %s : thread %x exit / nothing done for vpn %x / cycle %d\n",
    876890__FUNCTION__, CURRENT_THREAD, vpn, cycle );
  • trunk/hal/tsar_mips32/core/hal_ppm.c

    r432 r443  
    101101        }
    102102
    103 // printk("\n@@@ in %s : reserved = %d / total = %d\n", __FUNCTION__, reserved_pages, pages_nr );
    104 
    105103        // - set PG_RESERVED flag for reserved pages (kernel code & pages_tbl[])
    106104        // - release all other pages to populate the free lists
     
    115113                // TODO optimisation : decompose this enormous set of small pages
    116114                // to several sets of big pages with various order values [AG]
    117 
    118 // if( (i < (reserved_pages+10)) || (i > (pages_nr-5)) ) ppm_print();
    119 
    120115        }
    121116
    122 // assert( false , __FUNCTION__ , "PMM init completed\n");
    123  
    124117        // check consistency
    125118        return ppm_assert_order( ppm );
  • trunk/kernel/kern/cluster.c

    r440 r443  
    3434#include <spinlock.h>
    3535#include <core.h>
     36#include <chdev.h>
    3637#include <scheduler.h>
    3738#include <list.h>
     
    4950/////////////////////////////////////////////////////////////////////////////////////
    5051
    51 extern process_t process_zero;     // allocated in kernel_init.c file
    52 
    53 
    54 /////////////////////////////////////////////////
     52extern process_t           process_zero;     // allocated in kernel_init.c file
     53extern chdev_directory_t   chdev_dir;        // allocated in kernel_init.c file
     54
     55///////////////////////////////////////////////n
    5556error_t cluster_init( struct boot_info_s * info )
    5657{
     
    252253
    253254//////////////////////////////////////////////////////
     255xptr_t cluster_get_process_from_pid_in_cxy( cxy_t cxy,
     256                                            pid_t pid )
     257{
     258    xptr_t      root_xp;       // xptr on root of list of processes in owner cluster
     259    xptr_t      lock_xp;       // xptr on lock protecting this list
     260    xptr_t      iter_xp;       // iterator
     261    xptr_t      current_xp;    // xptr on current process descriptor
     262    bool_t      found;
     263
     264    cluster_t * cluster = LOCAL_CLUSTER;
     265
     266    // get owner cluster and lpid
     267    cxy_t   owner_cxy = CXY_FROM_PID( pid );
     268    lpid_t  lpid      = LPID_FROM_PID( pid );
     269
     270    // get lock & root of list of copies from owner cluster
     271    root_xp = XPTR( owner_cxy , &cluster->pmgr.copies_root[lpid] );
     272    lock_xp = XPTR( owner_cxy , &cluster->pmgr.copies_lock[lpid] );
     273
     274    // take the lock protecting the list of processes
     275    remote_spinlock_lock( lock_xp );
     276
     277    // scan list of processes
     278    found = false;
     279    XLIST_FOREACH( root_xp , iter_xp )
     280    {
     281        current_xp  = XLIST_ELEMENT( iter_xp , process_t , copies_list );
     282
     283        if( GET_CXY( current_xp ) == cxy )
     284        {
     285            found = true;
     286            break;
     287        }
     288    }
     289
     290    // release the lock protecting the list of processes
     291    remote_spinlock_unlock( lock_xp );
     292
     293    // return extended pointer on process descriptor in owner cluster
     294    if( found ) return current_xp;
     295    else        return XPTR_NULL;
     296
     297}  // end cluster_get_process_from_pid_in_cxy()
     298
     299
     300//////////////////////////////////////////////////////
    254301xptr_t cluster_get_owner_process_from_pid( pid_t pid )
    255302{
     
    298345}  // end cluster_get_owner_process_from_pid()
    299346
     347
    300348//////////////////////////////////////////////////////////
    301349xptr_t cluster_get_reference_process_from_pid( pid_t pid )
     
    459507void cluster_process_local_link( process_t * process )
    460508{
    461     uint32_t irq_state;
     509    reg_t    save_sr;
     510
    462511    pmgr_t * pm = &LOCAL_CLUSTER->pmgr;
    463512
     513    // get extended pointers on local process list root & lock
     514    xptr_t root_xp = XPTR( local_cxy , &pm->local_root );
     515    xptr_t lock_xp = XPTR( local_cxy , &pm->local_lock );
     516
    464517    // get lock protecting the process manager local list
    465     remote_spinlock_lock_busy( XPTR( local_cxy , &pm->local_lock ) , & irq_state );
    466 
    467     xlist_add_last( XPTR( local_cxy , &pm->local_root ),
    468                     XPTR( local_cxy , &process->local_list ) );
     518    remote_spinlock_lock_busy( lock_xp , &save_sr );
     519
     520    // register process in local list
     521    xlist_add_last( root_xp , XPTR( local_cxy , &process->local_list ) );
    469522    pm->local_nr++;
    470523
    471524    // release lock protecting the process manager local list
    472     remote_spinlock_unlock_busy( XPTR( local_cxy , &pm->local_lock ) , irq_state );
     525    remote_spinlock_unlock_busy( lock_xp , save_sr );
    473526}
    474527
     
    476529void cluster_process_local_unlink( process_t * process )
    477530{
    478     uint32_t irq_state;
     531    reg_t save_sr;
     532
    479533    pmgr_t * pm = &LOCAL_CLUSTER->pmgr;
    480534
     535    // get extended pointers on local process list lock
     536    xptr_t lock_xp = XPTR( local_cxy , &pm->local_lock );
     537
    481538    // get lock protecting the process manager local list
    482     remote_spinlock_lock_busy( XPTR( local_cxy , &pm->local_lock ) , &irq_state );
    483 
     539    remote_spinlock_lock_busy( lock_xp , &save_sr );
     540
     541    // remove process from local list
    484542    xlist_unlink( XPTR( local_cxy , &process->local_list ) );
    485543    pm->local_nr--;
    486544
    487545    // release lock protecting the process manager local list
    488     remote_spinlock_unlock_busy( XPTR( local_cxy , &pm->local_lock ) , irq_state );
     546    remote_spinlock_unlock_busy( lock_xp , save_sr );
    489547}
    490548
     
    582640{
    583641    xptr_t        root_xp;
     642    xptr_t        lock_xp;
    584643    xptr_t        iter_xp;
    585     xptr_t        process_xp;     
    586 
    587     // get extended pointer on root of process in cluster cxy
     644    xptr_t        process_xp;
     645    cxy_t         txt0_cxy;
     646    chdev_t     * txt0_ptr;
     647    xptr_t        txt0_xp;
     648    xptr_t        txt0_lock_xp;
     649    reg_t         txt0_save_sr;     // save SR to take TXT0 lock in busy mode     
     650
     651    assert( (cluster_is_undefined( cxy ) == false),
     652    __FUNCTION__, "illegal cluster index" );
     653
     654    // get extended pointer on root and lock for local process list in cluster
    588655    root_xp = XPTR( cxy , &LOCAL_CLUSTER->pmgr.local_root );
    589 
    590     // skip one line
    591     printk("\n***** processes in cluster %x / cycle %d\n", cxy , (uint32_t)hal_get_cycles() );
    592 
    593     // loop on all reference processes in cluster cxy
     656    lock_xp = XPTR( cxy , &LOCAL_CLUSTER->pmgr.local_lock );
     657
     658    // get pointers on TXT0 chdev
     659    txt0_xp  = chdev_dir.txt_tx[0];
     660    txt0_cxy = GET_CXY( txt0_xp );
     661    txt0_ptr = GET_PTR( txt0_xp );
     662
     663    // get extended pointer on TXT0 lock
     664    txt0_lock_xp = XPTR( txt0_cxy , &txt0_ptr->wait_lock );
     665
     666    // get lock on local process list
     667    remote_spinlock_lock( lock_xp );
     668
     669    // get TXT0 lock in busy waiting mode
     670    remote_spinlock_lock_busy( txt0_lock_xp , &txt0_save_sr );
     671     
     672    // display header
     673    nolock_printk("\n***** processes in cluster %x / cycle %d\n",
     674    cxy , (uint32_t)hal_get_cycles() );
     675
     676    // loop on all processes in cluster cxy
    594677    XLIST_FOREACH( root_xp , iter_xp )
    595678    {
     
    597680        process_display( process_xp );
    598681    }
     682
     683    // release TXT0 lock in busy waiting mode
     684    remote_spinlock_unlock_busy( txt0_lock_xp , txt0_save_sr );
     685
     686    // release lock on local process list
     687    remote_spinlock_unlock( lock_xp );
     688
    599689}  // end cluster_processes_display()
    600690
  • trunk/kernel/kern/cluster.h

    r440 r443  
    6161 * Warning : the "owner" cluster, and the "reference" cluster can be different clusters.
    6262 *
    63  * The process manager of a cluster K maintains three structures:
    64  * 1) The pref_tbl[] is an array indexed by lpid. There is one entry per owned process.
     63 * The process manager of a cluster K maintains three sets of process descriptors:
     64 *
     65 * 1) pref_tbl[] is an array indexed by lpid. There is one entry per owned process.
    6566 *    Each entry contains an extended pointer on the reference process descriptor.
    6667 *
    67  * 2) The local_root is the root of the local list of process descriptors in cluster K.
     68 * 2) The local_root is the root of the local list of all process descriptors in cluster K.
    6869 *    A process descriptor P is present in K, as soon as P has a thread in cluster K.
    6970 *
     
    187188/******************************************************************************************
    188189 * This function returns an extended pointer on the process descriptor in owner cluster
    189  * from the process PID. This PID can be be different from the calling process PID.
     190 * from the process <pid>. This PID can be be different from the calling process PID.
    190191 * It can be called by any thread running in any cluster,
    191192 ******************************************************************************************
     
    197198/******************************************************************************************
    198199 * This function returns an extended pointer on the reference process descriptor
    199  * from the process PID. This PID can be be different from the calling process PID.
     200 * from the process <pid>. This PID can be be different from the calling process PID.
    200201 * It can be called by any thread running in any cluster,
    201202 ******************************************************************************************
     
    204205 *****************************************************************************************/
    205206xptr_t cluster_get_reference_process_from_pid( pid_t pid );
     207
     208/******************************************************************************************
     209 * This function returns an extended pointer on the process descriptor copy for the
     210 * process identified by <pid> in cluster defined by <cxy> argument.
     211 * This PID can be be different from the calling process PID.
     212 * It can be called by any thread running in any cluster,
     213 ******************************************************************************************
     214 * @ cxy  : target cluster identifier.
     215 * @ pid  : process identifier.
     216 * @ return extended pointer on reference process if found / XPTR_NULL if not found.
     217 *****************************************************************************************/
     218xptr_t cluster_get_process_from_pid_in_cxy( cxy_t cxy,
     219                                            pid_t pid );
    206220
    207221/******************************************************************************************
  • trunk/kernel/kern/core.c

    r438 r443  
    4949        core->usage             = 0;
    5050        core->spurious_irqs     = 0;
    51         core->thread_idle       = NULL;
    5251        core->fpu_owner         = NULL;
    5352        core->rand_last         = hal_time_stamp() & 0xFFF;
     
    9089void core_compute_stats( core_t * core )
    9190{
    92         thread_t * idle  = core->thread_idle;
     91        thread_t * idle  = core->scheduler.idle;
    9392        uint32_t   ticks = core->ticks_nr;
    9493
     
    115114void core_reset_stats( core_t * core )
    116115{
    117         core->ticks_nr              = 0;
    118         core->usage                 = 0;
    119         core->thread_idle->ticks_nr = 0;
     116        thread_t * idle  = core->scheduler.idle;
     117
     118        core->ticks_nr = 0;
     119        core->usage    = 0;
     120        idle->ticks_nr = 0;
     121
    120122        hal_fence();
    121123}
  • trunk/kernel/kern/core.h

    r409 r443  
    5757        uint32_t            usage;          /*! cumulated busy_percent (idle / total)      */
    5858        uint32_t            spurious_irqs;  /*! for instrumentation...                     */
    59         struct thread_s   * thread_idle;    /*! pointer on idle thread descriptor          */
    6059        struct thread_s   * fpu_owner;      /*! pointer on current FPU owner thread        */
    6160    uint32_t            rand_last;      /*! last computed random value                 */
  • trunk/kernel/kern/do_syscall.c

    r438 r443  
    102102    sys_trace,              // 47
    103103    sys_fg,                 // 48
     104    sys_undefined,          // 49
    104105};
    105106
     
    136137        else if( index == SYS_CLOSEDIR       ) return "CLOSEDIR";         // 25
    137138        else if( index == SYS_GETCWD         ) return "GETCWD";           // 26
     139        else if( index == SYS_ISATTY         ) return "ISATTY";           // 27
    138140        else if( index == SYS_ALARM          ) return "ALARM";            // 28
    139141        else if( index == SYS_RMDIR          ) return "RMDIR";            // 29
  • trunk/kernel/kern/kernel_init.c

    r440 r443  
    5959#include <mapper.h>
    6060
    61 #define KERNEL_INIT_SYNCHRO  0xA5A5B5B5
    62 
    6361///////////////////////////////////////////////////////////////////////////////////////////
    6462// All the following global variables are replicated in all clusters.
     
    912910
    913911#if( DEBUG_KERNEL_INIT & 1 )
     912if( (core_lid ==  0) & (local_cxy == 0) )
    914913chdev_dir_display();
    915914#endif
     
    11791178printk("\n[DBG] %s : exit barrier 8 : process init created / cycle %d\n",
    11801179__FUNCTION__ , (uint32_t)hal_get_cycles() );
     1180#endif
     1181
     1182#if (DEBUG_KERNEL_INIT & 1)
     1183if( (core_lid ==  0) & (local_cxy == 0) )
     1184sched_display( 0 );
    11811185#endif
    11821186
  • trunk/kernel/kern/printk.c

    r437 r443  
    350350{
    351351    va_list       args;
    352     uint32_t      save_sr;
     352    reg_t         save_sr;
    353353
    354354    // get pointers on TXT0 chdev
  • trunk/kernel/kern/process.c

    r441 r443  
    135135        process->pid        = pid;
    136136    process->ref_xp     = XPTR( local_cxy , process );
     137    process->owner_xp   = XPTR( local_cxy , process );
    137138    process->parent_xp  = parent_xp;
    138139    process->term_state = 0;
     
    320321    local_process->parent_xp  = hal_remote_lwd( XPTR( ref_cxy , &ref_ptr->parent_xp ) );
    321322    local_process->ref_xp     = reference_process_xp;
     323    local_process->owner_xp   = reference_process_xp;
    322324    local_process->term_state = 0;
    323325
     
    409411    cluster_process_copies_unlink( process );
    410412
    411     // remove process from children_list if process is in owner cluster
     413    // remove process from children_list if process owner cluster
    412414    if( CXY_FROM_PID( pid ) == local_cxy )
    413415    {
     
    426428    }
    427429
    428     // release the process PID to cluster manager if owner cluster
     430    // release the process PID to cluster manager if process owner cluster
    429431    if( CXY_FROM_PID( pid ) == local_cxy ) cluster_pid_release( pid );
    430432
     
    800802        // allocate memory for local process descriptor
    801803        process_ptr = process_alloc();
     804
    802805        if( process_ptr == NULL )  return NULL;
    803806
    804807        // initialize local process descriptor copy
    805808        error = process_copy_init( process_ptr , ref_xp );
     809
    806810        if( error ) return NULL;
    807811    }
     
    10211025    }
    10221026
    1023 
    10241027    // release lock protecting th_tbl
    10251028    hal_fence();
     
    10301033}  // end process_register_thread()
    10311034
    1032 ///////////////////////////////////////////////
    1033 void process_remove_thread( thread_t * thread )
    1034 {
     1035/////////////////////////////////////////////////
     1036bool_t process_remove_thread( thread_t * thread )
     1037{
     1038    uint32_t count;  // number of threads in local process descriptor
     1039
    10351040    assert( (thread != NULL) , __FUNCTION__ , "thread argument is NULL" );
    10361041
     
    10431048    spinlock_lock( &process->th_lock );
    10441049
    1045     assert( (process->th_nr) , __FUNCTION__ , "process th_nr cannot be 0\n" );
     1050    count = process->th_nr;
     1051
     1052    assert( (count > 0) , __FUNCTION__ , "process th_nr cannot be 0\n" );
    10461053
    10471054    // remove thread from th_tbl[]
     
    10491056    process->th_nr--;
    10501057
     1058    // release lock protecting th_tbl
    10511059    hal_fence();
    1052 
    1053     // release lock protecting th_tbl
    10541060    spinlock_unlock( &process->th_lock );
     1061
     1062    return (count == 1);
    10551063
    10561064}  // process_remove_thread()
     
    14011409    process->pid        = 0;
    14021410    process->ref_xp     = XPTR( local_cxy , process );
     1411    process->owner_xp   = XPTR( local_cxy , process );
    14031412    process->parent_xp  = XPTR_NULL;
    14041413    process->term_state = 0;
     
    15311540    process_t   * process_ptr;
    15321541    cxy_t         process_cxy;
     1542
    15331543    xptr_t        parent_xp;       // extended pointer on parent process
    15341544    process_t   * parent_ptr;
    15351545    cxy_t         parent_cxy;
    15361546
     1547    xptr_t        owner_xp;        // extended pointer on owner process
     1548    process_t   * owner_ptr;
     1549    cxy_t         owner_cxy;
     1550
    15371551    pid_t         pid;
    15381552    pid_t         ppid;
    15391553    uint32_t      state;
    1540     xptr_t        ref_xp;
    15411554    uint32_t      th_nr;
    15421555
    1543     xptr_t        txt_file_xp;     // extended pointer on TXT_RX pseudo file
    1544     xptr_t        chdev_xp;        // extended pointer on TXT_RX chdev
    1545     chdev_t     * chdev_ptr;
    1546     cxy_t         chdev_cxy;
    1547     xptr_t        owner_xp;        // extended pointer on TXT owner process
     1556    xptr_t        txt_file_xp;     // extended pointer on TXT_RX file descriptor
     1557    xptr_t        txt_chdev_xp;    // extended pointer on TXT_RX chdev
     1558    chdev_t     * txt_chdev_ptr;
     1559    cxy_t         txt_chdev_cxy;
     1560    xptr_t        txt_owner_xp;    // extended pointer on TXT owner process
    15481561
    15491562    xptr_t        elf_file_xp;     // extended pointer on .elf file
     
    15581571    process_ptr = GET_PTR( process_xp );
    15591572    process_cxy = GET_CXY( process_xp );
    1560 
    1561     // check reference process
    1562     ref_xp = hal_remote_lwd( XPTR( process_cxy , &process_ptr->ref_xp ) );
    1563     assert( (process_xp == ref_xp) , __FUNCTION__ , "process is not the reference\n");
    15641573
    15651574    // get PID and state
     
    15761585    th_nr      = hal_remote_lw( XPTR( process_cxy , &process_ptr->th_nr ) );
    15771586
    1578     // get TXT name and process owner
    1579     txt_file_xp = hal_remote_lwd( XPTR( process_cxy , &process_ptr->fd_array.array[0] ) );
     1587    // get pointers on owner process descriptor
     1588    owner_xp  = hal_remote_lwd( XPTR( process_cxy , &process_ptr->owner_xp ) );
     1589    owner_cxy = GET_CXY( owner_xp );
     1590    owner_ptr = GET_PTR( owner_xp );
     1591
     1592    // get extended pointer on TXT_RX file descriptor attached to process
     1593    txt_file_xp = hal_remote_lwd( XPTR( owner_cxy , &owner_ptr->fd_array.array[0] ) );
    15801594
    15811595    assert( (txt_file_xp != XPTR_NULL) , __FUNCTION__ ,
    15821596    "process must be attached to one TXT terminal\n" );
    15831597
    1584     chdev_xp  = chdev_from_file( txt_file_xp );
    1585     chdev_cxy = GET_CXY( chdev_xp );
    1586     chdev_ptr = (chdev_t *)GET_PTR( chdev_xp );
     1598    // get TXT_RX chdev pointers
     1599    txt_chdev_xp  = chdev_from_file( txt_file_xp );
     1600    txt_chdev_cxy = GET_CXY( txt_chdev_xp );
     1601    txt_chdev_ptr = GET_PTR( txt_chdev_xp );
     1602
     1603    // get TXT_RX name and ownership
    15871604    hal_remote_strcpy( XPTR( local_cxy , txt_name ) ,
    1588                            XPTR( chdev_cxy , chdev_ptr->name ) );
    1589     owner_xp = (xptr_t)hal_remote_lwd( XPTR( chdev_cxy , &chdev_ptr->ext.txt.owner_xp ) );
     1605                       XPTR( txt_chdev_cxy , txt_chdev_ptr->name ) );
     1606   
     1607    txt_owner_xp = (xptr_t)hal_remote_lwd( XPTR( txt_chdev_cxy,
     1608                                                 &txt_chdev_ptr->ext.txt.owner_xp ) );
    15901609   
    15911610    // get process .elf name
    15921611    elf_file_xp   = hal_remote_lwd( XPTR( process_cxy , &process_ptr->vfs_bin_xp ) );
    1593 
    15941612    elf_file_cxy  = GET_CXY( elf_file_xp );
    15951613    elf_file_ptr  = (vfs_file_t *)GET_PTR( elf_file_xp );
     
    15981616
    15991617    // display process info
    1600     if( owner_xp == process_xp )
    1601     {
    1602         printk("PID %X | PPID %X | STS %X | %s (FG) | %X | %d | %s\n",
     1618    if( txt_owner_xp == process_xp )
     1619    {
     1620        nolock_printk("PID %X | PPID %X | STS %X | %s (FG) | %X | %d | %s\n",
    16031621        pid, ppid, state, txt_name, process_ptr, th_nr, elf_name );
    16041622    }
    16051623    else
    16061624    {
    1607         printk("PID %X | PPID %X | STS %X | %s (BG) | %X | %d | %s\n",
     1625        nolock_printk("PID %X | PPID %X | STS %X | %s (BG) | %X | %d | %s\n",
    16081626        pid, ppid, state, txt_name, process_ptr, th_nr, elf_name );
    16091627    }
     
    19882006    xptr_t      current_xp;
    19892007    xptr_t      iter_xp;
    1990 
    1991     // check terminal index
     2008    cxy_t       txt0_cxy;
     2009    chdev_t   * txt0_ptr;
     2010    xptr_t      txt0_xp;
     2011    xptr_t      txt0_lock_xp;
     2012    reg_t       txt0_save_sr;    // save SR to take TXT0 lock in busy mode
     2013   
    19922014    assert( (txt_id < LOCAL_CLUSTER->nb_txt_channels) ,
    19932015    __FUNCTION__ , "illegal TXT terminal index" );
     2016
     2017    // get pointers on TXT0 chdev
     2018    txt0_xp  = chdev_dir.txt_tx[0];
     2019    txt0_cxy = GET_CXY( txt0_xp );
     2020    txt0_ptr = GET_PTR( txt0_xp );
     2021
     2022    // get extended pointer on TXT0 lock
     2023    txt0_lock_xp = XPTR( txt0_cxy , &txt0_ptr->wait_lock );
    19942024
    19952025    // get pointers on TXT_RX[txt_id] chdev
     
    20022032    lock_xp = XPTR( chdev_cxy , &chdev_ptr->ext.txt.lock );
    20032033
     2034    // get lock on attached process list
     2035    remote_spinlock_lock( lock_xp );
     2036
     2037    // get TXT0 lock in busy waiting mode
     2038    remote_spinlock_lock_busy( txt0_lock_xp , &txt0_save_sr );
     2039
    20042040    // display header
    2005     printk("\n***** processes attached to TXT_%d\n", txt_id );
    2006 
    2007     // get lock
    2008     remote_spinlock_lock( lock_xp );
     2041    nolock_printk("\n***** processes attached to TXT_%d / cycle %d\n",
     2042    txt_id , (uint32_t)hal_get_cycles() );
    20092043
    20102044    // scan attached process list
     
    20152049    }
    20162050
    2017     // release lock
     2051    // release TXT0 lock in busy waiting mode
     2052    remote_spinlock_unlock_busy( txt0_lock_xp , txt0_save_sr );
     2053
     2054    // release lock on attached process list
    20182055    remote_spinlock_unlock( lock_xp );
    20192056
  • trunk/kernel/kern/process.h

    r441 r443  
    9090 * The process descriptor is replicated in all clusters containing at least one thread
    9191 * of the PID process, with the following rules :
    92  * 1) The <pid>, <ppid>, <ref_xp>, <vfs_root_xp>, <vfs_bin_xp>  fields are defined
    93  *    in all process descriptor copies.
     92 * 1) The <pid>, <ppid>, <ref_xp>, <owner_xp>, <vfs_root_xp>, <vfs_bin_xp>  fields are
     93 *    defined in all process descriptor copies.
    9494 * 2) The <vfs_cwd_xp> and associated <cwd_lock>, that can be dynamically modified,
    9595 *    are only defined in the reference process descriptor.
     
    106106 *    are defined in all process descriptors copies.
    107107 * 7) The termination <flags> and <exit_status> are only defined in the reference cluster.
    108  *    The term state format is defined in the shared_syscalls.h file.
     108 *    The term_state format is defined in the shared_syscalls.h file.
    109109 ********************************************************************************************/
    110110
     
    119119        pid_t             pid;              /*! process identifier                              */
    120120    xptr_t            ref_xp;           /*! extended pointer on reference process           */
     121    xptr_t            owner_xp;         /*! extended pointer on owner process               */
    121122    xptr_t            parent_xp;        /*! extended pointer on parent process              */
    122123
     
    264265/*********************************************************************************************
    265266 * This debug function diplays on the kernel terminal TXT0 detailed informations on a
    266  * reference process identified by the <process_xp> argument.
     267 * process descriptor identified by the <process_xp> argument.
    267268 * It can be called by a thread running in any cluster.
    268  *********************************************************************************************
    269  * @ process_xp : extended pointer on reference process.
     269 * WARNING: this function uses the nolock_printk() function, and the  TXT0 lock MUST be
     270 * taken by the caller function.
     271 *********************************************************************************************
     272 * @ process_xp : extended pointer on process descriptor.
    270273 ********************************************************************************************/
    271274void process_display( xptr_t process_xp );
     
    379382
    380383/*********************************************************************************************
    381  * This function implements the "fork" system call, and is called by the sys_fork() function.
    382  * It allocates memory and initializes a new "child" process descriptor, and the
    383  * associated "child" thread descriptor in the local cluster. This function can involve
    384  * up to three different clusters :
    385  * - the child (local) cluster can be any cluster defined by the sys_fork function.
     384 * This function implements the "fork" system call, and is called by the sys_fork() function,
     385 * likely throuch the RPC_PROCESS_MAKE_FORK.
     386 * It allocates memory and initializes a new "child" process descriptor, and the associated
     387 * "child" thread descriptor in local cluster. It involves up to three different clusters :
     388 * - the child (local) cluster can be any cluster selected by the sys_fork function.
    386389 * - the parent cluster must be the reference cluster for the parent process.
    387390 * - the client cluster containing the thread requesting the fork can be any cluster.
     
    483486 * It checks that there is an available slot in the local th_tbl[] array,
    484487 * allocates a new LTID, and registers the new thread in the th_tbl[].
    485  * WARNING : the lock protecting the th_tbl[] must be taken by the caller.
     488 * It takes the lock protecting exclusive access to the th_tbl[].
    486489 *********************************************************************************************
    487490 * @ process  : pointer on the local process descriptor.
     
    496499/*********************************************************************************************
    497500 * This function removes a thread registration from the local process descriptor.
    498  * WARNING : the lock protecting the th_tbl[] must be taken by the caller.
     501 * It takes the lock protecting exclusive access to the th_tbl[].
    499502 *********************************************************************************************
    500503 * @ thread   : local pointer on thread to be removed.
    501  ********************************************************************************************/
    502 void process_remove_thread( struct thread_s * thread );
     504 * @ return true if the removed thread was the last registered thread.
     505 ********************************************************************************************/
     506bool_t process_remove_thread( struct thread_s * thread );
    503507
    504508
     
    551555 * When the process dentified by the <owner_xp> argument has the exclusive ownership of
    552556 * the TXT_RX terminal, this function transfer this ownership to another attached process.
    553  * The process descriptor must be in the process owner cluster.
    554  * This function does nothing if the <pid> process is not the owner.
     557 * The process descriptor must be the process owner.
     558 * This function does nothing if the process identified by the <process_xp> is not
     559 * the TXT owner.
    555560 * - If the current owner is not the KSH process, the new owner is the KSH process.
    556  * - If the <pid> process is the the KSH process, the new owner is another attached process.
     561 * - If the current owner is the KSH process, the new owner is another attached process.
    557562 * - If there is no other attached process, the TXT has no more defined owner.
    558563 *********************************************************************************************
  • 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
  • trunk/kernel/kern/scheduler.h

    r437 r443  
    5050    struct thread_s * current;         /*! pointer on current running thread                */
    5151    volatile bool_t   req_ack_pending; /*! sequencialize ack requests when true             */
     52    bool_t            trace;           /*! context switches trace activated if true         */
    5253}
    5354scheduler_t;
  • trunk/kernel/kern/thread.c

    r440 r443  
    142142        cluster_t    * local_cluster = LOCAL_CLUSTER;
    143143
     144#if DEBUG_THREAD_USER_INIT
     145uint32_t cycle = (uint32_t)hal_get_cycles();
     146if( DEBUG_THREAD_USER_INIT < cycle )
     147printk("\n[DBG] %s : thread %x enter to init thread %x in process %x / cycle %d\n",
     148__FUNCTION__, CURRENT_THREAD, thread, process->pid , cycle );
     149#endif
     150
    144151    // register new thread in process descriptor, and get a TRDID
    145152    error = process_register_thread( process, thread , &trdid );
     
    196203        thread->signature = THREAD_SIGNATURE;
    197204
    198     // FIXME call hal_thread_init() function to initialise the save_sr field
     205    // FIXME define and call an architecture specific hal_thread_init()
     206    // function to initialise the save_sr field
    199207    thread->save_sr = 0xFF13;
    200208
     
    204212        // update DQDT
    205213    dqdt_update_threads( 1 );
     214
     215#if DEBUG_THREAD_USER_INIT
     216cycle = (uint32_t)hal_get_cycles();
     217if( DEBUG_THREAD_USER_INIT < cycle )
     218printk("\n[DBG] %s : thread %x exit  after init of thread %x in process %x / cycle %d\n",
     219__FUNCTION__, CURRENT_THREAD, thread, process->pid , cycle );
     220#endif
    206221
    207222        return 0;
     
    227242uint32_t cycle = (uint32_t)hal_get_cycles();
    228243if( DEBUG_THREAD_USER_CREATE < cycle )
    229 printk("\n[DBG] %s : thread %x enter / process %x / cycle %d\n",
    230 __FUNCTION__, CURRENT_THREAD, pid , cycle );
     244printk("\n[DBG] %s : thread %x enter for process %x in cluster %x / cycle %d\n",
     245__FUNCTION__, CURRENT_THREAD, pid , local_cxy , cycle );
    231246#endif
    232247
     
    240255        return ENOMEM;
    241256    }
     257
     258#if( DEBUG_THREAD_USER_CREATE & 1)
     259if( DEBUG_THREAD_USER_CREATE < cycle )
     260printk("\n[DBG] %s : process descriptor = %x for process %x in cluster %x\n",
     261__FUNCTION__, process , pid , local_cxy );
     262#endif
    242263
    243264    // select a target core in local cluster
     
    256277        core_lid = cluster_select_local_core();
    257278    }
     279
     280#if( DEBUG_THREAD_USER_CREATE & 1)
     281if( DEBUG_THREAD_USER_CREATE < cycle )
     282printk("\n[DBG] %s : core[%x,%d] selected\n",
     283__FUNCTION__, local_cxy , core_lid );
     284#endif
    258285
    259286    // allocate a stack from local VMM
     
    282309        return ENOMEM;
    283310    }
     311
     312#if( DEBUG_THREAD_USER_CREATE & 1)
     313if( DEBUG_THREAD_USER_CREATE < cycle )
     314printk("\n[DBG] %s : thread descriptor %x allocated\n",
     315__FUNCTION__, thread );
     316#endif
    284317
    285318    // initialize thread descriptor
     
    300333    }
    301334
     335#if( DEBUG_THREAD_USER_CREATE & 1)
     336if( DEBUG_THREAD_USER_CREATE < cycle )
     337printk("\n[DBG] %s : thread descriptor %x initialised / trdid = %x\n",
     338__FUNCTION__, thread , thread->trdid );
     339#endif
     340
    302341    // set DETACHED flag if required
    303342    if( attr->attributes & PT_ATTR_DETACH )
     
    327366cycle = (uint32_t)hal_get_cycles();
    328367if( DEBUG_THREAD_USER_CREATE < cycle )
    329 printk("\n[DBG] %s : thread %x exit / process %x / new_thread %x / core %d / cycle %d\n",
    330 __FUNCTION__, CURRENT_THREAD, pid, thread, core_lid, cycle );
     368printk("\n[DBG] %s : thread %x exit / new_thread %x in process %x / core %d / cycle %d\n",
     369__FUNCTION__, CURRENT_THREAD, thread->trdid , pid , core_lid, cycle );
    331370#endif
    332371
     
    602641// has been released, using a cache of mmap requests. [AG]
    603642///////////////////////////////////////////////////////////////////////////////////////
    604 void thread_destroy( thread_t * thread )
     643bool_t thread_destroy( thread_t * thread )
    605644{
    606645    reg_t        save_sr;
     646    bool_t       last_thread;
    607647
    608648    process_t  * process    = thread->process;
     
    616656#endif
    617657
    618     assert( (thread->local_locks == 0) , __FUNCTION__ , "all local locks not released" );
    619 
    620     assert( (thread->remote_locks == 0) , __FUNCTION__ , "all remote locks not released" );
     658    assert( (thread->local_locks == 0) , __FUNCTION__ ,
     659    "local lock not released for thread %x in process %x", thread->trdid, process->pid );
     660
     661    assert( (thread->remote_locks == 0) , __FUNCTION__ ,
     662    "remote lock not released for thread %x in process %x", thread->trdid, process->pid );
    621663
    622664    // update intrumentation values
     
    637679
    638680    // remove thread from process th_tbl[]
    639     process_remove_thread( thread );
     681    last_thread = process_remove_thread( thread );
    640682       
    641683    // update DQDT
     
    654696__FUNCTION__, CURRENT_THREAD, thread, process->pid, cycle );
    655697#endif
     698
     699    return last_thread;
    656700
    657701}   // end thread_destroy()
     
    10921136        hal_enable_irq( NULL );
    10931137
    1094         if( CONFIG_THREAD_IDLE_MODE_SLEEP ) // force core to low-power mode
     1138        // force core to low-power mode (optional)
     1139        if( CONFIG_THREAD_IDLE_MODE_SLEEP )
    10951140        {
    10961141
     
    11131158
    11141159        }
    1115         else                                // search a runable thread
    1116         {
    1117             sched_yield( "IDLE" );
    1118         }
     1160
     1161        // search a runable thread
     1162        sched_yield( "IDLE" );
    11191163    }
    11201164}  // end thread_idle()
  • trunk/kernel/kern/thread.h

    r440 r443  
    7777
    7878/***************************************************************************************
    79  * This defines the masks associated to the blocking causes.
     79 * This defines the thread blocking causes bit-vector.
    8080 **************************************************************************************/
    8181
     
    278278
    279279/***************************************************************************************
    280  * This function is called by the kernel_init() function to initialize the IDLE thread.
    281  * It initializes an existing thread descriptor from arguments values.
     280 * This function is called by the kernel_init() function to initialize the IDLE thread
     281 * descriptor from arguments values.
    282282 * The THREAD_BLOCKED_GLOBAL bit is set, and the thread must be activated to start.
    283283 ***************************************************************************************
     
    296296
    297297/***************************************************************************************
    298  * This function releases the physical memory allocated for a thread in a given cluster.
    299  * This include the thread descriptor itself, the associated CPU and FPU context, and
    300  * the physical memory allocated for an user thread local stack.
     298 * This function is called by the sched_handle_signals() function to releases
     299 * the physical memory allocated for a thread in a given cluster, when this thread
     300 * is marked for delete. This include the thread descriptor itself, the associated
     301 * CPU and FPU context, and the physical memory allocated for an user thread local stack.
     302 * The destroyed thread is removed from the local process th_tbl[] array, and returns
     303 * true when the destroyed thread was the last thread registered in process.
    301304 ***************************************************************************************
    302305 * @ thread  : pointer on the thread descriptor to release.
    303  **************************************************************************************/
    304 void thread_destroy( thread_t * thread );
     306 * @ return true, if the thread was the last registerd thread in local process.
     307 **************************************************************************************/
     308bool_t thread_destroy( thread_t * thread );
    305309
    306310/***************************************************************************************
    307311 * This function defines the code of the thread executed by all cores after kernel_init,
    308312 * or when no other thread is runnable for a given core.
    309  *
    310  * TODO: In the TSAR architecture, it enters an infinite loop, in wich it forces
    311  * the core in sleep (low-power) mode. Any IRQ will force the core to exit this sleep
    312  * mode, but no ISR is executed.
    313  * TODO: We must analyse if we have the same behaviour for I86 architectures...
     313 * It enter and infinite loop in wich:
     314 * - it unmask the IRQs
     315 * - it optionally calls the hal_core_sleep() function to reduce the power consumption
     316 *   (this behavior is controlled by the CONFIG_THREAD_IDLE_MODE_SLEEP flag).
     317 * - it call the sched_yield() function to find another runnable thread.
     318 *
     319 * TODO: In the TSAR architecture the hal_core_sleep() function forces the core to
     320 * low-power mode. Any IRQ will force the core to exit this low-power mode, but no ISR
     321 * is executed. We must analyse if we have the same behaviour for I86 architectures...
    314322 **************************************************************************************/
    315323void thread_idle_func();
     
    357365/***************************************************************************************
    358366 * This function is used by the four sys_thread_cancel(), sys_thread_exit(),
    359  * sys_kill() and sys_exit() system calls to delete a given thread.
     367 * sys_kill() and sys_exit() system calls to mark for delete a given thread.
    360368 * It set the THREAD_BLOCKED_GLOBAL bit and set the the THREAD_FLAG_REQ_DELETE bit
    361369 * in the thread descriptor identified by the <thread_xp> argument, to ask the scheduler
  • trunk/kernel/kernel_config.h

    r441 r443  
    6767#define DEBUG_FATFS_LOAD               0
    6868
    69 #define DEBUG_GPT_ACCESS               0
     69#define DEBUG_HAL_GPT_ACCESS           0
     70#define DEBUG_HAL_GPT_CREATE           0
     71#define DEBUG_HAL_GPT_DESTROY          0
    7072
    7173#define DEBUG_HAL_KENTRY               0
     
    7678#define DEBUG_HAL_IOC_RX               0
    7779#define DEBUG_HAL_IOC_TX               0
     80#define DEBUG_HAL_GPT
    7881
    7982#define DEBUG_KCM                      0
     
    115118#define DEBUG_RPC_VMM_GET_VSEG         0
    116119
    117 #define DEBUG_SCHED_HANDLE_SIGNALS     0
    118 #define DEBUG_SCHED_YIELD              0
     120#define DEBUG_SCHED_HANDLE_SIGNALS     2
     121#define DEBUG_SCHED_YIELD              2    // dynamically activated by the trace() syscall
    119122
    120123#define DEBUG_SYSCALLS_ERROR           2
     
    132135#define DEBUG_SYS_THREAD_CANCEL        0
    133136#define DEBUG_SYS_THREAD_CREATE        0
    134 #define DEBUG_SYS_THREAD_EXIT          1
     137#define DEBUG_SYS_THREAD_EXIT          0
    135138#define DEBUG_SYS_THREAD_JOIN          0
    136139#define DEBUG_SYS_THREAD_SLEEP         0
    137140#define DEBUG_SYS_THREAD_WAKEUP        0
     141#define DEBUG_SYS_TRACE                0
    138142#define DEBUG_SYS_WAIT                 0
    139143#define DEBUG_SYS_WRITE                0
     
    146150#define DEBUG_THREAD_DESTROY           0
    147151#define DEBUG_THREAD_IDLE              0
     152#define DEBUG_THREAD_INIT              0
    148153#define DEBUG_THREAD_KERNEL_CREATE     0
    149154#define DEBUG_THREAD_KILL              0
     
    199204
    200205#define CONFIG_TXT_ECHO_MODE                1          // echo mode for TXT peripheral
    201 #define CONFIG_TXT_KBUF_SIZE                256        // kernel buffer for TXT write
     206#define CONFIG_TXT_KBUF_SIZE                512        // kernel buffer for TXT write
    202207
    203208#define CONFIG_FBF_WIDTH                    128
     
    265270#define CONFIG_THREAD_DESC_SIZE             0x4000  // thread desc size (with kernel stack)
    266271#define CONFIG_THREAD_DESC_ORDER            2       // ln( number of 4K pages )
    267 #define CONFIG_THREAD_IDLE_MODE_SLEEP       0       // idle thread enter sleep mode
     272#define CONFIG_THREAD_IDLE_MODE_SLEEP       false   // idle thread enter sleep mode
    268273
    269274////////////////////////////////////////////////////////////////////////////////////////////
  • trunk/kernel/libk/remote_spinlock.c

    r438 r443  
    201201xlist_add_first( XPTR( local_cxy , &thread_ptr->xlocks_root ),
    202202                 XPTR( lock_cxy  , &lock_ptr->list ) );
    203 
    204 // if( (uint32_t)lock_ptr == 0x66788 )
    205 // printk("\n@@@ %s : thread %x takes remote_spinlock %x\n",
    206 //__FUNCTION__, thread_ptr, lock_ptr );
    207 
    208203#endif
    209204
     
    225220hal_remote_swd( XPTR( lock_cxy , &lock_ptr->owner ) , XPTR_NULL );
    226221xlist_unlink( XPTR( lock_cxy , &lock_ptr->list ) );
    227 
    228 // if( (uint32_t)lock_ptr == 0x66788 )
    229 // printk("\n@@@ %s : thread %x releases remote_spinlock %x\n",
    230 // __FUNCTION__, thread_ptr, lock_ptr );
    231 
    232222#endif
    233223
  • trunk/kernel/mm/vmm.c

    r441 r443  
    201201    gpt_t * gpt = &vmm->gpt;
    202202
    203     printk("\n***** VSL and GPT for process %x in cluster %x\n\n",
    204     process->pid , local_cxy );
     203    printk("\n***** VSL and GPT for process %x in cluster %x\n\n", process->pid , local_cxy );
    205204
    206205    // get lock protecting the vseg list
     
    666665uint32_t cycle = (uint32_t)hal_get_cycles();
    667666if( DEBUG_VMM_DESTROY < cycle )
    668 printk("\n[DBG] %s : thread %x enter for process %x / cycle %d\n",
    669 __FUNCTION__ , CURRENT_THREAD , process->pid , cycle );
     667printk("\n[DBG] %s : thread %x enter for process %x in cluster %x / cycle %d\n",
     668__FUNCTION__ , CURRENT_THREAD , process->pid , local_cxy , cycle );
    670669#endif
    671670
    672671#if (DEBUG_VMM_DESTROY & 1 )
     672if( DEBUG_VMM_DESTROY < cycle )
    673673vmm_display( process , true );
    674674#endif
     
    693693#if( DEBUG_VMM_DESTROY & 1 )
    694694if( DEBUG_VMM_DESTROY < cycle )
    695 printk("\n[DBG] %s : %s / vpn_base %x / vpn_size %d\n",
     695printk("\n[DBG] %s : found %s vseg / vpn_base %x / vpn_size %d\n",
    696696__FUNCTION__ , vseg_type_str( vseg->type ), vseg->vpn_base, vseg->vpn_size );
    697697#endif
    698 
    699698        // unmap and release physical pages
    700699        vmm_unmap_vseg( process , vseg );
     
    705704        // release memory allocated to vseg descriptor
    706705        vseg_free( vseg );
     706
     707#if( DEBUG_VMM_DESTROY & 1 )
     708if( DEBUG_VMM_DESTROY < cycle )
     709printk("\n[DBG] %s : %s vseg released / vpn_base %x / vpn_size %d\n",
     710__FUNCTION__ , vseg_type_str( vseg->type ), vseg->vpn_base, vseg->vpn_size );
     711#endif
     712
    707713        }
    708714
     
    717723            {
    718724                    vseg = LIST_FIRST( &vmm->mmap_mgr.zombi_list[i] , vseg_t , zlist );
     725
     726#if( DEBUG_VMM_DESTROY & 1 )
     727if( DEBUG_VMM_DESTROY < cycle )
     728printk("\n[DBG] %s : found zombi vseg / vpn_base %x / vpn_size %d\n",
     729__FUNCTION__ , vseg_type_str( vseg->type ), vseg->vpn_base, vseg->vpn_size );
     730#endif
    719731                    vseg_detach( vmm , vseg );
    720732            vseg_free( vseg );
     733
     734#if( DEBUG_VMM_DESTROY & 1 )
     735if( DEBUG_VMM_DESTROY < cycle )
     736printk("\n[DBG] %s : zombi vseg released / vpn_base %x / vpn_size %d\n",
     737__FUNCTION__ , vseg_type_str( vseg->type ), vseg->vpn_base, vseg->vpn_size );
     738#endif
    721739            }
    722740    }
     
    728746cycle = (uint32_t)hal_get_cycles();
    729747if( DEBUG_VMM_DESTROY < cycle )
    730 printk("\n[DBG] %s : thread %x exit / cycle %d\n",
    731 __FUNCTION__ , CURRENT_THREAD , cycle );
     748printk("\n[DBG] %s : thread %x exit for process %x in cluster %x / cycle %d\n",
     749__FUNCTION__ , CURRENT_THREAD , process->pid , local_cxy , cycle );
    732750#endif
    733751
  • trunk/kernel/syscalls/sys_display.c

    r440 r443  
    3030#include <process.h>
    3131#include <string.h>
    32 
     32#include <shared_syscalls.h>
     33
     34/////////////////////////////////////////////////////////////////////////////////
     35// This static function returns a printable string for the type of display.
     36/////////////////////////////////////////////////////////////////////////////////
     37
     38#if DEBUG_SYS_DISPLAY
     39static char* display_type_str( uint32_t type )
     40{
     41    if     ( type == DISPLAY_STRING            ) return "STRING";
     42    else if( type == DISPLAY_VMM               ) return "VMM";
     43    else if( type == DISPLAY_SCHED             ) return "SCHED";
     44    else if( type == DISPLAY_CLUSTER_PROCESSES ) return "CLUSTER_PROCESSES";
     45    else if( type == DISPLAY_VFS               ) return "VFS";
     46    else if( type == DISPLAY_CHDEV             ) return "CHDEV";
     47    else if( type == DISPLAY_TXT_PROCESSES     ) return "TXT_PROCESSES";
     48}
     49#endif
    3350
    3451/////////////////////////////
     
    4966tm_start = hal_get_cycles();
    5067if( DEBUG_SYS_DISPLAY < tm_start )
    51 printk("\n[DBG] %s : thread %d enter / process %x / type  %d / cycle = %d\n",
    52 __FUNCTION__, this, this->process->pid, type, (uint32_t)tm_start );
     68printk("\n[DBG] %s : thread %d enter / process %x / type  %s / cycle = %d\n",
     69__FUNCTION__, this, this->process->pid, display_type_str(type), (uint32_t)tm_start );
    5370#endif
    5471
     
    98115    else if( type == DISPLAY_VMM )
    99116    {
    100         pid_t pid = (pid_t)arg0;
    101 
    102         // get extended pointer on reference process
    103         xptr_t process_xp = cluster_get_reference_process_from_pid( pid );
     117        cxy_t cxy = (cxy_t)arg0;
     118        pid_t pid = (pid_t)arg1;
     119
     120        // check cxy argument
     121            if( cluster_is_undefined( cxy ) )
     122        {
     123
     124#if DEBUG_SYSCALLS_ERROR
     125printk("\n[ERROR] in %s : illegal cxy argument %x / thread %x / process %x\n",
     126__FUNCTION__ , cxy , this->trdid , process->pid );
     127#endif
     128            this->errno = EINVAL;
     129            return -1;
     130        }
     131
     132        // get extended pointer on process PID in cluster CXY
     133        xptr_t process_xp = cluster_get_process_from_pid_in_cxy( cxy , pid );
    104134
    105135            if( process_xp == XPTR_NULL )
     
    107137
    108138#if DEBUG_SYSCALLS_ERROR
    109 printk("\n[ERROR] in %s : undefined pid argument %d / thread %x / process %x\n",
    110 __FUNCTION__ , pid , this->trdid , process->pid );
    111 #endif
    112             this->errno = EINVAL;
    113             return -1;
    114         }
    115 
    116         // get cluster and local pointer on process
    117         cxy_t       process_cxy = GET_CXY( process_xp );
    118         process_t * process_ptr = (process_t *)GET_PTR( process_xp );
     139printk("\n[ERROR] in %s : process %x in cluster %x not found / thread %x / process %x\n",
     140__FUNCTION__ , pid , cxy , this->trdid , process->pid );
     141#endif
     142            this->errno = EINVAL;
     143            return -1;
     144        }
     145
     146        // get local pointer on process
     147        process_t * process = (process_t *)GET_PTR( process_xp );
    119148
    120149        // call kernel function
    121         if( process_cxy == local_cxy )
    122         {
    123                 vmm_display( process_ptr , true );
     150        if( cxy == local_cxy )
     151        {
     152                vmm_display( process , true );
    124153        }
    125154        else
    126155        {
    127             rpc_vmm_display_client( process_cxy , process_ptr , true );
     156            rpc_vmm_display_client( cxy , process , true );
    128157        }
    129158    }
  • trunk/kernel/syscalls/sys_exit.c

    r441 r443  
    5151#endif
    5252
    53     // get owner process descriptor pointers and cluster
    54     xptr_t      owner_xp  = cluster_get_owner_process_from_pid( pid );
     53    // get owner process descriptor pointers
     54    xptr_t      owner_xp  = process->owner_xp;
    5555    cxy_t       owner_cxy = GET_CXY( owner_xp );
    5656    process_t * owner_ptr = GET_PTR( owner_xp );
     
    6262    hal_enable_irq( &save_sr );
    6363
    64     // mark for delete all process threads in all clusters
    65     // (but the main thread and this calling thread)
     64    // mark for delete all process threads in all clusters,
     65    // but the main thread and this calling thread
    6666    process_sigaction( pid , DELETE_ALL_THREADS );
    6767
     
    8181#if( DEBUG_SYS_EXIT & 1)
    8282if( tm_start > DEBUG_SYS_EXIT )
    83 printk("\n[DBG] %s : calling thread %x deleted itself / process %x\n",
     83printk("\n[DBG] %s : calling thread %x marked iself for delete / process %x\n",
    8484__FUNCTION__ , this, pid );
    8585#endif
  • trunk/kernel/syscalls/sys_fg.c

    r438 r443  
    3636int sys_fg( pid_t    pid )
    3737{
    38     xptr_t      process_xp;
     38    xptr_t      process_xp;     // extended pointer on reference process descriptor
    3939    process_t * process_ptr;
    4040    cxy_t       process_cxy;
    41     xptr_t      chdev_xp;
     41    xptr_t      file_xp;        // extended pointer on STDIN file descriptor
     42    xptr_t      chdev_xp;       // extended pointer on TXT0_RX chdev
    4243    chdev_t   * chdev_ptr;
    4344    cxy_t       chdev_cxy;
     
    7071    process_ptr = (process_t *)GET_PTR( process_xp );
    7172    process_cxy = GET_CXY( process_xp );
     73
     74    // get extended pointer on the reference process STDIN file descriptor
     75    file_xp = hal_remote_lwd( XPTR( process_cxy , &process_ptr->fd_array.array[0] ) );
    7276 
    7377    // get extended pointer on TXT_RX chdev
    74     chdev_xp = chdev_from_file( XPTR( process_cxy , &process_ptr->fd_array.array[0] ) );
     78    chdev_xp = chdev_from_file( file_xp );
    7579
    7680    // get chdev cluster and local pointer
  • trunk/kernel/syscalls/sys_read.c

    r441 r443  
    147147        // check file readable
    148148        uint32_t attr = hal_remote_lw( XPTR( file_cxy , &file_ptr->attr ) );
     149
    149150        if( (attr & FD_ATTR_READ_ENABLE) == 0 )
    150151            {
     
    231232exit_sys_read = (uint32_t)tm_end;
    232233
    233 printk("\n@@@@@@@@@@@@ timing to read character\n"
     234printk("\n***** timing to read one character *****\n"
    234235" - enter_sys_read          = %d / delta %d\n"
    235236" - enter_devfs_read        = %d / delta %d\n"
  • trunk/kernel/syscalls/sys_thread_cancel.c

    r440 r443  
    3737    cxy_t        target_cxy;    // target thread cluster identifier
    3838    ltid_t       target_ltid;   // target thread local index
     39    xptr_t       owner_xp;      // extended pointer on owner process
    3940    cxy_t        owner_cxy;     // process owner cluster identifier
    40     xptr_t       owner_xp;      // extended pointer on owner process
    4141
    4242    // get killer thread pointers
     
    4444    process_t  * process = this->process;
    4545    pid_t        pid     = process->pid;
     46
     47#if DEBUG_SYS_THREAD_CANCEL
     48uint64_t     tm_start;
     49uint64_t     tm_end;
     50tm_start = hal_get_cycles();
     51if( DEBUG_SYS_THREAD_CANCEL < tm_start )
     52printk("\n[DBG] %s : thread %x enter to kill thread %x in process %x / cycle %d\n",
     53__FUNCTION__, this , trdid , pid , (uint32_t)tm_start );
     54#endif
    4655
    4756    // get extended pointer on target thread
     
    5968    }
    6069
    61 #if DEBUG_SYS_THREAD_CANCEL
    62 uint64_t     tm_start;
    63 uint64_t     tm_end;
    64 tm_start = hal_get_cycles();
    65 if( DEBUG_SYS_THREAD_CANCEL < tm_start )
    66 printk("\n[DBG] %s : thread %x enter to kill thread %x / cycle %d\n",
    67 __FUCTION__, this, GET_PTR( target_xp ), (uint32_t)tm_start );
    68 #endif
    69 
    70     // get process owner cluster identifier
    71     owner_cxy = CXY_FROM_PID( pid );
     70    // get process owner cluster
     71    owner_xp  = process->owner_xp;
     72    owner_cxy = GET_CXY( owner_xp );
    7273
    7374    // get target thread ltid and cluster
     
    7980    if( (target_cxy == owner_cxy) && (target_ltid == 0) )
    8081    {
    81         // get extended pointer on owner cluster
    82         owner_xp = cluster_get_owner_process_from_pid( pid );
    83 
    8482        // mark for delete all threads but the main
    8583        hal_enable_irq( &save_sr );
     
    107105tm_end = hal_get_cycles();
    108106if( DEBUG_SYS_THREAD_CANCEL < tm_end )
    109 printk("\n[DBG] %s : thread %x exit after kill thread %x / cycle %d\n",
    110 __FUCTION__, this, GET_PTR( target_xp ), (uint32_t)tm_end );
     107printk("\n[DBG] %s : thread %x exit after kill thread %x in process %x / cycle %d\n",
     108__FUNCTION__, this , trdid , pid , (uint32_t)tm_end );
    111109#endif
    112110
  • trunk/kernel/syscalls/sys_trace.c

    r407 r443  
    11/*
    2  * sys_trace.c - show kernel active processes and threads
     2 * sys_trace.c - activate / desactivate the context switches trace for a given core
    33 *
    4  * Author    Alain Greiner (c) (2016,2017)
     4 * Author    Alain Greiner (c) (2016,2017,2018)
    55 *
    66 * Copyright (c) UPMC Sorbonne Universites
     
    2727#include <thread.h>
    2828#include <errno.h>
     29#include <shared_syscalls.h>
    2930#include <syscalls.h>
    3031
    31 //////////////////////////////////
    32 int sys_trace( uint32_t operation,
    33                pid_t    pid,
    34                uint32_t trdid )
     32///////////////////////////////
     33int sys_trace( bool_t   active,
     34               cxy_t    cxy,
     35               lid_t    lid )
    3536{
    36     // get extended pointer on target thread
    37     xptr_t thread_xp = thread_get_xptr( pid , trdid );
     37    uint32_t    ncores;
    3838
    39     if( thread_xp == XPTR_NULL )
     39    thread_t  * this    = CURRENT_THREAD;
     40    process_t * process = this->process;
     41
     42#if DEBUG_SYS_TRACE
     43uint64_t    tm_start;
     44uint64_t    tm_end;
     45tm_start = hal_get_cycles();
     46if( DEBUG_SYS_TRACE < tm_start )
     47printk("\n[DBG] %s : thread %d enter / process %x / cycle = %d\n",
     48__FUNCTION__, this, this->process->pid, (uint32_t)tm_start );
     49#endif
     50
     51    // check cluster identifier
     52    if( cluster_is_undefined( cxy ) )
    4053    {
    41         printk("\n[ERROR] in %s : undefined thread for PID = %x / TRDID = %x\n",
    42                __FUNCTION__ , pid , trdid );
    43         CURRENT_THREAD->errno = EINVAL;
     54
     55#if DEBUG_SYSCALLS_ERROR
     56printk("\n[ERROR] in %s : illegal cxy argument %x / thread %x / process %x\n",
     57__FUNCTION__ , cxy , this->trdid , process->pid );
     58#endif
     59        this->errno = EINVAL;
    4460        return -1;
    4561    }
    4662
    47     if( operation == TRACE_OFF )
     63    // check core local index
     64    ncores = hal_remote_lw( XPTR( cxy , &LOCAL_CLUSTER->cores_nr ) );
     65    if( lid >= ncores )
    4866    {
    49         // desactivate thread trace TODO
    5067
    51             printk("\n[DBG] %s : trace OFF  for thread %x in process %x\n",
    52                __FUNCTION__ , trdid , pid );
    53     }
    54     else if( operation == TRACE_ON )
    55     {
    56         // activate thread trace TODO
    57                    
    58             printk("\n[DBG] %s : trace ON for thread %x in process %x\n",
    59                __FUNCTION__ , trdid , pid );
    60     }
    61     else
    62     {
    63         printk("\n[ERROR] in %s : undefined operation\n", __FUNCTION__ );
    64         CURRENT_THREAD->errno = EINVAL;
     68#if DEBUG_SYSCALLS_ERROR
     69printk("\n[ERROR] in %s : illegal lid argument %x / thread %x / process %x\n",
     70__FUNCTION__ , lid , this->trdid , process->pid );
     71#endif
     72        this->errno = EINVAL;
    6573        return -1;
    6674    }
    6775
     76    // get local pointer on target core
     77    core_t * core = &LOCAL_CLUSTER->core_tbl[lid];
     78
     79    // get extended pointer on target scheduler trace field
     80    xptr_t trace_xp = XPTR( cxy , &core->scheduler.trace );
     81
     82    if ( active ) hal_remote_sw( trace_xp , 1 );
     83    else          hal_remote_sw( trace_xp , 0 );
     84   
    6885    hal_fence();
     86
     87#if DEBUG_SYS_TRACE
     88tm_end = hal_get_cycles();
     89if( DEBUG_SYS_TRACE < tm_end )
     90printk("\n[DBG] %s : thread %x exit / process %x / cost = %d / cycle %d\n",
     91__FUNCTION__, this, this->process->pid, (uint32_t)(tm_end - tm_start) , (uint32_t)tm_end );
     92#endif
    6993
    7094    return 0;
  • trunk/kernel/syscalls/sys_wait.c

    r440 r443  
    7373        }
    7474
    75     // get process owner cluster and calling thread trdid
     75    // get calling process owner cluster
    7676    cxy_t   owner_cxy = CXY_FROM_PID( pid );
    77     trdid_t trdid     = this->trdid;
    7877
    79     // wait must be executed by the main thread
     78    // get calling thread trdid
     79    trdid_t trdid = this->trdid;
     80
     81    // this function must be executed by the process main thread
    8082    if( (owner_cxy != local_cxy) || (LTID_FROM_TRDID(trdid) != 0) )
    8183    {
     
    113115            child_state = (int)hal_remote_lw ( XPTR(child_cxy,&child_ptr->term_state));
    114116
    115             // test if child process is terminated,
     117            // test if this child process is terminated,
    116118            // but termination not yet reported to parent process
    117119            if( ((child_state & PROCESS_TERM_EXIT)  ||
     
    120122                 ((child_state & PROCESS_TERM_WAIT) == 0) )
    121123            {
    122                 // get pointer on main thread and PID from child owner process
     124                // get pointer on child main thread and PID from child owner process
    123125                child_pid    = (pid_t)     hal_remote_lw (XPTR( child_cxy , &child_ptr->pid ));
    124126                child_thread = (thread_t *)hal_remote_lpt(XPTR( child_cxy ,
    125127                                                                &child_ptr->th_tbl[0] ));
    126128
    127                 // set the PROCESS_FLAG_WAIT in owner child descriptor
     129                // set the PROCESS_FLAG_WAIT in owner child process descriptor
    128130                hal_remote_atomic_or( XPTR( child_cxy , &child_ptr->term_state ),
    129131                                      PROCESS_TERM_WAIT );
  • trunk/kernel/syscalls/sys_write.c

    r441 r443  
    103103    }
    104104
    105     // enable IRQs
    106     hal_enable_irq( &save_sr );
    107 
    108105    // get extended pointer on remote file descriptor
    109106    file_xp = process_fd_get_xptr( process , file_id );
     
    128125    vfs_inode_type_t type = hal_remote_lw( XPTR( file_cxy , &file_ptr->type ) );
    129126
    130     // action depend on file type
     127    // enable IRQs
     128    hal_enable_irq( &save_sr );
     129
     130   // action depend on file type
    131131    if( type == INODE_TYPE_FILE )  // check file writable & write to mapper
    132132    {
     
    152152    else if( type == INODE_TYPE_DEV )  // check ownership & write to device
    153153    {
     154        // check user buffer size for TXT_TX
     155        if( (type == INODE_TYPE_DEV) && (count >= CONFIG_TXT_KBUF_SIZE) )
     156        {
     157
     158#if DEBUG_SYSCALLS_ERROR
     159printk("\n[ERROR] in %s : user buffer size %x too large / thread %x / process %x\n",
     160__FUNCTION__ , count, this->trdid, process->pid );
     161#endif
     162                    this->errno = EINVAL;
     163                    return -1;
     164        }
     165
    154166        // move count bytes to device
    155167        nbytes = devfs_user_move( false,             // from buffer to device
     
    158170                                 count );
    159171    }
    160     else
     172    else  // not FILE and not DEV
    161173    {
    162174        nbytes = 0;
     
    192204exit_sys_write = (uint32_t)tm_end;
    193205
    194 printk("\n@@@@@@@@@@@@ timing to write\n"
     206printk("\n***** timing to write a string *****\n"
    195207" - enter_sys_write          = %d / delta %d\n"
    196208" - enter_devfs_write        = %d / delta %d\n"
  • trunk/kernel/syscalls/syscalls.h

    r440 r443  
    170170 * [10] This function implement the exit system call terminating a POSIX process.
    171171 * It can be called by any thread running in any cluster.
    172  * It uses both remote accesses to access the owner process descriptor, ans the
    173  * RPC_PROCESS_SIGACTION to delete remote process and thread descriptors
     172 * It uses both remote accesses to access the owner process descriptor, and the
     173 * RPC_PROCESS_SIGACTION to delete remote process and thread descriptors.
    174174 * In the present implementation, this function implements actually the _exit():
    175175 * - it does not flush open output streams.
     
    600600
    601601/******************************************************************************************
    602  * [47] This non-standard function is used to activate / desactivate the trace for a thread
    603  * identified by the <trdid> and <pid> arguments.
     602 * [47] This debug function is used to activate / desactivate the context switches trace
     603 * for a core identified by the <cxy> and <lid> arguments.
    604604 * It can be called by any other thread in the same process.
    605605 ******************************************************************************************
    606  * @ operation  : operation type as defined below.
    607  * @ pid        : process identifier.
    608  * @ trdid      : thread identifier.
     606 * @ active     : activate trace if true / desactivate trace if false.
     607 * @ cxy        : cluster identifier.
     608 * @ lid        : core local index.
    609609 * @ returns O if success / returns -1 if failure.
    610610 *****************************************************************************************/
    611 int sys_trace( uint32_t operation,
    612                pid_t    pid,
    613                uint32_t trdid );
     611int sys_trace( bool_t   active,
     612               cxy_t    cxy,
     613               lid_t    lid );
    614614
    615615/******************************************************************************************
  • trunk/libs/mini-libc/stdio.c

    r439 r443  
    328328}
    329329
    330 ///////////////////////////////////
    331 int display_vmm( unsigned int pid )
     330//////////////////////////////////
     331int display_vmm( unsigned int cxy,
     332                 unsigned int pid )
    332333{
    333334    return hal_user_syscall( SYS_DISPLAY,
    334335                             DISPLAY_VMM,
    335                              (reg_t)pid, 0, 0 );
    336 }
    337 
    338 ////////////////////////////////
     336                             (reg_t)cxy,
     337                             (reg_t)pid, 0 );
     338}
     339
     340////////////////////////////////////
    339341int display_sched( unsigned int cxy,
    340342                   unsigned int lid )
     
    383385}
    384386
    385 //////////////////////////////////
    386 int trace( unsigned int operation,
    387            unsigned int pid,
    388            unsigned int trdid )
     387///////////////////////////////
     388int trace( unsigned int active,
     389           unsigned int cxy,
     390           unsigned int lid )
    389391{
    390392    return hal_user_syscall( SYS_TRACE,
    391                              (reg_t)pid,
    392                              (reg_t)trdid, 0, 0 );
    393 }
    394 
    395 
     393                             (reg_t)active,
     394                             (reg_t)cxy,
     395                             (reg_t)lid, 0 );
     396}
     397
     398
  • trunk/libs/mini-libc/stdio.h

    r439 r443  
    402402/***************************************************************************************
    403403 * This debug function displays on the kernel terminal TXT0
    404  * the state of the process VMM identified by the <pid> argument.
     404 * the state of the VMM forthe process <pid>, in cluster <cxy>.
    405405 * It can be called by any thread running in any cluster.
    406406 ***************************************************************************************
     
    408408 * @ return 0 if success / return -1 if illegal argument.
    409409 **************************************************************************************/
    410 int display_vmm( unsigned int  pid );
     410int display_vmm( unsigned int  cxy,
     411                 unsigned int  pid );
    411412
    412413/***************************************************************************************
     
    460461
    461462/*****************************************************************************************
    462  * This debug function is used to activate / desactivate the trace for a thread
    463  * identified by the <trdid> and <pid> arguments.
    464  * It can be called by any other thread in the same process.
    465  *****************************************************************************************
    466  * @ operation  : operation type.
    467  * @ pid        : process identifier.
    468  * @ trdid      : thread identifier.
     463 * This debug function is used to activate / desactivate the context switches trace
     464 * for a core identified by the <cxy> and <lid> arguments.
     465 * It can be called by any thread running in any cluster.
     466 *****************************************************************************************
     467 * @ active     : activate trace if non zero / desactivate if zero.
     468 * @ cxy        : cluster identifier.
     469 * @ lid        : core local index.
    469470 * @ returns O if success / returns -1 if illegal arguments.
    470471 ****************************************************************************************/
    471 int trace( unsigned int operation,
    472            unsigned int pid,
    473            unsigned int trdid );
     472int trace( unsigned int active,
     473           unsigned int cxy,
     474           unsigned int lid );
    474475
    475476
  • trunk/libs/mini-libc/stdlib.c

    r441 r443  
    553553    printf("\n[ERROR] in %s : not implemented yet : do nothing\n", __FUNCTION__ );
    554554}
     555
     556///////////
     557void idbg()
     558{
     559   char          cmd;
     560   unsigned int  cxy;
     561   unsigned int  lid;
     562   unsigned int  txt;
     563   unsigned int  active;
     564
     565   while( 1 )
     566   {
     567        printf("\n[idbg] cmd = ");
     568        cmd = (char)getchar();
     569
     570        if( cmd == 'h' )
     571        {
     572            printf("h\n"
     573                   "p : display on TXT0 process descriptors in cluster[cxy]\n"
     574                   "s : display on TXT0 scheduler state for core[cxy,lid]\n"
     575                   "v : display on TXT0 VMM for calling process in cluster [cxy]\n"
     576                   "t : display on TXT0 process decriptors attached to TXT[tid]\n"
     577                   "y : activate/desactivate trace for core[cxy,lid]\n"
     578                   "x : force calling process to exit\n"
     579                   "c : resume calling process execution\n"
     580                   "h : list supported commands\n");
     581        }
     582        else if( cmd == 'p' )
     583        {
     584            printf("p / cxy = ");
     585            cxy = getint();
     586            display_cluster_processes( cxy );
     587        }
     588        else if( cmd == 's' )
     589        {
     590            printf("s / cxy = ");
     591            cxy = getint();
     592            printf(" / lid = ");
     593            lid = getint();
     594            display_sched( cxy , lid );
     595        }
     596        else if( cmd == 'v' )
     597        {
     598            printf("v / cxy = ");
     599            cxy = getint();
     600            display_vmm( cxy , (unsigned int)getpid() );
     601        }
     602        else if( cmd == 't' )
     603        {
     604            printf("t / txt_id = ");
     605            txt = getint();
     606            display_txt_processes( txt );
     607        }
     608        else if( cmd == 'y' )
     609        {
     610            printf("y / active = ");
     611            active = getint();
     612            printf(" / cxy = ");
     613            cxy    = getint();
     614            printf(" / lid = ");
     615            lid    = getint();
     616            trace( active , cxy , lid );
     617        }
     618        else if( cmd == 'x' )
     619        {
     620            printf("x\n");
     621            exit( 0 );
     622        }
     623        else if( cmd == 'c' )
     624        {
     625            printf("c\n");
     626            break;
     627        }
     628    }
     629}  // end idbg()
     630
     631
     632
  • trunk/libs/mini-libc/stdlib.h

    r439 r443  
    130130int rand();
    131131
     132/*********************************************************************************************
     133 * This blocking function implements an user-level interactive debugger that can be
     134 * introduced in any user application to display various kernel distributed structures
     135 * related to the calling process. The supported commands are:
     136 * - p (cxy)     : display all processes descriptors in a given cluster.
     137 * - s (cxy,lid) : display all threads attached to a given core in a given cluster.
     138 * - v (cxy)     : display the calling process VMM in a given cluster.
     139 * - t (tid)     : display all owner process descriptors attached to a given TXT terminal.
     140 * - x           : force the calling process to exit.
     141 * - c           : continue calling process execution.
     142 *********************************************************************************************
     143 * @ return an integer value between 0 and RAND_MAX.
     144 ********************************************************************************************/
     145void idbg();
     146
     147
    132148#endif  // _STDLIB_H_
  • trunk/params-hard.mk

    r440 r443  
    22
    33ARCH      = /users/alain/soc/tsar-trunk-svn-2013/platforms/tsar_generic_iob
    4 X_SIZE    = 1
     4X_SIZE    = 2
    55Y_SIZE    = 2
    6 NB_PROCS  = 2
     6NB_PROCS  = 1
    77NB_TTYS   = 3
    88FBF_WIDTH = 128
Note: See TracChangeset for help on using the changeset viewer.