Add support for ppc hw tb clock, remove kernelcompat.h
[lttng-ust.git] / libust / tracer.h
CommitLineData
9dad1eb8
PMF
1/*
2 * Copyright (C) 2005,2006,2008 Mathieu Desnoyers (mathieu.desnoyers@polymtl.ca)
e4621c7f 3 * Copyright (C) 2009 Pierre-Marc Fournier
9dad1eb8
PMF
4 *
5 * This contains the definitions for the Linux Trace Toolkit tracer.
e4621c7f
PMF
6 *
7 * Ported to userspace by Pierre-Marc Fournier.
8 *
8fc2d8db
PMF
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
9dad1eb8
PMF
22 */
23
24#ifndef _LTT_TRACER_H
25#define _LTT_TRACER_H
26
b6bf28ec 27#include <sys/types.h>
9dad1eb8 28#include <stdarg.h>
518d7abb
PMF
29#include <ust/marker.h>
30#include <ust/probe.h>
31#include <ust/core.h>
b6bf28ec 32#include "channels.h"
bb07823d 33#include "tracercore.h"
b73a4c47 34#include "tracerconst.h"
8c36d1ee 35#include "buffers.h"
9dad1eb8
PMF
36
37/* Number of bytes to log with a read/write event */
38#define LTT_LOG_RW_SIZE 32L
39
40/* Interval (in jiffies) at which the LTT per-CPU timer fires */
41#define LTT_PERCPU_TIMER_INTERVAL 1
42
43#ifndef LTT_ARCH_TYPE
44#define LTT_ARCH_TYPE LTT_ARCH_TYPE_UNDEFINED
45#endif
46
47#ifndef LTT_ARCH_VARIANT
48#define LTT_ARCH_VARIANT LTT_ARCH_VARIANT_NONE
49#endif
50
51struct ltt_active_marker;
52
53/* Maximum number of callbacks per marker */
54#define LTT_NR_CALLBACKS 10
55
56struct ltt_serialize_closure;
57struct ltt_probe_private_data;
58
9dad1eb8
PMF
59struct ltt_serialize_closure {
60 ltt_serialize_cb *callbacks;
61 long cb_args[LTT_NR_CALLBACKS];
62 unsigned int cb_idx;
63};
64
b5b073e2 65extern size_t ltt_serialize_data(struct ust_buffer *buf, size_t buf_offset,
9dad1eb8
PMF
66 struct ltt_serialize_closure *closure,
67 void *serialize_private,
68 int *largest_align, const char *fmt, va_list *args);
69
9dad1eb8 70struct ltt_probe_private_data {
b73a4c47 71 struct ust_trace *trace; /*
9dad1eb8
PMF
72 * Target trace, for metadata
73 * or statedump.
74 */
75 ltt_serialize_cb serializer; /*
76 * Serialization function override.
77 */
78 void *serialize_private; /*
79 * Private data for serialization
80 * functions.
81 */
82};
83
84enum ltt_channels {
85 LTT_CHANNEL_METADATA,
b6bf28ec 86 LTT_CHANNEL_UST,
9dad1eb8
PMF
87};
88
89struct ltt_active_marker {
90 struct list_head node; /* active markers list */
91 const char *channel;
92 const char *name;
93 const char *format;
94 struct ltt_available_probe *probe;
95};
96
b6bf28ec 97struct marker; //ust//
9dad1eb8 98extern void ltt_vtrace(const struct marker *mdata, void *probe_data,
75667d04 99 struct registers *regs, void *call_data, const char *fmt, va_list *args);
9dad1eb8 100extern void ltt_trace(const struct marker *mdata, void *probe_data,
75667d04 101 struct registers *regs, void *call_data, const char *fmt, ...);
9dad1eb8
PMF
102
103/*
104 * Unique ID assigned to each registered probe.
105 */
106enum marker_id {
107 MARKER_ID_SET_MARKER_ID = 0, /* Static IDs available (range 0-7) */
108 MARKER_ID_SET_MARKER_FORMAT,
109 MARKER_ID_COMPACT, /* Compact IDs (range: 8-127) */
110 MARKER_ID_DYNAMIC, /* Dynamic IDs (range: 128-65535) */
111};
112
113/* static ids 0-1 reserved for internal use. */
114#define MARKER_CORE_IDS 2
a2fd50ef 115static __inline__ enum marker_id marker_id_type(uint16_t id)
9dad1eb8
PMF
116{
117 if (id < MARKER_CORE_IDS)
118 return (enum marker_id)id;
119 else
120 return MARKER_ID_DYNAMIC;
121}
122
9dad1eb8
PMF
123struct user_dbg_data {
124 unsigned long avail_size;
125 unsigned long write;
126 unsigned long read;
127};
128
129struct ltt_trace_ops {
130 /* First 32 bytes cache-hot cacheline */
b5b073e2 131 void (*wakeup_channel) (struct ust_channel *channel);
b73a4c47 132 int (*user_blocking) (struct ust_trace *trace,
bb07823d
PMF
133 unsigned int index, size_t data_size,
134 struct user_dbg_data *dbg);
b5b073e2 135 /* End of first 32 bytes cacheline */
b73a4c47
PMF
136 int (*create_dirs) (struct ust_trace *new_trace);
137 void (*remove_dirs) (struct ust_trace *new_trace);
b5b073e2 138 int (*create_channel) (const char *trace_name,
b73a4c47 139 struct ust_trace *trace,
b5b073e2
PMF
140 const char *channel_name,
141 struct ust_channel *channel,
142 unsigned int subbuf_size,
143 unsigned int n_subbufs, int overwrite);
144 void (*finish_channel) (struct ust_channel *channel);
145 void (*remove_channel) (struct ust_channel *channel);
b73a4c47 146 void (*user_errors) (struct ust_trace *trace,
b5b073e2 147 unsigned int index, size_t data_size,
204141ee 148 struct user_dbg_data *dbg, unsigned int cpu);
b73a4c47 149};
9dad1eb8
PMF
150
151struct ltt_transport {
152 char *name;
153 struct module *owner;
154 struct list_head node;
155 struct ltt_trace_ops ops;
156};
157
158enum trace_mode { LTT_TRACE_NORMAL, LTT_TRACE_FLIGHT, LTT_TRACE_HYBRID };
159
160#define CHANNEL_FLAG_ENABLE (1U<<0)
161#define CHANNEL_FLAG_OVERWRITE (1U<<1)
162
163/* Per-trace information - each trace/flight recorder represented by one */
b73a4c47 164struct ust_trace {
9dad1eb8
PMF
165 /* First 32 bytes cache-hot cacheline */
166 struct list_head list;
167 struct ltt_trace_ops *ops;
168 int active;
169 /* Second 32 bytes cache-hot cacheline */
b5b073e2 170 struct ust_channel *channels;
9dad1eb8
PMF
171 unsigned int nr_channels;
172 u32 freq_scale;
173 u64 start_freq;
174 u64 start_tsc;
175 unsigned long long start_monotonic;
176 struct timeval start_time;
177 struct ltt_channel_setting *settings;
178 struct {
179 struct dentry *trace_root;
180 } dentry;
9dad1eb8
PMF
181 struct kref kref; /* Each channel has a kref of the trace struct */
182 struct ltt_transport *transport;
183 struct kref ltt_transport_kref;
9dad1eb8
PMF
184 char trace_name[NAME_MAX];
185} ____cacheline_aligned;
186
9dad1eb8
PMF
187/*
188 * We use asm/timex.h : cpu_khz/HZ variable in here : we might have to deal
189 * specifically with CPU frequency scaling someday, so using an interpolation
190 * between the start and end of buffer values is not flexible enough. Using an
191 * immediate frequency value permits to calculate directly the times for parts
192 * of a buffer that would be before a frequency change.
193 *
194 * Keep the natural field alignment for _each field_ within this structure if
195 * you ever add/remove a field from this header. Packed attribute is not used
196 * because gcc generates poor code on at least powerpc and mips. Don't ever
197 * let gcc add padding between the structure elements.
198 */
199struct ltt_subbuffer_header {
200 uint64_t cycle_count_begin; /* Cycle count at subbuffer start */
201 uint64_t cycle_count_end; /* Cycle count at subbuffer end */
202 uint32_t magic_number; /*
203 * Trace magic number.
204 * contains endianness information.
205 */
206 uint8_t major_version;
207 uint8_t minor_version;
208 uint8_t arch_size; /* Architecture pointer size */
209 uint8_t alignment; /* LTT data alignment */
210 uint64_t start_time_sec; /* NTP-corrected start time */
211 uint64_t start_time_usec;
212 uint64_t start_freq; /*
213 * Frequency at trace start,
214 * used all along the trace.
215 */
216 uint32_t freq_scale; /* Frequency scaling (divisor) */
8c36d1ee
PMF
217 uint32_t data_size; /* Size of data in subbuffer */
218 uint32_t sb_size; /* Subbuffer size (including padding) */
9dad1eb8
PMF
219 uint32_t events_lost; /*
220 * Events lost in this subbuffer since
221 * the beginning of the trace.
222 * (may overflow)
223 */
224 uint32_t subbuf_corrupt; /*
225 * Corrupted (lost) subbuffers since
226 * the begginig of the trace.
227 * (may overflow)
228 */
229 uint8_t header_end[0]; /* End of header */
230};
231
232/**
233 * ltt_subbuffer_header_size - called on buffer-switch to a new sub-buffer
234 *
235 * Return header size without padding after the structure. Don't use packed
236 * structure because gcc generates inefficient code on some architectures
237 * (powerpc, mips..)
238 */
a2fd50ef 239static __inline__ size_t ltt_subbuffer_header_size(void)
9dad1eb8
PMF
240{
241 return offsetof(struct ltt_subbuffer_header, header_end);
242}
243
12e81b07 244extern size_t ltt_write_event_header_slow(struct ust_channel *channel,
b73a4c47
PMF
245 struct ust_buffer *buf, long buf_offset,
246 u16 eID, u32 event_size,
247 u64 tsc, unsigned int rflags);
248
9dad1eb8
PMF
249
250/*
251 * ltt_write_event_header
252 *
253 * Writes the event header to the offset (already aligned on 32-bits).
254 *
255 * @trace : trace to write to.
256 * @channel : pointer to the channel structure..
257 * @buf : buffer to write to.
258 * @buf_offset : buffer offset to write to (aligned on 32 bits).
259 * @eID : event ID
260 * @event_size : size of the event, excluding the event header.
261 * @tsc : time stamp counter.
262 * @rflags : reservation flags.
263 *
264 * returns : offset where the event data must be written.
265 */
12e81b07 266static __inline__ size_t ltt_write_event_header(struct ust_channel *chan,
b5b073e2 267 struct ust_buffer *buf, long buf_offset,
b73a4c47 268 u16 eID, u32 event_size,
9dad1eb8
PMF
269 u64 tsc, unsigned int rflags)
270{
271 struct ltt_event_header header;
9dad1eb8 272
b73a4c47
PMF
273 if (unlikely(rflags))
274 goto slow_path;
9dad1eb8 275
b73a4c47 276 header.id_time = eID << LTT_TSC_BITS;
8c36d1ee
PMF
277 header.id_time |= (u32)tsc & LTT_TSC_MASK;
278 ust_buffers_write(buf, buf_offset, &header, sizeof(header));
279 buf_offset += sizeof(header);
9dad1eb8 280
b73a4c47 281 return buf_offset;
9dad1eb8 282
b73a4c47 283slow_path:
12e81b07 284 return ltt_write_event_header_slow(chan, buf, buf_offset,
b73a4c47
PMF
285 eID, event_size, tsc, rflags);
286}
9dad1eb8
PMF
287
288/*
289 * Control channels :
290 * control/metadata
291 * control/interrupts
292 * control/...
293 *
294 * cpu channel :
295 * cpu
296 */
9dad1eb8
PMF
297
298#define LTT_METADATA_CHANNEL "metadata_state"
b6bf28ec 299#define LTT_UST_CHANNEL "ust"
9dad1eb8
PMF
300
301#define LTT_FLIGHT_PREFIX "flight-"
302
303/* Tracer properties */
32072f29
PMF
304//#define LTT_DEFAULT_SUBBUF_SIZE_LOW 134217728
305#define LTT_DEFAULT_SUBBUF_SIZE_LOW 65536
306//#define LTT_DEFAULT_SUBBUF_SIZE_LOW 4096
9dad1eb8 307#define LTT_DEFAULT_N_SUBBUFS_LOW 2
32072f29
PMF
308//#define LTT_DEFAULT_SUBBUF_SIZE_MED 134217728
309#define LTT_DEFAULT_SUBBUF_SIZE_MED 262144
310//#define LTT_DEFAULT_SUBBUF_SIZE_MED 4096
9dad1eb8 311#define LTT_DEFAULT_N_SUBBUFS_MED 2
32072f29
PMF
312//#define LTT_DEFAULT_SUBBUF_SIZE_HIGH 134217728
313#define LTT_DEFAULT_SUBBUF_SIZE_HIGH 1048576
314//#define LTT_DEFAULT_SUBBUF_SIZE_HIGH 4096
9dad1eb8
PMF
315#define LTT_DEFAULT_N_SUBBUFS_HIGH 2
316#define LTT_TRACER_MAGIC_NUMBER 0x00D6B7ED
317#define LTT_TRACER_VERSION_MAJOR 2
31607b38 318#define LTT_TRACER_VERSION_MINOR 6
9dad1eb8 319
b73a4c47
PMF
320/**
321 * ust_write_trace_header - Write trace header
322 * @trace: Trace information
323 * @header: Memory address where the information must be written to
324 */
325static __inline__ void ltt_write_trace_header(struct ust_trace *trace,
326 struct ltt_subbuffer_header *header)
327{
328 header->magic_number = LTT_TRACER_MAGIC_NUMBER;
329 header->major_version = LTT_TRACER_VERSION_MAJOR;
330 header->minor_version = LTT_TRACER_VERSION_MINOR;
331 header->arch_size = sizeof(void *);
332 header->alignment = ltt_get_alignment();
333 header->start_time_sec = trace->start_time.tv_sec;
334 header->start_time_usec = trace->start_time.tv_usec;
335 header->start_freq = trace->start_freq;
336 header->freq_scale = trace->freq_scale;
337}
338
12e81b07
PMF
339static __inline__ int ust_get_cpu(void)
340{
341#ifndef UST_VALGRIND
342 return sched_getcpu();
343#else
344 /* Valgrind does not support the sched_getcpu() vsyscall.
345 * It causes it to detect a segfault in the program and stop it.
346 * So if we want to check libust with valgrind, we have to refrain
347 * from using this call. TODO: it would probably be better to return
348 * other values too, to better test it.
349 */
350 return 0;
351#endif
352}
353
b73a4c47 354
9dad1eb8
PMF
355/*
356 * Size reserved for high priority events (interrupts, NMI, BH) at the end of a
357 * nearly full buffer. User space won't use this last amount of space when in
358 * blocking mode. This space also includes the event header that would be
359 * written by this user space event.
360 */
361#define LTT_RESERVE_CRITICAL 4096
362
363/* Register and unregister function pointers */
364
365enum ltt_module_function {
366 LTT_FUNCTION_RUN_FILTER,
367 LTT_FUNCTION_FILTER_CONTROL,
368 LTT_FUNCTION_STATEDUMP
369};
370
064842c6
PMF
371extern void ltt_transport_register(struct ltt_transport *transport);
372extern void ltt_transport_unregister(struct ltt_transport *transport);
9dad1eb8
PMF
373
374/* Exported control function */
375
9dad1eb8
PMF
376union ltt_control_args {
377 struct {
378 enum trace_mode mode;
379 unsigned int subbuf_size_low;
380 unsigned int n_subbufs_low;
381 unsigned int subbuf_size_med;
382 unsigned int n_subbufs_med;
383 unsigned int subbuf_size_high;
384 unsigned int n_subbufs_high;
385 } new_trace;
386};
387
064842c6
PMF
388extern int _ltt_trace_setup(const char *trace_name);
389extern int ltt_trace_setup(const char *trace_name);
b73a4c47 390extern struct ust_trace *_ltt_trace_find_setup(const char *trace_name);
064842c6
PMF
391extern int ltt_trace_set_type(const char *trace_name, const char *trace_type);
392extern int ltt_trace_set_channel_subbufsize(const char *trace_name,
9dad1eb8 393 const char *channel_name, unsigned int size);
064842c6 394extern int ltt_trace_set_channel_subbufcount(const char *trace_name,
9dad1eb8 395 const char *channel_name, unsigned int cnt);
064842c6 396extern int ltt_trace_set_channel_enable(const char *trace_name,
9dad1eb8 397 const char *channel_name, unsigned int enable);
064842c6 398extern int ltt_trace_set_channel_overwrite(const char *trace_name,
9dad1eb8 399 const char *channel_name, unsigned int overwrite);
064842c6 400extern int ltt_trace_alloc(const char *trace_name);
31d392f1 401extern int ltt_trace_destroy(const char *trace_name, int drop);
064842c6
PMF
402extern int ltt_trace_start(const char *trace_name);
403extern int ltt_trace_stop(const char *trace_name);
9dad1eb8 404
9dad1eb8
PMF
405enum ltt_filter_control_msg {
406 LTT_FILTER_DEFAULT_ACCEPT,
407 LTT_FILTER_DEFAULT_REJECT
408};
409
410extern int ltt_filter_control(enum ltt_filter_control_msg msg,
411 const char *trace_name);
412
413extern struct dentry *get_filter_root(void);
414
b73a4c47 415extern void ltt_write_trace_header(struct ust_trace *trace,
9dad1eb8 416 struct ltt_subbuffer_header *header);
b5b073e2 417extern void ltt_buffer_destroy(struct ust_channel *ltt_chan);
9dad1eb8 418
064842c6 419extern void ltt_core_register(int (*function)(u8, void *));
9dad1eb8 420
064842c6 421extern void ltt_core_unregister(void);
9dad1eb8 422
064842c6
PMF
423extern void ltt_release_trace(struct kref *kref);
424extern void ltt_release_transport(struct kref *kref);
9dad1eb8 425
b73a4c47 426extern void ltt_dump_marker_state(struct ust_trace *trace);
9dad1eb8 427
064842c6
PMF
428extern void ltt_lock_traces(void);
429extern void ltt_unlock_traces(void);
9dad1eb8 430
b73a4c47 431extern struct ust_trace *_ltt_trace_find(const char *trace_name);
d0b5f2b9 432
9dad1eb8 433#endif /* _LTT_TRACER_H */
This page took 0.051224 seconds and 4 git commands to generate.