aboutsummaryrefslogtreecommitdiff
path: root/mapper.lv2
diff options
context:
space:
mode:
authorGravatar Hanspeter Portner <dev@open-music-kontrollers.ch>2017-03-17 09:48:51 +0100
committerGravatar Hanspeter Portner <dev@open-music-kontrollers.ch>2017-03-17 09:48:51 +0100
commitf9150a90bd577f8c2578152abc71dd056ff09963 (patch)
treeda91bf1101d926d7ce5c981dda76b779c2df7731 /mapper.lv2
parent307b2d00eb002efc08a6315a1a67b722a39c1206 (diff)
parent1a6cf3bbb0e1cc49ecb828e8df4885b05d0b8871 (diff)
downloadsynthpod-f9150a90bd577f8c2578152abc71dd056ff09963.zip
synthpod-f9150a90bd577f8c2578152abc71dd056ff09963.tar.gz
synthpod-f9150a90bd577f8c2578152abc71dd056ff09963.tar.bz2
synthpod-f9150a90bd577f8c2578152abc71dd056ff09963.tar.xz
Merge commit '1a6cf3bbb0e1cc49ecb828e8df4885b05d0b8871' into nk
Diffstat (limited to 'mapper.lv2')
-rw-r--r--mapper.lv2/test/mapper_test.c67
1 files changed, 58 insertions, 9 deletions
diff --git a/mapper.lv2/test/mapper_test.c b/mapper.lv2/test/mapper_test.c
index 7b649b1..5eb0a10 100644
--- a/mapper.lv2/test/mapper_test.c
+++ b/mapper.lv2/test/mapper_test.c
@@ -29,6 +29,7 @@
typedef struct _rtmem_slot_t rtmem_slot_t;
typedef struct _rtmem_t rtmem_t;
+typedef struct _nrtmem_t nrtmem_t;
typedef struct _pool_t pool_t;
// test URIs are of fixed length
@@ -38,11 +39,17 @@ struct _rtmem_slot_t {
// dummy rt memory structure
struct _rtmem_t {
- atomic_uint nalloc; // counts number allocations
+ atomic_uint nalloc; // counts number of allocations
atomic_uint nfree; // counts number of frees
rtmem_slot_t slots [0]; // contains slots as multiple of MAX_ITEMS
};
+// dummy non-rt memory structure
+struct _nrtmem_t {
+ atomic_uint nalloc; // counts number of allocations
+ atomic_uint nfree; // counts number of frees
+};
+
// per-thread properties
struct _pool_t {
pthread_t thread;
@@ -90,6 +97,31 @@ _rtmem_free(void *data, char *uri)
memset(uri, 0x0, MAX_URI_LEN);
}
+static void
+nrtmem_init(nrtmem_t *nrtmem)
+{
+ atomic_init(&nrtmem->nalloc, 0);
+ atomic_init(&nrtmem->nfree, 0);
+}
+
+static char *
+_nrtmem_alloc(void *data, size_t size)
+{
+ nrtmem_t *nrtmem = data;
+
+ atomic_fetch_add_explicit(&nrtmem->nalloc, 1, memory_order_relaxed);
+ return malloc(size);
+}
+
+static void
+_nrtmem_free(void *data, char *uri)
+{
+ nrtmem_t *nrtmem = data;
+
+ atomic_fetch_add_explicit(&nrtmem->nfree, 1, memory_order_relaxed);
+ free(uri);
+}
+
// threads should start (un)mapping at the same time
static atomic_bool rolling = ATOMIC_VAR_INIT(false);
@@ -125,6 +157,7 @@ int
main(int argc, char **argv)
{
static char zeros [MAX_URI_LEN];
+ static nrtmem_t nrtmem;
assert(mapper_is_lock_free());
@@ -137,6 +170,9 @@ main(int argc, char **argv)
rtmem_t *rtmem = rtmem_new(r);
assert(rtmem);
+ // initialize non-rt memory
+ nrtmem_init(&nrtmem);
+
// create mapper
mapper_t *mapper = mapper_new(MAX_ITEMS);
assert(mapper);
@@ -154,7 +190,7 @@ main(int argc, char **argv)
if(p < r) // let thread use real-time memory
mapper_pool_init(mapper_pool, mapper, _rtmem_alloc, _rtmem_free, rtmem);
else
- mapper_pool_init(mapper_pool, mapper, NULL, NULL, NULL); // fall-back
+ mapper_pool_init(mapper_pool, mapper, _nrtmem_alloc, _nrtmem_free, &nrtmem);
pthread_create(&pool->thread, NULL, _thread, mapper_pool);
}
@@ -175,8 +211,17 @@ main(int argc, char **argv)
assert(usage == MAX_ITEMS/2);
// query rt memory allocations and frees
- const uint32_t nalloc = atomic_load_explicit(&rtmem->nalloc, memory_order_relaxed);
- const uint32_t nfree = atomic_load_explicit(&rtmem->nfree, memory_order_relaxed);
+ const uint32_t rt_nalloc = atomic_load_explicit(&rtmem->nalloc, memory_order_relaxed);
+ const uint32_t rt_nfree = atomic_load_explicit(&rtmem->nfree, memory_order_relaxed);
+
+ // query non-rt memory allocations and frees
+ const uint32_t nrt_nalloc = atomic_load_explicit(&nrtmem.nalloc, memory_order_relaxed);
+ const uint32_t nrt_nfree = atomic_load_explicit(&nrtmem.nfree, memory_order_relaxed);
+
+ // check whether combined allocations and frees match usage
+ const uint32_t tot_nalloc = rt_nalloc + nrt_nalloc;
+ const uint32_t tot_nfree = rt_nfree + nrt_nfree;
+ assert(tot_nalloc - tot_nfree == usage);
// deinit threads
for(uint32_t p = 0; p < n; p++)
@@ -197,7 +242,7 @@ main(int argc, char **argv)
mapper_free(mapper);
// check if all rt memory has been cleared
- for(uint32_t i = 0; i < nalloc; i++)
+ for(uint32_t i = 0; i < rt_nalloc; i++)
{
rtmem_slot_t *slot = &rtmem->slots[i];
@@ -207,10 +252,14 @@ main(int argc, char **argv)
// free rt memory
rtmem_free(rtmem);
- // report rt memory allocations and collisions
- printf("\trt-allocs: %.1f%%, rt-collisions: %.1f%%\n",
- 100.f * (nalloc - nfree) / usage,
- 100.f * nfree / usage);
+ printf(
+ " rt-allocs : %"PRIu32"\n"
+ " rt-frees : %"PRIu32"\n"
+ " nrt-allocs: %"PRIu32"\n"
+ " nrt-frees : %"PRIu32"\n"
+ " collisions: %"PRIu32" (%.1f%% of total allocations -> +%.1f%% allocation overhead)\n",
+ rt_nalloc, rt_nfree, nrt_nalloc, nrt_nfree,
+ tot_nfree, 100.f * tot_nfree / tot_nalloc, 100.f * tot_nfree / usage);
return 0;
}