提交 c5617b20 编写于 作者: L Linus Torvalds

Merge branch 'perf-core-for-linus' of...

Merge branch 'perf-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip

* 'perf-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip: (61 commits)
  tracing: Add __used annotation to event variable
  perf, trace: Fix !x86 build bug
  perf report: Support multiple events on the TUI
  perf annotate: Fix up usage of the build id cache
  x86/mmiotrace: Remove redundant instruction prefix checks
  perf annotate: Add TUI interface
  perf tui: Remove annotate from popup menu after failure
  perf report: Don't start the TUI if -D is used
  perf: Fix getline undeclared
  perf: Optimize perf_tp_event_match()
  perf: Remove more code from the fastpath
  perf: Optimize the !vmalloc backed buffer
  perf: Optimize perf_output_copy()
  perf: Fix wakeup storm for RO mmap()s
  perf-record: Share per-cpu buffers
  perf-record: Remove -M
  perf: Ensure that IOC_OUTPUT isn't used to create multi-writer buffers
  perf, trace: Optimize tracepoints by using per-tracepoint-per-cpu hlist to track events
  perf, trace: Optimize tracepoints by removing IRQ-disable from perf/tracepoint interaction
  perf tui: Allow disabling the TUI on a per command basis in ~/.perfconfig
  ...
