source: src/benchmark/csv-data.c@ a5b7905

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new with_gc
Last change on this file since a5b7905 was a5b7905, checked in by Thierry Delisle <tdelisle@…>, 8 years ago

Jenkins now uses the sqlite database

  • Property mode set to 100644
File size: 6.0 KB
Line 
1#include <fstream>
2#include <monitor>
3#include <stdlib>
4#include <thread>
5
6#include "bench.h"
7
8coroutine GreatSuspender {};
9
10void ?{}( GreatSuspender & this ) {
11 prime(this);
12}
13
14void main( GreatSuspender & this )
15{
16 while( true ) {
17 suspend();
18 }
19}
20
21void resumer( GreatSuspender * this, const unsigned int NoOfTimes ) {
22 for ( volatile unsigned int i = 0; i < NoOfTimes; i += 1 ) {
23 resume( *this );
24 }
25}
26
27//-----------------------------------------------------------------------------
28// coroutine context switch
29long long int measure_coroutine() {
30 const unsigned int NoOfTimes = 50000000;
31 long long int StartTime, EndTime;
32
33 GreatSuspender s;
34
35 StartTime = Time();
36 resumer( &s, NoOfTimes );
37 EndTime = Time();
38
39 return ( EndTime - StartTime ) / NoOfTimes;
40}
41
42//-----------------------------------------------------------------------------
43// thread context switch
44long long int measure_thread() {
45 const unsigned int NoOfTimes = 50000000;
46 long long int StartTime, EndTime;
47
48 StartTime = Time();
49 for ( volatile unsigned int i = 0; i < NoOfTimes; i += 1 ) {
50 yield();
51 }
52 EndTime = Time();
53
54 return ( EndTime - StartTime ) / NoOfTimes;
55}
56
57//-----------------------------------------------------------------------------
58// single monitor entry
59monitor mon_t {};
60void dummy( mon_t & mutex m ) {}
61
62long long int measure_1_monitor_entry() {
63 const unsigned int NoOfTimes = 5000000;
64 long long int StartTime, EndTime;
65 mon_t mon;
66
67 StartTime = Time();
68 for ( volatile unsigned int i = 0; i < NoOfTimes; i += 1 ) {
69 dummy( mon );
70 }
71 EndTime = Time();
72
73 return ( EndTime - StartTime ) / NoOfTimes;
74}
75
76//-----------------------------------------------------------------------------
77// multi monitor entry
78void dummy( mon_t & mutex m1, mon_t & mutex m2 ) {}
79
80long long int measure_2_monitor_entry() {
81 const unsigned int NoOfTimes = 5000000;
82 long long int StartTime, EndTime;
83 mon_t mon1, mon2;
84
85 StartTime = Time();
86 for ( volatile unsigned int i = 0; i < NoOfTimes; i += 1 ) {
87 dummy( mon1, mon2 );
88 }
89 EndTime = Time();
90
91 return ( EndTime - StartTime ) / NoOfTimes;
92}
93
94//-----------------------------------------------------------------------------
95// single internal sched entry
96const unsigned int NoOfTimes = 500000;
97
98mon_t mon1;
99
100condition cond1a;
101condition cond1b;
102
103thread thrd1a { long long int * out; };
104thread thrd1b {};
105
106void ?{}( thrd1a & this, long long int * out ) {
107 this.out = out;
108}
109
110void side1A( mon_t & mutex a, long long int * out ) {
111 const unsigned int NoOfTimes = 500000;
112 long long int StartTime, EndTime;
113
114 StartTime = Time();
115 for( int i = 0;; i++ ) {
116 signal(cond1a);
117 if( i > NoOfTimes ) break;
118 wait(cond1b);
119 }
120 EndTime = Time();
121
122 *out = ( EndTime - StartTime ) / NoOfTimes;
123}
124
125void side1B( mon_t & mutex a ) {
126 for( int i = 0;; i++ ) {
127 signal(cond1b);
128 if( i > N ) break;
129 wait(cond1a);
130 }
131}
132
133void main( thrd1a & this ) { side1A( mon1, this.out ); }
134void main( thrd1b & this ) { side1B( mon1 ); }
135
136long long int measure_1_sched_int() {
137 long long int t;
138 {
139 thrd1a a = { &t };
140 thrd1b b;
141 }
142 return t;
143}
144
145//-----------------------------------------------------------------------------
146// multi internal sched
147mon_t mon2;
148
149condition cond2a;
150condition cond2b;
151
152thread thrd2a { long long int * out; };
153thread thrd2b {};
154
155void ?{}( thrd2a & this, long long int * out ) {
156 this.out = out;
157}
158
159void side2A( mon_t & mutex a, mon_t & mutex b, long long int * out ) {
160 const unsigned int NoOfTimes = 500000;
161 long long int StartTime, EndTime;
162
163 StartTime = Time();
164 for( int i = 0;; i++ ) {
165 signal(cond2a);
166 if( i > NoOfTimes ) break;
167 wait(cond2b);
168 }
169 EndTime = Time();
170
171 *out = ( EndTime - StartTime ) / NoOfTimes;
172}
173
174void side2B( mon_t & mutex a, mon_t & mutex b ) {
175 for( int i = 0;; i++ ) {
176 signal(cond2b);
177 if( i > N ) break;
178 wait(cond2a);
179 }
180}
181
182void main( thrd2a & this ) { side2A( mon1, mon2, this.out ); }
183void main( thrd2b & this ) { side2B( mon1, mon2 ); }
184
185long long int measure_2_sched_int() {
186 long long int t;
187 {
188 thrd2a a = { &t };
189 thrd2b b;
190 }
191 return t;
192}
193
194//-----------------------------------------------------------------------------
195// single external sched
196
197volatile int go = 0;
198
199void __attribute__((noinline)) call( mon_t & mutex m1 ) {}
200
201long long int __attribute__((noinline)) wait( mon_t & mutex m1 ) {
202 go = 1;
203 const unsigned int NoOfTimes = 5000000;
204 long long int StartTime, EndTime;
205
206 StartTime = Time();
207 for (size_t i = 0; i < NoOfTimes; i++) {
208 waitfor(call, m1);
209 }
210
211 EndTime = Time();
212 go = 0;
213 return ( EndTime - StartTime ) / NoOfTimes;
214}
215
216thread thrd3 {};
217void ^?{}( thrd3 & mutex this ) {}
218void main( thrd3 & this ) {
219 while(go == 0) { yield(); }
220 while(go == 1) { call(mon1); }
221
222}
223
224long long int measure_1_sched_ext() {
225 go = 0;
226 thrd3 t;
227 return wait(mon1);
228}
229
230//-----------------------------------------------------------------------------
231// multi external sched
232
233void __attribute__((noinline)) call( mon_t & mutex m1, mon_t & mutex m2 ) {}
234
235long long int __attribute__((noinline)) wait( mon_t & mutex m1, mon_t & mutex m2 ) {
236 go = 1;
237 const unsigned int NoOfTimes = 5000000;
238 long long int StartTime, EndTime;
239
240 StartTime = Time();
241 for (size_t i = 0; i < NoOfTimes; i++) {
242 waitfor(call, m1, m2);
243 }
244
245 EndTime = Time();
246 go = 0;
247 return ( EndTime - StartTime ) / NoOfTimes;
248}
249
250thread thrd4 {};
251void ^?{}( thrd4 & mutex this ) {}
252void main( thrd4 & this ) {
253 while(go == 0) { yield(); }
254 while(go == 1) { call(mon1, mon2); }
255
256}
257
258long long int measure_2_sched_ext() {
259 go = 0;
260 thrd3 t;
261 return wait(mon1, mon2);
262}
263
264//-----------------------------------------------------------------------------
265// main loop
266int main()
267{
268 sout | "\tepoch:" | time(NULL) | ',' | endl;
269 sout | "\tctxswitch: {" | endl;
270 sout | "\t\tcoroutine: "| measure_coroutine() | ',' | endl;
271 sout | "\t\tthread:" | measure_thread() | ',' | endl;
272 sout | "\t}," | endl;
273 sout | "\tmutex: [" | measure_1_monitor_entry() | ',' | measure_2_monitor_entry() | "]," | endl;
274 sout | "\tscheduling: ["| measure_1_sched_int() | ',' | measure_2_sched_int() | ',' |
275 measure_1_sched_ext() | ',' | measure_2_sched_ext() | "]," | endl;
276}
Note: See TracBrowser for help on using the repository browser.