2009-03-06 10:35:29 +08:00
|
|
|
/*
|
|
|
|
* trace_export.c - export basic ftrace utilities to user space
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 Steven Rostedt <srostedt@redhat.com>
|
|
|
|
*/
|
|
|
|
#include <linux/stringify.h>
|
|
|
|
#include <linux/kallsyms.h>
|
|
|
|
#include <linux/seq_file.h>
|
|
|
|
#include <linux/uaccess.h>
|
|
|
|
#include <linux/ftrace.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
|
|
|
|
#include "trace_output.h"
|
|
|
|
|
2009-09-13 07:26:21 +08:00
|
|
|
#undef TRACE_SYSTEM
|
|
|
|
#define TRACE_SYSTEM ftrace
|
tracing: new format for specialized trace points
Impact: clean up and enhancement
The TRACE_EVENT_FORMAT macro looks quite ugly and is limited in its
ability to save data as well as to print the record out. Working with
Ingo Molnar, we came up with a new format that is much more pleasing to
the eye of C developers. This new macro is more C style than the old
macro, and is more obvious to what it does.
Here's the example. The only updated macro in this patch is the
sched_switch trace point.
The old method looked like this:
TRACE_EVENT_FORMAT(sched_switch,
TP_PROTO(struct rq *rq, struct task_struct *prev,
struct task_struct *next),
TP_ARGS(rq, prev, next),
TP_FMT("task %s:%d ==> %s:%d",
prev->comm, prev->pid, next->comm, next->pid),
TRACE_STRUCT(
TRACE_FIELD(pid_t, prev_pid, prev->pid)
TRACE_FIELD(int, prev_prio, prev->prio)
TRACE_FIELD_SPECIAL(char next_comm[TASK_COMM_LEN],
next_comm,
TP_CMD(memcpy(TRACE_ENTRY->next_comm,
next->comm,
TASK_COMM_LEN)))
TRACE_FIELD(pid_t, next_pid, next->pid)
TRACE_FIELD(int, next_prio, next->prio)
),
TP_RAW_FMT("prev %d:%d ==> next %s:%d:%d")
);
The above method is hard to read and requires two format fields.
The new method:
/*
* Tracepoint for task switches, performed by the scheduler:
*
* (NOTE: the 'rq' argument is not used by generic trace events,
* but used by the latency tracer plugin. )
*/
TRACE_EVENT(sched_switch,
TP_PROTO(struct rq *rq, struct task_struct *prev,
struct task_struct *next),
TP_ARGS(rq, prev, next),
TP_STRUCT__entry(
__array( char, prev_comm, TASK_COMM_LEN )
__field( pid_t, prev_pid )
__field( int, prev_prio )
__array( char, next_comm, TASK_COMM_LEN )
__field( pid_t, next_pid )
__field( int, next_prio )
),
TP_printk("task %s:%d [%d] ==> %s:%d [%d]",
__entry->prev_comm, __entry->prev_pid, __entry->prev_prio,
__entry->next_comm, __entry->next_pid, __entry->next_prio),
TP_fast_assign(
memcpy(__entry->next_comm, next->comm, TASK_COMM_LEN);
__entry->prev_pid = prev->pid;
__entry->prev_prio = prev->prio;
memcpy(__entry->prev_comm, prev->comm, TASK_COMM_LEN);
__entry->next_pid = next->pid;
__entry->next_prio = next->prio;
)
);
This macro is called TRACE_EVENT, it is broken up into 5 parts:
TP_PROTO: the proto type of the trace point
TP_ARGS: the arguments of the trace point
TP_STRUCT_entry: the structure layout of the entry in the ring buffer
TP_printk: the printk format
TP_fast_assign: the method used to write the entry into the ring buffer
The structure is the definition of how the event will be saved in the
ring buffer. The printk is used by the internal tracing in case of
an oops, and the kernel needs to print out the format of the record
to the console. This the TP_printk gives a means to show the records
in a human readable format. It is also used to print out the data
from the trace file.
The TP_fast_assign is executed directly. It is basically like a C function,
where the __entry is the handle to the record.
Signed-off-by: Steven Rostedt <srostedt@redhat.com>
2009-03-10 05:14:30 +08:00
|
|
|
|
2012-02-15 22:51:51 +08:00
|
|
|
/*
|
|
|
|
* The FTRACE_ENTRY_REG macro allows ftrace entry to define register
|
|
|
|
* function and thus become accesible via perf.
|
|
|
|
*/
|
|
|
|
#undef FTRACE_ENTRY_REG
|
2012-02-15 22:51:53 +08:00
|
|
|
#define FTRACE_ENTRY_REG(name, struct_name, id, tstruct, print, \
|
|
|
|
filter, regfn) \
|
|
|
|
FTRACE_ENTRY(name, struct_name, id, PARAMS(tstruct), PARAMS(print), \
|
|
|
|
filter)
|
2012-02-15 22:51:51 +08:00
|
|
|
|
2009-09-13 07:26:21 +08:00
|
|
|
/* not needed for this file */
|
|
|
|
#undef __field_struct
|
|
|
|
#define __field_struct(type, item)
|
tracing: new format for specialized trace points
Impact: clean up and enhancement
The TRACE_EVENT_FORMAT macro looks quite ugly and is limited in its
ability to save data as well as to print the record out. Working with
Ingo Molnar, we came up with a new format that is much more pleasing to
the eye of C developers. This new macro is more C style than the old
macro, and is more obvious to what it does.
Here's the example. The only updated macro in this patch is the
sched_switch trace point.
The old method looked like this:
TRACE_EVENT_FORMAT(sched_switch,
TP_PROTO(struct rq *rq, struct task_struct *prev,
struct task_struct *next),
TP_ARGS(rq, prev, next),
TP_FMT("task %s:%d ==> %s:%d",
prev->comm, prev->pid, next->comm, next->pid),
TRACE_STRUCT(
TRACE_FIELD(pid_t, prev_pid, prev->pid)
TRACE_FIELD(int, prev_prio, prev->prio)
TRACE_FIELD_SPECIAL(char next_comm[TASK_COMM_LEN],
next_comm,
TP_CMD(memcpy(TRACE_ENTRY->next_comm,
next->comm,
TASK_COMM_LEN)))
TRACE_FIELD(pid_t, next_pid, next->pid)
TRACE_FIELD(int, next_prio, next->prio)
),
TP_RAW_FMT("prev %d:%d ==> next %s:%d:%d")
);
The above method is hard to read and requires two format fields.
The new method:
/*
* Tracepoint for task switches, performed by the scheduler:
*
* (NOTE: the 'rq' argument is not used by generic trace events,
* but used by the latency tracer plugin. )
*/
TRACE_EVENT(sched_switch,
TP_PROTO(struct rq *rq, struct task_struct *prev,
struct task_struct *next),
TP_ARGS(rq, prev, next),
TP_STRUCT__entry(
__array( char, prev_comm, TASK_COMM_LEN )
__field( pid_t, prev_pid )
__field( int, prev_prio )
__array( char, next_comm, TASK_COMM_LEN )
__field( pid_t, next_pid )
__field( int, next_prio )
),
TP_printk("task %s:%d [%d] ==> %s:%d [%d]",
__entry->prev_comm, __entry->prev_pid, __entry->prev_prio,
__entry->next_comm, __entry->next_pid, __entry->next_prio),
TP_fast_assign(
memcpy(__entry->next_comm, next->comm, TASK_COMM_LEN);
__entry->prev_pid = prev->pid;
__entry->prev_prio = prev->prio;
memcpy(__entry->prev_comm, prev->comm, TASK_COMM_LEN);
__entry->next_pid = next->pid;
__entry->next_prio = next->prio;
)
);
This macro is called TRACE_EVENT, it is broken up into 5 parts:
TP_PROTO: the proto type of the trace point
TP_ARGS: the arguments of the trace point
TP_STRUCT_entry: the structure layout of the entry in the ring buffer
TP_printk: the printk format
TP_fast_assign: the method used to write the entry into the ring buffer
The structure is the definition of how the event will be saved in the
ring buffer. The printk is used by the internal tracing in case of
an oops, and the kernel needs to print out the format of the record
to the console. This the TP_printk gives a means to show the records
in a human readable format. It is also used to print out the data
from the trace file.
The TP_fast_assign is executed directly. It is basically like a C function,
where the __entry is the handle to the record.
Signed-off-by: Steven Rostedt <srostedt@redhat.com>
2009-03-10 05:14:30 +08:00
|
|
|
|
2009-09-14 15:54:52 +08:00
|
|
|
#undef __field
|
|
|
|
#define __field(type, item) type item;
|
|
|
|
|
|
|
|
#undef __field_desc
|
|
|
|
#define __field_desc(type, container, item) type item;
|
|
|
|
|
|
|
|
#undef __array
|
|
|
|
#define __array(type, item, size) type item[size];
|
|
|
|
|
|
|
|
#undef __array_desc
|
|
|
|
#define __array_desc(type, container, item, size) type item[size];
|
|
|
|
|
|
|
|
#undef __dynamic_array
|
|
|
|
#define __dynamic_array(type, item) type item[];
|
|
|
|
|
|
|
|
#undef F_STRUCT
|
|
|
|
#define F_STRUCT(args...) args
|
|
|
|
|
|
|
|
#undef F_printk
|
|
|
|
#define F_printk(fmt, args...) fmt, args
|
|
|
|
|
|
|
|
#undef FTRACE_ENTRY
|
2012-02-15 22:51:53 +08:00
|
|
|
#define FTRACE_ENTRY(name, struct_name, id, tstruct, print, filter) \
|
|
|
|
struct ____ftrace_##name { \
|
|
|
|
tstruct \
|
|
|
|
}; \
|
|
|
|
static void __always_unused ____ftrace_check_##name(void) \
|
|
|
|
{ \
|
|
|
|
struct ____ftrace_##name *__entry = NULL; \
|
|
|
|
\
|
|
|
|
/* force compile-time check on F_printk() */ \
|
|
|
|
printk(print); \
|
2009-09-14 15:54:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#undef FTRACE_ENTRY_DUP
|
2012-02-15 22:51:53 +08:00
|
|
|
#define FTRACE_ENTRY_DUP(name, struct_name, id, tstruct, print, filter) \
|
|
|
|
FTRACE_ENTRY(name, struct_name, id, PARAMS(tstruct), PARAMS(print), \
|
|
|
|
filter)
|
2009-09-14 15:54:52 +08:00
|
|
|
|
|
|
|
#include "trace_entries.h"
|
|
|
|
|
2009-09-13 07:26:21 +08:00
|
|
|
#undef __field
|
|
|
|
#define __field(type, item) \
|
|
|
|
ret = trace_define_field(event_call, #type, #item, \
|
|
|
|
offsetof(typeof(field), item), \
|
|
|
|
sizeof(field.item), \
|
2012-02-15 22:51:53 +08:00
|
|
|
is_signed_type(type), filter_type); \
|
2009-09-13 07:26:21 +08:00
|
|
|
if (ret) \
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
#undef __field_desc
|
|
|
|
#define __field_desc(type, container, item) \
|
|
|
|
ret = trace_define_field(event_call, #type, #item, \
|
|
|
|
offsetof(typeof(field), \
|
|
|
|
container.item), \
|
|
|
|
sizeof(field.container.item), \
|
2012-02-15 22:51:53 +08:00
|
|
|
is_signed_type(type), filter_type); \
|
2009-09-13 07:26:21 +08:00
|
|
|
if (ret) \
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
#undef __array
|
|
|
|
#define __array(type, item, len) \
|
2010-11-13 11:32:11 +08:00
|
|
|
do { \
|
2014-02-14 11:51:48 +08:00
|
|
|
char *type_str = #type"["__stringify(len)"]"; \
|
2010-11-13 11:32:11 +08:00
|
|
|
BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \
|
2014-02-14 11:51:48 +08:00
|
|
|
ret = trace_define_field(event_call, type_str, #item, \
|
2009-09-13 07:26:21 +08:00
|
|
|
offsetof(typeof(field), item), \
|
2009-12-15 15:39:38 +08:00
|
|
|
sizeof(field.item), \
|
2012-02-15 22:51:53 +08:00
|
|
|
is_signed_type(type), filter_type); \
|
2010-11-13 11:32:11 +08:00
|
|
|
if (ret) \
|
|
|
|
return ret; \
|
|
|
|
} while (0);
|
2009-09-13 07:26:21 +08:00
|
|
|
|
|
|
|
#undef __array_desc
|
|
|
|
#define __array_desc(type, container, item, len) \
|
|
|
|
BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \
|
|
|
|
ret = trace_define_field(event_call, #type "[" #len "]", #item, \
|
|
|
|
offsetof(typeof(field), \
|
|
|
|
container.item), \
|
2009-12-15 15:39:38 +08:00
|
|
|
sizeof(field.container.item), \
|
2012-02-15 22:51:53 +08:00
|
|
|
is_signed_type(type), filter_type); \
|
2009-09-13 07:26:21 +08:00
|
|
|
if (ret) \
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
#undef __dynamic_array
|
2009-12-15 15:39:34 +08:00
|
|
|
#define __dynamic_array(type, item) \
|
|
|
|
ret = trace_define_field(event_call, #type, #item, \
|
|
|
|
offsetof(typeof(field), item), \
|
2012-02-15 22:51:53 +08:00
|
|
|
0, is_signed_type(type), filter_type);\
|
2009-12-15 15:39:34 +08:00
|
|
|
if (ret) \
|
|
|
|
return ret;
|
2009-09-13 07:26:21 +08:00
|
|
|
|
|
|
|
#undef FTRACE_ENTRY
|
2012-02-15 22:51:53 +08:00
|
|
|
#define FTRACE_ENTRY(name, struct_name, id, tstruct, print, filter) \
|
2013-02-21 10:33:33 +08:00
|
|
|
static int __init \
|
2015-05-05 23:45:27 +08:00
|
|
|
ftrace_define_fields_##name(struct trace_event_call *event_call) \
|
2009-03-31 13:49:16 +08:00
|
|
|
{ \
|
2009-09-13 07:26:21 +08:00
|
|
|
struct struct_name field; \
|
2009-03-31 13:49:16 +08:00
|
|
|
int ret; \
|
2012-02-15 22:51:53 +08:00
|
|
|
int filter_type = filter; \
|
2009-03-31 13:49:16 +08:00
|
|
|
\
|
2009-09-13 07:26:21 +08:00
|
|
|
tstruct; \
|
2009-03-31 13:49:16 +08:00
|
|
|
\
|
|
|
|
return ret; \
|
|
|
|
}
|
|
|
|
|
2009-09-13 07:26:21 +08:00
|
|
|
#include "trace_entries.h"
|
|
|
|
|
2009-12-15 15:39:42 +08:00
|
|
|
#undef __entry
|
|
|
|
#define __entry REC
|
|
|
|
|
2009-09-13 07:26:21 +08:00
|
|
|
#undef __field
|
|
|
|
#define __field(type, item)
|
|
|
|
|
|
|
|
#undef __field_desc
|
|
|
|
#define __field_desc(type, container, item)
|
|
|
|
|
|
|
|
#undef __array
|
|
|
|
#define __array(type, item, len)
|
|
|
|
|
|
|
|
#undef __array_desc
|
|
|
|
#define __array_desc(type, container, item, len)
|
|
|
|
|
|
|
|
#undef __dynamic_array
|
|
|
|
#define __dynamic_array(type, item)
|
|
|
|
|
2009-12-15 15:39:42 +08:00
|
|
|
#undef F_printk
|
2012-03-22 18:18:20 +08:00
|
|
|
#define F_printk(fmt, args...) __stringify(fmt) ", " __stringify(args)
|
2009-12-15 15:39:42 +08:00
|
|
|
|
2012-02-15 22:51:51 +08:00
|
|
|
#undef FTRACE_ENTRY_REG
|
2012-02-15 22:51:53 +08:00
|
|
|
#define FTRACE_ENTRY_REG(call, struct_name, etype, tstruct, print, filter,\
|
|
|
|
regfn) \
|
2009-03-06 10:35:29 +08:00
|
|
|
\
|
2015-05-05 23:45:27 +08:00
|
|
|
struct trace_event_class __refdata event_class_ftrace_##call = { \
|
2010-04-22 22:35:55 +08:00
|
|
|
.system = __stringify(TRACE_SYSTEM), \
|
|
|
|
.define_fields = ftrace_define_fields_##call, \
|
2010-05-24 16:24:52 +08:00
|
|
|
.fields = LIST_HEAD_INIT(event_class_ftrace_##call.fields),\
|
2012-02-15 22:51:51 +08:00
|
|
|
.reg = regfn, \
|
2010-04-22 22:35:55 +08:00
|
|
|
}; \
|
|
|
|
\
|
2015-05-05 23:45:27 +08:00
|
|
|
struct trace_event_call __used event_##call = { \
|
2010-04-22 22:35:55 +08:00
|
|
|
.class = &event_class_ftrace_##call, \
|
2014-04-10 05:06:08 +08:00
|
|
|
{ \
|
|
|
|
.name = #call, \
|
|
|
|
}, \
|
|
|
|
.event.type = etype, \
|
2009-12-15 15:39:42 +08:00
|
|
|
.print_fmt = print, \
|
2015-03-03 15:21:33 +08:00
|
|
|
.flags = TRACE_EVENT_FL_IGNORE_ENABLE, \
|
2009-03-31 13:48:49 +08:00
|
|
|
}; \
|
2015-05-05 23:45:27 +08:00
|
|
|
struct trace_event_call __used \
|
tracing: Replace trace_event struct array with pointer array
Currently the trace_event structures are placed in the _ftrace_events
section, and at link time, the linker makes one large array of all
the trace_event structures. On boot up, this array is read (much like
the initcall sections) and the events are processed.
The problem is that there is no guarantee that gcc will place complex
structures nicely together in an array format. Two structures in the
same file may be placed awkwardly, because gcc has no clue that they
are suppose to be in an array.
A hack was used previous to force the alignment to 4, to pack the
structures together. But this caused alignment issues with other
architectures (sparc).
Instead of packing the structures into an array, the structures' addresses
are now put into the _ftrace_event section. As pointers are always the
natural alignment, gcc should always pack them tightly together
(otherwise initcall, extable, etc would also fail).
By having the pointers to the structures in the section, we can still
iterate the trace_events without causing unnecessary alignment problems
with other architectures, or depending on the current behaviour of
gcc that will likely change in the future just to tick us kernel developers
off a little more.
The _ftrace_event section is also moved into the .init.data section
as it is now only needed at boot up.
Suggested-by: David Miller <davem@davemloft.net>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Acked-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2011-01-27 22:15:30 +08:00
|
|
|
__attribute__((section("_ftrace_events"))) *__event_##call = &event_##call;
|
2009-03-31 13:48:49 +08:00
|
|
|
|
2012-02-15 22:51:51 +08:00
|
|
|
#undef FTRACE_ENTRY
|
2012-02-15 22:51:53 +08:00
|
|
|
#define FTRACE_ENTRY(call, struct_name, etype, tstruct, print, filter) \
|
2012-02-15 22:51:51 +08:00
|
|
|
FTRACE_ENTRY_REG(call, struct_name, etype, \
|
2012-02-15 22:51:53 +08:00
|
|
|
PARAMS(tstruct), PARAMS(print), filter, NULL)
|
2012-02-15 22:51:51 +08:00
|
|
|
|
2015-09-29 22:43:36 +08:00
|
|
|
bool ftrace_event_is_function(struct trace_event_call *call)
|
2012-02-15 22:51:52 +08:00
|
|
|
{
|
|
|
|
return call == &event_function;
|
|
|
|
}
|
|
|
|
|
2009-09-13 07:26:21 +08:00
|
|
|
#include "trace_entries.h"
|