[9cf2b0f] | 1 | #include "rq_bench.hpp"
|
---|
| 2 | #include <libfibre/fibre.h>
|
---|
[04b5cef] | 3 |
|
---|
| 4 | volatile bool run = false;
|
---|
| 5 | volatile unsigned long long global_counter;
|
---|
| 6 |
|
---|
| 7 |
|
---|
[9cf2b0f] | 8 | void fibre_main() {
|
---|
| 9 | fibre_park();
|
---|
| 10 | unsigned long long count = 0;
|
---|
| 11 | for(;;) {
|
---|
[3b80db8] | 12 | Fibre::yield();
|
---|
[9cf2b0f] | 13 | count++;
|
---|
| 14 | if( clock_mode && stop) break;
|
---|
| 15 | if(!clock_mode && count >= stop_count) break;
|
---|
[04b5cef] | 16 | }
|
---|
[9cf2b0f] | 17 |
|
---|
| 18 | __atomic_fetch_add(&global_counter, count, __ATOMIC_SEQ_CST);
|
---|
| 19 | __atomic_fetch_add(&threads_left, -1, __ATOMIC_SEQ_CST);
|
---|
[04b5cef] | 20 | }
|
---|
| 21 |
|
---|
| 22 | int main(int argc, char * argv[]) {
|
---|
[9cf2b0f] | 23 | option_t opt[] = {
|
---|
| 24 | BENCH_OPT
|
---|
| 25 | };
|
---|
| 26 | BENCH_OPT_PARSE("libfibre yield benchmark");
|
---|
[04b5cef] | 27 |
|
---|
| 28 | {
|
---|
| 29 | printf("Running %d threads on %d processors for %lf seconds\n", nthreads, nprocs, duration);
|
---|
| 30 |
|
---|
[9cf2b0f] | 31 | FibreInit(1, nprocs);
|
---|
| 32 | uint64_t start, end;
|
---|
[04b5cef] | 33 | {
|
---|
[9cf2b0f] | 34 | threads_left = nthreads;
|
---|
| 35 | Fibre * threads[nthreads];
|
---|
| 36 | for(unsigned i = 0; i < nthreads; i++) {
|
---|
[3b80db8] | 37 | threads[i] = new Fibre();
|
---|
| 38 | threads[i]->run(fibre_main);
|
---|
[9cf2b0f] | 39 | }
|
---|
| 40 | printf("Starting\n");
|
---|
| 41 | bool is_tty = isatty(STDOUT_FILENO);
|
---|
| 42 | start = timeHiRes();
|
---|
[04b5cef] | 43 |
|
---|
[9cf2b0f] | 44 | for(unsigned i = 0; i < nthreads; i++ ) {
|
---|
| 45 | fibre_unpark( threads[i] );
|
---|
| 46 | }
|
---|
| 47 | wait<Fibre>(start, is_tty);
|
---|
[04b5cef] | 48 |
|
---|
[9cf2b0f] | 49 | stop = true;
|
---|
| 50 | end = timeHiRes();
|
---|
| 51 | for(unsigned i = 0; i < nthreads; i++ ) {
|
---|
| 52 | fibre_join( threads[i], nullptr );
|
---|
[04b5cef] | 53 | }
|
---|
| 54 | }
|
---|
| 55 |
|
---|
[9cf2b0f] | 56 | printf("Duration (ms) : %'ld\n", to_miliseconds(end - start));
|
---|
| 57 | printf("Number of processors : %'d\n", nprocs);
|
---|
| 58 | printf("Number of threads : %'d\n", nthreads);
|
---|
| 59 | printf("Total Operations(ops): %'15llu\n", global_counter);
|
---|
| 60 | printf("Ops per second : %'18.2lf\n", ((double)global_counter) / to_fseconds(end - start));
|
---|
| 61 | printf("ns per ops : %'18.2lf\n", ((double)(end - start)) / global_counter);
|
---|
| 62 | printf("Ops per threads : %'15llu\n", global_counter / nthreads);
|
---|
| 63 | printf("Ops per procs : %'15llu\n", global_counter / nprocs);
|
---|
| 64 | printf("Ops/sec/procs : %'18.2lf\n", (((double)global_counter) / nprocs) / to_fseconds(end - start));
|
---|
| 65 | printf("ns per ops/procs : %'18.2lf\n", ((double)(end - start)) / (global_counter / nprocs));
|
---|
| 66 | fflush(stdout);
|
---|
[04b5cef] | 67 | }
|
---|
[3b80db8] | 68 | }
|
---|