Skip to content

Commit

Permalink
benchmark: rework kernel entry/exit tracing
Browse files Browse the repository at this point in the history
Signed-off-by: Axel Heider <[email protected]>
  • Loading branch information
axel-h authored and Axel Heider committed Jul 8, 2024
1 parent 44780d3 commit 85850be
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 93 deletions.
25 changes: 14 additions & 11 deletions include/benchmark/benchmark.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,26 @@

#include <config.h>
#include <util.h>

#ifdef CONFIG_ENABLE_BENCHMARKS

#include <types.h>
#include <arch/benchmark.h>
#include <machine/io.h>
#include <sel4/arch/constants.h>
#include <arch/machine/hardware.h>
#include <mode/hardware.h>
#include <arch/benchmark.h>

#ifdef CONFIG_KERNEL_LOG_BUFFER
extern seL4_Word ksLogIndex = 0;
extern paddr_t ksUserLogBuffer;
#endif /* CONFIG_KERNEL_LOG_BUFFER */

#if defined(CONFIG_BENCHMARK_TRACK_KERNEL_ENTRIES) || defined(CONFIG_BENCHMARK_TRACK_UTILISATION)
/* Having one global kernel entry timestamp does not work in SMP configurations,
* as the kernel could be entered in parallel on different cores. For now, it is
* assumed that benchmarking is used on single core configurations only.
*/
#if defined(CONFIG_DEBUG_BUILD) || defined(ENABLE_TRACE_KERNEL_ENTRY_EXIT)
#include <sel4/benchmark_track_types.h>
extern kernel_entry_t ksKernelEntry;
#endif /* CONFIG_DEBUG_BUILD || ENABLE_TRACE_KERNEL_ENTRY_EXIT */

#ifdef CONFIG_BENCHMARK_TRACK_UTILISATION
extern timestamp_t ksEnter;
#endif /* CONFIG_BENCHMARK_TRACK_KERNEL_ENTRIES CONFIG_BENCHMARK_TRACK_UTILISATION */
#endif /* CONFIG_BENCHMARK_TRACK_UTILISATION */

#ifdef ENABLE_KERNEL_TRACEPOINTS
#include <sel4/benchmark_tracepoints_types.h>
Expand All @@ -42,6 +40,12 @@ void trace_point_stop(word_t id);
#define TRACE_POINT_STOP(...) do {} while(0)
#endif /* [not] ENABLE_KERNEL_TRACEPOINTS */

#ifdef ENABLE_TRACE_KERNEL_ENTRY_EXIT
void trace_kernel_entry(void);
void trace_kernel_exit(void);
#endif /* ENABLE_TRACE_KERNEL_ENTRY_EXIT */

#ifdef CONFIG_ENABLE_BENCHMARKS
exception_t handle_SysBenchmarkFlushCaches(void);
exception_t handle_SysBenchmarkResetLog(void);
exception_t handle_SysBenchmarkFinalizeLog(void);
Expand All @@ -56,5 +60,4 @@ exception_t handle_SysBenchmarkDumpAllThreadsUtilisation(void);
exception_t handle_SysBenchmarkResetAllThreadsUtilisation(void);
#endif /* CONFIG_DEBUG_BUILD */
#endif /* CONFIG_BENCHMARK_TRACK_UTILISATION */

#endif /* CONFIG_ENABLE_BENCHMARKS */
28 changes: 3 additions & 25 deletions include/benchmark/benchmark_track.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,17 @@
#pragma once

#include <config.h>
#include <benchmark/benchmark.h>

#if defined(CONFIG_DEBUG_BUILD) || defined(CONFIG_BENCHMARK_TRACK_KERNEL_ENTRIES)
#ifdef ENABLE_TRACE_KERNEL_ENTRY

#include <benchmark/benchmark.h>
#include <sel4/benchmark_track_types.h>
#include <sel4/arch/constants.h>
#include <machine/io.h>
#include <kernel/cspace.h>
#include <model/statedata.h>
#include <mode/machine.h>

#define TRACK_KERNEL_ENTRIES 1
extern kernel_entry_t ksKernelEntry;

