Changeset 69d1748
- Timestamp:
- Nov 18, 2020, 4:34:08 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:
- 7c9ac4a
- Parents:
- 3ea8ad1
- Location:
- benchmark/readyQ
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
benchmark/readyQ/cycle.cfa
r3ea8ad1 r69d1748 77 77 78 78 for(i; tthreads) { 79 post( thddata[i].self ); 79 80 Partner & partner = join( *threads[i] ).partner; 80 81 global_counter += partner.count; -
benchmark/readyQ/cycle.cpp
r3ea8ad1 r69d1748 1 1 2 2 #include "rq_bench.hpp" 3 #include <libfibre/fibre.h> 3 4 5 class __attribute__((aligned(128))) bench_sem { 6 Fibre * volatile ptr = nullptr; 7 public: 8 inline bool wait() { 9 static Fibre * const ready = reinterpret_cast<Fibre * const>(1ull); 10 for(;;) { 11 Fibre * expected = this->ptr; 12 if(expected == ready) { 13 if(__atomic_compare_exchange_n(&this->ptr, &expected, nullptr, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) { 14 return false; 15 } 16 } 17 else { 18 /* paranoid */ assert( expected == nullptr ); 19 if(__atomic_compare_exchange_n(&this->ptr, &expected, fibre_self(), false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) { 20 fibre_park(); 21 return true; 22 } 23 } 24 25 } 26 } 27 28 inline bool post() { 29 static Fibre * const ready = reinterpret_cast<Fibre * const>(1ull); 30 for(;;) { 31 Fibre * expected = this->ptr; 32 if(expected == ready) return false; 33 if(expected == nullptr) { 34 if(__atomic_compare_exchange_n(&this->ptr, &expected, ready, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) { 35 return false; 36 } 37 } 38 else { 39 if(__atomic_compare_exchange_n(&this->ptr, &expected, nullptr, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) { 40 fibre_unpark( expected ); 41 return true; 42 } 43 } 44 } 45 } 46 }; 4 47 struct Partner { 5 48 unsigned long long count = 0; … … 55 98 thddata[i].self.post(); 56 99 } 57 wait (start, is_tty);100 wait<Fibre>(start, is_tty); 58 101 59 102 stop = true; … … 62 105 63 106 for(int i = 0; i < tthreads; i++) { 107 thddata[i].self.post(); 64 108 fibre_join( threads[i], nullptr ); 65 109 global_counter += thddata[i].count; -
benchmark/readyQ/cycle.go
r3ea8ad1 r69d1748 63 63 global_counter := uint64(0) 64 64 for i := 0; i < tthreads; i++ { 65 select { 66 case channels[i] <- 0: 67 default: 68 } 65 69 global_counter += <- result 66 70 }
Note: See TracChangeset
for help on using the changeset viewer.