1 /*
2  * Copyright 2014, General Dynamics C4 Systems
3  *
4  * SPDX-License-Identifier: GPL-2.0-only
5  */
6 
7 #pragma once
8 
9 #include <arch/benchmark.h>
10 #include <machine/io.h>
11 #include <sel4/arch/constants.h>
12 #include <arch/machine/hardware.h>
13 #include <sel4/benchmark_tracepoints_types.h>
14 #include <mode/hardware.h>
15 
16 #if CONFIG_MAX_NUM_TRACE_POINTS > 0
17 #define TRACE_POINT_START(x) trace_point_start(x)
18 #define TRACE_POINT_STOP(x)   trace_point_stop(x)
19 
20 #define MAX_LOG_SIZE (seL4_LogBufferSize / sizeof(benchmark_tracepoint_log_entry_t))
21 
22 extern timestamp_t ksEntries[CONFIG_MAX_NUM_TRACE_POINTS];
23 extern bool_t ksStarted[CONFIG_MAX_NUM_TRACE_POINTS];
24 extern timestamp_t ksExit;
25 extern seL4_Word ksLogIndex;
26 extern seL4_Word ksLogIndexFinalized;
27 extern paddr_t ksUserLogBuffer;
28 
trace_point_start(word_t id)29 static inline void trace_point_start(word_t id)
30 {
31     ksEntries[id] = timestamp();
32     ksStarted[id] = true;
33 }
34 
trace_point_stop(word_t id)35 static inline void trace_point_stop(word_t id)
36 {
37     benchmark_tracepoint_log_entry_t *ksLog = (benchmark_tracepoint_log_entry_t *) KS_LOG_PPTR;
38     ksExit = timestamp();
39 
40     if (likely(ksUserLogBuffer != 0)) {
41         if (likely(ksStarted[id])) {
42             ksStarted[id] = false;
43             if (likely(ksLogIndex < MAX_LOG_SIZE)) {
44                 ksLog[ksLogIndex] = (benchmark_tracepoint_log_entry_t) {
45                     id, ksExit - ksEntries[id]
46                 };
47             }
48             /* increment the log index even if we have exceeded the log size
49              * this is so we can tell if we need a bigger log */
50             ksLogIndex++;
51         }
52         /* If this fails integer overflow has occurred. */
53         assert(ksLogIndex > 0);
54     }
55 }
56 
57 #else
58 
59 #define TRACE_POINT_START(x)
60 #define TRACE_POINT_STOP(x)
61 
62 #endif /* CONFIG_MAX_NUM_TRACE_POINTS > 0 */
63 
64