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

Fix bugs in exec

File:
1 edited

Legend:

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

    r408 r409  
    4444
    4545/***************************************************************************************
    46  * These macros are used to compose or decompose global thread identifier (TRDID)
     46 * These macros are used to compose or decompose the global thread identifier (TRDID)
    4747 * to or from cluster identifier / local thread index (CXY , LTID)
    4848 **************************************************************************************/
     
    6969 **************************************************************************************/
    7070
    71 #define THREAD_FLAG_LOADABLE     0x0001  /*! This thread has not been executed yet    */
    72 #define THREAD_FLAG_DETACHED     0x0002  /*! This thread is detached from parent      */
    73 #define THREAD_FLAG_JOIN         0x0004  /*! Parent thread made a join                */
    74 #define THREAD_FLAG_EXIT         0x0008  /*! This thread made an exit                 */
    75 #define THREAD_FLAG_SCHED        0x0010  /*! Scheduling required for this thread      */
    76 
    77 /***************************************************************************************
    78  * This defines the masks associated to the thread signals.
    79  **************************************************************************************/
    80 
    81 #define THREAD_SIG_KILL          0x0001  /*! This thread killed by another thread     */
    82 #define THREAD_SIG_SUICIDE       0x0002  /*! This thread required exit                */
     71#define THREAD_FLAG_DETACHED     0x0001  /*! This thread is detached from parent      */
     72#define THREAD_FLAG_JOIN_DONE    0x0002  /*! Parent thread made a join                */
     73#define THREAD_FLAG_SCHED        0x0004  /*! Scheduling required for this thread      */
     74#define THREAD_FLAG_SIGNAL       0x0004  /*! Acknowledge of descheduling required     */
    8375
    8476/***************************************************************************************
     
    8981#define THREAD_BLOCKED_IO        0x0002  /*! thread wait IO operation completion      */
    9082#define THREAD_BLOCKED_MAPPER    0x0004  /*! thread wait mapper                       */
    91 #define THREAD_BLOCKED_JOIN      0x0008  /*! thread blocked in join / wait exit       */
    92 #define THREAD_BLOCKED_EXIT      0x0010  /*! thread blocked in exit / wait join       */
    93 #define THREAD_BLOCKED_KILL      0x0020  /*! thread received kill signal              */
    94 #define THREAD_BLOCKED_SEM       0x0040  /*! thread wait semaphore                    */
    95 #define THREAD_BLOCKED_PAGE      0x0080  /*! thread wait page access                  */
    96 #define THREAD_BLOCKED_USERSYNC  0x0100  /*! thread wait POSIX (cond/mutex/barrier)   */
     83#define THREAD_BLOCKED_EXIT      0x0008  /*! thread blocked in join / wait exit       */
     84#define THREAD_BLOCKED_JOIN      0x0010  /*! thread blocked in exit / wait join       */
     85#define THREAD_BLOCKED_SEM       0x0020  /*! thread wait semaphore                    */
     86#define THREAD_BLOCKED_PAGE      0x0040  /*! thread wait page access                  */
     87#define THREAD_BLOCKED_USERSYNC  0x0100  /*! thread wait (cond/mutex/barrier)         */
    9788#define THREAD_BLOCKED_RPC       0x0200  /*! thread wait RPC completion               */
    98 
    99 #define THREAD_BLOCKED_DEV_ISR   0x4000  /*! thread DEV wait ISR                      */
     89#define THREAD_BLOCKED_DEV_ISR   0x0400  /*! thread DEV wait ISR                      */
    10090
    10191/***************************************************************************************
     
    156146    xptr_t              parent;          /*! extended pointer on parent thread        */
    157147
    158     void              * exit_value;      /*! exit_value used in case of join          */
    159 
    160148        uint32_t            local_locks;         /*! number of local locks owned by thread    */
    161     list_entry_t        locks_root;      /*! root of local locks list                 */
    162 
    163     remote_spinlock_t * flags_lock;      /*! lock protecting the flags                */
    164 
    165         uint32_t            remote_locks;        /*! number of local locks owned by thread    */
    166     xlist_entry_t       xlocks_root;     /*! root of remote locks list                */
     149        uint32_t            remote_locks;        /*! number of remote locks owned by thread   */
     150
     151    remote_spinlock_t * join_lock;       /*! lock protecting the join/exit            */
     152    void              * join_value;      /*! exit_value used in case of join          */
     153    xptr_t              join_xp;         /*! extended pointer on joining thread       */
     154
     155    uint32_t          * sig_rsp_count;   /*! pointer on signal response counter       */
    167156
    168157        intptr_t            u_stack_base;    /*! user stack base address                  */
     
    173162
    174163    uint32_t            flags;           /*! bit vector of flags                      */
    175     uint32_t            signals;         /*! bit vector of (KILL / SUICIDE) signals   */
    176164    uint32_t            blocked;         /*! bit vector of blocking causes            */
    177165
     
    203191
    204192    xlist_entry_t       wait_list;       /*! member of threads blocked on same cond   */
     193
     194#if CONFIG_LOCKS_DEBUG
     195    list_entry_t        locks_root;      /*! root of list of locks taken              */
     196    xlist_entry_t       xlocks_root;     /*! root of xlist of remote locks taken      */
     197#endif
    205198
    206199        thread_info_t       info;            /*! embedded thread_info_t                   */
     
    311304
    312305/***************************************************************************************
    313  * This function releases the physical memory allocated for a thread descriptor
    314  * in the local cluster. It can be used for both an user and a kernel thread.
    315  * The physical memory dynamically allocated in the HEAP or MMAP zones by an user
    316  * thread will be released when the process is killed, and the page table flushed.
     306 * This function releases the physical memory allocated for a thread in a given cluster.
     307 * This include the thread descriptor itself, the associated CPU and FPU context, and
     308 * the physical memory allocated for an user thread local stack.
    317309 ***************************************************************************************
    318310 * @ thread  : pointer on the thread descriptor to release.
     
    353345
    354346/***************************************************************************************
    355  * This function atomically sets a signal in a thread descriptor.
     347 * This function is used by a killer thread running in the same cluster as a target
     348 * thread to request the scheduler of the target to call the thread_handle_signal()
     349 * at the next context switch, to confirm that the target thread is blocked and
     350 * not currently running. This function executes atomically the following actions :
     351 * - it set the sig_pending flag in the target scheduler descriptor.
     352 * - it set the SIG flag in the "flags" field of the target thread descriptor.
     353 * - It registers the responses counter pointer in the target thread descriptor.
     354 * The sig_pending flag is handled as a set/reset flip-flop by the killer thread
     355 * and by the target scheduler.
     356 ***************************************************************************************
     357 * @ target        : local pointer on target thread.
     358 * @ sig_rsp_count : local pointer on responses counter.
     359 **************************************************************************************/
     360void thread_set_signal( thread_t * thread,
     361                        uint32_t * sig_rsp_count );
     362
     363/***************************************************************************************
     364 * This function is used by the sched_handle_signal() function executed by a scheduler
     365 * to reset a pending signal in both a target <thread> descriptor, and in the target
     366 * thread scheduler.
    356367 ***************************************************************************************
    357368 * @ thread    : local pointer on target thread.
    358  *s released all locks @ mask      : mask on selected signal.
    359  **************************************************************************************/
    360 inline void thread_set_signal( thread_t * thread,
    361                                uint32_t   mask );
    362 
    363 /***************************************************************************************
    364  * This function resets a signal in a thread descriptor.
    365  ***************************************************************************************
    366  * @ thread    : local pointer on target thread.
    367  * @ mask      : mask on selected signal.
    368  **************************************************************************************/
    369 inline void thread_reset_signal( thread_t * thread,
    370                                  uint32_t   mask );
     369 **************************************************************************************/
     370void thread_reset_signal( thread_t * thread );
    371371
    372372/***************************************************************************************
     
    385385
    386386/***************************************************************************************
    387  * This function is used by the calling thread to suicide.
    388  * All locks must be previously released. The scenario depends on the DETACHED flag.
    389  * if detached :
    390  * 1) the calling thread sets the SIG_SUICIDE bit in the "signals" bit_vector,
    391  *    registers the BLOCKED_GLOBAL bit in the "blocked" bit_vector, and deschedule.
    392  * 2) the scheduler, detecting the SIG_SUICIDE bit, remove the thread from the
    393  *    scheduler list, remove the thread from its process, and destroys the thread.
    394  * if attached :
    395  * 1) the calling thread simply sets the BLOCKED_EXIT bit in the "blocked" bit vector
    396  *    and deschedule.
    397  * 2) The SIG_KILL bit and BLOCKED_SIGNAL bits are set by the parent thread when
    398  *    executing the pthread_join(), and detecting the BLOCKED_EXIT bit.
    399  *    The scenario is a standard kill as described below.
    400  ***************************************************************************************
    401  * @ returns 0 if success / returns EINVAL if locks_count is not zero.
    402  **************************************************************************************/
    403 error_t thread_exit();
    404 
    405 /***************************************************************************************
    406  * This function request to kill a local target thread, with the following scenario:
    407  * 1. This function set the BLOCKED_GLOBAL bit in target thread "blocked" bit_vector,
    408  *    set the SIG_KILL bit in target thread "signals" bit_vector, and send an IPI
    409  *    to the target thread core to force scheduling.
    410  * 2. The scheduler, detecting the SIG_KILL set, removes the thread from the scheduler
    411  *    list, and reset the SIG_KILL bit to acknowledge the killer.
    412  * 3. The caller of this function, (such as the process_kill() function), must poll
    413  *    SIG_KILL bit until reset, detach the thread from its parent if the thread is
    414  *    attached, remove the thread from its process, and destroys the thread.
    415  *
    416  * NOTE: The third step must be done by the caller to allows the process_kill()
    417  *       function to parallelize the work on all schedulers in a given cluster.
     387 * This function is called to handle the "pthread_cancel" system call.
     388 * It allows a killer thread to kill one single target thread.
     389 * The killer thread must be running in the same cluster as the target thread.
     390 * If not, the client thread must use the RPC_THREAD_KILL.
     391 * - When the killer thread is running on the same core as the target thread,
     392 *   This function simply detach the target thread from the scheduler,
     393 *   detach it from the parent thread if it is attached, detach it from the
     394 *   local process descriptor, and rrleases all memory allocated to the thread.
     395 * - When the killer thread is running on a different core than the target thread
     396 *   The killer send a signal to the target thread scheduler requesting this
     397 *   scheduler to confirm that the target thread is blocked and not running.
     398 *   Then, it executes the same actions as described above.
    418399 ***************************************************************************************
    419400 * @ thread   : local pointer on the target thread.
Note: See TracChangeset for help on using the changeset viewer.