source: doc/theses/colby_parsons_MMAth/benchmarks/mutex_stmt/cfa/baseline.cfa @ 26d40a1

Last change on this file since 26d40a1 was 0da7181, checked in by caparsons <caparson@…>, 20 months ago

added randomized lock ordering bench for mutexstmt

  • Property mode set to 100644
File size: 1.8 KB
Line 
1#include <locks.hfa>
2#include <mutex_stmt.hfa>
3#include <stdio.h>
4
5#include "../bench.h"
6
7test_spinlock LOCKS;
8
9inline void lock( test_spinlock &a, test_spinlock &b ) {
10    lock(a); lock(b);
11}
12inline void lock( test_spinlock &a, test_spinlock &b, test_spinlock &c, test_spinlock &d ) {
13    lock(a); lock(b); lock(c); lock(d);
14}
15inline void lock( test_spinlock &a, test_spinlock &b, test_spinlock &c, test_spinlock &d, test_spinlock &e, test_spinlock &f, test_spinlock &g, test_spinlock &h ) {
16    lock(a); lock(b); lock(c); lock(d); lock(e); lock(f); lock(g); lock(h);
17}
18inline void unlock( test_spinlock &a, test_spinlock &b ) {
19    unlock(a); unlock(b);
20}
21inline void unlock( test_spinlock &a, test_spinlock &b, test_spinlock &c, test_spinlock &d ) {
22    unlock(a); unlock(b); unlock(c); unlock(d);
23}
24inline void unlock( test_spinlock &a, test_spinlock &b, test_spinlock &c, test_spinlock &d, test_spinlock &e, test_spinlock &f, test_spinlock &g, test_spinlock &h ) {
25    unlock(a); unlock(b); unlock(c); unlock(d); unlock(e); unlock(f); unlock(g); unlock(h);
26}
27
28bool done = false;
29uint64_t total = 0;
30thread worker {};
31static inline void ?{}( worker & this, cluster & clu ) {
32    ((thread &)this){ clu };
33}
34void main( worker & w ) {
35    BENCH( lock( LOCKS ); unlock( LOCKS );, total, done )
36}
37
38int main( int argc, char * argv[] ) {
39        BENCH_START()
40    cluster clus;
41    processor * proc[threads];
42    for ( i; threads ) // create procs
43        (*(proc[i] = alloc())){clus};
44
45    worker * w[threads];
46    for ( i; threads ) // create threads
47        (*(w[i] = alloc())){ clus };
48   
49    sleep( 10`s );
50    done = true;
51
52    for ( i; threads ) // delete threads
53        delete(w[i]);
54
55    for ( i; threads ) // delete procs
56        delete(proc[i]);
57        printf( "%lu\n", total );
58}
59
60// Local Variables: //
61// tab-width: 4 //
62// End: //
Note: See TracBrowser for help on using the repository browser.