#ifndef BENCHMARK_UTILISATION_H
#define BENCHMARK_UTILISATION_H
#include <config.h>
#include <arch/benchmark.h>
#include <benchmark/benchmark_utilisation_types.h>
#include <arch/api/constants.h>
#include <model/statedata.h>
#ifdef CONFIG_ARM_ENABLE_PMU_OVERFLOW_INTERRUPT
#include <armv/benchmark_irqHandler.h>
#endif
#ifdef CONFIG_BENCHMARK_TRACK_UTILISATION
extern bool_t benchmark_log_utilisation_enabled;
extern timestamp_t ksEnter;
extern timestamp_t benchmark_start_time;
extern timestamp_t benchmark_end_time;
void benchmark_track_utilisation_dump(void);
void benchmark_track_reset_utilisation(void);
static inline void benchmark_utilisation_switch(tcb_t *heir, tcb_t *next)
{
if (likely(benchmark_log_utilisation_enabled)) {
if (likely(ksEnter > heir->benchmark.schedule_start_time)) {
heir->benchmark.utilisation += (ksEnter - heir->benchmark.schedule_start_time);
} else {
#ifdef CONFIG_ARM_ENABLE_PMU_OVERFLOW_INTERRUPT
heir->benchmark.utilisation += (0xFFFFFFFFU - heir->benchmark.schedule_start_time) + ksEnter;
armv_handleOverflowIRQ();
#endif
}
next->benchmark.schedule_start_time = ksEnter;
}
}
static inline void benchmark_utilisation_kentry_stamp(void)
{
ksEnter = timestamp();
}
static inline void benchmark_utilisation_finalise(void)
{
benchmark_utilisation_switch(NODE_STATE(ksCurThread), NODE_STATE(ksIdleThread));
benchmark_end_time = ksEnter;
benchmark_log_utilisation_enabled = false;
}
#endif
#endif