Changeset 174 for trunk/kernel/kern


Ignore:
Timestamp:
Jul 11, 2017, 10:46:55 AM (7 years ago)
Author:
max@…
Message:

style

File:
1 edited

Legend:

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

    r23 r174  
    11/*
    22 * thread.h -  Thread and related operations definition.
    3  * 
     3 *
    44 * Author  Ghassan Almaless (2008,2009,2010,2011,2012)
    55 *         Alain Greiner (2016)
     
    4646 **************************************************************************************/
    4747
    48 #define LTID_FROM_TRDID( trdid )   (ltid_t)(trdid & 0x0000FFFF) 
     48#define LTID_FROM_TRDID( trdid )   (ltid_t)(trdid & 0x0000FFFF)
    4949#define CXY_FROM_TRDID( trdid )    (cxy_t)(trdid >> 16)
    5050#define TRDID( cxy , ltid )        (trdid_t)((cxy << 16) | ltid )
     
    5555
    5656/***************************************************************************************
    57  * This opaque structure contains the user defined attributes for an user thread.
     57 * This opaque structure contains the user defined attributes for a user thread.
    5858 * It is passed as input argument to the thread_user_create() function.
    5959 * It is set by the user application itself, using the pthread_attr_***() functions.
    6060 * The currently supported attributes are defined below.
    6161 **************************************************************************************/
    62  
     62
    6363typedef struct pthread_attr_s
    6464{
     
    6666        cxy_t       cxy;             /*! target cluster identifier                        */
    6767        lid_t       lid;             /*! target core index                                */
    68 } 
     68}
    6969pthread_attr_t;
    7070
     
    8282
    8383typedef enum
    84 {   
    85         THREAD_USER    = 0,          /*! user thread (pthread)                            */ 
     84{
     85        THREAD_USER    = 0,          /*! user thread (pthread)                            */
    8686        THREAD_RPC     = 1,          /*! kernel thread executing pending RPCs             */
    8787        THREAD_DEV     = 2,          /*! kernel thread executing I/O device commands      */
     
    8989        THREAD_IDLE    = 4,          /*! kernel idle thread                               */
    9090        THREAD_TYPES_NR
    91 } 
     91}
    9292thread_type_t;
    9393
     
    111111 **************************************************************************************/
    112112
    113 #define THREAD_BLOCKED_GLOBAL    0x0001  /*! thread desactivated / wait activation    */
     113#define THREAD_BLOCKED_GLOBAL    0x0001  /*! thread deactivated / wait activation     */
    114114#define THREAD_BLOCKED_IO        0x0002  /*! thread wait IO operation completion      */
    115115#define THREAD_BLOCKED_MAPPER    0x0004  /*! thread wait mapper                       */
     
    150150 * This structure defines a thread descriptor.
    151151 * It is used for both the user threads and the kernel threads.
    152  * In a process, an user thread is identified by a unique TRDID (thread identifier),
     152 * In a process, a user thread is identified by a unique TRDID (thread identifier),
    153153 * that is returned by the kernel to the user:
    154154 * - The TRDID 16 LSB bits contain the LTID (Local Thread Index).
     
    156156 * - The LTID is used to index the th_tbl[] array in the local process descriptor.
    157157 * This TRDID is computed by the process_register_thread() function, when the user
    158  * thread is registerd in the local copy of the process descriptor.
     158 * thread is registered in the local copy of the process descriptor.
    159159 **************************************************************************************/
    160160
     
    174174        core_t            * core;            /*! pointer to the owner core                */
    175175        process_t         * process;         /*! pointer on local process descriptor      */
    176     xptr_t              parent;          /*! extended pointer on parent thread        */       
     176    xptr_t              parent;          /*! extended pointer on parent thread        */
    177177
    178178    void              * exit_value;      /*! exit_value used in case of join          */
    179    
     179
    180180        uint32_t            local_locks;         /*! number of local locks owned by thread    */
    181181    list_entry_t        locks_root;      /*! root of local locks list                 */
     
    220220        mmc_command_t   mmc;             /*! MMC device generic command               */
    221221        dma_command_t   dma;             /*! DMA device generic command               */
    222     } 
     222    }
    223223    command;
    224    
     224
    225225        cxy_t               rpc_client_cxy;  /*! client cluster index (for a RPC thread)  */
    226226
     
    230230
    231231        uint32_t            signature;       /*! for kernel stack overflow detection      */
    232 } 
     232}
    233233thread_t;
    234234
     
    248248
    249249/***************************************************************************************
    250  * This function allocates memory for an user thread descriptor in the local cluster,
     250 * This function allocates memory for a user thread descriptor in the local cluster,
    251251 * 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.
     252 * It is used by the "pthread_create" system call.
     253 * The CPU context is initialized from scratch, and the "loadable" field is set.
    254254 * The new thread is attached to the core specified in the <attr> argument.
    255255 * It is registered in the local process descriptor specified by the <pid> argument.
    256256 * The thread descriptor pointer is returned to allow the parent thread to register it
    257257 * in its children list.
    258  * The THREAD_BLOCKED_GLOBAL bit is set => the thread must be activated to start.   
     258 * The THREAD_BLOCKED_GLOBAL bit is set => the thread must be activated to start.
    259259 ***************************************************************************************
    260260 * @ pid          : process identifier.
     
    262262 * @ start_args   : pointer on function argument (can be NULL).
    263263 * @ attr         : pointer on pthread attributes descriptor.
    264  * @ new_thread   : [out] address of buffer for new thread descriptor pointer. 
     264 * @ new_thread   : [out] address of buffer for new thread descriptor pointer.
    265265 * @ returns 0 if success / returns ENOMEM if error.
    266266 **************************************************************************************/
     
    273273/***************************************************************************************
    274274 * This function allocates memory for an user thread descriptor in the local cluster,
    275  * and initialises it from informations contained in the calling thread descriptor.
     275 * and initializes it from information contained in the calling thread descriptor.
    276276 * It is used by the fork() system call to create the child process main thread.
    277  * The new thread is attached to the core with the lowest load. 
     277 * The new thread is attached to the core with the lowest load.
    278278 * It is registered in the process descriptor defined by the "process" argument.
    279279 * This new thread inherits its execution context from the calling thread,
    280280 * and the "loadable" field is NOT set.
    281  * The THREAD_BLOCKED_GLOBAL bit is set, and the thread must be activated to start.   
     281 * The THREAD_BLOCKED_GLOBAL bit is set, and the thread must be activated to start.
    282282 ***************************************************************************************
    283283 * @ process      : local pointer on owner process descriptor.
    284  * @ new_thread   : [out] address of buffer for new thread descriptor pointer. 
     284 * @ new_thread   : [out] address of buffer for new thread descriptor pointer.
    285285 * @ returns 0 if success / returns ENOMEM if error.
    286286 **************************************************************************************/
     
    290290/***************************************************************************************
    291291 * This function allocates memory for a kernel thread descriptor in the local cluster,
    292  * and initialise it from arguments values, calling the thread_kernel_init() function,
     292 * and initializes it from arguments values, calling the thread_kernel_init() function,
    293293 * that also allocates and initializes the CPU context.
    294  * The THREAD_BLOCKED_GLOBAL bit is set, and the thread must be activated to start.   
     294 * The THREAD_BLOCKED_GLOBAL bit is set, and the thread must be activated to start.
    295295 ***************************************************************************************
    296296 * @ new_thread   : address of buffer for new thread pointer.
     
    303303error_t thread_kernel_create( thread_t     ** new_thread,
    304304                              thread_type_t   type,
    305                               void          * func, 
     305                              void          * func,
    306306                              void          * args,
    307307                              lid_t           core_lid );
    308308
    309309/***************************************************************************************
    310  * This function initialises an existing kernel thread descriptor from arguments values.
    311  * The THREAD_BLOCKED_GLOBAL bit is set, and the thread must be activated to start.   
     310 * This function initializes an existing kernel thread descriptor from arguments values.
     311 * The THREAD_BLOCKED_GLOBAL bit is set, and the thread must be activated to start.
    312312 ***************************************************************************************
    313313 * @ thread   : pointer on existing thread descriptor.
     
    320320error_t thread_kernel_init( thread_t      * thread,
    321321                            thread_type_t   type,
    322                             void          * func, 
     322                            void          * func,
    323323                            void          * args,
    324324                            lid_t           core_lid );
    325325
    326326/***************************************************************************************
    327  * This function releases the physical memory allocated for a thread descriptor 
     327 * This function releases the physical memory allocated for a thread descriptor
    328328 * in the local cluster. It can be used for both an user and a kernel thread.
    329  * The physical memory dynamically allocated in the HEAP or MMAP zones by an user 
     329 * The physical memory dynamically allocated in the HEAP or MMAP zones by an user
    330330 * thread will be released when the process is killed, and the page table flushed.
    331331 ***************************************************************************************
    332  * @ thread  : pointer on the thread descriptor to release. 
     332 * @ thread  : pointer on the thread descriptor to release.
    333333 **************************************************************************************/
    334334void thread_destroy( thread_t * thread );
     
    338338 * or when no other thread is runnable for a given core.
    339339 *
    340  * TODO: In the TSAR architecture, it enters an infinite loop, in wich it forces 
     340 * TODO: In the TSAR architecture, it enters an infinite loop, in wich it forces
    341341 * the core in sleep (low-power) mode. Any IRQ will force the core to exit this sleep
    342342 * mode, but no ISR is executed.
     
    346346
    347347/***************************************************************************************
    348  * This function registers a child thread in the global list of attached 
     348 * This function registers a child thread in the global list of attached
    349349 * children threads of a parent thread.
    350  * It does NOT take a lock, as this function is allways called by the parent thread.
     350 * It does NOT take a lock, as this function is always called by the parent thread.
    351351 ***************************************************************************************
    352352 * @ xp_parent : extended pointer on the parent thread descriptor.
     
    357357
    358358/***************************************************************************************
    359  * This function removes an user thread from the parent thread global list 
    360  * of attached children threads. 
     359 * This function removes an user thread from the parent thread global list
     360 * of attached children threads.
    361361 ***************************************************************************************
    362362 * @ xp_parent : extended pointer on the parent thread descriptor.
     
    367367
    368368/***************************************************************************************
    369  * This function atomically set a signal in a thread descriptor.
     369 * This function atomically sets a signal in a thread descriptor.
    370370 ***************************************************************************************
    371371 * @ thread    : local pointer on target thread.
     
    376376
    377377/***************************************************************************************
    378  * This function reset a signal in a thread descriptor.
     378 * This function resets a signal in a thread descriptor.
    379379 ***************************************************************************************
    380380 * @ thread    : local pointer on target thread.
     
    395395
    396396/***************************************************************************************
    397  * This function cheks if the calling thread can deschedule.
     397 * This function checks if the calling thread can deschedule.
    398398 ***************************************************************************************
    399399 * @ returns true if no locks taken.
     
    402402
    403403/***************************************************************************************
    404  * This function checks if the calling thread must be descheduled. 
     404 * This function checks if the calling thread must be descheduled.
    405405 ***************************************************************************************
    406406 * @ returns true if no locks taken, and elapsed time.
     
    410410/***************************************************************************************
    411411 * This function can be used by the calling thread to suicide.
    412  * All locks must be previouly released.
     412 * All locks must be previously released.
    413413 * The scenario depends on the attached/detached flag :
    414  * - if detached, it set the SIG_KILL signal in the "signals" bit_vector, registers
     414 * - if detached, it sets the SIG_KILL signal in the "signals" bit_vector, registers
    415415 *   the BLOCKED_EXIT bit in the "blocked" bit_vector, and deschedule.
    416  * - if attached, it simply set the BLOCKED_EXIT bit in the "blocked" bit vector
     416 * - if attached, it simply sets the BLOCKED_EXIT bit in the "blocked" bit vector
    417417 *   and deschedule. The SIG_KILL signal will be set by the parent thread when
    418418 *   executing the pthread_join().
     
    422422error_t thread_exit();
    423423
    424 /*************************************************************************************** 
     424/***************************************************************************************
    425425 * This function registers a blocking cause in the target thread "blocked" bit vector.
    426426 * Warning : this function does not deschedule the calling thread.
    427  * The descheduling can be forced by a sched_yield(). 
     427 * The descheduling can be forced by a sched_yield().
    428428 ***************************************************************************************
    429429 * @ thread   : local pointer on target thread.
     
    433433                   uint32_t   cause );
    434434
    435 /*************************************************************************************** 
    436  * This function reset the bit identified by the cause argument in the "blocked"
     435/***************************************************************************************
     436 * This function resets the bit identified by the cause argument in the "blocked"
    437437 * bit vector of a remote thread descriptor.
    438438 * We need an extended pointer, because the client thread of an I/O operation on a
    439439 * given device is not in the same cluster as the associated device descriptor.
    440  * Warning : this function does not reschedule the remote thread. 
     440 * Warning : this function does not reschedule the remote thread.
    441441 * The scheduling can be forced by sending an IPI to the core running the remote thread.
    442442 ***************************************************************************************
     
    447447                     uint32_t cause );
    448448
    449 /*************************************************************************************** 
     449/***************************************************************************************
    450450 * This function kills a target thread, identified by its local pointer.
    451451 * It is generally called by the local process_destroy() function.
     
    460460
    461461/***************************************************************************************
    462  * This function updates the calling thread user_time counter, and reset the thread
     462 * This function updates the calling thread user_time counter, and resets the thread
    463463 * cycles counter.
    464464 * TODO This function is not implemented.
     
    469469
    470470/**************************************************************************************n
    471  * This function updates the calling thread kernel_time counter, and reset the thread
     471 * This function updates the calling thread kernel_time counter, and resets the thread
    472472 * cycles counter.
    473473 * TODO This function is not implemented.
     
    478478
    479479/***************************************************************************************
    480  * This function handle all pending signals for the thread identified by the <thread>
    481  * argument. It is called each time the core exit the kernel, after handling an
    482  * interrupt, exception or syscall. 
     480 * This function handles all pending signals for the thread identified by the <thread>
     481 * argument. It is called each time the core exits the kernel, after handling an
     482 * interrupt, exception or syscall.
    483483 * TODO This function is not implemented.
    484484 ***************************************************************************************
     
    494494 * @ pid     : process identifier.
    495495 * @ trdid   : thread identifier.
    496  * @ return the extended pointer if thread found / return XPTR_NULL if not found. 
     496 * @ return the extended pointer if thread found / return XPTR_NULL if not found.
    497497 **************************************************************************************/
    498498xptr_t thread_get_xptr( pid_t    pid,
Note: See TracChangeset for help on using the changeset viewer.