[445] | 1 | /* |
---|
| 2 | * shared_pthread.h - Shared structures and mnemonics used by the pthread related syscalls. |
---|
| 3 | * |
---|
| 4 | * Author Alain Greiner (2016,2017,2018) |
---|
| 5 | * |
---|
| 6 | * Copyright (c) UPMC Sorbonne Universites |
---|
| 7 | * |
---|
| 8 | * This file is part of ALMOS-MKH. |
---|
| 9 | * |
---|
| 10 | * ALMOS-MKH is free software; you can redistribute it and/or modify it |
---|
| 11 | * under the terms of the GNU General Public License as published by |
---|
| 12 | * the Free Software Foundation; version 2.0 of the License. |
---|
| 13 | * |
---|
| 14 | * ALMOS-MKH is distributed in the hope that it will be useful, but |
---|
| 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
| 17 | * General Public License for more details. |
---|
| 18 | * |
---|
| 19 | * You should have received a copy of the GNU General Public License |
---|
| 20 | * along with ALMOS-MKH; if not, write to the Free Software Foundation, |
---|
| 21 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
| 22 | */ |
---|
| 23 | |
---|
| 24 | #ifndef _SHARED_PTHREAD_H_ |
---|
| 25 | #define _SHARED_PTHREAD_H_ |
---|
| 26 | |
---|
| 27 | /******************************************************************************************* |
---|
[566] | 28 | * This file defines the types and mnemonics that are shared by the kernel |
---|
| 29 | * and by the <pthread> user level library. |
---|
| 30 | ******************************************************************************************/ |
---|
| 31 | |
---|
| 32 | |
---|
| 33 | /******************************************************************************************* |
---|
[581] | 34 | * These typedef and enum define the shared information related to the POSIX thread. |
---|
[445] | 35 | ******************************************************************************************/ |
---|
| 36 | |
---|
[581] | 37 | typedef unsigned int pthread_t; |
---|
[566] | 38 | |
---|
[445] | 39 | typedef struct pthread_attr_s |
---|
| 40 | { |
---|
[581] | 41 | unsigned int attributes; /*! user defined attributes bit vector */ |
---|
| 42 | unsigned int cxy; /*! target cluster identifier */ |
---|
| 43 | unsigned int lid; /*! target core local index */ |
---|
[445] | 44 | } |
---|
| 45 | pthread_attr_t; |
---|
| 46 | |
---|
| 47 | enum |
---|
| 48 | { |
---|
[581] | 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 */ |
---|
[445] | 52 | }; |
---|
| 53 | |
---|
[581] | 54 | /******************************************************************************************* |
---|
| 55 | * These typedef and enum define the shared informations related to the POSIX mutex. |
---|
[445] | 56 | ******************************************************************************************/ |
---|
| 57 | |
---|
[581] | 58 | typedef unsigned int pthread_mutex_t; |
---|
| 59 | |
---|
| 60 | typedef unsigned int pthread_mutexattr_t; // TODO not implemented |
---|
| 61 | |
---|
[445] | 62 | typedef enum |
---|
| 63 | { |
---|
[581] | 64 | MUTEX_INIT, |
---|
| 65 | MUTEX_DESTROY, |
---|
| 66 | MUTEX_LOCK, |
---|
| 67 | MUTEX_UNLOCK, |
---|
| 68 | MUTEX_TRYLOCK, |
---|
| 69 | } |
---|
| 70 | mutex_operation_t; |
---|
| 71 | |
---|
| 72 | /******************************************************************************************* |
---|
| 73 | * These typedef and enum define the shared informations related to the POSIX condvar. |
---|
| 74 | ******************************************************************************************/ |
---|
| 75 | |
---|
| 76 | typedef unsigned int pthread_cond_t; |
---|
| 77 | |
---|
| 78 | typedef unsigned int pthread_condattr_t; // TODO not implemented |
---|
| 79 | |
---|
| 80 | typedef enum |
---|
| 81 | { |
---|
[445] | 82 | CONDVAR_INIT, |
---|
| 83 | CONDVAR_DESTROY, |
---|
| 84 | CONDVAR_WAIT, |
---|
| 85 | CONDVAR_SIGNAL, |
---|
| 86 | CONDVAR_BROADCAST, |
---|
| 87 | } |
---|
| 88 | condvar_operation_t; |
---|
| 89 | |
---|
[581] | 90 | /******************************************************************************************* |
---|
| 91 | * These typedef define and enum the shared informations related to the POSIX rwlock. |
---|
| 92 | ******************************************************************************************/ |
---|
| 93 | |
---|
| 94 | typedef unsigned int pthread_rwlock_t; // TODO not implemented |
---|
| 95 | |
---|
| 96 | typedef unsigned int pthread_rwlockattr_t; // TODO not implemented |
---|
| 97 | |
---|
[445] | 98 | /******************************************************************************************* |
---|
[581] | 99 | * These typedef and enum define the shared informations related to POSIX barriers. |
---|
[604] | 100 | * The following struct is NOT used in the current implementation or the POSIX barrier |
---|
| 101 | * that is based on a - non scalable - single shared variable. |
---|
| 102 | * It can be used by another implementation, based on a distributed quadtree implemented |
---|
| 103 | * in user space, and relying on a busy waiting policy. |
---|
[445] | 104 | ******************************************************************************************/ |
---|
| 105 | |
---|
[581] | 106 | typedef unsigned int pthread_barrier_t; |
---|
| 107 | |
---|
| 108 | typedef struct pthread_barrierattr_s |
---|
| 109 | { |
---|
| 110 | unsigned int x_size; /*! number of clusters in a row */ |
---|
| 111 | unsigned int y_size; /*! number of clusters in a column */ |
---|
| 112 | unsigned int nthreads; /*! number of expected threads in a cluster */ |
---|
| 113 | } |
---|
| 114 | pthread_barrierattr_t; |
---|
| 115 | |
---|
[445] | 116 | typedef enum |
---|
| 117 | { |
---|
| 118 | BARRIER_INIT, |
---|
| 119 | BARRIER_DESTROY, |
---|
| 120 | BARRIER_WAIT, |
---|
| 121 | } |
---|
| 122 | barrier_operation_t; |
---|
| 123 | |
---|
[581] | 124 | /********************************************************************************************* |
---|
| 125 | * These structures define another implementation for the POSIX barrier: |
---|
| 126 | * It is implemented as a hierarchical, physically distributed quad-tree, |
---|
| 127 | * covering all clusters specified, with the following constraints: |
---|
| 128 | * . The involved clusters form a mesh [x_size * y_size] |
---|
| 129 | * . The lower left involved cluster is cluster(0,0) |
---|
| 130 | * . The number of threads per cluster is the same in all clusters. |
---|
| 131 | * |
---|
| 132 | * Implementation note: |
---|
| 133 | * - The quad three is implemented as a three dimensions array of node[x][y][l] |
---|
| 134 | * . [x][y] are the cluster coordinates / max values are (QDT_XMAX-1), (QDT_YMAX-1) |
---|
| 135 | * . [l] is the node level / 0 for terminal nodes / (QDT_LMAX-1) for the root node |
---|
| 136 | ********************************************************************************************/ |
---|
[445] | 137 | |
---|
[581] | 138 | /* |
---|
| 139 | |
---|
| 140 | #define QDT_XMAX 16 // max number of clusters in a row |
---|
| 141 | #define QDT_YMAX 16 // max number of clusters in a column |
---|
| 142 | #define QDT_LMAX 5 // max depth of the quad tree |
---|
| 143 | #define QDT_YWIDTH 4 // Y field in cxy, for cxy <=> (x,y) translation |
---|
| 144 | #define QDT_YMASK 0xF // Y field in cxy, for cxy <=> (x,y) translation |
---|
| 145 | |
---|
| 146 | typedef struct sqt_node_s |
---|
[445] | 147 | { |
---|
[581] | 148 | volatile unsigned int sense; // barrier state (toggle) |
---|
| 149 | volatile unsigned int count; // number of not arrived tasks |
---|
| 150 | unsigned int arity; // number of locally expected tasks |
---|
| 151 | unsigned int level; // hierarchical level (0 is bottom) |
---|
| 152 | struct sqt_node_s * parent; // pointer on parent node (NULL for root) |
---|
| 153 | struct sqt_node_s * child[4]; // pointer on children node (NULL for bottom) |
---|
| 154 | } |
---|
| 155 | sqt_node_t; |
---|
[445] | 156 | |
---|
[581] | 157 | typedef struct pthread_barrier_s |
---|
| 158 | { |
---|
| 159 | sqt_node_t * node[QDT_XMAX][QDT_YMAX][QDT_LMAX]; |
---|
| 160 | } |
---|
| 161 | pthread_barrier_t; |
---|
[445] | 162 | |
---|
[581] | 163 | */ |
---|
[445] | 164 | |
---|
| 165 | #endif // _PTHREAD_H_ |
---|