source: benchmark/readyQ/churn.cfa@ 124400b

ast-experimental
Last change on this file since 124400b was 8fe35be, checked in by Thierry Delisle <tdelisle@…>, 3 years ago

Fixed some benchmarks that were still using stack arrays

  • Property mode set to 100644
File size: 2.6 KB
RevLine 
[3df86cc]1#include "rq_bench.hfa"
2
[111a2ab3]3#include <locks.hfa>
4
[3df86cc]5unsigned spot_cnt = 2;
[111a2ab3]6semaphore * spots;
[3df86cc]7
8thread BThrd {
9 unsigned long long count;
10 unsigned long long blocks;
[111a2ab3]11 bool skip;
[3df86cc]12};
13
14void ?{}( BThrd & this ) {
15 ((thread&)this){ bench_cluster };
16 this.count = 0;
17 this.blocks = 0;
[111a2ab3]18 this.skip = false;
[3df86cc]19}
20
21void ^?{}( BThrd & mutex this ) {}
22
23void 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
41int 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;
[8fe35be]60 BThrd ** threads = alloc(nthreads);
[3df86cc]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);
[8fe35be]92 free(threads);
[3df86cc]93 }
94
95 printf("Duration (ms) : %'lf\n", (end - start)`dms);
96 printf("Number of processors : %'d\n", nprocs);
97 printf("Number of threads : %'d\n", nthreads);
98 printf("Number of spots : %'d\n", spot_cnt);
99 printf("Total Operations(ops): %'15llu\n", global_counter);
100 printf("Total blocks : %'15llu\n", global_blocks);
101 printf("Ops per second : %'18.2lf\n", ((double)global_counter) / (end - start)`ds);
102 printf("ns per ops : %'18.2lf\n", (end - start)`dns / global_counter);
103 printf("Ops per threads : %'15llu\n", global_counter / nthreads);
104 printf("Ops per procs : %'15llu\n", global_counter / nprocs);
105 printf("Ops/sec/procs : %'18.2lf\n", (((double)global_counter) / nprocs) / (end - start)`ds);
106 printf("ns per ops/procs : %'18.2lf\n", (end - start)`dns / (global_counter / nprocs));
107 fflush(stdout);
108 }
109
110 return 0;
[75965a6]111}
Note: See TracBrowser for help on using the repository browser.