Replace rdtsc with clock_gettime to run on Octopus machine, MPMC shows too good result--not correct most probably
This commit is contained in:
parent
b1890be20e
commit
3e835aed10
4 changed files with 52 additions and 19 deletions
22
mpmc_test.c
22
mpmc_test.c
|
@ -6,6 +6,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
|
||||
/* There are not many compilers yet which support threads.h natively.
|
||||
* We will fallback to a drop-in replacement which is based on pthreads.h */
|
||||
|
@ -23,7 +24,7 @@
|
|||
|
||||
size_t const thread_count = 4;
|
||||
size_t const batch_size = 10;
|
||||
size_t const iter_count = 20000000;
|
||||
size_t const iter_count = 2000000;
|
||||
size_t const queue_size = 1 << 20;
|
||||
|
||||
int volatile g_start = 0;
|
||||
|
@ -54,6 +55,7 @@ __attribute__((always_inline)) static inline uint64_t rdtscp()
|
|||
:
|
||||
: "%rcx", "%rdx", "memory");
|
||||
|
||||
printf("tsc %lu\n", tsc);
|
||||
return tsc;
|
||||
}
|
||||
|
||||
|
@ -101,22 +103,30 @@ int main()
|
|||
thrd_t threads[thread_count];
|
||||
int ret;
|
||||
|
||||
mpmc_queue_init(&queue, queue_size, &memtype_hugepage);
|
||||
mpmc_queue_init(&queue, queue_size, &memtype_heap);
|
||||
|
||||
for (int i = 0; i != thread_count; ++i)
|
||||
thrd_create(&threads[i], thread_func, &queue);
|
||||
|
||||
sleep(1);
|
||||
|
||||
long long starttime, endtime;
|
||||
struct timespec start, end;
|
||||
|
||||
if(clock_gettime(CLOCK_REALTIME, &start))
|
||||
return -1;
|
||||
|
||||
uint64_t start = rdtscp();
|
||||
g_start = 1;
|
||||
|
||||
for (int i = 0; i != thread_count; ++i)
|
||||
thrd_join(threads[i], NULL);
|
||||
|
||||
uint64_t end = rdtscp();
|
||||
if(clock_gettime(CLOCK_REALTIME, &end))
|
||||
return -1;
|
||||
|
||||
printf("cycles/op = %lu\n", (end - start) / (batch_size * iter_count * 2 * thread_count));
|
||||
starttime = start.tv_sec*1000000000LL + start.tv_nsec;
|
||||
endtime = end.tv_sec*1000000000LL + end.tv_nsec;
|
||||
printf("cycles/op = %lld\n", (endtime - starttime) / (batch_size * iter_count * 2 * thread_count));
|
||||
|
||||
size_t used = mpmc_queue_available(&queue);
|
||||
if (used > 0)
|
||||
|
@ -127,4 +137,4 @@ int main()
|
|||
printf("Failed to destroy queue: %d", ret);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -156,20 +156,29 @@ int test_multi_threaded(struct mpmc_queue *q)
|
|||
|
||||
sleep(1);
|
||||
|
||||
uint64_t start = rdtscp();
|
||||
long long starttime, endtime;
|
||||
struct timespec start, end;
|
||||
|
||||
if(clock_gettime(CLOCK_REALTIME, &start))
|
||||
return -1;
|
||||
|
||||
g_start = 1;
|
||||
|
||||
thrd_join(thrp, &resp);
|
||||
thrd_join(thrc, &resc);
|
||||
|
||||
uint64_t end = rdtscp();
|
||||
|
||||
if(clock_gettime(CLOCK_REALTIME, &end))
|
||||
return -1;
|
||||
|
||||
starttime = start.tv_sec*1000000000LL + start.tv_nsec;
|
||||
endtime = end.tv_sec*1000000000LL + end.tv_nsec;
|
||||
|
||||
if (resc || resp)
|
||||
printf("Queue Test failed");
|
||||
else
|
||||
printf("Two-thread Test Complete\n");
|
||||
|
||||
printf("cycles/op = %lu\n", (end - start) / N );
|
||||
printf("cycles/op = %lld\n", (endtime - starttime) / N );
|
||||
|
||||
size_t used = mpmc_queue_available(q);
|
||||
if (used > 0)
|
||||
|
|
|
@ -160,20 +160,27 @@ int test_multi_threaded(struct spsc_queue *q)
|
|||
|
||||
sleep(1);
|
||||
|
||||
uint64_t start = rdtscp();
|
||||
long long starttime, endtime;
|
||||
struct timespec start, end;
|
||||
if(clock_gettime(CLOCK_REALTIME, &start))
|
||||
return -1;
|
||||
|
||||
g_start = 1;
|
||||
|
||||
thrd_join(thrp, &resp);
|
||||
thrd_join(thrc, &resc);
|
||||
|
||||
uint64_t end = rdtscp();
|
||||
|
||||
if(clock_gettime(CLOCK_REALTIME, &end))
|
||||
return -1;
|
||||
|
||||
if (resc || resp)
|
||||
printf("Queue Test failed\n");
|
||||
else
|
||||
printf("Two-thread Test Complete\n");
|
||||
|
||||
printf("cycles/op = %lu\n", (end - start) / N );
|
||||
starttime = start.tv_sec*1000000000LL + start.tv_nsec;
|
||||
endtime = end.tv_sec*1000000000LL + end.tv_nsec;
|
||||
printf("cycles/op = %lld\n", (endtime - starttime) / N );
|
||||
|
||||
if (spsc_queue_available(q) != q->capacity)
|
||||
printf("slots in use? There is something wrong with the test %d\n", spsc_queue_available(q));
|
||||
|
@ -184,7 +191,7 @@ int test_multi_threaded(struct spsc_queue *q)
|
|||
int main()
|
||||
{
|
||||
struct spsc_queue * q = NULL;
|
||||
q = spsc_queue_init(q, 1<<20, &memtype_hugepage);
|
||||
q = spsc_queue_init(q, 1<<20, &memtype_heap);
|
||||
|
||||
//test_single_threaded(q); /** Single threaded test fails with N > queue size*/
|
||||
test_multi_threaded(q);
|
||||
|
|
|
@ -156,20 +156,27 @@ int test_multi_threaded(struct spsc_ub_queue *q)
|
|||
|
||||
sleep(1);
|
||||
|
||||
uint64_t start = rdtscp();
|
||||
long long starttime, endtime;
|
||||
struct timespec start, end;
|
||||
if(clock_gettime(CLOCK_REALTIME, &start))
|
||||
return -1;
|
||||
|
||||
g_start = 1;
|
||||
|
||||
thrd_join(thrp, &resp);
|
||||
thrd_join(thrc, &resc);
|
||||
|
||||
uint64_t end = rdtscp();
|
||||
|
||||
if(clock_gettime(CLOCK_REALTIME, &end))
|
||||
return -1;
|
||||
|
||||
if (resc || resp)
|
||||
printf("Queue Test failed");
|
||||
else
|
||||
printf("Two-thread Test Complete\n");
|
||||
|
||||
printf("cycles/op = %lu\n", (end - start) / N );
|
||||
starttime = start.tv_sec*1000000000LL + start.tv_nsec;
|
||||
endtime = end.tv_sec*1000000000LL + end.tv_nsec;
|
||||
printf("cycles/op = %lld\n", (endtime - starttime) / N );
|
||||
|
||||
if (q->_tail->_next != NULL)
|
||||
printf("slots in use? There is something wrong with the test\n");
|
||||
|
|
Loading…
Add table
Reference in a new issue