Skip to contentSkip to conversation

perf: Drop the obsolete profile naming for trace events

PATCH In review Frederic Weisbecker 2 participants 13 messages Mar 5, 2010 – Mar 10, 2010

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 perf: Drop the obsolete profile naming for trace events

Drop the obsolete "profile" naming used by perf for trace events. Perf can now do more than simple events counting, so generalize the API naming.

Cc Ingo Molnar <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Masami Hiramatsu <[email protected]>
Cc Jason Baron <[email protected]>
---
 include/linux/ftrace_event.h                       |   16 ++--
 include/linux/syscalls.h                           |   24 +++---
 include/trace/ftrace.h                             |   38 +++++-----
 include/trace/syscall.h                            |    8 +-
 kernel/perf_event.c                                |    4 +-
 kernel/trace/Makefile                              |    2 +-
 .../{trace_event_profile.c => trace_event_perf.c}  |   44 ++++++------
 kernel/trace/trace_events.c                        |    2 +-
 kernel/trace/trace_kprobe.c                        |   28 ++++----
 kernel/trace/trace_syscalls.c                      |   72 ++++++++++----------
 10 files changed, 119 insertions(+), 119 deletions(-)
 rename kernel/trace/{trace_event_profile.c => trace_event_perf.c} (73%)
include/linux/ftrace_event.h +8 -8
index 48b367e..7ee157d 100644
@@ -132,12 +132,12 @@ struct ftrace_event_call {
 	void			*mod;
 	void			*data;
 
-	int			profile_count;
-	int			(*profile_enable)(struct ftrace_event_call *);
-	void			(*profile_disable)(struct ftrace_event_call *);
+	int			perf_refcount;
+	int			(*perf_event_enable)(struct ftrace_event_call *);
+	void			(*perf_event_disable)(struct ftrace_event_call *);
 };
 
-#define FTRACE_MAX_PROFILE_SIZE	2048
+#define PERF_MAX_TRACE_SIZE	2048
 
 #define MAX_FILTER_PRED		32
 #define MAX_FILTER_STR_VAL	256	/* Should handle KSYM_SYMBOL_LEN */
@@ -191,17 +191,17 @@ struct perf_event;
 
 DECLARE_PER_CPU(struct pt_regs, perf_trace_regs);
 
-extern int ftrace_profile_enable(int event_id);
-extern void ftrace_profile_disable(int event_id);
+extern int perf_trace_enable(int event_id);
+extern void perf_trace_disable(int event_id);
 extern int ftrace_profile_set_filter(struct perf_event *event, int event_id,
 				     char *filter_str);
 extern void ftrace_profile_free_filter(struct perf_event *event);
 extern void *
-ftrace_perf_buf_prepare(int size, unsigned short type, int *rctxp,
+perf_trace_buf_prepare(int size, unsigned short type, int *rctxp,
 			 unsigned long *irq_flags);
 
 static inline void
-ftrace_perf_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)
 {
 	struct trace_entry *entry = raw_data;
include/linux/syscalls.h +12 -12
index feee739..eb46f5b 100644
@@ -101,18 +101,18 @@ struct perf_event_attr;
 
 #ifdef CONFIG_PERF_EVENTS
 
-#define TRACE_SYS_ENTER_PROFILE_INIT(sname)				       \
-	.profile_enable = prof_sysenter_enable,				       \
-	.profile_disable = prof_sysenter_disable,
+#define TRACE_SYS_ENTER_PERF_INIT(sname)				       \
+	.perf_event_enable = perf_sysenter_enable,			       \
+	.perf_event_disable = perf_sysenter_disable,
 
-#define TRACE_SYS_EXIT_PROFILE_INIT(sname)				       \
-	.profile_enable = prof_sysexit_enable,				       \
-	.profile_disable = prof_sysexit_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_PROFILE(sname)
-#define TRACE_SYS_ENTER_PROFILE_INIT(sname)
-#define TRACE_SYS_EXIT_PROFILE(sname)
-#define TRACE_SYS_EXIT_PROFILE_INIT(sname)
+#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
@@ -149,7 +149,7 @@ struct perf_event_attr;
 		.regfunc		= reg_event_syscall_enter,	\
 		.unregfunc		= unreg_event_syscall_enter,	\
 		.data			= (void *)&__syscall_meta_##sname,\
-		TRACE_SYS_ENTER_PROFILE_INIT(sname)			\
+		TRACE_SYS_ENTER_PERF_INIT(sname)			\
 	}
 
 #define SYSCALL_TRACE_EXIT_EVENT(sname)					\
@@ -171,7 +171,7 @@ struct perf_event_attr;
 		.regfunc		= reg_event_syscall_exit,	\
 		.unregfunc		= unreg_event_syscall_exit,	\
 		.data			= (void *)&__syscall_meta_##sname,\
-		TRACE_SYS_EXIT_PROFILE_INIT(sname)			\
+		TRACE_SYS_EXIT_PERF_INIT(sname)			\
 	}
 
 #define SYSCALL_METADATA(sname, nb)				\
include/trace/ftrace.h +19 -19
index a4fa51c..e92f037 100644
@@ -524,16 +524,16 @@ static inline int ftrace_get_offsets_##call(				\
 #undef DEFINE_EVENT
 #define DEFINE_EVENT(template, name, proto, args)			\
 									\
-static void ftrace_profile_##name(proto);				\
+static void perf_trace_##name(proto);					\
 									\
