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