Ignore:
Timestamp:
Nov 3, 2020, 1:21:36 PM (13 months ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
arm-eh, jacob/cs343-translation, master, new-ast-unique-expr
Children:
dbb1073
Parents:
58688bf
Message:

Fixed cycle benchmark to avoid extra unmatched unpark.
Added libfibre implementation.
Split out go common code into bench.go

File:
1 edited

Legend:

Unmodified
Added
Removed
  • benchmark/readyQ/cycle.go

    r58688bf r2c7eee0  
    22
    33import (
    4         "bufio"
    54        "flag"
    65        "fmt"
    7         "os"
    8         "runtime"
    96        "sync/atomic"
    107        "time"
     
    129        "golang.org/x/text/message"
    1310)
    14 
    15 var clock_mode bool
    16 var threads_left int64
    17 var stop int32
    18 var duration float64
    19 var stop_count uint64
    20 
    21 func fflush(f *bufio.Writer) {
    22         defer f.Flush()
    23         f.Write([]byte("\r"))
    24 }
    25 
    26 func 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 }
    4411
    4512func partner(result chan uint64, mine chan int, next chan int) {
     
    5825
    5926func main() {
    60         var nprocs int
    61         var nthreads int
    6227        var ring_size int
    6328
    64         nprocsOpt := flag.Int("p", 1, "The number of processors")
    65         nthreadsOpt := flag.Int("t", 1, "The number of threads")
    6629        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")
    6930
    70         flag.Parse()
     31        bench_init()
    7132
    72         nprocs = *nprocsOpt
    73         nthreads = *nthreadsOpt
    7433        ring_size = *ring_sizeOpt
    75         duration = *durationOpt
    76         stop_count = *stopOpt
    7734
    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)
    9435        tthreads := nthreads * ring_size
    9536        threads_left = int64(tthreads)
     
    12667
    12768        p := message.NewPrinter(language.English)
    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)))
     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)))
    13980
    14081}
Note: See TracChangeset for help on using the changeset viewer.