-
Notifications
You must be signed in to change notification settings - Fork 1
/
bop_api.h
189 lines (149 loc) · 4.91 KB
/
bop_api.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/* Behavior-oriented parallelization. See Ding et al. PLDI 2007 and Ke
et al. OOPSLA 2011. A complete re-write on June 29, 2012.
*/
#ifndef _BOP_API_H_
#define _BOP_API_H_
#ifndef NDEBUG
/* We want the task status while debugging->bop_msg **/
#define bop_debug(x, ...) bop_msg(1, "%s:%d " x "" , __FILE__, __LINE__, ##__VA_ARGS__);
#else
#define bop_debug(...)
#endif
void error_alert_monitor(void);
#if defined(BOP)
#include <stdarg.h> /* for bop_msg */
#include <assert.h> /* for assert */
#include <stdio.h> /* for IO */
#include <stdint.h>
typedef uintptr_t addr_t;
#define TRUE 1
#define FALSE 0
typedef enum {
SEQ = -2, // sequential mode, ready to change at next PPR
UNDY = 0, // the understudy
MAIN, // first PPR task after SEQ mode
SPEC // a speculation process
} task_status_t;
typedef enum {
PPR = 0,
GAP,
PSEQ
} ppr_pos_t;
typedef enum {
SERIAL = 0,
PARALLEL
} bop_mode_t;
task_status_t BOP_task_status(void);
ppr_pos_t BOP_ppr_pos(void);
bop_mode_t BOP_mode(void);
int BOP_spec_order(void);
int BOP_ppr_index(void);
/* system wide data structure for a memory range */
typedef struct _mem_range_t {
addr_t base;
size_t size;
void *rec; /* optional data record */
unsigned task; /* optional ppr_index used by post-wait */
} mem_range_t;
// %------------------ Function Prototype -------------- %
/* the TOLABEL macro by Grant Farmer */
#define TOL(x) L##x
#define TOLABEL(x) TOL(x)
#define TOS(x) #x
#define TOSTRING(x) TOS(x)
extern int _BOP_ppr_begin(int);
extern void _BOP_ppr_end(int);
#define BOP_ppr_begin(id) if (_BOP_ppr_begin(id)==1) goto TOLABEL(id)
#define BOP_ppr_end(id) _BOP_ppr_end(id); TOLABEL(id):
extern void _BOP_group_over(int);
#define BOP_group_over(id) _BOP_group_over(id)
void BOP_ordered_begin( addr_t );
void BOP_ordered_end( addr_t );
void BOP_ordered_skip( addr_t );
int BOP_get_group_size(void);
int BOP_get_verbose(void);
void BOP_set_group_size(int sz);
void BOP_set_verbose(int x);
/* Byte granularity interface */
void BOP_record_read(void* addr, size_t size);
void BOP_record_write(void* addr, size_t size);
#define BOP_use( x, y ) BOP_record_read( x, y )
#define BOP_promise( x, y ) BOP_record_write( x, y )
typedef void monitor_t (void *, size_t);
/* Called by a speculation process in case of error. */
void BOP_abort_spec( const char* msg, ...) __attribute__ ((format (printf, 1, 2)));
void BOP_abort_next_spec( char* msg );
/* FILE I/O */
int BOP_printf(const char *format, ...);
int BOP_fprintf(FILE *stream, const char *format, ...);
/* Check if addr has been read/written. Return the memory range;
otherwise NULL*/
mem_range_t *BOP_check_read(void* addr);
mem_range_t *BOP_check_write(void* addr);
mem_range_t *BOP_check_access(void* addr);
// %--------------- For Debug ------------- %
void bop_set_verbose( int );
int bop_get_verbose( void );
void bop_msg(int level, const char * msg, ...);
#define bop_assert(x) if(!(x)) {bop_msg(0, ("Assertion: %s failed, %s:%d %s"), #x, __FILE__, __LINE__, __func__); abort();}
/* For collecting statistics */
typedef struct {
double start_time;
int num_by_spec;
int num_by_main;
int num_by_undy;
int data_copied;
int data_posted;
} stats_t;
extern stats_t bop_stats;
/* For BOP_malloc */
void *_BOP_malloc(size_t sz, char *file, unsigned line);
void *_BOP_calloc(size_t n_elements, size_t elem_size, char *file, unsigned line);
void _BOP_free(void* mem, char *file, unsigned line);
void *_BOP_realloc(void* mem, size_t newsize, char *file, unsigned line);
#define BOP_malloc( sz ) malloc( sz )
#define BOP_alloc( n, s ) calloc( n, s )
#define BOP_free( m ) free ( m )
#define BOP_realloc( m, nsz ) realloc( m, nsz )
// Original Code
/*
#define BOP_malloc( sz ) _BOP_malloc( sz, __FILE__, __LINE__ )
#define BOP_calloc( n, s ) _BOP_calloc( n, s, __FILE__, __LINE__ )
#define BOP_free( m ) _BOP_free( m, __FILE__, __LINE__ )
#define BOP_realloc( m, nsz ) _BOP_realloc( m, nsz, __FILE__, __LINE__ )
*/
/* should be disabled if defining BOP_printf printf
#define printf BOP_printf
#define fprintf BOP_fprintf
#define scanf BOP_abort_spec_group(); scanf
#define fscanf BOP_abort_spec_group(); fscanf
*/
//#define BOP_malloc(s) malloc(s)
//#define BOP_free(s) free(s)
//#define BOP_realloc(p, s) realloc(p, s)
//#define BOP_calloc(c, s) calloc(c, s)
#define PAGESIZEX 12
size_t max_ppr_request;
#else
/* original code */
#define BOP_set_verbose( x )
#define BOP_set_group_size( x )
#define BOP_spec_order( ) 0
#define BOP_ppr_index( ) 0
#define BOP_ppr_begin(id)
#define BOP_ppr_end(id)
#define BOP_ordered_begin(id)
#define BOP_ordered_end(id)
#define BOP_group_over(id)
#define BOP_record_read( addr, size )
#define BOP_record_write( addr, size )
#define BOP_use( addr, size )
#define BOP_promise( addr, size )
#define bop_msg(ignored, ...) printf( __VA_ARGS__ )
#define BOP_abort_spec( msg, ... )
#define BOP_abort_next_spec( msg )
#define BOP_abort_spec_group( msg )
#define bop_assert(x) assert(x)
#include <stdlib.h>
#endif
#endif