1 /*
2  * Copyright 2016, General Dynamics C4 Systems
3  *
4  * SPDX-License-Identifier: GPL-2.0-only
5  */
6 
7 #pragma once
8 
9 #include <config.h>
10 #include <arch/benchmark.h>
11 #include <sel4/benchmark_track_types.h>
12 #include <sel4/arch/constants.h>
13 #include <machine/io.h>
14 #include <kernel/cspace.h>
15 #include <model/statedata.h>
16 #include <mode/machine.h>
17 
18 #if defined(CONFIG_DEBUG_BUILD) || defined(CONFIG_BENCHMARK_TRACK_KERNEL_ENTRIES)
19 #define TRACK_KERNEL_ENTRIES 1
20 extern kernel_entry_t ksKernelEntry;
21 #ifdef CONFIG_BENCHMARK_TRACK_KERNEL_ENTRIES
22 /**
23  *  Calculate the maximum number of kernel entries that can be tracked,
24  *  limited by the log buffer size. This is also the number of ksLog entries.
25  *
26  */
27 #define MAX_LOG_SIZE (seL4_LogBufferSize / \
28              sizeof(benchmark_track_kernel_entry_t))
29 
30 extern timestamp_t ksEnter;
31 extern seL4_Word ksLogIndex;
32 extern seL4_Word ksLogIndexFinalized;
33 
34 /**
35  * @brief Fill in logging info for kernel entries
36  *
37  */
38 void benchmark_track_exit(void);
39 
40 /**
41  * @brief Start logging kernel entries
42  *
43  */
benchmark_track_start(void)44 static inline void benchmark_track_start(void)
45 {
46     ksEnter = timestamp();
47 }
48 #endif /* CONFIG_BENCHMARK_TRACK_KERNEL_ENTRIES */
49 
benchmark_debug_syscall_start(word_t cptr,word_t msgInfo,word_t syscall)50 static inline void benchmark_debug_syscall_start(word_t cptr, word_t msgInfo, word_t syscall)
51 {
52     seL4_MessageInfo_t info = messageInfoFromWord_raw(msgInfo);
53     lookupCapAndSlot_ret_t lu_ret = lookupCapAndSlot(NODE_STATE(ksCurThread), cptr);
54     ksKernelEntry.path = Entry_Syscall;
55     ksKernelEntry.syscall_no = -syscall;
56     ksKernelEntry.cap_type = cap_get_capType(lu_ret.cap);
57     ksKernelEntry.invocation_tag = seL4_MessageInfo_get_label(info);
58 }
59 #endif
60 
61