X-Git-Url: http://git.liburcu.org/?a=blobdiff_plain;f=tests%2Ftest_perthreadlock_timing.c;h=d0cc11c3841df70e08a1718417cc9e9c134d1116;hb=372b9ad7acc40810bbcec6a796c71b54901b3ca7;hp=9eb1c1357b65c84fe833a16a1a1c991889d3ebc6;hpb=6982d6d71aeed16d2d929bd0ed221e8f444b706e;p=urcu.git diff --git a/tests/test_perthreadlock_timing.c b/tests/test_perthreadlock_timing.c index 9eb1c13..d0cc11c 100644 --- a/tests/test_perthreadlock_timing.c +++ b/tests/test_perthreadlock_timing.c @@ -29,12 +29,15 @@ #include #include #include -#include #include #include #include +#ifdef __linux__ +#include +#endif + #if defined(_syscall0) _syscall0(pid_t, gettid) #elif defined(__NR_gettid) @@ -60,7 +63,7 @@ static struct test_array test_array = { 8 }; struct per_thread_lock { pthread_mutex_t lock; -} __attribute__((aligned(CACHE_LINE_SIZE))); /* cache-line aligned */ +} __attribute__((aligned(CAA_CACHE_LINE_SIZE))); /* cache-line aligned */ static struct per_thread_lock *per_thread_lock; @@ -78,8 +81,8 @@ static int num_write; #define NR_READ num_read #define NR_WRITE num_write -static cycles_t __attribute__((aligned(CACHE_LINE_SIZE))) *reader_time; -static cycles_t __attribute__((aligned(CACHE_LINE_SIZE))) *writer_time; +static cycles_t __attribute__((aligned(CAA_CACHE_LINE_SIZE))) *reader_time; +static cycles_t __attribute__((aligned(CAA_CACHE_LINE_SIZE))) *writer_time; void *thr_reader(void *arg) { @@ -88,10 +91,11 @@ void *thr_reader(void *arg) long tidx = (long)arg; printf("thread_begin %s, thread id : %lx, tid %lu\n", - "reader", pthread_self(), (unsigned long)gettid()); + "reader", (unsigned long) pthread_self(), + (unsigned long) gettid()); sleep(2); - time1 = get_cycles(); + time1 = caa_get_cycles(); for (i = 0; i < OUTER_READ_LOOP; i++) { for (j = 0; j < INNER_READ_LOOP; j++) { pthread_mutex_lock(&per_thread_lock[tidx].lock); @@ -99,13 +103,14 @@ void *thr_reader(void *arg) pthread_mutex_unlock(&per_thread_lock[tidx].lock); } } - time2 = get_cycles(); + time2 = caa_get_cycles(); reader_time[tidx] = time2 - time1; sleep(2); printf("thread_end %s, thread id : %lx, tid %lu\n", - "reader", pthread_self(), (unsigned long)gettid()); + "reader", (unsigned long) pthread_self(), + (unsigned long) gettid()); return ((void*)1); } @@ -117,12 +122,13 @@ void *thr_writer(void *arg) cycles_t time1, time2; printf("thread_begin %s, thread id : %lx, tid %lu\n", - "writer", pthread_self(), (unsigned long)gettid()); + "writer", (unsigned long) pthread_self(), + (unsigned long) gettid()); sleep(2); for (i = 0; i < OUTER_WRITE_LOOP; i++) { for (j = 0; j < INNER_WRITE_LOOP; j++) { - time1 = get_cycles(); + time1 = caa_get_cycles(); for (tidx = 0; tidx < NR_READ; tidx++) { pthread_mutex_lock(&per_thread_lock[tidx].lock); } @@ -130,14 +136,15 @@ void *thr_writer(void *arg) for (tidx = NR_READ - 1; tidx >= 0; tidx--) { pthread_mutex_unlock(&per_thread_lock[tidx].lock); } - time2 = get_cycles(); + time2 = caa_get_cycles(); writer_time[(unsigned long)arg] += time2 - time1; usleep(1); } } printf("thread_end %s, thread id : %lx, tid %lu\n", - "writer", pthread_self(), (unsigned long)gettid()); + "writer", (unsigned long) pthread_self(), + (unsigned long) gettid()); return ((void*)2); } @@ -163,7 +170,8 @@ int main(int argc, char **argv) tid_writer = malloc(sizeof(*tid_writer) * num_write); printf("thread %-6s, thread id : %lx, tid %lu\n", - "main", pthread_self(), (unsigned long)gettid()); + "main", (unsigned long) pthread_self(), + (unsigned long) gettid()); per_thread_lock = malloc(sizeof(struct per_thread_lock) * NR_READ);