- Timestamp:
- Sep 26, 2019, 4:25:04 PM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 1e24d13
- Parents:
- b2a37b0
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/thierry_delisle_PhD/code/processor_list_fast.cpp
rb2a37b0 r50aeb6f 19 19 unsigned id; 20 20 }; 21 void run(unsigned nthread, double duration, unsigned writes ) {21 void run(unsigned nthread, double duration, unsigned writes, unsigned epochs) { 22 22 assert(writes < 100); 23 23 … … 30 30 // Data to check everything is OK 31 31 size_t write_committed = 0ul; 32 std::atomic_size_t lock_cnt_write = { 0ul }; 33 std::atomic_size_t lock_cnt_read = { 0ul }; 32 struct { 33 std::atomic_size_t write = { 0ul }; 34 std::atomic_size_t read = { 0ul }; 35 std::atomic_size_t epoch = { 0ul }; 36 } lock_cnt; 34 37 35 38 // Flag to signal termination … … 39 42 unsigned i = 1; 40 43 for(auto & t : threads) { 41 t = new std::thread([&done, &list, &barrier, &write_committed, &lock_cnt _write, &lock_cnt_read, writes](unsigned tid) {44 t = new std::thread([&done, &list, &barrier, &write_committed, &lock_cnt, writes, epochs](unsigned tid) { 42 45 Random rand(tid + rdtscl()); 43 46 processor proc; … … 45 48 size_t writes_cnt = 0; 46 49 size_t reads_cnt = 0; 50 size_t epoch_cnt = 0; 47 51 48 52 affinity(tid); … … 51 55 52 56 while(__builtin_expect(!done, true)) { 53 if ((rand.next() % 100) < writes) { 57 auto r = rand.next() % 100; 58 if (r < writes) { 54 59 auto n = list.write_lock(); 55 60 write_committed++; … … 57 62 assert(writes_cnt < -2ul); 58 63 list.write_unlock(n); 64 } 65 else if(r < epochs) { 66 list.epoch_check(); 67 epoch_cnt++; 59 68 } 60 69 else { … … 70 79 auto p = list.unregister(proc.id); 71 80 assert(&proc == p); 72 lock_cnt_write += writes_cnt; 73 lock_cnt_read += reads_cnt; 81 lock_cnt.write += writes_cnt; 82 lock_cnt.read += reads_cnt; 83 lock_cnt.epoch += epoch_cnt; 74 84 }, i++); 75 85 } … … 98 108 } 99 109 100 assert(write_committed == lock_cnt _write);110 assert(write_committed == lock_cnt.write); 101 111 102 size_t ops_sec = size_t(double(lock_cnt_read + lock_cnt_write) / duration); 112 size_t totalop = lock_cnt.read + lock_cnt.write + lock_cnt.epoch; 113 size_t ops_sec = size_t(double(totalop) / duration); 103 114 size_t ops_thread = ops_sec / nthread; 104 115 double dur_nano = duration_cast<std::nano>(1.0); 105 116 106 117 std::cout << "Duration : " << duration << "s\n"; 107 std::cout << "Total ops : " << (lock_cnt_read + lock_cnt_write) << "(" << lock_cnt_read << "r, " << lock_cnt_write << "w)\n";118 std::cout << "Total ops : " << totalop << "(" << lock_cnt.read << "r, " << lock_cnt.write << "w, " << lock_cnt.epoch << "e)\n"; 108 119 std::cout << "Ops/sec : " << ops_sec << "\n"; 109 120 std::cout << "Ops/sec/thread: " << ops_thread << "\n"; … … 121 132 unsigned nthreads = 2; 122 133 unsigned writes = 0; 134 unsigned epochs = 0; 123 135 124 136 std::cout.imbue(std::locale("")); … … 126 138 switch (argc) 127 139 { 140 case 5: 141 epochs = std::stoul(argv[4]); 142 [[fallthrough]]; 128 143 case 4: 129 144 writes = std::stoul(argv[3]); 130 if( writes >=100 ) {131 std::cerr << "Writes must be valid percentage, was " << argv[3] << "(" << writes << ")" << std::endl;145 if( (writes + epochs) > 100 ) { 146 std::cerr << "Writes + Epochs must be valid percentage, was " << argv[3] << " + " << argv[4] << "(" << writes << " + " << epochs << ")" << std::endl; 132 147 usage(argv); 133 148 } … … 152 167 check_cache_line_size(); 153 168 154 std::cout << "Running " << nthreads << " threads for " << duration << " seconds with " << writes << "% writes " << std::endl;155 run(nthreads, duration, writes );169 std::cout << "Running " << nthreads << " threads for " << duration << " seconds with " << writes << "% writes and " << epochs << "% epochs" << std::endl; 170 run(nthreads, duration, writes, epochs + writes); 156 171 157 172 return 0;
Note: See TracChangeset
for help on using the changeset viewer.