forked from Minki/linux
0a19e53c15
This patch allows event filters to be safely removed or switched on-the-fly while avoiding the use of rcu or the suspension of tracing of previous versions. It does it by adding a new filter_pred_none() predicate function which does nothing and by never deallocating either the predicates or any of the filter_pred members used in matching; the predicate lists are allocated and initialized during ftrace_event_calls initialization. Whenever a filter is removed or replaced, the filter_pred_* functions currently in use by the affected ftrace_event_call are immediately switched over to to the filter_pred_none() function, while the rest of the filter_pred members are left intact, allowing any currently executing filter_pred_* functions to finish up, using the values they're currently using. In the case of filter replacement, the new predicate values are copied into the old predicates after the above step, and the filter_pred_none() functions are replaced by the filter_pred_* functions for the new filter. In this case, it is possible though very unlikely that a previous filter_pred_* is still running even after the filter_pred_none() switch and the switch to the new filter_pred_*. In that case, however, because nothing has been deallocated in the filter_pred, the worst that can happen is that the old filter_pred_* function sees the new values and as a result produces either a false positive or a false negative, depending on the values it finds. So one downside to this method is that rarely, it can produce a bad match during the filter switch, but it should be possible to live with that, IMHO. The other downside is that at least in this patch the predicate lists are always pre-allocated, taking up memory from the start. They could probably be allocated on first-use, and de-allocated when tracing is completely stopped - if this patch makes sense, I could create another one to do that later on. Oh, and it also places a restriction on the size of __arrays in events, currently set to 128, since they can't be larger than the now embedded str_val arrays in the filter_pred struct. Signed-off-by: Tom Zanussi <tzanussi@gmail.com> Acked-by: Frederic Weisbecker <fweisbec@gmail.com> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: paulmck@linux.vnet.ibm.com LKML-Reference: <1239610670.6660.49.camel@tropicana> Signed-off-by: Ingo Molnar <mingo@elte.hu>
188 lines
4.9 KiB
C
188 lines
4.9 KiB
C
/*
|
|
* 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/debugfs.h>
|
|
#include <linux/uaccess.h>
|
|
#include <linux/ftrace.h>
|
|
#include <linux/module.h>
|
|
#include <linux/init.h>
|
|
#include <linux/fs.h>
|
|
|
|
#include "trace_output.h"
|
|
|
|
|
|
#undef TRACE_STRUCT
|
|
#define TRACE_STRUCT(args...) args
|
|
|
|
#undef TRACE_FIELD
|
|
#define TRACE_FIELD(type, item, assign) \
|
|
ret = trace_seq_printf(s, "\tfield:" #type " " #item ";\t" \
|
|
"offset:%u;\tsize:%u;\n", \
|
|
(unsigned int)offsetof(typeof(field), item), \
|
|
(unsigned int)sizeof(field.item)); \
|
|
if (!ret) \
|
|
return 0;
|
|
|
|
|
|
#undef TRACE_FIELD_SPECIAL
|
|
#define TRACE_FIELD_SPECIAL(type_item, item, len, cmd) \
|
|
ret = trace_seq_printf(s, "\tfield special:" #type_item ";\t" \
|
|
"offset:%u;\tsize:%u;\n", \
|
|
(unsigned int)offsetof(typeof(field), item), \
|
|
(unsigned int)sizeof(field.item)); \
|
|
if (!ret) \
|
|
return 0;
|
|
|
|
#undef TRACE_FIELD_ZERO_CHAR
|
|
#define TRACE_FIELD_ZERO_CHAR(item) \
|
|
ret = trace_seq_printf(s, "\tfield:char " #item ";\t" \
|
|
"offset:%u;\tsize:0;\n", \
|
|
(unsigned int)offsetof(typeof(field), item)); \
|
|
if (!ret) \
|
|
return 0;
|
|
|
|
|
|
#undef TP_RAW_FMT
|
|
#define TP_RAW_FMT(args...) args
|
|
|
|
#undef TRACE_EVENT_FORMAT
|
|
#define TRACE_EVENT_FORMAT(call, proto, args, fmt, tstruct, tpfmt) \
|
|
static int \
|
|
ftrace_format_##call(struct trace_seq *s) \
|
|
{ \
|
|
struct args field; \
|
|
int ret; \
|
|
\
|
|
tstruct; \
|
|
\
|
|
trace_seq_printf(s, "\nprint fmt: \"%s\"\n", tpfmt); \
|
|
\
|
|
return ret; \
|
|
}
|
|
|
|
#undef TRACE_EVENT_FORMAT_NOFILTER
|
|
#define TRACE_EVENT_FORMAT_NOFILTER(call, proto, args, fmt, tstruct, \
|
|
tpfmt) \
|
|
static int \
|
|
ftrace_format_##call(struct trace_seq *s) \
|
|
{ \
|
|
struct args field; \
|
|
int ret; \
|
|
\
|
|
tstruct; \
|
|
\
|
|
trace_seq_printf(s, "\nprint fmt: \"%s\"\n", tpfmt); \
|
|
\
|
|
return ret; \
|
|
}
|
|
|
|
#include "trace_event_types.h"
|
|
|
|
#undef TRACE_ZERO_CHAR
|
|
#define TRACE_ZERO_CHAR(arg)
|
|
|
|
#undef TRACE_FIELD
|
|
#define TRACE_FIELD(type, item, assign)\
|
|
entry->item = assign;
|
|
|
|
#undef TRACE_FIELD
|
|
#define TRACE_FIELD(type, item, assign)\
|
|
entry->item = assign;
|
|
|
|
#undef TP_CMD
|
|
#define TP_CMD(cmd...) cmd
|
|
|
|
#undef TRACE_ENTRY
|
|
#define TRACE_ENTRY entry
|
|
|
|
#undef TRACE_FIELD_SPECIAL
|
|
#define TRACE_FIELD_SPECIAL(type_item, item, len, cmd) \
|
|
cmd;
|
|
|
|
#undef TRACE_EVENT_FORMAT
|
|
#define TRACE_EVENT_FORMAT(call, proto, args, fmt, tstruct, tpfmt) \
|
|
int ftrace_define_fields_##call(void); \
|
|
static int ftrace_raw_init_event_##call(void); \
|
|
\
|
|
struct ftrace_event_call __used \
|
|
__attribute__((__aligned__(4))) \
|
|
__attribute__((section("_ftrace_events"))) event_##call = { \
|
|
.name = #call, \
|
|
.id = proto, \
|
|
.system = __stringify(TRACE_SYSTEM), \
|
|
.raw_init = ftrace_raw_init_event_##call, \
|
|
.show_format = ftrace_format_##call, \
|
|
.define_fields = ftrace_define_fields_##call, \
|
|
}; \
|
|
static int ftrace_raw_init_event_##call(void) \
|
|
{ \
|
|
INIT_LIST_HEAD(&event_##call.fields); \
|
|
init_preds(&event_##call); \
|
|
return 0; \
|
|
} \
|
|
|
|
#undef TRACE_EVENT_FORMAT_NOFILTER
|
|
#define TRACE_EVENT_FORMAT_NOFILTER(call, proto, args, fmt, tstruct, \
|
|
tpfmt) \
|
|
\
|
|
struct ftrace_event_call __used \
|
|
__attribute__((__aligned__(4))) \
|
|
__attribute__((section("_ftrace_events"))) event_##call = { \
|
|
.name = #call, \
|
|
.id = proto, \
|
|
.system = __stringify(TRACE_SYSTEM), \
|
|
.show_format = ftrace_format_##call, \
|
|
};
|
|
|
|
#include "trace_event_types.h"
|
|
|
|
#undef TRACE_FIELD
|
|
#define TRACE_FIELD(type, item, assign) \
|
|
ret = trace_define_field(event_call, #type, #item, \
|
|
offsetof(typeof(field), item), \
|
|
sizeof(field.item)); \
|
|
if (ret) \
|
|
return ret;
|
|
|
|
#undef TRACE_FIELD_SPECIAL
|
|
#define TRACE_FIELD_SPECIAL(type, item, len, cmd) \
|
|
ret = trace_define_field(event_call, #type "[" #len "]", #item, \
|
|
offsetof(typeof(field), item), \
|
|
sizeof(field.item)); \
|
|
if (ret) \
|
|
return ret;
|
|
|
|
#undef TRACE_FIELD_ZERO_CHAR
|
|
#define TRACE_FIELD_ZERO_CHAR(item)
|
|
|
|
#undef TRACE_EVENT_FORMAT
|
|
#define TRACE_EVENT_FORMAT(call, proto, args, fmt, tstruct, tpfmt) \
|
|
int \
|
|
ftrace_define_fields_##call(void) \
|
|
{ \
|
|
struct ftrace_event_call *event_call = &event_##call; \
|
|
struct args field; \
|
|
int ret; \
|
|
\
|
|
__common_field(unsigned char, type); \
|
|
__common_field(unsigned char, flags); \
|
|
__common_field(unsigned char, preempt_count); \
|
|
__common_field(int, pid); \
|
|
__common_field(int, tgid); \
|
|
\
|
|
tstruct; \
|
|
\
|
|
return ret; \
|
|
}
|
|
|
|
#undef TRACE_EVENT_FORMAT_NOFILTER
|
|
#define TRACE_EVENT_FORMAT_NOFILTER(call, proto, args, fmt, tstruct, \
|
|
tpfmt)
|
|
|
|
#include "trace_event_types.h"
|