-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.c
More file actions
143 lines (122 loc) · 3.01 KB
/
Copy pathutils.c
File metadata and controls
143 lines (122 loc) · 3.01 KB
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
#include <assert.h>
#include <errno.h>
#include <stdarg.h> /* for bop_msg */
#include <stdlib.h> /* getenv */
#include <sys/time.h>
#include <unistd.h>
#include <semaphore.h>
#include <fcntl.h>
#include "bop_api.h"
#include "utils.h"
extern task_status_t task_status;
extern ppr_pos_t ppr_pos;
extern int ppr_index;
extern int spec_order;
extern bop_mode_t bop_mode;
task_status_t BOP_task_status(void) {
return task_status;
}
ppr_pos_t BOP_ppr_pos( void ) {
return ppr_pos;
}
int BOP_ppr_index( void ) {
if ( ppr_pos == GAP ) return ppr_index + 1;
else return ppr_index;
}
int BOP_spec_order( void ) {
return spec_order;
}
bop_mode_t BOP_mode( void ) {
return bop_mode;
}
unsigned long long read_tsc(void) {
unsigned long long tsc;
asm ("rdtsc":"=A" (tsc):);
return tsc;
}
int bop_verbose = 0;
void BOP_set_verbose(int x) {
assert( x < 6 && x > 0 );
bop_verbose = x;
}
int BOP_get_verbose( void ) {
return bop_verbose;
}
extern char in_ordered_region; // bop_ordered.c
extern int errno;
char *strerror(int errnum);
void bop_msg(int level, const char * msg, ...) {
if(bop_verbose >= level)
{
//msg_init();
va_list v;
va_start(v,msg);
fprintf(stderr, "%d-", getpid());
char *pos;
switch (ppr_pos) {
case PPR:
pos = "";
break;
case GAP:
pos = "g";
break;
default:
assert(0);
}
if (in_ordered_region) {
assert( ppr_pos == PPR );
pos = "od";
}
unsigned pidx = BOP_ppr_index( );
switch(task_status) {
case UNDY: fprintf(stderr, "Undy-(idx %d%s): ", pidx, pos); break;
case MAIN: fprintf(stderr, "Main-%d(idx %d%s): ", spec_order, pidx, pos); break;
case SEQ: fprintf(stderr, "Seq-(idx %d%s): ", pidx, pos); break;
case SPEC: fprintf(stderr, "Spec-%d(idx %d%s): ", spec_order, pidx, pos); break;
}
struct timeval tv;
gettimeofday(&tv, NULL);
double curr_time = tv.tv_sec + (tv.tv_usec/1000000.0);
if (bop_stats.start_time != 0)
fprintf(stderr, " (%.6lfs) ", curr_time - bop_stats.start_time);
vfprintf(stderr,msg,v);
fprintf(stderr,"\n");
fflush(stderr);
}
}
void msg_init(){
}
void msg_destroy(){
}
/* read the environment variable env, and returns it's integer value.
if the value is undefined, the default value def is returned.
the value is restricted to the range [min,max] */
int get_int_from_env(const char* env, int min, int max, int def)
{
char* cval;
assert( min < max );
cval = getenv( env );
if (cval == NULL) {
bop_msg( 2, "Variable %s is set to default (%d).", env, def);
return def;
}
int ival = atoi( cval );
if ( ival < min ) ival = min;
if ( ival > max ) ival = max;
bop_msg( 2, "Variable %s is set as %d based on env ([%d, %d]).", env, ival, min, max);
return ival;
}
char * BOP_task_str(){
switch(task_status){
case MAIN:
return "Main speculation";
case SPEC:
return "Speculation";
case UNDY:
return "Understudy";
case SEQ:
return "Sequential";
default:
return "Unkown!";
}
}