Commit | Line | Data |
---|---|---|
1c8284eb MD |
1 | /* |
2 | * Copyright (C) 2005,2006,2008 Mathieu Desnoyers (mathieu.desnoyers@polymtl.ca) | |
3 | * | |
4 | * This contains the definitions for the Linux Trace Toolkit tracer. | |
5 | * | |
6 | * Dual LGPL v2.1/GPL v2 license. | |
7 | */ | |
8 | ||
9 | #ifndef _LTT_TRACER_H | |
10 | #define _LTT_TRACER_H | |
11 | ||
12 | #include <stdarg.h> | |
13 | #include <linux/types.h> | |
14 | #include <linux/limits.h> | |
15 | #include <linux/list.h> | |
16 | #include <linux/cache.h> | |
1c8284eb MD |
17 | #include <linux/timex.h> |
18 | #include <linux/wait.h> | |
1c8284eb MD |
19 | #include <asm/atomic.h> |
20 | #include <asm/local.h> | |
21 | ||
f3bc08c5 | 22 | #include "wrapper/trace-clock.h" |
1c8284eb | 23 | #include "ltt-tracer-core.h" |
1c25284c | 24 | #include "ltt-events.h" |
1c8284eb MD |
25 | |
26 | /* Number of bytes to log with a read/write event */ | |
27 | #define LTT_LOG_RW_SIZE 32L | |
28 | ||
1c8284eb MD |
29 | /* Maximum number of callbacks per marker */ |
30 | #define LTT_NR_CALLBACKS 10 | |
31 | ||
11b5a3c2 MD |
32 | struct ltt_serialize_closure; |
33 | ||
34 | /* Serialization callback */ | |
35 | typedef size_t (*ltt_serialize_cb)(struct lib_ring_buffer *buf, | |
36 | size_t buf_offset, | |
37 | struct ltt_serialize_closure *closure, | |
38 | void *serialize_private, | |
39 | unsigned int stack_pos_ctx, | |
40 | int *largest_align, | |
41 | const char *fmt, va_list *args); | |
42 | ||
1c8284eb MD |
43 | struct ltt_serialize_closure { |
44 | ltt_serialize_cb *callbacks; | |
45 | long cb_args[LTT_NR_CALLBACKS]; | |
46 | unsigned int cb_idx; | |
47 | }; | |
48 | ||
11b5a3c2 | 49 | size_t ltt_serialize_data(struct lib_ring_buffer *buf, size_t buf_offset, |
1c8284eb MD |
50 | struct ltt_serialize_closure *closure, |
51 | void *serialize_private, unsigned int stack_pos_ctx, | |
52 | int *largest_align, const char *fmt, va_list *args); | |
53 | ||
1c8284eb MD |
54 | enum ltt_channels { |
55 | LTT_CHANNEL_METADATA, | |
56 | LTT_CHANNEL_FD_STATE, | |
57 | LTT_CHANNEL_GLOBAL_STATE, | |
58 | LTT_CHANNEL_IRQ_STATE, | |
59 | LTT_CHANNEL_MODULE_STATE, | |
60 | LTT_CHANNEL_NETIF_STATE, | |
61 | LTT_CHANNEL_SOFTIRQ_STATE, | |
62 | LTT_CHANNEL_SWAP_STATE, | |
63 | LTT_CHANNEL_SYSCALL_STATE, | |
64 | LTT_CHANNEL_TASK_STATE, | |
65 | LTT_CHANNEL_VM_STATE, | |
66 | LTT_CHANNEL_FS, | |
67 | LTT_CHANNEL_INPUT, | |
68 | LTT_CHANNEL_IPC, | |
69 | LTT_CHANNEL_KERNEL, | |
70 | LTT_CHANNEL_MM, | |
71 | LTT_CHANNEL_RCU, | |
72 | LTT_CHANNEL_DEFAULT, | |
73 | }; | |
74 | ||
7514523f MD |
75 | /* |
76 | * Hardcoded event headers | |
1c8284eb MD |
77 | * |
78 | * event header for a trace with active heartbeat : 27 bits timestamps | |
79 | * | |
80 | * headers are 32-bits aligned. In order to insure such alignment, a dynamic per | |
81 | * trace alignment value must be done. | |
82 | * | |
83 | * Remember that the C compiler does align each member on the boundary | |
84 | * equivalent to their own size. | |
85 | * | |
86 | * As relay subbuffers are aligned on pages, we are sure that they are 4 and 8 | |
87 | * bytes aligned, so the buffer header and trace header are aligned. | |
88 | * | |
89 | * Event headers are aligned depending on the trace alignment option. | |
90 | * | |
91 | * Note using C structure bitfields for cross-endianness and portability | |
92 | * concerns. | |
93 | */ | |
94 | ||
95 | #define LTT_RESERVED_EVENTS 3 | |
96 | #define LTT_EVENT_BITS 5 | |
97 | #define LTT_FREE_EVENTS ((1 << LTT_EVENT_BITS) - LTT_RESERVED_EVENTS) | |
98 | #define LTT_TSC_BITS 27 | |
99 | #define LTT_TSC_MASK ((1 << LTT_TSC_BITS) - 1) | |
100 | ||
7514523f | 101 | struct event_header { |
1c8284eb MD |
102 | u32 id_time; /* 5 bits event id (MSB); 27 bits time (LSB) */ |
103 | }; | |
104 | ||
105 | /* Reservation flags */ | |
106 | #define LTT_RFLAG_ID (1 << 0) | |
107 | #define LTT_RFLAG_ID_SIZE (1 << 1) | |
108 | #define LTT_RFLAG_ID_SIZE_TSC (1 << 2) | |
109 | ||
110 | #define LTT_MAX_SMALL_SIZE 0xFFFFU | |
111 | ||
112 | /* | |
113 | * We use asm/timex.h : cpu_khz/HZ variable in here : we might have to deal | |
114 | * specifically with CPU frequency scaling someday, so using an interpolation | |
115 | * between the start and end of buffer values is not flexible enough. Using an | |
116 | * immediate frequency value permits to calculate directly the times for parts | |
117 | * of a buffer that would be before a frequency change. | |
118 | * | |
119 | * Keep the natural field alignment for _each field_ within this structure if | |
120 | * you ever add/remove a field from this header. Packed attribute is not used | |
121 | * because gcc generates poor code on at least powerpc and mips. Don't ever | |
122 | * let gcc add padding between the structure elements. | |
123 | */ | |
1c25284c MD |
124 | struct packet_header { |
125 | uint32_t magic; /* | |
1c8284eb MD |
126 | * Trace magic number. |
127 | * contains endianness information. | |
128 | */ | |
1c25284c MD |
129 | uint8_t trace_uuid[16]; |
130 | uint32_t stream_id; | |
131 | uint64_t timestamp_begin; /* Cycle count at subbuffer start */ | |
132 | uint64_t timestamp_end; /* Cycle count at subbuffer end */ | |
133 | uint32_t content_size; /* Size of data in subbuffer */ | |
134 | uint32_t packet_size; /* Subbuffer size (include padding) */ | |
135 | uint32_t events_lost; /* | |
136 | * Events lost in this subbuffer since | |
137 | * the beginning of the trace. | |
138 | * (may overflow) | |
139 | */ | |
140 | /* TODO: move to metadata */ | |
141 | #if 0 | |
1c8284eb MD |
142 | uint8_t major_version; |
143 | uint8_t minor_version; | |
144 | uint8_t arch_size; /* Architecture pointer size */ | |
145 | uint8_t alignment; /* LTT data alignment */ | |
146 | uint64_t start_time_sec; /* NTP-corrected start time */ | |
147 | uint64_t start_time_usec; | |
148 | uint64_t start_freq; /* | |
149 | * Frequency at trace start, | |
150 | * used all along the trace. | |
151 | */ | |
152 | uint32_t freq_scale; /* Frequency scaling (divisor) */ | |
1c25284c | 153 | #endif //0 |
1c8284eb MD |
154 | uint8_t header_end[0]; /* End of header */ |
155 | }; | |
156 | ||
1c8284eb | 157 | /* Tracer properties */ |
1c25284c | 158 | #define CTF_MAGIC_NUMBER 0xC1FC1FC1 |
881833e3 | 159 | #define TSDL_MAGIC_NUMBER 0x75D11D57 |
1c25284c MD |
160 | #define LTT_TRACER_VERSION_MAJOR 3 |
161 | #define LTT_TRACER_VERSION_MINOR 0 | |
1c8284eb | 162 | |
1c8284eb MD |
163 | /* |
164 | * Size reserved for high priority events (interrupts, NMI, BH) at the end of a | |
165 | * nearly full buffer. User space won't use this last amount of space when in | |
166 | * blocking mode. This space also includes the event header that would be | |
167 | * written by this user space event. | |
168 | */ | |
169 | #define LTT_RESERVE_CRITICAL 4096 | |
170 | ||
171 | /* Register and unregister function pointers */ | |
172 | ||
173 | enum ltt_module_function { | |
174 | LTT_FUNCTION_RUN_FILTER, | |
175 | LTT_FUNCTION_FILTER_CONTROL, | |
176 | LTT_FUNCTION_STATEDUMP | |
177 | }; | |
178 | ||
179 | extern int ltt_module_register(enum ltt_module_function name, void *function, | |
180 | struct module *owner); | |
181 | extern void ltt_module_unregister(enum ltt_module_function name); | |
182 | ||
1c8284eb MD |
183 | /* Exported control function */ |
184 | ||
1c8284eb MD |
185 | void ltt_core_register(int (*function)(u8, void *)); |
186 | ||
187 | void ltt_core_unregister(void); | |
188 | ||
1c8284eb MD |
189 | extern |
190 | void ltt_statedump_register_kprobes_dump(void (*callback)(void *call_data)); | |
191 | extern | |
192 | void ltt_statedump_unregister_kprobes_dump(void (*callback)(void *call_data)); | |
193 | ||
194 | extern void ltt_dump_softirq_vec(void *call_data); | |
195 | ||
f277b4c1 | 196 | #ifdef CONFIG_HAVE_LTT_DUMP_TABLES |
1c8284eb MD |
197 | extern void ltt_dump_sys_call_table(void *call_data); |
198 | extern void ltt_dump_idt_table(void *call_data); | |
f277b4c1 MD |
199 | #else |
200 | static inline void ltt_dump_sys_call_table(void *call_data) | |
201 | { | |
202 | } | |
203 | ||
204 | static inline void ltt_dump_idt_table(void *call_data) | |
205 | { | |
206 | } | |
207 | #endif | |
1c8284eb | 208 | |
1c8284eb | 209 | #endif /* _LTT_TRACER_H */ |