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

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 c3d048c3 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
RevLine 
[cf97ccb]1#include <fstream>
[bd951f7]2#include <monitor>
[cf97ccb]3#include <stdlib>
[29f44a74]4#include <thread>
[cf97ccb]5
[8cb6fcd]6#include "bench.h"
[cf97ccb]7
[b510ac2]8coroutine GreatSuspender {};
[cf97ccb]9
[bd37119]10void ?{}( GreatSuspender & this ) {
[cf97ccb]11 prime(this);
12}
13
[bd37119]14void main( GreatSuspender & this )
[cf97ccb]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 ) {
[bd37119]23 resume( *this );
[cf97ccb]24 }
25}
26
[bd951f7]27//-----------------------------------------------------------------------------
28// coroutine context switch
[cf97ccb]29long long int measure_coroutine() {
[a5b7905]30 const unsigned int NoOfTimes = 50000000;
[cf97ccb]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
[bd951f7]42//-----------------------------------------------------------------------------
43// thread context switch
[cf97ccb]44long long int measure_thread() {
[a5b7905]45 const unsigned int NoOfTimes = 50000000;
[cf97ccb]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
[bd951f7]57//-----------------------------------------------------------------------------
58// single monitor entry
59monitor mon_t {};
[bd37119]60void dummy( mon_t & mutex m ) {}
[bd951f7]61
62long long int measure_1_monitor_entry() {
[a5b7905]63 const unsigned int NoOfTimes = 5000000;
[bd951f7]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 ) {
[bd37119]69 dummy( mon );
[bd951f7]70 }
71 EndTime = Time();
72
73 return ( EndTime - StartTime ) / NoOfTimes;
74}
75
76//-----------------------------------------------------------------------------
77// multi monitor entry
[bd37119]78void dummy( mon_t & mutex m1, mon_t & mutex m2 ) {}
[bd951f7]79
80long long int measure_2_monitor_entry() {
[a5b7905]81 const unsigned int NoOfTimes = 5000000;
[bd951f7]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 ) {
[bd37119]87 dummy( mon1, mon2 );
[bd951f7]88 }
89 EndTime = Time();
90
91 return ( EndTime - StartTime ) / NoOfTimes;
92}
93
[43426d4]94//-----------------------------------------------------------------------------
95// single internal sched entry
[a5b7905]96const unsigned int NoOfTimes = 500000;
97
[43426d4]98mon_t mon1;
99
[7286a40]100condition cond1a;
[43426d4]101condition cond1b;
102
103thread thrd1a { long long int * out; };
104thread thrd1b {};
105
[bd37119]106void ?{}( thrd1a & this, long long int * out ) {
107 this.out = out;
[43426d4]108}
109
[bd37119]110void side1A( mon_t & mutex a, long long int * out ) {
[a5b7905]111 const unsigned int NoOfTimes = 500000;
[43426d4]112 long long int StartTime, EndTime;
113
114 StartTime = Time();
115 for( int i = 0;; i++ ) {
[4cedd9f]116 signal(cond1a);
[a5b7905]117 if( i > NoOfTimes ) break;
[4cedd9f]118 wait(cond1b);
[43426d4]119 }
120 EndTime = Time();
121
[a5b7905]122 *out = ( EndTime - StartTime ) / NoOfTimes;
[43426d4]123}
124
[bd37119]125void side1B( mon_t & mutex a ) {
[43426d4]126 for( int i = 0;; i++ ) {
[4cedd9f]127 signal(cond1b);
[43426d4]128 if( i > N ) break;
[4cedd9f]129 wait(cond1a);
[43426d4]130 }
131}
132
[bd37119]133void main( thrd1a & this ) { side1A( mon1, this.out ); }
134void main( thrd1b & this ) { side1B( mon1 ); }
[43426d4]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//-----------------------------------------------------------------------------
[a5b7905]146// multi internal sched
[43426d4]147mon_t mon2;
148
[7286a40]149condition cond2a;
[43426d4]150condition cond2b;
151
152thread thrd2a { long long int * out; };
153thread thrd2b {};
154
[bd37119]155void ?{}( thrd2a & this, long long int * out ) {
156 this.out = out;
[43426d4]157}
158
[bd37119]159void side2A( mon_t & mutex a, mon_t & mutex b, long long int * out ) {
[a5b7905]160 const unsigned int NoOfTimes = 500000;
[43426d4]161 long long int StartTime, EndTime;
162
163 StartTime = Time();
164 for( int i = 0;; i++ ) {
[4cedd9f]165 signal(cond2a);
[a5b7905]166 if( i > NoOfTimes ) break;
[4cedd9f]167 wait(cond2b);
[43426d4]168 }
169 EndTime = Time();
170
[a5b7905]171 *out = ( EndTime - StartTime ) / NoOfTimes;
[43426d4]172}
173
[bd37119]174void side2B( mon_t & mutex a, mon_t & mutex b ) {
[43426d4]175 for( int i = 0;; i++ ) {
[4cedd9f]176 signal(cond2b);
[43426d4]177 if( i > N ) break;
[4cedd9f]178 wait(cond2a);
[43426d4]179 }
180}
181
[bd37119]182void main( thrd2a & this ) { side2A( mon1, mon2, this.out ); }
183void main( thrd2b & this ) { side2B( mon1, mon2 ); }
[43426d4]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
[a5b7905]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
[43426d4]264//-----------------------------------------------------------------------------
265// main loop
[cf97ccb]266int main()
267{
[a5b7905]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;
[cf97ccb]276}
Note: See TracBrowser for help on using the repository browser.