1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

Merge pull request #7048 from smlng/enh/ps/schedstats

schedstats: revert to 32Bit, and enhance output of schedstats
This commit is contained in:
Kaspar Schleiser 2017-09-28 16:08:51 +02:00 committed by GitHub
commit 5cc8204e10
4 changed files with 40 additions and 22 deletions

View File

@ -179,7 +179,7 @@ NORETURN void sched_task_exit(void);
* Scheduler statistics
*/
typedef struct {
uint64_t laststart; /**< Time stamp of the last time this thread was
uint32_t laststart; /**< Time stamp of the last time this thread was
scheduled to run */
unsigned int schedules; /**< How often the thread was scheduled to run */
uint64_t runtime_ticks; /**< The total runtime of this thread in ticks */

View File

@ -101,7 +101,7 @@ int __attribute__((used)) sched_run(void)
}
#ifdef MODULE_SCHEDSTATISTICS
uint64_t now = _xtimer_now64();
uint32_t now = xtimer_now().ticks32;
#endif
if (active_thread) {

View File

@ -61,10 +61,10 @@ void ps(void)
#endif
"%-9sQ | pri "
#ifdef DEVELHELP
"| stack ( used) | base | current "
"| stack ( used) | base addr | current "
#endif
#ifdef MODULE_SCHEDSTATISTICS
"| runtime | switches"
"| runtime | switches"
#endif
"\n",
#ifdef DEVELHELP
@ -77,13 +77,23 @@ void ps(void)
void *isr_start = thread_arch_isr_stack_start();
void *isr_sp = thread_arch_isr_stack_pointer();
printf("\t - | isr_stack | - - |"
" - | %5i (%5i) | %10p | %10p\n", ISR_STACKSIZE, isr_usage, isr_start, isr_sp);
" - | %6i (%5i) | %10p | %10p\n", ISR_STACKSIZE, isr_usage, isr_start, isr_sp);
overall_stacksz += ISR_STACKSIZE;
if (isr_usage > 0) {
overall_used += isr_usage;
}
#endif
#ifdef MODULE_SCHEDSTATISTICS
uint64_t rt_sum = 0;
for (kernel_pid_t i = KERNEL_PID_FIRST; i <= KERNEL_PID_LAST; i++) {
thread_t *p = (thread_t *)sched_threads[i];
if (p != NULL) {
rt_sum += sched_pidlist[i].runtime_ticks;
}
}
#endif /* MODULE_SCHEDSTATISTICS */
for (kernel_pid_t i = KERNEL_PID_FIRST; i <= KERNEL_PID_LAST; i++) {
thread_t *p = (thread_t *)sched_threads[i];
@ -98,9 +108,11 @@ void ps(void)
overall_used += stacksz;
#endif
#ifdef MODULE_SCHEDSTATISTICS
double runtime_ticks = sched_pidlist[i].runtime_ticks /
(double) _xtimer_now64() * 100;
int switches = sched_pidlist[i].schedules;
/* multiply with 100 for percentage and to avoid floats/doubles */
uint64_t runtime_ticks = sched_pidlist[i].runtime_ticks * 100;
unsigned runtime_major = runtime_ticks / rt_sum;
unsigned runtime_minor = ((runtime_ticks % rt_sum) * 1000) / rt_sum;
unsigned switches = sched_pidlist[i].schedules;
#endif
printf("\t%3" PRIkernel_pid
#ifdef DEVELHELP
@ -108,10 +120,10 @@ void ps(void)
#endif
" | %-8s %.1s | %3i"
#ifdef DEVELHELP
" | %5i (%5i) | %10p | %10p "
" | %6i (%5i) | %10p | %10p "
#endif
#ifdef MODULE_SCHEDSTATISTICS
" | %6.3f%% | %8d"
" | %2d.%03d%% | %8u"
#endif
"\n",
p->pid,
@ -123,14 +135,14 @@ void ps(void)
, p->stack_size, stacksz, (void *)p->stack_start, (void *)p->sp
#endif
#ifdef MODULE_SCHEDSTATISTICS
, runtime_ticks, switches
, runtime_major, runtime_minor, switches
#endif
);
}
}
#ifdef DEVELHELP
printf("\t%5s %-21s|%13s%6s %5i (%5i)\n", "|", "SUM", "|", "|",
printf("\t%5s %-21s|%13s%6s %6i (%5i)\n", "|", "SUM", "|", "|",
overall_stacksz, overall_used);
# ifdef MODULE_TLSF
puts("\nHeap usage:");

View File

@ -1,5 +1,6 @@
/*
* Copyright (C) 2017 OTA keys S.A.
* 2017 HAW Hamburg
*
* 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
@ -14,6 +15,7 @@
* @brief ps schedstatistics test app
*
* @author Vincent Dupont <vincent@otakeys.com>
* @author Sebastian Meiling <s@mlng.net>
*
* @}
*/
@ -25,23 +27,26 @@
#include <thread.h>
#include <xtimer.h>
#define NB_THREADS 5
#define NB_THREADS (5U)
static char stacks[NB_THREADS][THREAD_STACKSIZE_DEFAULT];
static kernel_pid_t pids[NB_THREADS];
static void *_thread_fn(void *arg)
{
int next = (int)arg < NB_THREADS - 1 ? (int)arg + 1 : 0;
msg_t msg;
int next = ((int)arg + 1) % NB_THREADS;
printf("Creating thread #%d, next=%d\n", (int)arg, next);
while (1) {
msg_receive(&msg);
xtimer_usleep(XTIMER_BACKOFF - 1);
xtimer_usleep(2 * XTIMER_BACKOFF);
msg_send(&msg, pids[next]);
msg_t m1, m2;
msg_receive(&m1);
/* generate differents loads per thead */
for (int i = 0; i < (10 * (next + 1)); ++i) {
_xtimer_now64();
}
xtimer_usleep(XTIMER_BACKOFF * 3);
msg_send(&m2, pids[next]);
}
return NULL;
@ -49,13 +54,14 @@ static void *_thread_fn(void *arg)
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]),
THREAD_PRIORITY_MAIN + 1,
THREAD_PRIORITY_MAIN - 1,
THREAD_CREATE_STACKTEST,
_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_send(&msg, pids[0]);