#include #include #include #include extern "C" { #include #include } #include #include #include #include #include "../benchcltr.hfa" extern bool traceHeapOn(); volatile bool run = false; volatile unsigned long long global_counter; thread __attribute__((aligned(128))) Yielder { unsigned long long counter; }; void ?{}( Yielder & this ) { this.counter = 0; ((thread&)this){ "Yielder Thread", *the_benchmark_cluster }; } void main( Yielder & this ) { park( __cfaabi_dbg_ctx ); /* paranoid */ assert( true == __atomic_load_n(&run, __ATOMIC_RELAXED) ); while(__atomic_load_n(&run, __ATOMIC_RELAXED)) { yield(); this.counter++; } __atomic_fetch_add(&global_counter, this.counter, __ATOMIC_SEQ_CST); } int main(int argc, char * argv[]) { BENCH_DECL for(;;) { static struct option options[] = { BENCH_OPT_LONG {0, 0, 0, 0} }; int idx = 0; int opt = getopt_long(argc, argv, BENCH_OPT_SHORT, options, &idx); const char * arg = optarg ? optarg : ""; char * end; switch(opt) { case -1: goto run; BENCH_OPT_CASE default: /* ? */ fprintf( stderr, "Unkown option '%c'\n", opt); usage: bench_usage( argv ); exit(1); } } run: { printf("Running %d threads on %d processors for %f seconds\n", nthreads, nprocs, duration); Time start, end; BenchCluster cl = { 0, CFA_STATS_READY_Q }; { BenchProc procs[nprocs]; { Yielder threads[nthreads]; printf("Starting\n"); bool is_tty = isatty(STDOUT_FILENO); start = getTimeNsec(); run = true; for(i; nthreads) { unpark( threads[i] __cfaabi_dbg_ctx2 ); } wait(duration, start, end, is_tty); run = false; end = getTimeNsec(); printf("\nDone\n"); } } printf("Took %'ld ms\n", (end - start)`ms); printf("Yields per second : %'18.2lf\n", ((double)global_counter) / (end - start)`s); printf("ns per yields : %'18.2lf\n", ((double)(end - start)`ns) / global_counter); printf("Total yields : %'15llu\n", global_counter); printf("Yields per procs : %'15llu\n", global_counter / nprocs); printf("Yields/sec/procs : %'18.2lf\n", (((double)global_counter) / nprocs) / (end - start)`s); printf("ns per yields/procs : %'18.2lf\n", ((double)(end - start)`ns) / (global_counter / nprocs)); fflush(stdout); } }