From 599197a66f5d9f9c14d86405f208690047919679 Mon Sep 17 00:00:00 2001 From: Manuel Pitz Date: Thu, 1 Jul 2021 22:26:44 +0200 Subject: [PATCH] fix calculation of maximum number of signals in nodes/paths --- include/villas/hook_list.hpp | 3 +++ include/villas/node.h | 4 ++++ include/villas/node_direction.h | 2 ++ include/villas/path.h | 4 +++- lib/hook_list.cpp | 18 ++++++++++++++++++ lib/node.cpp | 13 +++++++++++++ lib/node_direction.cpp | 11 +++++++++++ lib/path.cpp | 13 +++++++++++-- lib/path_source.cpp | 4 ++-- 9 files changed, 67 insertions(+), 5 deletions(-) diff --git a/include/villas/hook_list.hpp b/include/villas/hook_list.hpp index 89a718238..831cc177f 100644 --- a/include/villas/hook_list.hpp +++ b/include/villas/hook_list.hpp @@ -75,4 +75,7 @@ void hook_list_stop(struct vlist *hs); struct vlist * hook_list_get_signals(struct vlist *hs); +/** Get the maximum number of signals which is used by any of the hooks in the list. */ +unsigned hook_list_get_signals_max_cnt(struct vlist *hs); + json_t * hook_list_to_json(struct vlist *hs); diff --git a/include/villas/node.h b/include/villas/node.h index 396ee6fd4..9ce050207 100644 --- a/include/villas/node.h +++ b/include/villas/node.h @@ -192,6 +192,10 @@ struct vlist * node_output_signals(struct vnode *n); struct vlist * node_input_signals(struct vnode *n); +unsigned node_input_signals_max_cnt(struct vnode *n); + +unsigned node_output_signals_max_cnt(struct vnode *n); + /** Reverse local and remote socket address. * * @see node_type::reverse diff --git a/include/villas/node_direction.h b/include/villas/node_direction.h index 109b96081..a353dd6e0 100644 --- a/include/villas/node_direction.h +++ b/include/villas/node_direction.h @@ -79,4 +79,6 @@ int node_direction_stop(struct vnode_direction *nd, struct vnode *n); struct vlist * node_direction_get_signals(struct vnode_direction *nd); +unsigned node_direction_get_signals_max_cnt(struct vnode_direction *nd); + /** @} */ diff --git a/include/villas/path.h b/include/villas/path.h index c6ad27405..899a07cea 100644 --- a/include/villas/path.h +++ b/include/villas/path.h @@ -144,7 +144,9 @@ int path_destroy(struct vpath *p) __attribute__ ((warn_unused_result)); const char * path_name(struct vpath *p); /** Get a list of signals which is emitted by the path. */ -struct vlist * path_output_signals(struct vpath *n); +struct vlist * path_output_signals(struct vpath *p); + +unsigned path_output_signals_max_cnt(struct vpath *p); /** Reverse a path */ int path_reverse(struct vpath *p, struct vpath *r); diff --git a/lib/hook_list.cpp b/lib/hook_list.cpp index db6824982..2c21a4188 100644 --- a/lib/hook_list.cpp +++ b/lib/hook_list.cpp @@ -132,6 +132,7 @@ skip_add: sigs = h->getSignals(); auto logger = logging.get("hook"); + logger->debug("Signal list after hook {}:", i); signal_list_dump(logger, sigs); } } @@ -210,6 +211,23 @@ struct vlist * hook_list_get_signals(struct vlist *hs) return h->getSignals(); } +unsigned hook_list_get_signals_max_cnt(struct vlist *hs) +{ + unsigned max_cnt = 0; + + for (size_t i = 0; i < vlist_length(hs); i++) { + Hook *h = (Hook *) vlist_at(hs, i); + + struct vlist *sigs = h->getSignals(); + unsigned sigs_cnt = vlist_length(sigs); + + if (sigs_cnt > max_cnt) + max_cnt = sigs_cnt; + } + + return max_cnt; +} + json_t * hook_list_to_json(struct vlist *hs) { json_t *json_hooks = json_array(); diff --git a/lib/node.cpp b/lib/node.cpp index a8fc2a0b9..5be36eaff 100644 --- a/lib/node.cpp +++ b/lib/node.cpp @@ -680,6 +680,19 @@ struct vlist * node_output_signals(struct vnode *n) return nullptr; } +unsigned node_input_signals_max_cnt(struct vnode *n) +{ + return node_direction_get_signals_max_cnt(&n->in); +} + +unsigned node_output_signals_max_cnt(struct vnode *n) +{ + if (n->out.path) + return path_output_signals_max_cnt(n->out.path); + + return 0; +} + json_t * node_to_json(struct vnode *n) { struct vlist *output_signals; diff --git a/lib/node_direction.cpp b/lib/node_direction.cpp index 9f34090cb..a02f5a157 100644 --- a/lib/node_direction.cpp +++ b/lib/node_direction.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -216,3 +217,13 @@ struct vlist * node_direction_get_signals(struct vnode_direction *nd) return &nd->signals; } + +unsigned node_direction_get_signals_max_cnt(struct vnode_direction *nd) +{ +#ifdef WITH_HOOKS + if (vlist_length(&nd->hooks) > 0) + return MAX(vlist_length(&nd->signals), hook_list_get_signals_max_cnt(&nd->hooks)); +#endif /* WITH_HOOKS */ + + return vlist_length(&nd->signals); +} diff --git a/lib/path.cpp b/lib/path.cpp index d58349da1..9e3d79ccb 100644 --- a/lib/path.cpp +++ b/lib/path.cpp @@ -378,8 +378,7 @@ int path_prepare(struct vpath *p, NodeList &nodes) /* Prepare pool */ pool_size = MAX(1UL, vlist_length(&p->destinations)) * p->queuelen; - ret = pool_init(&p->pool, pool_size, SAMPLE_LENGTH(vlist_length(path_output_signals(p))), pool_mt); - + ret = pool_init(&p->pool, pool_size, SAMPLE_LENGTH(path_output_signals_max_cnt(p)), pool_mt); if (ret) return ret; @@ -827,6 +826,16 @@ struct vlist * path_output_signals(struct vpath *p) return &p->signals; } +unsigned path_output_signals_max_cnt(struct vpath *p) +{ +#ifdef WITH_HOOKS + if (vlist_length(&p->hooks) > 0) + return MAX(vlist_length(&p->signals), hook_list_get_signals_max_cnt(&p->hooks)); +#endif /* WITH_HOOKS */ + + return vlist_length(&p->signals); +} + json_t * path_to_json(struct vpath *p) { char uuid[37]; diff --git a/lib/path_source.cpp b/lib/path_source.cpp index c1e4feca0..b34d32ada 100644 --- a/lib/path_source.cpp +++ b/lib/path_source.cpp @@ -52,12 +52,12 @@ int path_source_init_master(struct vpath_source *ps, struct vnode *n) if (ret) return ret; - int pool_size = MAX(DEFAULT_QUEUE_LENGTH, 40 * ps->node->in.vectorize); + int pool_size = MAX(DEFAULT_QUEUE_LENGTH, 20 * ps->node->in.vectorize); if (ps->node->_vt->pool_size) pool_size = ps->node->_vt->pool_size; - ret = pool_init(&ps->pool, pool_size, SAMPLE_LENGTH(vlist_length(node_input_signals(ps->node))), node_memory_type(ps->node)); + ret = pool_init(&ps->pool, pool_size, SAMPLE_LENGTH(node_input_signals_max_cnt(ps->node)), node_memory_type(ps->node)); if (ret) return ret;