mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
Merge pull request #7786 from kaspar030/add_some_benchmarks
tests: add some benchmarks
This commit is contained in:
commit
99460669d3
12
tests/bench_msg_pingpong/Makefile
Normal file
12
tests/bench_msg_pingpong/Makefile
Normal file
@ -0,0 +1,12 @@
|
||||
include ../Makefile.tests_common
|
||||
|
||||
BOARD_INSUFFICIENT_MEMORY := nucleo-f031k6
|
||||
|
||||
USEMODULE += xtimer
|
||||
|
||||
TEST_ON_CI_WHITELIST += all
|
||||
|
||||
include $(RIOTBASE)/Makefile.include
|
||||
|
||||
test:
|
||||
tests/01-run.py
|
9
tests/bench_msg_pingpong/README.md
Normal file
9
tests/bench_msg_pingpong/README.md
Normal file
@ -0,0 +1,9 @@
|
||||
# About
|
||||
|
||||
This test will measure the amount of messages that could be sent from one
|
||||
thread to another during an interval of one second. The result amounts to the
|
||||
number of messages sent, which is half the number of context switches incurred
|
||||
through sending the messages.
|
||||
|
||||
This test application intentionally duplicates code with some similar benchmark
|
||||
applications in order to be able to compare code sizes.
|
81
tests/bench_msg_pingpong/main.c
Normal file
81
tests/bench_msg_pingpong/main.c
Normal file
@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Kaspar Schleiser <kaspar@schleiser.de>
|
||||
*
|
||||
* 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 messages send per second
|
||||
*
|
||||
* @author Kaspar Schleiser <kaspar@schleiser.de>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "thread.h"
|
||||
|
||||
#include "msg.h"
|
||||
#include "xtimer.h"
|
||||
|
||||
#ifndef TEST_DURATION
|
||||
#define TEST_DURATION (1000000U)
|
||||
#endif
|
||||
|
||||
volatile unsigned _flag = 0;
|
||||
static char _stack[THREAD_STACKSIZE_MAIN];
|
||||
|
||||
static void _timer_callback(void*arg)
|
||||
{
|
||||
(void)arg;
|
||||
|
||||
_flag = 1;
|
||||
}
|
||||
|
||||
static void *_second_thread(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
msg_t test;
|
||||
|
||||
while(1) {
|
||||
msg_receive(&test);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
printf("main starting\n");
|
||||
|
||||
kernel_pid_t other = thread_create(_stack,
|
||||
sizeof(_stack),
|
||||
(THREAD_PRIORITY_MAIN - 1),
|
||||
THREAD_CREATE_STACKTEST,
|
||||
_second_thread,
|
||||
NULL,
|
||||
"second_thread");
|
||||
|
||||
xtimer_t timer;
|
||||
timer.callback = _timer_callback;
|
||||
|
||||
msg_t test;
|
||||
|
||||
uint32_t n = 0;
|
||||
|
||||
xtimer_set(&timer, TEST_DURATION);
|
||||
while(!_flag) {
|
||||
msg_send(&test, other);
|
||||
n++;
|
||||
}
|
||||
|
||||
printf("{ \"result\" : %"PRIu32" }\n", n);
|
||||
|
||||
return 0;
|
||||
}
|
21
tests/bench_msg_pingpong/tests/01-run.py
Executable file
21
tests/bench_msg_pingpong/tests/01-run.py
Executable file
@ -0,0 +1,21 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Copyright (C) 2018 Kaspar Schleiser <kaspar@schleiser.de>
|
||||
# 2017 Sebastian Meiling <s@mlng.net>
|
||||
#
|
||||
# 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
|
||||
|
||||
|
||||
def testfunc(child):
|
||||
child.expect(r"{ \"result\" : \d+ }")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.path.append(os.path.join(os.environ['RIOTTOOLS'], 'testrunner'))
|
||||
from testrunner import run
|
||||
sys.exit(run(testfunc))
|
12
tests/bench_mutex_pingpong/Makefile
Normal file
12
tests/bench_mutex_pingpong/Makefile
Normal file
@ -0,0 +1,12 @@
|
||||
include ../Makefile.tests_common
|
||||
|
||||
BOARD_INSUFFICIENT_MEMORY := nucleo-f031k6
|
||||
|
||||
USEMODULE += xtimer
|
||||
|
||||
TEST_ON_CI_WHITELIST += all
|
||||
|
||||
include $(RIOTBASE)/Makefile.include
|
||||
|
||||
test:
|
||||
tests/01-run.py
|
8
tests/bench_mutex_pingpong/README.md
Normal file
8
tests/bench_mutex_pingpong/README.md
Normal file
@ -0,0 +1,8 @@
|
||||
# About
|
||||
|
||||
In this test, one thread will repeatedly lock a mutex, while another thread
|
||||
will unlock it. The result is the number of unlocks done in an interval of one
|
||||
second, which amounts to half the number of incurred context switches.
|
||||
|
||||
This test application intentionally duplicates code with some similar benchmark
|
||||
applications in order to be able to compare code sizes.
|
84
tests/bench_mutex_pingpong/main.c
Normal file
84
tests/bench_mutex_pingpong/main.c
Normal file
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Kaspar Schleiser <kaspar@schleiser.de>
|
||||
*
|
||||
* 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 Mutex context switch benchmark
|
||||
*
|
||||
* @author Kaspar Schleiser <kaspar@schleiser.de>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "mutex.h"
|
||||
#include "thread.h"
|
||||
#include "xtimer.h"
|
||||
|
||||
#ifndef TEST_DURATION
|
||||
#define TEST_DURATION (1000000U)
|
||||
#endif
|
||||
|
||||
volatile unsigned _flag = 0;
|
||||
static char _stack[THREAD_STACKSIZE_MAIN];
|
||||
static mutex_t _mutex = MUTEX_INIT;
|
||||
|
||||
static void _timer_callback(void*arg)
|
||||
{
|
||||
(void)arg;
|
||||
|
||||
_flag = 1;
|
||||
}
|
||||
|
||||
|
||||
static void *_second_thread(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
|
||||
while(1) {
|
||||
mutex_lock(&_mutex);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
printf("main starting\n");
|
||||
|
||||
thread_create(_stack,
|
||||
sizeof(_stack),
|
||||
THREAD_PRIORITY_MAIN - 1,
|
||||
THREAD_CREATE_WOUT_YIELD | THREAD_CREATE_STACKTEST,
|
||||
_second_thread,
|
||||
NULL,
|
||||
"second_thread");
|
||||
|
||||
/* lock the mutex, then yield to second_thread */
|
||||
mutex_lock(&_mutex);
|
||||
thread_yield_higher();
|
||||
|
||||
xtimer_t timer;
|
||||
timer.callback = _timer_callback;
|
||||
|
||||
uint32_t n = 0;
|
||||
|
||||
xtimer_set(&timer, TEST_DURATION);
|
||||
while(!_flag) {
|
||||
mutex_unlock(&_mutex);
|
||||
n++;
|
||||
}
|
||||
|
||||
printf("{ \"result\" : %"PRIu32" }\n", n);
|
||||
|
||||
return 0;
|
||||
}
|
21
tests/bench_mutex_pingpong/tests/01-run.py
Executable file
21
tests/bench_mutex_pingpong/tests/01-run.py
Executable file
@ -0,0 +1,21 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Copyright (C) 2018 Kaspar Schleiser <kaspar@schleiser.de>
|
||||
# 2017 Sebastian Meiling <s@mlng.net>
|
||||
#
|
||||
# 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
|
||||
|
||||
|
||||
def testfunc(child):
|
||||
child.expect(r"{ \"result\" : \d+ }")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.path.append(os.path.join(os.environ['RIOTTOOLS'], 'testrunner'))
|
||||
from testrunner import run
|
||||
sys.exit(run(testfunc))
|
10
tests/bench_sched_nop/Makefile
Normal file
10
tests/bench_sched_nop/Makefile
Normal file
@ -0,0 +1,10 @@
|
||||
include ../Makefile.tests_common
|
||||
|
||||
USEMODULE += xtimer
|
||||
|
||||
TEST_ON_CI_WHITELIST += all
|
||||
|
||||
include $(RIOTBASE)/Makefile.include
|
||||
|
||||
test:
|
||||
tests/01-run.py
|
10
tests/bench_sched_nop/README.md
Normal file
10
tests/bench_sched_nop/README.md
Normal file
@ -0,0 +1,10 @@
|
||||
# About
|
||||
|
||||
This test calls "thread_yield()" in a loop. As there is no other thread with a
|
||||
higher or same priority, this measures the raw context save / restore
|
||||
performance plus the (short) time the scheduler need to realize there's no
|
||||
other active thread.
|
||||
The result amounts to the number of thread_yield() calls per second.
|
||||
|
||||
This test application intentionally duplicates code with some similar benchmark
|
||||
applications in order to be able to compare code sizes.
|
57
tests/bench_sched_nop/main.c
Normal file
57
tests/bench_sched_nop/main.c
Normal file
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Kaspar Schleiser <kaspar@schleiser.de>
|
||||
*
|
||||
* 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 Scheduler benchmark test application
|
||||
*
|
||||
* @author Kaspar Schleiser <kaspar@schleiser.de>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "thread.h"
|
||||
|
||||
#include "xtimer.h"
|
||||
|
||||
#ifndef TEST_DURATION
|
||||
#define TEST_DURATION (1000000U)
|
||||
#endif
|
||||
|
||||
volatile unsigned _flag = 0;
|
||||
|
||||
static void _timer_callback(void*arg)
|
||||
{
|
||||
(void)arg;
|
||||
|
||||
_flag = 1;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
printf("main starting\n");
|
||||
|
||||
xtimer_t timer;
|
||||
timer.callback = _timer_callback;
|
||||
|
||||
uint32_t n = 0;
|
||||
|
||||
xtimer_set(&timer, TEST_DURATION);
|
||||
while(!_flag) {
|
||||
thread_yield();
|
||||
n++;
|
||||
}
|
||||
|
||||
printf("{ \"result\" : %"PRIu32" }\n", n);
|
||||
|
||||
return 0;
|
||||
}
|
21
tests/bench_sched_nop/tests/01-run.py
Executable file
21
tests/bench_sched_nop/tests/01-run.py
Executable file
@ -0,0 +1,21 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Copyright (C) 2018 Kaspar Schleiser <kaspar@schleiser.de>
|
||||
# 2017 Sebastian Meiling <s@mlng.net>
|
||||
#
|
||||
# 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
|
||||
|
||||
|
||||
def testfunc(child):
|
||||
child.expect(r"{ \"result\" : \d+ }")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.path.append(os.path.join(os.environ['RIOTTOOLS'], 'testrunner'))
|
||||
from testrunner import run
|
||||
sys.exit(run(testfunc))
|
13
tests/bench_thread_flags_pingpong/Makefile
Normal file
13
tests/bench_thread_flags_pingpong/Makefile
Normal file
@ -0,0 +1,13 @@
|
||||
include ../Makefile.tests_common
|
||||
|
||||
BOARD_INSUFFICIENT_MEMORY := nucleo-f031k6
|
||||
|
||||
USEMODULE += core_thread_flags
|
||||
USEMODULE += xtimer
|
||||
|
||||
TEST_ON_CI_WHITELIST += all
|
||||
|
||||
include $(RIOTBASE)/Makefile.include
|
||||
|
||||
test:
|
||||
tests/01-run.py
|
9
tests/bench_thread_flags_pingpong/README.md
Normal file
9
tests/bench_thread_flags_pingpong/README.md
Normal file
@ -0,0 +1,9 @@
|
||||
# About
|
||||
|
||||
This test measures the number of times one thread can set (and wakeup) another
|
||||
thread using thread_flags(). The result amounts to the number of times the
|
||||
thread flag was set, which is half the number of context switches incurred in
|
||||
that time.
|
||||
|
||||
This test application intentionally duplicates code with some similar benchmark
|
||||
applications in order to be able to compare code sizes.
|
80
tests/bench_thread_flags_pingpong/main.c
Normal file
80
tests/bench_thread_flags_pingpong/main.c
Normal file
@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Kaspar Schleiser <kaspar@schleiser.de>
|
||||
*
|
||||
* 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 Thread flags benchmark test application
|
||||
*
|
||||
* @author Kaspar Schleiser <kaspar@schleiser.de>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "thread.h"
|
||||
|
||||
#include "thread_flags.h"
|
||||
#include "xtimer.h"
|
||||
|
||||
#ifndef TEST_DURATION
|
||||
#define TEST_DURATION (1000000U)
|
||||
#endif
|
||||
|
||||
volatile unsigned _flag = 0;
|
||||
static char _stack[THREAD_STACKSIZE_MAIN];
|
||||
|
||||
static void _timer_callback(void*arg)
|
||||
{
|
||||
(void)arg;
|
||||
|
||||
_flag = 1;
|
||||
}
|
||||
|
||||
static void *_second_thread(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
|
||||
while(1) {
|
||||
thread_flags_wait_any(0x0 - 1);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
printf("main starting\n");
|
||||
|
||||
kernel_pid_t other = thread_create(_stack,
|
||||
sizeof(_stack),
|
||||
(THREAD_PRIORITY_MAIN - 1),
|
||||
THREAD_CREATE_STACKTEST,
|
||||
_second_thread,
|
||||
NULL,
|
||||
"second_thread");
|
||||
|
||||
thread_t *tcb = (thread_t *)sched_threads[other];
|
||||
|
||||
xtimer_t timer;
|
||||
timer.callback = _timer_callback;
|
||||
|
||||
uint32_t n = 0;
|
||||
|
||||
xtimer_set(&timer, TEST_DURATION);
|
||||
while(!_flag) {
|
||||
thread_flags_set(tcb, 0x1);
|
||||
n++;
|
||||
}
|
||||
|
||||
printf("{ \"result\" : %"PRIu32" }\n", n);
|
||||
|
||||
return 0;
|
||||
}
|
21
tests/bench_thread_flags_pingpong/tests/01-run.py
Executable file
21
tests/bench_thread_flags_pingpong/tests/01-run.py
Executable file
@ -0,0 +1,21 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Copyright (C) 2018 Kaspar Schleiser <kaspar@schleiser.de>
|
||||
# 2017 Sebastian Meiling <s@mlng.net>
|
||||
#
|
||||
# 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
|
||||
|
||||
|
||||
def testfunc(child):
|
||||
child.expect(r"{ \"result\" : \d+ }")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.path.append(os.path.join(os.environ['RIOTTOOLS'], 'testrunner'))
|
||||
from testrunner import run
|
||||
sys.exit(run(testfunc))
|
12
tests/bench_thread_yield_pingpong/Makefile
Normal file
12
tests/bench_thread_yield_pingpong/Makefile
Normal file
@ -0,0 +1,12 @@
|
||||
include ../Makefile.tests_common
|
||||
|
||||
BOARD_INSUFFICIENT_MEMORY := nucleo-f031k6
|
||||
|
||||
USEMODULE += xtimer
|
||||
|
||||
TEST_ON_CI_WHITELIST += all
|
||||
|
||||
include $(RIOTBASE)/Makefile.include
|
||||
|
||||
test:
|
||||
tests/01-run.py
|
8
tests/bench_thread_yield_pingpong/README.md
Normal file
8
tests/bench_thread_yield_pingpong/README.md
Normal file
@ -0,0 +1,8 @@
|
||||
# About
|
||||
|
||||
This test measures the amount of context switches between two threads of the
|
||||
same priority. The result amounts to the number of thread_yield() calls in
|
||||
*one* thread (half the number of actual context switches).
|
||||
|
||||
This test application intentionally duplicates code with some similar benchmark
|
||||
applications in order to be able to compare code sizes.
|
77
tests/bench_thread_yield_pingpong/main.c
Normal file
77
tests/bench_thread_yield_pingpong/main.c
Normal file
@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Kaspar Schleiser <kaspar@schleiser.de>
|
||||
*
|
||||
* 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 Context switch benchmark test application
|
||||
*
|
||||
* @author Kaspar Schleiser <kaspar@schleiser.de>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "thread.h"
|
||||
#include "xtimer.h"
|
||||
|
||||
#ifndef TEST_DURATION
|
||||
#define TEST_DURATION (1000000U)
|
||||
#endif
|
||||
|
||||
volatile unsigned _flag = 0;
|
||||
static char _stack[THREAD_STACKSIZE_MAIN];
|
||||
|
||||
static void _timer_callback(void*arg)
|
||||
{
|
||||
(void)arg;
|
||||
|
||||
_flag = 1;
|
||||
}
|
||||
|
||||
static void *_second_thread(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
|
||||
while(1) {
|
||||
thread_yield();
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
printf("main starting\n");
|
||||
|
||||
thread_create(_stack,
|
||||
sizeof(_stack),
|
||||
THREAD_PRIORITY_MAIN,
|
||||
THREAD_CREATE_STACKTEST,
|
||||
_second_thread,
|
||||
NULL,
|
||||
"second_thread");
|
||||
|
||||
xtimer_t timer;
|
||||
timer.callback = _timer_callback;
|
||||
|
||||
uint32_t n = 0;
|
||||
|
||||
xtimer_set(&timer, TEST_DURATION);
|
||||
while(!_flag) {
|
||||
thread_yield();
|
||||
n++;
|
||||
}
|
||||
|
||||
printf("{ \"result\" : %"PRIu32" }\n", n);
|
||||
|
||||
return 0;
|
||||
}
|
21
tests/bench_thread_yield_pingpong/tests/01-run.py
Executable file
21
tests/bench_thread_yield_pingpong/tests/01-run.py
Executable file
@ -0,0 +1,21 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Copyright (C) 2018 Kaspar Schleiser <kaspar@schleiser.de>
|
||||
# 2017 Sebastian Meiling <s@mlng.net>
|
||||
#
|
||||
# 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
|
||||
|
||||
|
||||
def testfunc(child):
|
||||
child.expect(r"{ \"result\" : \d+ }")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.path.append(os.path.join(os.environ['RIOTTOOLS'], 'testrunner'))
|
||||
from testrunner import run
|
||||
sys.exit(run(testfunc))
|
Loading…
Reference in New Issue
Block a user