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