]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/l4re-core/l4sys/include/ktrace.h
Update
[l4.git] / l4 / pkg / l4re-core / l4sys / include / ktrace.h
1 /**
2  * \file
3  * \brief   L4 kernel event tracing
4  * \ingroup api_calls
5  */
6 /*
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)
12  *
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.
16  *
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.
25  */
26 /*****************************************************************************/
27 #ifndef __L4_KTRACE_H__
28 #define __L4_KTRACE_H__
29
30 #include <l4/sys/types.h>
31 #include <l4/sys/ktrace_events.h>
32
33 enum
34 {
35   LOG_EVENT_CONTEXT_SWITCH = 0,  /**< Event: context switch
36                                   **  \ingroup api_calls_fiasco
37                                   **/
38   LOG_EVENT_IPC_SHORTCUT   = 1,  /**< Event: IPC shortcut
39                                   **  \ingroup api_calls_fiasco
40                                   **/
41   LOG_EVENT_IRQ_RAISED     = 2,  /**< Event: IRQ occurred
42                                   **  \ingroup api_calls_fiasco
43                                   **/
44   LOG_EVENT_TIMER_IRQ      = 3,  /**< Event: Timer IRQ occurred
45                                   **  \ingroup api_calls_fiasco
46                                   **/
47   LOG_EVENT_THREAD_EX_REGS = 4,  /**< Event: thread_ex_regs
48                                   **  \ingroup api_calls_fiasco
49                                   **/
50   LOG_EVENT_MAX_EVENTS     = 16, /**< Maximum number of events
51                                   **  \ingroup api_calls_fiasco
52                                   **/
53 };
54
55 /**
56  * Trace-buffer status window descriptor.
57  * \ingroup api_calls_fiasco
58  */
59 // keep in sync with fiasco/src/jabi/jdb_ktrace.cpp
60 typedef struct
61 {
62   /// Address of trace-buffer
63   l4_tracebuffer_entry_t *tracebuffer;
64   /// Size of trace-buffer
65   l4_umword_t size;
66   /// Version number of trace-buffer  (incremented if trace-buffer overruns)
67   volatile l4_uint64_t version;
68 } l4_tracebuffer_status_window_t;
69
70 /**
71  * Trace-buffer status.
72  * \ingroup api_calls_fiasco
73  */
74 // keep in sync with fiasco/src/jabi/jdb_ktrace.cpp
75 typedef struct
76 {
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];
82
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;
89
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;
115
116 } l4_tracebuffer_status_t;
117
118 /**
119  * Return trace-buffer status.
120  * \ingroup api_calls_fiasco
121  *
122  * \return Pointer to trace-buffer status struct.
123  */
124 L4_INLINE l4_tracebuffer_status_t *
125 fiasco_tbuf_get_status(void);
126
127 /**
128  * Return the physical address of the trace-buffer status struct.
129  * \ingroup api_calls_fiasco
130  *
131  * \return physical address of status struct.
132  */
133 L4_INLINE l4_addr_t
134 fiasco_tbuf_get_status_phys(void);
135
136 /**
137  * Create new trace-buffer entry with describing \<text\>.
138  * \ingroup api_calls_fiasco
139  *
140  * \param  text   Logging text
141  * \return Pointer to trace-buffer entry
142  */
143 L4_INLINE l4_umword_t
144 fiasco_tbuf_log(const char *text);
145
146 /**
147  * Create new trace-buffer entry with describing \<text\> and three additional
148  * values.
149  * \ingroup api_calls_fiasco
150  *
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
156  */
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);
159
160 /**
161  * Create new trace-buffer entry with binary data.
162  * \ingroup api_calls_fiasco
163  *
164  * \param  data       binary data
165  * \return Pointer to trace-buffer entry
166  */
167 L4_INLINE l4_umword_t
168 fiasco_tbuf_log_binary(const unsigned char *data);
169
170 /**
171  * Clear trace-buffer.
172  * \ingroup api_calls_fiasco
173  */
174 L4_INLINE void
175 fiasco_tbuf_clear(void);
176
177 /**
178  * Dump trace-buffer to kernel console.
179  * \ingroup api_calls_fiasco
180  */
181 L4_INLINE void
182 fiasco_tbuf_dump(void);
183
184 /**
185  * Disable the kernel scheduling timer.
186  */
187 L4_INLINE void
188 fiasco_timer_disable(void);
189
190 /**
191  * Enable the kernel scheduling timer (after it was disabled with
192  * fiasco_timer_disable).
193  */
194 L4_INLINE void
195 fiasco_timer_enable(void);
196
197 #include <l4/sys/ktrace-arch.h>
198
199 #endif