Changeset 0b84b15
- Timestamp:
- Oct 29, 2020, 3:33:45 PM (4 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 93068e53
- Parents:
- b35ab2d
- Location:
- benchmark/readyQ
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
benchmark/readyQ/cycle.cfa
rb35ab2d r0b84b15 4 4 Partner * partner; 5 5 unsigned long long count; 6 bool first;7 6 }; 8 7 … … 12 11 13 12 void main( Partner & this ) { 14 thread_loop { 13 this.count = 0; 14 for() { 15 15 park(); 16 16 unpark( *this.partner ); 17 this.count ++; 18 if( clock_mode && stop) break; 19 if(!clock_mode && this.count >= stop_count) break; 17 20 } 18 21 19 22 __atomic_fetch_add(&threads_left, -1, __ATOMIC_SEQ_CST); 20 21 if(this.first) park();22 23 } 23 24 … … 41 42 unsigned pi = (i + nthreads) % tthreads; 42 43 threads[i].partner = &threads[pi]; 43 threads[i].first = i < nthreads;44 44 } 45 45 printf("Starting\n"); … … 51 51 unpark( threads[i] ); 52 52 } 53 wait(start, end,is_tty);53 wait(start, is_tty); 54 54 55 55 stop = true; -
benchmark/readyQ/cycle.go
rb35ab2d r0b84b15 1 package main 2 3 import ( 4 "bufio" 5 "flag" 6 "fmt" 7 "os" 8 "runtime" 9 "sync/atomic" 10 "time" 11 "golang.org/x/text/language" 12 "golang.org/x/text/message" 13 ) 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 } 44 45 func partner(result chan uint64, mine chan int, next chan int) { 46 count := uint64(0) 47 for true { 48 <- mine 49 next <- 0 50 count += 1 51 if clock_mode && atomic.LoadInt32(&stop) == 1 { break } 52 if !clock_mode && count >= stop_count { break } 53 } 54 55 atomic.AddInt64(&threads_left, -1); 56 result <- count 57 } 58 59 func main() { 60 var nprocs int 61 var nthreads int 62 var ring_size int 63 64 nprocsOpt := flag.Int("p", 1, "The number of processors") 65 nthreadsOpt := flag.Int("t", 1, "The number of threads") 66 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") 69 70 flag.Parse() 71 72 nprocs = *nprocsOpt 73 nthreads = *nthreadsOpt 74 ring_size = *ring_sizeOpt 75 duration = *durationOpt 76 stop_count = *stopOpt 77 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) 94 tthreads := nthreads * ring_size 95 threads_left = int64(tthreads) 96 97 result := make(chan uint64) 98 channels := make([]chan int, tthreads) 99 for i := range channels { 100 channels[i] = make(chan int, 1) 101 } 102 103 for i := 0; i < tthreads; i++ { 104 pi := (i + nthreads) % tthreads 105 go partner(result, channels[i], channels[pi]) 106 } 107 fmt.Printf("Starting\n"); 108 109 atomic.StoreInt32(&stop, 0) 110 start := time.Now() 111 for i := 0; i < nthreads; i++ { 112 channels[i] <- 0 113 } 114 wait(start, true); 115 116 atomic.StoreInt32(&stop, 1) 117 end := time.Now() 118 delta := end.Sub(start) 119 120 fmt.Printf("\nDone\n") 121 122 global_counter := uint64(0) 123 for i := 0; i < tthreads; i++ { 124 global_counter += <- result 125 } 126 127 p := message.NewPrinter(language.English) 128 p.Printf("Took %f ms\n", delta.Seconds()) 129 p.Printf("Yields per second : %18.2f\n", float64(global_counter) / delta.Seconds()) 130 p.Printf("ns per yields : %18.2f\n", float64(delta.Nanoseconds()) / float64(global_counter)) 131 p.Printf("Total yields : %15d\n", global_counter) 132 p.Printf("Yields per threads : %15d\n", global_counter / uint64(tthreads)) 133 p.Printf("Yields per procs : %15d\n", global_counter / uint64(nprocs)) 134 p.Printf("Yields/sec/procs : %18.2f\n", (float64(global_counter) / float64(nprocs)) / delta.Seconds()) 135 p.Printf("ns per yields/procs : %18.2f\n", float64(delta.Nanoseconds()) / (float64(global_counter) / float64(nprocs))) 136 137 } -
benchmark/readyQ/rq_bench.hfa
rb35ab2d r0b84b15 17 17 volatile unsigned long long threads_left; 18 18 19 #define thread_loop for(this.count = 0; this.count < stop_count && !stop; this.count++)19 #define thread_loop for(this.count = 0;; this.count++) 20 20 21 21 #define BENCH_OPT \ … … 36 36 clock_mode = true; \ 37 37 stop_count = 0xFFFFFFFFFFFFFFFF; \ 38 printf("Running for %lf seconds\n", duration); \ 38 39 } else if(stop_count > 0) { \ 39 40 clock_mode = false; \ 41 printf("Running for %lu iterations\n", stop_count); \ 40 42 } else { \ 41 43 duration = 5; clock_mode = true;\ 44 printf("Running for %lf seconds\n", duration); \ 42 45 } \ 43 46 } … … 67 70 } 68 71 69 void wait( Time & start, Time & end, bool is_tty) {72 void wait(const Time & start, bool is_tty) { 70 73 for() { 71 74 sleep(100`ms); 72 end = getTimeNsec();75 Time end = getTimeNsec(); 73 76 Duration delta = end - start; 74 77 if(is_tty) {
Note: See TracChangeset
for help on using the changeset viewer.