Merge pull request #11935 from fjmolinas/pr_schedstatistics_module
sys: add schedstatistics module
This commit is contained in:
commit
9cf1da9f04
@ -203,29 +203,6 @@ extern clist_node_t sched_runqueues[SCHED_PRIO_LEVELS];
|
|||||||
*/
|
*/
|
||||||
NORETURN void sched_task_exit(void);
|
NORETURN void sched_task_exit(void);
|
||||||
|
|
||||||
#ifdef MODULE_SCHEDSTATISTICS
|
|
||||||
/**
|
|
||||||
* Scheduler statistics
|
|
||||||
*/
|
|
||||||
typedef struct {
|
|
||||||
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 */
|
|
||||||
} schedstat_t;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Thread statistics table
|
|
||||||
*/
|
|
||||||
extern schedstat_t sched_pidlist[KERNEL_PID_LAST + 1];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Registers the sched statistics callback and sets laststart for
|
|
||||||
* caller thread
|
|
||||||
*/
|
|
||||||
void init_schedstatistics(void);
|
|
||||||
#endif /* MODULE_SCHEDSTATISTICS */
|
|
||||||
|
|
||||||
#ifdef MODULE_SCHED_CB
|
#ifdef MODULE_SCHED_CB
|
||||||
/**
|
/**
|
||||||
* @brief Register a callback that will be called on every scheduler run
|
* @brief Register a callback that will be called on every scheduler run
|
||||||
|
|||||||
34
core/sched.c
34
core/sched.c
@ -33,10 +33,6 @@
|
|||||||
#include "mpu.h"
|
#include "mpu.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef MODULE_SCHEDSTATISTICS
|
|
||||||
#include "xtimer.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define ENABLE_DEBUG (0)
|
#define ENABLE_DEBUG (0)
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
@ -77,9 +73,6 @@ const uint8_t _tcb_name_offset = offsetof(thread_t, name);
|
|||||||
#ifdef MODULE_SCHED_CB
|
#ifdef MODULE_SCHED_CB
|
||||||
static void (*sched_cb) (kernel_pid_t active_thread, kernel_pid_t next_thread) = NULL;
|
static void (*sched_cb) (kernel_pid_t active_thread, kernel_pid_t next_thread) = NULL;
|
||||||
#endif
|
#endif
|
||||||
#ifdef MODULE_SCHEDSTATISTICS
|
|
||||||
schedstat_t sched_pidlist[KERNEL_PID_LAST + 1];
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int __attribute__((used)) sched_run(void)
|
int __attribute__((used)) sched_run(void)
|
||||||
{
|
{
|
||||||
@ -212,30 +205,3 @@ void sched_register_cb(void (*callback)(kernel_pid_t, kernel_pid_t))
|
|||||||
sched_cb = callback;
|
sched_cb = callback;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef MODULE_SCHEDSTATISTICS
|
|
||||||
void sched_statistics_cb(kernel_pid_t active_thread, kernel_pid_t next_thread)
|
|
||||||
{
|
|
||||||
uint32_t now = xtimer_now().ticks32;
|
|
||||||
|
|
||||||
/* Update active thread runtime, there is always an active thread since
|
|
||||||
first sched_run happens when main_trampoline gets scheduled */
|
|
||||||
schedstat_t *active_stat = &sched_pidlist[active_thread];
|
|
||||||
active_stat->runtime_ticks += now - active_stat->laststart;
|
|
||||||
|
|
||||||
/* Update next_thread stats */
|
|
||||||
schedstat_t *next_stat = &sched_pidlist[next_thread];
|
|
||||||
next_stat->laststart = now;
|
|
||||||
next_stat->schedules++;
|
|
||||||
}
|
|
||||||
|
|
||||||
void init_schedstatistics(void)
|
|
||||||
{
|
|
||||||
/* Init laststart for the thread starting schedstatistics since the callback
|
|
||||||
wasn't registered when it was first scheduled */
|
|
||||||
schedstat_t *active_stat = &sched_pidlist[sched_active_pid];
|
|
||||||
active_stat->laststart = xtimer_now().ticks32;
|
|
||||||
active_stat->schedules = 1;
|
|
||||||
sched_register_cb(sched_statistics_cb);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|||||||
@ -71,7 +71,6 @@ PSEUDOMODULES += saul_default
|
|||||||
PSEUDOMODULES += saul_gpio
|
PSEUDOMODULES += saul_gpio
|
||||||
PSEUDOMODULES += saul_nrf_temperature
|
PSEUDOMODULES += saul_nrf_temperature
|
||||||
PSEUDOMODULES += scanf_float
|
PSEUDOMODULES += scanf_float
|
||||||
PSEUDOMODULES += schedstatistics
|
|
||||||
PSEUDOMODULES += sched_cb
|
PSEUDOMODULES += sched_cb
|
||||||
PSEUDOMODULES += semtech_loramac_rx
|
PSEUDOMODULES += semtech_loramac_rx
|
||||||
PSEUDOMODULES += sock
|
PSEUDOMODULES += sock
|
||||||
|
|||||||
@ -93,7 +93,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef MODULE_SCHEDSTATISTICS
|
#ifdef MODULE_SCHEDSTATISTICS
|
||||||
#include "sched.h"
|
#include "schedstatistics.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define ENABLE_DEBUG (0)
|
#define ENABLE_DEBUG (0)
|
||||||
|
|||||||
65
sys/include/schedstatistics.h
Normal file
65
sys/include/schedstatistics.h
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2014 Freie Universität Berlin
|
||||||
|
* 2019 Inria
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @defgroup schedstatistics Schedstatistics
|
||||||
|
* @ingroup sys
|
||||||
|
* @brief When including this module scheduler statistics
|
||||||
|
* (@ref schedstat_t) for a thread will be updated on every
|
||||||
|
* @ref sched_run().
|
||||||
|
*
|
||||||
|
* @note If auto_init is disabled `init_schedstatistics()` needs to be
|
||||||
|
* called as well as xtimer_init().
|
||||||
|
* @{
|
||||||
|
*
|
||||||
|
* @file
|
||||||
|
* @brief Scheduler statisctics
|
||||||
|
*
|
||||||
|
* @author Kaspar Schleiser <kaspar@schleiser.de>
|
||||||
|
* @author Francisco Molina <francois-xavier.molina@inria.fr>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef SCHEDSTATISTICS_H
|
||||||
|
#define SCHEDSTATISTICS_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include "kernel_types.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scheduler statistics
|
||||||
|
*/
|
||||||
|
typedef struct {
|
||||||
|
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 */
|
||||||
|
} schedstat_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Thread statistics table
|
||||||
|
*/
|
||||||
|
extern schedstat_t sched_pidlist[KERNEL_PID_LAST + 1];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Registers the sched statistics callback and sets laststart for
|
||||||
|
* caller thread
|
||||||
|
*/
|
||||||
|
void init_schedstatistics(void);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* SCHEDSTATISTICS_H */
|
||||||
|
/** @} */
|
||||||
@ -22,6 +22,10 @@
|
|||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
#include "kernel_types.h"
|
#include "kernel_types.h"
|
||||||
|
|
||||||
|
#ifdef MODULE_SCHEDSTATISTICS
|
||||||
|
#include "schedstatistics.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef MODULE_TLSF_MALLOC
|
#ifdef MODULE_TLSF_MALLOC
|
||||||
#include "tlsf.h"
|
#include "tlsf.h"
|
||||||
#include "tlsf-malloc.h"
|
#include "tlsf-malloc.h"
|
||||||
|
|||||||
1
sys/schedstatistics/Makefile
Normal file
1
sys/schedstatistics/Makefile
Normal file
@ -0,0 +1 @@
|
|||||||
|
include $(RIOTBASE)/Makefile.base
|
||||||
53
sys/schedstatistics/schedstatistics.c
Normal file
53
sys/schedstatistics/schedstatistics.c
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2014 Freie Universität Berlin
|
||||||
|
* 2019 Inria
|
||||||
|
*
|
||||||
|
* 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 sys
|
||||||
|
* @{
|
||||||
|
*
|
||||||
|
* @file
|
||||||
|
* @brief Scheduler statistics implementation
|
||||||
|
*
|
||||||
|
* @author Kaspar Schleiser <kaspar@schleiser.de>
|
||||||
|
* @author René Kijewski <rene.kijewski@fu-berlin.de>
|
||||||
|
* @author Francisco Molina <francois-xavier.molina@inria.fr>
|
||||||
|
*
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "sched.h"
|
||||||
|
#include "xtimer.h"
|
||||||
|
#include "schedstatistics.h"
|
||||||
|
|
||||||
|
schedstat_t sched_pidlist[KERNEL_PID_LAST + 1];
|
||||||
|
|
||||||
|
void sched_statistics_cb(kernel_pid_t active_thread, kernel_pid_t next_thread)
|
||||||
|
{
|
||||||
|
uint32_t now = xtimer_now().ticks32;
|
||||||
|
|
||||||
|
/* Update active thread runtime, there is allways an active thread since
|
||||||
|
first sched_run happens when main_trampoline gets scheduled */
|
||||||
|
schedstat_t *active_stat = &sched_pidlist[active_thread];
|
||||||
|
active_stat->runtime_ticks += now - active_stat->laststart;
|
||||||
|
|
||||||
|
/* Update next_thread stats */
|
||||||
|
schedstat_t *next_stat = &sched_pidlist[next_thread];
|
||||||
|
next_stat->laststart = now;
|
||||||
|
next_stat->schedules++;
|
||||||
|
}
|
||||||
|
|
||||||
|
void init_schedstatistics(void)
|
||||||
|
{
|
||||||
|
/* Init laststart for the thread starting schedstatistics since the callback
|
||||||
|
wasn't registered when it was first scheduled */
|
||||||
|
schedstat_t *active_stat = &sched_pidlist[sched_active_pid];
|
||||||
|
active_stat->laststart = xtimer_now().ticks32;
|
||||||
|
active_stat->schedules = 1;
|
||||||
|
sched_register_cb(sched_statistics_cb);
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user