Ignore:
Timestamp:
Jun 18, 2017, 10:06:41 PM (7 years ago)
Author:
alain
Message:

Introduce syscalls.

File:
1 edited

Legend:

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

    r16 r23  
    33 *
    44 * Author  Ghassan Almaless (2008,2009,2010,2011,2012)
    5  *         Mohamed Lamine Karaoui (2015)
    65 *         Alain Greiner (2016)
    76 *
     
    4342
    4443/***************************************************************************************
    45  * This defines the various pthread_attr_t flags.
    46  **************************************************************************************/
    47 
    48 #define PT_FLAG_DETACH                0x001    // user defined not joinable
    49 #define PT_FLAG_CLUSTER_DEFINED       0x002    // user defined target cluster
    50 #define PT_FLAG_CORE_DEFINED          0x004    // user defined core cluster
    51 
    52 /***************************************************************************************
    53  * This structure defines the input argument of the pthread_create() system call.
    54  * It contains all informations required to initialize an user thread, and is passed
    55  * as input argument to the thread_user_create() function.
    56  * It is partly set by the kernel, partly set by the user application itself,
    57  * using the pthread_attr_***() functions.
     44 * These macros are used to compose or decompose global thread identifier (TRDID)
     45 * to or from cluster identifier / local thread index (CXY , LTID)
     46 **************************************************************************************/
     47
     48#define LTID_FROM_TRDID( trdid )   (ltid_t)(trdid & 0x0000FFFF)
     49#define CXY_FROM_TRDID( trdid )    (cxy_t)(trdid >> 16)
     50#define TRDID( cxy , ltid )        (trdid_t)((cxy << 16) | ltid )
     51
     52/***************************************************************************************
     53 * This defines the various pthread_attr_t attributes bit-vector.
     54 **************************************************************************************/
     55
     56/***************************************************************************************
     57 * This opaque structure contains the user defined attributes for an user thread.
     58 * It is passed as input argument to the thread_user_create() function.
     59 * It is set by the user application itself, using the pthread_attr_***() functions.
     60 * The currently supported attributes are defined below.
    5861 **************************************************************************************/
    5962 
    6063typedef struct pthread_attr_s
    6164{
    62     pid_t       pid;             /*! owner process identifier                         */
    63         void      * entry_func;      /*! pointer on entry function                        */
    64         void      * entry_args;      /*! pointer on entry function arguments              */
    65         uint32_t    flags;           /*! pthread flags        (entirely user specified)   */
    66         cxy_t       cxy;             /*! target cluster       (can be user specified)     */
    67         lid_t       lid;             /*! target core          (can be user specified)     */
     65        uint32_t    attributes;      /*! user defined attributes bit vector               */
     66        cxy_t       cxy;             /*! target cluster identifier                        */
     67        lid_t       lid;             /*! target core index                                */
    6868}
    6969pthread_attr_t;
    7070
     71typedef enum
     72{
     73    PT_ATTR_DETACH          = 0x0001,  /*! user defined not joinable                  */
     74    PT_ATTR_CLUSTER_DEFINED = 0x0002,  /*! user defined target cluster                */
     75    PT_ATTR_CORE_DEFINED    = 0x0004,  /*! user defined core index in cluster         */
     76}
     77pt_attributes_t;
    7178
    7279/***************************************************************************************
     
    8693
    8794/***************************************************************************************
    88  * This defines the masks associated to the thread flags.
     95 * This defines the thread flags bit-vector.
    8996 **************************************************************************************/
    9097
    9198#define THREAD_FLAG_LOADABLE     0x0001  /*! This thread has not been executed yet    */
    92 #define THREAD_FLAG_DETACHED     0x0002  /*! This user thread is detached from parent */
     99#define THREAD_FLAG_DETACHED     0x0002  /*! This thread is detached from parent      */
     100#define THREAD_FLAG_JOIN         0x0004  /*! Parent thread made a join                */
     101#define THREAD_FLAG_EXIT         0x0008  /*! This thread made an exit                 */
    93102
    94103/***************************************************************************************
     
    102111 **************************************************************************************/
    103112
    104 #define THREAD_BLOCKED_GLOBAL    0x0001  /*! thread global blocking                   */
     113#define THREAD_BLOCKED_GLOBAL    0x0001  /*! thread desactivated / wait activation    */
    105114#define THREAD_BLOCKED_IO        0x0002  /*! thread wait IO operation completion      */
    106115#define THREAD_BLOCKED_MAPPER    0x0004  /*! thread wait mapper                       */
    107 #define THREAD_BLOCKED_EXIT      0x0010  /*! thread requested exit                    */
     116#define THREAD_BLOCKED_JOIN      0x0008  /*! thread blocked in join / wait exit       */
     117#define THREAD_BLOCKED_EXIT      0x0010  /*! thread blocked in exit / wait join i     */
    108118#define THREAD_BLOCKED_KILL      0x0020  /*! thread received kill signal              */
    109119#define THREAD_BLOCKED_SEM       0x0040  /*! thread wait semaphore                    */
    110120#define THREAD_BLOCKED_PAGE      0x0080  /*! thread wait page access                  */
     121#define THREAD_BLOCKED_USERSYNC  0x0100  /*! thread wait POSIX (cond/mutex/barrier)   */
     122
    111123#define THREAD_BLOCKED_IDLE      0x1000  /*! thread RPC wait activation               */
    112124#define THREAD_BLOCKED_DEV_QUEUE 0x2000  /*! thread DEV wait queue                    */
     
    141153 * that is returned by the kernel to the user:
    142154 * - The TRDID 16 LSB bits contain the LTID (Local Thread Index).
    143  * - The TRDID 16 MSB bits contain the owner cluster CXY.
     155 * - The TRDID 16 MSB bits contain the CXY of cluster containing the thread.
    144156 * - The LTID is used to index the th_tbl[] array in the local process descriptor.
    145157 * This TRDID is computed by the process_register_thread() function, when the user
     
    155167        void              * fpu_context;     /*! used for dynamic FPU allocation          */
    156168
    157         uint32_t            trdid;           /*! thread index (in THTBL)                  */
     169        uint32_t            trdid;           /*! thread index (cxy.ltid)                  */
    158170        thread_type_t       type;            /*! thread type                              */
    159171        uint32_t            quantum;         /*! number of clock ticks given to thread    */
     
    162174        core_t            * core;            /*! pointer to the owner core                */
    163175        process_t         * process;         /*! pointer on local process descriptor      */
    164 
     176    xptr_t              parent;          /*! extended pointer on parent thread        */       
     177
     178    void              * exit_value;      /*! exit_value used in case of join          */
     179   
    165180        uint32_t            local_locks;         /*! number of local locks owned by thread    */
    166181    list_entry_t        locks_root;      /*! root of local locks list                 */
     182
     183    remote_spinlock_t * flags_lock;      /*! lock protecting the flags                */
    167184
    168185        uint32_t            remote_locks;        /*! number of local locks owned by thread    */
     
    182199
    183200        error_t             errno;           /*! errno value set by last system call      */
     201    uint32_t            utls;            /*! user thread local storage                */
    184202
    185203    bool_t              fork_user;       /*! user defined placement for next fork()   */
     
    231249/***************************************************************************************
    232250 * This function allocates memory for an user thread descriptor in the local cluster,
    233  * and initializes it from information contained in the "attr" argument.
    234  * It is used by the pthread_create system call, the CPU context is initialised from
    235  * scratch, and the "loadable" field is set.
    236  * The new thread is attached to the core specified in the "attr" argument.
    237  * It is registered in the local process descriptor for the process specified in "attr".
     251 * and initializes it from information contained in the arguments.
     252 * It is used by the "pthread_create" system call.
     253 * The CPU context is initialised from scratch, and the "loadable" field is set.
     254 * The new thread is attached to the core specified in the <attr> argument.
     255 * It is registered in the local process descriptor specified by the <pid> argument.
    238256 * The thread descriptor pointer is returned to allow the parent thread to register it
    239257 * in its children list.
    240  * The THREAD_BLOCKED_GLOBAL bit is set, and the thread must be activated to start.   
    241  ***************************************************************************************
    242  * @ new_thread   : address of buffer for new thread descriptor pointer. 
     258 * The THREAD_BLOCKED_GLOBAL bit is set => the thread must be activated to start.   
     259 ***************************************************************************************
     260 * @ pid          : process identifier.
     261 * @ start_func   : pointer on entry function.
     262 * @ start_args   : pointer on function argument (can be NULL).
    243263 * @ attr         : pointer on pthread attributes descriptor.
    244  * @ u_stack_base : actual user stack size.
    245  * @ u_stack_size : actual user stack base.
     264 * @ new_thread   : [out] address of buffer for new thread descriptor pointer. 
    246265 * @ returns 0 if success / returns ENOMEM if error.
    247266 **************************************************************************************/
    248 error_t thread_user_create( thread_t       ** new_thread,
     267error_t thread_user_create( pid_t             pid,
     268                            void            * start_func,
     269                            void            * start_arg,
    249270                            pthread_attr_t  * attr,
    250                             intptr_t          u_stack_base,
    251                             uint32_t          u_stack_size );
     271                            thread_t       ** new_thread );
    252272
    253273/***************************************************************************************
     
    261281 * The THREAD_BLOCKED_GLOBAL bit is set, and the thread must be activated to start.   
    262282 ***************************************************************************************
    263  * @ new_thread   : address of buffer for new thread descriptor pointer. 
    264283 * @ process      : local pointer on owner process descriptor.
    265  * @ u_stack_base : actual user stack size.
    266  * @ u_stack_size : actual user stack base.
     284 * @ new_thread   : [out] address of buffer for new thread descriptor pointer. 
    267285 * @ returns 0 if success / returns ENOMEM if error.
    268286 **************************************************************************************/
    269 error_t thread_user_fork( thread_t ** new_thread,
    270                           process_t * process,
    271                           intptr_t    u_stack_base,
    272                           uint32_t    u_stack_size );
     287error_t thread_user_fork( process_t * process,
     288                          thread_t ** new_thread );
    273289
    274290/***************************************************************************************
     
    343359 * This function removes an user thread from the parent thread global list
    344360 * of attached children threads.
    345  * It does take the lock, as this function can be called by the child thread.
    346  * In this case, it uses the extended pointer on the parent thread contained
    347  * in the pthread_attr_t embedded in the child thread descriptor.
    348361 ***************************************************************************************
    349362 * @ xp_parent : extended pointer on the parent thread descriptor.
     
    352365void thread_child_parent_unlink( xptr_t xp_parent,
    353366                                 xptr_t xp_child );
    354 
    355367
    356368/***************************************************************************************
     
    475487void thread_signals_handle( thread_t * thread );
    476488
     489/***************************************************************************************
     490 * This function returns the extended pointer on a thread descriptor identified
     491 * by its thread identifier, and process identifier.
     492 * It can be called by any thread running in any cluster.
     493 ***************************************************************************************
     494 * @ pid     : process identifier.
     495 * @ trdid   : thread identifier.
     496 * @ return the extended pointer if thread found / return XPTR_NULL if not found.
     497 **************************************************************************************/
     498xptr_t thread_get_xptr( pid_t    pid,
     499                        trdid_t  trdid );
    477500
    478501
Note: See TracChangeset for help on using the changeset viewer.