From 46f31cff299d1f2ad8ddcb9919428889c2c59454 Mon Sep 17 00:00:00 2001 From: Lukasz Dorau Date: Thu, 17 Jan 2019 16:14:55 +0100 Subject: [PATCH 1/3] test: add three messages --- tests/vmemcache_test_mt.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/vmemcache_test_mt.c b/tests/vmemcache_test_mt.c index 59c2e222..0548b6cf 100644 --- a/tests/vmemcache_test_mt.c +++ b/tests/vmemcache_test_mt.c @@ -137,6 +137,8 @@ run_test_put(VMEMcache *cache, unsigned n_threads, os_thread_t *threads, ctx[i].thread_routine = worker_thread_put; } + printf("%s: STARTED\n", __func__); + run_threads(n_threads, threads, ctx); printf("%s: PASSED\n", __func__); @@ -165,6 +167,8 @@ run_test_get(VMEMcache *cache, unsigned n_threads, os_thread_t *threads, int cache_is_full = 0; vmemcache_callback_on_evict(cache, on_evict_cb, &cache_is_full); + printf("%s: filling up the pool...\n", __func__); + unsigned long long i = 0; while (!cache_is_full) { if (vmemcache_put(ctx->cache, (char *)&i, sizeof(i), @@ -183,6 +187,8 @@ run_test_get(VMEMcache *cache, unsigned n_threads, os_thread_t *threads, ctx[i].ops_count = ops_count; } + printf("%s: STARTED\n", __func__); + run_threads(n_threads, threads, ctx); printf("%s: PASSED\n", __func__); From 36dacb7112c78c6e399fb2581a661c77dd7a9b27 Mon Sep 17 00:00:00 2001 From: Lukasz Dorau Date: Thu, 17 Jan 2019 16:16:20 +0100 Subject: [PATCH 2/3] test: fix setting number of operations --- tests/vmemcache_test_mt.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/tests/vmemcache_test_mt.c b/tests/vmemcache_test_mt.c index 0548b6cf..3458b886 100644 --- a/tests/vmemcache_test_mt.c +++ b/tests/vmemcache_test_mt.c @@ -129,12 +129,13 @@ worker_thread_get(void *arg) */ static void run_test_put(VMEMcache *cache, unsigned n_threads, os_thread_t *threads, - struct context *ctx) + unsigned ops_per_thread, struct context *ctx) { free_cache(cache); for (unsigned i = 0; i < n_threads; ++i) { ctx[i].thread_routine = worker_thread_put; + ctx[i].ops_count = ops_per_thread; } printf("%s: STARTED\n", __func__); @@ -160,7 +161,7 @@ on_evict_cb(VMEMcache *cache, const char *key, size_t key_size, void *arg) */ static void run_test_get(VMEMcache *cache, unsigned n_threads, os_thread_t *threads, - struct context *ctx) + unsigned ops_per_thread, struct context *ctx) { free_cache(cache); @@ -169,7 +170,7 @@ run_test_get(VMEMcache *cache, unsigned n_threads, os_thread_t *threads, printf("%s: filling up the pool...\n", __func__); - unsigned long long i = 0; + unsigned i = 0; while (!cache_is_full) { if (vmemcache_put(ctx->cache, (char *)&i, sizeof(i), ctx->buffs[i % ctx->nbuffs].buff, @@ -178,13 +179,18 @@ run_test_get(VMEMcache *cache, unsigned n_threads, os_thread_t *threads, i++; } - unsigned long long ops_count = i; - vmemcache_callback_on_evict(cache, NULL, NULL); + if (ops_per_thread > i) { + /* we cannot get more than we have put */ + ops_per_thread = i; + printf("%s: decreasing ops_count to: %u\n", + __func__, n_threads * ops_per_thread); + } + for (unsigned i = 0; i < n_threads; ++i) { ctx[i].thread_routine = worker_thread_get; - ctx[i].ops_count = ops_count; + ctx[i].ops_count = ops_per_thread; } printf("%s: STARTED\n", __func__); @@ -274,12 +280,13 @@ main(int argc, char *argv[]) ctx[i].cache = cache; ctx[i].buffs = buffs; ctx[i].nbuffs = nbuffs; - ctx[i].ops_count = ops_count / n_threads; } + unsigned ops_per_thread = ops_count / n_threads; + /* run all tests */ - run_test_put(cache, n_threads, threads, ctx); - run_test_get(cache, n_threads, threads, ctx); + run_test_put(cache, n_threads, threads, ops_per_thread, ctx); + run_test_get(cache, n_threads, threads, ops_per_thread, ctx); ret = 0; From 7d92269a1469a2bc04c5a409f3ebf61b696c2476 Mon Sep 17 00:00:00 2001 From: Lukasz Dorau Date: Tue, 8 Jan 2019 14:33:55 +0100 Subject: [PATCH 3/3] test: add get+put multi-threaded test --- tests/vmemcache_test_mt.c | 67 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 65 insertions(+), 2 deletions(-) diff --git a/tests/vmemcache_test_mt.c b/tests/vmemcache_test_mt.c index 3458b886..0effdd4a 100644 --- a/tests/vmemcache_test_mt.c +++ b/tests/vmemcache_test_mt.c @@ -124,6 +124,32 @@ worker_thread_get(void *arg) return NULL; } +/* + * worker_thread_put_in_gets -- (internal) worker testing vmemcache_put() + */ +static void * +worker_thread_put_in_gets(void *arg) +{ + struct context *ctx = arg; + unsigned long long i; + unsigned long long start = ctx->ops_count + (ctx->thread_number & 0x1); + + /* + * There is '3' here - in order to have the same number (ctx->ops_count) + * of operations per each thread. + */ + unsigned long long end = 3 * ctx->ops_count; + + for (i = start; i < end; i += 2) { + if (vmemcache_put(ctx->cache, (char *)&i, sizeof(i), + ctx->buffs[i % ctx->nbuffs].buff, + ctx->buffs[i % ctx->nbuffs].size)) + FATAL("ERROR: vmemcache_put: %s", vmemcache_errormsg()); + } + + return NULL; +} + /* * run_test_put -- (internal) run test for vmemcache_put() */ @@ -157,10 +183,10 @@ on_evict_cb(VMEMcache *cache, const char *key, size_t key_size, void *arg) } /* - * run_test_get -- (internal) run test for vmemcache_get() + * init_test_get -- (internal) initialize test for vmemcache_get() */ static void -run_test_get(VMEMcache *cache, unsigned n_threads, os_thread_t *threads, +init_test_get(VMEMcache *cache, unsigned n_threads, os_thread_t *threads, unsigned ops_per_thread, struct context *ctx) { free_cache(cache); @@ -192,6 +218,16 @@ run_test_get(VMEMcache *cache, unsigned n_threads, os_thread_t *threads, ctx[i].thread_routine = worker_thread_get; ctx[i].ops_count = ops_per_thread; } +} + +/* + * run_test_get -- (internal) run test for vmemcache_get() + */ +static void +run_test_get(VMEMcache *cache, unsigned n_threads, os_thread_t *threads, + unsigned ops_per_thread, struct context *ctx) +{ + init_test_get(cache, n_threads, threads, ops_per_thread, ctx); printf("%s: STARTED\n", __func__); @@ -200,6 +236,32 @@ run_test_get(VMEMcache *cache, unsigned n_threads, os_thread_t *threads, printf("%s: PASSED\n", __func__); } +/* + * run_test_get_put -- (internal) run test for vmemcache_get() + * and vmemcache_put() + */ +static void +run_test_get_put(VMEMcache *cache, unsigned n_threads, os_thread_t *threads, + unsigned ops_per_thread, struct context *ctx) +{ + init_test_get(cache, n_threads, threads, ops_per_thread, ctx); + + if (n_threads < 10) { + ctx[n_threads >> 1].thread_routine = worker_thread_put_in_gets; + } else { + /* 20% of threads (in the middle of their array) are puts */ + unsigned n_puts = (2 * n_threads) / 10; /* 20% of threads */ + unsigned start = (n_threads / 2) - (n_puts / 2); + for (unsigned i = start; i < start + n_puts; i++) + ctx[i].thread_routine = worker_thread_put_in_gets; + } + + printf("%s: STARTED\n", __func__); + + run_threads(n_threads, threads, ctx); + + printf("%s: PASSED\n", __func__); +} int main(int argc, char *argv[]) @@ -287,6 +349,7 @@ main(int argc, char *argv[]) /* run all tests */ run_test_put(cache, n_threads, threads, ops_per_thread, ctx); run_test_get(cache, n_threads, threads, ops_per_thread, ctx); + run_test_get_put(cache, n_threads, threads, ops_per_thread, ctx); ret = 0;