diff --git a/include/villas/memory_type.h b/include/villas/memory_type.h index 50ca0f5dc..5f1130961 100644 --- a/include/villas/memory_type.h +++ b/include/villas/memory_type.h @@ -54,6 +54,7 @@ struct memory_type { extern struct memory_type memory_heap; extern struct memory_type memory_hugepage; +extern struct memory_type *memory_default; struct memory_type * memory_ib(struct node *n, struct memory_type *parent); struct memory_type * memory_managed(void *ptr, size_t len); diff --git a/include/villas/node.h b/include/villas/node.h index ecb988920..e67f91175 100644 --- a/include/villas/node.h +++ b/include/villas/node.h @@ -193,7 +193,7 @@ struct node_type * node_type(struct node *n) return n->_vt; } -struct memory_type * node_memory_type(struct node *n, struct memory_type *parent); +struct memory_type * node_memory_type(struct node *n); bool node_is_valid_name(const char *name); diff --git a/include/villas/pool.h b/include/villas/pool.h index 259950080..8deec4774 100644 --- a/include/villas/pool.h +++ b/include/villas/pool.h @@ -57,7 +57,7 @@ struct pool { * @retval 0 The pool has been successfully initialized. * @retval <>0 There was an error during the pool initialization. */ -int pool_init(struct pool *p, size_t cnt, size_t blocksz, struct memory_type *mem); +int pool_init(struct pool *p, size_t cnt, size_t blocksz, struct memory_type *mem = memory_default); /** Destroy and release memory used by pool. */ int pool_destroy(struct pool *p); diff --git a/include/villas/queue.h b/include/villas/queue.h index dbb87af4a..95113f079 100644 --- a/include/villas/queue.h +++ b/include/villas/queue.h @@ -41,9 +41,7 @@ #include #include - -/* Forward declarations */ -struct memory_type; +#include typedef char cacheline_pad_t[CACHELINE_SIZE]; @@ -73,7 +71,7 @@ struct queue { }; /** Initialize MPMC queue */ -int queue_init(struct queue *q, size_t size, struct memory_type *mem); +int queue_init(struct queue *q, size_t size, struct memory_type *mem = memory_default); /** Desroy MPMC queue and release memory */ int queue_destroy(struct queue *q); diff --git a/include/villas/queue_signalled.h b/include/villas/queue_signalled.h index 916052cd1..e51a965ba 100644 --- a/include/villas/queue_signalled.h +++ b/include/villas/queue_signalled.h @@ -64,7 +64,7 @@ struct queue_signalled { #define queue_signalled_available(q) queue_available(&((q)->queue)) -int queue_signalled_init(struct queue_signalled *qs, size_t size, struct memory_type *mem, enum QueueSignalledMode mode = QueueSignalledMode::AUTO, int flags = 0); +int queue_signalled_init(struct queue_signalled *qs, size_t size, struct memory_type *mem = memory_default, enum QueueSignalledMode mode = QueueSignalledMode::AUTO, int flags = 0); int queue_signalled_destroy(struct queue_signalled *qs); diff --git a/lib/node.cpp b/lib/node.cpp index 186533bc8..b551419d5 100644 --- a/lib/node.cpp +++ b/lib/node.cpp @@ -542,9 +542,9 @@ int node_netem_fds(struct node *n, int fds[]) return node_type(n)->netem_fds ? node_type(n)->netem_fds(n, fds) : -1; } -struct memory_type * node_memory_type(struct node *n, struct memory_type *parent) +struct memory_type * node_memory_type(struct node *n) { - return node_type(n)->memory_type ? node_type(n)->memory_type(n, parent) : &memory_hugepage; + return node_type(n)->memory_type ? node_type(n)->memory_type(n, memory_default) : memory_default; } int node_list_parse(struct vlist *list, json_t *cfg, struct vlist *all) diff --git a/lib/nodes/iec61850_sv.cpp b/lib/nodes/iec61850_sv.cpp index 9bada0d21..8be64c3e5 100644 --- a/lib/nodes/iec61850_sv.cpp +++ b/lib/nodes/iec61850_sv.cpp @@ -328,11 +328,11 @@ int iec61850_sv_start(struct node *n) SVReceiver_addSubscriber(i->in.receiver, i->in.subscriber); /* Initialize pool and queue to pass samples between threads */ - ret = pool_init(&i->in.pool, 1024, SAMPLE_LENGTH(vlist_length(&n->in.signals)), &memory_hugepage); + ret = pool_init(&i->in.pool, 1024, SAMPLE_LENGTH(vlist_length(&n->in.signals))); if (ret) return ret; - ret = queue_signalled_init(&i->in.queue, 1024, &memory_hugepage); + ret = queue_signalled_init(&i->in.queue, 1024); if (ret) return ret; diff --git a/lib/nodes/loopback.cpp b/lib/nodes/loopback.cpp index c90cd3a8e..1aba21327 100644 --- a/lib/nodes/loopback.cpp +++ b/lib/nodes/loopback.cpp @@ -81,11 +81,11 @@ int loopback_start(struct node *n) vlist_length(&n->out.signals) ); - ret = pool_init(&l->pool, l->queuelen, SAMPLE_LENGTH(len), &memory_hugepage); + ret = pool_init(&l->pool, l->queuelen, SAMPLE_LENGTH(len)); if (ret) return ret; - return queue_signalled_init(&l->queue, l->queuelen, &memory_hugepage, l->mode); + return queue_signalled_init(&l->queue, l->queuelen, memory_default, l->mode); } int loopback_stop(struct node *n) diff --git a/lib/nodes/mqtt.cpp b/lib/nodes/mqtt.cpp index 1e69d7ab4..50cb90e64 100644 --- a/lib/nodes/mqtt.cpp +++ b/lib/nodes/mqtt.cpp @@ -361,11 +361,11 @@ int mqtt_start(struct node *n) if (ret) return ret; - ret = pool_init(&m->pool, 1024, SAMPLE_LENGTH(vlist_length(&n->in.signals)), &memory_hugepage); + ret = pool_init(&m->pool, 1024, SAMPLE_LENGTH(vlist_length(&n->in.signals))); if (ret) return ret; - ret = queue_signalled_init(&m->queue, 1024, &memory_hugepage); + ret = queue_signalled_init(&m->queue, 1024); if (ret) return ret; diff --git a/lib/nodes/websocket.cpp b/lib/nodes/websocket.cpp index 6228144db..a9ec5f6b7 100644 --- a/lib/nodes/websocket.cpp +++ b/lib/nodes/websocket.cpp @@ -86,7 +86,7 @@ static int websocket_connection_init(struct websocket_connection *c) c->_name = nullptr; - ret = queue_init(&c->queue, DEFAULT_QUEUE_LENGTH, &memory_hugepage); + ret = queue_init(&c->queue, DEFAULT_QUEUE_LENGTH); if (ret) return ret; @@ -391,11 +391,11 @@ int websocket_start(struct node *n) int ret; struct websocket *w = (struct websocket *) n->_vd; - ret = pool_init(&w->pool, DEFAULT_WEBSOCKET_QUEUE_LENGTH, SAMPLE_LENGTH(DEFAULT_WEBSOCKET_SAMPLE_LENGTH), &memory_hugepage); + ret = pool_init(&w->pool, DEFAULT_WEBSOCKET_QUEUE_LENGTH, SAMPLE_LENGTH(DEFAULT_WEBSOCKET_SAMPLE_LENGTH)); if (ret) return ret; - ret = queue_signalled_init(&w->queue, DEFAULT_WEBSOCKET_QUEUE_LENGTH, &memory_hugepage); + ret = queue_signalled_init(&w->queue, DEFAULT_WEBSOCKET_QUEUE_LENGTH); if (ret) return ret; diff --git a/lib/path.cpp b/lib/path.cpp index dd3960b5a..2eb915ebf 100644 --- a/lib/path.cpp +++ b/lib/path.cpp @@ -226,7 +226,7 @@ int path_prepare(struct path *p) assert(p->state == State::CHECKED); /* Initialize destinations */ - struct memory_type *pool_mt = &memory_hugepage; + struct memory_type *pool_mt = memory_default; unsigned pool_size = MAX(1UL, vlist_length(&p->destinations)) * p->queuelen; for (size_t i = 0; i < vlist_length(&p->destinations); i++) { @@ -236,7 +236,7 @@ int path_prepare(struct path *p) pool_size = node_type(pd->node)->pool_size; if (node_type(pd->node)->memory_type) - pool_mt = node_memory_type(pd->node, &memory_hugepage); + pool_mt = node_memory_type(pd->node); ret = path_destination_init(pd, p->queuelen); if (ret) diff --git a/lib/path_destination.cpp b/lib/path_destination.cpp index 3dd9e18f4..3324c50d9 100644 --- a/lib/path_destination.cpp +++ b/lib/path_destination.cpp @@ -31,7 +31,7 @@ int path_destination_init(struct path_destination *pd, int queuelen) { int ret; - ret = queue_init(&pd->queue, queuelen, &memory_hugepage); + ret = queue_init(&pd->queue, queuelen); if (ret) return ret; diff --git a/lib/path_source.cpp b/lib/path_source.cpp index bb63b953d..becee51ae 100644 --- a/lib/path_source.cpp +++ b/lib/path_source.cpp @@ -37,7 +37,7 @@ int path_source_init(struct path_source *ps) if (ps->node->_vt->pool_size) pool_size = ps->node->_vt->pool_size; - ret = pool_init(&ps->pool, pool_size, SAMPLE_LENGTH(vlist_length(&ps->node->in.signals)), node_memory_type(ps->node, &memory_hugepage)); + ret = pool_init(&ps->pool, pool_size, SAMPLE_LENGTH(vlist_length(&ps->node->in.signals)), node_memory_type(ps->node)); if (ret) return ret; diff --git a/src/villas-hook.cpp b/src/villas-hook.cpp index 95f29c207..6b2f2b4b8 100644 --- a/src/villas-hook.cpp +++ b/src/villas-hook.cpp @@ -201,7 +201,7 @@ check: if (optarg == endptr) smps = new struct sample*[cnt]; - ret = pool_init(&p, 10 * cnt, SAMPLE_LENGTH(DEFAULT_SAMPLE_LENGTH), &memory_hugepage); + ret = pool_init(&p, 10 * cnt, SAMPLE_LENGTH(DEFAULT_SAMPLE_LENGTH)); if (ret) throw RuntimeError("Failed to initilize memory pool"); diff --git a/src/villas-pipe.cpp b/src/villas-pipe.cpp index f2d1c0dea..5b84363d0 100644 --- a/src/villas-pipe.cpp +++ b/src/villas-pipe.cpp @@ -81,7 +81,7 @@ public: unsigned vec = LOG2_CEIL(MAX(node->out.vectorize, node->in.vectorize)); unsigned pool_size = node_type(node)->pool_size ? node_type(node)->pool_size : vec; - int ret = pool_init(&pool, pool_size, SAMPLE_LENGTH(DEFAULT_SAMPLE_LENGTH), node_memory_type(node, &memory_hugepage)); + int ret = pool_init(&pool, pool_size, SAMPLE_LENGTH(DEFAULT_SAMPLE_LENGTH), node_memory_type(node)); if (ret < 0) throw RuntimeError("Failed to allocate memory for pool."); } diff --git a/tests/unit/io.cpp b/tests/unit/io.cpp index 4cf4ab85a..43d9f059f 100644 --- a/tests/unit/io.cpp +++ b/tests/unit/io.cpp @@ -227,7 +227,7 @@ ParameterizedTest(struct param *p, io, lowlevel, .init = init_memory) struct sample *smps[p->cnt]; struct sample *smpt[p->cnt]; - ret = pool_init(&pool, 2 * p->cnt, SAMPLE_LENGTH(NUM_VALUES), &memory_hugepage); + ret = pool_init(&pool, 2 * p->cnt, SAMPLE_LENGTH(NUM_VALUES)); cr_assert_eq(ret, 0); vlist_init(&signals); @@ -297,7 +297,7 @@ ParameterizedTest(struct param *p, io, highlevel, .init = init_memory) struct sample *smps[p->cnt]; struct sample *smpt[p->cnt]; - ret = pool_init(&pool, 2 * p->cnt, SAMPLE_LENGTH(NUM_VALUES), &memory_hugepage); + ret = pool_init(&pool, 2 * p->cnt, SAMPLE_LENGTH(NUM_VALUES)); cr_assert_eq(ret, 0); ret = sample_alloc_many(&pool, smps, p->cnt);