1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-18 12:52:44 +01:00

Merge pull request #11935 from fjmolinas/pr_schedstatistics_module

sys: add schedstatistics module
This commit is contained in:
Juan I Carrano 2019-09-13 15:09:12 +02:00 committed by GitHub
commit 9cf1da9f04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 124 additions and 59 deletions

View File

@ -203,29 +203,6 @@ extern clist_node_t sched_runqueues[SCHED_PRIO_LEVELS];
*/
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
/**
* @brief Register a callback that will be called on every scheduler run

View File

@ -33,10 +33,6 @@
#include "mpu.h"
#endif
#ifdef MODULE_SCHEDSTATISTICS
#include "xtimer.h"
#endif
#define ENABLE_DEBUG (0)
#include "debug.h"
@ -77,9 +73,6 @@ const uint8_t _tcb_name_offset = offsetof(thread_t, name);
#ifdef MODULE_SCHED_CB
static void (*sched_cb) (kernel_pid_t active_thread, kernel_pid_t next_thread) = NULL;
#endif
#ifdef MODULE_SCHEDSTATISTICS
schedstat_t sched_pidlist[KERNEL_PID_LAST + 1];
#endif
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;
}
#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

View File

@ -71,7 +71,6 @@ PSEUDOMODULES += saul_default
PSEUDOMODULES += saul_gpio
PSEUDOMODULES += saul_nrf_temperature
PSEUDOMODULES += scanf_float
PSEUDOMODULES += schedstatistics
PSEUDOMODULES += sched_cb
PSEUDOMODULES += semtech_loramac_rx
PSEUDOMODULES += sock

View File

@ -93,7 +93,7 @@
#endif
#ifdef MODULE_SCHEDSTATISTICS
#include "sched.h"
#include "schedstatistics.h"
#endif
#define ENABLE_DEBUG (0)

View 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 */
/** @} */

View File

@ -22,6 +22,10 @@
#include "thread.h"
#include "kernel_types.h"
#ifdef MODULE_SCHEDSTATISTICS
#include "schedstatistics.h"
#endif
#ifdef MODULE_TLSF_MALLOC
#include "tlsf.h"
#include "tlsf-malloc.h"

View File

@ -0,0 +1 @@
include $(RIOTBASE)/Makefile.base

View 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);
}