Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • benchmark/readyQ/transfer.go

    r65c9208 r6dc2db9  
    66        "math/rand"
    77        "os"
    8         "regexp"
    98        "runtime"
    109        "sync/atomic"
     
    1716        id uint64
    1817        idx uint64
    19         estop uint64
    2018        seed uint64
    2119}
     
    3634
    3735func NewLeader(size uint64) (*LeaderInfo) {
    38         this := &LeaderInfo{0, 0, 0, uint64(os.Getpid())}
     36        this := &LeaderInfo{0, 0, uint64(os.Getpid())}
    3937
    4038        r := rand.Intn(10)
     
    5351}
    5452
    55 func waitgroup(leader * LeaderInfo, idx uint64, threads [] MyThread, main_sem chan struct {}) {
     53func waitgroup(idx uint64, threads [] MyThread) {
    5654        start := time.Now()
    57         Outer:
    5855        for i := 0; i < len(threads); i++ {
    5956                // fmt.Fprintf(os.Stderr, "Waiting for :%d (%d)\n", threads[i].id, atomic.LoadUint64(&threads[i].idx) );
     
    6461                        if delta.Seconds() > 5 {
    6562                                fmt.Fprintf(os.Stderr, "Programs has been blocked for more than 5 secs")
    66                                 atomic.StoreUint64(&leader.estop, 1);
    67                                 main_sem <- (struct {}{})
    68                                 break Outer
     63                                os.Exit(1)
    6964                        }
    7065                }
     
    7974                if i != me {
    8075                        // debug!( "Leader waking {}", i);
    81                         defer func() {
    82                                 if err := recover(); err != nil {
    83                                         fmt.Fprintf(os.Stderr, "Panic occurred: %s\n", err)
    84                                 }
    85                         }()
    8676                        threads[i].sem <- (struct {}{})
    8777                }
     
    9484        atomic.StoreUint64(&leader.idx, nidx);
    9585
    96         if nidx > stop_count || atomic.LoadUint64(&leader.estop) != 0 {
     86        if nidx > stop_count {
    9787                // debug!( "Leader {} done", this.id);
    9888                main_sem <- (struct {}{})
     
    10292        // debug!( "====================\nLeader no {} : {}", nidx, this.id);
    10393
    104         waitgroup(leader, nidx, threads, main_sem);
     94        waitgroup(nidx, threads);
    10595
    10696        leader.next( uint64(len(threads)) );
     
    156146                        waitleader( exhaust, leader, &threads[me], &r )
    157147                }
    158                 if atomic.LoadUint64(&leader.idx) > stop_count || atomic.LoadUint64(&leader.estop) != 0 { break; }
     148                if atomic.LoadUint64(&leader.idx) > stop_count { break; }
    159149        }
    160150
     
    165155func main() {
    166156        // Benchmark specific command line arguments
    167         exhaustOpt := flag.String("e", "no", "Whether or not threads that have seen the new epoch should park instead of yielding.")
     157        exhaustOpt := flag.Bool("e", false, "Whether or not threads that have seen the new epoch should park instead of yielding.")
    168158
    169159        // General benchmark initialization and deinitialization
    170         bench_init()
    171 
    172         exhaustVal := *exhaustOpt;
    173 
    174         var exhaust bool
    175         re_yes := regexp.MustCompile("[Yy]|[Yy][Ee][Ss]")
    176         re_no  := regexp.MustCompile("[Nn]|[Nn][Oo]")
    177         if re_yes.Match([]byte(exhaustVal)) {
    178                 exhaust = true
    179         } else if re_no.Match([]byte(exhaustVal)) {
    180                 exhaust = false
    181         } else {
    182                 fmt.Fprintf(os.Stderr, "Unrecognized exhaust(-e) option '%s'\n", exhaustVal)
    183                 os.Exit(1)
    184         }
    185 
     160        defer bench_init()()
     161
     162        exhaust := *exhaustOpt;
    186163        if clock_mode {
    187                 fmt.Fprintf(os.Stderr, "Programs does not support fixed duration mode\n")
     164                fmt.Fprintf(os.Stderr, "Programs does not support fixed duration mode")
    188165                os.Exit(1)
    189166        }
     
    238215                ws = "no"
    239216        }
    240         p.Printf("Duration (ms)           : %d\n", delta.Milliseconds() )
     217        p.Printf("Duration (ms)           : %f\n", delta.Milliseconds() )
    241218        p.Printf("Number of processors    : %d\n", nprocs )
    242219        p.Printf("Number of threads       : %d\n", nthreads )
    243         p.Printf("Total Operations(ops)   : %15d\n", (leader.idx - 1) )
     220        p.Printf("Total Operations(ops)   : %15d\n", stop_count )
    244221        p.Printf("Threads parking on wait : %s\n", ws)
    245222        p.Printf("Rechecking              : %d\n", rechecks )
    246         p.Printf("ns per transfer         : %f\n", float64(delta.Nanoseconds()) / float64(leader.idx) )
    247 }
     223}
Note: See TracChangeset for help on using the changeset viewer.