...@@ -92,6 +92,8 @@ struct cpu_hw_events { ...@@ -92,6 +92,8 @@ struct cpu_hw_events {
/* Enabled/disable state. */ /* Enabled/disable state. */
int enabled; int enabled;
unsigned int group_flag;
}; };
DEFINE_PER_CPU(struct cpu_hw_events, cpu_hw_events) = { .enabled = 1, }; DEFINE_PER_CPU(struct cpu_hw_events, cpu_hw_events) = { .enabled = 1, };
...@@ -981,53 +983,6 @@ static int collect_events(struct perf_event *group, int max_count, ...@@ -981,53 +983,6 @@ static int collect_events(struct perf_event *group, int max_count,
return n; return n;
} }
static void event_sched_in(struct perf_event *event)
{
event->state = PERF_EVENT_STATE_ACTIVE;
event->oncpu = smp_processor_id();
event->tstamp_running += event->ctx->time - event->tstamp_stopped;
if (is_software_event(event))
event->pmu->enable(event);
}
int hw_perf_group_sched_in(struct perf_event *group_leader,
struct perf_cpu_context *cpuctx,
struct perf_event_context *ctx)
{
struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
struct perf_event *sub;
int n0, n;
if (!sparc_pmu)
return 0;
n0 = cpuc->n_events;
n = collect_events(group_leader, perf_max_events - n0,
&cpuc->event[n0], &cpuc->events[n0],
&cpuc->current_idx[n0]);
if (n < 0)
return -EAGAIN;
if (check_excludes(cpuc->event, n0, n))
return -EINVAL;
if (sparc_check_constraints(cpuc->event, cpuc->events, n + n0))
return -EAGAIN;
cpuc->n_events = n0 + n;
cpuc->n_added += n;
cpuctx->active_oncpu += n;
n = 1;
event_sched_in(group_leader);
list_for_each_entry(sub, &group_leader->sibling_list, group_entry) {
if (sub->state != PERF_EVENT_STATE_OFF) {
event_sched_in(sub);
n++;
}
}
ctx->nr_active += n;
return 1;
}
static int sparc_pmu_enable(struct perf_event *event) static int sparc_pmu_enable(struct perf_event *event)
{ {
struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
...@@ -1045,11 +1000,20 @@ static int sparc_pmu_enable(struct perf_event *event) ...@@ -1045,11 +1000,20 @@ static int sparc_pmu_enable(struct perf_event *event)
cpuc->events[n0] = event->hw.event_base; cpuc->events[n0] = event->hw.event_base;
cpuc->current_idx[n0] = PIC_NO_INDEX; cpuc->current_idx[n0] = PIC_NO_INDEX;
/*
* If group events scheduling transaction was started,
* skip the schedulability test here, it will be peformed
* at commit time(->commit_txn) as a whole
*/
if (cpuc->group_flag & PERF_EVENT_TXN_STARTED)
goto nocheck;
if (check_excludes(cpuc->event, n0, 1)) if (check_excludes(cpuc->event, n0, 1))
goto out; goto out;
if (sparc_check_constraints(cpuc->event, cpuc->events, n0 + 1)) if (sparc_check_constraints(cpuc->event, cpuc->events, n0 + 1))
goto out; goto out;
nocheck:
cpuc->n_events++; cpuc->n_events++;
cpuc->n_added++; cpuc->n_added++;
...@@ -1129,11 +1093,61 @@ static int __hw_perf_event_init(struct perf_event *event) ...@@ -1129,11 +1093,61 @@ static int __hw_perf_event_init(struct perf_event *event)
return 0; return 0;
} }
/*
* Start group events scheduling transaction
* Set the flag to make pmu::enable() not perform the
* schedulability test, it will be performed at commit time
*/
static void sparc_pmu_start_txn(const struct pmu *pmu)
{
struct cpu_hw_events *cpuhw = &__get_cpu_var(cpu_hw_events);
cpuhw->group_flag |= PERF_EVENT_TXN_STARTED;
}
/*
* Stop group events scheduling transaction
* Clear the flag and pmu::enable() will perform the
* schedulability test.
*/
static void sparc_pmu_cancel_txn(const struct pmu *pmu)
{
struct cpu_hw_events *cpuhw = &__get_cpu_var(cpu_hw_events);
cpuhw->group_flag &= ~PERF_EVENT_TXN_STARTED;
}
/*
* Commit group events scheduling transaction
* Perform the group schedulability test as a whole
* Return 0 if success
*/
static int sparc_pmu_commit_txn(const struct pmu *pmu)
{
struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
int n;
if (!sparc_pmu)
return -EINVAL;
cpuc = &__get_cpu_var(cpu_hw_events);
n = cpuc->n_events;
if (check_excludes(cpuc->event, 0, n))
return -EINVAL;
if (sparc_check_constraints(cpuc->event, cpuc->events, n))
return -EAGAIN;
return 0;
}
static const struct pmu pmu = { static const struct pmu pmu = {
.enable = sparc_pmu_enable, .enable = sparc_pmu_enable,
.disable = sparc_pmu_disable, .disable = sparc_pmu_disable,
.read = sparc_pmu_read, .read = sparc_pmu_read,
.unthrottle = sparc_pmu_unthrottle, .unthrottle = sparc_pmu_unthrottle,
.start_txn = sparc_pmu_start_txn,
.cancel_txn = sparc_pmu_cancel_txn,
.commit_txn = sparc_pmu_commit_txn,
}; };
const struct pmu *hw_perf_event_init(struct perf_event *event) const struct pmu *hw_perf_event_init(struct perf_event *event)
......
...@@ -89,7 +89,8 @@ ...@@ -89,7 +89,8 @@
P4_CCCR_ENABLE) P4_CCCR_ENABLE)
/* HT mask */ /* HT mask */
#define P4_CCCR_MASK_HT (P4_CCCR_MASK | P4_CCCR_THREAD_ANY) #define P4_CCCR_MASK_HT \
(P4_CCCR_MASK | P4_CCCR_OVF_PMI_T1 | P4_CCCR_THREAD_ANY)
#define P4_GEN_ESCR_EMASK(class, name, bit) \ #define P4_GEN_ESCR_EMASK(class, name, bit) \
class##__##name = ((1 << bit) << P4_ESCR_EVENTMASK_SHIFT) class##__##name = ((1 << bit) << P4_ESCR_EVENTMASK_SHIFT)
......
...@@ -1717,7 +1717,11 @@ void perf_arch_fetch_caller_regs(struct pt_regs *regs, unsigned long ip, int ski ...@@ -1717,7 +1717,11 @@ void perf_arch_fetch_caller_regs(struct pt_regs *regs, unsigned long ip, int ski
*/ */
regs->bp = rewind_frame_pointer(skip + 1); regs->bp = rewind_frame_pointer(skip + 1);
regs->cs = __KERNEL_CS; regs->cs = __KERNEL_CS;
local_save_flags(regs->flags); /*
* We abuse bit 3 to pass exact information, see perf_misc_flags
* and the comment with PERF_EFLAGS_EXACT.
*/
regs->flags = 0;
} }
unsigned long perf_instruction_pointer(struct pt_regs *regs) unsigned long perf_instruction_pointer(struct pt_regs *regs)
......
...@@ -465,15 +465,21 @@ static int p4_hw_config(struct perf_event *event) ...@@ -465,15 +465,21 @@ static int p4_hw_config(struct perf_event *event)
return rc; return rc;
} }
static inline void p4_pmu_clear_cccr_ovf(struct hw_perf_event *hwc) static inline int p4_pmu_clear_cccr_ovf(struct hw_perf_event *hwc)
{ {
unsigned long dummy; int overflow = 0;
u32 low, high;
rdmsrl(hwc->config_base + hwc->idx, dummy); rdmsr(hwc->config_base + hwc->idx, low, high);
if (dummy & P4_CCCR_OVF) {
/* we need to check high bit for unflagged overflows */
if ((low & P4_CCCR_OVF) || !(high & (1 << 31))) {
overflow = 1;
(void)checking_wrmsrl(hwc->config_base + hwc->idx, (void)checking_wrmsrl(hwc->config_base + hwc->idx,
((u64)dummy) & ~P4_CCCR_OVF); ((u64)low) & ~P4_CCCR_OVF);
} }
return overflow;
} }
static inline void p4_pmu_disable_event(struct perf_event *event) static inline void p4_pmu_disable_event(struct perf_event *event)
...@@ -584,20 +590,14 @@ static int p4_pmu_handle_irq(struct pt_regs *regs) ...@@ -584,20 +590,14 @@ static int p4_pmu_handle_irq(struct pt_regs *regs)
WARN_ON_ONCE(hwc->idx != idx); WARN_ON_ONCE(hwc->idx != idx);
/* /* it might be unflagged overflow */
* FIXME: Redundant call, actually not needed handled = p4_pmu_clear_cccr_ovf(hwc);
* but just to check if we're screwed
*/
p4_pmu_clear_cccr_ovf(hwc);
val = x86_perf_event_update(event); val = x86_perf_event_update(event);
if (val & (1ULL << (x86_pmu.cntval_bits - 1))) if (!handled && (val & (1ULL << (x86_pmu.cntval_bits - 1))))
continue; continue;
/* /* event overflow for sure */
* event overflow
*/
handled = 1;
data.period = event->hw.last_period; data.period = event->hw.last_period;
if (!x86_perf_event_set_period(event)) if (!x86_perf_event_set_period(event))
...@@ -670,7 +670,7 @@ static void p4_pmu_swap_config_ts(struct hw_perf_event *hwc, int cpu) ...@@ -670,7 +670,7 @@ static void p4_pmu_swap_config_ts(struct hw_perf_event *hwc, int cpu)
/* /*
* ESCR address hashing is tricky, ESCRs are not sequential * ESCR address hashing is tricky, ESCRs are not sequential
* in memory but all starts from MSR_P4_BSU_ESCR0 (0x03e0) and * in memory but all starts from MSR_P4_BSU_ESCR0 (0x03a0) and
* the metric between any ESCRs is laid in range [0xa0,0xe1] * the metric between any ESCRs is laid in range [0xa0,0xe1]
* *
* so we make ~70% filled hashtable * so we make ~70% filled hashtable
...@@ -736,7 +736,8 @@ static int p4_get_escr_idx(unsigned int addr) ...@@ -736,7 +736,8 @@ static int p4_get_escr_idx(unsigned int addr)
unsigned int idx = P4_ESCR_MSR_IDX(addr); unsigned int idx = P4_ESCR_MSR_IDX(addr);
if (unlikely(idx >= P4_ESCR_MSR_TABLE_SIZE || if (unlikely(idx >= P4_ESCR_MSR_TABLE_SIZE ||
!p4_escr_table[idx])) { !p4_escr_table[idx] ||
p4_escr_table[idx] != addr)) {
WARN_ONCE(1, "P4 PMU: Wrong address passed: %x\n", addr); WARN_ONCE(1, "P4 PMU: Wrong address passed: %x\n", addr);
return -1; return -1;
} }
...@@ -762,7 +763,7 @@ static int p4_pmu_schedule_events(struct cpu_hw_events *cpuc, int n, int *assign ...@@ -762,7 +763,7 @@ static int p4_pmu_schedule_events(struct cpu_hw_events *cpuc, int n, int *assign
{ {
unsigned long used_mask[BITS_TO_LONGS(X86_PMC_IDX_MAX)]; unsigned long used_mask[BITS_TO_LONGS(X86_PMC_IDX_MAX)];
unsigned long escr_mask[BITS_TO_LONGS(P4_ESCR_MSR_TABLE_SIZE)]; unsigned long escr_mask[BITS_TO_LONGS(P4_ESCR_MSR_TABLE_SIZE)];
int cpu = raw_smp_processor_id(); int cpu = smp_processor_id();
struct hw_perf_event *hwc; struct hw_perf_event *hwc;
struct p4_event_bind *bind; struct p4_event_bind *bind;
unsigned int i, thread, num; unsigned int i, thread, num;
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
/* IA32 Manual 3, 2-1 */ /* IA32 Manual 3, 2-1 */
static unsigned char prefix_codes[] = { static unsigned char prefix_codes[] = {
0xF0, 0xF2, 0xF3, 0x2E, 0x36, 0x3E, 0x26, 0x64, 0xF0, 0xF2, 0xF3, 0x2E, 0x36, 0x3E, 0x26, 0x64,
0x65, 0x2E, 0x3E, 0x66, 0x67 0x65, 0x66, 0x67
}; };
/* IA32 Manual 3, 3-432*/ /* IA32 Manual 3, 3-432*/
static unsigned int reg_rop[] = { static unsigned int reg_rop[] = {
......
...@@ -73,18 +73,25 @@ struct trace_iterator { ...@@ -73,18 +73,25 @@ struct trace_iterator {
}; };
struct trace_event;
typedef enum print_line_t (*trace_print_func)(struct trace_iterator *iter, typedef enum print_line_t (*trace_print_func)(struct trace_iterator *iter,
int flags); int flags, struct trace_event *event);
struct trace_event {
struct hlist_node node; struct trace_event_functions {
struct list_head list;
int type;
trace_print_func trace; trace_print_func trace;
trace_print_func raw; trace_print_func raw;
trace_print_func hex; trace_print_func hex;
trace_print_func binary; trace_print_func binary;
}; };
struct trace_event {
struct hlist_node node;
struct list_head list;
int type;
struct trace_event_functions *funcs;
};
extern int register_ftrace_event(struct trace_event *event); extern int register_ftrace_event(struct trace_event *event);
extern int unregister_ftrace_event(struct trace_event *event); extern int unregister_ftrace_event(struct trace_event *event);
...@@ -116,28 +123,70 @@ void tracing_record_cmdline(struct task_struct *tsk); ...@@ -116,28 +123,70 @@ void tracing_record_cmdline(struct task_struct *tsk);
struct event_filter; struct event_filter;
enum trace_reg {
TRACE_REG_REGISTER,
TRACE_REG_UNREGISTER,
TRACE_REG_PERF_REGISTER,
TRACE_REG_PERF_UNREGISTER,
};
struct ftrace_event_call;
struct ftrace_event_class {
char *system;
void *probe;
#ifdef CONFIG_PERF_EVENTS
void *perf_probe;
#endif
int (*reg)(struct ftrace_event_call *event,
enum trace_reg type);
int (*define_fields)(struct ftrace_event_call *);
struct list_head *(*get_fields)(struct ftrace_event_call *);
struct list_head fields;
int (*raw_init)(struct ftrace_event_call *);
};
enum {
TRACE_EVENT_FL_ENABLED_BIT,
TRACE_EVENT_FL_FILTERED_BIT,
};
enum {
TRACE_EVENT_FL_ENABLED = (1 << TRACE_EVENT_FL_ENABLED_BIT),
TRACE_EVENT_FL_FILTERED = (1 << TRACE_EVENT_FL_FILTERED_BIT),
};
struct ftrace_event_call { struct ftrace_event_call {
struct list_head list; struct list_head list;
struct ftrace_event_class *class;
char *name; char *name;
char *system;
struct dentry *dir; struct dentry *dir;
struct trace_event *event; struct trace_event event;
int enabled;
int (*regfunc)(struct ftrace_event_call *);
void (*unregfunc)(struct ftrace_event_call *);
int id;
const char *print_fmt; const char *print_fmt;
int (*raw_init)(struct ftrace_event_call *);
int (*define_fields)(struct ftrace_event_call *);
struct list_head fields;
int filter_active;
struct event_filter *filter; struct event_filter *filter;
void *mod; void *mod;
void *data; void *data;
/*
* 32 bit flags:
* bit 1: enabled
* bit 2: filter_active
*
* Changes to flags must hold the event_mutex.
*
* Note: Reads of flags do not hold the event_mutex since
* they occur in critical sections. But the way flags
* is currently used, these changes do no affect the code
* except that when a change is made, it may have a slight
* delay in propagating the changes to other CPUs due to
* caching and such.
*/
unsigned int flags;
#ifdef CONFIG_PERF_EVENTS
int perf_refcount; int perf_refcount;
int (*perf_event_enable)(struct ftrace_event_call *); struct hlist_head *perf_events;
void (*perf_event_disable)(struct ftrace_event_call *); #endif
}; };
#define PERF_MAX_TRACE_SIZE 2048 #define PERF_MAX_TRACE_SIZE 2048
...@@ -194,24 +243,22 @@ struct perf_event; ...@@ -194,24 +243,22 @@ struct perf_event;
DECLARE_PER_CPU(struct pt_regs, perf_trace_regs); DECLARE_PER_CPU(struct pt_regs, perf_trace_regs);
extern int perf_trace_enable(int event_id); extern int perf_trace_init(struct perf_event *event);
extern void perf_trace_disable(int event_id); extern void perf_trace_destroy(struct perf_event *event);
extern int perf_trace_enable(struct perf_event *event);
extern void perf_trace_disable(struct perf_event *event);
extern int ftrace_profile_set_filter(struct perf_event *event, int event_id, extern int ftrace_profile_set_filter(struct perf_event *event, int event_id,
char *filter_str); char *filter_str);
extern void ftrace_profile_free_filter(struct perf_event *event); extern void ftrace_profile_free_filter(struct perf_event *event);
extern void * extern void *perf_trace_buf_prepare(int size, unsigned short type,
perf_trace_buf_prepare(int size, unsigned short type, int *rctxp, struct pt_regs *regs, int *rctxp);
unsigned long *irq_flags);
static inline void static inline void
perf_trace_buf_submit(void *raw_data, int size, int rctx, u64 addr, perf_trace_buf_submit(void *raw_data, int size, int rctx, u64 addr,
u64 count, unsigned long irq_flags, struct pt_regs *regs) u64 count, struct pt_regs *regs, void *head)
{ {
struct trace_entry *entry = raw_data; perf_tp_event(addr, count, raw_data, size, regs, head);
perf_tp_event(entry->type, addr, count, raw_data, size, regs);
perf_swevent_put_recursion_context(rctx); perf_swevent_put_recursion_context(rctx);
local_irq_restore(irq_flags);
} }
#endif #endif
......
...@@ -485,6 +485,7 @@ struct perf_guest_info_callbacks { ...@@ -485,6 +485,7 @@ struct perf_guest_info_callbacks {
#include <linux/ftrace.h> #include <linux/ftrace.h>
#include <linux/cpu.h> #include <linux/cpu.h>
#include <asm/atomic.h> #include <asm/atomic.h>
#include <asm/local.h>
#define PERF_MAX_STACK_DEPTH 255 #define PERF_MAX_STACK_DEPTH 255
...@@ -587,21 +588,19 @@ struct perf_mmap_data { ...@@ -587,21 +588,19 @@ struct perf_mmap_data {
struct rcu_head rcu_head; struct rcu_head rcu_head;
#ifdef CONFIG_PERF_USE_VMALLOC #ifdef CONFIG_PERF_USE_VMALLOC
struct work_struct work; struct work_struct work;
int page_order; /* allocation order */
#endif #endif
int data_order;
int nr_pages; /* nr of data pages */ int nr_pages; /* nr of data pages */
int writable; /* are we writable */ int writable; /* are we writable */
int nr_locked; /* nr pages mlocked */ int nr_locked; /* nr pages mlocked */
atomic_t poll; /* POLL_ for wakeups */ atomic_t poll; /* POLL_ for wakeups */
atomic_t events; /* event_id limit */
atomic_long_t head; /* write position */ local_t head; /* write position */
atomic_long_t done_head; /* completed head */ local_t nest; /* nested writers */
local_t events; /* event limit */
atomic_t lock; /* concurrent writes */ local_t wakeup; /* wakeup stamp */
atomic_t wakeup; /* needs a wakeup */ local_t lost; /* nr records lost */
atomic_t lost; /* nr records lost */
long watermark; /* wakeup watermark */ long watermark; /* wakeup watermark */
...@@ -728,6 +727,7 @@ struct perf_event { ...@@ -728,6 +727,7 @@ struct perf_event {
perf_overflow_handler_t overflow_handler; perf_overflow_handler_t overflow_handler;
#ifdef CONFIG_EVENT_TRACING #ifdef CONFIG_EVENT_TRACING
struct ftrace_event_call *tp_event;
struct event_filter *filter; struct event_filter *filter;
#endif #endif
...@@ -803,11 +803,12 @@ struct perf_cpu_context { ...@@ -803,11 +803,12 @@ struct perf_cpu_context {
struct perf_output_handle { struct perf_output_handle {
struct perf_event *event; struct perf_event *event;
struct perf_mmap_data *data; struct perf_mmap_data *data;
unsigned long head; unsigned long wakeup;
unsigned long offset; unsigned long size;
void *addr;
int page;
int nmi; int nmi;
int sample; int sample;
int locked;
}; };
#ifdef CONFIG_PERF_EVENTS #ifdef CONFIG_PERF_EVENTS
...@@ -993,8 +994,9 @@ static inline bool perf_paranoid_kernel(void) ...@@ -993,8 +994,9 @@ static inline bool perf_paranoid_kernel(void)
} }
extern void perf_event_init(void); extern void perf_event_init(void);
extern void perf_tp_event(int event_id, u64 addr, u64 count, void *record, extern void perf_tp_event(u64 addr, u64 count, void *record,
int entry_size, struct pt_regs *regs); int entry_size, struct pt_regs *regs,
struct hlist_head *head);
extern void perf_bp_event(struct perf_event *event, void *data); extern void perf_bp_event(struct perf_event *event, void *data);
#ifndef perf_misc_flags #ifndef perf_misc_flags
......
...@@ -103,22 +103,6 @@ struct perf_event_attr; ...@@ -103,22 +103,6 @@ struct perf_event_attr;
#define __SC_TEST5(t5, a5, ...) __SC_TEST(t5); __SC_TEST4(__VA_ARGS__) #define __SC_TEST5(t5, a5, ...) __SC_TEST(t5); __SC_TEST4(__VA_ARGS__)
#define __SC_TEST6(t6, a6, ...) __SC_TEST(t6); __SC_TEST5(__VA_ARGS__) #define __SC_TEST6(t6, a6, ...) __SC_TEST(t6); __SC_TEST5(__VA_ARGS__)
#ifdef CONFIG_PERF_EVENTS
#define TRACE_SYS_ENTER_PERF_INIT(sname) \
.perf_event_enable = perf_sysenter_enable, \
.perf_event_disable = perf_sysenter_disable,
#define TRACE_SYS_EXIT_PERF_INIT(sname) \
.perf_event_enable = perf_sysexit_enable, \
.perf_event_disable = perf_sysexit_disable,
#else
#define TRACE_SYS_ENTER_PERF(sname)
#define TRACE_SYS_ENTER_PERF_INIT(sname)
#define TRACE_SYS_EXIT_PERF(sname)
#define TRACE_SYS_EXIT_PERF_INIT(sname)
#endif /* CONFIG_PERF_EVENTS */
#ifdef CONFIG_FTRACE_SYSCALLS #ifdef CONFIG_FTRACE_SYSCALLS
#define __SC_STR_ADECL1(t, a) #a #define __SC_STR_ADECL1(t, a) #a
#define __SC_STR_ADECL2(t, a, ...) #a, __SC_STR_ADECL1(__VA_ARGS__) #define __SC_STR_ADECL2(t, a, ...) #a, __SC_STR_ADECL1(__VA_ARGS__)
...@@ -134,54 +118,43 @@ struct perf_event_attr; ...@@ -134,54 +118,43 @@ struct perf_event_attr;
#define __SC_STR_TDECL5(t, a, ...) #t, __SC_STR_TDECL4(__VA_ARGS__) #define __SC_STR_TDECL5(t, a, ...) #t, __SC_STR_TDECL4(__VA_ARGS__)
#define __SC_STR_TDECL6(t, a, ...) #t, __SC_STR_TDECL5(__VA_ARGS__) #define __SC_STR_TDECL6(t, a, ...) #t, __SC_STR_TDECL5(__VA_ARGS__)
extern struct ftrace_event_class event_class_syscall_enter;
extern struct ftrace_event_class event_class_syscall_exit;
extern struct trace_event_functions enter_syscall_print_funcs;
extern struct trace_event_functions exit_syscall_print_funcs;
#define SYSCALL_TRACE_ENTER_EVENT(sname) \ #define SYSCALL_TRACE_ENTER_EVENT(sname) \
static const struct syscall_metadata __syscall_meta_##sname; \ static struct syscall_metadata __syscall_meta_##sname; \
static struct ftrace_event_call \ static struct ftrace_event_call \
__attribute__((__aligned__(4))) event_enter_##sname; \ __attribute__((__aligned__(4))) event_enter_##sname; \
static struct trace_event enter_syscall_print_##sname = { \
.trace = print_syscall_enter, \
}; \
static struct ftrace_event_call __used \ static struct ftrace_event_call __used \
__attribute__((__aligned__(4))) \ __attribute__((__aligned__(4))) \
__attribute__((section("_ftrace_events"))) \ __attribute__((section("_ftrace_events"))) \
event_enter_##sname = { \ event_enter_##sname = { \
.name = "sys_enter"#sname, \ .name = "sys_enter"#sname, \
.system = "syscalls", \ .class = &event_class_syscall_enter, \
.event = &enter_syscall_print_##sname, \ .event.funcs = &enter_syscall_print_funcs, \
.raw_init = init_syscall_trace, \
.define_fields = syscall_enter_define_fields, \
.regfunc = reg_event_syscall_enter, \
.unregfunc = unreg_event_syscall_enter, \
.data = (void *)&__syscall_meta_##sname,\ .data = (void *)&__syscall_meta_##sname,\
TRACE_SYS_ENTER_PERF_INIT(sname) \
} }
#define SYSCALL_TRACE_EXIT_EVENT(sname) \ #define SYSCALL_TRACE_EXIT_EVENT(sname) \
static const struct syscall_metadata __syscall_meta_##sname; \ static struct syscall_metadata __syscall_meta_##sname; \
static struct ftrace_event_call \ static struct ftrace_event_call \
__attribute__((__aligned__(4))) event_exit_##sname; \ __attribute__((__aligned__(4))) event_exit_##sname; \
static struct trace_event exit_syscall_print_##sname = { \
.trace = print_syscall_exit, \
}; \
static struct ftrace_event_call __used \ static struct ftrace_event_call __used \
__attribute__((__aligned__(4))) \ __attribute__((__aligned__(4))) \
__attribute__((section("_ftrace_events"))) \ __attribute__((section("_ftrace_events"))) \
event_exit_##sname = { \ event_exit_##sname = { \
.name = "sys_exit"#sname, \ .name = "sys_exit"#sname, \
.system = "syscalls", \ .class = &event_class_syscall_exit, \
.event = &exit_syscall_print_##sname, \ .event.funcs = &exit_syscall_print_funcs, \
.raw_init = init_syscall_trace, \
.define_fields = syscall_exit_define_fields, \
.regfunc = reg_event_syscall_exit, \
.unregfunc = unreg_event_syscall_exit, \
.data = (void *)&__syscall_meta_##sname,\ .data = (void *)&__syscall_meta_##sname,\
TRACE_SYS_EXIT_PERF_INIT(sname) \
} }
#define SYSCALL_METADATA(sname, nb) \ #define SYSCALL_METADATA(sname, nb) \
SYSCALL_TRACE_ENTER_EVENT(sname); \ SYSCALL_TRACE_ENTER_EVENT(sname); \
SYSCALL_TRACE_EXIT_EVENT(sname); \ SYSCALL_TRACE_EXIT_EVENT(sname); \
static const struct syscall_metadata __used \ static struct syscall_metadata __used \
__attribute__((__aligned__(4))) \ __attribute__((__aligned__(4))) \
__attribute__((section("__syscalls_metadata"))) \ __attribute__((section("__syscalls_metadata"))) \
__syscall_meta_##sname = { \ __syscall_meta_##sname = { \
...@@ -191,12 +164,14 @@ struct perf_event_attr; ...@@ -191,12 +164,14 @@ struct perf_event_attr;
.args = args_##sname, \ .args = args_##sname, \
.enter_event = &event_enter_##sname, \ .enter_event = &event_enter_##sname, \
.exit_event = &event_exit_##sname, \ .exit_event = &event_exit_##sname, \
.enter_fields = LIST_HEAD_INIT(__syscall_meta_##sname.enter_fields), \
.exit_fields = LIST_HEAD_INIT(__syscall_meta_##sname.exit_fields), \
}; };
#define SYSCALL_DEFINE0(sname) \ #define SYSCALL_DEFINE0(sname) \
SYSCALL_TRACE_ENTER_EVENT(_##sname); \ SYSCALL_TRACE_ENTER_EVENT(_##sname); \
SYSCALL_TRACE_EXIT_EVENT(_##sname); \ SYSCALL_TRACE_EXIT_EVENT(_##sname); \
static const struct syscall_metadata __used \ static struct syscall_metadata __used \
__attribute__((__aligned__(4))) \ __attribute__((__aligned__(4))) \
__attribute__((section("__syscalls_metadata"))) \ __attribute__((section("__syscalls_metadata"))) \
__syscall_meta__##sname = { \ __syscall_meta__##sname = { \
...@@ -204,6 +179,8 @@ struct perf_event_attr; ...@@ -204,6 +179,8 @@ struct perf_event_attr;
.nb_args = 0, \ .nb_args = 0, \
.enter_event = &event_enter__##sname, \ .enter_event = &event_enter__##sname, \
.exit_event = &event_exit__##sname, \ .exit_event = &event_exit__##sname, \
.enter_fields = LIST_HEAD_INIT(__syscall_meta__##sname.enter_fields), \
.exit_fields = LIST_HEAD_INIT(__syscall_meta__##sname.exit_fields), \
}; \ }; \
asmlinkage long sys_##sname(void) asmlinkage long sys_##sname(void)
#else #else
......
...@@ -20,12 +20,17 @@ ...@@ -20,12 +20,17 @@
struct module; struct module;
struct tracepoint; struct tracepoint;
struct tracepoint_func {
void *func;
void *data;
};
struct tracepoint { struct tracepoint {
const char *name; /* Tracepoint name */ const char *name; /* Tracepoint name */
int state; /* State. */ int state; /* State. */
void (*regfunc)(void); void (*regfunc)(void);
void (*unregfunc)(void); void (*unregfunc)(void);
void **funcs; struct tracepoint_func *funcs;
} __attribute__((aligned(32))); /* } __attribute__((aligned(32))); /*
* Aligned on 32 bytes because it is * Aligned on 32 bytes because it is
* globally visible and gcc happily * globally visible and gcc happily
...@@ -37,16 +42,19 @@ struct tracepoint { ...@@ -37,16 +42,19 @@ struct tracepoint {
* Connect a probe to a tracepoint. * Connect a probe to a tracepoint.
* Internal API, should not be used directly. * Internal API, should not be used directly.
*/ */
extern int tracepoint_probe_register(const char *name, void *probe); extern int tracepoint_probe_register(const char *name, void *probe, void *data);
/* /*
* Disconnect a probe from a tracepoint. * Disconnect a probe from a tracepoint.
* Internal API, should not be used directly. * Internal API, should not be used directly.
*/ */
extern int tracepoint_probe_unregister(const char *name, void *probe); extern int
tracepoint_probe_unregister(const char *name, void *probe, void *data);
extern int tracepoint_probe_register_noupdate(const char *name, void *probe); extern int tracepoint_probe_register_noupdate(const char *name, void *probe,
extern int tracepoint_probe_unregister_noupdate(const char *name, void *probe); void *data);
extern int tracepoint_probe_unregister_noupdate(const char *name, void *probe,
void *data);
extern void tracepoint_probe_update_all(void); extern void tracepoint_probe_update_all(void);
struct tracepoint_iter { struct tracepoint_iter {
...@@ -102,17 +110,27 @@ static inline void tracepoint_update_probe_range(struct tracepoint *begin, ...@@ -102,17 +110,27 @@ static inline void tracepoint_update_probe_range(struct tracepoint *begin,
/* /*
* it_func[0] is never NULL because there is at least one element in the array * it_func[0] is never NULL because there is at least one element in the array
* when the array itself is non NULL. * when the array itself is non NULL.
*
* Note, the proto and args passed in includes "__data" as the first parameter.
* The reason for this is to handle the "void" prototype. If a tracepoint
* has a "void" prototype, then it is invalid to declare a function
* as "(void *, void)". The DECLARE_TRACE_NOARGS() will pass in just
* "void *data", where as the DECLARE_TRACE() will pass in "void *data, proto".
*/ */
#define __DO_TRACE(tp, proto, args) \ #define __DO_TRACE(tp, proto, args) \
do { \ do { \
void **it_func; \ struct tracepoint_func *it_func_ptr; \
void *it_func; \
void *__data; \
\ \
rcu_read_lock_sched_notrace(); \ rcu_read_lock_sched_notrace(); \
it_func = rcu_dereference_sched((tp)->funcs); \ it_func_ptr = rcu_dereference_sched((tp)->funcs); \
if (it_func) { \ if (it_func_ptr) { \
do { \ do { \
((void(*)(proto))(*it_func))(args); \ it_func = (it_func_ptr)->func; \
} while (*(++it_func)); \ __data = (it_func_ptr)->data; \
((void(*)(proto))(it_func))(args); \
} while ((++it_func_ptr)->func); \
} \ } \
rcu_read_unlock_sched_notrace(); \ rcu_read_unlock_sched_notrace(); \
} while (0) } while (0)
...@@ -122,24 +140,32 @@ static inline void tracepoint_update_probe_range(struct tracepoint *begin, ...@@ -122,24 +140,32 @@ static inline void tracepoint_update_probe_range(struct tracepoint *begin,
* not add unwanted padding between the beginning of the section and the * not add unwanted padding between the beginning of the section and the
* structure. Force alignment to the same alignment as the section start. * structure. Force alignment to the same alignment as the section start.
*/ */
#define DECLARE_TRACE(name, proto, args) \ #define __DECLARE_TRACE(name, proto, args, data_proto, data_args) \
extern struct tracepoint __tracepoint_##name; \ extern struct tracepoint __tracepoint_##name; \
static inline void trace_##name(proto) \ static inline void trace_##name(proto) \
{ \ { \
if (unlikely(__tracepoint_##name.state)) \ if (unlikely(__tracepoint_##name.state)) \
__DO_TRACE(&__tracepoint_##name, \ __DO_TRACE(&__tracepoint_##name, \
TP_PROTO(proto), TP_ARGS(args)); \ TP_PROTO(data_proto), \
TP_ARGS(data_args)); \
} \
static inline int \
register_trace_##name(void (*probe)(data_proto), void *data) \
{ \
return tracepoint_probe_register(#name, (void *)probe, \
data); \
} \ } \
static inline int register_trace_##name(void (*probe)(proto)) \ static inline int \
unregister_trace_##name(void (*probe)(data_proto), void *data) \
{ \ { \
return tracepoint_probe_register(#name, (void *)probe); \ return tracepoint_probe_unregister(#name, (void *)probe, \
data); \
} \ } \
static inline int unregister_trace_##name(void (*probe)(proto)) \ static inline void \
check_trace_callback_type_##name(void (*cb)(data_proto)) \
{ \ { \
return tracepoint_probe_unregister(#name, (void *)probe);\
} }
#define DEFINE_TRACE_FN(name, reg, unreg) \ #define DEFINE_TRACE_FN(name, reg, unreg) \
static const char __tpstrtab_##name[] \ static const char __tpstrtab_##name[] \
__attribute__((section("__tracepoints_strings"))) = #name; \ __attribute__((section("__tracepoints_strings"))) = #name; \
...@@ -156,18 +182,23 @@ static inline void tracepoint_update_probe_range(struct tracepoint *begin, ...@@ -156,18 +182,23 @@ static inline void tracepoint_update_probe_range(struct tracepoint *begin,
EXPORT_SYMBOL(__tracepoint_##name) EXPORT_SYMBOL(__tracepoint_##name)
#else /* !CONFIG_TRACEPOINTS */ #else /* !CONFIG_TRACEPOINTS */
#define DECLARE_TRACE(name, proto, args) \ #define __DECLARE_TRACE(name, proto, args, data_proto, data_args) \
static inline void _do_trace_##name(struct tracepoint *tp, proto) \
{ } \
static inline void trace_##name(proto) \ static inline void trace_##name(proto) \
{ } \ { } \
static inline int register_trace_##name(void (*probe)(proto)) \ static inline int \
register_trace_##name(void (*probe)(data_proto), \
void *data) \
{ \ { \
return -ENOSYS; \ return -ENOSYS; \
} \ } \
static inline int unregister_trace_##name(void (*probe)(proto)) \ static inline int \
unregister_trace_##name(void (*probe)(data_proto), \
void *data) \
{ \ { \
return -ENOSYS; \ return -ENOSYS; \
} \
static inline void check_trace_callback_type_##name(void (*cb)(data_proto)) \
{ \
} }
#define DEFINE_TRACE_FN(name, reg, unreg) #define DEFINE_TRACE_FN(name, reg, unreg)
...@@ -176,6 +207,29 @@ static inline void tracepoint_update_probe_range(struct tracepoint *begin, ...@@ -176,6 +207,29 @@ static inline void tracepoint_update_probe_range(struct tracepoint *begin,
#define EXPORT_TRACEPOINT_SYMBOL(name) #define EXPORT_TRACEPOINT_SYMBOL(name)
#endif /* CONFIG_TRACEPOINTS */ #endif /* CONFIG_TRACEPOINTS */
/*
* The need for the DECLARE_TRACE_NOARGS() is to handle the prototype
* (void). "void" is a special value in a function prototype and can
* not be combined with other arguments. Since the DECLARE_TRACE()
* macro adds a data element at the beginning of the prototype,
* we need a way to differentiate "(void *data, proto)" from
* "(void *data, void)". The second prototype is invalid.
*
* DECLARE_TRACE_NOARGS() passes "void" as the tracepoint prototype
* and "void *__data" as the callback prototype.
*
* DECLARE_TRACE() passes "proto" as the tracepoint protoype and
* "void *__data, proto" as the callback prototype.
*/
#define DECLARE_TRACE_NOARGS(name) \
__DECLARE_TRACE(name, void, , void *__data, __data)
#define DECLARE_TRACE(name, proto, args) \
__DECLARE_TRACE(name, PARAMS(proto), PARAMS(args), \
PARAMS(void *__data, proto), \
PARAMS(__data, args))
#endif /* DECLARE_TRACE */ #endif /* DECLARE_TRACE */
#ifndef TRACE_EVENT #ifndef TRACE_EVENT
......
...@@ -62,10 +62,13 @@ ...@@ -62,10 +62,13 @@
struct trace_entry ent; \ struct trace_entry ent; \
tstruct \ tstruct \
char __data[0]; \ char __data[0]; \
}; }; \
\
static struct ftrace_event_class event_class_##name;
#undef DEFINE_EVENT #undef DEFINE_EVENT
#define DEFINE_EVENT(template, name, proto, args) \ #define DEFINE_EVENT(template, name, proto, args) \
static struct ftrace_event_call \ static struct ftrace_event_call __used \
__attribute__((__aligned__(4))) event_##name __attribute__((__aligned__(4))) event_##name
#undef DEFINE_EVENT_PRINT #undef DEFINE_EVENT_PRINT
...@@ -147,7 +150,7 @@ ...@@ -147,7 +150,7 @@
* *
* entry = iter->ent; * entry = iter->ent;
* *
* if (entry->type != event_<call>.id) { * if (entry->type != event_<call>->event.type) {
* WARN_ON_ONCE(1); * WARN_ON_ONCE(1);
* return TRACE_TYPE_UNHANDLED; * return TRACE_TYPE_UNHANDLED;
* } * }
...@@ -206,18 +209,22 @@ ...@@ -206,18 +209,22 @@
#undef DECLARE_EVENT_CLASS #undef DECLARE_EVENT_CLASS
#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
static notrace enum print_line_t \ static notrace enum print_line_t \
ftrace_raw_output_id_##call(int event_id, const char *name, \ ftrace_raw_output_##call(struct trace_iterator *iter, int flags, \
struct trace_iterator *iter, int flags) \ struct trace_event *trace_event) \
{ \ { \
struct ftrace_event_call *event; \
struct trace_seq *s = &iter->seq; \ struct trace_seq *s = &iter->seq; \
struct ftrace_raw_##call *field; \ struct ftrace_raw_##call *field; \
struct trace_entry *entry; \ struct trace_entry *entry; \
struct trace_seq *p; \ struct trace_seq *p; \
int ret; \ int ret; \
\ \
event = container_of(trace_event, struct ftrace_event_call, \
event); \
\
entry = iter->ent; \ entry = iter->ent; \
\ \
if (entry->type != event_id) { \ if (entry->type != event->event.type) { \
WARN_ON_ONCE(1); \ WARN_ON_ONCE(1); \
return TRACE_TYPE_UNHANDLED; \ return TRACE_TYPE_UNHANDLED; \
} \ } \
...@@ -226,7 +233,7 @@ ftrace_raw_output_id_##call(int event_id, const char *name, \ ...@@ -226,7 +233,7 @@ ftrace_raw_output_id_##call(int event_id, const char *name, \
\ \
p = &get_cpu_var(ftrace_event_seq); \ p = &get_cpu_var(ftrace_event_seq); \
trace_seq_init(p); \ trace_seq_init(p); \
ret = trace_seq_printf(s, "%s: ", name); \ ret = trace_seq_printf(s, "%s: ", event->name); \
if (ret) \ if (ret) \
ret = trace_seq_printf(s, print); \ ret = trace_seq_printf(s, print); \
put_cpu(); \ put_cpu(); \
...@@ -234,21 +241,16 @@ ftrace_raw_output_id_##call(int event_id, const char *name, \ ...@@ -234,21 +241,16 @@ ftrace_raw_output_id_##call(int event_id, const char *name, \
return TRACE_TYPE_PARTIAL_LINE; \ return TRACE_TYPE_PARTIAL_LINE; \
\ \
return TRACE_TYPE_HANDLED; \ return TRACE_TYPE_HANDLED; \
} } \
static struct trace_event_functions ftrace_event_type_funcs_##call = { \
#undef DEFINE_EVENT .trace = ftrace_raw_output_##call, \
#define DEFINE_EVENT(template, name, proto, args) \ };
static notrace enum print_line_t \
ftrace_raw_output_##name(struct trace_iterator *iter, int flags) \
{ \
return ftrace_raw_output_id_##template(event_##name.id, \
#name, iter, flags); \
}
#undef DEFINE_EVENT_PRINT #undef DEFINE_EVENT_PRINT
#define DEFINE_EVENT_PRINT(template, call, proto, args, print) \ #define DEFINE_EVENT_PRINT(template, call, proto, args, print) \
static notrace enum print_line_t \ static notrace enum print_line_t \
ftrace_raw_output_##call(struct trace_iterator *iter, int flags) \ ftrace_raw_output_##call(struct trace_iterator *iter, int flags, \
struct trace_event *event) \
{ \ { \
struct trace_seq *s = &iter->seq; \ struct trace_seq *s = &iter->seq; \
struct ftrace_raw_##template *field; \ struct ftrace_raw_##template *field; \
...@@ -258,7 +260,7 @@ ftrace_raw_output_##call(struct trace_iterator *iter, int flags) \ ...@@ -258,7 +260,7 @@ ftrace_raw_output_##call(struct trace_iterator *iter, int flags) \
\ \
entry = iter->ent; \ entry = iter->ent; \
\ \
if (entry->type != event_##call.id) { \ if (entry->type != event_##call.event.type) { \
WARN_ON_ONCE(1); \ WARN_ON_ONCE(1); \
return TRACE_TYPE_UNHANDLED; \ return TRACE_TYPE_UNHANDLED; \
} \ } \
...@@ -275,7 +277,10 @@ ftrace_raw_output_##call(struct trace_iterator *iter, int flags) \ ...@@ -275,7 +277,10 @@ ftrace_raw_output_##call(struct trace_iterator *iter, int flags) \
return TRACE_TYPE_PARTIAL_LINE; \ return TRACE_TYPE_PARTIAL_LINE; \
\ \
return TRACE_TYPE_HANDLED; \ return TRACE_TYPE_HANDLED; \
} } \
static struct trace_event_functions ftrace_event_type_funcs_##call = { \
.trace = ftrace_raw_output_##call, \
};
#include TRACE_INCLUDE(TRACE_INCLUDE_FILE) #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
...@@ -381,80 +386,18 @@ static inline notrace int ftrace_get_offsets_##call( \ ...@@ -381,80 +386,18 @@ static inline notrace int ftrace_get_offsets_##call( \
#include TRACE_INCLUDE(TRACE_INCLUDE_FILE) #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
#ifdef CONFIG_PERF_EVENTS
/*
* Generate the functions needed for tracepoint perf_event support.
*
* NOTE: The insertion profile callback (ftrace_profile_<call>) is defined later
*
* static int ftrace_profile_enable_<call>(void)
* {
* return register_trace_<call>(ftrace_profile_<call>);
* }
*
* static void ftrace_profile_disable_<call>(void)
* {
* unregister_trace_<call>(ftrace_profile_<call>);
* }
*
*/
#undef DECLARE_EVENT_CLASS
#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print)
#undef DEFINE_EVENT
#define DEFINE_EVENT(template, name, proto, args) \
\
static void perf_trace_##name(proto); \
\
static notrace int \
perf_trace_enable_##name(struct ftrace_event_call *unused) \
{ \
return register_trace_##name(perf_trace_##name); \
} \
\
static notrace void \
perf_trace_disable_##name(struct ftrace_event_call *unused) \
{ \
unregister_trace_##name(perf_trace_##name); \
}
#undef DEFINE_EVENT_PRINT
#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
#endif /* CONFIG_PERF_EVENTS */
/* /*
* Stage 4 of the trace events. * Stage 4 of the trace events.
* *
* Override the macros in <trace/trace_events.h> to include the following: * Override the macros in <trace/trace_events.h> to include the following:
* *
* static void ftrace_event_<call>(proto)
* {
* event_trace_printk(_RET_IP_, "<call>: " <fmt>);
* }
*
* static int ftrace_reg_event_<call>(struct ftrace_event_call *unused)
* {
* return register_trace_<call>(ftrace_event_<call>);
* }
*
* static void ftrace_unreg_event_<call>(struct ftrace_event_call *unused)
* {
* unregister_trace_<call>(ftrace_event_<call>);
* }
*
*
* For those macros defined with TRACE_EVENT: * For those macros defined with TRACE_EVENT:
* *
* static struct ftrace_event_call event_<call>; * static struct ftrace_event_call event_<call>;
* *
* static void ftrace_raw_event_<call>(proto) * static void ftrace_raw_event_<call>(void *__data, proto)
* { * {
* struct ftrace_event_call *event_call = __data;
* struct ftrace_data_offsets_<call> __maybe_unused __data_offsets; * struct ftrace_data_offsets_<call> __maybe_unused __data_offsets;
* struct ring_buffer_event *event; * struct ring_buffer_event *event;
* struct ftrace_raw_<call> *entry; <-- defined in stage 1 * struct ftrace_raw_<call> *entry; <-- defined in stage 1
...@@ -469,7 +412,7 @@ perf_trace_disable_##name(struct ftrace_event_call *unused) \ ...@@ -469,7 +412,7 @@ perf_trace_disable_##name(struct ftrace_event_call *unused) \
* __data_size = ftrace_get_offsets_<call>(&__data_offsets, args); * __data_size = ftrace_get_offsets_<call>(&__data_offsets, args);
* *
* event = trace_current_buffer_lock_reserve(&buffer, * event = trace_current_buffer_lock_reserve(&buffer,
* event_<call>.id, * event_<call>->event.type,
* sizeof(*entry) + __data_size, * sizeof(*entry) + __data_size,
* irq_flags, pc); * irq_flags, pc);
* if (!event) * if (!event)
...@@ -484,43 +427,42 @@ perf_trace_disable_##name(struct ftrace_event_call *unused) \ ...@@ -484,43 +427,42 @@ perf_trace_disable_##name(struct ftrace_event_call *unused) \
* event, irq_flags, pc); * event, irq_flags, pc);
* } * }
* *
* static int ftrace_raw_reg_event_<call>(struct ftrace_event_call *unused)
* {
* return register_trace_<call>(ftrace_raw_event_<call>);
* }
*
* static void ftrace_unreg_event_<call>(struct ftrace_event_call *unused)
* {
* unregister_trace_<call>(ftrace_raw_event_<call>);
* }
*
* static struct trace_event ftrace_event_type_<call> = { * static struct trace_event ftrace_event_type_<call> = {
* .trace = ftrace_raw_output_<call>, <-- stage 2 * .trace = ftrace_raw_output_<call>, <-- stage 2
* }; * };
* *
* static const char print_fmt_<call>[] = <TP_printk>; * static const char print_fmt_<call>[] = <TP_printk>;
* *
* static struct ftrace_event_class __used event_class_<template> = {
* .system = "<system>",
* .define_fields = ftrace_define_fields_<call>,
* .fields = LIST_HEAD_INIT(event_class_##call.fields),
* .raw_init = trace_event_raw_init,
* .probe = ftrace_raw_event_##call,
* };
*
* static struct ftrace_event_call __used * static struct ftrace_event_call __used
* __attribute__((__aligned__(4))) * __attribute__((__aligned__(4)))
* __attribute__((section("_ftrace_events"))) event_<call> = { * __attribute__((section("_ftrace_events"))) event_<call> = {
* .name = "<call>", * .name = "<call>",
* .system = "<system>", * .class = event_class_<template>,
* .raw_init = trace_event_raw_init, * .event = &ftrace_event_type_<call>,
* .regfunc = ftrace_reg_event_<call>,
* .unregfunc = ftrace_unreg_event_<call>,
* .print_fmt = print_fmt_<call>, * .print_fmt = print_fmt_<call>,
* .define_fields = ftrace_define_fields_<call>, * };
* }
* *
*/ */
#ifdef CONFIG_PERF_EVENTS #ifdef CONFIG_PERF_EVENTS
#define _TRACE_PERF_PROTO(call, proto) \
static notrace void \
perf_trace_##call(void *__data, proto);
#define _TRACE_PERF_INIT(call) \ #define _TRACE_PERF_INIT(call) \
.perf_event_enable = perf_trace_enable_##call, \ .perf_probe = perf_trace_##call,
.perf_event_disable = perf_trace_disable_##call,
#else #else
#define _TRACE_PERF_PROTO(call, proto)
#define _TRACE_PERF_INIT(call) #define _TRACE_PERF_INIT(call)
#endif /* CONFIG_PERF_EVENTS */ #endif /* CONFIG_PERF_EVENTS */
...@@ -554,9 +496,9 @@ perf_trace_disable_##name(struct ftrace_event_call *unused) \ ...@@ -554,9 +496,9 @@ perf_trace_disable_##name(struct ftrace_event_call *unused) \
#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
\ \
static notrace void \ static notrace void \
ftrace_raw_event_id_##call(struct ftrace_event_call *event_call, \ ftrace_raw_event_##call(void *__data, proto) \
proto) \
{ \ { \
struct ftrace_event_call *event_call = __data; \
struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\ struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\
struct ring_buffer_event *event; \ struct ring_buffer_event *event; \
struct ftrace_raw_##call *entry; \ struct ftrace_raw_##call *entry; \
...@@ -571,7 +513,7 @@ ftrace_raw_event_id_##call(struct ftrace_event_call *event_call, \ ...@@ -571,7 +513,7 @@ ftrace_raw_event_id_##call(struct ftrace_event_call *event_call, \
__data_size = ftrace_get_offsets_##call(&__data_offsets, args); \ __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \
\ \
event = trace_current_buffer_lock_reserve(&buffer, \ event = trace_current_buffer_lock_reserve(&buffer, \
event_call->id, \ event_call->event.type, \
sizeof(*entry) + __data_size, \ sizeof(*entry) + __data_size, \
irq_flags, pc); \ irq_flags, pc); \
if (!event) \ if (!event) \
...@@ -586,34 +528,21 @@ ftrace_raw_event_id_##call(struct ftrace_event_call *event_call, \ ...@@ -586,34 +528,21 @@ ftrace_raw_event_id_##call(struct ftrace_event_call *event_call, \
trace_nowake_buffer_unlock_commit(buffer, \ trace_nowake_buffer_unlock_commit(buffer, \
event, irq_flags, pc); \ event, irq_flags, pc); \
} }
/*
* The ftrace_test_probe is compiled out, it is only here as a build time check
* to make sure that if the tracepoint handling changes, the ftrace probe will
* fail to compile unless it too is updated.
*/
#undef DEFINE_EVENT #undef DEFINE_EVENT
#define DEFINE_EVENT(template, call, proto, args) \ #define DEFINE_EVENT(template, call, proto, args) \
\ static inline void ftrace_test_probe_##call(void) \
static notrace void ftrace_raw_event_##call(proto) \
{ \ { \
ftrace_raw_event_id_##template(&event_##call, args); \ check_trace_callback_type_##call(ftrace_raw_event_##template); \
} \ }
\
static notrace int \
ftrace_raw_reg_event_##call(struct ftrace_event_call *unused) \
{ \
return register_trace_##call(ftrace_raw_event_##call); \
} \
\
static notrace void \
ftrace_raw_unreg_event_##call(struct ftrace_event_call *unused) \
{ \
unregister_trace_##call(ftrace_raw_event_##call); \
} \
\
static struct trace_event ftrace_event_type_##call = { \
.trace = ftrace_raw_output_##call, \
};
#undef DEFINE_EVENT_PRINT #undef DEFINE_EVENT_PRINT
#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \ #define DEFINE_EVENT_PRINT(template, name, proto, args, print)
DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
#include TRACE_INCLUDE(TRACE_INCLUDE_FILE) #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
...@@ -630,7 +559,16 @@ static struct trace_event ftrace_event_type_##call = { \ ...@@ -630,7 +559,16 @@ static struct trace_event ftrace_event_type_##call = { \
#undef DECLARE_EVENT_CLASS #undef DECLARE_EVENT_CLASS
#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
static const char print_fmt_##call[] = print; _TRACE_PERF_PROTO(call, PARAMS(proto)); \
static const char print_fmt_##call[] = print; \
static struct ftrace_event_class __used event_class_##call = { \
.system = __stringify(TRACE_SYSTEM), \
.define_fields = ftrace_define_fields_##call, \
.fields = LIST_HEAD_INIT(event_class_##call.fields),\
.raw_init = trace_event_raw_init, \
.probe = ftrace_raw_event_##call, \
_TRACE_PERF_INIT(call) \
};
#undef DEFINE_EVENT #undef DEFINE_EVENT
#define DEFINE_EVENT(template, call, proto, args) \ #define DEFINE_EVENT(template, call, proto, args) \
...@@ -639,15 +577,10 @@ static struct ftrace_event_call __used \ ...@@ -639,15 +577,10 @@ static struct ftrace_event_call __used \
__attribute__((__aligned__(4))) \ __attribute__((__aligned__(4))) \
__attribute__((section("_ftrace_events"))) event_##call = { \ __attribute__((section("_ftrace_events"))) event_##call = { \
.name = #call, \ .name = #call, \
.system = __stringify(TRACE_SYSTEM), \ .class = &event_class_##template, \
.event = &ftrace_event_type_##call, \ .event.funcs = &ftrace_event_type_funcs_##template, \
.raw_init = trace_event_raw_init, \
.regfunc = ftrace_raw_reg_event_##call, \
.unregfunc = ftrace_raw_unreg_event_##call, \
.print_fmt = print_fmt_##template, \ .print_fmt = print_fmt_##template, \
.define_fields = ftrace_define_fields_##template, \ };
_TRACE_PERF_INIT(call) \
}
#undef DEFINE_EVENT_PRINT #undef DEFINE_EVENT_PRINT
#define DEFINE_EVENT_PRINT(template, call, proto, args, print) \ #define DEFINE_EVENT_PRINT(template, call, proto, args, print) \
...@@ -658,14 +591,9 @@ static struct ftrace_event_call __used \ ...@@ -658,14 +591,9 @@ static struct ftrace_event_call __used \
__attribute__((__aligned__(4))) \ __attribute__((__aligned__(4))) \
__attribute__((section("_ftrace_events"))) event_##call = { \ __attribute__((section("_ftrace_events"))) event_##call = { \
.name = #call, \ .name = #call, \
.system = __stringify(TRACE_SYSTEM), \ .class = &event_class_##template, \
.event = &ftrace_event_type_##call, \ .event.funcs = &ftrace_event_type_funcs_##call, \
.raw_init = trace_event_raw_init, \
.regfunc = ftrace_raw_reg_event_##call, \
.unregfunc = ftrace_raw_unreg_event_##call, \
.print_fmt = print_fmt_##call, \ .print_fmt = print_fmt_##call, \
.define_fields = ftrace_define_fields_##template, \
_TRACE_PERF_INIT(call) \
} }
#include TRACE_INCLUDE(TRACE_INCLUDE_FILE) #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
...@@ -765,17 +693,20 @@ __attribute__((section("_ftrace_events"))) event_##call = { \ ...@@ -765,17 +693,20 @@ __attribute__((section("_ftrace_events"))) event_##call = { \
#undef DECLARE_EVENT_CLASS #undef DECLARE_EVENT_CLASS
#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
static notrace void \ static notrace void \
perf_trace_templ_##call(struct ftrace_event_call *event_call, \ perf_trace_##call(void *__data, proto) \
struct pt_regs *__regs, proto) \
{ \ { \
struct ftrace_event_call *event_call = __data; \
struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\ struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\
struct ftrace_raw_##call *entry; \ struct ftrace_raw_##call *entry; \
struct pt_regs __regs; \
u64 __addr = 0, __count = 1; \ u64 __addr = 0, __count = 1; \
unsigned long irq_flags; \ struct hlist_head *head; \
int __entry_size; \ int __entry_size; \
int __data_size; \ int __data_size; \
int rctx; \ int rctx; \
\ \
perf_fetch_caller_regs(&__regs, 1); \
\
__data_size = ftrace_get_offsets_##call(&__data_offsets, args); \ __data_size = ftrace_get_offsets_##call(&__data_offsets, args); \
__entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),\ __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),\
sizeof(u64)); \ sizeof(u64)); \
...@@ -784,32 +715,34 @@ perf_trace_templ_##call(struct ftrace_event_call *event_call, \ ...@@ -784,32 +715,34 @@ perf_trace_templ_##call(struct ftrace_event_call *event_call, \
if (WARN_ONCE(__entry_size > PERF_MAX_TRACE_SIZE, \ if (WARN_ONCE(__entry_size > PERF_MAX_TRACE_SIZE, \
"profile buffer not large enough")) \ "profile buffer not large enough")) \
return; \ return; \
\
entry = (struct ftrace_raw_##call *)perf_trace_buf_prepare( \ entry = (struct ftrace_raw_##call *)perf_trace_buf_prepare( \
__entry_size, event_call->id, &rctx, &irq_flags); \ __entry_size, event_call->event.type, &__regs, &rctx); \
if (!entry) \ if (!entry) \
return; \ return; \
\
tstruct \ tstruct \
\ \
{ assign; } \ { assign; } \
\ \
head = per_cpu_ptr(event_call->perf_events, smp_processor_id());\
perf_trace_buf_submit(entry, __entry_size, rctx, __addr, \ perf_trace_buf_submit(entry, __entry_size, rctx, __addr, \
__count, irq_flags, __regs); \ __count, &__regs, head); \
} }
/*
* This part is compiled out, it is only here as a build time check
* to make sure that if the tracepoint handling changes, the
* perf probe will fail to compile unless it too is updated.
*/
#undef DEFINE_EVENT #undef DEFINE_EVENT
#define DEFINE_EVENT(template, call, proto, args) \ #define DEFINE_EVENT(template, call, proto, args) \
static notrace void perf_trace_##call(proto) \ static inline void perf_test_probe_##call(void) \
{ \ { \
struct ftrace_event_call *event_call = &event_##call; \ check_trace_callback_type_##call(perf_trace_##template); \
struct pt_regs *__regs = &get_cpu_var(perf_trace_regs); \
\
perf_fetch_caller_regs(__regs, 1); \
\
perf_trace_templ_##template(event_call, __regs, args); \
\
put_cpu_var(perf_trace_regs); \
} }
#undef DEFINE_EVENT_PRINT #undef DEFINE_EVENT_PRINT
#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \ #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args)) DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
......
...@@ -25,6 +25,8 @@ struct syscall_metadata { ...@@ -25,6 +25,8 @@ struct syscall_metadata {
int nb_args; int nb_args;
const char **types; const char **types;
const char **args; const char **args;
struct list_head enter_fields;
struct list_head exit_fields;
struct ftrace_event_call *enter_event; struct ftrace_event_call *enter_event;
struct ftrace_event_call *exit_event; struct ftrace_event_call *exit_event;
...@@ -34,16 +36,16 @@ struct syscall_metadata { ...@@ -34,16 +36,16 @@ struct syscall_metadata {
extern unsigned long arch_syscall_addr(int nr); extern unsigned long arch_syscall_addr(int nr);
extern int init_syscall_trace(struct ftrace_event_call *call); extern int init_syscall_trace(struct ftrace_event_call *call);
extern int syscall_enter_define_fields(struct ftrace_event_call *call);
extern int syscall_exit_define_fields(struct ftrace_event_call *call);
extern int reg_event_syscall_enter(struct ftrace_event_call *call); extern int reg_event_syscall_enter(struct ftrace_event_call *call);
extern void unreg_event_syscall_enter(struct ftrace_event_call *call); extern void unreg_event_syscall_enter(struct ftrace_event_call *call);
extern int reg_event_syscall_exit(struct ftrace_event_call *call); extern int reg_event_syscall_exit(struct ftrace_event_call *call);
extern void unreg_event_syscall_exit(struct ftrace_event_call *call); extern void unreg_event_syscall_exit(struct ftrace_event_call *call);
extern int extern int
ftrace_format_syscall(struct ftrace_event_call *call, struct trace_seq *s); ftrace_format_syscall(struct ftrace_event_call *call, struct trace_seq *s);
enum print_line_t print_syscall_enter(struct trace_iterator *iter, int flags); enum print_line_t print_syscall_enter(struct trace_iterator *iter, int flags,
enum print_line_t print_syscall_exit(struct trace_iterator *iter, int flags); struct trace_event *event);
enum print_line_t print_syscall_exit(struct trace_iterator *iter, int flags,
struct trace_event *event);
#endif #endif
#ifdef CONFIG_PERF_EVENTS #ifdef CONFIG_PERF_EVENTS
......
此差异已折叠。
...@@ -675,28 +675,33 @@ static void blk_add_trace_rq(struct request_queue *q, struct request *rq, ...@@ -675,28 +675,33 @@ static void blk_add_trace_rq(struct request_queue *q, struct request *rq,
} }
} }
static void blk_add_trace_rq_abort(struct request_queue *q, struct request *rq) static void blk_add_trace_rq_abort(void *ignore,
struct request_queue *q, struct request *rq)
{ {
blk_add_trace_rq(q, rq, BLK_TA_ABORT); blk_add_trace_rq(q, rq, BLK_TA_ABORT);
} }
static void blk_add_trace_rq_insert(struct request_queue *q, struct request *rq) static void blk_add_trace_rq_insert(void *ignore,
struct request_queue *q, struct request *rq)
{ {
blk_add_trace_rq(q, rq, BLK_TA_INSERT); blk_add_trace_rq(q, rq, BLK_TA_INSERT);
} }
static void blk_add_trace_rq_issue(struct request_queue *q, struct request *rq) static void blk_add_trace_rq_issue(void *ignore,
struct request_queue *q, struct request *rq)
{ {
blk_add_trace_rq(q, rq, BLK_TA_ISSUE); blk_add_trace_rq(q, rq, BLK_TA_ISSUE);
} }
static void blk_add_trace_rq_requeue(struct request_queue *q, static void blk_add_trace_rq_requeue(void *ignore,
struct request_queue *q,
struct request *rq) struct request *rq)
{ {
blk_add_trace_rq(q, rq, BLK_TA_REQUEUE); blk_add_trace_rq(q, rq, BLK_TA_REQUEUE);
} }
static void blk_add_trace_rq_complete(struct request_queue *q, static void blk_add_trace_rq_complete(void *ignore,
struct request_queue *q,
struct request *rq) struct request *rq)
{ {
blk_add_trace_rq(q, rq, BLK_TA_COMPLETE); blk_add_trace_rq(q, rq, BLK_TA_COMPLETE);
...@@ -724,34 +729,40 @@ static void blk_add_trace_bio(struct request_queue *q, struct bio *bio, ...@@ -724,34 +729,40 @@ static void blk_add_trace_bio(struct request_queue *q, struct bio *bio,
!bio_flagged(bio, BIO_UPTODATE), 0, NULL); !bio_flagged(bio, BIO_UPTODATE), 0, NULL);
} }
static void blk_add_trace_bio_bounce(struct request_queue *q, struct bio *bio) static void blk_add_trace_bio_bounce(void *ignore,
struct request_queue *q, struct bio *bio)
{ {
blk_add_trace_bio(q, bio, BLK_TA_BOUNCE); blk_add_trace_bio(q, bio, BLK_TA_BOUNCE);
} }
static void blk_add_trace_bio_complete(struct request_queue *q, struct bio *bio) static void blk_add_trace_bio_complete(void *ignore,
struct request_queue *q, struct bio *bio)
{ {
blk_add_trace_bio(q, bio, BLK_TA_COMPLETE); blk_add_trace_bio(q, bio, BLK_TA_COMPLETE);
} }
static void blk_add_trace_bio_backmerge(struct request_queue *q, static void blk_add_trace_bio_backmerge(void *ignore,
struct request_queue *q,
struct bio *bio) struct bio *bio)
{ {
blk_add_trace_bio(q, bio, BLK_TA_BACKMERGE); blk_add_trace_bio(q, bio, BLK_TA_BACKMERGE);
} }
static void blk_add_trace_bio_frontmerge(struct request_queue *q, static void blk_add_trace_bio_frontmerge(void *ignore,
struct request_queue *q,
struct bio *bio) struct bio *bio)
{ {
blk_add_trace_bio(q, bio, BLK_TA_FRONTMERGE); blk_add_trace_bio(q, bio, BLK_TA_FRONTMERGE);
} }
static void blk_add_trace_bio_queue(struct request_queue *q, struct bio *bio) static void blk_add_trace_bio_queue(void *ignore,
struct request_queue *q, struct bio *bio)
{ {
blk_add_trace_bio(q, bio, BLK_TA_QUEUE); blk_add_trace_bio(q, bio, BLK_TA_QUEUE);
} }
static void blk_add_trace_getrq(struct request_queue *q, static void blk_add_trace_getrq(void *ignore,
struct request_queue *q,
struct bio *bio, int rw) struct bio *bio, int rw)
{ {
if (bio) if (bio)
...@@ -765,7 +776,8 @@ static void blk_add_trace_getrq(struct request_queue *q, ...@@ -765,7 +776,8 @@ static void blk_add_trace_getrq(struct request_queue *q,
} }
static void blk_add_trace_sleeprq(struct request_queue *q, static void blk_add_trace_sleeprq(void *ignore,
struct request_queue *q,
struct bio *bio, int rw) struct bio *bio, int rw)
{ {
if (bio) if (bio)
...@@ -779,7 +791,7 @@ static void blk_add_trace_sleeprq(struct request_queue *q, ...@@ -779,7 +791,7 @@ static void blk_add_trace_sleeprq(struct request_queue *q,
} }
} }
static void blk_add_trace_plug(struct request_queue *q) static void blk_add_trace_plug(void *ignore, struct request_queue *q)
{ {
struct blk_trace *bt = q->blk_trace; struct blk_trace *bt = q->blk_trace;
...@@ -787,7 +799,7 @@ static void blk_add_trace_plug(struct request_queue *q) ...@@ -787,7 +799,7 @@ static void blk_add_trace_plug(struct request_queue *q)
__blk_add_trace(bt, 0, 0, 0, BLK_TA_PLUG, 0, 0, NULL); __blk_add_trace(bt, 0, 0, 0, BLK_TA_PLUG, 0, 0, NULL);
} }
static void blk_add_trace_unplug_io(struct request_queue *q) static void blk_add_trace_unplug_io(void *ignore, struct request_queue *q)
{ {
struct blk_trace *bt = q->blk_trace; struct blk_trace *bt = q->blk_trace;
...@@ -800,7 +812,7 @@ static void blk_add_trace_unplug_io(struct request_queue *q) ...@@ -800,7 +812,7 @@ static void blk_add_trace_unplug_io(struct request_queue *q)
} }
} }
static void blk_add_trace_unplug_timer(struct request_queue *q) static void blk_add_trace_unplug_timer(void *ignore, struct request_queue *q)
{ {
struct blk_trace *bt = q->blk_trace; struct blk_trace *bt = q->blk_trace;
...@@ -813,7 +825,8 @@ static void blk_add_trace_unplug_timer(struct request_queue *q) ...@@ -813,7 +825,8 @@ static void blk_add_trace_unplug_timer(struct request_queue *q)
} }
} }
static void blk_add_trace_split(struct request_queue *q, struct bio *bio, static void blk_add_trace_split(void *ignore,
struct request_queue *q, struct bio *bio,
unsigned int pdu) unsigned int pdu)
{ {
struct blk_trace *bt = q->blk_trace; struct blk_trace *bt = q->blk_trace;
...@@ -839,7 +852,8 @@ static void blk_add_trace_split(struct request_queue *q, struct bio *bio, ...@@ -839,7 +852,8 @@ static void blk_add_trace_split(struct request_queue *q, struct bio *bio,
* it spans a stripe (or similar). Add a trace for that action. * it spans a stripe (or similar). Add a trace for that action.
* *
**/ **/
static void blk_add_trace_remap(struct request_queue *q, struct bio *bio, static void blk_add_trace_remap(void *ignore,
struct request_queue *q, struct bio *bio,
dev_t dev, sector_t from) dev_t dev, sector_t from)
{ {
struct blk_trace *bt = q->blk_trace; struct blk_trace *bt = q->blk_trace;
...@@ -869,7 +883,8 @@ static void blk_add_trace_remap(struct request_queue *q, struct bio *bio, ...@@ -869,7 +883,8 @@ static void blk_add_trace_remap(struct request_queue *q, struct bio *bio,
* Add a trace for that action. * Add a trace for that action.
* *
**/ **/
static void blk_add_trace_rq_remap(struct request_queue *q, static void blk_add_trace_rq_remap(void *ignore,
struct request_queue *q,
struct request *rq, dev_t dev, struct request *rq, dev_t dev,
sector_t from) sector_t from)
{ {
...@@ -921,64 +936,64 @@ static void blk_register_tracepoints(void) ...@@ -921,64 +936,64 @@ static void blk_register_tracepoints(void)
{ {
int ret; int ret;
ret = register_trace_block_rq_abort(blk_add_trace_rq_abort); ret = register_trace_block_rq_abort(blk_add_trace_rq_abort, NULL);
WARN_ON(ret); WARN_ON(ret);
ret = register_trace_block_rq_insert(blk_add_trace_rq_insert); ret = register_trace_block_rq_insert(blk_add_trace_rq_insert, NULL);
WARN_ON(ret); WARN_ON(ret);
ret = register_trace_block_rq_issue(blk_add_trace_rq_issue); ret = register_trace_block_rq_issue(blk_add_trace_rq_issue, NULL);
WARN_ON(ret); WARN_ON(ret);
ret = register_trace_block_rq_requeue(blk_add_trace_rq_requeue); ret = register_trace_block_rq_requeue(blk_add_trace_rq_requeue, NULL);
WARN_ON(ret); WARN_ON(ret);
ret = register_trace_block_rq_complete(blk_add_trace_rq_complete); ret = register_trace_block_rq_complete(blk_add_trace_rq_complete, NULL);
WARN_ON(ret); WARN_ON(ret);
ret = register_trace_block_bio_bounce(blk_add_trace_bio_bounce); ret = register_trace_block_bio_bounce(blk_add_trace_bio_bounce, NULL);
WARN_ON(ret); WARN_ON(ret);
ret = register_trace_block_bio_complete(blk_add_trace_bio_complete); ret = register_trace_block_bio_complete(blk_add_trace_bio_complete, NULL);
WARN_ON(ret); WARN_ON(ret);
ret = register_trace_block_bio_backmerge(blk_add_trace_bio_backmerge); ret = register_trace_block_bio_backmerge(blk_add_trace_bio_backmerge, NULL);
WARN_ON(ret); WARN_ON(ret);
ret = register_trace_block_bio_frontmerge(blk_add_trace_bio_frontmerge); ret = register_trace_block_bio_frontmerge(blk_add_trace_bio_frontmerge, NULL);
WARN_ON(ret); WARN_ON(ret);
ret = register_trace_block_bio_queue(blk_add_trace_bio_queue); ret = register_trace_block_bio_queue(blk_add_trace_bio_queue, NULL);
WARN_ON(ret); WARN_ON(ret);
ret = register_trace_block_getrq(blk_add_trace_getrq); ret = register_trace_block_getrq(blk_add_trace_getrq, NULL);
WARN_ON(ret); WARN_ON(ret);
ret = register_trace_block_sleeprq(blk_add_trace_sleeprq); ret = register_trace_block_sleeprq(blk_add_trace_sleeprq, NULL);
WARN_ON(ret); WARN_ON(ret);
ret = register_trace_block_plug(blk_add_trace_plug); ret = register_trace_block_plug(blk_add_trace_plug, NULL);
WARN_ON(ret); WARN_ON(ret);
ret = register_trace_block_unplug_timer(blk_add_trace_unplug_timer); ret = register_trace_block_unplug_timer(blk_add_trace_unplug_timer, NULL);
WARN_ON(ret); WARN_ON(ret);
ret = register_trace_block_unplug_io(blk_add_trace_unplug_io); ret = register_trace_block_unplug_io(blk_add_trace_unplug_io, NULL);
WARN_ON(ret); WARN_ON(ret);
ret = register_trace_block_split(blk_add_trace_split); ret = register_trace_block_split(blk_add_trace_split, NULL);
WARN_ON(ret); WARN_ON(ret);
ret = register_trace_block_remap(blk_add_trace_remap); ret = register_trace_block_remap(blk_add_trace_remap, NULL);
WARN_ON(ret); WARN_ON(ret);
ret = register_trace_block_rq_remap(blk_add_trace_rq_remap); ret = register_trace_block_rq_remap(blk_add_trace_rq_remap, NULL);
WARN_ON(ret); WARN_ON(ret);
} }
static void blk_unregister_tracepoints(void) static void blk_unregister_tracepoints(void)
{ {
unregister_trace_block_rq_remap(blk_add_trace_rq_remap); unregister_trace_block_rq_remap(blk_add_trace_rq_remap, NULL);
unregister_trace_block_remap(blk_add_trace_remap); unregister_trace_block_remap(blk_add_trace_remap, NULL);
unregister_trace_block_split(blk_add_trace_split); unregister_trace_block_split(blk_add_trace_split, NULL);
unregister_trace_block_unplug_io(blk_add_trace_unplug_io); unregister_trace_block_unplug_io(blk_add_trace_unplug_io, NULL);
unregister_trace_block_unplug_timer(blk_add_trace_unplug_timer); unregister_trace_block_unplug_timer(blk_add_trace_unplug_timer, NULL);
unregister_trace_block_plug(blk_add_trace_plug); unregister_trace_block_plug(blk_add_trace_plug, NULL);
unregister_trace_block_sleeprq(blk_add_trace_sleeprq); unregister_trace_block_sleeprq(blk_add_trace_sleeprq, NULL);
unregister_trace_block_getrq(blk_add_trace_getrq); unregister_trace_block_getrq(blk_add_trace_getrq, NULL);
unregister_trace_block_bio_queue(blk_add_trace_bio_queue); unregister_trace_block_bio_queue(blk_add_trace_bio_queue, NULL);
unregister_trace_block_bio_frontmerge(blk_add_trace_bio_frontmerge); unregister_trace_block_bio_frontmerge(blk_add_trace_bio_frontmerge, NULL);
unregister_trace_block_bio_backmerge(blk_add_trace_bio_backmerge); unregister_trace_block_bio_backmerge(blk_add_trace_bio_backmerge, NULL);
unregister_trace_block_bio_complete(blk_add_trace_bio_complete); unregister_trace_block_bio_complete(blk_add_trace_bio_complete, NULL);
unregister_trace_block_bio_bounce(blk_add_trace_bio_bounce); unregister_trace_block_bio_bounce(blk_add_trace_bio_bounce, NULL);
unregister_trace_block_rq_complete(blk_add_trace_rq_complete); unregister_trace_block_rq_complete(blk_add_trace_rq_complete, NULL);
unregister_trace_block_rq_requeue(blk_add_trace_rq_requeue); unregister_trace_block_rq_requeue(blk_add_trace_rq_requeue, NULL);
unregister_trace_block_rq_issue(blk_add_trace_rq_issue); unregister_trace_block_rq_issue(blk_add_trace_rq_issue, NULL);
unregister_trace_block_rq_insert(blk_add_trace_rq_insert); unregister_trace_block_rq_insert(blk_add_trace_rq_insert, NULL);
unregister_trace_block_rq_abort(blk_add_trace_rq_abort); unregister_trace_block_rq_abort(blk_add_trace_rq_abort, NULL);
tracepoint_synchronize_unregister(); tracepoint_synchronize_unregister();
} }
...@@ -1321,7 +1336,7 @@ static enum print_line_t print_one_line(struct trace_iterator *iter, ...@@ -1321,7 +1336,7 @@ static enum print_line_t print_one_line(struct trace_iterator *iter,
} }
static enum print_line_t blk_trace_event_print(struct trace_iterator *iter, static enum print_line_t blk_trace_event_print(struct trace_iterator *iter,
int flags) int flags, struct trace_event *event)
{ {
return print_one_line(iter, false); return print_one_line(iter, false);
} }
...@@ -1343,7 +1358,8 @@ static int blk_trace_synthesize_old_trace(struct trace_iterator *iter) ...@@ -1343,7 +1358,8 @@ static int blk_trace_synthesize_old_trace(struct trace_iterator *iter)
} }
static enum print_line_t static enum print_line_t
blk_trace_event_print_binary(struct trace_iterator *iter, int flags) blk_trace_event_print_binary(struct trace_iterator *iter, int flags,
struct trace_event *event)
{ {
return blk_trace_synthesize_old_trace(iter) ? return blk_trace_synthesize_old_trace(iter) ?
TRACE_TYPE_HANDLED : TRACE_TYPE_PARTIAL_LINE; TRACE_TYPE_HANDLED : TRACE_TYPE_PARTIAL_LINE;
...@@ -1381,12 +1397,16 @@ static struct tracer blk_tracer __read_mostly = { ...@@ -1381,12 +1397,16 @@ static struct tracer blk_tracer __read_mostly = {
.set_flag = blk_tracer_set_flag, .set_flag = blk_tracer_set_flag,
}; };
static struct trace_event trace_blk_event = { static struct trace_event_functions trace_blk_event_funcs = {
.type = TRACE_BLK,
.trace = blk_trace_event_print, .trace = blk_trace_event_print,
.binary = blk_trace_event_print_binary, .binary = blk_trace_event_print_binary,
}; };
static struct trace_event trace_blk_event = {
.type = TRACE_BLK,
.funcs = &trace_blk_event_funcs,
};
static int __init init_blk_tracer(void) static int __init init_blk_tracer(void)
{ {
if (!register_ftrace_event(&trace_blk_event)) { if (!register_ftrace_event(&trace_blk_event)) {
......
...@@ -3234,7 +3234,8 @@ static int alloc_retstack_tasklist(struct ftrace_ret_stack **ret_stack_list) ...@@ -3234,7 +3234,8 @@ static int alloc_retstack_tasklist(struct ftrace_ret_stack **ret_stack_list)
} }
static void static void
ftrace_graph_probe_sched_switch(struct task_struct *prev, struct task_struct *next) ftrace_graph_probe_sched_switch(void *ignore,
struct task_struct *prev, struct task_struct *next)
{ {
unsigned long long timestamp; unsigned long long timestamp;
int index; int index;
...@@ -3288,7 +3289,7 @@ static int start_graph_tracing(void) ...@@ -3288,7 +3289,7 @@ static int start_graph_tracing(void)
} while (ret == -EAGAIN); } while (ret == -EAGAIN);
if (!ret) { if (!ret) {
ret = register_trace_sched_switch(ftrace_graph_probe_sched_switch); ret = register_trace_sched_switch(ftrace_graph_probe_sched_switch, NULL);
if (ret) if (ret)
pr_info("ftrace_graph: Couldn't activate tracepoint" pr_info("ftrace_graph: Couldn't activate tracepoint"
" probe to kernel_sched_switch\n"); " probe to kernel_sched_switch\n");
...@@ -3364,7 +3365,7 @@ void unregister_ftrace_graph(void) ...@@ -3364,7 +3365,7 @@ void unregister_ftrace_graph(void)
ftrace_graph_entry = ftrace_graph_entry_stub; ftrace_graph_entry = ftrace_graph_entry_stub;
ftrace_shutdown(FTRACE_STOP_FUNC_RET); ftrace_shutdown(FTRACE_STOP_FUNC_RET);
unregister_pm_notifier(&ftrace_suspend_notifier); unregister_pm_notifier(&ftrace_suspend_notifier);
unregister_trace_sched_switch(ftrace_graph_probe_sched_switch); unregister_trace_sched_switch(ftrace_graph_probe_sched_switch, NULL);
out: out:
mutex_unlock(&ftrace_lock); mutex_unlock(&ftrace_lock);
......
...@@ -95,7 +95,8 @@ static inline void kmemtrace_free(enum kmemtrace_type_id type_id, ...@@ -95,7 +95,8 @@ static inline void kmemtrace_free(enum kmemtrace_type_id type_id,
trace_wake_up(); trace_wake_up();
} }
static void kmemtrace_kmalloc(unsigned long call_site, static void kmemtrace_kmalloc(void *ignore,
unsigned long call_site,
const void *ptr, const void *ptr,
size_t bytes_req, size_t bytes_req,
size_t bytes_alloc, size_t bytes_alloc,
...@@ -105,7 +106,8 @@ static void kmemtrace_kmalloc(unsigned long call_site, ...@@ -105,7 +106,8 @@ static void kmemtrace_kmalloc(unsigned long call_site,
bytes_req, bytes_alloc, gfp_flags, -1); bytes_req, bytes_alloc, gfp_flags, -1);
} }
static void kmemtrace_kmem_cache_alloc(unsigned long call_site, static void kmemtrace_kmem_cache_alloc(void *ignore,
unsigned long call_site,
const void *ptr, const void *ptr,
size_t bytes_req, size_t bytes_req,
size_t bytes_alloc, size_t bytes_alloc,
...@@ -115,7 +117,8 @@ static void kmemtrace_kmem_cache_alloc(unsigned long call_site, ...@@ -115,7 +117,8 @@ static void kmemtrace_kmem_cache_alloc(unsigned long call_site,
bytes_req, bytes_alloc, gfp_flags, -1); bytes_req, bytes_alloc, gfp_flags, -1);
} }
static void kmemtrace_kmalloc_node(unsigned long call_site, static void kmemtrace_kmalloc_node(void *ignore,
unsigned long call_site,
const void *ptr, const void *ptr,
size_t bytes_req, size_t bytes_req,
size_t bytes_alloc, size_t bytes_alloc,
...@@ -126,7 +129,8 @@ static void kmemtrace_kmalloc_node(unsigned long call_site, ...@@ -126,7 +129,8 @@ static void kmemtrace_kmalloc_node(unsigned long call_site,
bytes_req, bytes_alloc, gfp_flags, node); bytes_req, bytes_alloc, gfp_flags, node);
} }
static void kmemtrace_kmem_cache_alloc_node(unsigned long call_site, static void kmemtrace_kmem_cache_alloc_node(void *ignore,
unsigned long call_site,
const void *ptr, const void *ptr,
size_t bytes_req, size_t bytes_req,
size_t bytes_alloc, size_t bytes_alloc,
...@@ -137,12 +141,14 @@ static void kmemtrace_kmem_cache_alloc_node(unsigned long call_site, ...@@ -137,12 +141,14 @@ static void kmemtrace_kmem_cache_alloc_node(unsigned long call_site,
bytes_req, bytes_alloc, gfp_flags, node); bytes_req, bytes_alloc, gfp_flags, node);
} }
static void kmemtrace_kfree(unsigned long call_site, const void *ptr) static void
kmemtrace_kfree(void *ignore, unsigned long call_site, const void *ptr)
{ {
kmemtrace_free(KMEMTRACE_TYPE_KMALLOC, call_site, ptr); kmemtrace_free(KMEMTRACE_TYPE_KMALLOC, call_site, ptr);
} }
static void kmemtrace_kmem_cache_free(unsigned long call_site, const void *ptr) static void kmemtrace_kmem_cache_free(void *ignore,
unsigned long call_site, const void *ptr)
{ {
kmemtrace_free(KMEMTRACE_TYPE_CACHE, call_site, ptr); kmemtrace_free(KMEMTRACE_TYPE_CACHE, call_site, ptr);
} }
...@@ -151,34 +157,34 @@ static int kmemtrace_start_probes(void) ...@@ -151,34 +157,34 @@ static int kmemtrace_start_probes(void)
{ {
int err; int err;
err = register_trace_kmalloc(kmemtrace_kmalloc); err = register_trace_kmalloc(kmemtrace_kmalloc, NULL);
if (err) if (err)
return err; return err;
err = register_trace_kmem_cache_alloc(kmemtrace_kmem_cache_alloc); err = register_trace_kmem_cache_alloc(kmemtrace_kmem_cache_alloc, NULL);
if (err) if (err)
return err; return err;
err = register_trace_kmalloc_node(kmemtrace_kmalloc_node); err = register_trace_kmalloc_node(kmemtrace_kmalloc_node, NULL);
if (err) if (err)
return err; return err;
err = register_trace_kmem_cache_alloc_node(kmemtrace_kmem_cache_alloc_node); err = register_trace_kmem_cache_alloc_node(kmemtrace_kmem_cache_alloc_node, NULL);
if (err) if (err)
return err; return err;
err = register_trace_kfree(kmemtrace_kfree); err = register_trace_kfree(kmemtrace_kfree, NULL);
if (err) if (err)
return err; return err;
err = register_trace_kmem_cache_free(kmemtrace_kmem_cache_free); err = register_trace_kmem_cache_free(kmemtrace_kmem_cache_free, NULL);
return err; return err;
} }
static void kmemtrace_stop_probes(void) static void kmemtrace_stop_probes(void)
{ {
unregister_trace_kmalloc(kmemtrace_kmalloc); unregister_trace_kmalloc(kmemtrace_kmalloc, NULL);
unregister_trace_kmem_cache_alloc(kmemtrace_kmem_cache_alloc); unregister_trace_kmem_cache_alloc(kmemtrace_kmem_cache_alloc, NULL);
unregister_trace_kmalloc_node(kmemtrace_kmalloc_node); unregister_trace_kmalloc_node(kmemtrace_kmalloc_node, NULL);
unregister_trace_kmem_cache_alloc_node(kmemtrace_kmem_cache_alloc_node); unregister_trace_kmem_cache_alloc_node(kmemtrace_kmem_cache_alloc_node, NULL);
unregister_trace_kfree(kmemtrace_kfree); unregister_trace_kfree(kmemtrace_kfree, NULL);
unregister_trace_kmem_cache_free(kmemtrace_kmem_cache_free); unregister_trace_kmem_cache_free(kmemtrace_kmem_cache_free, NULL);
} }
static int kmem_trace_init(struct trace_array *tr) static int kmem_trace_init(struct trace_array *tr)
...@@ -237,7 +243,8 @@ struct kmemtrace_user_event_alloc { ...@@ -237,7 +243,8 @@ struct kmemtrace_user_event_alloc {
}; };
static enum print_line_t static enum print_line_t
kmemtrace_print_alloc(struct trace_iterator *iter, int flags) kmemtrace_print_alloc(struct trace_iterator *iter, int flags,
struct trace_event *event)
{ {
struct trace_seq *s = &iter->seq; struct trace_seq *s = &iter->seq;
struct kmemtrace_alloc_entry *entry; struct kmemtrace_alloc_entry *entry;
...@@ -257,7 +264,8 @@ kmemtrace_print_alloc(struct trace_iterator *iter, int flags) ...@@ -257,7 +264,8 @@ kmemtrace_print_alloc(struct trace_iterator *iter, int flags)
} }
static enum print_line_t static enum print_line_t
kmemtrace_print_free(struct trace_iterator *iter, int flags) kmemtrace_print_free(struct trace_iterator *iter, int flags,
struct trace_event *event)
{ {
struct trace_seq *s = &iter->seq; struct trace_seq *s = &iter->seq;
struct kmemtrace_free_entry *entry; struct kmemtrace_free_entry *entry;
...@@ -275,7 +283,8 @@ kmemtrace_print_free(struct trace_iterator *iter, int flags) ...@@ -275,7 +283,8 @@ kmemtrace_print_free(struct trace_iterator *iter, int flags)
} }
static enum print_line_t static enum print_line_t
kmemtrace_print_alloc_user(struct trace_iterator *iter, int flags) kmemtrace_print_alloc_user(struct trace_iterator *iter, int flags,
struct trace_event *event)
{ {
struct trace_seq *s = &iter->seq; struct trace_seq *s = &iter->seq;
struct kmemtrace_alloc_entry *entry; struct kmemtrace_alloc_entry *entry;
...@@ -309,7 +318,8 @@ kmemtrace_print_alloc_user(struct trace_iterator *iter, int flags) ...@@ -309,7 +318,8 @@ kmemtrace_print_alloc_user(struct trace_iterator *iter, int flags)
} }
static enum print_line_t static enum print_line_t
kmemtrace_print_free_user(struct trace_iterator *iter, int flags) kmemtrace_print_free_user(struct trace_iterator *iter, int flags,
struct trace_event *event)
{ {
struct trace_seq *s = &iter->seq; struct trace_seq *s = &iter->seq;
struct kmemtrace_free_entry *entry; struct kmemtrace_free_entry *entry;
...@@ -463,18 +473,26 @@ static enum print_line_t kmemtrace_print_line(struct trace_iterator *iter) ...@@ -463,18 +473,26 @@ static enum print_line_t kmemtrace_print_line(struct trace_iterator *iter)
} }
} }
static struct trace_event kmem_trace_alloc = { static struct trace_event_functions kmem_trace_alloc_funcs = {
.type = TRACE_KMEM_ALLOC,
.trace = kmemtrace_print_alloc, .trace = kmemtrace_print_alloc,
.binary = kmemtrace_print_alloc_user, .binary = kmemtrace_print_alloc_user,
}; };
static struct trace_event kmem_trace_free = { static struct trace_event kmem_trace_alloc = {
.type = TRACE_KMEM_FREE, .type = TRACE_KMEM_ALLOC,
.funcs = &kmem_trace_alloc_funcs,
};
static struct trace_event_functions kmem_trace_free_funcs = {
.trace = kmemtrace_print_free, .trace = kmemtrace_print_free,
.binary = kmemtrace_print_free_user, .binary = kmemtrace_print_free_user,
}; };
static struct trace_event kmem_trace_free = {
.type = TRACE_KMEM_FREE,
.funcs = &kmem_trace_free_funcs,
};
static struct tracer kmem_tracer __read_mostly = { static struct tracer kmem_tracer __read_mostly = {
.name = "kmemtrace", .name = "kmemtrace",
.init = kmem_trace_init, .init = kmem_trace_init,
......
...@@ -1936,7 +1936,7 @@ static enum print_line_t print_trace_fmt(struct trace_iterator *iter) ...@@ -1936,7 +1936,7 @@ static enum print_line_t print_trace_fmt(struct trace_iterator *iter)
} }
if (event) if (event)
return event->trace(iter, sym_flags); return event->funcs->trace(iter, sym_flags, event);
if (!trace_seq_printf(s, "Unknown type %d\n", entry->type)) if (!trace_seq_printf(s, "Unknown type %d\n", entry->type))
goto partial; goto partial;
...@@ -1962,7 +1962,7 @@ static enum print_line_t print_raw_fmt(struct trace_iterator *iter) ...@@ -1962,7 +1962,7 @@ static enum print_line_t print_raw_fmt(struct trace_iterator *iter)
event = ftrace_find_event(entry->type); event = ftrace_find_event(entry->type);
if (event) if (event)
return event->raw(iter, 0); return event->funcs->raw(iter, 0, event);
if (!trace_seq_printf(s, "%d ?\n", entry->type)) if (!trace_seq_printf(s, "%d ?\n", entry->type))
goto partial; goto partial;
...@@ -1989,7 +1989,7 @@ static enum print_line_t print_hex_fmt(struct trace_iterator *iter) ...@@ -1989,7 +1989,7 @@ static enum print_line_t print_hex_fmt(struct trace_iterator *iter)
event = ftrace_find_event(entry->type); event = ftrace_find_event(entry->type);
if (event) { if (event) {
enum print_line_t ret = event->hex(iter, 0); enum print_line_t ret = event->funcs->hex(iter, 0, event);
if (ret != TRACE_TYPE_HANDLED) if (ret != TRACE_TYPE_HANDLED)
return ret; return ret;
} }
...@@ -2014,7 +2014,8 @@ static enum print_line_t print_bin_fmt(struct trace_iterator *iter) ...@@ -2014,7 +2014,8 @@ static enum print_line_t print_bin_fmt(struct trace_iterator *iter)
} }
event = ftrace_find_event(entry->type); event = ftrace_find_event(entry->type);
return event ? event->binary(iter, 0) : TRACE_TYPE_HANDLED; return event ? event->funcs->binary(iter, 0, event) :
TRACE_TYPE_HANDLED;
} }
int trace_empty(struct trace_iterator *iter) int trace_empty(struct trace_iterator *iter)
......
...@@ -405,12 +405,12 @@ void ftrace_trace_userstack(struct ring_buffer *buffer, unsigned long flags, ...@@ -405,12 +405,12 @@ void ftrace_trace_userstack(struct ring_buffer *buffer, unsigned long flags,
void __trace_stack(struct trace_array *tr, unsigned long flags, int skip, void __trace_stack(struct trace_array *tr, unsigned long flags, int skip,
int pc); int pc);
#else #else
static inline void ftrace_trace_stack(struct trace_array *tr, static inline void ftrace_trace_stack(struct ring_buffer *buffer,
unsigned long flags, int skip, int pc) unsigned long flags, int skip, int pc)
{ {
} }
static inline void ftrace_trace_userstack(struct trace_array *tr, static inline void ftrace_trace_userstack(struct ring_buffer *buffer,
unsigned long flags, int pc) unsigned long flags, int pc)
{ {
} }
...@@ -778,12 +778,15 @@ extern void print_subsystem_event_filter(struct event_subsystem *system, ...@@ -778,12 +778,15 @@ extern void print_subsystem_event_filter(struct event_subsystem *system,
struct trace_seq *s); struct trace_seq *s);
extern int filter_assign_type(const char *type); extern int filter_assign_type(const char *type);
struct list_head *
trace_get_fields(struct ftrace_event_call *event_call);
static inline int static inline int
filter_check_discard(struct ftrace_event_call *call, void *rec, filter_check_discard(struct ftrace_event_call *call, void *rec,
struct ring_buffer *buffer, struct ring_buffer *buffer,
struct ring_buffer_event *event) struct ring_buffer_event *event)
{ {
if (unlikely(call->filter_active) && if (unlikely(call->flags & TRACE_EVENT_FL_FILTERED) &&
!filter_match_preds(call->filter, rec)) { !filter_match_preds(call->filter, rec)) {
ring_buffer_discard_commit(buffer, event); ring_buffer_discard_commit(buffer, event);
return 1; return 1;
......
...@@ -143,7 +143,7 @@ static void branch_trace_reset(struct trace_array *tr) ...@@ -143,7 +143,7 @@ static void branch_trace_reset(struct trace_array *tr)
} }
static enum print_line_t trace_branch_print(struct trace_iterator *iter, static enum print_line_t trace_branch_print(struct trace_iterator *iter,
int flags) int flags, struct trace_event *event)
{ {
struct trace_branch *field; struct trace_branch *field;
...@@ -167,9 +167,13 @@ static void branch_print_header(struct seq_file *s) ...@@ -167,9 +167,13 @@ static void branch_print_header(struct seq_file *s)
" |\n"); " |\n");
} }
static struct trace_event_functions trace_branch_funcs = {
.trace = trace_branch_print,
};
static struct trace_event trace_branch_event = { static struct trace_event trace_branch_event = {
.type = TRACE_BRANCH, .type = TRACE_BRANCH,
.trace = trace_branch_print, .funcs = &trace_branch_funcs,
}; };
static struct tracer branch_trace __read_mostly = static struct tracer branch_trace __read_mostly =
......
...@@ -9,13 +9,9 @@ ...@@ -9,13 +9,9 @@
#include <linux/kprobes.h> #include <linux/kprobes.h>
#include "trace.h" #include "trace.h"
DEFINE_PER_CPU(struct pt_regs, perf_trace_regs);
EXPORT_PER_CPU_SYMBOL_GPL(perf_trace_regs);
EXPORT_SYMBOL_GPL(perf_arch_fetch_caller_regs); EXPORT_SYMBOL_GPL(perf_arch_fetch_caller_regs);
static char *perf_trace_buf; static char *perf_trace_buf[4];
static char *perf_trace_buf_nmi;
/* /*
* Force it to be aligned to unsigned long to avoid misaligned accesses * Force it to be aligned to unsigned long to avoid misaligned accesses
...@@ -27,57 +23,82 @@ typedef typeof(unsigned long [PERF_MAX_TRACE_SIZE / sizeof(unsigned long)]) ...@@ -27,57 +23,82 @@ typedef typeof(unsigned long [PERF_MAX_TRACE_SIZE / sizeof(unsigned long)])
/* Count the events in use (per event id, not per instance) */ /* Count the events in use (per event id, not per instance) */
static int total_ref_count; static int total_ref_count;
static int perf_trace_event_enable(struct ftrace_event_call *event) static int perf_trace_event_init(struct ftrace_event_call *tp_event,
struct perf_event *p_event)
{ {
char *buf; struct hlist_head *list;
int ret = -ENOMEM; int ret = -ENOMEM;
int cpu;
if (event->perf_refcount++ > 0) p_event->tp_event = tp_event;
if (tp_event->perf_refcount++ > 0)
return 0; return 0;
if (!total_ref_count) { list = alloc_percpu(struct hlist_head);
buf = (char *)alloc_percpu(perf_trace_t); if (!list)
if (!buf) goto fail;
goto fail_buf;
for_each_possible_cpu(cpu)
INIT_HLIST_HEAD(per_cpu_ptr(list, cpu));
rcu_assign_pointer(perf_trace_buf, buf); tp_event->perf_events = list;
if (!total_ref_count) {
char *buf;
int i;
for (i = 0; i < 4; i++) {
buf = (char *)alloc_percpu(perf_trace_t); buf = (char *)alloc_percpu(perf_trace_t);
if (!buf) if (!buf)
goto fail_buf_nmi; goto fail;
rcu_assign_pointer(perf_trace_buf_nmi, buf); perf_trace_buf[i] = buf;
} }
}
if (tp_event->class->reg)
ret = tp_event->class->reg(tp_event, TRACE_REG_PERF_REGISTER);
else
ret = tracepoint_probe_register(tp_event->name,
tp_event->class->perf_probe,
tp_event);
if (ret)
goto fail;
ret = event->perf_event_enable(event);
if (!ret) {
total_ref_count++; total_ref_count++;
return 0; return 0;
}
fail_buf_nmi: fail:
if (!total_ref_count) { if (!total_ref_count) {
free_percpu(perf_trace_buf_nmi); int i;
free_percpu(perf_trace_buf);
perf_trace_buf_nmi = NULL; for (i = 0; i < 4; i++) {
perf_trace_buf = NULL; free_percpu(perf_trace_buf[i]);
perf_trace_buf[i] = NULL;
}
}
if (!--tp_event->perf_refcount) {
free_percpu(tp_event->perf_events);
tp_event->perf_events = NULL;
} }
fail_buf:
event->perf_refcount--;
return ret; return ret;
} }
int perf_trace_enable(int event_id) int perf_trace_init(struct perf_event *p_event)
{ {
struct ftrace_event_call *event; struct ftrace_event_call *tp_event;
int event_id = p_event->attr.config;
int ret = -EINVAL; int ret = -EINVAL;
mutex_lock(&event_mutex); mutex_lock(&event_mutex);
list_for_each_entry(event, &ftrace_events, list) { list_for_each_entry(tp_event, &ftrace_events, list) {
if (event->id == event_id && event->perf_event_enable && if (tp_event->event.type == event_id &&
try_module_get(event->mod)) { tp_event->class && tp_event->class->perf_probe &&
ret = perf_trace_event_enable(event); try_module_get(tp_event->mod)) {
ret = perf_trace_event_init(tp_event, p_event);
break; break;
} }
} }
...@@ -86,90 +107,78 @@ int perf_trace_enable(int event_id) ...@@ -86,90 +107,78 @@ int perf_trace_enable(int event_id)
return ret; return ret;
} }
static void perf_trace_event_disable(struct ftrace_event_call *event) int perf_trace_enable(struct perf_event *p_event)
{ {
char *buf, *nmi_buf; struct ftrace_event_call *tp_event = p_event->tp_event;
struct hlist_head *list;
if (--event->perf_refcount > 0)
return;
event->perf_event_disable(event); list = tp_event->perf_events;
if (WARN_ON_ONCE(!list))
if (!--total_ref_count) { return -EINVAL;
buf = perf_trace_buf;
rcu_assign_pointer(perf_trace_buf, NULL);
nmi_buf = perf_trace_buf_nmi; list = per_cpu_ptr(list, smp_processor_id());
rcu_assign_pointer(perf_trace_buf_nmi, NULL); hlist_add_head_rcu(&p_event->hlist_entry, list);
/* return 0;
* Ensure every events in profiling have finished before }
* releasing the buffers
*/
synchronize_sched();
free_percpu(buf); void perf_trace_disable(struct perf_event *p_event)
free_percpu(nmi_buf); {
} hlist_del_rcu(&p_event->hlist_entry);
} }
void perf_trace_disable(int event_id) void perf_trace_destroy(struct perf_event *p_event)
{ {
struct ftrace_event_call *event; struct ftrace_event_call *tp_event = p_event->tp_event;
int i;
mutex_lock(&event_mutex); if (--tp_event->perf_refcount > 0)
list_for_each_entry(event, &ftrace_events, list) { return;
if (event->id == event_id) {
perf_trace_event_disable(event); if (tp_event->class->reg)
module_put(event->mod); tp_event->class->reg(tp_event, TRACE_REG_PERF_UNREGISTER);
break; else
tracepoint_probe_unregister(tp_event->name,
tp_event->class->perf_probe,
tp_event);
free_percpu(tp_event->perf_events);
tp_event->perf_events = NULL;
if (!--total_ref_count) {
for (i = 0; i < 4; i++) {
free_percpu(perf_trace_buf[i]);
perf_trace_buf[i] = NULL;
} }
} }
mutex_unlock(&event_mutex);
} }
__kprobes void *perf_trace_buf_prepare(int size, unsigned short type, __kprobes void *perf_trace_buf_prepare(int size, unsigned short type,
int *rctxp, unsigned long *irq_flags) struct pt_regs *regs, int *rctxp)
{ {
struct trace_entry *entry; struct trace_entry *entry;
char *trace_buf, *raw_data; unsigned long flags;
int pc, cpu; char *raw_data;
int pc;
BUILD_BUG_ON(PERF_MAX_TRACE_SIZE % sizeof(unsigned long)); BUILD_BUG_ON(PERF_MAX_TRACE_SIZE % sizeof(unsigned long));
pc = preempt_count(); pc = preempt_count();
/* Protect the per cpu buffer, begin the rcu read side */
local_irq_save(*irq_flags);
*rctxp = perf_swevent_get_recursion_context(); *rctxp = perf_swevent_get_recursion_context();
if (*rctxp < 0) if (*rctxp < 0)
goto err_recursion; return NULL;
cpu = smp_processor_id();
if (in_nmi())
trace_buf = rcu_dereference_sched(perf_trace_buf_nmi);
else
trace_buf = rcu_dereference_sched(perf_trace_buf);
if (!trace_buf)
goto err;
raw_data = per_cpu_ptr(trace_buf, cpu); raw_data = per_cpu_ptr(perf_trace_buf[*rctxp], smp_processor_id());
/* zero the dead bytes from align to not leak stack to user */ /* zero the dead bytes from align to not leak stack to user */
memset(&raw_data[size - sizeof(u64)], 0, sizeof(u64)); memset(&raw_data[size - sizeof(u64)], 0, sizeof(u64));
entry = (struct trace_entry *)raw_data; entry = (struct trace_entry *)raw_data;
tracing_generic_entry_update(entry, *irq_flags, pc); local_save_flags(flags);
tracing_generic_entry_update(entry, flags, pc);
entry->type = type; entry->type = type;
return raw_data; return raw_data;
err:
perf_swevent_put_recursion_context(*rctxp);
err_recursion:
local_irq_restore(*irq_flags);
return NULL;
} }
EXPORT_SYMBOL_GPL(perf_trace_buf_prepare); EXPORT_SYMBOL_GPL(perf_trace_buf_prepare);
...@@ -29,11 +29,23 @@ DEFINE_MUTEX(event_mutex); ...@@ -29,11 +29,23 @@ DEFINE_MUTEX(event_mutex);
LIST_HEAD(ftrace_events); LIST_HEAD(ftrace_events);
struct list_head *
trace_get_fields(struct ftrace_event_call *event_call)
{
if (!event_call->class->get_fields)
return &event_call->class->fields;
return event_call->class->get_fields(event_call);
}
int trace_define_field(struct ftrace_event_call *call, const char *type, int trace_define_field(struct ftrace_event_call *call, const char *type,
const char *name, int offset, int size, int is_signed, const char *name, int offset, int size, int is_signed,
int filter_type) int filter_type)
{ {
struct ftrace_event_field *field; struct ftrace_event_field *field;
struct list_head *head;
if (WARN_ON(!call->class))
return 0;
field = kzalloc(sizeof(*field), GFP_KERNEL); field = kzalloc(sizeof(*field), GFP_KERNEL);
if (!field) if (!field)
...@@ -56,7 +68,8 @@ int trace_define_field(struct ftrace_event_call *call, const char *type, ...@@ -56,7 +68,8 @@ int trace_define_field(struct ftrace_event_call *call, const char *type,
field->size = size; field->size = size;
field->is_signed = is_signed; field->is_signed = is_signed;
list_add(&field->link, &call->fields); head = trace_get_fields(call);
list_add(&field->link, head);
return 0; return 0;
...@@ -94,8 +107,10 @@ static int trace_define_common_fields(struct ftrace_event_call *call) ...@@ -94,8 +107,10 @@ static int trace_define_common_fields(struct ftrace_event_call *call)
void trace_destroy_fields(struct ftrace_event_call *call) void trace_destroy_fields(struct ftrace_event_call *call)
{ {
struct ftrace_event_field *field, *next; struct ftrace_event_field *field, *next;
struct list_head *head;
list_for_each_entry_safe(field, next, &call->fields, link) { head = trace_get_fields(call);
list_for_each_entry_safe(field, next, head, link) {
list_del(&field->link); list_del(&field->link);
kfree(field->type); kfree(field->type);
kfree(field->name); kfree(field->name);
...@@ -107,11 +122,9 @@ int trace_event_raw_init(struct ftrace_event_call *call) ...@@ -107,11 +122,9 @@ int trace_event_raw_init(struct ftrace_event_call *call)
{ {
int id; int id;
id = register_ftrace_event(call->event); id = register_ftrace_event(&call->event);
if (!id) if (!id)
return -ENODEV; return -ENODEV;
call->id = id;
INIT_LIST_HEAD(&call->fields);
return 0; return 0;
} }
...@@ -124,23 +137,33 @@ static int ftrace_event_enable_disable(struct ftrace_event_call *call, ...@@ -124,23 +137,33 @@ static int ftrace_event_enable_disable(struct ftrace_event_call *call,
switch (enable) { switch (enable) {
case 0: case 0:
if (call->enabled) { if (call->flags & TRACE_EVENT_FL_ENABLED) {
call->enabled = 0; call->flags &= ~TRACE_EVENT_FL_ENABLED;
tracing_stop_cmdline_record(); tracing_stop_cmdline_record();
call->unregfunc(call); if (call->class->reg)
call->class->reg(call, TRACE_REG_UNREGISTER);
else
tracepoint_probe_unregister(call->name,
call->class->probe,
call);
} }
break; break;
case 1: case 1:
if (!call->enabled) { if (!(call->flags & TRACE_EVENT_FL_ENABLED)) {
tracing_start_cmdline_record(); tracing_start_cmdline_record();
ret = call->regfunc(call); if (call->class->reg)
ret = call->class->reg(call, TRACE_REG_REGISTER);
else
ret = tracepoint_probe_register(call->name,
call->class->probe,
call);
if (ret) { if (ret) {
tracing_stop_cmdline_record(); tracing_stop_cmdline_record();
pr_info("event trace: Could not enable event " pr_info("event trace: Could not enable event "
"%s\n", call->name); "%s\n", call->name);
break; break;
} }
call->enabled = 1; call->flags |= TRACE_EVENT_FL_ENABLED;
} }
break; break;
} }
...@@ -171,15 +194,16 @@ static int __ftrace_set_clr_event(const char *match, const char *sub, ...@@ -171,15 +194,16 @@ static int __ftrace_set_clr_event(const char *match, const char *sub,
mutex_lock(&event_mutex); mutex_lock(&event_mutex);
list_for_each_entry(call, &ftrace_events, list) { list_for_each_entry(call, &ftrace_events, list) {
if (!call->name || !call->regfunc) if (!call->name || !call->class ||
(!call->class->probe && !call->class->reg))
continue; continue;
if (match && if (match &&
strcmp(match, call->name) != 0 && strcmp(match, call->name) != 0 &&
strcmp(match, call->system) != 0) strcmp(match, call->class->system) != 0)
continue; continue;
if (sub && strcmp(sub, call->system) != 0) if (sub && strcmp(sub, call->class->system) != 0)
continue; continue;
if (event && strcmp(event, call->name) != 0) if (event && strcmp(event, call->name) != 0)
...@@ -297,7 +321,7 @@ t_next(struct seq_file *m, void *v, loff_t *pos) ...@@ -297,7 +321,7 @@ t_next(struct seq_file *m, void *v, loff_t *pos)
* The ftrace subsystem is for showing formats only. * The ftrace subsystem is for showing formats only.
* They can not be enabled or disabled via the event files. * They can not be enabled or disabled via the event files.
*/ */
if (call->regfunc) if (call->class && (call->class->probe || call->class->reg))
return call; return call;
} }
...@@ -328,7 +352,7 @@ s_next(struct seq_file *m, void *v, loff_t *pos) ...@@ -328,7 +352,7 @@ s_next(struct seq_file *m, void *v, loff_t *pos)
(*pos)++; (*pos)++;
list_for_each_entry_continue(call, &ftrace_events, list) { list_for_each_entry_continue(call, &ftrace_events, list) {
if (call->enabled) if (call->flags & TRACE_EVENT_FL_ENABLED)
return call; return call;
} }
...@@ -355,8 +379,8 @@ static int t_show(struct seq_file *m, void *v) ...@@ -355,8 +379,8 @@ static int t_show(struct seq_file *m, void *v)
{ {
struct ftrace_event_call *call = v; struct ftrace_event_call *call = v;
if (strcmp(call->system, TRACE_SYSTEM) != 0) if (strcmp(call->class->system, TRACE_SYSTEM) != 0)
seq_printf(m, "%s:", call->system); seq_printf(m, "%s:", call->class->system);
seq_printf(m, "%s\n", call->name); seq_printf(m, "%s\n", call->name);
return 0; return 0;
...@@ -387,7 +411,7 @@ event_enable_read(struct file *filp, char __user *ubuf, size_t cnt, ...@@ -387,7 +411,7 @@ event_enable_read(struct file *filp, char __user *ubuf, size_t cnt,
struct ftrace_event_call *call = filp->private_data; struct ftrace_event_call *call = filp->private_data;
char *buf; char *buf;
if (call->enabled) if (call->flags & TRACE_EVENT_FL_ENABLED)
buf = "1\n"; buf = "1\n";
else else
buf = "0\n"; buf = "0\n";
...@@ -450,10 +474,11 @@ system_enable_read(struct file *filp, char __user *ubuf, size_t cnt, ...@@ -450,10 +474,11 @@ system_enable_read(struct file *filp, char __user *ubuf, size_t cnt,
mutex_lock(&event_mutex); mutex_lock(&event_mutex);
list_for_each_entry(call, &ftrace_events, list) { list_for_each_entry(call, &ftrace_events, list) {
if (!call->name || !call->regfunc) if (!call->name || !call->class ||
(!call->class->probe && !call->class->reg))
continue; continue;
if (system && strcmp(call->system, system) != 0) if (system && strcmp(call->class->system, system) != 0)
continue; continue;
/* /*
...@@ -461,7 +486,7 @@ system_enable_read(struct file *filp, char __user *ubuf, size_t cnt, ...@@ -461,7 +486,7 @@ system_enable_read(struct file *filp, char __user *ubuf, size_t cnt,
* or if all events or cleared, or if we have * or if all events or cleared, or if we have
* a mixture. * a mixture.
*/ */
set |= (1 << !!call->enabled); set |= (1 << !!(call->flags & TRACE_EVENT_FL_ENABLED));
/* /*
* If we have a mixture, no need to look further. * If we have a mixture, no need to look further.
...@@ -525,6 +550,7 @@ event_format_read(struct file *filp, char __user *ubuf, size_t cnt, ...@@ -525,6 +550,7 @@ event_format_read(struct file *filp, char __user *ubuf, size_t cnt,
{ {
struct ftrace_event_call *call = filp->private_data; struct ftrace_event_call *call = filp->private_data;
struct ftrace_event_field *field; struct ftrace_event_field *field;
struct list_head *head;
struct trace_seq *s; struct trace_seq *s;
int common_field_count = 5; int common_field_count = 5;
char *buf; char *buf;
...@@ -540,10 +566,11 @@ event_format_read(struct file *filp, char __user *ubuf, size_t cnt, ...@@ -540,10 +566,11 @@ event_format_read(struct file *filp, char __user *ubuf, size_t cnt,
trace_seq_init(s); trace_seq_init(s);
trace_seq_printf(s, "name: %s\n", call->name); trace_seq_printf(s, "name: %s\n", call->name);
trace_seq_printf(s, "ID: %d\n", call->id); trace_seq_printf(s, "ID: %d\n", call->event.type);
trace_seq_printf(s, "format:\n"); trace_seq_printf(s, "format:\n");
list_for_each_entry_reverse(field, &call->fields, link) { head = trace_get_fields(call);
list_for_each_entry_reverse(field, head, link) {
/* /*
* Smartly shows the array type(except dynamic array). * Smartly shows the array type(except dynamic array).
* Normal: * Normal:
...@@ -613,7 +640,7 @@ event_id_read(struct file *filp, char __user *ubuf, size_t cnt, loff_t *ppos) ...@@ -613,7 +640,7 @@ event_id_read(struct file *filp, char __user *ubuf, size_t cnt, loff_t *ppos)
return -ENOMEM; return -ENOMEM;
trace_seq_init(s); trace_seq_init(s);
trace_seq_printf(s, "%d\n", call->id); trace_seq_printf(s, "%d\n", call->event.type);
r = simple_read_from_buffer(ubuf, cnt, ppos, r = simple_read_from_buffer(ubuf, cnt, ppos,
s->buffer, s->len); s->buffer, s->len);
...@@ -919,14 +946,15 @@ event_create_dir(struct ftrace_event_call *call, struct dentry *d_events, ...@@ -919,14 +946,15 @@ event_create_dir(struct ftrace_event_call *call, struct dentry *d_events,
const struct file_operations *filter, const struct file_operations *filter,
const struct file_operations *format) const struct file_operations *format)
{ {
struct list_head *head;
int ret; int ret;
/* /*
* If the trace point header did not define TRACE_SYSTEM * If the trace point header did not define TRACE_SYSTEM
* then the system would be called "TRACE_SYSTEM". * then the system would be called "TRACE_SYSTEM".
*/ */
if (strcmp(call->system, TRACE_SYSTEM) != 0) if (strcmp(call->class->system, TRACE_SYSTEM) != 0)
d_events = event_subsystem_dir(call->system, d_events); d_events = event_subsystem_dir(call->class->system, d_events);
call->dir = debugfs_create_dir(call->name, d_events); call->dir = debugfs_create_dir(call->name, d_events);
if (!call->dir) { if (!call->dir) {
...@@ -935,23 +963,32 @@ event_create_dir(struct ftrace_event_call *call, struct dentry *d_events, ...@@ -935,23 +963,32 @@ event_create_dir(struct ftrace_event_call *call, struct dentry *d_events,
return -1; return -1;
} }
if (call->regfunc) if (call->class->probe || call->class->reg)
trace_create_file("enable", 0644, call->dir, call, trace_create_file("enable", 0644, call->dir, call,
enable); enable);
if (call->id && call->perf_event_enable) #ifdef CONFIG_PERF_EVENTS
if (call->event.type && (call->class->perf_probe || call->class->reg))
trace_create_file("id", 0444, call->dir, call, trace_create_file("id", 0444, call->dir, call,
id); id);
#endif
if (call->define_fields) { if (call->class->define_fields) {
/*
* Other events may have the same class. Only update
* the fields if they are not already defined.
*/
head = trace_get_fields(call);
if (list_empty(head)) {
ret = trace_define_common_fields(call); ret = trace_define_common_fields(call);
if (!ret) if (!ret)
ret = call->define_fields(call); ret = call->class->define_fields(call);
if (ret < 0) { if (ret < 0) {
pr_warning("Could not initialize trace point" pr_warning("Could not initialize trace point"
" events/%s\n", call->name); " events/%s\n", call->name);
return ret; return ret;
} }
}
trace_create_file("filter", 0644, call->dir, call, trace_create_file("filter", 0644, call->dir, call,
filter); filter);
} }
...@@ -970,8 +1007,8 @@ static int __trace_add_event_call(struct ftrace_event_call *call) ...@@ -970,8 +1007,8 @@ static int __trace_add_event_call(struct ftrace_event_call *call)
if (!call->name) if (!call->name)
return -EINVAL; return -EINVAL;
if (call->raw_init) { if (call->class->raw_init) {
ret = call->raw_init(call); ret = call->class->raw_init(call);
if (ret < 0) { if (ret < 0) {
if (ret != -ENOSYS) if (ret != -ENOSYS)
pr_warning("Could not initialize trace " pr_warning("Could not initialize trace "
...@@ -1035,13 +1072,13 @@ static void remove_subsystem_dir(const char *name) ...@@ -1035,13 +1072,13 @@ static void remove_subsystem_dir(const char *name)
static void __trace_remove_event_call(struct ftrace_event_call *call) static void __trace_remove_event_call(struct ftrace_event_call *call)
{ {
ftrace_event_enable_disable(call, 0); ftrace_event_enable_disable(call, 0);
if (call->event) if (call->event.funcs)
__unregister_ftrace_event(call->event); __unregister_ftrace_event(&call->event);
debugfs_remove_recursive(call->dir); debugfs_remove_recursive(call->dir);
list_del(&call->list); list_del(&call->list);
trace_destroy_fields(call); trace_destroy_fields(call);
destroy_preds(call); destroy_preds(call);
remove_subsystem_dir(call->system); remove_subsystem_dir(call->class->system);
} }
/* Remove an event_call */ /* Remove an event_call */
...@@ -1132,8 +1169,8 @@ static void trace_module_add_events(struct module *mod) ...@@ -1132,8 +1169,8 @@ static void trace_module_add_events(struct module *mod)
/* The linker may leave blanks */ /* The linker may leave blanks */
if (!call->name) if (!call->name)
continue; continue;
if (call->raw_init) { if (call->class->raw_init) {
ret = call->raw_init(call); ret = call->class->raw_init(call);
if (ret < 0) { if (ret < 0) {
if (ret != -ENOSYS) if (ret != -ENOSYS)
pr_warning("Could not initialize trace " pr_warning("Could not initialize trace "
...@@ -1286,8 +1323,8 @@ static __init int event_trace_init(void) ...@@ -1286,8 +1323,8 @@ static __init int event_trace_init(void)
/* The linker may leave blanks */ /* The linker may leave blanks */
if (!call->name) if (!call->name)
continue; continue;
if (call->raw_init) { if (call->class->raw_init) {
ret = call->raw_init(call); ret = call->class->raw_init(call);
if (ret < 0) { if (ret < 0) {
if (ret != -ENOSYS) if (ret != -ENOSYS)
pr_warning("Could not initialize trace " pr_warning("Could not initialize trace "
...@@ -1388,8 +1425,8 @@ static __init void event_trace_self_tests(void) ...@@ -1388,8 +1425,8 @@ static __init void event_trace_self_tests(void)
list_for_each_entry(call, &ftrace_events, list) { list_for_each_entry(call, &ftrace_events, list) {
/* Only test those that have a regfunc */ /* Only test those that have a probe */
if (!call->regfunc) if (!call->class || !call->class->probe)
continue; continue;
/* /*
...@@ -1399,8 +1436,8 @@ static __init void event_trace_self_tests(void) ...@@ -1399,8 +1436,8 @@ static __init void event_trace_self_tests(void)
* syscalls as we test. * syscalls as we test.
*/ */
#ifndef CONFIG_EVENT_TRACE_TEST_SYSCALLS #ifndef CONFIG_EVENT_TRACE_TEST_SYSCALLS
if (call->system && if (call->class->system &&
strcmp(call->system, "syscalls") == 0) strcmp(call->class->system, "syscalls") == 0)
continue; continue;
#endif #endif
...@@ -1410,7 +1447,7 @@ static __init void event_trace_self_tests(void) ...@@ -1410,7 +1447,7 @@ static __init void event_trace_self_tests(void)
* If an event is already enabled, someone is using * If an event is already enabled, someone is using
* it and the self test should not be on. * it and the self test should not be on.
*/ */
if (call->enabled) { if (call->flags & TRACE_EVENT_FL_ENABLED) {
pr_warning("Enabled event during self test!\n"); pr_warning("Enabled event during self test!\n");
WARN_ON_ONCE(1); WARN_ON_ONCE(1);
continue; continue;
......
...@@ -500,8 +500,10 @@ static struct ftrace_event_field * ...@@ -500,8 +500,10 @@ static struct ftrace_event_field *
find_event_field(struct ftrace_event_call *call, char *name) find_event_field(struct ftrace_event_call *call, char *name)
{ {
struct ftrace_event_field *field; struct ftrace_event_field *field;
struct list_head *head;
list_for_each_entry(field, &call->fields, link) { head = trace_get_fields(call);
list_for_each_entry(field, head, link) {
if (!strcmp(field->name, name)) if (!strcmp(field->name, name))
return field; return field;
} }
...@@ -545,7 +547,7 @@ static void filter_disable_preds(struct ftrace_event_call *call) ...@@ -545,7 +547,7 @@ static void filter_disable_preds(struct ftrace_event_call *call)
struct event_filter *filter = call->filter; struct event_filter *filter = call->filter;
int i; int i;
call->filter_active = 0; call->flags &= ~TRACE_EVENT_FL_FILTERED;
filter->n_preds = 0; filter->n_preds = 0;
for (i = 0; i < MAX_FILTER_PRED; i++) for (i = 0; i < MAX_FILTER_PRED; i++)
...@@ -572,7 +574,7 @@ void destroy_preds(struct ftrace_event_call *call) ...@@ -572,7 +574,7 @@ void destroy_preds(struct ftrace_event_call *call)
{ {
__free_preds(call->filter); __free_preds(call->filter);
call->filter = NULL; call->filter = NULL;
call->filter_active = 0; call->flags &= ~TRACE_EVENT_FL_FILTERED;
} }
static struct event_filter *__alloc_preds(void) static struct event_filter *__alloc_preds(void)
...@@ -611,7 +613,7 @@ static int init_preds(struct ftrace_event_call *call) ...@@ -611,7 +613,7 @@ static int init_preds(struct ftrace_event_call *call)
if (call->filter) if (call->filter)
return 0; return 0;
call->filter_active = 0; call->flags &= ~TRACE_EVENT_FL_FILTERED;
call->filter = __alloc_preds(); call->filter = __alloc_preds();
if (IS_ERR(call->filter)) if (IS_ERR(call->filter))
return PTR_ERR(call->filter); return PTR_ERR(call->filter);
...@@ -625,10 +627,10 @@ static int init_subsystem_preds(struct event_subsystem *system) ...@@ -625,10 +627,10 @@ static int init_subsystem_preds(struct event_subsystem *system)
int err; int err;
list_for_each_entry(call, &ftrace_events, list) { list_for_each_entry(call, &ftrace_events, list) {
if (!call->define_fields) if (!call->class || !call->class->define_fields)
continue; continue;
if (strcmp(call->system, system->name) != 0) if (strcmp(call->class->system, system->name) != 0)
continue; continue;
err = init_preds(call); err = init_preds(call);
...@@ -644,10 +646,10 @@ static void filter_free_subsystem_preds(struct event_subsystem *system) ...@@ -644,10 +646,10 @@ static void filter_free_subsystem_preds(struct event_subsystem *system)
struct ftrace_event_call *call; struct ftrace_event_call *call;
list_for_each_entry(call, &ftrace_events, list) { list_for_each_entry(call, &ftrace_events, list) {
if (!call->define_fields) if (!call->class || !call->class->define_fields)
continue; continue;
if (strcmp(call->system, system->name) != 0) if (strcmp(call->class->system, system->name) != 0)
continue; continue;
filter_disable_preds(call); filter_disable_preds(call);
...@@ -1249,10 +1251,10 @@ static int replace_system_preds(struct event_subsystem *system, ...@@ -1249,10 +1251,10 @@ static int replace_system_preds(struct event_subsystem *system,
list_for_each_entry(call, &ftrace_events, list) { list_for_each_entry(call, &ftrace_events, list) {
struct event_filter *filter = call->filter; struct event_filter *filter = call->filter;
if (!call->define_fields) if (!call->class || !call->class->define_fields)
continue; continue;
if (strcmp(call->system, system->name) != 0) if (strcmp(call->class->system, system->name) != 0)
continue; continue;
/* try to see if the filter can be applied */ /* try to see if the filter can be applied */
...@@ -1266,7 +1268,7 @@ static int replace_system_preds(struct event_subsystem *system, ...@@ -1266,7 +1268,7 @@ static int replace_system_preds(struct event_subsystem *system,
if (err) if (err)
filter_disable_preds(call); filter_disable_preds(call);
else { else {
call->filter_active = 1; call->flags |= TRACE_EVENT_FL_FILTERED;
replace_filter_string(filter, filter_string); replace_filter_string(filter, filter_string);
} }
fail = false; fail = false;
...@@ -1315,7 +1317,7 @@ int apply_event_filter(struct ftrace_event_call *call, char *filter_string) ...@@ -1315,7 +1317,7 @@ int apply_event_filter(struct ftrace_event_call *call, char *filter_string)
if (err) if (err)
append_filter_err(ps, call->filter); append_filter_err(ps, call->filter);
else else
call->filter_active = 1; call->flags |= TRACE_EVENT_FL_FILTERED;
out: out:
filter_opstack_clear(ps); filter_opstack_clear(ps);
postfix_clear(ps); postfix_clear(ps);
...@@ -1393,7 +1395,7 @@ int ftrace_profile_set_filter(struct perf_event *event, int event_id, ...@@ -1393,7 +1395,7 @@ int ftrace_profile_set_filter(struct perf_event *event, int event_id,
mutex_lock(&event_mutex); mutex_lock(&event_mutex);
list_for_each_entry(call, &ftrace_events, list) { list_for_each_entry(call, &ftrace_events, list) {
if (call->id == event_id) if (call->event.type == event_id)
break; break;
} }
......
...@@ -127,7 +127,7 @@ ftrace_define_fields_##name(struct ftrace_event_call *event_call) \ ...@@ -127,7 +127,7 @@ ftrace_define_fields_##name(struct ftrace_event_call *event_call) \
static int ftrace_raw_init_event(struct ftrace_event_call *call) static int ftrace_raw_init_event(struct ftrace_event_call *call)
{ {
INIT_LIST_HEAD(&call->fields); INIT_LIST_HEAD(&call->class->fields);
return 0; return 0;
} }
...@@ -153,17 +153,21 @@ static int ftrace_raw_init_event(struct ftrace_event_call *call) ...@@ -153,17 +153,21 @@ static int ftrace_raw_init_event(struct ftrace_event_call *call)
#define F_printk(fmt, args...) #fmt ", " __stringify(args) #define F_printk(fmt, args...) #fmt ", " __stringify(args)
#undef FTRACE_ENTRY #undef FTRACE_ENTRY
#define FTRACE_ENTRY(call, struct_name, type, tstruct, print) \ #define FTRACE_ENTRY(call, struct_name, etype, tstruct, print) \
\
struct ftrace_event_class event_class_ftrace_##call = { \
.system = __stringify(TRACE_SYSTEM), \
.define_fields = ftrace_define_fields_##call, \
.raw_init = ftrace_raw_init_event, \
}; \
\ \
struct ftrace_event_call __used \ struct ftrace_event_call __used \
__attribute__((__aligned__(4))) \ __attribute__((__aligned__(4))) \
__attribute__((section("_ftrace_events"))) event_##call = { \ __attribute__((section("_ftrace_events"))) event_##call = { \
.name = #call, \ .name = #call, \
.id = type, \ .event.type = etype, \
.system = __stringify(TRACE_SYSTEM), \ .class = &event_class_ftrace_##call, \
.raw_init = ftrace_raw_init_event, \
.print_fmt = print, \ .print_fmt = print, \
.define_fields = ftrace_define_fields_##call, \
}; \ }; \
#include "trace_entries.h" #include "trace_entries.h"
...@@ -1025,7 +1025,7 @@ print_graph_comment(struct trace_seq *s, struct trace_entry *ent, ...@@ -1025,7 +1025,7 @@ print_graph_comment(struct trace_seq *s, struct trace_entry *ent,
if (!event) if (!event)
return TRACE_TYPE_UNHANDLED; return TRACE_TYPE_UNHANDLED;
ret = event->trace(iter, sym_flags); ret = event->funcs->trace(iter, sym_flags, event);
if (ret != TRACE_TYPE_HANDLED) if (ret != TRACE_TYPE_HANDLED)
return ret; return ret;
} }
...@@ -1112,7 +1112,8 @@ print_graph_function(struct trace_iterator *iter) ...@@ -1112,7 +1112,8 @@ print_graph_function(struct trace_iterator *iter)
} }
static enum print_line_t static enum print_line_t
print_graph_function_event(struct trace_iterator *iter, int flags) print_graph_function_event(struct trace_iterator *iter, int flags,
struct trace_event *event)
{ {
return print_graph_function(iter); return print_graph_function(iter);
} }
...@@ -1225,14 +1226,18 @@ void graph_trace_close(struct trace_iterator *iter) ...@@ -1225,14 +1226,18 @@ void graph_trace_close(struct trace_iterator *iter)
} }
} }
static struct trace_event_functions graph_functions = {
.trace = print_graph_function_event,
};
static struct trace_event graph_trace_entry_event = { static struct trace_event graph_trace_entry_event = {
.type = TRACE_GRAPH_ENT, .type = TRACE_GRAPH_ENT,
.trace = print_graph_function_event, .funcs = &graph_functions,
}; };
static struct trace_event graph_trace_ret_event = { static struct trace_event graph_trace_ret_event = {
.type = TRACE_GRAPH_RET, .type = TRACE_GRAPH_RET,
.trace = print_graph_function_event, .funcs = &graph_functions
}; };
static struct tracer graph_trace __read_mostly = { static struct tracer graph_trace __read_mostly = {
......
...@@ -324,8 +324,8 @@ struct trace_probe { ...@@ -324,8 +324,8 @@ struct trace_probe {
unsigned long nhit; unsigned long nhit;
unsigned int flags; /* For TP_FLAG_* */ unsigned int flags; /* For TP_FLAG_* */
const char *symbol; /* symbol name */ const char *symbol; /* symbol name */
struct ftrace_event_class class;
struct ftrace_event_call call; struct ftrace_event_call call;
struct trace_event event;
ssize_t size; /* trace entry size */ ssize_t size; /* trace entry size */
unsigned int nr_args; unsigned int nr_args;
struct probe_arg args[]; struct probe_arg args[];
...@@ -404,6 +404,7 @@ static struct trace_probe *alloc_trace_probe(const char *group, ...@@ -404,6 +404,7 @@ static struct trace_probe *alloc_trace_probe(const char *group,
goto error; goto error;
} }
tp->call.class = &tp->class;
tp->call.name = kstrdup(event, GFP_KERNEL); tp->call.name = kstrdup(event, GFP_KERNEL);
if (!tp->call.name) if (!tp->call.name)
goto error; goto error;
...@@ -413,8 +414,8 @@ static struct trace_probe *alloc_trace_probe(const char *group, ...@@ -413,8 +414,8 @@ static struct trace_probe *alloc_trace_probe(const char *group,
goto error; goto error;
} }
tp->call.system = kstrdup(group, GFP_KERNEL); tp->class.system = kstrdup(group, GFP_KERNEL);
if (!tp->call.system) if (!tp->class.system)
goto error; goto error;
INIT_LIST_HEAD(&tp->list); INIT_LIST_HEAD(&tp->list);
...@@ -443,7 +444,7 @@ static void free_trace_probe(struct trace_probe *tp) ...@@ -443,7 +444,7 @@ static void free_trace_probe(struct trace_probe *tp)
for (i = 0; i < tp->nr_args; i++) for (i = 0; i < tp->nr_args; i++)
free_probe_arg(&tp->args[i]); free_probe_arg(&tp->args[i]);
kfree(tp->call.system); kfree(tp->call.class->system);
kfree(tp->call.name); kfree(tp->call.name);
kfree(tp->symbol); kfree(tp->symbol);
kfree(tp); kfree(tp);
...@@ -456,7 +457,7 @@ static struct trace_probe *find_probe_event(const char *event, ...@@ -456,7 +457,7 @@ static struct trace_probe *find_probe_event(const char *event,
list_for_each_entry(tp, &probe_list, list) list_for_each_entry(tp, &probe_list, list)
if (strcmp(tp->call.name, event) == 0 && if (strcmp(tp->call.name, event) == 0 &&
strcmp(tp->call.system, group) == 0) strcmp(tp->call.class->system, group) == 0)
return tp; return tp;
return NULL; return NULL;
} }
...@@ -481,7 +482,7 @@ static int register_trace_probe(struct trace_probe *tp) ...@@ -481,7 +482,7 @@ static int register_trace_probe(struct trace_probe *tp)
mutex_lock(&probe_lock); mutex_lock(&probe_lock);
/* register as an event */ /* register as an event */
old_tp = find_probe_event(tp->call.name, tp->call.system); old_tp = find_probe_event(tp->call.name, tp->call.class->system);
if (old_tp) { if (old_tp) {
/* delete old event */ /* delete old event */
unregister_trace_probe(old_tp); unregister_trace_probe(old_tp);
...@@ -904,7 +905,7 @@ static int probes_seq_show(struct seq_file *m, void *v) ...@@ -904,7 +905,7 @@ static int probes_seq_show(struct seq_file *m, void *v)
int i; int i;
seq_printf(m, "%c", probe_is_return(tp) ? 'r' : 'p'); seq_printf(m, "%c", probe_is_return(tp) ? 'r' : 'p');
seq_printf(m, ":%s/%s", tp->call.system, tp->call.name); seq_printf(m, ":%s/%s", tp->call.class->system, tp->call.name);
if (!tp->symbol) if (!tp->symbol)
seq_printf(m, " 0x%p", tp->rp.kp.addr); seq_printf(m, " 0x%p", tp->rp.kp.addr);
...@@ -1061,8 +1062,8 @@ static __kprobes void kprobe_trace_func(struct kprobe *kp, struct pt_regs *regs) ...@@ -1061,8 +1062,8 @@ static __kprobes void kprobe_trace_func(struct kprobe *kp, struct pt_regs *regs)
size = sizeof(*entry) + tp->size; size = sizeof(*entry) + tp->size;
event = trace_current_buffer_lock_reserve(&buffer, call->id, size, event = trace_current_buffer_lock_reserve(&buffer, call->event.type,
irq_flags, pc); size, irq_flags, pc);
if (!event) if (!event)
return; return;
...@@ -1094,8 +1095,8 @@ static __kprobes void kretprobe_trace_func(struct kretprobe_instance *ri, ...@@ -1094,8 +1095,8 @@ static __kprobes void kretprobe_trace_func(struct kretprobe_instance *ri,
size = sizeof(*entry) + tp->size; size = sizeof(*entry) + tp->size;
event = trace_current_buffer_lock_reserve(&buffer, call->id, size, event = trace_current_buffer_lock_reserve(&buffer, call->event.type,
irq_flags, pc); size, irq_flags, pc);
if (!event) if (!event)
return; return;
...@@ -1112,18 +1113,17 @@ static __kprobes void kretprobe_trace_func(struct kretprobe_instance *ri, ...@@ -1112,18 +1113,17 @@ static __kprobes void kretprobe_trace_func(struct kretprobe_instance *ri,
/* Event entry printers */ /* Event entry printers */
enum print_line_t enum print_line_t
print_kprobe_event(struct trace_iterator *iter, int flags) print_kprobe_event(struct trace_iterator *iter, int flags,
struct trace_event *event)
{ {
struct kprobe_trace_entry_head *field; struct kprobe_trace_entry_head *field;
struct trace_seq *s = &iter->seq; struct trace_seq *s = &iter->seq;
struct trace_event *event;
struct trace_probe *tp; struct trace_probe *tp;
u8 *data; u8 *data;
int i; int i;
field = (struct kprobe_trace_entry_head *)iter->ent; field = (struct kprobe_trace_entry_head *)iter->ent;
event = ftrace_find_event(field->ent.type); tp = container_of(event, struct trace_probe, call.event);
tp = container_of(event, struct trace_probe, event);
if (!trace_seq_printf(s, "%s: (", tp->call.name)) if (!trace_seq_printf(s, "%s: (", tp->call.name))
goto partial; goto partial;
...@@ -1149,18 +1149,17 @@ print_kprobe_event(struct trace_iterator *iter, int flags) ...@@ -1149,18 +1149,17 @@ print_kprobe_event(struct trace_iterator *iter, int flags)
} }
enum print_line_t enum print_line_t
print_kretprobe_event(struct trace_iterator *iter, int flags) print_kretprobe_event(struct trace_iterator *iter, int flags,
struct trace_event *event)
{ {
struct kretprobe_trace_entry_head *field; struct kretprobe_trace_entry_head *field;
struct trace_seq *s = &iter->seq; struct trace_seq *s = &iter->seq;
struct trace_event *event;
struct trace_probe *tp; struct trace_probe *tp;
u8 *data; u8 *data;
int i; int i;
field = (struct kretprobe_trace_entry_head *)iter->ent; field = (struct kretprobe_trace_entry_head *)iter->ent;
event = ftrace_find_event(field->ent.type); tp = container_of(event, struct trace_probe, call.event);
tp = container_of(event, struct trace_probe, event);
if (!trace_seq_printf(s, "%s: (", tp->call.name)) if (!trace_seq_printf(s, "%s: (", tp->call.name))
goto partial; goto partial;
...@@ -1217,8 +1216,6 @@ static void probe_event_disable(struct ftrace_event_call *call) ...@@ -1217,8 +1216,6 @@ static void probe_event_disable(struct ftrace_event_call *call)
static int probe_event_raw_init(struct ftrace_event_call *event_call) static int probe_event_raw_init(struct ftrace_event_call *event_call)
{ {
INIT_LIST_HEAD(&event_call->fields);
return 0; return 0;
} }
...@@ -1341,9 +1338,9 @@ static __kprobes void kprobe_perf_func(struct kprobe *kp, ...@@ -1341,9 +1338,9 @@ static __kprobes void kprobe_perf_func(struct kprobe *kp,
struct trace_probe *tp = container_of(kp, struct trace_probe, rp.kp); struct trace_probe *tp = container_of(kp, struct trace_probe, rp.kp);
struct ftrace_event_call *call = &tp->call; struct ftrace_event_call *call = &tp->call;
struct kprobe_trace_entry_head *entry; struct kprobe_trace_entry_head *entry;
struct hlist_head *head;
u8 *data; u8 *data;
int size, __size, i; int size, __size, i;
unsigned long irq_flags;
int rctx; int rctx;
__size = sizeof(*entry) + tp->size; __size = sizeof(*entry) + tp->size;
...@@ -1353,7 +1350,7 @@ static __kprobes void kprobe_perf_func(struct kprobe *kp, ...@@ -1353,7 +1350,7 @@ static __kprobes void kprobe_perf_func(struct kprobe *kp,
"profile buffer not large enough")) "profile buffer not large enough"))
return; return;
entry = perf_trace_buf_prepare(size, call->id, &rctx, &irq_flags); entry = perf_trace_buf_prepare(size, call->event.type, regs, &rctx);
if (!entry) if (!entry)
return; return;
...@@ -1362,7 +1359,8 @@ static __kprobes void kprobe_perf_func(struct kprobe *kp, ...@@ -1362,7 +1359,8 @@ static __kprobes void kprobe_perf_func(struct kprobe *kp,
for (i = 0; i < tp->nr_args; i++) for (i = 0; i < tp->nr_args; i++)
call_fetch(&tp->args[i].fetch, regs, data + tp->args[i].offset); call_fetch(&tp->args[i].fetch, regs, data + tp->args[i].offset);
perf_trace_buf_submit(entry, size, rctx, entry->ip, 1, irq_flags, regs); head = per_cpu_ptr(call->perf_events, smp_processor_id());
perf_trace_buf_submit(entry, size, rctx, entry->ip, 1, regs, head);
} }
/* Kretprobe profile handler */ /* Kretprobe profile handler */
...@@ -1372,9 +1370,9 @@ static __kprobes void kretprobe_perf_func(struct kretprobe_instance *ri, ...@@ -1372,9 +1370,9 @@ static __kprobes void kretprobe_perf_func(struct kretprobe_instance *ri,
struct trace_probe *tp = container_of(ri->rp, struct trace_probe, rp); struct trace_probe *tp = container_of(ri->rp, struct trace_probe, rp);
struct ftrace_event_call *call = &tp->call; struct ftrace_event_call *call = &tp->call;
struct kretprobe_trace_entry_head *entry; struct kretprobe_trace_entry_head *entry;
struct hlist_head *head;
u8 *data; u8 *data;
int size, __size, i; int size, __size, i;
unsigned long irq_flags;
int rctx; int rctx;
__size = sizeof(*entry) + tp->size; __size = sizeof(*entry) + tp->size;
...@@ -1384,7 +1382,7 @@ static __kprobes void kretprobe_perf_func(struct kretprobe_instance *ri, ...@@ -1384,7 +1382,7 @@ static __kprobes void kretprobe_perf_func(struct kretprobe_instance *ri,
"profile buffer not large enough")) "profile buffer not large enough"))
return; return;
entry = perf_trace_buf_prepare(size, call->id, &rctx, &irq_flags); entry = perf_trace_buf_prepare(size, call->event.type, regs, &rctx);
if (!entry) if (!entry)
return; return;
...@@ -1394,8 +1392,8 @@ static __kprobes void kretprobe_perf_func(struct kretprobe_instance *ri, ...@@ -1394,8 +1392,8 @@ static __kprobes void kretprobe_perf_func(struct kretprobe_instance *ri,
for (i = 0; i < tp->nr_args; i++) for (i = 0; i < tp->nr_args; i++)
call_fetch(&tp->args[i].fetch, regs, data + tp->args[i].offset); call_fetch(&tp->args[i].fetch, regs, data + tp->args[i].offset);
perf_trace_buf_submit(entry, size, rctx, entry->ret_ip, 1, head = per_cpu_ptr(call->perf_events, smp_processor_id());
irq_flags, regs); perf_trace_buf_submit(entry, size, rctx, entry->ret_ip, 1, regs, head);
} }
static int probe_perf_enable(struct ftrace_event_call *call) static int probe_perf_enable(struct ftrace_event_call *call)
...@@ -1425,6 +1423,26 @@ static void probe_perf_disable(struct ftrace_event_call *call) ...@@ -1425,6 +1423,26 @@ static void probe_perf_disable(struct ftrace_event_call *call)
} }
#endif /* CONFIG_PERF_EVENTS */ #endif /* CONFIG_PERF_EVENTS */
static __kprobes
int kprobe_register(struct ftrace_event_call *event, enum trace_reg type)
{
switch (type) {
case TRACE_REG_REGISTER:
return probe_event_enable(event);
case TRACE_REG_UNREGISTER:
probe_event_disable(event);
return 0;
#ifdef CONFIG_PERF_EVENTS
case TRACE_REG_PERF_REGISTER:
return probe_perf_enable(event);
case TRACE_REG_PERF_UNREGISTER:
probe_perf_disable(event);
return 0;
#endif
}
return 0;
}
static __kprobes static __kprobes
int kprobe_dispatcher(struct kprobe *kp, struct pt_regs *regs) int kprobe_dispatcher(struct kprobe *kp, struct pt_regs *regs)
...@@ -1454,6 +1472,14 @@ int kretprobe_dispatcher(struct kretprobe_instance *ri, struct pt_regs *regs) ...@@ -1454,6 +1472,14 @@ int kretprobe_dispatcher(struct kretprobe_instance *ri, struct pt_regs *regs)
return 0; /* We don't tweek kernel, so just return 0 */ return 0; /* We don't tweek kernel, so just return 0 */
} }
static struct trace_event_functions kretprobe_funcs = {
.trace = print_kretprobe_event
};
static struct trace_event_functions kprobe_funcs = {
.trace = print_kprobe_event
};
static int register_probe_event(struct trace_probe *tp) static int register_probe_event(struct trace_probe *tp)
{ {
struct ftrace_event_call *call = &tp->call; struct ftrace_event_call *call = &tp->call;
...@@ -1461,36 +1487,31 @@ static int register_probe_event(struct trace_probe *tp) ...@@ -1461,36 +1487,31 @@ static int register_probe_event(struct trace_probe *tp)
/* Initialize ftrace_event_call */ /* Initialize ftrace_event_call */
if (probe_is_return(tp)) { if (probe_is_return(tp)) {
tp->event.trace = print_kretprobe_event; INIT_LIST_HEAD(&call->class->fields);
call->raw_init = probe_event_raw_init; call->event.funcs = &kretprobe_funcs;
call->define_fields = kretprobe_event_define_fields; call->class->raw_init = probe_event_raw_init;
call->class->define_fields = kretprobe_event_define_fields;
} else { } else {
tp->event.trace = print_kprobe_event; INIT_LIST_HEAD(&call->class->fields);
call->raw_init = probe_event_raw_init; call->event.funcs = &kprobe_funcs;
call->define_fields = kprobe_event_define_fields; call->class->raw_init = probe_event_raw_init;
call->class->define_fields = kprobe_event_define_fields;
} }
if (set_print_fmt(tp) < 0) if (set_print_fmt(tp) < 0)
return -ENOMEM; return -ENOMEM;
call->event = &tp->event; ret = register_ftrace_event(&call->event);
call->id = register_ftrace_event(&tp->event); if (!ret) {
if (!call->id) {
kfree(call->print_fmt); kfree(call->print_fmt);
return -ENODEV; return -ENODEV;
} }
call->enabled = 0; call->flags = 0;
call->regfunc = probe_event_enable; call->class->reg = kprobe_register;
call->unregfunc = probe_event_disable;
#ifdef CONFIG_PERF_EVENTS
call->perf_event_enable = probe_perf_enable;
call->perf_event_disable = probe_perf_disable;
#endif
call->data = tp; call->data = tp;
ret = trace_add_event_call(call); ret = trace_add_event_call(call);
if (ret) { if (ret) {
pr_info("Failed to register kprobe event: %s\n", call->name); pr_info("Failed to register kprobe event: %s\n", call->name);
kfree(call->print_fmt); kfree(call->print_fmt);
unregister_ftrace_event(&tp->event); unregister_ftrace_event(&call->event);
} }
return ret; return ret;
} }
......
...@@ -742,6 +742,9 @@ int register_ftrace_event(struct trace_event *event) ...@@ -742,6 +742,9 @@ int register_ftrace_event(struct trace_event *event)
if (WARN_ON(!event)) if (WARN_ON(!event))
goto out; goto out;
if (WARN_ON(!event->funcs))
goto out;
INIT_LIST_HEAD(&event->list); INIT_LIST_HEAD(&event->list);
if (!event->type) { if (!event->type) {
...@@ -774,14 +777,14 @@ int register_ftrace_event(struct trace_event *event) ...@@ -774,14 +777,14 @@ int register_ftrace_event(struct trace_event *event)
goto out; goto out;
} }
if (event->trace == NULL) if (event->funcs->trace == NULL)
event->trace = trace_nop_print; event->funcs->trace = trace_nop_print;
if (event->raw == NULL) if (event->funcs->raw == NULL)
event->raw = trace_nop_print; event->funcs->raw = trace_nop_print;
if (event->hex == NULL) if (event->funcs->hex == NULL)
event->hex = trace_nop_print; event->funcs->hex = trace_nop_print;
if (event->binary == NULL) if (event->funcs->binary == NULL)
event->binary = trace_nop_print; event->funcs->binary = trace_nop_print;
key = event->type & (EVENT_HASHSIZE - 1); key = event->type & (EVENT_HASHSIZE - 1);
...@@ -823,13 +826,15 @@ EXPORT_SYMBOL_GPL(unregister_ftrace_event); ...@@ -823,13 +826,15 @@ EXPORT_SYMBOL_GPL(unregister_ftrace_event);
* Standard events * Standard events
*/ */
enum print_line_t trace_nop_print(struct trace_iterator *iter, int flags) enum print_line_t trace_nop_print(struct trace_iterator *iter, int flags,
struct trace_event *event)
{ {
return TRACE_TYPE_HANDLED; return TRACE_TYPE_HANDLED;
} }
/* TRACE_FN */ /* TRACE_FN */
static enum print_line_t trace_fn_trace(struct trace_iterator *iter, int flags) static enum print_line_t trace_fn_trace(struct trace_iterator *iter, int flags,
struct trace_event *event)
{ {
struct ftrace_entry *field; struct ftrace_entry *field;
struct trace_seq *s = &iter->seq; struct trace_seq *s = &iter->seq;
...@@ -856,7 +861,8 @@ static enum print_line_t trace_fn_trace(struct trace_iterator *iter, int flags) ...@@ -856,7 +861,8 @@ static enum print_line_t trace_fn_trace(struct trace_iterator *iter, int flags)
return TRACE_TYPE_PARTIAL_LINE; return TRACE_TYPE_PARTIAL_LINE;
} }
static enum print_line_t trace_fn_raw(struct trace_iterator *iter, int flags) static enum print_line_t trace_fn_raw(struct trace_iterator *iter, int flags,
struct trace_event *event)
{ {
struct ftrace_entry *field; struct ftrace_entry *field;
...@@ -870,7 +876,8 @@ static enum print_line_t trace_fn_raw(struct trace_iterator *iter, int flags) ...@@ -870,7 +876,8 @@ static enum print_line_t trace_fn_raw(struct trace_iterator *iter, int flags)
return TRACE_TYPE_HANDLED; return TRACE_TYPE_HANDLED;
} }
static enum print_line_t trace_fn_hex(struct trace_iterator *iter, int flags) static enum print_line_t trace_fn_hex(struct trace_iterator *iter, int flags,
struct trace_event *event)
{ {
struct ftrace_entry *field; struct ftrace_entry *field;
struct trace_seq *s = &iter->seq; struct trace_seq *s = &iter->seq;
...@@ -883,7 +890,8 @@ static enum print_line_t trace_fn_hex(struct trace_iterator *iter, int flags) ...@@ -883,7 +890,8 @@ static enum print_line_t trace_fn_hex(struct trace_iterator *iter, int flags)
return TRACE_TYPE_HANDLED; return TRACE_TYPE_HANDLED;
} }
static enum print_line_t trace_fn_bin(struct trace_iterator *iter, int flags) static enum print_line_t trace_fn_bin(struct trace_iterator *iter, int flags,
struct trace_event *event)
{ {
struct ftrace_entry *field; struct ftrace_entry *field;
struct trace_seq *s = &iter->seq; struct trace_seq *s = &iter->seq;
...@@ -896,14 +904,18 @@ static enum print_line_t trace_fn_bin(struct trace_iterator *iter, int flags) ...@@ -896,14 +904,18 @@ static enum print_line_t trace_fn_bin(struct trace_iterator *iter, int flags)
return TRACE_TYPE_HANDLED; return TRACE_TYPE_HANDLED;
} }
static struct trace_event trace_fn_event = { static struct trace_event_functions trace_fn_funcs = {
.type = TRACE_FN,
.trace = trace_fn_trace, .trace = trace_fn_trace,
.raw = trace_fn_raw, .raw = trace_fn_raw,
.hex = trace_fn_hex, .hex = trace_fn_hex,
.binary = trace_fn_bin, .binary = trace_fn_bin,
}; };
static struct trace_event trace_fn_event = {
.type = TRACE_FN,
.funcs = &trace_fn_funcs,
};
/* TRACE_CTX an TRACE_WAKE */ /* TRACE_CTX an TRACE_WAKE */
static enum print_line_t trace_ctxwake_print(struct trace_iterator *iter, static enum print_line_t trace_ctxwake_print(struct trace_iterator *iter,
char *delim) char *delim)
...@@ -932,13 +944,14 @@ static enum print_line_t trace_ctxwake_print(struct trace_iterator *iter, ...@@ -932,13 +944,14 @@ static enum print_line_t trace_ctxwake_print(struct trace_iterator *iter,
return TRACE_TYPE_HANDLED; return TRACE_TYPE_HANDLED;
} }
static enum print_line_t trace_ctx_print(struct trace_iterator *iter, int flags) static enum print_line_t trace_ctx_print(struct trace_iterator *iter, int flags,
struct trace_event *event)
{ {
return trace_ctxwake_print(iter, "==>"); return trace_ctxwake_print(iter, "==>");
} }
static enum print_line_t trace_wake_print(struct trace_iterator *iter, static enum print_line_t trace_wake_print(struct trace_iterator *iter,
int flags) int flags, struct trace_event *event)
{ {
return trace_ctxwake_print(iter, " +"); return trace_ctxwake_print(iter, " +");
} }
...@@ -966,12 +979,14 @@ static int trace_ctxwake_raw(struct trace_iterator *iter, char S) ...@@ -966,12 +979,14 @@ static int trace_ctxwake_raw(struct trace_iterator *iter, char S)
return TRACE_TYPE_HANDLED; return TRACE_TYPE_HANDLED;
} }
static enum print_line_t trace_ctx_raw(struct trace_iterator *iter, int flags) static enum print_line_t trace_ctx_raw(struct trace_iterator *iter, int flags,
struct trace_event *event)
{ {
return trace_ctxwake_raw(iter, 0); return trace_ctxwake_raw(iter, 0);
} }
static enum print_line_t trace_wake_raw(struct trace_iterator *iter, int flags) static enum print_line_t trace_wake_raw(struct trace_iterator *iter, int flags,
struct trace_event *event)
{ {
return trace_ctxwake_raw(iter, '+'); return trace_ctxwake_raw(iter, '+');
} }
...@@ -1000,18 +1015,20 @@ static int trace_ctxwake_hex(struct trace_iterator *iter, char S) ...@@ -1000,18 +1015,20 @@ static int trace_ctxwake_hex(struct trace_iterator *iter, char S)
return TRACE_TYPE_HANDLED; return TRACE_TYPE_HANDLED;
} }
static enum print_line_t trace_ctx_hex(struct trace_iterator *iter, int flags) static enum print_line_t trace_ctx_hex(struct trace_iterator *iter, int flags,
struct trace_event *event)
{ {
return trace_ctxwake_hex(iter, 0); return trace_ctxwake_hex(iter, 0);
} }
static enum print_line_t trace_wake_hex(struct trace_iterator *iter, int flags) static enum print_line_t trace_wake_hex(struct trace_iterator *iter, int flags,
struct trace_event *event)
{ {
return trace_ctxwake_hex(iter, '+'); return trace_ctxwake_hex(iter, '+');
} }
static enum print_line_t trace_ctxwake_bin(struct trace_iterator *iter, static enum print_line_t trace_ctxwake_bin(struct trace_iterator *iter,
int flags) int flags, struct trace_event *event)
{ {
struct ctx_switch_entry *field; struct ctx_switch_entry *field;
struct trace_seq *s = &iter->seq; struct trace_seq *s = &iter->seq;
...@@ -1028,25 +1045,33 @@ static enum print_line_t trace_ctxwake_bin(struct trace_iterator *iter, ...@@ -1028,25 +1045,33 @@ static enum print_line_t trace_ctxwake_bin(struct trace_iterator *iter,
return TRACE_TYPE_HANDLED; return TRACE_TYPE_HANDLED;
} }
static struct trace_event trace_ctx_event = { static struct trace_event_functions trace_ctx_funcs = {
.type = TRACE_CTX,
.trace = trace_ctx_print, .trace = trace_ctx_print,
.raw = trace_ctx_raw, .raw = trace_ctx_raw,
.hex = trace_ctx_hex, .hex = trace_ctx_hex,
.binary = trace_ctxwake_bin, .binary = trace_ctxwake_bin,
}; };
static struct trace_event trace_wake_event = { static struct trace_event trace_ctx_event = {
.type = TRACE_WAKE, .type = TRACE_CTX,
.funcs = &trace_ctx_funcs,
};
static struct trace_event_functions trace_wake_funcs = {
.trace = trace_wake_print, .trace = trace_wake_print,
.raw = trace_wake_raw, .raw = trace_wake_raw,
.hex = trace_wake_hex, .hex = trace_wake_hex,
.binary = trace_ctxwake_bin, .binary = trace_ctxwake_bin,
}; };
static struct trace_event trace_wake_event = {
.type = TRACE_WAKE,
.funcs = &trace_wake_funcs,
};
/* TRACE_SPECIAL */ /* TRACE_SPECIAL */
static enum print_line_t trace_special_print(struct trace_iterator *iter, static enum print_line_t trace_special_print(struct trace_iterator *iter,
int flags) int flags, struct trace_event *event)
{ {
struct special_entry *field; struct special_entry *field;
...@@ -1062,7 +1087,7 @@ static enum print_line_t trace_special_print(struct trace_iterator *iter, ...@@ -1062,7 +1087,7 @@ static enum print_line_t trace_special_print(struct trace_iterator *iter,
} }
static enum print_line_t trace_special_hex(struct trace_iterator *iter, static enum print_line_t trace_special_hex(struct trace_iterator *iter,
int flags) int flags, struct trace_event *event)
{ {
struct special_entry *field; struct special_entry *field;
struct trace_seq *s = &iter->seq; struct trace_seq *s = &iter->seq;
...@@ -1077,7 +1102,7 @@ static enum print_line_t trace_special_hex(struct trace_iterator *iter, ...@@ -1077,7 +1102,7 @@ static enum print_line_t trace_special_hex(struct trace_iterator *iter,
} }
static enum print_line_t trace_special_bin(struct trace_iterator *iter, static enum print_line_t trace_special_bin(struct trace_iterator *iter,
int flags) int flags, struct trace_event *event)
{ {
struct special_entry *field; struct special_entry *field;
struct trace_seq *s = &iter->seq; struct trace_seq *s = &iter->seq;
...@@ -1091,18 +1116,22 @@ static enum print_line_t trace_special_bin(struct trace_iterator *iter, ...@@ -1091,18 +1116,22 @@ static enum print_line_t trace_special_bin(struct trace_iterator *iter,
return TRACE_TYPE_HANDLED; return TRACE_TYPE_HANDLED;
} }
static struct trace_event trace_special_event = { static struct trace_event_functions trace_special_funcs = {
.type = TRACE_SPECIAL,
.trace = trace_special_print, .trace = trace_special_print,
.raw = trace_special_print, .raw = trace_special_print,
.hex = trace_special_hex, .hex = trace_special_hex,
.binary = trace_special_bin, .binary = trace_special_bin,
}; };
static struct trace_event trace_special_event = {
.type = TRACE_SPECIAL,
.funcs = &trace_special_funcs,
};
/* TRACE_STACK */ /* TRACE_STACK */
static enum print_line_t trace_stack_print(struct trace_iterator *iter, static enum print_line_t trace_stack_print(struct trace_iterator *iter,
int flags) int flags, struct trace_event *event)
{ {
struct stack_entry *field; struct stack_entry *field;
struct trace_seq *s = &iter->seq; struct trace_seq *s = &iter->seq;
...@@ -1130,17 +1159,21 @@ static enum print_line_t trace_stack_print(struct trace_iterator *iter, ...@@ -1130,17 +1159,21 @@ static enum print_line_t trace_stack_print(struct trace_iterator *iter,
return TRACE_TYPE_PARTIAL_LINE; return TRACE_TYPE_PARTIAL_LINE;
} }
static struct trace_event trace_stack_event = { static struct trace_event_functions trace_stack_funcs = {
.type = TRACE_STACK,
.trace = trace_stack_print, .trace = trace_stack_print,
.raw = trace_special_print, .raw = trace_special_print,
.hex = trace_special_hex, .hex = trace_special_hex,
.binary = trace_special_bin, .binary = trace_special_bin,
}; };
static struct trace_event trace_stack_event = {
.type = TRACE_STACK,
.funcs = &trace_stack_funcs,
};
/* TRACE_USER_STACK */ /* TRACE_USER_STACK */
static enum print_line_t trace_user_stack_print(struct trace_iterator *iter, static enum print_line_t trace_user_stack_print(struct trace_iterator *iter,
int flags) int flags, struct trace_event *event)
{ {
struct userstack_entry *field; struct userstack_entry *field;
struct trace_seq *s = &iter->seq; struct trace_seq *s = &iter->seq;
...@@ -1159,17 +1192,22 @@ static enum print_line_t trace_user_stack_print(struct trace_iterator *iter, ...@@ -1159,17 +1192,22 @@ static enum print_line_t trace_user_stack_print(struct trace_iterator *iter,
return TRACE_TYPE_PARTIAL_LINE; return TRACE_TYPE_PARTIAL_LINE;
} }
static struct trace_event trace_user_stack_event = { static struct trace_event_functions trace_user_stack_funcs = {
.type = TRACE_USER_STACK,
.trace = trace_user_stack_print, .trace = trace_user_stack_print,
.raw = trace_special_print, .raw = trace_special_print,
.hex = trace_special_hex, .hex = trace_special_hex,
.binary = trace_special_bin, .binary = trace_special_bin,
}; };
static struct trace_event trace_user_stack_event = {
.type = TRACE_USER_STACK,
.funcs = &trace_user_stack_funcs,
};
/* TRACE_BPRINT */ /* TRACE_BPRINT */
static enum print_line_t static enum print_line_t
trace_bprint_print(struct trace_iterator *iter, int flags) trace_bprint_print(struct trace_iterator *iter, int flags,
struct trace_event *event)
{ {
struct trace_entry *entry = iter->ent; struct trace_entry *entry = iter->ent;
struct trace_seq *s = &iter->seq; struct trace_seq *s = &iter->seq;
...@@ -1194,7 +1232,8 @@ trace_bprint_print(struct trace_iterator *iter, int flags) ...@@ -1194,7 +1232,8 @@ trace_bprint_print(struct trace_iterator *iter, int flags)
static enum print_line_t static enum print_line_t
trace_bprint_raw(struct trace_iterator *iter, int flags) trace_bprint_raw(struct trace_iterator *iter, int flags,
struct trace_event *event)
{ {
struct bprint_entry *field; struct bprint_entry *field;
struct trace_seq *s = &iter->seq; struct trace_seq *s = &iter->seq;
...@@ -1213,16 +1252,19 @@ trace_bprint_raw(struct trace_iterator *iter, int flags) ...@@ -1213,16 +1252,19 @@ trace_bprint_raw(struct trace_iterator *iter, int flags)
return TRACE_TYPE_PARTIAL_LINE; return TRACE_TYPE_PARTIAL_LINE;
} }
static struct trace_event_functions trace_bprint_funcs = {
.trace = trace_bprint_print,
.raw = trace_bprint_raw,
};
static struct trace_event trace_bprint_event = { static struct trace_event trace_bprint_event = {
.type = TRACE_BPRINT, .type = TRACE_BPRINT,
.trace = trace_bprint_print, .funcs = &trace_bprint_funcs,
.raw = trace_bprint_raw,
}; };
/* TRACE_PRINT */ /* TRACE_PRINT */
static enum print_line_t trace_print_print(struct trace_iterator *iter, static enum print_line_t trace_print_print(struct trace_iterator *iter,
int flags) int flags, struct trace_event *event)
{ {
struct print_entry *field; struct print_entry *field;
struct trace_seq *s = &iter->seq; struct trace_seq *s = &iter->seq;
...@@ -1241,7 +1283,8 @@ static enum print_line_t trace_print_print(struct trace_iterator *iter, ...@@ -1241,7 +1283,8 @@ static enum print_line_t trace_print_print(struct trace_iterator *iter,
return TRACE_TYPE_PARTIAL_LINE; return TRACE_TYPE_PARTIAL_LINE;
} }
static enum print_line_t trace_print_raw(struct trace_iterator *iter, int flags) static enum print_line_t trace_print_raw(struct trace_iterator *iter, int flags,
struct trace_event *event)
{ {
struct print_entry *field; struct print_entry *field;
...@@ -1256,12 +1299,16 @@ static enum print_line_t trace_print_raw(struct trace_iterator *iter, int flags) ...@@ -1256,12 +1299,16 @@ static enum print_line_t trace_print_raw(struct trace_iterator *iter, int flags)
return TRACE_TYPE_PARTIAL_LINE; return TRACE_TYPE_PARTIAL_LINE;
} }
static struct trace_event trace_print_event = { static struct trace_event_functions trace_print_funcs = {
.type = TRACE_PRINT,
.trace = trace_print_print, .trace = trace_print_print,
.raw = trace_print_raw, .raw = trace_print_raw,
}; };
static struct trace_event trace_print_event = {
.type = TRACE_PRINT,
.funcs = &trace_print_funcs,
};
static struct trace_event *events[] __initdata = { static struct trace_event *events[] __initdata = {
&trace_fn_event, &trace_fn_event,
......
...@@ -25,7 +25,7 @@ extern void trace_event_read_unlock(void); ...@@ -25,7 +25,7 @@ extern void trace_event_read_unlock(void);
extern struct trace_event *ftrace_find_event(int type); extern struct trace_event *ftrace_find_event(int type);
extern enum print_line_t trace_nop_print(struct trace_iterator *iter, extern enum print_line_t trace_nop_print(struct trace_iterator *iter,
int flags); int flags, struct trace_event *event);
extern int extern int
trace_print_lat_fmt(struct trace_seq *s, struct trace_entry *entry); trace_print_lat_fmt(struct trace_seq *s, struct trace_entry *entry);
......
...@@ -50,7 +50,7 @@ tracing_sched_switch_trace(struct trace_array *tr, ...@@ -50,7 +50,7 @@ tracing_sched_switch_trace(struct trace_array *tr,
} }
static void static void
probe_sched_switch(struct task_struct *prev, struct task_struct *next) probe_sched_switch(void *ignore, struct task_struct *prev, struct task_struct *next)
{ {
struct trace_array_cpu *data; struct trace_array_cpu *data;
unsigned long flags; unsigned long flags;
...@@ -108,7 +108,7 @@ tracing_sched_wakeup_trace(struct trace_array *tr, ...@@ -108,7 +108,7 @@ tracing_sched_wakeup_trace(struct trace_array *tr,
} }
static void static void
probe_sched_wakeup(struct task_struct *wakee, int success) probe_sched_wakeup(void *ignore, struct task_struct *wakee, int success)
{ {
struct trace_array_cpu *data; struct trace_array_cpu *data;
unsigned long flags; unsigned long flags;
...@@ -138,21 +138,21 @@ static int tracing_sched_register(void) ...@@ -138,21 +138,21 @@ static int tracing_sched_register(void)
{ {
int ret; int ret;
ret = register_trace_sched_wakeup(probe_sched_wakeup); ret = register_trace_sched_wakeup(probe_sched_wakeup, NULL);
if (ret) { if (ret) {
pr_info("wakeup trace: Couldn't activate tracepoint" pr_info("wakeup trace: Couldn't activate tracepoint"
" probe to kernel_sched_wakeup\n"); " probe to kernel_sched_wakeup\n");
return ret; return ret;
} }
ret = register_trace_sched_wakeup_new(probe_sched_wakeup); ret = register_trace_sched_wakeup_new(probe_sched_wakeup, NULL);
if (ret) { if (ret) {
pr_info("wakeup trace: Couldn't activate tracepoint" pr_info("wakeup trace: Couldn't activate tracepoint"
" probe to kernel_sched_wakeup_new\n"); " probe to kernel_sched_wakeup_new\n");
goto fail_deprobe; goto fail_deprobe;
} }
ret = register_trace_sched_switch(probe_sched_switch); ret = register_trace_sched_switch(probe_sched_switch, NULL);
if (ret) { if (ret) {
pr_info("sched trace: Couldn't activate tracepoint" pr_info("sched trace: Couldn't activate tracepoint"
" probe to kernel_sched_switch\n"); " probe to kernel_sched_switch\n");
...@@ -161,17 +161,17 @@ static int tracing_sched_register(void) ...@@ -161,17 +161,17 @@ static int tracing_sched_register(void)
return ret; return ret;
fail_deprobe_wake_new: fail_deprobe_wake_new:
unregister_trace_sched_wakeup_new(probe_sched_wakeup); unregister_trace_sched_wakeup_new(probe_sched_wakeup, NULL);
fail_deprobe: fail_deprobe:
unregister_trace_sched_wakeup(probe_sched_wakeup); unregister_trace_sched_wakeup(probe_sched_wakeup, NULL);
return ret; return ret;
} }
static void tracing_sched_unregister(void) static void tracing_sched_unregister(void)
{ {
unregister_trace_sched_switch(probe_sched_switch); unregister_trace_sched_switch(probe_sched_switch, NULL);
unregister_trace_sched_wakeup_new(probe_sched_wakeup); unregister_trace_sched_wakeup_new(probe_sched_wakeup, NULL);
unregister_trace_sched_wakeup(probe_sched_wakeup); unregister_trace_sched_wakeup(probe_sched_wakeup, NULL);
} }
static void tracing_start_sched_switch(void) static void tracing_start_sched_switch(void)
......
...@@ -98,7 +98,8 @@ static int report_latency(cycle_t delta) ...@@ -98,7 +98,8 @@ static int report_latency(cycle_t delta)
return 1; return 1;
} }
static void probe_wakeup_migrate_task(struct task_struct *task, int cpu) static void
probe_wakeup_migrate_task(void *ignore, struct task_struct *task, int cpu)
{ {
if (task != wakeup_task) if (task != wakeup_task)
return; return;
...@@ -107,7 +108,8 @@ static void probe_wakeup_migrate_task(struct task_struct *task, int cpu) ...@@ -107,7 +108,8 @@ static void probe_wakeup_migrate_task(struct task_struct *task, int cpu)
} }
static void notrace static void notrace
probe_wakeup_sched_switch(struct task_struct *prev, struct task_struct *next) probe_wakeup_sched_switch(void *ignore,
struct task_struct *prev, struct task_struct *next)
{ {
struct trace_array_cpu *data; struct trace_array_cpu *data;
cycle_t T0, T1, delta; cycle_t T0, T1, delta;
...@@ -199,7 +201,7 @@ static void wakeup_reset(struct trace_array *tr) ...@@ -199,7 +201,7 @@ static void wakeup_reset(struct trace_array *tr)
} }
static void static void
probe_wakeup(struct task_struct *p, int success) probe_wakeup(void *ignore, struct task_struct *p, int success)
{ {
struct trace_array_cpu *data; struct trace_array_cpu *data;
int cpu = smp_processor_id(); int cpu = smp_processor_id();
...@@ -263,28 +265,28 @@ static void start_wakeup_tracer(struct trace_array *tr) ...@@ -263,28 +265,28 @@ static void start_wakeup_tracer(struct trace_array *tr)
{ {
int ret; int ret;
ret = register_trace_sched_wakeup(probe_wakeup); ret = register_trace_sched_wakeup(probe_wakeup, NULL);
if (ret) { if (ret) {
pr_info("wakeup trace: Couldn't activate tracepoint" pr_info("wakeup trace: Couldn't activate tracepoint"
" probe to kernel_sched_wakeup\n"); " probe to kernel_sched_wakeup\n");
return; return;
} }
ret = register_trace_sched_wakeup_new(probe_wakeup); ret = register_trace_sched_wakeup_new(probe_wakeup, NULL);
if (ret) { if (ret) {
pr_info("wakeup trace: Couldn't activate tracepoint" pr_info("wakeup trace: Couldn't activate tracepoint"
" probe to kernel_sched_wakeup_new\n"); " probe to kernel_sched_wakeup_new\n");
goto fail_deprobe; goto fail_deprobe;
} }
ret = register_trace_sched_switch(probe_wakeup_sched_switch); ret = register_trace_sched_switch(probe_wakeup_sched_switch, NULL);
if (ret) { if (ret) {
pr_info("sched trace: Couldn't activate tracepoint" pr_info("sched trace: Couldn't activate tracepoint"
" probe to kernel_sched_switch\n"); " probe to kernel_sched_switch\n");
goto fail_deprobe_wake_new; goto fail_deprobe_wake_new;
} }
ret = register_trace_sched_migrate_task(probe_wakeup_migrate_task); ret = register_trace_sched_migrate_task(probe_wakeup_migrate_task, NULL);
if (ret) { if (ret) {
pr_info("wakeup trace: Couldn't activate tracepoint" pr_info("wakeup trace: Couldn't activate tracepoint"
" probe to kernel_sched_migrate_task\n"); " probe to kernel_sched_migrate_task\n");
...@@ -311,19 +313,19 @@ static void start_wakeup_tracer(struct trace_array *tr) ...@@ -311,19 +313,19 @@ static void start_wakeup_tracer(struct trace_array *tr)
return; return;
fail_deprobe_wake_new: fail_deprobe_wake_new:
unregister_trace_sched_wakeup_new(probe_wakeup); unregister_trace_sched_wakeup_new(probe_wakeup, NULL);
fail_deprobe: fail_deprobe:
unregister_trace_sched_wakeup(probe_wakeup); unregister_trace_sched_wakeup(probe_wakeup, NULL);
} }
static void stop_wakeup_tracer(struct trace_array *tr) static void stop_wakeup_tracer(struct trace_array *tr)
{ {
tracer_enabled = 0; tracer_enabled = 0;
unregister_ftrace_function(&trace_ops); unregister_ftrace_function(&trace_ops);
unregister_trace_sched_switch(probe_wakeup_sched_switch); unregister_trace_sched_switch(probe_wakeup_sched_switch, NULL);
unregister_trace_sched_wakeup_new(probe_wakeup); unregister_trace_sched_wakeup_new(probe_wakeup, NULL);
unregister_trace_sched_wakeup(probe_wakeup); unregister_trace_sched_wakeup(probe_wakeup, NULL);
unregister_trace_sched_migrate_task(probe_wakeup_migrate_task); unregister_trace_sched_migrate_task(probe_wakeup_migrate_task, NULL);
} }
static int __wakeup_tracer_init(struct trace_array *tr) static int __wakeup_tracer_init(struct trace_array *tr)
......
...@@ -15,6 +15,54 @@ static int sys_refcount_exit; ...@@ -15,6 +15,54 @@ static int sys_refcount_exit;
static DECLARE_BITMAP(enabled_enter_syscalls, NR_syscalls); static DECLARE_BITMAP(enabled_enter_syscalls, NR_syscalls);
static DECLARE_BITMAP(enabled_exit_syscalls, NR_syscalls); static DECLARE_BITMAP(enabled_exit_syscalls, NR_syscalls);
static int syscall_enter_register(struct ftrace_event_call *event,
enum trace_reg type);
static int syscall_exit_register(struct ftrace_event_call *event,
enum trace_reg type);
static int syscall_enter_define_fields(struct ftrace_event_call *call);
static int syscall_exit_define_fields(struct ftrace_event_call *call);
static struct list_head *
syscall_get_enter_fields(struct ftrace_event_call *call)
{
struct syscall_metadata *entry = call->data;
return &entry->enter_fields;
}
static struct list_head *
syscall_get_exit_fields(struct ftrace_event_call *call)
{
struct syscall_metadata *entry = call->data;
return &entry->exit_fields;
}
struct trace_event_functions enter_syscall_print_funcs = {
.trace = print_syscall_enter,
};
struct trace_event_functions exit_syscall_print_funcs = {
.trace = print_syscall_exit,
};
struct ftrace_event_class event_class_syscall_enter = {
.system = "syscalls",
.reg = syscall_enter_register,
.define_fields = syscall_enter_define_fields,
.get_fields = syscall_get_enter_fields,
.raw_init = init_syscall_trace,
};
struct ftrace_event_class event_class_syscall_exit = {
.system = "syscalls",
.reg = syscall_exit_register,
.define_fields = syscall_exit_define_fields,
.get_fields = syscall_get_exit_fields,
.raw_init = init_syscall_trace,
};
extern unsigned long __start_syscalls_metadata[]; extern unsigned long __start_syscalls_metadata[];
extern unsigned long __stop_syscalls_metadata[]; extern unsigned long __stop_syscalls_metadata[];
...@@ -53,7 +101,8 @@ static struct syscall_metadata *syscall_nr_to_meta(int nr) ...@@ -53,7 +101,8 @@ static struct syscall_metadata *syscall_nr_to_meta(int nr)
} }
enum print_line_t enum print_line_t
print_syscall_enter(struct trace_iterator *iter, int flags) print_syscall_enter(struct trace_iterator *iter, int flags,
struct trace_event *event)
{ {
struct trace_seq *s = &iter->seq; struct trace_seq *s = &iter->seq;
struct trace_entry *ent = iter->ent; struct trace_entry *ent = iter->ent;
...@@ -68,7 +117,7 @@ print_syscall_enter(struct trace_iterator *iter, int flags) ...@@ -68,7 +117,7 @@ print_syscall_enter(struct trace_iterator *iter, int flags)
if (!entry) if (!entry)
goto end; goto end;
if (entry->enter_event->id != ent->type) { if (entry->enter_event->event.type != ent->type) {
WARN_ON_ONCE(1); WARN_ON_ONCE(1);
goto end; goto end;
} }
...@@ -105,7 +154,8 @@ print_syscall_enter(struct trace_iterator *iter, int flags) ...@@ -105,7 +154,8 @@ print_syscall_enter(struct trace_iterator *iter, int flags)
} }
enum print_line_t enum print_line_t
print_syscall_exit(struct trace_iterator *iter, int flags) print_syscall_exit(struct trace_iterator *iter, int flags,
struct trace_event *event)
{ {
struct trace_seq *s = &iter->seq; struct trace_seq *s = &iter->seq;
struct trace_entry *ent = iter->ent; struct trace_entry *ent = iter->ent;
...@@ -123,7 +173,7 @@ print_syscall_exit(struct trace_iterator *iter, int flags) ...@@ -123,7 +173,7 @@ print_syscall_exit(struct trace_iterator *iter, int flags)
return TRACE_TYPE_HANDLED; return TRACE_TYPE_HANDLED;
} }
if (entry->exit_event->id != ent->type) { if (entry->exit_event->event.type != ent->type) {
WARN_ON_ONCE(1); WARN_ON_ONCE(1);
return TRACE_TYPE_UNHANDLED; return TRACE_TYPE_UNHANDLED;
} }
...@@ -205,7 +255,7 @@ static void free_syscall_print_fmt(struct ftrace_event_call *call) ...@@ -205,7 +255,7 @@ static void free_syscall_print_fmt(struct ftrace_event_call *call)
kfree(call->print_fmt); kfree(call->print_fmt);
} }
int syscall_enter_define_fields(struct ftrace_event_call *call) static int syscall_enter_define_fields(struct ftrace_event_call *call)
{ {
struct syscall_trace_enter trace; struct syscall_trace_enter trace;
struct syscall_metadata *meta = call->data; struct syscall_metadata *meta = call->data;
...@@ -228,7 +278,7 @@ int syscall_enter_define_fields(struct ftrace_event_call *call) ...@@ -228,7 +278,7 @@ int syscall_enter_define_fields(struct ftrace_event_call *call)
return ret; return ret;
} }
int syscall_exit_define_fields(struct ftrace_event_call *call) static int syscall_exit_define_fields(struct ftrace_event_call *call)
{ {
struct syscall_trace_exit trace; struct syscall_trace_exit trace;
int ret; int ret;
...@@ -243,7 +293,7 @@ int syscall_exit_define_fields(struct ftrace_event_call *call) ...@@ -243,7 +293,7 @@ int syscall_exit_define_fields(struct ftrace_event_call *call)
return ret; return ret;
} }
void ftrace_syscall_enter(struct pt_regs *regs, long id) void ftrace_syscall_enter(void *ignore, struct pt_regs *regs, long id)
{ {
struct syscall_trace_enter *entry; struct syscall_trace_enter *entry;
struct syscall_metadata *sys_data; struct syscall_metadata *sys_data;
...@@ -265,7 +315,7 @@ void ftrace_syscall_enter(struct pt_regs *regs, long id) ...@@ -265,7 +315,7 @@ void ftrace_syscall_enter(struct pt_regs *regs, long id)
size = sizeof(*entry) + sizeof(unsigned long) * sys_data->nb_args; size = sizeof(*entry) + sizeof(unsigned long) * sys_data->nb_args;
event = trace_current_buffer_lock_reserve(&buffer, event = trace_current_buffer_lock_reserve(&buffer,
sys_data->enter_event->id, size, 0, 0); sys_data->enter_event->event.type, size, 0, 0);
if (!event) if (!event)
return; return;
...@@ -278,7 +328,7 @@ void ftrace_syscall_enter(struct pt_regs *regs, long id) ...@@ -278,7 +328,7 @@ void ftrace_syscall_enter(struct pt_regs *regs, long id)
trace_current_buffer_unlock_commit(buffer, event, 0, 0); trace_current_buffer_unlock_commit(buffer, event, 0, 0);
} }
void ftrace_syscall_exit(struct pt_regs *regs, long ret) void ftrace_syscall_exit(void *ignore, struct pt_regs *regs, long ret)
{ {
struct syscall_trace_exit *entry; struct syscall_trace_exit *entry;
struct syscall_metadata *sys_data; struct syscall_metadata *sys_data;
...@@ -297,7 +347,7 @@ void ftrace_syscall_exit(struct pt_regs *regs, long ret) ...@@ -297,7 +347,7 @@ void ftrace_syscall_exit(struct pt_regs *regs, long ret)
return; return;
event = trace_current_buffer_lock_reserve(&buffer, event = trace_current_buffer_lock_reserve(&buffer,
sys_data->exit_event->id, sizeof(*entry), 0, 0); sys_data->exit_event->event.type, sizeof(*entry), 0, 0);
if (!event) if (!event)
return; return;
...@@ -320,7 +370,7 @@ int reg_event_syscall_enter(struct ftrace_event_call *call) ...@@ -320,7 +370,7 @@ int reg_event_syscall_enter(struct ftrace_event_call *call)
return -ENOSYS; return -ENOSYS;
mutex_lock(&syscall_trace_lock); mutex_lock(&syscall_trace_lock);
if (!sys_refcount_enter) if (!sys_refcount_enter)
ret = register_trace_sys_enter(ftrace_syscall_enter); ret = register_trace_sys_enter(ftrace_syscall_enter, NULL);
if (!ret) { if (!ret) {
set_bit(num, enabled_enter_syscalls); set_bit(num, enabled_enter_syscalls);
sys_refcount_enter++; sys_refcount_enter++;
...@@ -340,7 +390,7 @@ void unreg_event_syscall_enter(struct ftrace_event_call *call) ...@@ -340,7 +390,7 @@ void unreg_event_syscall_enter(struct ftrace_event_call *call)
sys_refcount_enter--; sys_refcount_enter--;
clear_bit(num, enabled_enter_syscalls); clear_bit(num, enabled_enter_syscalls);
if (!sys_refcount_enter) if (!sys_refcount_enter)
unregister_trace_sys_enter(ftrace_syscall_enter); unregister_trace_sys_enter(ftrace_syscall_enter, NULL);
mutex_unlock(&syscall_trace_lock); mutex_unlock(&syscall_trace_lock);
} }
...@@ -354,7 +404,7 @@ int reg_event_syscall_exit(struct ftrace_event_call *call) ...@@ -354,7 +404,7 @@ int reg_event_syscall_exit(struct ftrace_event_call *call)
return -ENOSYS; return -ENOSYS;
mutex_lock(&syscall_trace_lock); mutex_lock(&syscall_trace_lock);
if (!sys_refcount_exit) if (!sys_refcount_exit)
ret = register_trace_sys_exit(ftrace_syscall_exit); ret = register_trace_sys_exit(ftrace_syscall_exit, NULL);
if (!ret) { if (!ret) {
set_bit(num, enabled_exit_syscalls); set_bit(num, enabled_exit_syscalls);
sys_refcount_exit++; sys_refcount_exit++;
...@@ -374,7 +424,7 @@ void unreg_event_syscall_exit(struct ftrace_event_call *call) ...@@ -374,7 +424,7 @@ void unreg_event_syscall_exit(struct ftrace_event_call *call)
sys_refcount_exit--; sys_refcount_exit--;
clear_bit(num, enabled_exit_syscalls); clear_bit(num, enabled_exit_syscalls);
if (!sys_refcount_exit) if (!sys_refcount_exit)
unregister_trace_sys_exit(ftrace_syscall_exit); unregister_trace_sys_exit(ftrace_syscall_exit, NULL);
mutex_unlock(&syscall_trace_lock); mutex_unlock(&syscall_trace_lock);
} }
...@@ -434,11 +484,11 @@ static DECLARE_BITMAP(enabled_perf_exit_syscalls, NR_syscalls); ...@@ -434,11 +484,11 @@ static DECLARE_BITMAP(enabled_perf_exit_syscalls, NR_syscalls);
static int sys_perf_refcount_enter; static int sys_perf_refcount_enter;
static int sys_perf_refcount_exit; static int sys_perf_refcount_exit;
static void perf_syscall_enter(struct pt_regs *regs, long id) static void perf_syscall_enter(void *ignore, struct pt_regs *regs, long id)
{ {
struct syscall_metadata *sys_data; struct syscall_metadata *sys_data;
struct syscall_trace_enter *rec; struct syscall_trace_enter *rec;
unsigned long flags; struct hlist_head *head;
int syscall_nr; int syscall_nr;
int rctx; int rctx;
int size; int size;
...@@ -461,14 +511,16 @@ static void perf_syscall_enter(struct pt_regs *regs, long id) ...@@ -461,14 +511,16 @@ static void perf_syscall_enter(struct pt_regs *regs, long id)
return; return;
rec = (struct syscall_trace_enter *)perf_trace_buf_prepare(size, rec = (struct syscall_trace_enter *)perf_trace_buf_prepare(size,
sys_data->enter_event->id, &rctx, &flags); sys_data->enter_event->event.type, regs, &rctx);
if (!rec) if (!rec)
return; return;
rec->nr = syscall_nr; rec->nr = syscall_nr;
syscall_get_arguments(current, regs, 0, sys_data->nb_args, syscall_get_arguments(current, regs, 0, sys_data->nb_args,
(unsigned long *)&rec->args); (unsigned long *)&rec->args);
perf_trace_buf_submit(rec, size, rctx, 0, 1, flags, regs);
head = per_cpu_ptr(sys_data->enter_event->perf_events, smp_processor_id());
perf_trace_buf_submit(rec, size, rctx, 0, 1, regs, head);
} }
int perf_sysenter_enable(struct ftrace_event_call *call) int perf_sysenter_enable(struct ftrace_event_call *call)
...@@ -480,7 +532,7 @@ int perf_sysenter_enable(struct ftrace_event_call *call) ...@@ -480,7 +532,7 @@ int perf_sysenter_enable(struct ftrace_event_call *call)
mutex_lock(&syscall_trace_lock); mutex_lock(&syscall_trace_lock);
if (!sys_perf_refcount_enter) if (!sys_perf_refcount_enter)
ret = register_trace_sys_enter(perf_syscall_enter); ret = register_trace_sys_enter(perf_syscall_enter, NULL);
if (ret) { if (ret) {
pr_info("event trace: Could not activate" pr_info("event trace: Could not activate"
"syscall entry trace point"); "syscall entry trace point");
...@@ -502,15 +554,15 @@ void perf_sysenter_disable(struct ftrace_event_call *call) ...@@ -502,15 +554,15 @@ void perf_sysenter_disable(struct ftrace_event_call *call)
sys_perf_refcount_enter--; sys_perf_refcount_enter--;
clear_bit(num, enabled_perf_enter_syscalls); clear_bit(num, enabled_perf_enter_syscalls);
if (!sys_perf_refcount_enter) if (!sys_perf_refcount_enter)
unregister_trace_sys_enter(perf_syscall_enter); unregister_trace_sys_enter(perf_syscall_enter, NULL);
mutex_unlock(&syscall_trace_lock); mutex_unlock(&syscall_trace_lock);
} }
static void perf_syscall_exit(struct pt_regs *regs, long ret) static void perf_syscall_exit(void *ignore, struct pt_regs *regs, long ret)
{ {
struct syscall_metadata *sys_data; struct syscall_metadata *sys_data;
struct syscall_trace_exit *rec; struct syscall_trace_exit *rec;
unsigned long flags; struct hlist_head *head;
int syscall_nr; int syscall_nr;
int rctx; int rctx;
int size; int size;
...@@ -536,14 +588,15 @@ static void perf_syscall_exit(struct pt_regs *regs, long ret) ...@@ -536,14 +588,15 @@ static void perf_syscall_exit(struct pt_regs *regs, long ret)
return; return;
rec = (struct syscall_trace_exit *)perf_trace_buf_prepare(size, rec = (struct syscall_trace_exit *)perf_trace_buf_prepare(size,
sys_data->exit_event->id, &rctx, &flags); sys_data->exit_event->event.type, regs, &rctx);
if (!rec) if (!rec)
return; return;
rec->nr = syscall_nr; rec->nr = syscall_nr;
rec->ret = syscall_get_return_value(current, regs); rec->ret = syscall_get_return_value(current, regs);
perf_trace_buf_submit(rec, size, rctx, 0, 1, flags, regs); head = per_cpu_ptr(sys_data->exit_event->perf_events, smp_processor_id());
perf_trace_buf_submit(rec, size, rctx, 0, 1, regs, head);
} }
int perf_sysexit_enable(struct ftrace_event_call *call) int perf_sysexit_enable(struct ftrace_event_call *call)
...@@ -555,7 +608,7 @@ int perf_sysexit_enable(struct ftrace_event_call *call) ...@@ -555,7 +608,7 @@ int perf_sysexit_enable(struct ftrace_event_call *call)
mutex_lock(&syscall_trace_lock); mutex_lock(&syscall_trace_lock);
if (!sys_perf_refcount_exit) if (!sys_perf_refcount_exit)
ret = register_trace_sys_exit(perf_syscall_exit); ret = register_trace_sys_exit(perf_syscall_exit, NULL);
if (ret) { if (ret) {
pr_info("event trace: Could not activate" pr_info("event trace: Could not activate"
"syscall exit trace point"); "syscall exit trace point");
...@@ -577,9 +630,50 @@ void perf_sysexit_disable(struct ftrace_event_call *call) ...@@ -577,9 +630,50 @@ void perf_sysexit_disable(struct ftrace_event_call *call)
sys_perf_refcount_exit--; sys_perf_refcount_exit--;
clear_bit(num, enabled_perf_exit_syscalls); clear_bit(num, enabled_perf_exit_syscalls);
if (!sys_perf_refcount_exit) if (!sys_perf_refcount_exit)
unregister_trace_sys_exit(perf_syscall_exit); unregister_trace_sys_exit(perf_syscall_exit, NULL);
mutex_unlock(&syscall_trace_lock); mutex_unlock(&syscall_trace_lock);
} }
#endif /* CONFIG_PERF_EVENTS */ #endif /* CONFIG_PERF_EVENTS */
static int syscall_enter_register(struct ftrace_event_call *event,
enum trace_reg type)
{
switch (type) {
case TRACE_REG_REGISTER:
return reg_event_syscall_enter(event);
case TRACE_REG_UNREGISTER:
unreg_event_syscall_enter(event);
return 0;
#ifdef CONFIG_PERF_EVENTS
case TRACE_REG_PERF_REGISTER:
return perf_sysenter_enable(event);
case TRACE_REG_PERF_UNREGISTER:
perf_sysenter_disable(event);
return 0;
#endif
}
return 0;
}
static int syscall_exit_register(struct ftrace_event_call *event,
enum trace_reg type)
{
switch (type) {
case TRACE_REG_REGISTER:
return reg_event_syscall_exit(event);
case TRACE_REG_UNREGISTER:
unreg_event_syscall_exit(event);
return 0;
#ifdef CONFIG_PERF_EVENTS
case TRACE_REG_PERF_REGISTER:
return perf_sysexit_enable(event);
case TRACE_REG_PERF_UNREGISTER:
perf_sysexit_disable(event);
return 0;
#endif
}
return 0;
}
...@@ -49,7 +49,8 @@ static void cpu_workqueue_stat_free(struct kref *kref) ...@@ -49,7 +49,8 @@ static void cpu_workqueue_stat_free(struct kref *kref)
/* Insertion of a work */ /* Insertion of a work */
static void static void
probe_workqueue_insertion(struct task_struct *wq_thread, probe_workqueue_insertion(void *ignore,
struct task_struct *wq_thread,
struct work_struct *work) struct work_struct *work)
{ {
int cpu = cpumask_first(&wq_thread->cpus_allowed); int cpu = cpumask_first(&wq_thread->cpus_allowed);
...@@ -70,7 +71,8 @@ probe_workqueue_insertion(struct task_struct *wq_thread, ...@@ -70,7 +71,8 @@ probe_workqueue_insertion(struct task_struct *wq_thread,
/* Execution of a work */ /* Execution of a work */
static void static void
probe_workqueue_execution(struct task_struct *wq_thread, probe_workqueue_execution(void *ignore,
struct task_struct *wq_thread,
struct work_struct *work) struct work_struct *work)
{ {
int cpu = cpumask_first(&wq_thread->cpus_allowed); int cpu = cpumask_first(&wq_thread->cpus_allowed);
...@@ -90,7 +92,8 @@ probe_workqueue_execution(struct task_struct *wq_thread, ...@@ -90,7 +92,8 @@ probe_workqueue_execution(struct task_struct *wq_thread,
} }
/* Creation of a cpu workqueue thread */ /* Creation of a cpu workqueue thread */
static void probe_workqueue_creation(struct task_struct *wq_thread, int cpu) static void probe_workqueue_creation(void *ignore,
struct task_struct *wq_thread, int cpu)
{ {
struct cpu_workqueue_stats *cws; struct cpu_workqueue_stats *cws;
unsigned long flags; unsigned long flags;
...@@ -114,7 +117,8 @@ static void probe_workqueue_creation(struct task_struct *wq_thread, int cpu) ...@@ -114,7 +117,8 @@ static void probe_workqueue_creation(struct task_struct *wq_thread, int cpu)
} }
/* Destruction of a cpu workqueue thread */ /* Destruction of a cpu workqueue thread */
static void probe_workqueue_destruction(struct task_struct *wq_thread) static void
probe_workqueue_destruction(void *ignore, struct task_struct *wq_thread)
{ {
/* Workqueue only execute on one cpu */ /* Workqueue only execute on one cpu */
int cpu = cpumask_first(&wq_thread->cpus_allowed); int cpu = cpumask_first(&wq_thread->cpus_allowed);
...@@ -259,19 +263,19 @@ int __init trace_workqueue_early_init(void) ...@@ -259,19 +263,19 @@ int __init trace_workqueue_early_init(void)
{ {
int ret, cpu; int ret, cpu;
ret = register_trace_workqueue_insertion(probe_workqueue_insertion); ret = register_trace_workqueue_insertion(probe_workqueue_insertion, NULL);
if (ret) if (ret)
goto out; goto out;
ret = register_trace_workqueue_execution(probe_workqueue_execution); ret = register_trace_workqueue_execution(probe_workqueue_execution, NULL);
if (ret) if (ret)
goto no_insertion; goto no_insertion;
ret = register_trace_workqueue_creation(probe_workqueue_creation); ret = register_trace_workqueue_creation(probe_workqueue_creation, NULL);
if (ret) if (ret)
goto no_execution; goto no_execution;
ret = register_trace_workqueue_destruction(probe_workqueue_destruction); ret = register_trace_workqueue_destruction(probe_workqueue_destruction, NULL);
if (ret) if (ret)
goto no_creation; goto no_creation;
...@@ -283,11 +287,11 @@ int __init trace_workqueue_early_init(void) ...@@ -283,11 +287,11 @@ int __init trace_workqueue_early_init(void)
return 0; return 0;
no_creation: no_creation:
unregister_trace_workqueue_creation(probe_workqueue_creation); unregister_trace_workqueue_creation(probe_workqueue_creation, NULL);
no_execution: no_execution:
unregister_trace_workqueue_execution(probe_workqueue_execution); unregister_trace_workqueue_execution(probe_workqueue_execution, NULL);
no_insertion: no_insertion:
unregister_trace_workqueue_insertion(probe_workqueue_insertion); unregister_trace_workqueue_insertion(probe_workqueue_insertion, NULL);
out: out:
pr_warning("trace_workqueue: unable to trace workqueues\n"); pr_warning("trace_workqueue: unable to trace workqueues\n");
......
...@@ -54,7 +54,7 @@ static struct hlist_head tracepoint_table[TRACEPOINT_TABLE_SIZE]; ...@@ -54,7 +54,7 @@ static struct hlist_head tracepoint_table[TRACEPOINT_TABLE_SIZE];
*/ */
struct tracepoint_entry { struct tracepoint_entry {
struct hlist_node hlist; struct hlist_node hlist;
void **funcs; struct tracepoint_func *funcs;
int refcount; /* Number of times armed. 0 if disarmed. */ int refcount; /* Number of times armed. 0 if disarmed. */
char name[0]; char name[0];
}; };
...@@ -64,12 +64,12 @@ struct tp_probes { ...@@ -64,12 +64,12 @@ struct tp_probes {
struct rcu_head rcu; struct rcu_head rcu;
struct list_head list; struct list_head list;
} u; } u;
void *probes[0]; struct tracepoint_func probes[0];
}; };
static inline void *allocate_probes(int count) static inline void *allocate_probes(int count)
{ {
struct tp_probes *p = kmalloc(count * sizeof(void *) struct tp_probes *p = kmalloc(count * sizeof(struct tracepoint_func)
+ sizeof(struct tp_probes), GFP_KERNEL); + sizeof(struct tp_probes), GFP_KERNEL);
return p == NULL ? NULL : p->probes; return p == NULL ? NULL : p->probes;
} }
...@@ -79,7 +79,7 @@ static void rcu_free_old_probes(struct rcu_head *head) ...@@ -79,7 +79,7 @@ static void rcu_free_old_probes(struct rcu_head *head)
kfree(container_of(head, struct tp_probes, u.rcu)); kfree(container_of(head, struct tp_probes, u.rcu));
} }
static inline void release_probes(void *old) static inline void release_probes(struct tracepoint_func *old)
{ {
if (old) { if (old) {
struct tp_probes *tp_probes = container_of(old, struct tp_probes *tp_probes = container_of(old,
...@@ -95,15 +95,16 @@ static void debug_print_probes(struct tracepoint_entry *entry) ...@@ -95,15 +95,16 @@ static void debug_print_probes(struct tracepoint_entry *entry)
if (!tracepoint_debug || !entry->funcs) if (!tracepoint_debug || !entry->funcs)
return; return;
for (i = 0; entry->funcs[i]; i++) for (i = 0; entry->funcs[i].func; i++)
printk(KERN_DEBUG "Probe %d : %p\n", i, entry->funcs[i]); printk(KERN_DEBUG "Probe %d : %p\n", i, entry->funcs[i].func);
} }
static void * static struct tracepoint_func *
tracepoint_entry_add_probe(struct tracepoint_entry *entry, void *probe) tracepoint_entry_add_probe(struct tracepoint_entry *entry,
void *probe, void *data)
{ {
int nr_probes = 0; int nr_probes = 0;
void **old, **new; struct tracepoint_func *old, *new;
WARN_ON(!probe); WARN_ON(!probe);
...@@ -111,8 +112,9 @@ tracepoint_entry_add_probe(struct tracepoint_entry *entry, void *probe) ...@@ -111,8 +112,9 @@ tracepoint_entry_add_probe(struct tracepoint_entry *entry, void *probe)
old = entry->funcs; old = entry->funcs;
if (old) { if (old) {
/* (N -> N+1), (N != 0, 1) probes */ /* (N -> N+1), (N != 0, 1) probes */
for (nr_probes = 0; old[nr_probes]; nr_probes++) for (nr_probes = 0; old[nr_probes].func; nr_probes++)
if (old[nr_probes] == probe) if (old[nr_probes].func == probe &&
old[nr_probes].data == data)
return ERR_PTR(-EEXIST); return ERR_PTR(-EEXIST);
} }
/* + 2 : one for new probe, one for NULL func */ /* + 2 : one for new probe, one for NULL func */
...@@ -120,9 +122,10 @@ tracepoint_entry_add_probe(struct tracepoint_entry *entry, void *probe) ...@@ -120,9 +122,10 @@ tracepoint_entry_add_probe(struct tracepoint_entry *entry, void *probe)
if (new == NULL) if (new == NULL)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
if (old) if (old)
memcpy(new, old, nr_probes * sizeof(void *)); memcpy(new, old, nr_probes * sizeof(struct tracepoint_func));
new[nr_probes] = probe; new[nr_probes].func = probe;
new[nr_probes + 1] = NULL; new[nr_probes].data = data;
new[nr_probes + 1].func = NULL;
entry->refcount = nr_probes + 1; entry->refcount = nr_probes + 1;
entry->funcs = new; entry->funcs = new;
debug_print_probes(entry); debug_print_probes(entry);
...@@ -130,10 +133,11 @@ tracepoint_entry_add_probe(struct tracepoint_entry *entry, void *probe) ...@@ -130,10 +133,11 @@ tracepoint_entry_add_probe(struct tracepoint_entry *entry, void *probe)
} }
static void * static void *
tracepoint_entry_remove_probe(struct tracepoint_entry *entry, void *probe) tracepoint_entry_remove_probe(struct tracepoint_entry *entry,
void *probe, void *data)
{ {
int nr_probes = 0, nr_del = 0, i; int nr_probes = 0, nr_del = 0, i;
void **old, **new; struct tracepoint_func *old, *new;
old = entry->funcs; old = entry->funcs;
...@@ -142,8 +146,10 @@ tracepoint_entry_remove_probe(struct tracepoint_entry *entry, void *probe) ...@@ -142,8 +146,10 @@ tracepoint_entry_remove_probe(struct tracepoint_entry *entry, void *probe)
debug_print_probes(entry); debug_print_probes(entry);
/* (N -> M), (N > 1, M >= 0) probes */ /* (N -> M), (N > 1, M >= 0) probes */
for (nr_probes = 0; old[nr_probes]; nr_probes++) { for (nr_probes = 0; old[nr_probes].func; nr_probes++) {
if ((!probe || old[nr_probes] == probe)) if (!probe ||
(old[nr_probes].func == probe &&
old[nr_probes].data == data))
nr_del++; nr_del++;
} }
...@@ -160,10 +166,11 @@ tracepoint_entry_remove_probe(struct tracepoint_entry *entry, void *probe) ...@@ -160,10 +166,11 @@ tracepoint_entry_remove_probe(struct tracepoint_entry *entry, void *probe)
new = allocate_probes(nr_probes - nr_del + 1); new = allocate_probes(nr_probes - nr_del + 1);
if (new == NULL) if (new == NULL)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
for (i = 0; old[i]; i++) for (i = 0; old[i].func; i++)
if ((probe && old[i] != probe)) if (probe &&
(old[i].func != probe || old[i].data != data))
new[j++] = old[i]; new[j++] = old[i];
new[nr_probes - nr_del] = NULL; new[nr_probes - nr_del].func = NULL;
entry->refcount = nr_probes - nr_del; entry->refcount = nr_probes - nr_del;
entry->funcs = new; entry->funcs = new;
} }
...@@ -315,18 +322,19 @@ static void tracepoint_update_probes(void) ...@@ -315,18 +322,19 @@ static void tracepoint_update_probes(void)
module_update_tracepoints(); module_update_tracepoints();
} }
static void *tracepoint_add_probe(const char *name, void *probe) static struct tracepoint_func *
tracepoint_add_probe(const char *name, void *probe, void *data)
{ {
struct tracepoint_entry *entry; struct tracepoint_entry *entry;
void *old; struct tracepoint_func *old;
entry = get_tracepoint(name); entry = get_tracepoint(name);
if (!entry) { if (!entry) {
entry = add_tracepoint(name); entry = add_tracepoint(name);
if (IS_ERR(entry)) if (IS_ERR(entry))
return entry; return (struct tracepoint_func *)entry;
} }
old = tracepoint_entry_add_probe(entry, probe); old = tracepoint_entry_add_probe(entry, probe, data);
if (IS_ERR(old) && !entry->refcount) if (IS_ERR(old) && !entry->refcount)
remove_tracepoint(entry); remove_tracepoint(entry);
return old; return old;
...@@ -340,12 +348,12 @@ static void *tracepoint_add_probe(const char *name, void *probe) ...@@ -340,12 +348,12 @@ static void *tracepoint_add_probe(const char *name, void *probe)
* Returns 0 if ok, error value on error. * Returns 0 if ok, error value on error.
* The probe address must at least be aligned on the architecture pointer size. * The probe address must at least be aligned on the architecture pointer size.
*/ */
int tracepoint_probe_register(const char *name, void *probe) int tracepoint_probe_register(const char *name, void *probe, void *data)
{ {
void *old; struct tracepoint_func *old;
mutex_lock(&tracepoints_mutex); mutex_lock(&tracepoints_mutex);
old = tracepoint_add_probe(name, probe); old = tracepoint_add_probe(name, probe, data);
mutex_unlock(&tracepoints_mutex); mutex_unlock(&tracepoints_mutex);
if (IS_ERR(old)) if (IS_ERR(old))
return PTR_ERR(old); return PTR_ERR(old);
...@@ -356,15 +364,16 @@ int tracepoint_probe_register(const char *name, void *probe) ...@@ -356,15 +364,16 @@ int tracepoint_probe_register(const char *name, void *probe)
} }
EXPORT_SYMBOL_GPL(tracepoint_probe_register); EXPORT_SYMBOL_GPL(tracepoint_probe_register);
static void *tracepoint_remove_probe(const char *name, void *probe) static struct tracepoint_func *
tracepoint_remove_probe(const char *name, void *probe, void *data)
{ {
struct tracepoint_entry *entry; struct tracepoint_entry *entry;
void *old; struct tracepoint_func *old;
entry = get_tracepoint(name); entry = get_tracepoint(name);
if (!entry) if (!entry)
return ERR_PTR(-ENOENT); return ERR_PTR(-ENOENT);
old = tracepoint_entry_remove_probe(entry, probe); old = tracepoint_entry_remove_probe(entry, probe, data);
if (IS_ERR(old)) if (IS_ERR(old))
return old; return old;
if (!entry->refcount) if (!entry->refcount)
...@@ -382,12 +391,12 @@ static void *tracepoint_remove_probe(const char *name, void *probe) ...@@ -382,12 +391,12 @@ static void *tracepoint_remove_probe(const char *name, void *probe)
* itself uses stop_machine(), which insures that every preempt disabled section * itself uses stop_machine(), which insures that every preempt disabled section
* have finished. * have finished.
*/ */
int tracepoint_probe_unregister(const char *name, void *probe) int tracepoint_probe_unregister(const char *name, void *probe, void *data)
{ {
void *old; struct tracepoint_func *old;
mutex_lock(&tracepoints_mutex); mutex_lock(&tracepoints_mutex);
old = tracepoint_remove_probe(name, probe); old = tracepoint_remove_probe(name, probe, data);
mutex_unlock(&tracepoints_mutex); mutex_unlock(&tracepoints_mutex);
if (IS_ERR(old)) if (IS_ERR(old))
return PTR_ERR(old); return PTR_ERR(old);
...@@ -418,12 +427,13 @@ static void tracepoint_add_old_probes(void *old) ...@@ -418,12 +427,13 @@ static void tracepoint_add_old_probes(void *old)
* *
* caller must call tracepoint_probe_update_all() * caller must call tracepoint_probe_update_all()
*/ */
int tracepoint_probe_register_noupdate(const char *name, void *probe) int tracepoint_probe_register_noupdate(const char *name, void *probe,
void *data)
{ {
void *old; struct tracepoint_func *old;
mutex_lock(&tracepoints_mutex); mutex_lock(&tracepoints_mutex);
old = tracepoint_add_probe(name, probe); old = tracepoint_add_probe(name, probe, data);
if (IS_ERR(old)) { if (IS_ERR(old)) {
mutex_unlock(&tracepoints_mutex); mutex_unlock(&tracepoints_mutex);
return PTR_ERR(old); return PTR_ERR(old);
...@@ -441,12 +451,13 @@ EXPORT_SYMBOL_GPL(tracepoint_probe_register_noupdate); ...@@ -441,12 +451,13 @@ EXPORT_SYMBOL_GPL(tracepoint_probe_register_noupdate);
* *
* caller must call tracepoint_probe_update_all() * caller must call tracepoint_probe_update_all()
*/ */
int tracepoint_probe_unregister_noupdate(const char *name, void *probe) int tracepoint_probe_unregister_noupdate(const char *name, void *probe,
void *data)
{ {
void *old; struct tracepoint_func *old;
mutex_lock(&tracepoints_mutex); mutex_lock(&tracepoints_mutex);
old = tracepoint_remove_probe(name, probe); old = tracepoint_remove_probe(name, probe, data);
if (IS_ERR(old)) { if (IS_ERR(old)) {
mutex_unlock(&tracepoints_mutex); mutex_unlock(&tracepoints_mutex);
return PTR_ERR(old); return PTR_ERR(old);
......
...@@ -172,12 +172,12 @@ static void trace_drop_common(struct sk_buff *skb, void *location) ...@@ -172,12 +172,12 @@ static void trace_drop_common(struct sk_buff *skb, void *location)
return; return;
} }
static void trace_kfree_skb_hit(struct sk_buff *skb, void *location) static void trace_kfree_skb_hit(void *ignore, struct sk_buff *skb, void *location)
{ {
trace_drop_common(skb, location); trace_drop_common(skb, location);
} }
static void trace_napi_poll_hit(struct napi_struct *napi) static void trace_napi_poll_hit(void *ignore, struct napi_struct *napi)
{ {
struct dm_hw_stat_delta *new_stat; struct dm_hw_stat_delta *new_stat;
...@@ -225,12 +225,12 @@ static int set_all_monitor_traces(int state) ...@@ -225,12 +225,12 @@ static int set_all_monitor_traces(int state)
switch (state) { switch (state) {
case TRACE_ON: case TRACE_ON:
rc |= register_trace_kfree_skb(trace_kfree_skb_hit); rc |= register_trace_kfree_skb(trace_kfree_skb_hit, NULL);
rc |= register_trace_napi_poll(trace_napi_poll_hit); rc |= register_trace_napi_poll(trace_napi_poll_hit, NULL);
break; break;
case TRACE_OFF: case TRACE_OFF:
rc |= unregister_trace_kfree_skb(trace_kfree_skb_hit); rc |= unregister_trace_kfree_skb(trace_kfree_skb_hit, NULL);
rc |= unregister_trace_napi_poll(trace_napi_poll_hit); rc |= unregister_trace_napi_poll(trace_napi_poll_hit, NULL);
tracepoint_synchronize_unregister(); tracepoint_synchronize_unregister();
......
...@@ -7,7 +7,5 @@ ...@@ -7,7 +7,5 @@
DECLARE_TRACE(subsys_event, DECLARE_TRACE(subsys_event,
TP_PROTO(struct inode *inode, struct file *file), TP_PROTO(struct inode *inode, struct file *file),
TP_ARGS(inode, file)); TP_ARGS(inode, file));
DECLARE_TRACE(subsys_eventb, DECLARE_TRACE_NOARGS(subsys_eventb);
TP_PROTO(void),
TP_ARGS());
#endif #endif
...@@ -13,7 +13,8 @@ ...@@ -13,7 +13,8 @@
* Here the caller only guarantees locking for struct file and struct inode. * Here the caller only guarantees locking for struct file and struct inode.
* Locking must therefore be done in the probe to use the dentry. * Locking must therefore be done in the probe to use the dentry.
*/ */
static void probe_subsys_event(struct inode *inode, struct file *file) static void probe_subsys_event(void *ignore,
struct inode *inode, struct file *file)
{ {
path_get(&file->f_path); path_get(&file->f_path);
dget(file->f_path.dentry); dget(file->f_path.dentry);
...@@ -23,7 +24,7 @@ static void probe_subsys_event(struct inode *inode, struct file *file) ...@@ -23,7 +24,7 @@ static void probe_subsys_event(struct inode *inode, struct file *file)
path_put(&file->f_path); path_put(&file->f_path);
} }
static void probe_subsys_eventb(void) static void probe_subsys_eventb(void *ignore)
{ {
printk(KERN_INFO "Event B is encountered\n"); printk(KERN_INFO "Event B is encountered\n");
} }
...@@ -32,9 +33,9 @@ static int __init tp_sample_trace_init(void) ...@@ -32,9 +33,9 @@ static int __init tp_sample_trace_init(void)
{ {
int ret; int ret;
ret = register_trace_subsys_event(probe_subsys_event); ret = register_trace_subsys_event(probe_subsys_event, NULL);
WARN_ON(ret); WARN_ON(ret);
ret = register_trace_subsys_eventb(probe_subsys_eventb); ret = register_trace_subsys_eventb(probe_subsys_eventb, NULL);
WARN_ON(ret); WARN_ON(ret);
return 0; return 0;
...@@ -44,8 +45,8 @@ module_init(tp_sample_trace_init); ...@@ -44,8 +45,8 @@ module_init(tp_sample_trace_init);
static void __exit tp_sample_trace_exit(void) static void __exit tp_sample_trace_exit(void)
{ {
unregister_trace_subsys_eventb(probe_subsys_eventb); unregister_trace_subsys_eventb(probe_subsys_eventb, NULL);
unregister_trace_subsys_event(probe_subsys_event); unregister_trace_subsys_event(probe_subsys_event, NULL);
tracepoint_synchronize_unregister(); tracepoint_synchronize_unregister();
} }
......
...@@ -12,7 +12,8 @@ ...@@ -12,7 +12,8 @@
* Here the caller only guarantees locking for struct file and struct inode. * Here the caller only guarantees locking for struct file and struct inode.
* Locking must therefore be done in the probe to use the dentry. * Locking must therefore be done in the probe to use the dentry.
*/ */
static void probe_subsys_event(struct inode *inode, struct file *file) static void probe_subsys_event(void *ignore,
struct inode *inode, struct file *file)
{ {
printk(KERN_INFO "Event is encountered with inode number %lu\n", printk(KERN_INFO "Event is encountered with inode number %lu\n",
inode->i_ino); inode->i_ino);
...@@ -22,7 +23,7 @@ static int __init tp_sample_trace_init(void) ...@@ -22,7 +23,7 @@ static int __init tp_sample_trace_init(void)
{ {
int ret; int ret;
ret = register_trace_subsys_event(probe_subsys_event); ret = register_trace_subsys_event(probe_subsys_event, NULL);
WARN_ON(ret); WARN_ON(ret);
return 0; return 0;
...@@ -32,7 +33,7 @@ module_init(tp_sample_trace_init); ...@@ -32,7 +33,7 @@ module_init(tp_sample_trace_init);
static void __exit tp_sample_trace_exit(void) static void __exit tp_sample_trace_exit(void)
{ {
unregister_trace_subsys_event(probe_subsys_event); unregister_trace_subsys_event(probe_subsys_event, NULL);
tracepoint_synchronize_unregister(); tracepoint_synchronize_unregister();
} }
......
...@@ -43,6 +43,9 @@ OPTIONS ...@@ -43,6 +43,9 @@ OPTIONS
-c:: -c::
scale counter values scale counter values
-B::
print large numbers with thousands' separators according to locale
EXAMPLES EXAMPLES
-------- --------
......
...@@ -277,7 +277,7 @@ static void hist_entry__print_hits(struct hist_entry *self) ...@@ -277,7 +277,7 @@ static void hist_entry__print_hits(struct hist_entry *self)
printf("%*s: %Lu\n", BITS_PER_LONG / 2, "h->sum", h->sum); printf("%*s: %Lu\n", BITS_PER_LONG / 2, "h->sum", h->sum);
} }
static void annotate_sym(struct hist_entry *he) static int hist_entry__tty_annotate(struct hist_entry *he)
{ {
struct map *map = he->ms.map; struct map *map = he->ms.map;
struct dso *dso = map->dso; struct dso *dso = map->dso;
...@@ -288,7 +288,7 @@ static void annotate_sym(struct hist_entry *he) ...@@ -288,7 +288,7 @@ static void annotate_sym(struct hist_entry *he)
struct objdump_line *pos, *n; struct objdump_line *pos, *n;
if (hist_entry__annotate(he, &head) < 0) if (hist_entry__annotate(he, &head) < 0)
return; return -1;
if (full_paths) if (full_paths)
d_filename = filename; d_filename = filename;
...@@ -317,31 +317,60 @@ static void annotate_sym(struct hist_entry *he) ...@@ -317,31 +317,60 @@ static void annotate_sym(struct hist_entry *he)
if (print_line) if (print_line)
free_source_line(he, len); free_source_line(he, len);
return 0;
} }
static void hists__find_annotations(struct hists *self) static void hists__find_annotations(struct hists *self)
{ {
struct rb_node *nd; struct rb_node *first = rb_first(&self->entries), *nd = first;
int key = KEY_RIGHT;
for (nd = rb_first(&self->entries); nd; nd = rb_next(nd)) { while (nd) {
struct hist_entry *he = rb_entry(nd, struct hist_entry, rb_node); struct hist_entry *he = rb_entry(nd, struct hist_entry, rb_node);
struct sym_priv *priv; struct sym_priv *priv;
if (he->ms.sym == NULL) if (he->ms.sym == NULL || he->ms.map->dso->annotate_warned)
continue; goto find_next;
priv = symbol__priv(he->ms.sym); priv = symbol__priv(he->ms.sym);
if (priv->hist == NULL) if (priv->hist == NULL) {
find_next:
if (key == KEY_LEFT)
nd = rb_prev(nd);
else
nd = rb_next(nd);
continue; continue;
}
annotate_sym(he); if (use_browser) {
key = hist_entry__tui_annotate(he);
if (is_exit_key(key))
break;
switch (key) {
case KEY_RIGHT:
case '\t':
nd = rb_next(nd);
break;
case KEY_LEFT:
if (nd == first)
continue;
nd = rb_prev(nd);
default:
break;
}
} else {
hist_entry__tty_annotate(he);
nd = rb_next(nd);
/* /*
* Since we have a hist_entry per IP for the same symbol, free * Since we have a hist_entry per IP for the same
* he->ms.sym->hist to signal we already processed this symbol. * symbol, free he->ms.sym->hist to signal we already
* processed this symbol.
*/ */
free(priv->hist); free(priv->hist);
priv->hist = NULL; priv->hist = NULL;
} }
}
} }
static struct perf_event_ops event_ops = { static struct perf_event_ops event_ops = {
...@@ -416,6 +445,8 @@ int cmd_annotate(int argc, const char **argv, const char *prefix __used) ...@@ -416,6 +445,8 @@ int cmd_annotate(int argc, const char **argv, const char *prefix __used)
{ {
argc = parse_options(argc, argv, options, annotate_usage, 0); argc = parse_options(argc, argv, options, annotate_usage, 0);
setup_browser();
symbol_conf.priv_size = sizeof(struct sym_priv); symbol_conf.priv_size = sizeof(struct sym_priv);
symbol_conf.try_vmlinux_path = true; symbol_conf.try_vmlinux_path = true;
...@@ -435,8 +466,6 @@ int cmd_annotate(int argc, const char **argv, const char *prefix __used) ...@@ -435,8 +466,6 @@ int cmd_annotate(int argc, const char **argv, const char *prefix __used)
sym_hist_filter = argv[0]; sym_hist_filter = argv[0];
} }
setup_pager();
if (field_sep && *field_sep == '.') { if (field_sep && *field_sep == '.') {
pr_err("'.' is the only non valid --field-separator argument\n"); pr_err("'.' is the only non valid --field-separator argument\n");
return -1; return -1;
......
...@@ -65,8 +65,10 @@ static int parse_probe_event(const char *str) ...@@ -65,8 +65,10 @@ static int parse_probe_event(const char *str)
int ret; int ret;
pr_debug("probe-definition(%d): %s\n", params.nevents, str); pr_debug("probe-definition(%d): %s\n", params.nevents, str);
if (++params.nevents == MAX_PROBES) if (++params.nevents == MAX_PROBES) {
die("Too many probes (> %d) are specified.", MAX_PROBES); pr_err("Too many probes (> %d) were specified.", MAX_PROBES);
return -1;
}
/* Parse a perf-probe command into event */ /* Parse a perf-probe command into event */
ret = parse_perf_probe_command(str, pev); ret = parse_perf_probe_command(str, pev);
...@@ -84,7 +86,9 @@ static int parse_probe_event_argv(int argc, const char **argv) ...@@ -84,7 +86,9 @@ static int parse_probe_event_argv(int argc, const char **argv)
len = 0; len = 0;
for (i = 0; i < argc; i++) for (i = 0; i < argc; i++)
len += strlen(argv[i]) + 1; len += strlen(argv[i]) + 1;
buf = xzalloc(len + 1); buf = zalloc(len + 1);
if (buf == NULL)
return -ENOMEM;
len = 0; len = 0;
for (i = 0; i < argc; i++) for (i = 0; i < argc; i++)
len += sprintf(&buf[len], "%s ", argv[i]); len += sprintf(&buf[len], "%s ", argv[i]);
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include <unistd.h> #include <unistd.h>
#include <sched.h> #include <sched.h>
#include <sys/mman.h>
enum write_mode_t { enum write_mode_t {
WRITE_FORCE, WRITE_FORCE,
...@@ -60,13 +61,8 @@ static bool call_graph = false; ...@@ -60,13 +61,8 @@ static bool call_graph = false;
static bool inherit_stat = false; static bool inherit_stat = false;
static bool no_samples = false; static bool no_samples = false;
static bool sample_address = false; static bool sample_address = false;
static bool multiplex = false;
static int multiplex_fd = -1;
static long samples = 0; static long samples = 0;
static struct timeval last_read;
static struct timeval this_read;
static u64 bytes_written = 0; static u64 bytes_written = 0;
static struct pollfd *event_array; static struct pollfd *event_array;
...@@ -86,7 +82,7 @@ struct mmap_data { ...@@ -86,7 +82,7 @@ struct mmap_data {
unsigned int prev; unsigned int prev;
}; };
static struct mmap_data *mmap_array[MAX_NR_CPUS][MAX_COUNTERS]; static struct mmap_data mmap_array[MAX_NR_CPUS];
static unsigned long mmap_read_head(struct mmap_data *md) static unsigned long mmap_read_head(struct mmap_data *md)
{ {
...@@ -146,8 +142,6 @@ static void mmap_read(struct mmap_data *md) ...@@ -146,8 +142,6 @@ static void mmap_read(struct mmap_data *md)
void *buf; void *buf;
int diff; int diff;
gettimeofday(&this_read, NULL);
/* /*
* If we're further behind than half the buffer, there's a chance * If we're further behind than half the buffer, there's a chance
* the writer will bite our tail and mess up the samples under us. * the writer will bite our tail and mess up the samples under us.
...@@ -158,23 +152,13 @@ static void mmap_read(struct mmap_data *md) ...@@ -158,23 +152,13 @@ static void mmap_read(struct mmap_data *md)
*/ */
diff = head - old; diff = head - old;
if (diff < 0) { if (diff < 0) {
struct timeval iv; fprintf(stderr, "WARNING: failed to keep up with mmap data\n");
unsigned long msecs;
timersub(&this_read, &last_read, &iv);
msecs = iv.tv_sec*1000 + iv.tv_usec/1000;
fprintf(stderr, "WARNING: failed to keep up with mmap data."
" Last read %lu msecs ago.\n", msecs);
/* /*
* head points to a known good entry, start there. * head points to a known good entry, start there.
*/ */
old = head; old = head;
} }
last_read = this_read;
if (old != head) if (old != head)
samples++; samples++;
...@@ -380,27 +364,30 @@ static void create_counter(int counter, int cpu) ...@@ -380,27 +364,30 @@ static void create_counter(int counter, int cpu)
*/ */
if (group && group_fd == -1) if (group && group_fd == -1)
group_fd = fd[nr_cpu][counter][thread_index]; group_fd = fd[nr_cpu][counter][thread_index];
if (multiplex && multiplex_fd == -1)
multiplex_fd = fd[nr_cpu][counter][thread_index];
if (multiplex && fd[nr_cpu][counter][thread_index] != multiplex_fd) { if (counter || thread_index) {
ret = ioctl(fd[nr_cpu][counter][thread_index],
ret = ioctl(fd[nr_cpu][counter][thread_index], PERF_EVENT_IOC_SET_OUTPUT, multiplex_fd); PERF_EVENT_IOC_SET_OUTPUT,
assert(ret != -1); fd[nr_cpu][0][0]);
if (ret) {
error("failed to set output: %d (%s)\n", errno,
strerror(errno));
exit(-1);
}
} else { } else {
event_array[nr_poll].fd = fd[nr_cpu][counter][thread_index]; mmap_array[nr_cpu].counter = counter;
event_array[nr_poll].events = POLLIN; mmap_array[nr_cpu].prev = 0;
nr_poll++; mmap_array[nr_cpu].mask = mmap_pages*page_size - 1;
mmap_array[nr_cpu].base = mmap(NULL, (mmap_pages+1)*page_size,
mmap_array[nr_cpu][counter][thread_index].counter = counter;
mmap_array[nr_cpu][counter][thread_index].prev = 0;
mmap_array[nr_cpu][counter][thread_index].mask = mmap_pages*page_size - 1;
mmap_array[nr_cpu][counter][thread_index].base = mmap(NULL, (mmap_pages+1)*page_size,
PROT_READ|PROT_WRITE, MAP_SHARED, fd[nr_cpu][counter][thread_index], 0); PROT_READ|PROT_WRITE, MAP_SHARED, fd[nr_cpu][counter][thread_index], 0);
if (mmap_array[nr_cpu][counter][thread_index].base == MAP_FAILED) { if (mmap_array[nr_cpu].base == MAP_FAILED) {
error("failed to mmap with %d (%s)\n", errno, strerror(errno)); error("failed to mmap with %d (%s)\n", errno, strerror(errno));
exit(-1); exit(-1);
} }
event_array[nr_poll].fd = fd[nr_cpu][counter][thread_index];
event_array[nr_poll].events = POLLIN;
nr_poll++;
} }
if (filter != NULL) { if (filter != NULL) {
...@@ -501,16 +488,11 @@ static struct perf_event_header finished_round_event = { ...@@ -501,16 +488,11 @@ static struct perf_event_header finished_round_event = {
static void mmap_read_all(void) static void mmap_read_all(void)
{ {
int i, counter, thread; int i;
for (i = 0; i < nr_cpu; i++) { for (i = 0; i < nr_cpu; i++) {
for (counter = 0; counter < nr_counters; counter++) { if (mmap_array[i].base)
for (thread = 0; thread < thread_num; thread++) { mmap_read(&mmap_array[i]);
if (mmap_array[i][counter][thread].base)
mmap_read(&mmap_array[i][counter][thread]);
}
}
} }
if (perf_header__has_feat(&session->header, HEADER_TRACE_INFO)) if (perf_header__has_feat(&session->header, HEADER_TRACE_INFO))
...@@ -834,8 +816,6 @@ static const struct option options[] = { ...@@ -834,8 +816,6 @@ static const struct option options[] = {
"Sample addresses"), "Sample addresses"),
OPT_BOOLEAN('n', "no-samples", &no_samples, OPT_BOOLEAN('n', "no-samples", &no_samples,
"don't sample"), "don't sample"),
OPT_BOOLEAN('M', "multiplex", &multiplex,
"multiplex counter output in a single channel"),
OPT_END() OPT_END()
}; };
...@@ -887,9 +867,7 @@ int cmd_record(int argc, const char **argv, const char *prefix __used) ...@@ -887,9 +867,7 @@ int cmd_record(int argc, const char **argv, const char *prefix __used)
for (i = 0; i < MAX_NR_CPUS; i++) { for (i = 0; i < MAX_NR_CPUS; i++) {
for (j = 0; j < MAX_COUNTERS; j++) { for (j = 0; j < MAX_COUNTERS; j++) {
fd[i][j] = malloc(sizeof(int)*thread_num); fd[i][j] = malloc(sizeof(int)*thread_num);
mmap_array[i][j] = zalloc( if (!fd[i][j])
sizeof(struct mmap_data)*thread_num);
if (!fd[i][j] || !mmap_array[i][j])
return -ENOMEM; return -ENOMEM;
} }
} }
......
此差异已折叠。
...@@ -50,6 +50,7 @@ ...@@ -50,6 +50,7 @@
#include <sys/prctl.h> #include <sys/prctl.h>
#include <math.h> #include <math.h>
#include <locale.h>
static struct perf_event_attr default_attrs[] = { static struct perf_event_attr default_attrs[] = {
...@@ -80,6 +81,8 @@ static pid_t *all_tids = NULL; ...@@ -80,6 +81,8 @@ static pid_t *all_tids = NULL;
static int thread_num = 0; static int thread_num = 0;
static pid_t child_pid = -1; static pid_t child_pid = -1;
static bool null_run = false; static bool null_run = false;
static bool big_num = false;
static int *fd[MAX_NR_CPUS][MAX_COUNTERS]; static int *fd[MAX_NR_CPUS][MAX_COUNTERS];
...@@ -377,7 +380,7 @@ static void nsec_printout(int counter, double avg) ...@@ -377,7 +380,7 @@ static void nsec_printout(int counter, double avg)
{ {
double msecs = avg / 1e6; double msecs = avg / 1e6;
fprintf(stderr, " %14.6f %-24s", msecs, event_name(counter)); fprintf(stderr, " %18.6f %-24s", msecs, event_name(counter));
if (MATCH_EVENT(SOFTWARE, SW_TASK_CLOCK, counter)) { if (MATCH_EVENT(SOFTWARE, SW_TASK_CLOCK, counter)) {
fprintf(stderr, " # %10.3f CPUs ", fprintf(stderr, " # %10.3f CPUs ",
...@@ -389,7 +392,10 @@ static void abs_printout(int counter, double avg) ...@@ -389,7 +392,10 @@ static void abs_printout(int counter, double avg)
{ {
double total, ratio = 0.0; double total, ratio = 0.0;
fprintf(stderr, " %14.0f %-24s", avg, event_name(counter)); if (big_num)
fprintf(stderr, " %'18.0f %-24s", avg, event_name(counter));
else
fprintf(stderr, " %18.0f %-24s", avg, event_name(counter));
if (MATCH_EVENT(HARDWARE, HW_INSTRUCTIONS, counter)) { if (MATCH_EVENT(HARDWARE, HW_INSTRUCTIONS, counter)) {
total = avg_stats(&runtime_cycles_stats); total = avg_stats(&runtime_cycles_stats);
...@@ -426,7 +432,7 @@ static void print_counter(int counter) ...@@ -426,7 +432,7 @@ static void print_counter(int counter)
int scaled = event_scaled[counter]; int scaled = event_scaled[counter];
if (scaled == -1) { if (scaled == -1) {
fprintf(stderr, " %14s %-24s\n", fprintf(stderr, " %18s %-24s\n",
"<not counted>", event_name(counter)); "<not counted>", event_name(counter));
return; return;
} }
...@@ -477,7 +483,7 @@ static void print_stat(int argc, const char **argv) ...@@ -477,7 +483,7 @@ static void print_stat(int argc, const char **argv)
print_counter(counter); print_counter(counter);
fprintf(stderr, "\n"); fprintf(stderr, "\n");
fprintf(stderr, " %14.9f seconds time elapsed", fprintf(stderr, " %18.9f seconds time elapsed",
avg_stats(&walltime_nsecs_stats)/1e9); avg_stats(&walltime_nsecs_stats)/1e9);
if (run_count > 1) { if (run_count > 1) {
fprintf(stderr, " ( +- %7.3f%% )", fprintf(stderr, " ( +- %7.3f%% )",
...@@ -534,6 +540,8 @@ static const struct option options[] = { ...@@ -534,6 +540,8 @@ static const struct option options[] = {
"repeat command and print average + stddev (max: 100)"), "repeat command and print average + stddev (max: 100)"),
OPT_BOOLEAN('n', "null", &null_run, OPT_BOOLEAN('n', "null", &null_run,
"null run - dont start any counters"), "null run - dont start any counters"),
OPT_BOOLEAN('B', "big-num", &big_num,
"print large numbers with thousands\' separators"),
OPT_END() OPT_END()
}; };
...@@ -542,6 +550,8 @@ int cmd_stat(int argc, const char **argv, const char *prefix __used) ...@@ -542,6 +550,8 @@ int cmd_stat(int argc, const char **argv, const char *prefix __used)
int status; int status;
int i,j; int i,j;
setlocale(LC_ALL, "");
argc = parse_options(argc, argv, options, stat_usage, argc = parse_options(argc, argv, options, stat_usage,
PARSE_OPT_STOP_AT_NON_OPTION); PARSE_OPT_STOP_AT_NON_OPTION);
if (!argc && target_pid == -1 && target_tid == -1) if (!argc && target_pid == -1 && target_tid == -1)
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
...@@ -5,4 +5,6 @@ ...@@ -5,4 +5,6 @@
extern struct perf_event_ops build_id__mark_dso_hit_ops; extern struct perf_event_ops build_id__mark_dso_hit_ops;
char *dso__build_id_filename(struct dso *self, char *bf, size_t size);
#endif #endif
此差异已折叠。
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include <errno.h> #include <errno.h>
#include <math.h> #include <math.h>
#include "util.h"
#include "callchain.h" #include "callchain.h"
bool ip_callchain__valid(struct ip_callchain *chain, event_t *event) bool ip_callchain__valid(struct ip_callchain *chain, event_t *event)
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册