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

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/kern/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
Note: See TracChangeset for help on using the changeset viewer.