#ifdef CONFIG_BENCHMARK_TRACK_KERNEL_ENTRIES

/**
* @brief Fill in logging info for kernel entries
*
*/
void benchmark_track_exit(void);

/**
* @brief Start logging kernel entries
*
*/
static inline void benchmark_track_start(void)
{
ksEnter = timestamp();
}

#endif /* CONFIG_BENCHMARK_TRACK_KERNEL_ENTRIES */

static inline void benchmark_debug_syscall_start(word_t cptr, word_t msgInfo, word_t syscall)
{
seL4_MessageInfo_t info = messageInfoFromWord_raw(msgInfo);
Expand All @@ -50,4 +28,4 @@ static inline void benchmark_debug_syscall_start(word_t cptr, word_t msgInfo, wo
ksKernelEntry.invocation_tag = seL4_MessageInfo_get_label(info);
}

#endif /* CONFIG_DEBUG_BUILD || CONFIG_BENCHMARK_TRACK_KERNEL_ENTRIES */
#endif /* ENABLE_TRACE_KERNEL_ENTRY_EXIT */
11 changes: 11 additions & 0 deletions include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@
#endif
#endif

#if defined(CONFIG_DEBUG_BUILD) || \
defined(CONFIG_BENCHMARK_TRACK_KERNEL_ENTRIES)
#define ENABLE_TRACE_KERNEL_ENTRY
#define TRACK_KERNEL_ENTRIES 1
#endif

#if defined(CONFIG_BENCHMARK_TRACK_KERNEL_ENTRIES) || \
defined(CONFIG_BENCHMARK_TRACK_UTILISATION)
#define ENABLE_TRACE_KERNEL_ENTRY_EXIT
#endif

#if defined(CONFIG_BENCHMARK_TRACEPOINTS) && (CONFIG_MAX_NUM_TRACE_POINTS > 0)
#define ENABLE_KERNEL_TRACEPOINTS
#endif
24 changes: 6 additions & 18 deletions include/kernel/traps.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,17 @@
#pragma once

#include <config.h>
#include <util.h>
#include <arch/kernel/traps.h>
#include <smp/lock.h>
#include <benchmark/benchmark.h>

/* This C function should be the first thing called from C after entry from
* assembly. It provides a single place to do any entry work that is not
* done in assembly for various reasons */
static inline void c_entry_hook(void)
{
arch_c_entry_hook();
#if defined(CONFIG_BENCHMARK_TRACK_KERNEL_ENTRIES) || defined(CONFIG_BENCHMARK_TRACK_UTILISATION)
ksEnter = timestamp();
#ifdef ENABLE_TRACE_KERNEL_ENTRY_EXIT
trace_kernel_entry();
#endif
}

Expand All @@ -28,19 +27,8 @@ static inline void c_entry_hook(void)
* in C before leaving the kernel */
static inline void c_exit_hook(void)
{
#ifdef CONFIG_BENCHMARK_TRACK_KERNEL_ENTRIES
benchmark_track_exit();
#endif /* CONFIG_BENCHMARK_TRACK_KERNEL_ENTRIES */
#ifdef CONFIG_BENCHMARK_TRACK_UTILISATION
if (likely(NODE_STATE(benchmark_log_utilisation_enabled))) {
timestamp_t exit = timestamp();
NODE_STATE(ksCurThread)->benchmark.number_kernel_entries++;
NODE_STATE(ksCurThread)->benchmark.kernel_utilisation += exit - ksEnter;
NODE_STATE(benchmark_kernel_number_entries)++;
NODE_STATE(benchmark_kernel_time) += exit - ksEnter;
}
#endif /* CONFIG_BENCHMARK_TRACK_UTILISATION */

#ifdef ENABLE_TRACE_KERNEL_ENTRY_EXIT
trace_kernel_exit();
#endif
arch_c_exit_hook();
}

4 changes: 0 additions & 4 deletions src/arch/x86/machine/breakpoint.c
Original file line number Diff line number Diff line change
Expand Up @@ -592,10 +592,6 @@ exception_t handleUserLevelDebugException(int int_vector)
ksKernelEntry.word = int_vector;
#endif /* DEBUG */

#ifdef CONFIG_BENCHMARK_TRACK_KERNEL_ENTRIES
benchmark_track_start();
#endif

ct = NODE_STATE(ksCurThread);

/* Software break request (INT3) is detected by the vector number */
Expand Down
55 changes: 51 additions & 4 deletions src/benchmark/benchmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,61 @@ seL4_Word ksLogIndex = 0;
paddr_t ksUserLogBuffer;
#endif /* CONFIG_KERNEL_LOG_BUFFER */

#if defined(CONFIG_DEBUG_BUILD) || defined(CONFIG_BENCHMARK_TRACK_KERNEL_ENTRIES)
#if defined(CONFIG_DEBUG_BUILD) || defined(ENABLE_TRACE_KERNEL_ENTRY_EXIT)
#include <sel4/benchmark_track_types.h>
kernel_entry_t ksKernelEntry;
#endif /* CONFIG_DEBUG_BUILD || CONFIG_BENCHMARK_TRACK_KERNEL_ENTRIES */
#endif /* CONFIG_DEBUG_BUILD || ENABLE_TRACE_KERNEL_ENTRY_EXIT */

#ifdef ENABLE_TRACE_KERNEL_ENTRY_EXIT

#if defined(CONFIG_BENCHMARK_TRACK_KERNEL_ENTRIES) || defined(CONFIG_BENCHMARK_TRACK_UTILISATION)
timestamp_t ksEnter;
#endif /* CONFIG_BENCHMARK_TRACK_KERNEL_ENTRIES CONFIG_BENCHMARK_TRACK_UTILISATION */

void trace_kernel_entry(void)
{
ksEnter = timestamp();

ksKernelEntry = (kernel_entry_t) {
.path = 0,
/* 29 bits are remaining, usage specific to path */
.core = CURRENT_CPU_INDEX(), /* 3 bits */
.word = 0, /* 26 bits */
};
}

void trace_kernel_exit(void)
{
#if defined(CONFIG_BENCHMARK_TRACK_KERNEL_ENTRIES) || \
defined(CONFIG_BENCHMARK_TRACK_UTILISATION)

timestamp_t now = timestamp();
timestamp_t duration = now - ksEnter;

#endif

#ifdef CONFIG_BENCHMARK_TRACK_KERNEL_ENTRIES
if (likely(ksUserLogBuffer != 0)) {
/* If Log buffer is filled, do nothing */
if (likely(ksLogIndex < (seL4_LogBufferSize / sizeof(benchmark_track_kernel_entry_t)))) {
benchmark_track_kernel_entry_t *ksLog = (benchmark_track_kernel_entry_t *)KS_LOG_PPTR;
ksLog[ksLogIndex].entry = ksKernelEntry;
ksLog[ksLogIndex].start_time = ksEnter;
ksLog[ksLogIndex].duration = duration;
ksLogIndex++;
}
}
#endif /* CONFIG_BENCHMARK_TRACK_KERNEL_ENTRIES */

#ifdef CONFIG_BENCHMARK_TRACK_UTILISATION
if (likely(NODE_STATE(benchmark_log_utilisation_enabled))) {
NODE_STATE(ksCurThread)->benchmark.number_kernel_entries++;
NODE_STATE(ksCurThread)->benchmark.kernel_utilisation += duration;
NODE_STATE(benchmark_kernel_number_entries)++;
NODE_STATE(benchmark_kernel_time) += duration;
}
#endif /* CONFIG_BENCHMARK_TRACK_UTILISATION */
}

#endif /* ENABLE_TRACE_KERNEL_ENTRY_EXIT */


#ifdef ENABLE_KERNEL_TRACEPOINTS
Expand Down
30 changes: 0 additions & 30 deletions src/benchmark/benchmark_track.c

This file was deleted.

1 change: 0 additions & 1 deletion src/config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ add_sources(
src/machine/registerset.c
src/machine/fpu.c
src/benchmark/benchmark.c
src/benchmark/benchmark_track.c
src/benchmark/benchmark_utilisation.c
src/smp/lock.c
src/smp/ipi.c
Expand Down

0 comments on commit 85850be

Please sign in to comment.