From 14656232ad09f6327c8a50aca36327b177b982ed Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Mon, 13 Aug 2018 15:26:24 +0200 Subject: [PATCH] refactoring and code cleanups --- lib/hooks/jitter_calc.c | 2 +- lib/kernel/tc_netem.c | 2 +- lib/log_config.c | 11 +++-------- lib/memory/hugepage.c | 15 +++++++-------- lib/memory/ib.c | 4 ++-- 5 files changed, 14 insertions(+), 20 deletions(-) diff --git a/lib/hooks/jitter_calc.c b/lib/hooks/jitter_calc.c index 36ceaf2dd..1e202b57d 100644 --- a/lib/hooks/jitter_calc.c +++ b/lib/hooks/jitter_calc.c @@ -118,7 +118,7 @@ int jitter_calc_read(struct hook *h, struct sample *smps[], unsigned *cnt) stats("%s: jitter=%" PRId64 " usec, moving average=%" PRId64 " usec, moving variance=%" PRId64 " usec", __FUNCTION__, j->jitter_val[(j->curr_count + 1) % GPS_NTP_DELAY_WIN_SIZE], j->moving_avg[j->curr_count], j->moving_var[j->curr_count]); j->curr_count++; - if(j->curr_count >= GPS_NTP_DELAY_WIN_SIZE) + if (j->curr_count >= GPS_NTP_DELAY_WIN_SIZE) j->curr_count = 0; } diff --git a/lib/kernel/tc_netem.c b/lib/kernel/tc_netem.c index 208fed4c6..e33a3a253 100644 --- a/lib/kernel/tc_netem.c +++ b/lib/kernel/tc_netem.c @@ -264,7 +264,7 @@ int tc_netem_set_delay_distribution(struct rtnl_qdisc *qdisc, json_t *json) { if (json_is_string(json)) return rtnl_netem_set_delay_distribution(qdisc, json_string_value(json)); - else if (json_is_array(json)){ + else if (json_is_array(json)) { json_t *elm; size_t idx; size_t len = json_array_size(json); diff --git a/lib/log_config.c b/lib/log_config.c index 57293bb07..6266f0095 100644 --- a/lib/log_config.c +++ b/lib/log_config.c @@ -37,14 +37,14 @@ int log_parse_wrapper(struct log *l, json_t *cfg) json_t *json_logging = NULL; json_error_t err; - if(cfg) { + if (cfg) { ret = json_unpack_ex(cfg, &err, 0, "{s?: o}", "logging", &json_logging ); if (ret) jerror(&err, "Failed to parse logging from global configuration"); - if(json_logging) + if (json_logging) log_parse(l, json_logging); } @@ -91,12 +91,7 @@ void jerror(json_error_t *err, const char *fmt, ...) va_end(ap); log_print(l, LOG_LVL_ERROR, "%s:", buf); - { - log_print(l, LOG_LVL_ERROR, "%s in %s:%d:%d", err->text, err->source, err->line, err->column); - - if (l->syslog) - syslog(LOG_ERR, "%s in %s:%d:%d", err->text, err->source, err->line, err->column); - } + log_print(l, LOG_LVL_ERROR, " %s in %s:%d:%d", err->text, err->source, err->line, err->column); free(buf); diff --git a/lib/memory/hugepage.c b/lib/memory/hugepage.c index 4af4091e0..cc3c8b90b 100644 --- a/lib/memory/hugepage.c +++ b/lib/memory/hugepage.c @@ -72,27 +72,26 @@ static struct memory_allocation * memory_hugepage_alloc(struct memory_type *m, s ma->address = mmap(NULL, ma->length, prot, flags, -1, 0); if (ma->address == MAP_FAILED) { - //try again without hugepages as fallback solution, warn the user - + /* Try again without hugepages as fallback solution, warn the user */ prot= PROT_READ | PROT_WRITE; + /* Same flags as above without hugepages */ flags = MAP_PRIVATE | MAP_ANONYMOUS; #ifdef __linux__ - if (getuid() == 0){ + if (getuid() == 0) flags |= MAP_LOCKED; - } #endif /* Length has to be aligned with pagesize */ ma->length = ALIGN(len, kernel_get_page_size()); + /* Try mmap again */ ma->address = mmap(NULL, ma->length, prot, flags, -1, 0); - if(ma->address == MAP_FAILED){ + if (ma->address == MAP_FAILED) { free(ma); return NULL; } - else{ - warn("memory_hugepage_alloc: hugepage could not be mapped, mapped without hugepages instead!"); - } + + warn("memory_hugepage_alloc: hugepage could not be mapped, mapped without hugepages instead!"); } return ma; diff --git a/lib/memory/ib.c b/lib/memory/ib.c index 3a5f24da6..3141bf26f 100644 --- a/lib/memory/ib.c +++ b/lib/memory/ib.c @@ -55,11 +55,11 @@ static struct memory_allocation * memory_ib_alloc(struct memory_type *m, size_t ma->parent = mi->parent->alloc(mi->parent, len + sizeof(struct ibv_mr *), alignment); ma->address = ma->parent->address; - if(!mi->pd) + if (!mi->pd) error("Protection domain is not registered!"); ma->ib.mr = ibv_reg_mr(mi->pd, ma->address, ma->length, IBV_ACCESS_LOCAL_WRITE | IBV_ACCESS_REMOTE_WRITE); - if(!ma->ib.mr) { + if (!ma->ib.mr) { mi->parent->free(mi->parent, ma->parent); free(ma); return NULL;