[258] | 1 | ////////////////////////////////////////////////////////////////////////////////// |
---|
| 2 | // File : barrier.h |
---|
| 3 | // Date : 01/04/2012 |
---|
| 4 | // Author : alain greiner |
---|
| 5 | // Copyright (c) UPMC-LIP6 |
---|
| 6 | /////////////////////////////////////////////////////////////////////////////////// |
---|
[368] | 7 | // The barrier.c and barrier.h files are part of the GIET-VM nano-kernel. |
---|
| 8 | // This user-level library provides a synchronisation service between several |
---|
| 9 | // tasks sharing the same address space in a parallel multi-tasks application. |
---|
| 10 | // |
---|
| 11 | // There is actually two types of barriers: |
---|
| 12 | // 1) The "giet_barrier_t" is a simple sense-reversing barrier. |
---|
| 13 | // It can be safely used several times (in a loop for example), |
---|
| 14 | // but it does not scale, and should not be used when the number |
---|
| 15 | // of tasks is larger than few tens. |
---|
| 16 | // |
---|
| 17 | // 2) The giet_sbt_barrier_t" can be used in multi-clusters architectures, |
---|
| 18 | // and is implemented as a physically distributed Sliced-Binary-Tree (SBT). |
---|
| 19 | // WARNING: The following placement constraints must be respected: |
---|
| 20 | // - The number of tasks must be a power of 2. |
---|
| 21 | // - There is one task per processor in a given cluster. |
---|
| 22 | // - The involved clusters form a mesh[N][N] or a mesh[N][N/2] |
---|
| 23 | // - The lower left involved cluster is cluster(0,0) |
---|
| 24 | // |
---|
| 25 | // Neither the barrier_init(), nor the barrier_wait() function require a syscall. |
---|
| 26 | // For both types of barriers, the barrier initialisation should be done by |
---|
| 27 | // one single task. |
---|
| 28 | /////////////////////////////////////////////////////////////////////////////////// |
---|
[258] | 29 | |
---|
| 30 | #ifndef _BARRIER_H_ |
---|
| 31 | #define _BARRIER_H_ |
---|
| 32 | |
---|
[368] | 33 | #include "hard_config.h" |
---|
| 34 | |
---|
[258] | 35 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 36 | /////////////////////////////////////////////////////////////////////////////////// |
---|
[368] | 37 | // simple barrier structure and access functions |
---|
| 38 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 39 | /////////////////////////////////////////////////////////////////////////////////// |
---|
[258] | 40 | |
---|
[295] | 41 | typedef struct giet_barrier_s |
---|
| 42 | { |
---|
[368] | 43 | char name[32]; // barrier name |
---|
| 44 | unsigned int sense; // barrier state (toggle) |
---|
| 45 | unsigned int ntasks; // total number of expected tasks |
---|
| 46 | unsigned int count; // number of not arrived tasks |
---|
[258] | 47 | } giet_barrier_t; |
---|
| 48 | |
---|
[368] | 49 | /////////////////////////////////////////////////// |
---|
| 50 | extern void barrier_init( giet_barrier_t* barrier, |
---|
| 51 | unsigned int ntasks ); |
---|
[258] | 52 | |
---|
[368] | 53 | //////////////////////////////////////////////////// |
---|
| 54 | extern void barrier_wait( giet_barrier_t* barrier ); |
---|
[258] | 55 | |
---|
[368] | 56 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 57 | ////////////////////////////////////////////////////////////////////////////////// |
---|
| 58 | // SBT barrier structures and access functions |
---|
| 59 | ////////////////////////////////////////////////////////////////////////////////// |
---|
| 60 | ////////////////////////////////////////////////////////////////////////////////// |
---|
[295] | 61 | |
---|
[368] | 62 | typedef struct sbt_node_s |
---|
| 63 | { |
---|
| 64 | unsigned int arity; // number of children (must be 2 or 4) |
---|
| 65 | unsigned int count; // number of not arrived children |
---|
| 66 | unsigned int sense; // barrier state (toggle) |
---|
| 67 | unsigned int level; // hierarchical level (0 is bottom) |
---|
| 68 | struct sbt_node_s* parent; // pointer on parent node (NULL for root) |
---|
| 69 | struct sbt_node_s* child0; // pointer on children node |
---|
| 70 | struct sbt_node_s* child1; // pointer on children node |
---|
[468] | 71 | unsigned int padding; // for 32 bytes alignment |
---|
[368] | 72 | } sbt_node_t; |
---|
| 73 | |
---|
| 74 | typedef struct giet_sbt_barrier_s |
---|
| 75 | { |
---|
| 76 | char name[32]; // barrier name |
---|
| 77 | unsigned int ntasks; // total number of expected tasks |
---|
| 78 | sbt_node_t* node[X_SIZE][Y_SIZE][9]; // array of pointers on SBT nodes |
---|
| 79 | } giet_sbt_barrier_t; |
---|
| 80 | |
---|
| 81 | /////////////////////////////////////////////////////////// |
---|
| 82 | extern void sbt_barrier_init( giet_sbt_barrier_t* barrier, |
---|
| 83 | unsigned int ntasks ); |
---|
| 84 | |
---|
| 85 | ///////////////////////////////////////////////////////////// |
---|
| 86 | extern void sbt_barrier_wait( giet_sbt_barrier_t* barrier ); |
---|
| 87 | |
---|
| 88 | ///////////////////////////////////////////// |
---|
| 89 | void sbt_build( giet_sbt_barrier_t* barrier, |
---|
| 90 | unsigned int x, |
---|
| 91 | unsigned int y, |
---|
| 92 | unsigned int level, |
---|
| 93 | sbt_node_t* parent ); |
---|
| 94 | |
---|
| 95 | /////////////////////////////////////// |
---|
| 96 | void sbt_decrement( sbt_node_t* node ); |
---|
| 97 | |
---|
| 98 | /////////////////////////////////// |
---|
| 99 | void sbt_release( sbt_node_t* node, |
---|
| 100 | unsigned int expected ); |
---|
| 101 | |
---|
| 102 | |
---|
| 103 | |
---|
[258] | 104 | #endif |
---|
| 105 | |
---|
| 106 | // Local Variables: |
---|
| 107 | // tab-width: 4 |
---|
| 108 | // c-basic-offset: 4 |
---|
| 109 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
| 110 | // indent-tabs-mode: nil |
---|
| 111 | // End: |
---|
| 112 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
| 113 | |
---|