-static int ftrace_profile_enable_##name(struct ftrace_event_call *unused)\
+static int perf_trace_enable_##name(struct ftrace_event_call *unused)	\
 {									\
-	return register_trace_##name(ftrace_profile_##name);		\
+	return register_trace_##name(perf_trace_##name);		\
 }									\
 									\
-static void ftrace_profile_disable_##name(struct ftrace_event_call *unused)\
+static void perf_trace_disable_##name(struct ftrace_event_call *unused)\
 {									\
-	unregister_trace_##name(ftrace_profile_##name);			\
+	unregister_trace_##name(perf_trace_##name);			\
 }
 
 #undef DEFINE_EVENT_PRINT
@@ -629,12 +629,12 @@ static void ftrace_profile_disable_##name(struct ftrace_event_call *unused)\
 
 #ifdef CONFIG_PERF_EVENTS
 
-#define _TRACE_PROFILE_INIT(call)					\
-	.profile_enable = ftrace_profile_enable_##call,			\
-	.profile_disable = ftrace_profile_disable_##call,
+#define _TRACE_PERF_INIT(call)						\
+	.perf_event_enable = perf_trace_enable_##call,			\
+	.perf_event_disable = perf_trace_disable_##call,
 
 #else
-#define _TRACE_PROFILE_INIT(call)
+#define _TRACE_PERF_INIT(call)
 #endif /* CONFIG_PERF_EVENTS */
 
 #undef __entry
@@ -739,7 +739,7 @@ __attribute__((section("_ftrace_events"))) event_##call = {		\
 	.unregfunc		= ftrace_raw_unreg_event_##call,	\
 	.show_format		= ftrace_format_##template,		\
 	.define_fields		= ftrace_define_fields_##template,	\
-	_TRACE_PROFILE_INIT(call)					\
+	_TRACE_PERF_INIT(call)					\
 }
 
 #undef DEFINE_EVENT_PRINT
@@ -756,18 +756,18 @@ __attribute__((section("_ftrace_events"))) event_##call = {		\
 	.unregfunc		= ftrace_raw_unreg_event_##call,	\
 	.show_format		= ftrace_format_##call,			\
 	.define_fields		= ftrace_define_fields_##template,	\
-	_TRACE_PROFILE_INIT(call)					\
+	_TRACE_PERF_INIT(call)					\
 }
 
 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
 
 /*
- * Define the insertion callback to profile events
+ * Define the insertion callback to perf events
  *
  * The job is very similar to ftrace_raw_event_<call> except that we don't
  * insert in the ring buffer but in a perf counter.
  *
- * static void ftrace_profile_<call>(proto)
+ * static void ftrace_perf_<call>(proto)
  * {
  *	struct ftrace_data_offsets_<call> __maybe_unused __data_offsets;
  *	struct ftrace_event_call *event_call = &event_<call>;
@@ -846,7 +846,7 @@ __attribute__((section("_ftrace_events"))) event_##call = {		\
 #undef DECLARE_EVENT_CLASS
 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print)	\
 static void								\
-ftrace_profile_templ_##call(struct ftrace_event_call *event_call,	\
+perf_trace_templ_##call(struct ftrace_event_call *event_call,		\
 			    proto)					\
 {									\
 	struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\
@@ -863,10 +863,10 @@ ftrace_profile_templ_##call(struct ftrace_event_call *event_call,	\
 			     sizeof(u64));				\
 	__entry_size -= sizeof(u32);					\
 									\
-	if (WARN_ONCE(__entry_size > FTRACE_MAX_PROFILE_SIZE,		\
+	if (WARN_ONCE(__entry_size > PERF_MAX_TRACE_SIZE,		\
 		      "profile buffer not large enough"))		\
 		return;							\
-	entry = (struct ftrace_raw_##call *)ftrace_perf_buf_prepare(	\
+	entry = (struct ftrace_raw_##call *)perf_trace_buf_prepare(	\
 		__entry_size, event_call->id, &rctx, &irq_flags);	\
 	if (!entry)							\
 		return;							\
@@ -877,17 +877,17 @@ ftrace_profile_templ_##call(struct ftrace_event_call *event_call,	\
 	__regs = &__get_cpu_var(perf_trace_regs);			\
 	perf_save_regs(__regs, 2);					\
 									\
-	ftrace_perf_buf_submit(entry, __entry_size, rctx, __addr,	\
+	perf_trace_buf_submit(entry, __entry_size, rctx, __addr,	\
 			       __count, irq_flags, __regs);		\
 }
 
 #undef DEFINE_EVENT
 #define DEFINE_EVENT(template, call, proto, args)		\
-static void ftrace_profile_##call(proto)			\
+static void perf_trace_##call(proto)				\
 {								\
 	struct ftrace_event_call *event_call = &event_##call;	\
 								\
-	ftrace_profile_templ_##template(event_call, args);	\
+	perf_trace_templ_##template(event_call, args);		\
 }
 
 #undef DEFINE_EVENT_PRINT
include/trace/syscall.h +4 -4
index 3d463dc..ad193fa 100644
@@ -51,10 +51,10 @@ enum print_line_t print_syscall_exit(struct trace_iterator *iter, int flags);
 #endif
 
 #ifdef CONFIG_PERF_EVENTS
-int prof_sysenter_enable(struct ftrace_event_call *call);
-void prof_sysenter_disable(struct ftrace_event_call *call);
-int prof_sysexit_enable(struct ftrace_event_call *call);
-void prof_sysexit_disable(struct ftrace_event_call *call);
+int perf_sysenter_enable(struct ftrace_event_call *call);
+void perf_sysenter_disable(struct ftrace_event_call *call);
+int perf_sysexit_enable(struct ftrace_event_call *call);
+void perf_sysexit_disable(struct ftrace_event_call *call);
 #endif
 
 #endif /* _TRACE_SYSCALL_H */
