source: soft/giet_vm/giet_libs/user_barrier.h @ 580

Last change on this file since 580 was 501, checked in by alain, 10 years ago

Introduce user-level, distributed barriers and locks (quad-tree based).

File size: 3.7 KB
Line 
1//////////////////////////////////////////////////////////////////////////////////
2// File     : user_barrier.h         
3// Date     : 01/04/2012
4// Author   : alain greiner
5// Copyright (c) UPMC-LIP6
6///////////////////////////////////////////////////////////////////////////////////
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_sqt_barrier_t" can be used in multi-clusters architectures,
18//    and is implemented as a physically distributed Synchro-Quad-Tree (SQT).
19//    WARNING: The following placement constraints must be respected:
20//    - The number of involved tasks in a cluster is the same in all clusters.
21//    - The involved clusters form a mesh[x_size * y_size]
22//    - The lower left involved cluster is cluster(0,0) 
23//
24// Neither the barrier_init(), nor the barrier_wait() function require a syscall.
25// For both types of barriers, the barrier initialisation should be done by
26// one single task.
27///////////////////////////////////////////////////////////////////////////////////
28
29#ifndef USER_BARRIER_H_
30#define USER_BARRIER_H_
31
32///////////////////////////////////////////////////////////////////////////////////
33//  simple barrier structure and access functions
34///////////////////////////////////////////////////////////////////////////////////
35
36typedef struct giet_barrier_s
37{
38    unsigned int sense;      // barrier state (toggle)
39    unsigned int arity;      // total number of expected tasks
40    unsigned int count;      // number of not arrived tasks
41} giet_barrier_t;
42
43///////////////////////////////////////////////////
44extern void barrier_init( giet_barrier_t* barrier,
45                          unsigned int    ntasks );   
46
47////////////////////////////////////////////////////
48extern void barrier_wait( giet_barrier_t* barrier );
49
50//////////////////////////////////////////////////////////////////////////////////
51// SQT barrier structures and access functions
52//////////////////////////////////////////////////////////////////////////////////
53
54typedef struct sqt_node_s
55{
56    unsigned int       arity;        // number of expected tasks
57    unsigned int       count;        // number of not arrived tasks
58    unsigned int       sense;        // barrier state (toggle)
59    unsigned int       level;        // hierarchical level (0 is bottom)
60    struct sqt_node_s* parent;       // pointer on parent node (NULL for root)
61    struct sqt_node_s* child[4];     // pointer on children node (NULL for bottom)
62    unsigned int       padding[7];   // for 64 bytes alignment
63} sqt_node_t;
64
65typedef struct giet_sqt_barrier_s
66{
67    sqt_node_t*     node[16][16][5];    // array of pointers on SBT nodes
68} giet_sqt_barrier_t;
69
70///////////////////////////////////////////////////////////
71extern void sqt_barrier_init( giet_sqt_barrier_t*  barrier,
72                              unsigned int         x_size,
73                              unsigned int         y_size,
74                              unsigned int         ntasks );   
75
76/////////////////////////////////////////////////////////////
77extern void sqt_barrier_wait( giet_sqt_barrier_t*  barrier );
78
79
80#endif
81
82// Local Variables:
83// tab-width: 4
84// c-basic-offset: 4
85// c-file-offsets:((innamespace . 0)(inline-open . 0))
86// indent-tabs-mode: nil
87// End:
88// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
89
Note: See TracBrowser for help on using the repository browser.