diff --git a/tests/bench_runtime_coreapis/Makefile b/tests/bench_runtime_coreapis/Makefile new file mode 100644 index 0000000000..14f75fd6b7 --- /dev/null +++ b/tests/bench_runtime_coreapis/Makefile @@ -0,0 +1,12 @@ +include ../Makefile.tests_common + +# we use thread flags in this benchmark by default, disable on demand +USEMODULE += core_thread_flags +USEMODULE += benchmark + +TEST_ON_CI_WHITELIST += all + +include $(RIOTBASE)/Makefile.include + +test: + tests/01-run.py diff --git a/tests/bench_runtime_coreapis/README.md b/tests/bench_runtime_coreapis/README.md new file mode 100644 index 0000000000..3a345451b9 --- /dev/null +++ b/tests/bench_runtime_coreapis/README.md @@ -0,0 +1,7 @@ +# Measure Runtime of Selected Core API functions + +This benchmark application measures the runtime of selected core API functions. +Its purpose is to provide a baseline to assess the impacts when doing changes to +core code. + +This application is not complete, simply add additional runs if needed. diff --git a/tests/bench_runtime_coreapis/main.c b/tests/bench_runtime_coreapis/main.c new file mode 100644 index 0000000000..5692d5e4cd --- /dev/null +++ b/tests/bench_runtime_coreapis/main.c @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2018 Freie Universität Berlin + * + * 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 + * directory for more details. + */ + +/** + * @ingroup tests + * @{ + * + * @file + * @brief Measure runtime of select core API functions + * + * @author Hauke Petersen + * + * @} + */ + +#include + +#include "mutex.h" +#include "benchmark.h" +#include "thread.h" +#include "thread_flags.h" + +#ifndef BENCH_RUNS +#define BENCH_RUNS (1000UL * 1000UL) +#endif + +static mutex_t _lock; +static thread_t *t; +static thread_flags_t _flag = 0x0001; +static msg_t _msg; + +static void _mutex_lockunlock(void) +{ + mutex_lock(&_lock); + mutex_unlock(&_lock); +} + +static void _flag_waitany(void) +{ + thread_flags_set(t, _flag); + thread_flags_wait_any(_flag); +} + +static void _flag_waitall(void) +{ + thread_flags_set(t, _flag); + thread_flags_wait_all(_flag); +} + +static void _flag_waitone(void) +{ + thread_flags_set(t, _flag); + thread_flags_wait_one(_flag); +} + +int main(void) +{ + puts("Runtime of Selected Core API functions\n"); + + t = (thread_t *)sched_active_thread; + + BENCHMARK_FUNC("nop loop", BENCH_RUNS, __asm__ volatile ("nop")); + puts(""); + BENCHMARK_FUNC("mutex_init()", BENCH_RUNS, mutex_init(&_lock)); + BENCHMARK_FUNC("mutex lock/unlock", BENCH_RUNS, _mutex_lockunlock()); + puts(""); + BENCHMARK_FUNC("thread_flags_set()", BENCH_RUNS, thread_flags_set(t, _flag)); + BENCHMARK_FUNC("thread_flags_clear()", BENCH_RUNS, thread_flags_clear(_flag)); + BENCHMARK_FUNC("thread flags set/wait any", BENCH_RUNS, _flag_waitany()); + BENCHMARK_FUNC("thread flags set/wait all", BENCH_RUNS, _flag_waitall()); + BENCHMARK_FUNC("thread flags set/wait one", BENCH_RUNS, _flag_waitone()); + puts(""); + BENCHMARK_FUNC("msg_try_receive()", BENCH_RUNS, msg_try_receive(&_msg)); + BENCHMARK_FUNC("msg_avail()", BENCH_RUNS, msg_avail()); + + puts("\n[SUCCESS]"); + return 0; +} diff --git a/tests/bench_runtime_coreapis/tests/01-run.py b/tests/bench_runtime_coreapis/tests/01-run.py new file mode 100755 index 0000000000..d741442230 --- /dev/null +++ b/tests/bench_runtime_coreapis/tests/01-run.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python3 + +# Copyright (C) 2018 Freie Universität Berlin +# +# 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 +# directory for more details. + +import os +import sys + + +# The default timeout is not enough for this test on some of the slower boards +TIMEOUT = 30 + + +def testfunc(child): + child.expect_exact('[SUCCESS]', timeout=TIMEOUT) + + +if __name__ == "__main__": + sys.path.append(os.path.join(os.environ['RIOTTOOLS'], 'testrunner')) + from testrunner import run + sys.exit(run(testfunc)) diff --git a/tests/periph_gpio/tests/02-bench.py b/tests/periph_gpio/tests/02-bench.py index 954089ea06..e1cc79c21f 100755 --- a/tests/periph_gpio/tests/02-bench.py +++ b/tests/periph_gpio/tests/02-bench.py @@ -16,12 +16,12 @@ def testfunc(child): for pin in range(0, 8): child.sendline("bench 0 {}".format(pin)) - child.expect(r" *nop loop: +(\d+)us --- +(\d+\.\d+)us per call") - child.expect(r" *gpio_set: +(\d+)us --- +(\d+\.\d+)us per call") - child.expect(r" *gpio_clear: +(\d+)us --- +(\d+\.\d+)us per call") - child.expect(r" *gpio_toggle: +(\d+)us --- +(\d+\.\d+)us per call") - child.expect(r" *gpio_read: +(\d+)us --- +(\d+\.\d+)us per call") - child.expect(r" *gpio_write: +(\d+)us --- +(\d+\.\d+)us per call") + child.expect(r" *nop loop: +(\d+)us --- +(\d+\.\d+)us per call --- +(\d+) calls per sec") + child.expect(r" *gpio_set: +(\d+)us --- +(\d+\.\d+)us per call --- +(\d+) calls per sec") + child.expect(r" *gpio_clear: +(\d+)us --- +(\d+\.\d+)us per call --- +(\d+) calls per sec") + child.expect(r" *gpio_toggle: +(\d+)us --- +(\d+\.\d+)us per call --- +(\d+) calls per sec") + child.expect(r" *gpio_read: +(\d+)us --- +(\d+\.\d+)us per call --- +(\d+) calls per sec") + child.expect(r" *gpio_write: +(\d+)us --- +(\d+\.\d+)us per call --- +(\d+) calls per sec") child.expect_exact(" --- DONE ---") child.expect_exact(">")