[3df86cc] | 1 | #include "rq_bench.hfa" |
---|
| 2 | |
---|
[111a2ab3] | 3 | #include <locks.hfa> |
---|
| 4 | |
---|
[3df86cc] | 5 | unsigned spot_cnt = 2; |
---|
[111a2ab3] | 6 | semaphore * spots; |
---|
[3df86cc] | 7 | |
---|
| 8 | thread BThrd { |
---|
| 9 | unsigned long long count; |
---|
| 10 | unsigned long long blocks; |
---|
[111a2ab3] | 11 | bool skip; |
---|
[3df86cc] | 12 | }; |
---|
| 13 | |
---|
| 14 | void ?{}( BThrd & this ) { |
---|
| 15 | ((thread&)this){ bench_cluster }; |
---|
| 16 | this.count = 0; |
---|
| 17 | this.blocks = 0; |
---|
[111a2ab3] | 18 | this.skip = false; |
---|
[3df86cc] | 19 | } |
---|
| 20 | |
---|
| 21 | void ^?{}( BThrd & mutex this ) {} |
---|
| 22 | |
---|
| 23 | void main( BThrd & this ) with( this ) { |
---|
[111a2ab3] | 24 | park(); |
---|
[3df86cc] | 25 | for() { |
---|
[111a2ab3] | 26 | uint32_t r = prng(this); |
---|
| 27 | semaphore & sem = spots[r % spot_cnt]; |
---|
| 28 | if(!skip) V( sem ); |
---|
| 29 | blocks += P( sem ); |
---|
| 30 | skip = false; |
---|
| 31 | |
---|
[3df86cc] | 32 | count ++; |
---|
| 33 | if( clock_mode && stop) break; |
---|
| 34 | if(!clock_mode && count >= stop_count) break; |
---|
| 35 | } |
---|
| 36 | |
---|
| 37 | __atomic_fetch_add(&threads_left, -1, __ATOMIC_SEQ_CST); |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | |
---|
| 41 | int main(int argc, char * argv[]) { |
---|
| 42 | cfa_option opt[] = { |
---|
| 43 | BENCH_OPT, |
---|
| 44 | { 's', "spots", "Number of spots in the system", spot_cnt } |
---|
| 45 | }; |
---|
[12bb5ab1] | 46 | BENCH_OPT_PARSE("cforall churn benchmark"); |
---|
[3df86cc] | 47 | |
---|
| 48 | { |
---|
| 49 | unsigned long long global_counter = 0; |
---|
| 50 | unsigned long long global_blocks = 0; |
---|
| 51 | Time start, end; |
---|
| 52 | BenchCluster bc = { nprocs }; |
---|
| 53 | { |
---|
| 54 | spots = aalloc(spot_cnt); |
---|
| 55 | for(i; spot_cnt) { |
---|
[111a2ab3] | 56 | (spots[i]){ 0 }; |
---|
[3df86cc] | 57 | } |
---|
| 58 | |
---|
| 59 | threads_left = nthreads; |
---|
| 60 | BThrd * threads[nthreads]; |
---|
| 61 | for(i; nthreads ) { |
---|
[111a2ab3] | 62 | BThrd & t = *(threads[i] = malloc()); |
---|
| 63 | (t){}; |
---|
| 64 | t.skip = i < spot_cnt; |
---|
[3df86cc] | 65 | } |
---|
| 66 | printf("Starting\n"); |
---|
| 67 | |
---|
| 68 | bool is_tty = isatty(STDOUT_FILENO); |
---|
| 69 | start = timeHiRes(); |
---|
| 70 | |
---|
| 71 | for(i; nthreads) { |
---|
[111a2ab3] | 72 | unpark( *threads[i] ); |
---|
[3df86cc] | 73 | } |
---|
| 74 | wait(start, is_tty); |
---|
| 75 | |
---|
| 76 | stop = true; |
---|
| 77 | end = timeHiRes(); |
---|
| 78 | printf("\nDone\n"); |
---|
| 79 | |
---|
[111a2ab3] | 80 | for(i; spot_cnt) { |
---|
| 81 | for(10000) V( spots[i] ); |
---|
| 82 | } |
---|
| 83 | |
---|
[3df86cc] | 84 | for(i; nthreads) { |
---|
| 85 | BThrd & thrd = join( *threads[i] ); |
---|
| 86 | global_counter += thrd.count; |
---|
| 87 | global_blocks += thrd.blocks; |
---|
| 88 | delete(threads[i]); |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | free(spots); |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | printf("Duration (ms) : %'lf\n", (end - start)`dms); |
---|
| 95 | printf("Number of processors : %'d\n", nprocs); |
---|
| 96 | printf("Number of threads : %'d\n", nthreads); |
---|
| 97 | printf("Number of spots : %'d\n", spot_cnt); |
---|
| 98 | printf("Total Operations(ops): %'15llu\n", global_counter); |
---|
| 99 | printf("Total blocks : %'15llu\n", global_blocks); |
---|
| 100 | printf("Ops per second : %'18.2lf\n", ((double)global_counter) / (end - start)`ds); |
---|
| 101 | printf("ns per ops : %'18.2lf\n", (end - start)`dns / global_counter); |
---|
| 102 | printf("Ops per threads : %'15llu\n", global_counter / nthreads); |
---|
| 103 | printf("Ops per procs : %'15llu\n", global_counter / nprocs); |
---|
| 104 | printf("Ops/sec/procs : %'18.2lf\n", (((double)global_counter) / nprocs) / (end - start)`ds); |
---|
| 105 | printf("ns per ops/procs : %'18.2lf\n", (end - start)`dns / (global_counter / nprocs)); |
---|
| 106 | fflush(stdout); |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | return 0; |
---|
[75965a6] | 110 | } |
---|