| [9cf2b0f] | 1 | #include "rq_bench.hfa"
 | 
|---|
| [2649ff9] | 2 | 
 | 
|---|
| [04b5cef] | 3 | thread __attribute__((aligned(128))) Yielder {
 | 
|---|
| [8197ca5] | 4 |         unsigned long long count;
 | 
|---|
| [2649ff9] | 5 | };
 | 
|---|
 | 6 | void ?{}( Yielder & this ) {
 | 
|---|
| [8197ca5] | 7 |         ((thread&)this){ "Yielder Thread", bench_cluster };
 | 
|---|
 | 8 |         this.count = 0;
 | 
|---|
| [2649ff9] | 9 | }
 | 
|---|
 | 10 | 
 | 
|---|
 | 11 | void main( Yielder & this ) {
 | 
|---|
| [e235429] | 12 |         park();
 | 
|---|
| [8197ca5] | 13 |         for() {
 | 
|---|
| [2649ff9] | 14 |                 yield();
 | 
|---|
| [8197ca5] | 15 |                 this.count++;
 | 
|---|
 | 16 |                 if( clock_mode && stop) break;
 | 
|---|
 | 17 |                 if(!clock_mode && this.count >= stop_count) break;
 | 
|---|
| [2649ff9] | 18 |         }
 | 
|---|
| [8197ca5] | 19 | 
 | 
|---|
 | 20 |         __atomic_fetch_add(&threads_left, -1, __ATOMIC_SEQ_CST);
 | 
|---|
| [2649ff9] | 21 | }
 | 
|---|
 | 22 | 
 | 
|---|
 | 23 | int main(int argc, char * argv[]) {
 | 
|---|
| [5bcdc8c] | 24 |         cfa_option opt[] = {
 | 
|---|
| [9cf2b0f] | 25 |                 BENCH_OPT
 | 
|---|
| [5bcdc8c] | 26 |         };
 | 
|---|
| [9cf2b0f] | 27 |         BENCH_OPT_PARSE("cforall yield benchmark");
 | 
|---|
| [2649ff9] | 28 | 
 | 
|---|
 | 29 |         {
 | 
|---|
| [8197ca5] | 30 |                 unsigned long long global_counter = 0;
 | 
|---|
| [2649ff9] | 31 | 
 | 
|---|
 | 32 |                 Time start, end;
 | 
|---|
| [9cf2b0f] | 33 |                 BenchCluster bc = { nprocs };
 | 
|---|
| [2649ff9] | 34 |                 {
 | 
|---|
| [8197ca5] | 35 |                         threads_left = nthreads;
 | 
|---|
| [8fe35be] | 36 |                         Yielder * threads = alloc(nthreads);
 | 
|---|
 | 37 |                         for(i; nthreads) {
 | 
|---|
 | 38 |                                 (threads[i]){};
 | 
|---|
 | 39 |                         }
 | 
|---|
 | 40 | 
 | 
|---|
| [9cf2b0f] | 41 |                         printf("Starting\n");
 | 
|---|
| [9791ab5] | 42 | 
 | 
|---|
| [9cf2b0f] | 43 |                         bool is_tty = isatty(STDOUT_FILENO);
 | 
|---|
 | 44 |                         start = timeHiRes();
 | 
|---|
| [2649ff9] | 45 | 
 | 
|---|
| [9cf2b0f] | 46 |                         for(i; nthreads) {
 | 
|---|
 | 47 |                                 unpark( threads[i] );
 | 
|---|
| [2649ff9] | 48 |                         }
 | 
|---|
| [9cf2b0f] | 49 |                         wait(start, is_tty);
 | 
|---|
 | 50 | 
 | 
|---|
| [8197ca5] | 51 |                         stop = true;
 | 
|---|
| [9cf2b0f] | 52 |                         end = timeHiRes();
 | 
|---|
 | 53 |                         printf("\nDone\n");
 | 
|---|
| [8197ca5] | 54 | 
 | 
|---|
 | 55 |                         for(i; nthreads) {
 | 
|---|
 | 56 |                                 Yielder & y = join( threads[i] );
 | 
|---|
 | 57 |                                 global_counter += y.count;
 | 
|---|
| [8fe35be] | 58 |                                 ^(threads[i]){};
 | 
|---|
| [8197ca5] | 59 |                         }
 | 
|---|
| [8fe35be] | 60 |                         free(threads);
 | 
|---|
| [2649ff9] | 61 |                 }
 | 
|---|
 | 62 | 
 | 
|---|
| [9cf2b0f] | 63 |                 printf("Duration (ms)        : %'ld\n", (end - start)`dms);
 | 
|---|
 | 64 |                 printf("Number of processors : %'d\n", nprocs);
 | 
|---|
 | 65 |                 printf("Number of threads    : %'d\n", nthreads);
 | 
|---|
 | 66 |                 printf("Total Operations(ops): %'15llu\n", global_counter);
 | 
|---|
 | 67 |                 printf("Ops per second       : %'18.2lf\n", ((double)global_counter) / (end - start)`s);
 | 
|---|
 | 68 |                 printf("ns per ops           : %'18.2lf\n", (end - start)`dns / global_counter);
 | 
|---|
 | 69 |                 printf("Ops per threads      : %'15llu\n", global_counter / nthreads);
 | 
|---|
 | 70 |                 printf("Ops per procs        : %'15llu\n", global_counter / nprocs);
 | 
|---|
 | 71 |                 printf("Ops/sec/procs        : %'18.2lf\n", (((double)global_counter) / nprocs) / (end - start)`s);
 | 
|---|
 | 72 |                 printf("ns per ops/procs     : %'18.2lf\n", (end - start)`dns / (global_counter / nprocs));
 | 
|---|
| [b813f53] | 73 |                 fflush(stdout);
 | 
|---|
| [2649ff9] | 74 |         }
 | 
|---|
| [e54d0c3] | 75 | }
 | 
|---|