X-Git-Url: https://git.liburcu.org/?p=urcu.git;a=blobdiff_plain;f=test_perthreadlock_timing.c;h=3e8268b6d7085c15d6a5de4ee1124ebcac77efca;hp=5369796759bfa950108117c5d4a864ca6aa06721;hb=1050892f30b28680a92f7d6966656d688201037b;hpb=102d1d236ae6c788bb543dce3de410531aca346f diff --git a/test_perthreadlock_timing.c b/test_perthreadlock_timing.c index 5369796..3e8268b 100644 --- a/test_perthreadlock_timing.c +++ b/test_perthreadlock_timing.c @@ -33,6 +33,9 @@ #include #include +/* Make this big enough to include the POWER5+ L3 cacheline size of 256B */ +#define CACHE_LINE_SIZE 4096 + #if defined(_syscall0) _syscall0(pid_t, gettid) #elif defined(__NR_gettid) @@ -58,7 +61,7 @@ static struct test_array test_array = { 8 }; struct per_thread_lock { pthread_mutex_t lock; -} __attribute__((aligned(128))); /* cache-line aligned */ +} __attribute__((aligned(CACHE_LINE_SIZE))); /* cache-line aligned */ static struct per_thread_lock *per_thread_lock; @@ -70,11 +73,14 @@ static struct per_thread_lock *per_thread_lock; #define INNER_WRITE_LOOP 200U #define WRITE_LOOP ((unsigned long long)OUTER_WRITE_LOOP * INNER_WRITE_LOOP) -#define NR_READ 10 -#define NR_WRITE 9 +static int num_read; +static int num_write; + +#define NR_READ num_read +#define NR_WRITE num_write -static cycles_t reader_time[NR_READ] __attribute__((aligned(128))); -static cycles_t writer_time[NR_WRITE] __attribute__((aligned(128))); +static cycles_t __attribute__((aligned(CACHE_LINE_SIZE))) *reader_time; +static cycles_t __attribute__((aligned(CACHE_LINE_SIZE))) *writer_time; void *thr_reader(void *arg) { @@ -127,8 +133,8 @@ void *thr_writer(void *arg) } time2 = get_cycles(); writer_time[(unsigned long)arg] += time2 - time1; + usleep(1); } - usleep(1); } printf("thread_end %s, thread id : %lx, tid %lu\n", @@ -136,15 +142,27 @@ void *thr_writer(void *arg) return ((void*)2); } -int main() +int main(int argc, char **argv) { int err; - pthread_t tid_reader[NR_READ], tid_writer[NR_WRITE]; + pthread_t *tid_reader, *tid_writer; void *tret; int i; cycles_t tot_rtime = 0; cycles_t tot_wtime = 0; + if (argc < 2) { + printf("Usage : %s nr_readers nr_writers\n", argv[0]); + exit(-1); + } + num_read = atoi(argv[1]); + num_write = atoi(argv[2]); + + reader_time = malloc(sizeof(*reader_time) * num_read); + writer_time = malloc(sizeof(*writer_time) * num_write); + tid_reader = malloc(sizeof(*tid_reader) * num_read); + tid_writer = malloc(sizeof(*tid_writer) * num_write); + printf("thread %-6s, thread id : %lx, tid %lu\n", "main", pthread_self(), (unsigned long)gettid()); @@ -186,5 +204,10 @@ int main() (double)tot_wtime / ((double)NR_WRITE * (double)WRITE_LOOP)); free(per_thread_lock); + free(reader_time); + free(writer_time); + free(tid_reader); + free(tid_writer); + return 0; }