Changes in / [9344f0e:6645cda]
- Location:
- doc/theses/thierry_delisle_PhD/code/readyQ_proto
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/thierry_delisle_PhD/code/readyQ_proto/utils.hpp
r9344f0e r6645cda 11 11 #include <sys/sysinfo.h> 12 12 13 //#include <x86intrin.h>13 #include <x86intrin.h> 14 14 15 15 // class Random { -
doc/theses/thierry_delisle_PhD/code/readyQ_proto/work_stealing.hpp
r9344f0e r6645cda 15 15 #include "snzi.hpp" 16 16 17 //#include <x86intrin.h>17 #include <x86intrin.h> 18 18 19 19 using namespace std; … … 28 28 template<typename node_t> 29 29 struct __attribute__((aligned(128))) localQ_t { 30 // volatile unsigned long long val = 0; 31 // mpsc_queue<node_t> queue = {}; 32 // spinlock_t lock = {}; 33 intrusive_queue_t<node_t> list; 34 35 inline auto ts() { return list.ts(); } 36 inline auto lock() { return list.lock.lock(); } 37 inline auto try_lock() { return list.lock.try_lock(); } 38 inline auto unlock() { return list.lock.unlock(); } 39 40 inline auto push( node_t * node ) { return list.push( node ); } 41 inline auto pop() { return list.pop(); } 30 mpsc_queue<node_t> queue = {}; 31 spinlock_t lock = {}; 32 bool needs_help = true; 42 33 }; 43 34 … … 53 44 work_stealing(unsigned _numThreads, unsigned) 54 45 : numThreads(_numThreads * nqueues) 55 , lists(new localQ_t<node_t>[numThreads]) 56 // , lists(new intrusive_queue_t<node_t>[numThreads]) 46 , lists(new intrusive_queue_t<node_t>[numThreads]) 57 47 , times(new timestamp_t[numThreads]) 58 48 // , snzi( std::log2( numThreads / 2 ), 2 ) … … 68 58 69 59 __attribute__((noinline, hot)) void push(node_t * node) { 70 node->_links.ts = rdtscl();71 //node->_links.ts = 1;60 // node->_links.ts = rdtscl(); 61 node->_links.ts = 1; 72 62 73 63 auto & list = *({ … … 82 72 i = tls.my_queue + (r % nqueues); 83 73 } 84 } while(!lists[i]. try_lock());74 } while(!lists[i].lock.try_lock()); 85 75 &lists[i]; 86 76 }); 87 77 88 78 list.push( node ); 89 list. unlock();79 list.lock.unlock(); 90 80 // tls.rng2.set_raw_state( tls.rng1.get_raw_state()); 91 81 // count++; … … 94 84 95 85 __attribute__((noinline, hot)) node_t * pop() { 86 if( tls.myfriend == outside ) { 87 auto r = tls.rng1.next(); 88 tls.myfriend = r % numThreads; 89 times[tls.myfriend].val = 0; 90 } 91 else if(times[tls.myfriend].val == 0) { 92 node_t * n = try_pop(tls.myfriend, tls.stats.pop.help); 93 tls.stats.help++; 94 tls.myfriend = outside; 95 if(n) return n; 96 } 97 96 98 if(tls.my_queue != outside) { 97 if( tls.myfriend == outside ) {98 auto r = tls.rng1.next();99 tls.myfriend = r % numThreads;100 tls.mytime = lists[(tls.it % nqueues) + tls.my_queue].ts();101 // times[tls.myfriend].val = 0;102 // lists[tls.myfriend].val = 0;103 }104 // else if(times[tls.myfriend].val == 0) {105 // else if(lists[tls.myfriend].val == 0) {106 else if(times[tls.myfriend].val < tls.mytime) {107 // else if(times[tls.myfriend].val < lists[(tls.it % nqueues) + tls.my_queue].ts()) {108 node_t * n = try_pop(tls.myfriend, tls.stats.pop.help);109 tls.stats.help++;110 tls.myfriend = outside;111 if(n) return n;112 }113 // if( tls.myfriend == outside ) {114 // auto r = tls.rng1.next();115 // tls.myfriend = r % numThreads;116 // tls.mytime = lists[((tls.it + 1) % nqueues) + tls.my_queue].ts();117 // }118 // else {119 // if(times[tls.myfriend].val + 1000 < tls.mytime) {120 // node_t * n = try_pop(tls.myfriend, tls.stats.pop.help);121 // tls.stats.help++;122 // if(n) return n;123 // }124 // tls.myfriend = outside;125 // }126 127 99 node_t * n = local(); 128 100 if(n) return n; … … 140 112 private: 141 113 inline node_t * local() { 114 // unsigned i = (tls.rng2.prev() % 4) + tls.my_queue; 142 115 unsigned i = (--tls.it % nqueues) + tls.my_queue; 143 116 return try_pop(i, tls.stats.pop.local); … … 180 153 181 154 // If we can't get the lock, move on 182 if( !list.try_lock() ) { stat.elock++; return nullptr; } 155 if( !list.lock.try_lock() ) { stat.elock++; return nullptr; } 156 183 157 184 158 // If list is empty, unlock and retry 185 159 if( list.ts() == 0 ) { 186 list. unlock();160 list.lock.unlock(); 187 161 stat.eempty++; 188 162 return nullptr; … … 190 164 191 165 auto node = list.pop(); 192 list. unlock();166 list.lock.unlock(); 193 167 stat.success++; 194 // times[i].val = 1;195 times[i].val = node.first->_links.ts;196 // lists[i].val = node.first->_links.ts;168 times[i].val = 1; //node.first->_links.ts; 169 // count--; 170 // _mm_stream_si64((long long int*)×[i].val, node.first->_links.ts); 197 171 return node.first; 198 172 } … … 217 191 unsigned my_queue = calc_preferred(); 218 192 unsigned myfriend = outside; 219 unsigned long long int mytime = 0;220 193 #if defined(READ) 221 194 unsigned it = 0; … … 238 211 private: 239 212 const unsigned numThreads; 240 std::unique_ptr<localQ_t<node_t> []> lists; 241 // std::unique_ptr<intrusive_queue_t<node_t> []> lists; 213 std::unique_ptr<intrusive_queue_t<node_t> []> lists; 242 214 std::unique_ptr<timestamp_t []> times; 243 215 __attribute__((aligned(128))) std::atomic_size_t count;
Note: See TracChangeset
for help on using the changeset viewer.