Ignore:
Timestamp:
Oct 10, 2018, 3:11:53 PM (6 years ago)
Author:
alain
Message:

1) Improve the busylock debug infrastructure.
2) introduce a non-distributed, but portable implementation for the pthread_barrier.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/syscalls/shared_include/shared_pthread.h

    r566 r581  
    3232
    3333/*******************************************************************************************
    34  * These typedef define the POSIX thread related types.
     34 * These typedef and enum define the shared information related to the POSIX thread.
    3535 ******************************************************************************************/
    3636
    37 typedef unsigned int      pthread_mutex_t;
    38 typedef unsigned int      pthread_mutexattr_t;         // TODO not implemented
    39 
    40 typedef unsigned int      pthread_cond_t;
    41 typedef unsigned int      pthread_condattr_t;          // TODO not implemented
    42 
    43 typedef unsigned int      pthread_rwlock_t;            // TODO not implemented
    44 typedef unsigned int      pthread_rwlockattr_t;        // TODO not implemented
    45 
    46 /*******************************************************************************************
    47  * This structure and enum define the attributes for the pthread_create() syscall.
    48  ******************************************************************************************/
    49 
    50 typedef unsigned int  pthread_t;               
     37typedef unsigned int    pthread_t;               
    5138
    5239typedef struct pthread_attr_s
    5340{
    54         unsigned int      attributes;      /*! user defined attributes bit vector             */
    55         unsigned int      cxy;             /*! target cluster identifier                      */
    56         unsigned int      lid;             /*! target core local index                        */
     41        unsigned int        attributes;      /*! user defined attributes bit vector           */
     42        unsigned int        cxy;             /*! target cluster identifier                    */
     43        unsigned int        lid;             /*! target core local index                      */
    5744}
    5845pthread_attr_t;
     
    6047enum
    6148{
    62     PT_ATTR_DETACH          = 0x0001,  /*! user defined not joinable                      */
    63     PT_ATTR_CLUSTER_DEFINED = 0x0002,  /*! user defined target cluster                    */
    64     PT_ATTR_CORE_DEFINED    = 0x0004,  /*! user defined core index in cluster             */
     49    PT_ATTR_DETACH          = 0x0001,    /*! user defined not joinable                    */
     50    PT_ATTR_CLUSTER_DEFINED = 0x0002,    /*! user defined target cluster                  */
     51    PT_ATTR_CORE_DEFINED    = 0x0004,    /*! user defined core index in cluster           */
    6552};
    6653
    67 /******************************************************************************************* 
    68  * This enum defines the operation mnemonics for operations on POSIX condition variables.
     54/*******************************************************************************************
     55 * These typedef and enum define the shared informations related to the POSIX mutex.
    6956 ******************************************************************************************/
     57
     58typedef unsigned int    pthread_mutex_t;
     59
     60typedef unsigned int    pthread_mutexattr_t;         // TODO not implemented
     61
     62typedef enum
     63{
     64        MUTEX_INIT,
     65        MUTEX_DESTROY,
     66        MUTEX_LOCK,
     67        MUTEX_UNLOCK,
     68    MUTEX_TRYLOCK,
     69}
     70mutex_operation_t;
     71
     72/*******************************************************************************************
     73 * These typedef and enum define the shared informations related to the POSIX condvar.
     74 ******************************************************************************************/
     75
     76typedef unsigned int    pthread_cond_t;
     77
     78typedef unsigned int    pthread_condattr_t;          // TODO not implemented
    7079
    7180typedef enum
     
    7988condvar_operation_t;
    8089
     90/*******************************************************************************************
     91 * These typedef define and enum the shared informations related to the POSIX rwlock.
     92 ******************************************************************************************/
     93
     94typedef unsigned int    pthread_rwlock_t;            // TODO not implemented
     95
     96typedef unsigned int    pthread_rwlockattr_t;        // TODO not implemented
     97
    8198/*******************************************************************************************
    82  * This enum defines the operation mnemonics for operations on POSIX barriers.
     99 * These typedef and enum define the shared informations related to POSIX barriers.
    83100 ******************************************************************************************/
     101
     102typedef unsigned int    pthread_barrier_t;
     103
     104typedef struct pthread_barrierattr_s
     105{
     106    unsigned int        x_size;         /*! number of clusters in a row                   */
     107    unsigned int        y_size;         /*! number of clusters in a column                */
     108    unsigned int        nthreads;       /*! number of expected threads in a cluster       */
     109}
     110pthread_barrierattr_t;
    84111
    85112typedef enum
     
    91118barrier_operation_t;
    92119
    93 /*******************************************************************************************
    94  * This enum defines the operation mnemonics for operations on POSIX mutex.
    95  ******************************************************************************************/
     120/*********************************************************************************************
     121 * These structures define another implementation for the POSIX barrier:
     122 * It is implemented as a hierarchical, physically distributed quad-tree,
     123 * covering all clusters specified, with the following constraints:
     124 *   . The involved clusters form a mesh [x_size * y_size]
     125 *   . The lower left involved cluster is cluster(0,0) 
     126 *   . The number of threads per cluster is the same in all clusters.
     127 *
     128 * Implementation note:
     129 * - The quad three is implemented as a three dimensions array of node[x][y][l]
     130 *   . [x][y] are the cluster coordinates / max values are (QDT_XMAX-1), (QDT_YMAX-1)
     131 *   . [l] is the node level / 0 for terminal nodes / (QDT_LMAX-1) for the root node
     132 ********************************************************************************************/
    96133
    97 typedef enum
     134/*
     135
     136#define  QDT_XMAX    16                // max number of clusters in a row
     137#define  QDT_YMAX    16                // max number of clusters in a column
     138#define  QDT_LMAX    5                 // max depth of the quad tree
     139#define  QDT_YWIDTH  4                 // Y field in cxy, for cxy <=> (x,y) translation
     140#define  QDT_YMASK   0xF               // Y field in cxy, for cxy <=> (x,y) translation
     141
     142typedef struct sqt_node_s
    98143{
    99         MUTEX_INIT,
    100         MUTEX_DESTROY,
    101         MUTEX_LOCK,
    102         MUTEX_UNLOCK,
    103     MUTEX_TRYLOCK,
    104 }
    105 mutex_operation_t;
     144    volatile unsigned int sense;       // barrier state (toggle)
     145    volatile unsigned int count;       // number of not arrived tasks
     146    unsigned int          arity;       // number of locally expected tasks
     147    unsigned int          level;       // hierarchical level (0 is bottom)
     148    struct sqt_node_s   * parent;      // pointer on parent node (NULL for root)
     149    struct sqt_node_s   * child[4];    // pointer on children node (NULL for bottom)
     150}
     151sqt_node_t;
    106152
     153typedef struct pthread_barrier_s
     154{
     155    sqt_node_t          * node[QDT_XMAX][QDT_YMAX][QDT_LMAX];
     156}
     157pthread_barrier_t;
    107158
     159*/
    108160
    109161#endif  // _PTHREAD_H_
Note: See TracChangeset for help on using the changeset viewer.