[2c7eee0] | 1 |
|
---|
| 2 | #include "rq_bench.hpp"
|
---|
[69d1748] | 3 | #include <libfibre/fibre.h>
|
---|
[2c7eee0] | 4 |
|
---|
| 5 | struct Partner {
|
---|
| 6 | unsigned long long count = 0;
|
---|
| 7 | unsigned long long blocks = 0;
|
---|
| 8 | bench_sem self;
|
---|
| 9 | bench_sem * next;
|
---|
| 10 | };
|
---|
| 11 |
|
---|
| 12 | void partner_main( Partner * self ) {
|
---|
| 13 | self->count = 0;
|
---|
| 14 | for(;;) {
|
---|
| 15 | self->blocks += self->self.wait();
|
---|
| 16 | self->next->post();
|
---|
| 17 | self->count ++;
|
---|
| 18 | if( clock_mode && stop) break;
|
---|
| 19 | if(!clock_mode && self->count >= stop_count) break;
|
---|
| 20 | }
|
---|
| 21 |
|
---|
| 22 | __atomic_fetch_add(&threads_left, -1, __ATOMIC_SEQ_CST);
|
---|
| 23 | }
|
---|
| 24 |
|
---|
| 25 | int main(int argc, char * argv[]) {
|
---|
| 26 | unsigned ring_size = 2;
|
---|
| 27 | option_t opt[] = {
|
---|
| 28 | BENCH_OPT,
|
---|
| 29 | { 'r', "ringsize", "Number of threads in a cycle", ring_size }
|
---|
| 30 | };
|
---|
[c4241b6] | 31 | BENCH_OPT_PARSE("libfibre cycle benchmark");
|
---|
[2c7eee0] | 32 |
|
---|
| 33 | {
|
---|
| 34 | unsigned long long global_counter = 0;
|
---|
| 35 | unsigned long long global_blocks = 0;
|
---|
| 36 | unsigned tthreads = nthreads * ring_size;
|
---|
| 37 | uint64_t start, end;
|
---|
| 38 | FibreInit(1, nprocs);
|
---|
| 39 | {
|
---|
| 40 | threads_left = tthreads;
|
---|
| 41 | Fibre * threads[tthreads];
|
---|
| 42 | Partner thddata[tthreads];
|
---|
[ebb6158] | 43 | for(unsigned i = 0; i < tthreads; i++) {
|
---|
[2c7eee0] | 44 | unsigned pi = (i + nthreads) % tthreads;
|
---|
| 45 | thddata[i].next = &thddata[pi].self;
|
---|
| 46 | }
|
---|
[ebb6158] | 47 | for(unsigned i = 0; i < tthreads; i++) {
|
---|
[3b80db8] | 48 | threads[i] = new Fibre();
|
---|
| 49 | threads[i]->run( partner_main, &thddata[i] );
|
---|
[2c7eee0] | 50 | }
|
---|
| 51 | printf("Starting\n");
|
---|
| 52 |
|
---|
| 53 | bool is_tty = isatty(STDOUT_FILENO);
|
---|
[e54d0c3] | 54 | start = timeHiRes();
|
---|
[2c7eee0] | 55 |
|
---|
[ebb6158] | 56 | for(unsigned i = 0; i < nthreads; i++) {
|
---|
[2c7eee0] | 57 | thddata[i].self.post();
|
---|
| 58 | }
|
---|
[69d1748] | 59 | wait<Fibre>(start, is_tty);
|
---|
[2c7eee0] | 60 |
|
---|
| 61 | stop = true;
|
---|
[e54d0c3] | 62 | end = timeHiRes();
|
---|
[2c7eee0] | 63 | printf("\nDone\n");
|
---|
| 64 |
|
---|
[ebb6158] | 65 | for(unsigned i = 0; i < tthreads; i++) {
|
---|
[69d1748] | 66 | thddata[i].self.post();
|
---|
[2c7eee0] | 67 | fibre_join( threads[i], nullptr );
|
---|
| 68 | global_counter += thddata[i].count;
|
---|
| 69 | global_blocks += thddata[i].blocks;
|
---|
| 70 | }
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | printf("Duration (ms) : %'ld\n", to_miliseconds(end - start));
|
---|
| 74 | printf("Number of processors : %'d\n", nprocs);
|
---|
| 75 | printf("Number of threads : %'d\n", tthreads);
|
---|
| 76 | printf("Cycle size (# thrds) : %'d\n", ring_size);
|
---|
| 77 | printf("Total Operations(ops): %'15llu\n", global_counter);
|
---|
| 78 | printf("Total blocks : %'15llu\n", global_blocks);
|
---|
| 79 | printf("Ops per second : %'18.2lf\n", ((double)global_counter) / to_fseconds(end - start));
|
---|
| 80 | printf("ns per ops : %'18.2lf\n", ((double)(end - start)) / global_counter);
|
---|
| 81 | printf("Ops per threads : %'15llu\n", global_counter / tthreads);
|
---|
| 82 | printf("Ops per procs : %'15llu\n", global_counter / nprocs);
|
---|
| 83 | printf("Ops/sec/procs : %'18.2lf\n", (((double)global_counter) / nprocs) / to_fseconds(end - start));
|
---|
| 84 | printf("ns per ops/procs : %'18.2lf\n", ((double)(end - start)) / (global_counter / nprocs));
|
---|
| 85 | fflush(stdout);
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | return 0;
|
---|
[e54d0c3] | 89 | }
|
---|