1 /*****************************************************************************/
4 * \brief L4 kernel event tracing
8 * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
9 * Björn Döbel <doebel@os.inf.tu-dresden.de>
10 * economic rights: Technische Universität Dresden (Germany)
12 * This file is part of TUD:OS and distributed under the terms of the
13 * GNU General Public License 2.
14 * Please see the COPYING-GPL-2 file for details.
16 * As a special exception, you may use this file as part of a free software
17 * library without restriction. Specifically, if other files instantiate
18 * templates or use macros or inline functions from this file, or you compile
19 * this file and link it with other files to produce an executable, this
20 * file does not by itself cause the resulting executable to be covered by
21 * the GNU General Public License. This exception does not however
22 * invalidate any other reasons why the executable file might be covered by
23 * the GNU General Public License.
25 /*****************************************************************************/
26 #ifndef __L4_KTRACE_H__
27 #define __L4_KTRACE_H__
29 #include <l4/sys/types.h>
30 #include <l4/sys/ktrace_events.h>
33 * \brief Log event types
34 * \ingroup api_calls_fiasco
37 LOG_EVENT_MAX_EVENTS = 16,
41 * Trace-buffer status window descriptor.
42 * \ingroup api_calls_fiasco
44 // keep in sync with fiasco/src/jabi/jdb_ktrace.cpp
47 /// Address of trace-buffer
48 l4_tracebuffer_entry_t *tracebuffer;
49 /// Size of trace-buffer
51 /// Version number of trace-buffer (incremented if trace-buffer overruns)
52 volatile l4_uint64_t version;
53 } l4_tracebuffer_status_window_t;
56 * Trace-buffer status.
57 * \ingroup api_calls_fiasco
59 // keep in sync with fiasco/src/jabi/jdb_ktrace.cpp
62 l4_tracebuffer_status_window_t window[2];
63 /// Address of the most current event in trace-buffer.
64 volatile l4_tracebuffer_entry_t * current_entry;
65 /// Available LOG events
66 l4_umword_t logevents[LOG_EVENT_MAX_EVENTS];
68 /// Scaler used for translation of CPU cycles to nano seconds
69 l4_umword_t scaler_tsc_to_ns;
70 /// Scaler used for translation of CPU cycles to micro seconds
71 l4_umword_t scaler_tsc_to_us;
72 /// Scaler used for translation of nano seconds to CPU cycles
73 l4_umword_t scaler_ns_to_tsc;
75 /// Number of context switches (intra AS or inter AS)
76 volatile l4_umword_t cnt_context_switch;
77 /// Number of inter AS context switches
78 volatile l4_umword_t cnt_addr_space_switch;
79 /// How often was the IPC shortcut taken
80 volatile l4_umword_t cnt_shortcut_failed;
81 /// How often was the IPC shortcut not taken
82 volatile l4_umword_t cnt_shortcut_success;
83 /// Number of hardware interrupts (without kernel scheduling interrupt)
84 volatile l4_umword_t cnt_irq;
85 /// Number of long IPCs
86 volatile l4_umword_t cnt_ipc_long;
87 /// Number of page faults
88 volatile l4_umword_t cnt_page_fault;
89 /// Number of faults (application runs at IOPL 0 and tries to execute
90 /// cli, sti, in, or out but does not have a sufficient in the I/O bitmap)
91 volatile l4_umword_t cnt_io_fault;
92 /// Number of tasks created
93 volatile l4_umword_t cnt_task_create;
94 /// Number of reschedules
95 volatile l4_umword_t cnt_schedule;
96 /// Number of flushes of the I/O bitmap. Increases on context switches
97 /// between two small address spaces if at least one of the spaces has
98 /// an I/O bitmap allocated.
99 volatile l4_umword_t cnt_iobmap_tlb_flush;
101 } l4_tracebuffer_status_t;
104 * Return trace-buffer status.
105 * \ingroup api_calls_fiasco
107 * \return Pointer to trace-buffer status struct.
109 L4_INLINE l4_tracebuffer_status_t *
110 fiasco_tbuf_get_status(void);
113 * Return the physical address of the trace-buffer status struct.
114 * \ingroup api_calls_fiasco
116 * \return physical address of status struct.
119 fiasco_tbuf_get_status_phys(void);
122 * Create new trace-buffer entry with describing \<text\>.
123 * \ingroup api_calls_fiasco
125 * \param text Logging text
126 * \return Pointer to trace-buffer entry
128 L4_INLINE l4_umword_t
129 fiasco_tbuf_log(const char *text);
132 * Create new trace-buffer entry with describing \<text\> and three additional
134 * \ingroup api_calls_fiasco
136 * \param text Logging text
137 * \param v1 first value
138 * \param v2 second value
139 * \param v3 third value
140 * \return Pointer to trace-buffer entry
142 L4_INLINE l4_umword_t
143 fiasco_tbuf_log_3val(const char *text, l4_umword_t v1, l4_umword_t v2, l4_umword_t v3);
146 * Create new trace-buffer entry with binary data.
147 * \ingroup api_calls_fiasco
149 * \param data binary data
150 * \return Pointer to trace-buffer entry
152 L4_INLINE l4_umword_t
153 fiasco_tbuf_log_binary(const unsigned char *data);
156 * Clear trace-buffer.
157 * \ingroup api_calls_fiasco
160 fiasco_tbuf_clear(void);
163 * Dump trace-buffer to kernel console.
164 * \ingroup api_calls_fiasco
167 fiasco_tbuf_dump(void);
170 * Disable the kernel scheduling timer.
173 fiasco_timer_disable(void);
176 * Enable the kernel scheduling timer (after it was disabled with
177 * fiasco_timer_disable).
180 fiasco_timer_enable(void);
182 /*****************************************************************************
184 *****************************************************************************/
186 L4_INLINE l4_tracebuffer_status_t *
187 fiasco_tbuf_get_status(void)
189 l4_tracebuffer_status_t *tbuf;
190 asm("int $3; cmpb $29, %%al" : "=a" (tbuf) : "0" (0));
195 fiasco_tbuf_get_status_phys(void)
198 asm("int $3; cmpb $29, %%al" : "=a" (tbuf_phys) : "0" (5));
202 L4_INLINE l4_umword_t
203 fiasco_tbuf_log(const char *text)
206 asm volatile("int $3; cmpb $29, %%al"
208 : "a" (1), "d" (text));
212 L4_INLINE l4_umword_t
213 fiasco_tbuf_log_3val(const char *text, l4_umword_t v1, l4_umword_t v2, l4_umword_t v3)
216 asm volatile("int $3; cmpb $29, %%al"
218 : "a" (4), "d" (text), "c" (v1), "S" (v2), "D" (v3));
223 fiasco_tbuf_clear(void)
225 asm volatile("int $3; cmpb $29, %%al" : : "a" (2));
229 fiasco_tbuf_dump(void)
231 asm volatile("int $3; cmpb $29, %%al" : : "a" (3));
235 fiasco_timer_disable(void)
237 asm volatile("int $3; cmpb $29, %%al" : : "a" (6));
241 fiasco_timer_enable(void)
243 asm volatile("int $3; cmpb $29, %%al" : : "a" (7));
246 L4_INLINE l4_umword_t
247 fiasco_tbuf_log_binary(const unsigned char *data)
250 asm volatile("int $3; cmpb $29, %%al"
252 : "a" (8), "d" (data));