| 1 | #include "rq_bench.hfa"
|
|---|
| 2 |
|
|---|
| 3 | extern bool traceHeapOn();
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 | volatile bool run = false;
|
|---|
| 7 | volatile unsigned long long global_counter;
|
|---|
| 8 |
|
|---|
| 9 | thread __attribute__((aligned(128))) Yielder {
|
|---|
| 10 | unsigned long long counter;
|
|---|
| 11 | };
|
|---|
| 12 | void ?{}( Yielder & this ) {
|
|---|
| 13 | this.counter = 0;
|
|---|
| 14 | ((thread&)this){ "Yielder Thread" };
|
|---|
| 15 | }
|
|---|
| 16 |
|
|---|
| 17 | void main( Yielder & this ) {
|
|---|
| 18 | park();
|
|---|
| 19 | /* paranoid */ assert( true == __atomic_load_n(&run, __ATOMIC_RELAXED) );
|
|---|
| 20 |
|
|---|
| 21 | while(__atomic_load_n(&run, __ATOMIC_RELAXED)) {
|
|---|
| 22 | yield();
|
|---|
| 23 | this.counter++;
|
|---|
| 24 | }
|
|---|
| 25 | __atomic_fetch_add(&global_counter, this.counter, __ATOMIC_SEQ_CST);
|
|---|
| 26 | }
|
|---|
| 27 |
|
|---|
| 28 | int main(int argc, char * argv[]) {
|
|---|
| 29 | cfa_option opt[] = {
|
|---|
| 30 | BENCH_OPT
|
|---|
| 31 | };
|
|---|
| 32 | BENCH_OPT_PARSE("cforall yield benchmark");
|
|---|
| 33 |
|
|---|
| 34 | {
|
|---|
| 35 | printf("Running %d threads on %d processors for %f seconds\n", nthreads, nprocs, duration);
|
|---|
| 36 |
|
|---|
| 37 | Time start, end;
|
|---|
| 38 | BenchCluster bc = { nprocs };
|
|---|
| 39 | {
|
|---|
| 40 | Yielder threads[nthreads];
|
|---|
| 41 | printf("Starting\n");
|
|---|
| 42 |
|
|---|
| 43 | bool is_tty = isatty(STDOUT_FILENO);
|
|---|
| 44 | start = timeHiRes();
|
|---|
| 45 | run = true;
|
|---|
| 46 |
|
|---|
| 47 | for(i; nthreads) {
|
|---|
| 48 | unpark( threads[i] );
|
|---|
| 49 | }
|
|---|
| 50 | wait(start, is_tty);
|
|---|
| 51 |
|
|---|
| 52 | run = false;
|
|---|
| 53 | end = timeHiRes();
|
|---|
| 54 | printf("\nDone\n");
|
|---|
| 55 | }
|
|---|
| 56 |
|
|---|
| 57 | printf("Duration (ms) : %'ld\n", (end - start)`dms);
|
|---|
| 58 | printf("Number of processors : %'d\n", nprocs);
|
|---|
| 59 | printf("Number of threads : %'d\n", nthreads);
|
|---|
| 60 | printf("Total Operations(ops): %'15llu\n", global_counter);
|
|---|
| 61 | printf("Ops per second : %'18.2lf\n", ((double)global_counter) / (end - start)`s);
|
|---|
| 62 | printf("ns per ops : %'18.2lf\n", (end - start)`dns / global_counter);
|
|---|
| 63 | printf("Ops per threads : %'15llu\n", global_counter / nthreads);
|
|---|
| 64 | printf("Ops per procs : %'15llu\n", global_counter / nprocs);
|
|---|
| 65 | printf("Ops/sec/procs : %'18.2lf\n", (((double)global_counter) / nprocs) / (end - start)`s);
|
|---|
| 66 | printf("ns per ops/procs : %'18.2lf\n", (end - start)`dns / (global_counter / nprocs));
|
|---|
| 67 | fflush(stdout);
|
|---|
| 68 | }
|
|---|
| 69 | }
|
|---|