1 |
|
---|
2 | #include "rq_bench.hpp"
|
---|
3 | #include <libfibre/fibre.h>
|
---|
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 | };
|
---|
31 | BENCH_OPT_PARSE("libfibre cycle benchmark");
|
---|
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 = new Fibre *[tthreads]();
|
---|
42 | Partner* thddata = new Partner[tthreads]();
|
---|
43 | for(unsigned i = 0; i < tthreads; i++) {
|
---|
44 | unsigned pi = (i + nthreads) % tthreads;
|
---|
45 | thddata[i].next = &thddata[pi].self;
|
---|
46 | }
|
---|
47 | for(unsigned i = 0; i < tthreads; i++) {
|
---|
48 | threads[i] = new Fibre();
|
---|
49 | threads[i]->run( partner_main, &thddata[i] );
|
---|
50 | }
|
---|
51 | printf("Starting\n");
|
---|
52 |
|
---|
53 | bool is_tty = isatty(STDOUT_FILENO);
|
---|
54 | start = timeHiRes();
|
---|
55 |
|
---|
56 | for(unsigned i = 0; i < nthreads; i++) {
|
---|
57 | thddata[i].self.post();
|
---|
58 | }
|
---|
59 | wait<Fibre>(start, is_tty);
|
---|
60 |
|
---|
61 | stop = true;
|
---|
62 | end = timeHiRes();
|
---|
63 | printf("\nDone\n");
|
---|
64 |
|
---|
65 | for(unsigned i = 0; i < tthreads; i++) {
|
---|
66 | thddata[i].self.post();
|
---|
67 | fibre_join( threads[i], nullptr );
|
---|
68 | global_counter += thddata[i].count;
|
---|
69 | global_blocks += thddata[i].blocks;
|
---|
70 | }
|
---|
71 |
|
---|
72 | delete[](threads);
|
---|
73 | delete[](thddata);
|
---|
74 | }
|
---|
75 |
|
---|
76 | printf("Duration (ms) : %'ld\n", to_miliseconds(end - start));
|
---|
77 | printf("Number of processors : %'d\n", nprocs);
|
---|
78 | printf("Number of threads : %'d\n", tthreads);
|
---|
79 | printf("Cycle size (# thrds) : %'d\n", ring_size);
|
---|
80 | printf("Total Operations(ops): %'15llu\n", global_counter);
|
---|
81 | printf("Total blocks : %'15llu\n", global_blocks);
|
---|
82 | printf("Ops per second : %'18.2lf\n", ((double)global_counter) / to_fseconds(end - start));
|
---|
83 | printf("ns per ops : %'18.2lf\n", ((double)(end - start)) / global_counter);
|
---|
84 | printf("Ops per threads : %'15llu\n", global_counter / tthreads);
|
---|
85 | printf("Ops per procs : %'15llu\n", global_counter / nprocs);
|
---|
86 | printf("Ops/sec/procs : %'18.2lf\n", (((double)global_counter) / nprocs) / to_fseconds(end - start));
|
---|
87 | printf("ns per ops/procs : %'18.2lf\n", ((double)(end - start)) / (global_counter / nprocs));
|
---|
88 | fflush(stdout);
|
---|
89 | }
|
---|
90 |
|
---|
91 | return 0;
|
---|
92 | }
|
---|