From 549e5b693a58c243bf779d37726c5d8fc6b981ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Fri, 5 Feb 2021 10:25:07 +0100 Subject: [PATCH] Modify the way we benchmark mem_{get,put} Previously, the mem_{get,put} benchmark would pass the allocation size as thread_create argument. This has been now changed, so the allocation size is stored and decremented (divided) in atomic variable and the thread create routing is given a memory context. This will allow to write tests where each thread is given different memory context and do the same for mempool benchmarking. --- lib/isc/tests/mem_test.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/isc/tests/mem_test.c b/lib/isc/tests/mem_test.c index 3b7c3e9ee1..a39b59c19b 100644 --- a/lib/isc/tests/mem_test.c +++ b/lib/isc/tests/mem_test.c @@ -22,6 +22,7 @@ #define UNIT_TESTING #include +#include #include #include #include @@ -372,17 +373,22 @@ isc_mem_traceflag_test(void **state) { #define NUM_ITEMS 1024 /* 768 */ #define ITEM_SIZE 65534 +static atomic_size_t mem_size; + static isc_threadresult_t mem_thread(isc_threadarg_t arg) { + isc_mem_t *mctx = (isc_mem_t *)arg; void *items[NUM_ITEMS]; - size_t size = *((size_t *)arg); + size_t size = atomic_load(&mem_size); + while (!atomic_compare_exchange_weak(&mem_size, &size, size / 2)) + ; for (int i = 0; i < ITERS; i++) { for (int j = 0; j < NUM_ITEMS; j++) { - items[j] = isc_mem_get(test_mctx, size); + items[j] = isc_mem_get(mctx, size); } for (int j = 0; j < NUM_ITEMS; j++) { - isc_mem_put(test_mctx, items[j], size); + isc_mem_put(mctx, items[j], size); } } @@ -396,16 +402,16 @@ isc_mem_benchmark(void **state) { isc_time_t ts1, ts2; double t; isc_result_t result; - size_t size = ITEM_SIZE; UNUSED(state); + atomic_init(&mem_size, ITEM_SIZE); + result = isc_time_now(&ts1); assert_int_equal(result, ISC_R_SUCCESS); for (int i = 0; i < nthreads; i++) { - isc_thread_create(mem_thread, &size, &threads[i]); - size = size / 2; + isc_thread_create(mem_thread, test_mctx, &threads[i]); } for (int i = 0; i < nthreads; i++) { isc_thread_join(threads[i], NULL); @@ -446,7 +452,6 @@ isc_mempool_benchmark(void **state) { isc_time_t ts1, ts2; double t; isc_result_t result; - size_t size = ITEM_SIZE; isc_mempool_t *mp = NULL; isc_mutex_t mplock; @@ -466,7 +471,6 @@ isc_mempool_benchmark(void **state) { for (int i = 0; i < nthreads; i++) { isc_thread_create(mempool_thread, mp, &threads[i]); - size = size / 2; } for (int i = 0; i < nthreads; i++) { isc_thread_join(threads[i], NULL);