kernel/perf_event.c +2 -2
index 763a482..4fa24a5 100644
@@ -4370,7 +4370,7 @@ static int perf_tp_event_match(struct perf_event *event,
 
 static void tp_perf_event_destroy(struct perf_event *event)
 {
-	ftrace_profile_disable(event->attr.config);
+	perf_trace_disable(event->attr.config);
 }
 
 static const struct pmu *tp_perf_event_init(struct perf_event *event)
@@ -4384,7 +4384,7 @@ static const struct pmu *tp_perf_event_init(struct perf_event *event)
 			!capable(CAP_SYS_ADMIN))
 		return ERR_PTR(-EPERM);
 
-	if (ftrace_profile_enable(event->attr.config))
+	if (perf_trace_enable(event->attr.config))
 		return NULL;
 
 	event->destroy = tp_perf_event_destroy;
kernel/trace/Makefile +1 -1
index d00c6fe..78edc64 100644
@@ -52,7 +52,7 @@ obj-$(CONFIG_EVENT_TRACING) += trace_events.o
 obj-$(CONFIG_EVENT_TRACING) += trace_export.o
 obj-$(CONFIG_FTRACE_SYSCALLS) += trace_syscalls.o
 ifeq ($(CONFIG_PERF_EVENTS),y)
-obj-$(CONFIG_EVENT_TRACING) += trace_event_profile.o
+obj-$(CONFIG_EVENT_TRACING) += trace_event_perf.o
 endif
 obj-$(CONFIG_EVENT_TRACING) += trace_events_filter.o
 obj-$(CONFIG_KPROBE_EVENT) += trace_kprobe.o
kernel/trace/trace_event_perf.c renamed from kernel/trace/trace_event_profile.c +22 -22

124 lines not on this page · raw message

