OLD | NEW |
1 //===- subzero/crosstest/test_sync_atomic_main.cpp - Driver for tests -----===// | 1 //===- subzero/crosstest/test_sync_atomic_main.cpp - Driver for tests -----===// |
2 // | 2 // |
3 // The Subzero Code Generator | 3 // The Subzero Code Generator |
4 // | 4 // |
5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
7 // | 7 // |
8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
9 // | 9 // |
10 // Driver for cross testing atomic intrinsics, via the sync builtins. | 10 // Driver for cross testing atomic intrinsics, via the sync builtins. |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 static const size_t NumReps = 8000; | 169 static const size_t NumReps = 8000; |
170 #endif // ARM32 | 170 #endif // ARM32 |
171 | 171 |
172 ThreadData<Type> *TData = reinterpret_cast<ThreadData<Type> *>(Data); | 172 ThreadData<Type> *TData = reinterpret_cast<ThreadData<Type> *>(Data); |
173 for (size_t i = 0; i < NumReps; ++i) { | 173 for (size_t i = 0; i < NumReps; ++i) { |
174 (void)TData->FuncPtr(TData->Fetch, TData->Ptr, TData->Adjustment); | 174 (void)TData->FuncPtr(TData->Fetch, TData->Ptr, TData->Adjustment); |
175 } | 175 } |
176 return NULL; | 176 return NULL; |
177 } | 177 } |
178 | 178 |
179 #ifndef X8664_STACK_HACK | |
180 void AllocStackForThread(uint32, pthread_attr_t *) {} | |
181 #else // defined(X8664_STACK_HACK) | |
182 void AllocStackForThread(uint32 m, pthread_attr_t *attr) { | |
183 static const uint32_t ThreadStackBase = 0x60000000; | |
184 static const uint32_t ThreadStackSize = 4 << 20; // 4MB. | |
185 if (pthread_attr_setstack( | |
186 attr, xAllocStack(ThreadStackBase - 2 * m * ThreadStackSize, | |
187 ThreadStackSize), | |
188 ThreadStackSize) != 0) { | |
189 std::cout << "pthread_attr_setstack: " << strerror(errno) << "\n"; | |
190 abort(); | |
191 } | |
192 } | |
193 #endif // X8664_STACK_HACK | |
194 | |
195 template <typename Type> | 179 template <typename Type> |
196 void testAtomicRMWThreads(volatile Type *AtomicLoc, size_t &TotalTests, | 180 void testAtomicRMWThreads(volatile Type *AtomicLoc, size_t &TotalTests, |
197 size_t &Passes, size_t &Failures) { | 181 size_t &Passes, size_t &Failures) { |
198 typedef Type (*FuncType)(bool, volatile Type *, Type); | 182 typedef Type (*FuncType)(bool, volatile Type *, Type); |
199 static struct { | 183 static struct { |
200 const char *Name; | 184 const char *Name; |
201 FuncType FuncLlc; | 185 FuncType FuncLlc; |
202 FuncType FuncSz; | 186 FuncType FuncSz; |
203 } Funcs[] = { | 187 } Funcs[] = { |
204 #define X(inst) \ | 188 #define X(inst) \ |
(...skipping 20 matching lines...) Expand all Loading... |
225 Value2}; | 209 Value2}; |
226 ++TotalTests; | 210 ++TotalTests; |
227 const size_t NumThreads = 4; | 211 const size_t NumThreads = 4; |
228 pthread_t t[NumThreads]; | 212 pthread_t t[NumThreads]; |
229 pthread_attr_t attr[NumThreads]; | 213 pthread_attr_t attr[NumThreads]; |
230 | 214 |
231 // Try N threads w/ just Llc. | 215 // Try N threads w/ just Llc. |
232 *AtomicLoc = Value1; | 216 *AtomicLoc = Value1; |
233 for (size_t m = 0; m < NumThreads; ++m) { | 217 for (size_t m = 0; m < NumThreads; ++m) { |
234 pthread_attr_init(&attr[m]); | 218 pthread_attr_init(&attr[m]); |
235 AllocStackForThread(m, &attr[m]); | |
236 if (pthread_create(&t[m], &attr[m], &threadWrapper<Type>, | 219 if (pthread_create(&t[m], &attr[m], &threadWrapper<Type>, |
237 reinterpret_cast<void *>(&TDataLlc)) != 0) { | 220 reinterpret_cast<void *>(&TDataLlc)) != 0) { |
238 std::cout << "pthread_create failed w/ " << strerror(errno) << "\n"; | 221 std::cout << "pthread_create failed w/ " << strerror(errno) << "\n"; |
239 abort(); | 222 abort(); |
240 } | 223 } |
241 } | 224 } |
242 for (size_t m = 0; m < NumThreads; ++m) { | 225 for (size_t m = 0; m < NumThreads; ++m) { |
243 pthread_join(t[m], NULL); | 226 pthread_join(t[m], NULL); |
244 } | 227 } |
245 Type ResultLlc = *AtomicLoc; | 228 Type ResultLlc = *AtomicLoc; |
246 | 229 |
247 // Try N threads w/ both Sz and Llc. | 230 // Try N threads w/ both Sz and Llc. |
248 *AtomicLoc = Value1; | 231 *AtomicLoc = Value1; |
249 for (size_t m = 0; m < NumThreads; ++m) { | 232 for (size_t m = 0; m < NumThreads; ++m) { |
250 pthread_attr_init(&attr[m]); | 233 pthread_attr_init(&attr[m]); |
251 AllocStackForThread(m, &attr[m]); | |
252 if (pthread_create(&t[m], &attr[m], &threadWrapper<Type>, | 234 if (pthread_create(&t[m], &attr[m], &threadWrapper<Type>, |
253 m % 2 == 0 | 235 m % 2 == 0 |
254 ? reinterpret_cast<void *>(&TDataLlc) | 236 ? reinterpret_cast<void *>(&TDataLlc) |
255 : reinterpret_cast<void *>(&TDataSz)) != 0) { | 237 : reinterpret_cast<void *>(&TDataSz)) != 0) { |
256 ++Failures; | 238 ++Failures; |
257 std::cout << "pthread_create failed w/ " << strerror(errno) << "\n"; | 239 std::cout << "pthread_create failed w/ " << strerror(errno) << "\n"; |
258 abort(); | 240 abort(); |
259 } | 241 } |
260 } | 242 } |
261 for (size_t m = 0; m < NumThreads; ++m) { | 243 for (size_t m = 0; m < NumThreads; ++m) { |
(...skipping 13 matching lines...) Expand all Loading... |
275 << (8 * sizeof(Type)) << "(" << static_cast<uint64>(Value1) | 257 << (8 * sizeof(Type)) << "(" << static_cast<uint64>(Value1) |
276 << ", " << static_cast<uint64>(Value2) | 258 << ", " << static_cast<uint64>(Value2) |
277 << "): llc=" << static_cast<uint64>(ResultLlc) | 259 << "): llc=" << static_cast<uint64>(ResultLlc) |
278 << " mixed=" << static_cast<uint64>(ResultMixed) << "\n"; | 260 << " mixed=" << static_cast<uint64>(ResultMixed) << "\n"; |
279 } | 261 } |
280 } | 262 } |
281 } | 263 } |
282 } | 264 } |
283 } | 265 } |
284 | 266 |
285 #ifdef X8664_STACK_HACK | |
286 extern "C" int wrapped_main(int argc, char *argv[]) { | |
287 #else // !defined(X8664_STACK_HACK) | |
288 int main(int argc, char *argv[]) { | 267 int main(int argc, char *argv[]) { |
289 #endif // X8664_STACK_HACK | |
290 size_t TotalTests = 0; | 268 size_t TotalTests = 0; |
291 size_t Passes = 0; | 269 size_t Passes = 0; |
292 size_t Failures = 0; | 270 size_t Failures = 0; |
293 | 271 |
294 testAtomicRMW<uint8_t>(&AtomicLocs.l8, TotalTests, Passes, Failures); | 272 testAtomicRMW<uint8_t>(&AtomicLocs.l8, TotalTests, Passes, Failures); |
295 testAtomicRMW<uint16_t>(&AtomicLocs.l16, TotalTests, Passes, Failures); | 273 testAtomicRMW<uint16_t>(&AtomicLocs.l16, TotalTests, Passes, Failures); |
296 testAtomicRMW<uint32_t>(&AtomicLocs.l32, TotalTests, Passes, Failures); | 274 testAtomicRMW<uint32_t>(&AtomicLocs.l32, TotalTests, Passes, Failures); |
297 testAtomicRMW<uint64>(&AtomicLocs.l64, TotalTests, Passes, Failures); | 275 testAtomicRMW<uint64>(&AtomicLocs.l64, TotalTests, Passes, Failures); |
298 testValCompareAndSwap<uint8_t>(&AtomicLocs.l8, TotalTests, Passes, Failures); | 276 testValCompareAndSwap<uint8_t>(&AtomicLocs.l8, TotalTests, Passes, Failures); |
299 testValCompareAndSwap<uint16_t>(&AtomicLocs.l16, TotalTests, Passes, | 277 testValCompareAndSwap<uint16_t>(&AtomicLocs.l16, TotalTests, Passes, |
300 Failures); | 278 Failures); |
301 testValCompareAndSwap<uint32_t>(&AtomicLocs.l32, TotalTests, Passes, | 279 testValCompareAndSwap<uint32_t>(&AtomicLocs.l32, TotalTests, Passes, |
302 Failures); | 280 Failures); |
303 testValCompareAndSwap<uint64>(&AtomicLocs.l64, TotalTests, Passes, Failures); | 281 testValCompareAndSwap<uint64>(&AtomicLocs.l64, TotalTests, Passes, Failures); |
304 testAtomicRMWThreads<uint8_t>(&AtomicLocs.l8, TotalTests, Passes, Failures); | 282 testAtomicRMWThreads<uint8_t>(&AtomicLocs.l8, TotalTests, Passes, Failures); |
305 testAtomicRMWThreads<uint16_t>(&AtomicLocs.l16, TotalTests, Passes, Failures); | 283 testAtomicRMWThreads<uint16_t>(&AtomicLocs.l16, TotalTests, Passes, Failures); |
306 testAtomicRMWThreads<uint32_t>(&AtomicLocs.l32, TotalTests, Passes, Failures); | 284 testAtomicRMWThreads<uint32_t>(&AtomicLocs.l32, TotalTests, Passes, Failures); |
307 testAtomicRMWThreads<uint64>(&AtomicLocs.l64, TotalTests, Passes, Failures); | 285 testAtomicRMWThreads<uint64>(&AtomicLocs.l64, TotalTests, Passes, Failures); |
308 | 286 |
309 std::cout << "TotalTests=" << TotalTests << " Passes=" << Passes | 287 std::cout << "TotalTests=" << TotalTests << " Passes=" << Passes |
310 << " Failures=" << Failures << "\n"; | 288 << " Failures=" << Failures << "\n"; |
311 return Failures; | 289 return Failures; |
312 } | 290 } |
OLD | NEW |