Changes in / [daefe93:82f791f]


Ignore:
Files:
2 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • benchmark/readyQ/cycle.cfa

    rdaefe93 r82f791f  
    11#include "rq_bench.hfa"
    22
    3 struct Partner {
     3thread Partner {
     4        Partner * partner;
    45        unsigned long long count;
    5         unsigned long long blocks;
    6         bench_sem self;
    7         bench_sem * next;
    86};
    97
    108void ?{}( Partner & this ) {
    11         this.count = this.blocks = 0;
     9        ((thread&)this){ bench_cluster };
    1210}
    1311
    14 thread BThrd {
    15         Partner & partner;
    16 };
    17 
    18 void ?{}( BThrd & this, Partner * partner ) {
    19         ((thread&)this){ bench_cluster };
    20         &this.partner = partner;
    21 }
    22 
    23 void ^?{}( BThrd & mutex this ) {}
    24 
    25 void main( BThrd & thrd ) with(thrd.partner) {
    26         count = 0;
     12void main( Partner & this ) {
     13        this.count = 0;
    2714        for() {
    28                 blocks += wait( self );
    29                 post( *next );
    30                 count ++;
     15                park();
     16                unpark( *this.partner );
     17                this.count ++;
    3118                if( clock_mode && stop) break;
    32                 if(!clock_mode && count >= stop_count) break;
     19                if(!clock_mode && this.count >= stop_count) break;
    3320        }
    3421
     
    4633        {
    4734                unsigned long long global_counter = 0;
    48                 unsigned long long global_blocks  = 0;
    4935                unsigned tthreads = nthreads * ring_size;
    5036                Time start, end;
     
    5238                {
    5339                        threads_left = tthreads;
    54                         BThrd * threads[tthreads];
    55                         Partner thddata[tthreads];
     40                        Partner threads[tthreads];
    5641                        for(i; tthreads) {
    5742                                unsigned pi = (i + nthreads) % tthreads;
    58                                 thddata[i].next = &thddata[pi].self;
    59                         }
    60                         for(int i = 0; i < tthreads; i++) {
    61                                 threads[i] = malloc();
    62                                 (*threads[i]){ &thddata[i] };
     43                                threads[i].partner = &threads[pi];
    6344                        }
    6445                        printf("Starting\n");
     
    6849
    6950                        for(i; nthreads) {
    70                                 post( thddata[i].self );
     51                                unpark( threads[i] );
    7152                        }
    7253                        wait(start, is_tty);
     
    7758
    7859                        for(i; tthreads) {
    79                                 Partner & partner = join( *threads[i] ).partner;
    80                                 global_counter += partner.count;
    81                                 global_blocks  += partner.blocks;
    82                                 delete(threads[i]);
     60                                global_counter += join( threads[i] ).count;
    8361                        }
    8462                }
    8563
    86                 printf("Duration (ms)        : %'ld\n", (end - start)`ms);
    87                 printf("Number of processors : %'d\n", nprocs);
    88                 printf("Number of threads    : %'d\n", tthreads);
    89                 printf("Cycle size (# thrds) : %'d\n", ring_size);
    90                 printf("Total Operations(ops): %'15llu\n", global_counter);
    91                 printf("Total blocks         : %'15llu\n", global_blocks);
    92                 printf("Ops per second       : %'18.2lf\n", ((double)global_counter) / (end - start)`s);
    93                 printf("ns per ops           : %'18.2lf\n", ((double)(end - start)`ns) / global_counter);
    94                 printf("Ops per threads      : %'15llu\n", global_counter / tthreads);
    95                 printf("Ops per procs        : %'15llu\n", global_counter / nprocs);
    96                 printf("Ops/sec/procs        : %'18.2lf\n", (((double)global_counter) / nprocs) / (end - start)`s);
    97                 printf("ns per ops/procs     : %'18.2lf\n", ((double)(end - start)`ns) / (global_counter / nprocs));
     64                printf("Duration (ms)       : %'ld\n", (end - start)`ms);
     65                printf("Number of processors: %'d\n", nprocs);
     66                printf("Number of threads   : %'d\n", tthreads);
     67                printf("Cycle size (# thrds): %'d\n", ring_size);
     68                printf("Yields per second   : %'18.2lf\n", ((double)global_counter) / (end - start)`s);
     69                printf("ns per yields       : %'18.2lf\n", ((double)(end - start)`ns) / global_counter);
     70                printf("Total yields        : %'15llu\n", global_counter);
     71                printf("Yields per threads  : %'15llu\n", global_counter / tthreads);
     72                printf("Yields per procs    : %'15llu\n", global_counter / nprocs);
     73                printf("Yields/sec/procs    : %'18.2lf\n", (((double)global_counter) / nprocs) / (end - start)`s);
     74                printf("ns per yields/procs : %'18.2lf\n", ((double)(end - start)`ns) / (global_counter / nprocs));
    9875                fflush(stdout);
    9976        }
  • benchmark/readyQ/cycle.cpp

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

    rdaefe93 r82f791f  
    22
    33import (
     4        "bufio"
    45        "flag"
    56        "fmt"
     7        "os"
     8        "runtime"
    69        "sync/atomic"
    710        "time"
     
    912        "golang.org/x/text/message"
    1013)
     14
     15var clock_mode bool
     16var threads_left int64
     17var stop int32
     18var duration float64
     19var stop_count uint64
     20
     21func fflush(f *bufio.Writer) {
     22        defer f.Flush()
     23        f.Write([]byte("\r"))
     24}
     25
     26func wait(start time.Time, is_tty bool) {
     27        f := bufio.NewWriter(os.Stdout)
     28        tdur := time.Duration(duration)
     29        for true {
     30                time.Sleep(100 * time.Millisecond)
     31                end := time.Now()
     32                delta := end.Sub(start)
     33                if is_tty {
     34                        fmt.Printf(" %.1f",delta.Seconds())
     35                        fflush(f)
     36                }
     37                if clock_mode && delta >= (tdur * time.Second) {
     38                        break
     39                } else if !clock_mode && atomic.LoadInt64(&threads_left) == 0 {
     40                        break
     41                }
     42        }
     43}
    1144
    1245func partner(result chan uint64, mine chan int, next chan int) {
     
    2558
    2659func main() {
     60        var nprocs int
     61        var nthreads int
    2762        var ring_size int
    2863
     64        nprocsOpt := flag.Int("p", 1, "The number of processors")
     65        nthreadsOpt := flag.Int("t", 1, "The number of threads")
    2966        ring_sizeOpt := flag.Int("r", 2, "The number of threads per cycles")
     67        durationOpt := flag.Float64("d", 0, "Duration of the experiment in seconds")
     68        stopOpt := flag.Uint64("i", 0, "Duration of the experiment in iterations")
    3069
    31         bench_init()
     70        flag.Parse()
    3271
     72        nprocs = *nprocsOpt
     73        nthreads = *nthreadsOpt
    3374        ring_size = *ring_sizeOpt
     75        duration = *durationOpt
     76        stop_count = *stopOpt
    3477
     78        if duration > 0 && stop_count > 0 {
     79                panic(fmt.Sprintf("--duration and --iterations cannot be used together\n"))
     80        } else if duration > 0 {
     81                clock_mode = true
     82                stop_count = 0xFFFFFFFFFFFFFFFF
     83                fmt.Printf("Running for %f seconds\n", duration)
     84        } else if stop_count > 0 {
     85                clock_mode = false
     86                fmt.Printf("Running for %d iterations\n", stop_count)
     87        } else {
     88                duration = 5
     89                clock_mode = true
     90                fmt.Printf("Running for %f seconds\n", duration)
     91        }
     92
     93        runtime.GOMAXPROCS(nprocs)
    3594        tthreads := nthreads * ring_size
    3695        threads_left = int64(tthreads)
     
    67126
    68127        p := message.NewPrinter(language.English)
    69         p.Printf("Duration (ms)        : %f\n", delta.Seconds());
    70         p.Printf("Number of processors : %d\n", nprocs);
    71         p.Printf("Number of threads    : %d\n", tthreads);
    72         p.Printf("Cycle size (# thrds) : %d\n", ring_size);
    73         p.Printf("Total Operations(ops): %15d\n", global_counter)
    74         p.Printf("Yields per second    : %18.2f\n", float64(global_counter) / delta.Seconds())
    75         p.Printf("ns per ops           : %18.2f\n", float64(delta.Nanoseconds()) / float64(global_counter))
    76         p.Printf("Ops per threads      : %15d\n", global_counter / uint64(tthreads))
    77         p.Printf("Ops per procs        : %15d\n", global_counter / uint64(nprocs))
    78         p.Printf("Ops/sec/procs        : %18.2f\n", (float64(global_counter) / float64(nprocs)) / delta.Seconds())
    79         p.Printf("ns per ops/procs    : %18.2f\n", float64(delta.Nanoseconds()) / (float64(global_counter) / float64(nprocs)))
     128        p.Printf("Duration (ms)       : %f\n", delta.Seconds());
     129        p.Printf("Number of processors: %d\n", nprocs);
     130        p.Printf("Number of threads   : %d\n", tthreads);
     131        p.Printf("Cycle size (# thrds): %d\n", ring_size);
     132        p.Printf("Yields per second   : %18.2f\n", float64(global_counter) / delta.Seconds())
     133        p.Printf("ns per yields       : %18.2f\n", float64(delta.Nanoseconds()) / float64(global_counter))
     134        p.Printf("Total yields        : %15d\n", global_counter)
     135        p.Printf("Yields per threads  : %15d\n", global_counter / uint64(tthreads))
     136        p.Printf("Yields per procs    : %15d\n", global_counter / uint64(nprocs))
     137        p.Printf("Yields/sec/procs    : %18.2f\n", (float64(global_counter) / float64(nprocs)) / delta.Seconds())
     138        p.Printf("ns per yields/procs : %18.2f\n", float64(delta.Nanoseconds()) / (float64(global_counter) / float64(nprocs)))
    80139
    81140}
  • benchmark/readyQ/rq_bench.hfa

    rdaefe93 r82f791f  
    6666
    6767void ^?{}( BenchCluster & this ) {
    68         adelete( this.procs );
     68        adelete( this.nprocs, this.procs );
    6969        ^(this.cl){};
    7070}
     
    8787        }
    8888}
    89 
    90 struct bench_sem {
    91         struct $thread * volatile ptr;
    92 };
    93 
    94 static inline {
    95         void  ?{}(bench_sem & this) {
    96                 this.ptr = 0p;
    97         }
    98 
    99         void ^?{}(bench_sem & this) {}
    100 
    101         bool wait(bench_sem & this) {
    102                 for() {
    103                         struct $thread * expected = this.ptr;
    104                         if(expected == 1p) {
    105                                 if(__atomic_compare_exchange_n(&this.ptr, &expected, 0p, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
    106                                         return false;
    107                                 }
    108                         }
    109                         else {
    110                                 /* paranoid */ verify( expected == 0p );
    111                                 if(__atomic_compare_exchange_n(&this.ptr, &expected, active_thread(), false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
    112                                         park();
    113                                         return true;
    114                                 }
    115                         }
    116 
    117                 }
    118         }
    119 
    120         bool post(bench_sem & this) {
    121                 for() {
    122                         struct $thread * expected = this.ptr;
    123                         if(expected == 1p) return false;
    124                         if(expected == 0p) {
    125                                 if(__atomic_compare_exchange_n(&this.ptr, &expected, 1p, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
    126                                         return false;
    127                                 }
    128                         }
    129                         else {
    130                                 if(__atomic_compare_exchange_n(&this.ptr, &expected, 0p, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
    131                                         unpark( expected );
    132                                         return true;
    133                                 }
    134                         }
    135                 }
    136         }
    137 }
  • benchmark/rmit.py

    rdaefe93 r82f791f  
    1010
    1111import argparse
    12 import datetime
    1312import itertools
    1413import os
     
    102101        return nopts
    103102
    104 def actions_eta(actions):
    105         time = 0
    106         for a in actions:
    107                 i = 0
    108                 while i < len(a):
    109                         if a[i] == '-d':
    110                                 i += 1
    111                                 if i != len(a):
    112                                         time += int(a[i])
    113                         i += 1
    114         return time
    115 
    116103if __name__ == "__main__":
    117104        # ================================================================================
     
    173160        # ================================================================================
    174161        # Prepare to run
    175         print(actions)
    176 
    177         # find expected time
    178         time = actions_eta(actions)
    179         print("Running {} trials{}".format(len(actions), "" if time == 0 else " (expecting to take {}".format(str(datetime.timedelta(seconds=int(time)))) ))
    180 
    181162        random.shuffle(actions)
     163
     164        print("Running {} trials".format(len(actions)))
    182165        result = []
    183166
  • libcfa/src/concurrency/kernel.cfa

    rdaefe93 r82f791f  
    469469
    470470                thrd->state = Halted;
    471                 if( TICKET_RUNNING != thrd->ticket ) { abort( "Thread terminated with pending unpark" ); }
     471
    472472                if( thrd != this->owner || this->recursion != 1) { abort( "Thread internal monitor has unbalanced recursion" ); }
    473473
     
    735735                this.print_halts = true;
    736736        }
    737 
    738         void print_stats_now( cluster & this, int flags ) {
    739                 __print_stats( this.stats, this.print_stats, true, this.name, (void*)&this );
    740         }
    741737#endif
    742738// Local Variables: //
Note: See TracChangeset for help on using the changeset viewer.