kernel/trace/trace_events.c +1 -1
index 189b09b..27296c7 100644
@@ -931,7 +931,7 @@ event_create_dir(struct ftrace_event_call *call, struct dentry *d_events,
 		trace_create_file("enable", 0644, call->dir, call,
 				  enable);
 
-	if (call->id && call->profile_enable)
+	if (call->id && call->perf_event_enable)
 		trace_create_file("id", 0444, call->dir, call,
 		 		  id);
 
kernel/trace/trace_kprobe.c +14 -14
index 73e0526..41ef5fa 100644
@@ -1234,7 +1234,7 @@ static int kretprobe_event_show_format(struct ftrace_event_call *call,
 #ifdef CONFIG_PERF_EVENTS
 
 /* Kprobe profile handler */
-static __kprobes void kprobe_profile_func(struct kprobe *kp,
+static __kprobes void kprobe_perf_func(struct kprobe *kp,
 					 struct pt_regs *regs)
 {
 	struct trace_probe *tp = container_of(kp, struct trace_probe, rp.kp);
@@ -1247,11 +1247,11 @@ static __kprobes void kprobe_profile_func(struct kprobe *kp,
 	__size = SIZEOF_KPROBE_TRACE_ENTRY(tp->nr_args);
 	size = ALIGN(__size + sizeof(u32), sizeof(u64));
 	size -= sizeof(u32);
-	if (WARN_ONCE(size > FTRACE_MAX_PROFILE_SIZE,
+	if (WARN_ONCE(size > PERF_MAX_TRACE_SIZE,
 		     "profile buffer not large enough"))
 		return;
 
-	entry = ftrace_perf_buf_prepare(size, call->id, &rctx, &irq_flags);
+	entry = perf_trace_buf_prepare(size, call->id, &rctx, &irq_flags);
 	if (!entry)
 		return;
 
@@ -1260,11 +1260,11 @@ static __kprobes void kprobe_profile_func(struct kprobe *kp,
 	for (i = 0; i < tp->nr_args; i++)
 		entry->args[i] = call_fetch(&tp->args[i].fetch, regs);
 
-	ftrace_perf_buf_submit(entry, size, rctx, entry->ip, 1, irq_flags, regs);
+	perf_trace_buf_submit(entry, size, rctx, entry->ip, 1, irq_flags, regs);
 }
 
 /* Kretprobe profile handler */
-static __kprobes void kretprobe_profile_func(struct kretprobe_instance *ri,
+static __kprobes void kretprobe_perf_func(struct kretprobe_instance *ri,
 					    struct pt_regs *regs)
 {
 	struct trace_probe *tp = container_of(ri->rp, struct trace_probe, rp);
@@ -1277,11 +1277,11 @@ static __kprobes void kretprobe_profile_func(struct kretprobe_instance *ri,
 	__size = SIZEOF_KRETPROBE_TRACE_ENTRY(tp->nr_args);
 	size = ALIGN(__size + sizeof(u32), sizeof(u64));
 	size -= sizeof(u32);
-	if (WARN_ONCE(size > FTRACE_MAX_PROFILE_SIZE,
+	if (WARN_ONCE(size > PERF_MAX_TRACE_SIZE,
 		     "profile buffer not large enough"))
 		return;
 
-	entry = ftrace_perf_buf_prepare(size, call->id, &rctx, &irq_flags);
+	entry = perf_trace_buf_prepare(size, call->id, &rctx, &irq_flags);
 	if (!entry)
 		return;
 
@@ -1291,11 +1291,11 @@ static __kprobes void kretprobe_profile_func(struct kretprobe_instance *ri,
 	for (i = 0; i < tp->nr_args; i++)
 		entry->args[i] = call_fetch(&tp->args[i].fetch, regs);
 
-	ftrace_perf_buf_submit(entry, size, rctx, entry->ret_ip, 1,
+	perf_trace_buf_submit(entry, size, rctx, entry->ret_ip, 1,
 			       irq_flags, regs);
 }
 
-static int probe_profile_enable(struct ftrace_event_call *call)
+static int probe_perf_enable(struct ftrace_event_call *call)
 {
 	struct trace_probe *tp = (struct trace_probe *)call->data;
 
@@ -1307,7 +1307,7 @@ static int probe_profile_enable(struct ftrace_event_call *call)
 		return enable_kprobe(&tp->rp.kp);
 }
 
-static void probe_profile_disable(struct ftrace_event_call *call)
+static void probe_perf_disable(struct ftrace_event_call *call)
 {
 	struct trace_probe *tp = (struct trace_probe *)call->data;
 
@@ -1332,7 +1332,7 @@ int kprobe_dispatcher(struct kprobe *kp, struct pt_regs *regs)
 		kprobe_trace_func(kp, regs);
 #ifdef CONFIG_PERF_EVENTS
 	if (tp->flags & TP_FLAG_PROFILE)
-		kprobe_profile_func(kp, regs);
+		kprobe_perf_func(kp, regs);
 #endif
 	return 0;	/* We don't tweek kernel, so just return 0 */
 }
@@ -1346,7 +1346,7 @@ int kretprobe_dispatcher(struct kretprobe_instance *ri, struct pt_regs *regs)
 		kretprobe_trace_func(ri, regs);
 #ifdef CONFIG_PERF_EVENTS
 	if (tp->flags & TP_FLAG_PROFILE)
-		kretprobe_profile_func(ri, regs);
+		kretprobe_perf_func(ri, regs);
 #endif
 	return 0;	/* We don't tweek kernel, so just return 0 */
 }
@@ -1377,8 +1377,8 @@ static int register_probe_event(struct trace_probe *tp)
 	call->unregfunc = probe_event_disable;
 
 #ifdef CONFIG_PERF_EVENTS
-	call->profile_enable = probe_profile_enable;
-	call->profile_disable = probe_profile_disable;
+	call->perf_event_enable = probe_perf_enable;
+	call->perf_event_disable = probe_perf_disable;
 #endif
 	call->data = tp;
 	ret = trace_add_event_call(call);
kernel/trace/trace_syscalls.c +36 -36

168 lines not on this page · raw message

Signature · 1 line
1.6.2.3
#1 lore raw

PATCH 2/2 perf: Walk through the relevant events only

Each time a trace event triggers, we walk through the entire list of events from the active contexts to find the perf events that match the current one.

This is wasteful. To solve this, we maintain a per cpu list of the active perf events for each running trace events and we directly commit to these.

Cc Ingo Molnar <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Masami Hiramatsu <[email protected]>
Cc Jason Baron <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
---
 include/linux/ftrace_event.h    |   15 ++++++----
 include/linux/perf_event.h      |    9 +++++-
 include/trace/ftrace.h          |    4 +-
 kernel/perf_event.c             |   58 ++++++++++++++++++++++-----------------
 kernel/trace/trace_event_perf.c |   52 +++++++++++++++++++++++++++++++---
 kernel/trace/trace_kprobe.c     |    7 +++--
 kernel/trace/trace_syscalls.c   |    9 +++++-
 7 files changed, 109 insertions(+), 45 deletions(-)
include/linux/ftrace_event.h +9 -6
index 7ee157d..b39e8d5 100644
@@ -132,6 +132,7 @@ struct ftrace_event_call {
 	void			*mod;
 	void			*data;
 
+	struct list_head	__percpu *perf_list;
 	int			perf_refcount;
 	int			(*perf_event_enable)(struct ftrace_event_call *);
 	void			(*perf_event_disable)(struct ftrace_event_call *);
@@ -191,7 +192,7 @@ struct perf_event;
 
 DECLARE_PER_CPU(struct pt_regs, perf_trace_regs);
 
-extern int perf_trace_enable(int event_id);
+extern int perf_trace_enable(int event_id, struct perf_event *perf_event);
 extern void perf_trace_disable(int event_id);
 extern int ftrace_profile_set_filter(struct perf_event *event, int event_id,
 				     char *filter_str);
@@ -201,15 +202,17 @@ perf_trace_buf_prepare(int size, unsigned short type, int *rctxp,
 			 unsigned long *irq_flags);
 
 static inline void
-perf_trace_buf_submit(void *raw_data, int size, int rctx, u64 addr,
-		       u64 count, unsigned long irq_flags, struct pt_regs *regs)
+perf_trace_buf_submit(struct ftrace_event_call *event, void *raw_data, int size,
+		      int rctx, u64 addr, u64 count, unsigned long irq_flags,
+		      struct pt_regs *regs)
 {
-	struct trace_entry *entry = raw_data;
-
-	perf_tp_event(entry->type, addr, count, raw_data, size, regs);
+	perf_tp_event(event, addr, count, raw_data, size, regs);
 	perf_swevent_put_recursion_context(rctx);
 	local_irq_restore(irq_flags);
 }
+
+extern int perf_trace_sched_in(struct perf_event *event);
+extern void perf_trace_sched_out(struct perf_event *event);
 #endif
 
 #endif /* _LINUX_FTRACE_EVENT_H */
include/linux/perf_event.h +7 -2
index e35ad6f..8a9e38f 100644
@@ -490,6 +490,8 @@ struct hw_perf_event {
 #ifdef CONFIG_HAVE_HW_BREAKPOINT
 		/* breakpoint */
 		struct arch_hw_breakpoint	info;
+		/* tracepoint */
+		struct ftrace_event_call	*trace_event;
 #endif
 	};
 	atomic64_t			prev_count;
@@ -578,6 +580,7 @@ struct perf_event {
 	struct list_head		group_entry;
 	struct list_head		event_entry;
 	struct list_head		sibling_list;
+	struct list_head		trace_list;
 	int				nr_siblings;
 	int				group_flags;
 	struct perf_event		*group_leader;
@@ -897,8 +900,8 @@ extern int sysctl_perf_event_mlock;
 extern int sysctl_perf_event_sample_rate;
 
 extern void perf_event_init(void);
-extern void perf_tp_event(int event_id, u64 addr, u64 count, void *record,
-			  int entry_size, struct pt_regs *regs);
+extern void perf_tp_event(struct ftrace_event_call *fevent, u64 addr, u64 count,
+			  void *record, int entry_size, struct pt_regs *regs);
 extern void perf_bp_event(struct perf_event *event, void *data);
 
 #ifndef perf_misc_flags
@@ -917,6 +920,8 @@ extern int perf_swevent_get_recursion_context(void);
 extern void perf_swevent_put_recursion_context(int rctx);
 extern void perf_event_enable(struct perf_event *event);
 extern void perf_event_disable(struct perf_event *event);
+extern int perf_swevent_enable(struct perf_event *event);
+extern void perf_swevent_disable(struct perf_event *event);
 #else
 static inline void
 perf_event_task_sched_in(struct task_struct *task)			{ }
include/trace/ftrace.h +2 -2
index e92f037..dbd5e1f 100644
@@ -877,8 +877,8 @@ perf_trace_templ_##call(struct ftrace_event_call *event_call,		\
 	__regs = &__get_cpu_var(perf_trace_regs);			\
 	perf_save_regs(__regs, 2);					\
 									\
-	perf_trace_buf_submit(entry, __entry_size, rctx, __addr,	\
-			       __count, irq_flags, __regs);		\
+	perf_trace_buf_submit(event_call, entry, __entry_size, rctx,	\
+			      __addr, __count, irq_flags, __regs);	\
 }
 
 #undef DEFINE_EVENT
kernel/perf_event.c +33 -25

114 lines not on this page · raw message

kernel/trace/trace_event_perf.c +47 -5

90 lines not on this page · raw message

kernel/trace/trace_kprobe.c +4 -3
index 41ef5fa..1184f48 100644
@@ -1260,7 +1260,8 @@ static __kprobes void kprobe_perf_func(struct kprobe *kp,
 	for (i = 0; i < tp->nr_args; i++)
 		entry->args[i] = call_fetch(&tp->args[i].fetch, regs);
 
-	perf_trace_buf_submit(entry, size, rctx, entry->ip, 1, irq_flags, regs);
+	perf_trace_buf_submit(call, entry, size, rctx, entry->ip, 1,
+			      irq_flags, regs);
 }
 
 /* Kretprobe profile handler */
@@ -1291,8 +1292,8 @@ static __kprobes void kretprobe_perf_func(struct kretprobe_instance *ri,
 	for (i = 0; i < tp->nr_args; i++)
 		entry->args[i] = call_fetch(&tp->args[i].fetch, regs);
 
-	perf_trace_buf_submit(entry, size, rctx, entry->ret_ip, 1,
-			       irq_flags, regs);
+	perf_trace_buf_submit(call, entry, size, rctx, entry->ret_ip, 1,
+			      irq_flags, regs);
 }
 
 static int probe_perf_enable(struct ftrace_event_call *call)
kernel/trace/trace_syscalls.c +7 -2
index 99cc45f..ed7d175 100644
@@ -431,6 +431,7 @@ static int sys_perf_refcount_exit;
 static void perf_syscall_enter(struct pt_regs *regs, long id)
 {
 	struct syscall_metadata *sys_data;
+	struct ftrace_event_call *event;
 	struct syscall_trace_enter *rec;
 	unsigned long flags;
 	int syscall_nr;
@@ -462,7 +463,8 @@ static void perf_syscall_enter(struct pt_regs *regs, long id)
 	rec->nr = syscall_nr;
 	syscall_get_arguments(current, regs, 0, sys_data->nb_args,
 			       (unsigned long *)&rec->args);
-	perf_trace_buf_submit(rec, size, rctx, 0, 1, flags, regs);
+	event = sys_data->enter_event;
+	perf_trace_buf_submit(event, rec, size, rctx, 0, 1, flags, regs);
 }
 
 int perf_sysenter_enable(struct ftrace_event_call *call)
@@ -503,6 +505,7 @@ void perf_sysenter_disable(struct ftrace_event_call *call)
 static void perf_syscall_exit(struct pt_regs *regs, long ret)
 {
 	struct syscall_metadata *sys_data;
+	struct ftrace_event_call *event;
 	struct syscall_trace_exit *rec;
 	unsigned long flags;
 	int syscall_nr;
@@ -537,7 +540,9 @@ static void perf_syscall_exit(struct pt_regs *regs, long ret)
 	rec->nr = syscall_nr;
 	rec->ret = syscall_get_return_value(current, regs);
 
-	perf_trace_buf_submit(rec, size, rctx, 0, 1, flags, regs);
+	event = sys_data->exit_event;
+
+	perf_trace_buf_submit(event, rec, size, rctx, 0, 1, flags, regs);
 }
 
 int perf_sysexit_enable(struct ftrace_event_call *call)
Signature · 1 line
1.6.2.3
maintainer
#2 lore raw

Re: [PATCH 2/2] perf: Walk through the relevant events only

Quoted 7 lines · Frederic Weisbecker

Each time a trace event triggers, we walk through the entire list of events from the active contexts to find the perf events that match the current one.

This is wasteful. To solve this, we maintain a per cpu list of the active perf events for each running trace events and we directly commit to these.

Right, so this seems a little trace specific. I once thought about using a hash table to do this for all software events. It also keeps it all nicely inside perf_event.[ch].

#3 lore raw

Re: [PATCH 2/2] perf: Walk through the relevant events only

Quoted 5 lines · Peter Zijlstra
Quoted 4 lines · Frederic Weisbecker

Each time a trace event triggers, we walk through the entire list of events from the active contexts to find the perf events that match the current one.

Quoted 7 lines
Quoted 3 lines

This is wasteful. To solve this, we maintain a per cpu list of the active perf events for each running trace events and we directly commit to these.

Right, so this seems a little trace specific. I once thought about using a hash table to do this for all software events. It also keeps it all nicely inside perf_event.[ch].

Right. We could have a per cpu type:event_id based hlist that would cover trace events and other software events.

That would do the trick more generically wrt perf.

Now isn't the problem more in the fact that most of the swevents should be tracepoints?

This is the case for most of them. Only PERF_COUNT_SW_CPU_CLOCK and PERF_COUNT_SW_TASK_CLOCK seem to be the exception, and they manage their own path by calling perf_event_overflow() directly.

And as you guess, turning them into tracepoints would benefit to everyone. We'll have interesting trace events in fault paths, we won't have zillions of hooks in the same place (in the context switch, we have the usual tracepoint plus the perf call). And eventually the off-case is better optimized, and further optimizations there (jmp/nop patching/whatever) will propagate to all tracepoint users.

Finally, we would have only one path to maintain for the swevents.

maintainer
#4 lore raw

Re: [PATCH 2/2] perf: Walk through the relevant events only

Quoted 3 lines · Frederic Weisbecker

Now isn't the problem more in the fact that most of the swevents should be tracepoints?

No, different interface, and I don't want to require TRACE=y, I already utterly hate that x86 requires PERF=y.

#5 lore raw

Re: [PATCH 2/2] perf: Walk through the relevant events only

Quoted 8 lines · Peter Zijlstra
Quoted 3 lines · Frederic Weisbecker

Now isn't the problem more in the fact that most of the swevents should be tracepoints?

No, different interface, and I don't want to require TRACE=y, I already utterly hate that x86 requires PERF=y.

This could be reduced to the strict minimum, say CONFIG_TRACEPOINT and some code around just to support the event ids.

Software events could be made optionals too.

I just don't like this multiplication of probe points of different natures in a single point. That's wasteful.

Quoted 2 lines

I already
utterly hate that x86 requires PERF=y.

Me too, and it's my bad, so me double too. Sometimes I think we should make BREAKPOINTs optional, default y. I just don't know if something like this that has always been builtin can be made optional.

maintainer
#6 lore raw

Re: [PATCH 2/2] perf: Walk through the relevant events only

Quoted 6 lines · Frederic Weisbecker
Quoted 5 lines · Peter Zijlstra
Quoted 3 lines · Frederic Weisbecker

Now isn't the problem more in the fact that most of the swevents should be tracepoints?

Quoted 6 lines
Quoted 3 lines

No, different interface, and I don't want to require TRACE=y, I already utterly hate that x86 requires PERF=y.

This could be reduced to the strict minimum, say CONFIG_TRACEPOINT and some code around just to support the event ids.

Can't, software events already are an ABI so we'll have to support that forever, but sure you can make something that reduces to the current software event callback on TRACE=n and maps to the right software event id when TRACE=y.

Quoted 1 line

Software events could be made optionals too.

Sure, but they're nowhere near as much code as tracepoints.

Quoted 8 lines
Quoted 2 lines

I already
utterly hate that x86 requires PERF=y.

Me too, and it's my bad, so me double too. Sometimes I think we should make BREAKPOINTs optional, default y. I just don't know if something like this that has always been builtin can be made optional.

Simply for build testing that would be useful, we could make it an embedded switch.

#7 lore raw

Re: [PATCH 2/2] perf: Walk through the relevant events only

Quoted 11 lines · Peter Zijlstra
Quoted 10 lines · Frederic Weisbecker
Quoted 8 lines · Peter Zijlstra
Quoted 3 lines · Frederic Weisbecker

Now isn't the problem more in the fact that most of the swevents should be tracepoints?

No, different interface, and I don't want to require TRACE=y, I already utterly hate that x86 requires PERF=y.

Quoted 7 lines
Quoted 2 lines

This could be reduced to the strict minimum, say CONFIG_TRACEPOINT and some code around just to support the event ids.

Can't, software events already are an ABI so we'll have to support that forever, but sure you can make something that reduces to the current software event callback on TRACE=n and maps to the right software event id when TRACE=y.

That looks feasible. I may try something like that.

Quoted 4 lines
Quoted 2 lines

Software events could be made optionals too.

Sure, but they're nowhere near as much code as tracepoints.

Yeah but they have the overhead of an off case to handle, something that can be turned off if we have only perf for breakpoints.

Quoted 5 lines
Quoted 5 lines
Quoted 3 lines

I already
utterly hate that x86 requires PERF=y.

Quoted 7 lines
Quoted 4 lines

Me too, and it's my bad, so me double too. Sometimes I think we should make BREAKPOINTs optional, default y. I just don't know if something like this that has always been builtin can be made optional.

Simply for build testing that would be useful, we could make it an embedded switch.

Agreed.

Ok, I'll work toward an hlist version for the initial topic. Thanks.

#8 lore raw

RFC PATCH 1/1 perf: Store relevant events in a hlist

In reply to Peter Zijlstra
Quoted 5 lines · Peter Zijlstra
Quoted 4 lines · Frederic Weisbecker

Each time a trace event triggers, we walk through the entire list of events from the active contexts to find the perf events that match the current one.

Quoted 7 lines
Quoted 3 lines

This is wasteful. To solve this, we maintain a per cpu list of the active perf events for each running trace events and we directly commit to these.

Right, so this seems a little trace specific. I once thought about using a hash table to do this for all software events. It also keeps it all nicely inside perf_event.[ch].

What do you think about this version?
It builds but crashes on runtime and doesn't handle cpu hotplug yet. Before spending more time in debugging/fixing, I'd like to know your opinion about the general architecture.

Thanks.

---

Quoted 1 line

From c389b296a87bd38cfd28da3124508eb1e5a5d553 Mon Sep 17 00:00:00 2001

From: Frederic Weisbecker <[email protected]>
Date: Mon, 8 Mar 2010 19:04:02 +0100
Subject: [PATCH] perf: Store relevant events in a hlist

When a software/tracepoint event triggers, we walk through the entire current cpu and task context's events lists to retrieve those that are concerned.

This is wasteful. This patch proposes a hashlist to walk through the relevant events only. The hash is calculated using the id of the event (could be further optimized using the type of the event too). Each hash map a list of distinct type:id that match the hash. To these type:id nodes, we affect a list of the active events matching the type:id.

-----------------------
Hash 1 | Hash 2 | ....
----------------------
|
swevent type:id node

  |       |
  |       ------- event 1 ---- event 2 ---- ....
  |
 swevent type:id node
          |
          --------[...]

The hashlist is per cpu (attached to perf_cpu_context) and the events in the lists gather those that are active in the cpu and task context. No more per events checks are needed to guess if the events are "counting" or "matching".

---
 include/linux/perf_event.h |   12 ++
 kernel/perf_event.c        |  294 ++++++++++++++++++++++++++++++++++---------
 2 files changed, 244 insertions(+), 62 deletions(-)
include/linux/perf_event.h +12 -0
index c859bee..bdd9794 100644
@@ -578,6 +578,7 @@ struct perf_event {
 	struct list_head		group_entry;
 	struct list_head		event_entry;
 	struct list_head		sibling_list;
+	struct list_head		swevent_list;
 	int				nr_siblings;
 	int				group_flags;
 	struct perf_event		*group_leader;
@@ -716,6 +717,14 @@ struct perf_event_context {
 	struct rcu_head			rcu_head;
 };
 
+#define PERF_SW_HLIST_BITS	10		/* 1024 entries */
+#define PERF_SW_HLIST_SIZE	1 << PERF_SW_HLIST_BITS
+
+struct swevents_hlist {
+	struct rcu_head			rcu_head;
+	struct hlist_head		hlist[PERF_SW_HLIST_SIZE];
+};
+
 /**
  * struct perf_event_cpu_context - per cpu event context structure
  */
@@ -732,6 +741,9 @@ struct perf_cpu_context {
 	 * task, softirq, irq, nmi context
 	 */
 	int				recursion[4];
+	struct swevents_hlist		*swevents_hlist;
+	struct mutex			hlist_mutex;
+	struct kref			hlist_refcount;
 };
 
 struct perf_output_handle {
kernel/perf_event.c +232 -62

372 lines not on this page · raw message

Signature · 1 line
1.6.2.3
maintainer
#9 lore raw

Re: [RFC PATCH] perf: Store relevant events in a hlist

Quoted 51 lines · Frederic Weisbecker
Quoted 5 lines · Peter Zijlstra
Quoted 4 lines · Frederic Weisbecker

Each time a trace event triggers, we walk through the entire list of events from the active contexts to find the perf events that match the current one.

Quoted 7 lines
Quoted 3 lines

This is wasteful. To solve this, we maintain a per cpu list of the active perf events for each running trace events and we directly commit to these.

Right, so this seems a little trace specific. I once thought about using a hash table to do this for all software events. It also keeps it all nicely inside perf_event.[ch].

What do you think about this version?
It builds but crashes on runtime and doesn't handle cpu hotplug yet. Before spending more time in debugging/fixing, I'd like to know your opinion about the general architecture.

Thanks.

---
From c389b296a87bd38cfd28da3124508eb1e5a5d553 Mon Sep 17 00:00:00 2001
From: Frederic Weisbecker <[email protected]>
Date: Mon, 8 Mar 2010 19:04:02 +0100
Subject: [PATCH] perf: Store relevant events in a hlist

When a software/tracepoint event triggers, we walk through the entire current cpu and task context's events lists to retrieve those that are concerned.

This is wasteful. This patch proposes a hashlist to walk through the relevant events only. The hash is calculated using the id of the event (could be further optimized using the type of the event too). Each hash map a list of distinct type:id that match the hash. To these type:id nodes, we affect a list of the active events matching the type:id.

-----------------------
Hash 1 | Hash 2 | ....
----------------------
|
swevent type:id node

  |       |
  |       ------- event 1 ---- event 2 ---- ....
  |
 swevent type:id node
          |
          --------[...]
Quoted 4 lines

The hashlist is per cpu (attached to perf_cpu_context) and the events in the lists gather those that are active in the cpu and task context. No more per events checks are needed to guess if the events are "counting" or "matching".

I'm not quite sure why you need the node thing, you already have a hash-bucket to iterate, simply stick all events into the one bucket and walk through it with a filter and process all events that match.

As to all those for_each_online_cpu() thingies, it might make sense to also have a global hash-table for events active on all cpus,... hmm was that the reason for the node thing, one event cannot be in multiple buckets?

#10 lore raw

Re: [RFC PATCH] perf: Store relevant events in a hlist

Quoted 3 lines · Peter Zijlstra

I'm not quite sure why you need the node thing, you already have a hash-bucket to iterate, simply stick all events into the one bucket and walk through it with a filter and process all events that match.

This inter level of indirection was one of my heaviest hesitations. In case we have a hash collision, I just wanted to ensure we keep an amortized O(n) in any case, that at the cost of this level of indirection. Plus that removed the config:id check in every events, as the check is made only once.

That said I guess we can indeed remove that and have the events directly in the hash bucket. Assuming we deal well to avoid collisions, it should be fine.

Quoted 4 lines

As to all those for_each_online_cpu() thingies, it might make sense to also have a global hash-table for events active on all cpus,... hmm was that the reason for the node thing, one event cannot be in multiple buckets?

There are several reasons I've made it per cpu.
Assuming we have a global hash table for wide events, it means we'll have some cache dance each time an event is disabled/enabled (which is quite often as wide events are per task, even worst if the initial task has numerous threads that have this event duplicated). Also, as wide events mean per task, the event will always be active in one cpu at a time, it would be wasteful to check it on other cpus.

maintainer
#11 lore raw

Re: [RFC PATCH] perf: Store relevant events in a hlist

Quoted 12 lines · Frederic Weisbecker
Quoted 3 lines · Peter Zijlstra

I'm not quite sure why you need the node thing, you already have a hash-bucket to iterate, simply stick all events into the one bucket and walk through it with a filter and process all events that match.

This inter level of indirection was one of my heaviest hesitations. In case we have a hash collision, I just wanted to ensure we keep an amortized O(n) in any case, that at the cost of this level of indirection. Plus that removed the config:id check in every events, as the check is made only once.

Quoted 3 lines

That said I guess we can indeed remove that and have the events directly in the hash bucket. Assuming we deal well to avoid collisions, it should be fine.

Right, lets start simple and go from there.

Quoted 6 lines
Quoted 4 lines

As to all those for_each_online_cpu() thingies, it might make sense to also have a global hash-table for events active on all cpus,... hmm was that the reason for the node thing, one event cannot be in multiple buckets?

Quoted 7 lines

There are several reasons I've made it per cpu.
Assuming we have a global hash table for wide events, it means we'll have some cache dance each time an event is disabled/enabled (which is quite often as wide events are per task, even worst if the initial task has numerous threads that have this event duplicated). Also, as wide events mean per task, the event will always be active in one cpu at a time, it would be wasteful to check it on other cpus.

Thing is, most events generated by perf are per cpu, even the per task ones, if they are machine wide the hash table bounces aren't the biggest problem.

But yeah..

#12 lore raw

Re: [RFC PATCH] perf: Store relevant events in a hlist

Quoted 13 lines · Peter Zijlstra
Quoted 12 lines · Frederic Weisbecker
Quoted 3 lines · Peter Zijlstra

I'm not quite sure why you need the node thing, you already have a hash-bucket to iterate, simply stick all events into the one bucket and walk through it with a filter and process all events that match.

This inter level of indirection was one of my heaviest hesitations. In case we have a hash collision, I just wanted to ensure we keep an amortized O(n) in any case, that at the cost of this level of indirection. Plus that removed the config:id check in every events, as the check is made only once.

Quoted 5 lines
Quoted 3 lines

That said I guess we can indeed remove that and have the events directly in the hash bucket. Assuming we deal well to avoid collisions, it should be fine.

Right, lets start simple and go from there.

Agreed.

Quoted 14 lines
Quoted 6 lines
Quoted 4 lines

As to all those for_each_online_cpu() thingies, it might make sense to also have a global hash-table for events active on all cpus,... hmm was that the reason for the node thing, one event cannot be in multiple buckets?

Quoted 7 lines

There are several reasons I've made it per cpu.
Assuming we have a global hash table for wide events, it means we'll have some cache dance each time an event is disabled/enabled (which is quite often as wide events are per task, even worst if the initial task has numerous threads that have this event duplicated). Also, as wide events mean per task, the event will always be active in one cpu at a time, it would be wasteful to check it on other cpus.

Quoted 3 lines

Thing is, most events generated by perf are per cpu, even the per task ones, if they are machine wide the hash table bounces aren't the biggest problem.

Indeed. But it also means a global hlist is going to be wasteful as we would double walk for each per task events.

It is also uninteresting if people use wide per task event for the bouncing problems we talked about.

Plus I guess we don't want to maintain a per cpu hlist and a global one.

I understand you worries about complexity but this is a true win in any case.

Thanks.