ADTast-experimental
Last change
on this file since 119e6c8 was
6e6989c,
checked in by caparsons <caparson@…>, 17 months ago
|
added mutex stmt benchmarking
|
-
Property mode set to
100644
|
File size:
1.5 KB
|
Rev | Line | |
---|
[6e6989c] | 1 | #pragma once |
---|
| 2 | |
---|
| 3 | #if defined(__cforall) |
---|
| 4 | extern "C" { |
---|
| 5 | #endif |
---|
| 6 | #include <stdlib.h> |
---|
| 7 | #include <stdint.h> // uint64_t |
---|
| 8 | #include <unistd.h> // sysconf |
---|
| 9 | #if ! defined(__cforall) |
---|
| 10 | #include <time.h> |
---|
| 11 | #include <sys/time.h> |
---|
| 12 | #else |
---|
| 13 | } |
---|
| 14 | #include <time.hfa> |
---|
| 15 | #endif |
---|
| 16 | |
---|
| 17 | #define L1 l1 |
---|
| 18 | #define L2 L1, l2 |
---|
| 19 | #define L3 L2, l3 |
---|
| 20 | #define L4 L3, l4 |
---|
| 21 | #define L5 L4, l5 |
---|
| 22 | #define L6 L5, l6 |
---|
| 23 | #define L7 L6, l7 |
---|
| 24 | #define L8 L7, l8 |
---|
| 25 | |
---|
| 26 | static inline uint64_t bench_time() { |
---|
| 27 | struct timespec ts; |
---|
| 28 | clock_gettime( CLOCK_THREAD_CPUTIME_ID, &ts ); |
---|
| 29 | return 1000000000LL * ts.tv_sec + ts.tv_nsec; |
---|
| 30 | } // bench_time |
---|
| 31 | |
---|
| 32 | |
---|
| 33 | #if defined(__cforall) |
---|
| 34 | struct test_spinlock { |
---|
| 35 | volatile bool lock; |
---|
| 36 | }; |
---|
| 37 | |
---|
| 38 | static inline void lock( test_spinlock & this ) { |
---|
| 39 | for ( ;; ) { |
---|
| 40 | if ( (this.lock == 0) && (__atomic_test_and_set( &this.lock, __ATOMIC_ACQUIRE ) == 0) ) break; |
---|
| 41 | } |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | static inline void unlock( test_spinlock & this ) { |
---|
| 45 | __atomic_clear( &this.lock, __ATOMIC_RELEASE ); |
---|
| 46 | } |
---|
| 47 | #endif |
---|
| 48 | |
---|
| 49 | size_t threads = 1; |
---|
| 50 | |
---|
| 51 | #define BENCH_START() \ |
---|
| 52 | if ( argc > 2 ) exit( EXIT_FAILURE ); \ |
---|
| 53 | if ( argc == 2 ) { \ |
---|
| 54 | threads = atoi( argv[1] ); \ |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | #define BENCH(statement, output, done_flag) \ |
---|
| 58 | uint64_t count = 0; \ |
---|
| 59 | while (true) { \ |
---|
| 60 | statement; \ |
---|
| 61 | count++; \ |
---|
| 62 | if (done_flag) break; \ |
---|
| 63 | } \ |
---|
| 64 | __atomic_add_fetch(&output, count, __ATOMIC_SEQ_CST); |
---|
| 65 | // EndTime = bench_time(); \ |
---|
| 66 | // double output = (double)( EndTime - StartTime ) / times; |
---|
| 67 | |
---|
| 68 | |
---|
| 69 | #if defined(__cforall) |
---|
| 70 | Duration default_preemption() { |
---|
| 71 | return 0; |
---|
| 72 | } |
---|
| 73 | #endif |
---|
| 74 | #if defined(__U_CPLUSPLUS__) |
---|
| 75 | unsigned int uDefaultPreemption() { |
---|
| 76 | return 0; |
---|
| 77 | } |
---|
| 78 | #endif |
---|
Note: See
TracBrowser
for help on using the repository browser.