Commit 995e4b5e authored by Steffen Vogel's avatar Steffen Vogel 🎅🏼

memory: use default value for memory type

parent 4a217580
......@@ -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);
......
......@@ -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);
......
......@@ -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);
......
......@@ -41,9 +41,7 @@
#include <villas/common.h>
#include <villas/config.h>
/* Forward declarations */
struct memory_type;
#include <villas/memory_type.h>
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);
......
......@@ -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);
......
......@@ -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)
......
......@@ -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;
......
......@@ -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)
......
......@@ -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;
......
......@@ -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;
......
......@@ -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)
......
......@@ -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;
......
......@@ -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;
......
......@@ -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");
......
......@@ -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.");
}
......
......@@ -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);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment