Changeset 65c9208 for benchmark


Ignore:
Timestamp:
May 10, 2022, 12:28:54 PM (2 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, ast-experimental, master, pthread-emulation, qualifiedEnum
Children:
e07187d
Parents:
3613e25
Message:

Changed transfer benchmark to be more consistent with other rmit benchmarks

Location:
benchmark/readyQ
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • benchmark/readyQ/transfer.cfa

    r3613e25 r65c9208  
    1414
    1515bool exhaust = false;
     16volatile bool estop = false;
     17
    1618
    1719thread$ * the_main;
     
    3537static void waitgroup() {
    3638        Time start = timeHiRes();
    37         for(i; nthreads) {
     39        OUTER: for(i; nthreads) {
    3840                PRINT( sout | "Waiting for :" | i | "(" | threads[i]->idx | ")"; )
    3941                while( threads[i]->idx != lead_idx ) {
     
    4244                                print_stats_now( bench_cluster, CFA_STATS_READY_Q | CFA_STATS_IO );
    4345                                serr | "Programs has been blocked for more than 5 secs";
    44                                 exit(1);
     46                                estop = true;
     47                                unpark( the_main );
     48                                break OUTER;
    4549                        }
    4650                }
     
    5963static void lead(MyThread & this) {
    6064        this.idx = ++lead_idx;
    61         if(lead_idx > stop_count) {
     65        if(lead_idx > stop_count || estop) {
    6266                PRINT( sout | "Leader" | this.id | "done"; )
    6367                unpark( the_main );
     
    100104                        wait( this );
    101105                }
    102                 if(lead_idx > stop_count) break;
     106                if(lead_idx > stop_count || estop) break;
    103107        }
    104108}
     
    172176        sout | "Number of processors    : " | nprocs;
    173177        sout | "Number of threads       : " | nthreads;
    174         sout | "Total Operations(ops)   : " | stop_count;
     178        sout | "Total Operations(ops)   : " | lead_idx - 1;
    175179        sout | "Threads parking on wait : " | (exhaust ? "yes" : "no");
    176180        sout | "Rechecking              : " | rechecks;
     181        sout | "ns per transfer         : " | (end - start)`dms / lead_idx;
    177182
    178183
  • benchmark/readyQ/transfer.cpp

    r3613e25 r65c9208  
    1212
    1313bool exhaust = false;
     14volatile bool estop = false;
    1415
    1516bench_sem the_main;
     
    4243                                if( to_miliseconds(timeHiRes() - start) > 5'000 ) {
    4344                                        std::cerr << "Programs has been blocked for more than 5 secs" << std::endl;
    44                                         std::exit(1);
     45                                        estop = true;
     46                                        the_main.post();
     47                                        goto END;
    4548                                }
    4649                        }
    4750                }
     51                END:;
    4852                PRINT( std::cout | "Waiting done"; )
    4953        }
     
    5963        void lead() {
    6064                this->idx = ++lead_idx;
    61                 if(lead_idx > stop_count) {
     65                if(lead_idx > stop_count || estop) {
    6266                        PRINT( std::cout << "Leader " << this->id << " done" << std::endl; )
    6367                        the_main.post();
     
    8892        }
    8993
    90         static void main(void * arg) {
    91                 MyThread & self = *reinterpret_cast<MyThread*>(arg);
     94        static void main(MyThread * arg) {
     95                MyThread & self = *arg;
    9296                self.park();
    9397
     
    101105                                self.wait();
    102106                        }
    103                         if(lead_idx > stop_count) break;
     107                        if(lead_idx > stop_count || estop) break;
    104108                }
    105109        }
     
    144148                        for(size_t i = 0; i < nthreads; i++) {
    145149                                threads[i] = new MyThread( i );
    146                                 handles[i] = new Fibre( MyThread::main, threads[i] );
     150                                handles[i] = new Fibre();
     151                                handles[i]->run( MyThread::main, threads[i] );
    147152                        }
    148153
     
    164169                                PRINT( std::cout << i << " joined" << std::endl; )
    165170                                rechecks += thrd.rechecks;
    166                                 // delete( handles[i] );
    167171                                delete( threads[i] );
    168172                        }
     
    176180        std::cout << "Number of processors    : " << nprocs << std::endl;
    177181        std::cout << "Number of threads       : " << nthreads << std::endl;
    178         std::cout << "Total Operations(ops)   : " << stop_count << std::endl;
     182        std::cout << "Total Operations(ops)   : " << (lead_idx - 1) << std::endl;
    179183        std::cout << "Threads parking on wait : " << (exhaust ? "yes" : "no") << std::endl;
    180184        std::cout << "Rechecking              : " << rechecks << std::endl;
     185        std::cout << "ns per transfer         : " << std::fixed << (((double)(end - start)) / (lead_idx)) << std::endl;
    181186
    182187
  • benchmark/readyQ/transfer.go

    r3613e25 r65c9208  
    66        "math/rand"
    77        "os"
     8        "regexp"
    89        "runtime"
    910        "sync/atomic"
     
    1617        id uint64
    1718        idx uint64
     19        estop uint64
    1820        seed uint64
    1921}
     
    3436
    3537func NewLeader(size uint64) (*LeaderInfo) {
    36         this := &LeaderInfo{0, 0, uint64(os.Getpid())}
     38        this := &LeaderInfo{0, 0, 0, uint64(os.Getpid())}
    3739
    3840        r := rand.Intn(10)
     
    5153}
    5254
    53 func waitgroup(idx uint64, threads [] MyThread) {
     55func waitgroup(leader * LeaderInfo, idx uint64, threads [] MyThread, main_sem chan struct {}) {
    5456        start := time.Now()
     57        Outer:
    5558        for i := 0; i < len(threads); i++ {
    5659                // fmt.Fprintf(os.Stderr, "Waiting for :%d (%d)\n", threads[i].id, atomic.LoadUint64(&threads[i].idx) );
     
    6164                        if delta.Seconds() > 5 {
    6265                                fmt.Fprintf(os.Stderr, "Programs has been blocked for more than 5 secs")
    63                                 os.Exit(1)
     66                                atomic.StoreUint64(&leader.estop, 1);
     67                                main_sem <- (struct {}{})
     68                                break Outer
    6469                        }
    6570                }
     
    7479                if i != me {
    7580                        // 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                        }()
    7686                        threads[i].sem <- (struct {}{})
    7787                }
     
    8494        atomic.StoreUint64(&leader.idx, nidx);
    8595
    86         if nidx > stop_count {
     96        if nidx > stop_count || atomic.LoadUint64(&leader.estop) != 0 {
    8797                // debug!( "Leader {} done", this.id);
    8898                main_sem <- (struct {}{})
     
    92102        // debug!( "====================\nLeader no {} : {}", nidx, this.id);
    93103
    94         waitgroup(nidx, threads);
     104        waitgroup(leader, nidx, threads, main_sem);
    95105
    96106        leader.next( uint64(len(threads)) );
     
    146156                        waitleader( exhaust, leader, &threads[me], &r )
    147157                }
    148                 if atomic.LoadUint64(&leader.idx) > stop_count { break; }
     158                if atomic.LoadUint64(&leader.idx) > stop_count || atomic.LoadUint64(&leader.estop) != 0 { break; }
    149159        }
    150160
     
    155165func main() {
    156166        // Benchmark specific command line arguments
    157         exhaustOpt := flag.Bool("e", false, "Whether or not threads that have seen the new epoch should park instead of yielding.")
     167        exhaustOpt := flag.String("e", "no", "Whether or not threads that have seen the new epoch should park instead of yielding.")
    158168
    159169        // General benchmark initialization and deinitialization
    160         defer bench_init()()
    161 
    162         exhaust := *exhaustOpt;
     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
    163186        if clock_mode {
    164                 fmt.Fprintf(os.Stderr, "Programs does not support fixed duration mode")
     187                fmt.Fprintf(os.Stderr, "Programs does not support fixed duration mode\n")
    165188                os.Exit(1)
    166189        }
     
    215238                ws = "no"
    216239        }
    217         p.Printf("Duration (ms)           : %f\n", delta.Milliseconds() )
     240        p.Printf("Duration (ms)           : %d\n", delta.Milliseconds() )
    218241        p.Printf("Number of processors    : %d\n", nprocs )
    219242        p.Printf("Number of threads       : %d\n", nthreads )
    220         p.Printf("Total Operations(ops)   : %15d\n", stop_count )
     243        p.Printf("Total Operations(ops)   : %15d\n", (leader.idx - 1) )
    221244        p.Printf("Threads parking on wait : %s\n", ws)
    222245        p.Printf("Rechecking              : %d\n", rechecks )
    223 }
     246        p.Printf("ns per transfer         : %f\n", float64(delta.Nanoseconds()) / float64(leader.idx) )
     247}
  • benchmark/readyQ/transfer.rs

    r3613e25 r65c9208  
    66use std::hint;
    77use std::sync::Arc;
    8 use std::sync::atomic::{AtomicUsize, Ordering};
     8use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
    99use std::time::{Instant,Duration};
    1010
     
    4444                        match val {
    4545                                "yes" => true,
     46                                "Y" => true,
     47                                "y" => true,
    4648                                "no"  => false,
     49                                "N"  => false,
     50                                "n"  => false,
    4751                                "maybe" | "I don't know" | "Can you repeat the question?" => {
    4852                                        eprintln!("Lines for 'Malcolm in the Middle' are not acceptable values of parameter 'exhaust'");
     
    6468        id: AtomicUsize,
    6569        idx: AtomicUsize,
     70        estop: AtomicBool,
    6671        seed: u128,
    6772}
     
    7277                        id: AtomicUsize::new(nthreads),
    7378                        idx: AtomicUsize::new(0),
     79                        estop: AtomicBool::new(false),
    7480                        seed: process::id() as u128
    7581                };
     
    100106}
    101107
    102 fn waitgroup(idx: usize, threads: &Vec<Arc<MyThread>>) {
     108fn waitgroup(leader: &LeaderInfo, idx: usize, threads: &Vec<Arc<MyThread>>, main_sem: &sync::Semaphore) {
    103109        let start = Instant::now();
    104         for t in threads {
     110        'outer: for t in threads {
    105111                debug!( "Waiting for :{} ({})", t.id, t.idx.load(Ordering::Relaxed) );
    106112                while t.idx.load(Ordering::Relaxed) != idx {
     
    108114                        if start.elapsed() > Duration::from_secs(5) {
    109115                                eprintln!("Programs has been blocked for more than 5 secs");
    110                                 std::process::exit(1);
     116                                leader.estop.store(true, Ordering::Relaxed);
     117                                main_sem.add_permits(1);
     118                                break 'outer;
    111119                        }
    112120                }
     
    131139        leader.idx.store(nidx, Ordering::Relaxed);
    132140
    133         if nidx as u64 > exp.stop_count {
     141        if nidx as u64 > exp.stop_count || leader.estop.load(Ordering::Relaxed) {
    134142                debug!( "Leader {} done", this.id);
    135143                main_sem.add_permits(1);
     
    139147        debug!( "====================\nLeader no {} : {}", nidx, this.id);
    140148
    141         waitgroup(nidx, threads);
     149        waitgroup(leader, nidx, threads, main_sem);
    142150
    143151        leader.next( threads.len() );
     
    192200                        wait( exhaust, &leader, &threads[me], &mut rechecks ).await;
    193201                }
    194                 if leader.idx.load(Ordering::Relaxed) as u64 > exp.stop_count { break; }
     202                if leader.idx.load(Ordering::Relaxed) as u64 > exp.stop_count || leader.estop.load(Ordering::Relaxed) { break; }
    195203        }
    196204
     
    273281        println!("Number of processors    : {}", (nprocs).to_formatted_string(&Locale::en));
    274282        println!("Number of threads       : {}", (nthreads).to_formatted_string(&Locale::en));
    275         println!("Total Operations(ops)   : {:>15}", (exp.stop_count).to_formatted_string(&Locale::en));
     283        println!("Total Operations(ops)   : {:>15}", (leader.idx.load(Ordering::Relaxed) - 1).to_formatted_string(&Locale::en));
    276284        println!("Threads parking on wait : {}", if exhaust { "yes" } else { "no" });
    277285        println!("Rechecking              : {}", rechecks );
    278 }
     286        println!("ns per transfer         : {}", ((duration.as_nanos() as f64) / leader.idx.load(Ordering::Relaxed) as f64));
     287
     288}
Note: See TracChangeset for help on using the changeset viewer.