-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2LClock_p.cpp
151 lines (123 loc) · 4 KB
/
2LClock_p.cpp
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
#include"clock_sync.h"
#include<stdio.h>
#include<pthread.h>
#define thread_count 2
#define test_times 50000
int number[10];
long long int ts_array[thread_count][test_times];
long long int cpu_ts_array[thread_count][test_times];
long long int get_ts_duration[thread_count][test_times];
bool flag;
int ready[thread_count];
bool next[2];
int file_id;
int call_duration[2][test_times];
void* test(void* argv){
int id = *((int*)argv); // we let two child reside in one node
int idp = id+1;
printf("Gonna bind on core %d\n", idp);
GlobalTimer gt;
gt.init(12450+233*(idp), (idp));
gt.run();
while(!gt.is_warmup_done()) sched_yield();
printf("Warm up done in node %d.\n", idp);
ready[id] = true;
long long int ts = 0, ts2 = 0, ts3 = 0;
for(int i=0; i<test_times; i++){
while(flag==false)
sched_yield();
// ts_t start = get_real_clock();
ts3 = get_real_clock();
ts = gt.get_timestamp();
ts2 = get_real_clock();
// ts_t end = get_real_clock();
get_ts_duration[id][i] = ts2 - ts3;
ts_array[id][i] = ts;
cpu_ts_array[id][i] = ts2;
// call_duration[id][i] = (int)(end-start);
next[id] = true;
while(flag==true)
sched_yield();
}
printf("Gonna finalize.\n");
gt.set_done();
printf("Set done finish in %d\n", idp);
gt.finalize();
printf("test finish\n");
printf("Thread %d quits\n", idp);
return NULL;
}
int main(int argc, char** argv){
// arg2: file id. arg3: load/no-load
assert(argc==3);
file_id = atoi(argv[1]);
for(int i=0; i<thread_count; i++){
number[i] = i;
ready[i] = false;
}
flag = false;
next[0] = false;
next[1] = false;
pthread_t thread_array[thread_count];
printf("start test.\n");
// test TS bandwidth and latency
for(int i=0; i<thread_count; i++)
pthread_create(thread_array+i, NULL, test, number+i);
retry:
for(int i=0; i<thread_count; i++)
if(!ready[i]){
sched_yield();
goto retry;
}
sleep(2);
printf("Gonna test accuracy\n");
for(int i=0; i<test_times; i++){
flag = true;
re:
for(int j=0; j<thread_count; j++)
if(!next[j])
goto re;
flag = false;
for(int k=0; k<thread_count; k++)
next[k] = false;
usleep(1000);
if(i%10000==0)
printf("%d finish\n", i);
}
printf("ts test finish\n");
for(int i=0; i<thread_count; i++)
pthread_join(thread_array[i], NULL);
ts_t error_array[test_times];
for(int i=0; i<test_times; i++){
// ts_array[0][i] -= ts_array[1][i];
error_array[i] = std::abs<ts_t>(ts_array[0][i] - ts_array[1][i] - (cpu_ts_array[0][i] - cpu_ts_array[1][i]));
// error_array[i] = ts_array[0][i] - ts_array[1][i];
}
char output_file[128];
sprintf(output_file, "./data/2LClock_%d_%s.txt", file_id, argv[2]);
std::fstream ofs;
if(file_id!=-1)
ofs.open(output_file, std::ios::out);
ts_t error = 0;
ts_t duration = 0;
for(int i=0; i<test_times; i++){
// printf("%lld ns\n", ts_array[0][i]);
error += error_array[i];
duration += (get_ts_duration[0][i]+get_ts_duration[1][i]);
if(file_id!=-1)
ofs<<error_array[i]<<" "<<cpu_ts_array[0][i]<<" "<<cpu_ts_array[1][i]<<std::endl;
}
error /= test_times;
duration /= (2*test_times);
printf("[RESULT]:\navg: %lld, ", error);
if(file_id!=-1)
ofs.close();
std::sort(error_array, error_array+test_times);
ts_t mid_error = error_array[test_times/2];
ts_t p90_error = error_array[(int)(test_times*0.90)];
ts_t p95_error = error_array[(int)(test_times*0.95)];
ts_t p99_error = error_array[(int)(test_times*0.99)];
ts_t max_error = error_array[test_times-1];
printf("mid: %lld, p90: %lld, p95: %lld, p99: %lld, max: %lld\n", mid_error, p90_error, p95_error, p99_error, max_error);
return 0;
}