Skip to content
Snippets Groups Projects
Commit 19351b5a authored by Sebastian Meiling's avatar Sebastian Meiling
Browse files

tests: enhance ps_schedstatistics

parent 3ac6d6c8
No related branches found
No related tags found
No related merge requests found
/* /*
* Copyright (C) 2017 OTA keys S.A. * Copyright (C) 2017 OTA keys S.A.
* 2017 HAW Hamburg
* *
* This file is subject to the terms and conditions of the GNU Lesser * 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 * General Public License v2.1. See the file LICENSE in the top level
...@@ -14,6 +15,7 @@ ...@@ -14,6 +15,7 @@
* @brief ps schedstatistics test app * @brief ps schedstatistics test app
* *
* @author Vincent Dupont <vincent@otakeys.com> * @author Vincent Dupont <vincent@otakeys.com>
* @author Sebastian Meiling <s@mlng.net>
* *
* @} * @}
*/ */
...@@ -25,23 +27,26 @@ ...@@ -25,23 +27,26 @@
#include <thread.h> #include <thread.h>
#include <xtimer.h> #include <xtimer.h>
#define NB_THREADS 5 #define NB_THREADS (5U)
static char stacks[NB_THREADS][THREAD_STACKSIZE_DEFAULT]; static char stacks[NB_THREADS][THREAD_STACKSIZE_DEFAULT];
static kernel_pid_t pids[NB_THREADS]; static kernel_pid_t pids[NB_THREADS];
static void *_thread_fn(void *arg) static void *_thread_fn(void *arg)
{ {
int next = (int)arg < NB_THREADS - 1 ? (int)arg + 1 : 0; int next = ((int)arg + 1) % NB_THREADS;
msg_t msg;
printf("Creating thread #%d, next=%d\n", (int)arg, next); printf("Creating thread #%d, next=%d\n", (int)arg, next);
while (1) { while (1) {
msg_receive(&msg); msg_t m1, m2;
xtimer_usleep(XTIMER_BACKOFF - 1); msg_receive(&m1);
xtimer_usleep(2 * XTIMER_BACKOFF); /* generate differents loads per thead */
msg_send(&msg, pids[next]); for (int i = 0; i < (10 * (next + 1)); ++i) {
_xtimer_now64();
}
xtimer_usleep(XTIMER_BACKOFF * 3);
msg_send(&m2, pids[next]);
} }
return NULL; return NULL;
...@@ -49,13 +54,14 @@ static void *_thread_fn(void *arg) ...@@ -49,13 +54,14 @@ static void *_thread_fn(void *arg)
int main(void) int main(void)
{ {
for (int i = 0; i < NB_THREADS; i++) { for (unsigned i = 0; i < NB_THREADS; ++i) {
pids[i] = thread_create(stacks[i], sizeof(stacks[i]), pids[i] = thread_create(stacks[i], sizeof(stacks[i]),
THREAD_PRIORITY_MAIN + 1, THREAD_PRIORITY_MAIN - 1,
THREAD_CREATE_STACKTEST, THREAD_CREATE_STACKTEST,
_thread_fn, (void *)i, "thread"); _thread_fn, (void *)i, "thread");
} }
/* sleep for a second, so that `ps` shows some % on idle at the beginning */
xtimer_sleep(1);
msg_t msg; msg_t msg;
msg_send(&msg, pids[0]); msg_send(&msg, pids[0]);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment