Ignore:
Timestamp:
May 20, 2022, 10:36:45 AM (4 years ago)
Author:
m3zulfiq <m3zulfiq@…>
Branches:
ADT, ast-experimental, master, pthread-emulation, qualifiedEnum
Children:
25fa20a
Parents:
29d8c02 (diff), 7831e8fb (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • benchmark/readyQ/yield.cfa

    r29d8c02 r74ec742  
    1 #include <stdlib.h>
    2 #include <stdio.h>
    3 #include <string.h>
    4 #include <limits.h>
    5 
    6 extern "C" {
    7         #include <locale.h>
    8         #include <getopt.h>
    9 }
    10 
    11 #include <unistd.h>
    12 
    13 #include <clock.hfa>
    14 #include <time.hfa>
    15 #include <stats.hfa>
    16 
    17 #include "../benchcltr.hfa"
    18 
    19 extern bool traceHeapOn();
    20 
    21 
    22 volatile bool run = false;
    23 volatile unsigned long long global_counter;
     1#include "rq_bench.hfa"
    242
    253thread __attribute__((aligned(128))) Yielder {
    26         unsigned long long counter;
     4        unsigned long long count;
    275};
    286void ?{}( Yielder & this ) {
    29         this.counter = 0;
    30         ((thread&)this){ "Yielder Thread", *the_benchmark_cluster };
     7        ((thread&)this){ "Yielder Thread", bench_cluster };
     8        this.count = 0;
    319}
    3210
    3311void main( Yielder & this ) {
    3412        park();
    35         /* paranoid */ assert( true == __atomic_load_n(&run, __ATOMIC_RELAXED) );
     13        for() {
     14                yield();
     15                this.count++;
     16                if( clock_mode && stop) break;
     17                if(!clock_mode && this.count >= stop_count) break;
     18        }
    3619
    37         while(__atomic_load_n(&run, __ATOMIC_RELAXED)) {
    38                 yield();
    39                 this.counter++;
    40         }
    41         __atomic_fetch_add(&global_counter, this.counter, __ATOMIC_SEQ_CST);
     20        __atomic_fetch_add(&threads_left, -1, __ATOMIC_SEQ_CST);
    4221}
    4322
    4423int main(int argc, char * argv[]) {
    45         unsigned num_io = 1;
    46         io_context_params params;
    47 
    4824        cfa_option opt[] = {
    49                 BENCH_OPT_CFA
     25                BENCH_OPT
    5026        };
    51         int opt_cnt = sizeof(opt) / sizeof(cfa_option);
    52 
    53         char **left;
    54         parse_args( argc, argv, opt, opt_cnt, "[OPTIONS]...\ncforall yield benchmark", left );
     27        BENCH_OPT_PARSE("cforall yield benchmark");
    5528
    5629        {
    57                 printf("Running %d threads on %d processors for %f seconds\n", nthreads, nprocs, duration);
     30                unsigned long long global_counter = 0;
    5831
    5932                Time start, end;
    60                 BenchCluster cl = { num_io, params, CFA_STATS_READY_Q };
     33                BenchCluster bc = { nprocs };
    6134                {
    62                         BenchProc procs[nprocs];
    63                         {
    64                                 Yielder threads[nthreads];
    65                                 printf("Starting\n");
     35                        threads_left = nthreads;
     36                        Yielder threads[nthreads];
     37                        printf("Starting\n");
    6638
    67                                 bool is_tty = isatty(STDOUT_FILENO);
    68                                 start = timeHiRes();
    69                                 run = true;
     39                        bool is_tty = isatty(STDOUT_FILENO);
     40                        start = timeHiRes();
    7041
    71                                 for(i; nthreads) {
    72                                         unpark( threads[i] );
    73                                 }
    74                                 wait(duration, start, end, is_tty);
     42                        for(i; nthreads) {
     43                                unpark( threads[i] );
     44                        }
     45                        wait(start, is_tty);
    7546
    76                                 run = false;
    77                                 end = timeHiRes();
    78                                 printf("\nDone\n");
     47                        stop = true;
     48                        end = timeHiRes();
     49                        printf("\nDone\n");
     50
     51                        for(i; nthreads) {
     52                                Yielder & y = join( threads[i] );
     53                                global_counter += y.count;
    7954                        }
    8055                }
    8156
    82                 printf("Duration (ms)       : %'ld\n", (end - start)`dms);
    83                 printf("Number of processors: %'d\n", nprocs);
    84                 printf("Number of threads   : %'d\n", nthreads);
    85                 printf("Total yields        : %'15llu\n", global_counter);
    86                 printf("Yields per second   : %'18.2lf\n", ((double)global_counter) / (end - start)`s);
    87                 printf("ns per yields       : %'18.2lf\n", ((double)(end - start)`ns) / global_counter);
    88                 printf("Yields per procs    : %'15llu\n", global_counter / nprocs);
    89                 printf("Yields/sec/procs    : %'18.2lf\n", (((double)global_counter) / nprocs) / (end - start)`s);
    90                 printf("ns per yields/procs : %'18.2lf\n", ((double)(end - start)`ns) / (global_counter / nprocs));
     57                printf("Duration (ms)        : %'ld\n", (end - start)`dms);
     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) / (end - start)`s);
     62                printf("ns per ops           : %'18.2lf\n", (end - start)`dns / 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) / (end - start)`s);
     66                printf("ns per ops/procs     : %'18.2lf\n", (end - start)`dns / (global_counter / nprocs));
    9167                fflush(stdout);
    9268        }
Note: See TracChangeset for help on using the changeset viewer.