From e3f85f0ae127e66ce57340b4f3a593c60dfce91b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Nohlg=C3=A5rd?= Date: Tue, 16 Oct 2018 19:11:47 +0200 Subject: [PATCH 1/3] spectrum-scanner: Run time performance improvements Experiments show that using ldexpf, ilogbf yields significantly faster run time performance on Cortex-M0+ without floating point hardware. --- spectrum-scanner/main.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/spectrum-scanner/main.c b/spectrum-scanner/main.c index 412ccfd..a228c97 100644 --- a/spectrum-scanner/main.c +++ b/spectrum-scanner/main.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 Eistec AB + * Copyright (C) 2017-2018 Eistec AB * * This file is subject to the terms and conditions of the GNU Lesser * General Public License v2.1. See the file LICENSE in the top level @@ -61,13 +61,14 @@ void spectrum_scanner(unsigned long interval_us) /* Using expf(x) (natural exponent) gives quicker computations on Cortex-M0+, * compared to using powf(10, x). */ /* - * This was optimized by testing different combinations of expf, powf, logf, log10f: + * This was optimized by testing different combinations of expf, powf, logf, log10f, ldexp, ilogbf: * - * functions used | measurement iterations per 0.5 s on reference system (frdm-kw41z) - * ------------------------------------------------------------------ - * expf, logf | 64 - * powf, log10f | 46 - * expf, log10f | 61 + * functions used | measurement iterations per 0.5 s on reference system (frdm-kw41z) + * -------------------------------------------------------------------- + * expf, logf | 64 + * powf, log10f | 46 + * expf, log10f | 61 + * ldexpf, ilogbf | 82 * no-op (baseline) | 83 (but the measurements are useless) */ @@ -105,11 +106,11 @@ void spectrum_scanner(unsigned long interval_us) } /* Convert dB to pseudo-energy before summing together the * measurements. "Pseudo" because we use the natural - * exponential function e^x instead of computing 10^x which + * exponential function 2^x instead of computing 10^x which * would be required if we needed the real measured energy. * There is no need to know the real energy level because we * will be converting back to dB again before printing. */ - ed_average[k][ch] += expf((float)level / 128.f); + ed_average[k][ch] += ldexpf(1.f, level); } } ++count; @@ -125,10 +126,10 @@ void spectrum_scanner(unsigned long interval_us) print("] ", 2); for (unsigned int ch = IEEE802154_CHANNEL_MIN; ch <= IEEE802154_CHANNEL_MAX; ++ch) { /* Compute the average pseudo-energy and convert back to dB */ - ed_average[k][ch] = logf(ed_average[k][ch] / count) * 128.f; + uint32_t ed = ilogbf(ed_average[k][ch] / count); print_u32_dec(ch); print(": ", 2); - print_float(ed_average[k][ch], 4); + print_s32_dec(ed); print(", ", 2); } print("\n", 1); From 644235e30d1f3bb624808382af4604bb3cce0fdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Nohlg=C3=A5rd?= Date: Fri, 26 Oct 2018 18:08:10 +0200 Subject: [PATCH 2/3] spectrum-scanner: Error if no network interfaces found --- spectrum-scanner/main.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spectrum-scanner/main.c b/spectrum-scanner/main.c index a228c97..52e4fec 100644 --- a/spectrum-scanner/main.c +++ b/spectrum-scanner/main.c @@ -57,6 +57,10 @@ void spectrum_scanner(unsigned long interval_us) { size_t netif_numof = gnrc_netif_numof(); + if (netif_numof == 0) { + puts("No network interfaces found!"); + return; + } /* Using expf(x) (natural exponent) gives quicker computations on Cortex-M0+, * compared to using powf(10, x). */ From 09775f0839c5ec30d0efe4e072f6d69cf71fc425 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Nohlg=C3=A5rd?= Date: Fri, 14 Dec 2018 11:01:19 +0100 Subject: [PATCH 3/3] fixup! spectrum-scanner: Run time performance improvements --- spectrum-scanner/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spectrum-scanner/main.c b/spectrum-scanner/main.c index 52e4fec..0473496 100644 --- a/spectrum-scanner/main.c +++ b/spectrum-scanner/main.c @@ -109,7 +109,7 @@ void spectrum_scanner(unsigned long interval_us) continue; } /* Convert dB to pseudo-energy before summing together the - * measurements. "Pseudo" because we use the natural + * measurements. "Pseudo" because we use the binary * exponential function 2^x instead of computing 10^x which * would be required if we needed the real measured energy. * There is no need to know the real energy level because we @@ -130,7 +130,7 @@ void spectrum_scanner(unsigned long interval_us) print("] ", 2); for (unsigned int ch = IEEE802154_CHANNEL_MIN; ch <= IEEE802154_CHANNEL_MAX; ++ch) { /* Compute the average pseudo-energy and convert back to dB */ - uint32_t ed = ilogbf(ed_average[k][ch] / count); + int32_t ed = ilogbf(ed_average[k][ch] / count); print_u32_dec(ch); print(": ", 2); print_s32_dec(ed);