3 * \brief L4 kernel event tracing
7 * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
8 * Björn Döbel <doebel@os.inf.tu-dresden.de>,
9 * Torsten Frenzel <frenzel@os.inf.tu-dresden.de>
10 * 2015 Adam Lackorzynski <adam@l4re.org>
11 * economic rights: Technische Universität Dresden (Germany)
13 * This file is part of TUD:OS and distributed under the terms of the
14 * GNU General Public License 2.
15 * Please see the COPYING-GPL-2 file for details.
17 * As a special exception, you may use this file as part of a free software
18 * library without restriction. Specifically, if other files instantiate
19 * templates or use macros or inline functions from this file, or you compile
20 * this file and link it with other files to produce an executable, this
21 * file does not by itself cause the resulting executable to be covered by
22 * the GNU General Public License. This exception does not however
23 * invalidate any other reasons why the executable file might be covered by
24 * the GNU General Public License.
26 /*****************************************************************************/
27 #ifndef __L4_KTRACE_H__
28 #define __L4_KTRACE_H__
30 #include <l4/sys/types.h>
31 #include <l4/sys/ktrace_events.h>
35 LOG_EVENT_CONTEXT_SWITCH = 0, /**< Event: context switch
36 ** \ingroup api_calls_fiasco
38 LOG_EVENT_IPC_SHORTCUT = 1, /**< Event: IPC shortcut
39 ** \ingroup api_calls_fiasco
41 LOG_EVENT_IRQ_RAISED = 2, /**< Event: IRQ occurred
42 ** \ingroup api_calls_fiasco
44 LOG_EVENT_TIMER_IRQ = 3, /**< Event: Timer IRQ occurred
45 ** \ingroup api_calls_fiasco
47 LOG_EVENT_THREAD_EX_REGS = 4, /**< Event: thread_ex_regs
48 ** \ingroup api_calls_fiasco
50 LOG_EVENT_MAX_EVENTS = 16, /**< Maximum number of events
51 ** \ingroup api_calls_fiasco
56 * Trace-buffer status window descriptor.
57 * \ingroup api_calls_fiasco
59 // keep in sync with fiasco/src/jabi/jdb_ktrace.cpp
62 /// Address of trace-buffer
63 l4_tracebuffer_entry_t *tracebuffer;
64 /// Size of trace-buffer
66 /// Version number of trace-buffer (incremented if trace-buffer overruns)
67 volatile l4_uint64_t version;
68 } l4_tracebuffer_status_window_t;
71 * Trace-buffer status.
72 * \ingroup api_calls_fiasco
74 // keep in sync with fiasco/src/jabi/jdb_ktrace.cpp
77 l4_tracebuffer_status_window_t window[2];
78 /// Address of the most current event in trace-buffer.
79 volatile l4_tracebuffer_entry_t * current_entry;
80 /// Available LOG events
81 l4_uint32_t logevents[LOG_EVENT_MAX_EVENTS];
83 /// Scaler used for translation of CPU cycles to nano seconds
84 l4_uint32_t scaler_tsc_to_ns;
85 /// Scaler used for translation of CPU cycles to micro seconds
86 l4_uint32_t scaler_tsc_to_us;
87 /// Scaler used for translation of nano seconds to CPU cycles
88 l4_uint32_t scaler_ns_to_tsc;
90 /// Number of context switches (intra AS or inter AS)
91 volatile l4_uint32_t cnt_context_switch;
92 /// Number of inter AS context switches
93 volatile l4_uint32_t cnt_addr_space_switch;
94 /// How often was the IPC shortcut taken
95 volatile l4_uint32_t cnt_shortcut_failed;
96 /// How often was the IPC shortcut not taken
97 volatile l4_uint32_t cnt_shortcut_success;
98 /// Number of hardware interrupts (without kernel scheduling interrupt)
99 volatile l4_uint32_t cnt_irq;
100 /// Number of long IPCs
101 volatile l4_uint32_t cnt_ipc_long;
102 /// Number of page faults
103 volatile l4_uint32_t cnt_page_fault;
104 /// Number of faults (application runs at IOPL 0 and tries to execute
105 /// cli, sti, in, or out but does not have a sufficient right in the I/O bitmap)
106 volatile l4_uint32_t cnt_io_fault;
107 /// Number of tasks created
108 volatile l4_uint32_t cnt_task_create;
109 /// Number of reschedules
110 volatile l4_uint32_t cnt_schedule;
111 /// Number of flushes of the I/O bitmap. Increases on context switches
112 /// between two small address spaces if at least one of the spaces has
113 /// an I/O bitmap allocated.
114 volatile l4_uint32_t cnt_iobmap_tlb_flush;
116 } l4_tracebuffer_status_t;
119 * Return trace-buffer status.
120 * \ingroup api_calls_fiasco
122 * \return Pointer to trace-buffer status struct.
124 L4_INLINE l4_tracebuffer_status_t *
125 fiasco_tbuf_get_status(void);
128 * Return the physical address of the trace-buffer status struct.
129 * \ingroup api_calls_fiasco
131 * \return physical address of status struct.
134 fiasco_tbuf_get_status_phys(void);
137 * Create new trace-buffer entry with describing \<text\>.
138 * \ingroup api_calls_fiasco
140 * \param text Logging text
141 * \return Pointer to trace-buffer entry
143 L4_INLINE l4_umword_t
144 fiasco_tbuf_log(const char *text);
147 * Create new trace-buffer entry with describing \<text\> and three additional
149 * \ingroup api_calls_fiasco
151 * \param text Logging text
152 * \param v1 first value
153 * \param v2 second value
154 * \param v3 third value
155 * \return Pointer to trace-buffer entry
157 L4_INLINE l4_umword_t
158 fiasco_tbuf_log_3val(const char *text, l4_umword_t v1, l4_umword_t v2, l4_umword_t v3);
161 * Create new trace-buffer entry with binary data.
162 * \ingroup api_calls_fiasco
164 * \param data binary data
165 * \return Pointer to trace-buffer entry
167 L4_INLINE l4_umword_t
168 fiasco_tbuf_log_binary(const unsigned char *data);
171 * Clear trace-buffer.
172 * \ingroup api_calls_fiasco
175 fiasco_tbuf_clear(void);
178 * Dump trace-buffer to kernel console.
179 * \ingroup api_calls_fiasco
182 fiasco_tbuf_dump(void);
185 * Disable the kernel scheduling timer.
188 fiasco_timer_disable(void);
191 * Enable the kernel scheduling timer (after it was disabled with
192 * fiasco_timer_disable).
195 fiasco_timer_enable(void);
197 #include <l4/sys/ktrace-arch.h>