From 267d2441678c7155870f7283d6c59efb41f62854 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Mon, 27 Mar 2017 12:50:01 +0200 Subject: [PATCH] minor cleanup, bug fixes and refactoring --- lib/node_type.c | 6 ++++-- lib/nodes/websocket.c | 8 ++++---- lib/stats.c | 6 ++---- src/fpga-bench.c | 18 +++++++++--------- src/fpga.c | 7 ++++--- src/hook.c | 4 +--- src/node.c | 7 ++++--- 7 files changed, 28 insertions(+), 28 deletions(-) diff --git a/lib/node_type.c b/lib/node_type.c index 92f074cec..f92d05bc2 100644 --- a/lib/node_type.c +++ b/lib/node_type.c @@ -18,7 +18,8 @@ int node_type_start(struct node_type *vt, int argc, char *argv[], config_setting { int ret; - assert(vt->state != STATE_STARTED); + if (vt->state != STATE_STARTED) + return 0; info("Initializing " YEL("%s") " node type which is used by %zu nodes", plugin_name(vt), list_length(&vt->instances)); { INDENT @@ -35,7 +36,8 @@ int node_type_stop(struct node_type *vt) { int ret; - assert(vt->state == STATE_STARTED); + if (vt->state != STATE_STARTED) + return 0; info("De-initializing " YEL("%s") " node type", plugin_name(vt)); { INDENT diff --git a/lib/nodes/websocket.c b/lib/nodes/websocket.c index daa242ec4..8ef9e10ee 100644 --- a/lib/nodes/websocket.c +++ b/lib/nodes/websocket.c @@ -71,7 +71,7 @@ static int websocket_connection_write(struct websocket_connection *c, struct sam return -1; case WEBSOCKET_CLOSED: if (c->node) { - struct websocket *w = (struct websocket *) c->node->_vd; + struct websocket *w = c->node->_vd; list_remove(&w->connections, c); } else @@ -169,7 +169,7 @@ int websocket_protocol_cb(struct lws *wsi, enum lws_callback_reasons reason, voi info("LWS: New connection %s", websocket_connection_name(c)); if (c->node != NULL) { - struct websocket *w = (struct websocket *) c->node->_vd; + struct websocket *w = c->node->_vd; list_push(&w->connections, c); } else { @@ -191,7 +191,7 @@ int websocket_protocol_cb(struct lws *wsi, enum lws_callback_reasons reason, voi case LWS_CALLBACK_CLIENT_WRITEABLE: case LWS_CALLBACK_SERVER_WRITEABLE: { - w = (struct websocket *) c->node->_vd; + w = c->node->_vd; if (c->node && c->node->state != STATE_STARTED) return -1; @@ -224,7 +224,7 @@ int websocket_protocol_cb(struct lws *wsi, enum lws_callback_reasons reason, voi case LWS_CALLBACK_CLIENT_RECEIVE: case LWS_CALLBACK_RECEIVE: { - w = (struct websocket *) c->node->_vd; + w = c->node->_vd; if (c->node->state != STATE_STARTED) return -1; diff --git a/lib/stats.c b/lib/stats.c index 234c8977a..7368b7668 100644 --- a/lib/stats.c +++ b/lib/stats.c @@ -1,10 +1,8 @@ /** Statistic collection. * * @author Steffen Vogel - * @copyright 2014-2016, Institute for Automation of Complex Power Systems, EONERC - * This file is part of VILLASnode. All Rights Reserved. Proprietary and confidential. - * Unauthorized copying of this file, via any medium is strictly prohibited. - */ + * @copyright 2017, Institute for Automation of Complex Power Systems, EONERC + *********************************************************************************/ #include "stats.h" #include "hist.h" diff --git a/src/fpga-bench.c b/src/fpga-bench.c index c342243f3..d244134f0 100644 --- a/src/fpga-bench.c +++ b/src/fpga-bench.c @@ -84,15 +84,15 @@ int fpga_benchmark_jitter(struct fpga_card *c) { int ret; - struct fpga_ip *tmr; - - tmr = list_lookup(&c->ips, "timer_0"); - if (!tmr || !c->intc) + struct fpga_ip *ip = list_lookup(&c->ips, "timer_0"); + if (!ip || !c->intc) return -1; - XTmrCtr *xtmr = &tmr->timer.inst; + struct timer *tmr = ip->_vd; - ret = intc_enable(c->intc, (1 << tmr->irq), intc_flags); + XTmrCtr *xtmr = &tmr->inst; + + ret = intc_enable(c->intc, (1 << ip->irq), intc_flags); if (ret) error("Failed to enable interrupt"); @@ -107,12 +107,12 @@ int fpga_benchmark_jitter(struct fpga_card *c) uint64_t end, start = rdtsc(); for (int i = 0; i < runs; i++) { - uint64_t cnt = intc_wait(c->intc, tmr->irq); + uint64_t cnt = intc_wait(c->intc, ip->irq); if (cnt != 1) warn("fail"); /* Ackowledge IRQ */ - XTmrCtr_WriteReg((uintptr_t) c->map + tmr->baseaddr, 0, XTC_TCSR_OFFSET, XTmrCtr_ReadReg((uintptr_t) c->map + tmr->baseaddr, 0, XTC_TCSR_OFFSET)); + XTmrCtr_WriteReg((uintptr_t) c->map + ip->baseaddr, 0, XTC_TCSR_OFFSET, XTmrCtr_ReadReg((uintptr_t) c->map + ip->baseaddr, 0, XTC_TCSR_OFFSET)); end = rdtsc(); hist[i] = end - start; @@ -130,7 +130,7 @@ int fpga_benchmark_jitter(struct fpga_card *c) free(hist); - ret = intc_disable(c->intc, (1 << tmr->irq)); + ret = intc_disable(c->intc, (1 << ip->irq)); if (ret) error("Failed to disable interrupt"); diff --git a/src/fpga.c b/src/fpga.c index bb2a6c2a8..98e8fca9c 100644 --- a/src/fpga.c +++ b/src/fpga.c @@ -33,8 +33,6 @@ void usage() printf(" -d Set log level\n\n"); print_copyright(); - - exit(EXIT_FAILURE); } int main(int argc, char *argv[]) @@ -44,8 +42,10 @@ int main(int argc, char *argv[]) struct super_node sn; struct fpga_card *card; - if (argc < 3) + if (argc < 3) { usage(argv[0]); + exit(EXIT_FAILURE); + } /* Parse arguments */ char c, *endptr; @@ -58,6 +58,7 @@ int main(int argc, char *argv[]) case '?': default: usage(); + exit(EXIT_SUCCESS); } } diff --git a/src/hook.c b/src/hook.c index b740fcaed..6b000a376 100644 --- a/src/hook.c +++ b/src/hook.c @@ -51,12 +51,10 @@ static int hook_parse_cli(struct hook *h, char *params[], int paramlen) cfg_root = config_root_setting(&cfg); ret = hook_parse(h, cfg_root); - if (ret) - error("Failed to parse hook settings"); free(str); - return 0; + return ret; } static void usage() diff --git a/src/node.c b/src/node.c index 1f0914e84..10bd2c645 100644 --- a/src/node.c +++ b/src/node.c @@ -82,8 +82,6 @@ int main(int argc, char *argv[]) else if (argc > 2) usage(); #endif - - super_node_init(&sn); info("This is VILLASnode %s (built on %s, %s)", BLD(YEL(VERSION_STR)), BLD(MAG(__DATE__)), BLD(MAG(__TIME__))); @@ -93,7 +91,10 @@ int main(int argc, char *argv[]) error("Your kernel version is to old: required >= %u.%u", KERNEL_VERSION_MAJ, KERNEL_VERSION_MIN); signals_init(quit); + log_init(&sn.log, V, LOG_ALL); + log_start(&sn.log); + super_node_init(&sn); super_node_parse_cli(&sn, argc, argv); super_node_check(&sn); super_node_start(&sn); @@ -113,7 +114,7 @@ int main(int argc, char *argv[]) for (size_t j = 0; j < list_length(&p->hooks); j++) { struct hook *h = list_at(&p->hooks, j); - hook_run(h, HOOK_PERIODIC, NULL, 0); + hook_periodic(h); } }