]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/l4sys/include/ARCH-x86/ktrace.h
update
[l4.git] / l4 / pkg / l4sys / include / ARCH-x86 / ktrace.h
1 /*****************************************************************************/
2 /**
3  * \file
4  * \brief   L4 kernel event tracing
5  * \ingroup api_calls
6  */
7 /*
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)
11  *
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.
15  *
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.
24  */
25 /*****************************************************************************/
26 #ifndef __L4_KTRACE_H__
27 #define __L4_KTRACE_H__
28
29 #include <l4/sys/types.h>
30 #include <l4/sys/ktrace_events.h>
31
32 /**
33  * \brief Log event types
34  * \ingroup api_calls_fiasco
35  */
36 enum {
37   LOG_EVENT_MAX_EVENTS = 16,
38 };
39
40 /**
41  * Trace-buffer status window descriptor.
42  * \ingroup api_calls_fiasco
43  */
44 // keep in sync with fiasco/src/jabi/jdb_ktrace.cpp
45 typedef struct
46 {
47   /// Address of trace-buffer
48   l4_tracebuffer_entry_t *tracebuffer;
49   /// Size of trace-buffer
50   l4_umword_t size;
51   /// Version number of trace-buffer  (incremented if trace-buffer overruns)
52   volatile l4_uint64_t version;
53 } l4_tracebuffer_status_window_t;
54
55 /**
56  * Trace-buffer status.
57  * \ingroup api_calls_fiasco
58  */
59 // keep in sync with fiasco/src/jabi/jdb_ktrace.cpp
60 typedef struct
61 {
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];
67
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;
74
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;
100
101 } l4_tracebuffer_status_t;
102
103 /**
104  * Return trace-buffer status.
105  * \ingroup api_calls_fiasco
106  *
107  * \return Pointer to trace-buffer status struct.
108  */
109 L4_INLINE l4_tracebuffer_status_t *
110 fiasco_tbuf_get_status(void);
111
112 /**
113  * Return the physical address of the trace-buffer status struct.
114  * \ingroup api_calls_fiasco
115  *
116  * \return physical address of status struct.
117  */
118 L4_INLINE l4_addr_t
119 fiasco_tbuf_get_status_phys(void);
120
121 /**
122  * Create new trace-buffer entry with describing \<text\>.
123  * \ingroup api_calls_fiasco
124  *
125  * \param  text   Logging text
126  * \return Pointer to trace-buffer entry
127  */
128 L4_INLINE l4_umword_t
129 fiasco_tbuf_log(const char *text);
130
131 /**
132  * Create new trace-buffer entry with describing \<text\> and three additional
133  * values.
134  * \ingroup api_calls_fiasco
135  *
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
141  */
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);
144
145 /**
146  * Create new trace-buffer entry with binary data.
147  * \ingroup api_calls_fiasco
148  *
149  * \param  data       binary data
150  * \return Pointer to trace-buffer entry
151  */
152 L4_INLINE l4_umword_t
153 fiasco_tbuf_log_binary(const unsigned char *data);
154
155 /**
156  * Clear trace-buffer.
157  * \ingroup api_calls_fiasco
158  */
159 L4_INLINE void
160 fiasco_tbuf_clear(void);
161
162 /**
163  * Dump trace-buffer to kernel console.
164  * \ingroup api_calls_fiasco
165  */
166 L4_INLINE void
167 fiasco_tbuf_dump(void);
168
169 /**
170  * Disable the kernel scheduling timer.
171  */
172 L4_INLINE void
173 fiasco_timer_disable(void);
174
175 /**
176  * Enable the kernel scheduling timer (after it was disabled with
177  * fiasco_timer_disable).
178  */
179 L4_INLINE void
180 fiasco_timer_enable(void);
181
182 /*****************************************************************************
183  *** Implementation
184  *****************************************************************************/
185
186 L4_INLINE l4_tracebuffer_status_t *
187 fiasco_tbuf_get_status(void)
188 {
189   l4_tracebuffer_status_t *tbuf;
190   asm("int $3; cmpb $29, %%al" : "=a" (tbuf) : "0" (0));
191   return tbuf;
192 }
193
194 L4_INLINE l4_addr_t
195 fiasco_tbuf_get_status_phys(void)
196 {
197   l4_addr_t tbuf_phys;
198   asm("int $3; cmpb $29, %%al" : "=a" (tbuf_phys) : "0" (5));
199   return tbuf_phys;
200 }
201
202 L4_INLINE l4_umword_t
203 fiasco_tbuf_log(const char *text)
204 {
205   l4_umword_t offset;
206   asm volatile("int $3; cmpb $29, %%al"
207               : "=a" (offset)
208               : "a" (1), "d" (text));
209   return offset;
210 }
211
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)
214 {
215   l4_umword_t offset;
216   asm volatile("int $3; cmpb $29, %%al"
217               : "=a" (offset)
218               : "a" (4), "d" (text), "c" (v1), "S" (v2), "D" (v3));
219   return offset;
220 }
221
222 L4_INLINE void
223 fiasco_tbuf_clear(void)
224 {
225   asm volatile("int $3; cmpb $29, %%al" : : "a" (2));
226 }
227
228 L4_INLINE void
229 fiasco_tbuf_dump(void)
230 {
231   asm volatile("int $3; cmpb $29, %%al" : : "a" (3));
232 }
233
234 L4_INLINE void
235 fiasco_timer_disable(void)
236 {
237   asm volatile("int $3; cmpb $29, %%al" : : "a" (6));
238 }
239
240 L4_INLINE void
241 fiasco_timer_enable(void)
242 {
243   asm volatile("int $3; cmpb $29, %%al" : : "a" (7));
244 }
245
246 L4_INLINE l4_umword_t
247 fiasco_tbuf_log_binary(const unsigned char *data)
248 {
249   l4_umword_t offset;
250   asm volatile("int $3; cmpb $29, %%al"
251                : "=a" (offset)
252                : "a" (8), "d" (data));
253   return offset;
254 }
255
256 #endif
257