Skip to contentSkip to conversation

perf: Carve out callchain functionality

PATCH In review Frederic Weisbecker 3 participants 3 messages Oct 16, 2011 – Nov 18, 2011 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf: Carve out callchain functionality

From: Borislav Petkov <[email protected]>

Split the callchain code from the perf events core into a new kernel/events/callchain.c file.

This simplifies a bit the big core.c

Cc Ingo Molnar <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Stephane Eranian <[email protected]>
[keep ctx recursion handling inline and use internal headers]
---
 kernel/events/Makefile    |    2 +-
 kernel/events/callchain.c |  191 +++++++++++++++++++++++++++++++++++++++++
 kernel/events/core.c      |  209 ---------------------------------------------
 kernel/events/internal.h  |   39 ++++++++-
 4 files changed, 230 insertions(+), 211 deletions(-)
 create mode 100644 kernel/events/callchain.c
kernel/events/Makefile +1 -1
index 89e5e8a..22d901f 100644
@@ -2,5 +2,5 @@ ifdef CONFIG_FUNCTION_TRACER
 CFLAGS_REMOVE_core.o = -pg
 endif
 
-obj-y := core.o ring_buffer.o
+obj-y := core.o ring_buffer.o callchain.o
 obj-$(CONFIG_HAVE_HW_BREAKPOINT) += hw_breakpoint.o
kernel/events/callchain.c new file +191 -0

191 lines not on this page · raw message

kernel/events/core.c +0 -209

215 lines not on this page · raw message

kernel/events/internal.h +38 -1
index 09097dd..be4a43f 100644
@@ -1,6 +1,10 @@
 #ifndef _KERNEL_EVENTS_INTERNAL_H
 #define _KERNEL_EVENTS_INTERNAL_H
 
+#include <linux/hardirq.h>
+
+/* Buffer handling */
+
 #define RING_BUFFER_WRITABLE		0x01
 
 struct ring_buffer {
@@ -64,7 +68,7 @@ static inline int page_order(struct ring_buffer *rb)
 }
 #endif
 
-static unsigned long perf_data_size(struct ring_buffer *rb)
+static inline unsigned long perf_data_size(struct ring_buffer *rb)
 {
 	return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
 }
@@ -93,4 +97,37 @@ __output_copy(struct perf_output_handle *handle,
 	} while (len);
 }
 
+/* Callchain handling */
+extern struct perf_callchain_entry *perf_callchain(struct pt_regs *regs);
+extern int get_callchain_buffers(void);
+extern void put_callchain_buffers(void);
+
+static inline int get_recursion_context(int *recursion)
+{
+	int rctx;
+
+	if (in_nmi())
+		rctx = 3;
+	else if (in_irq())
+		rctx = 2;
+	else if (in_softirq())
+		rctx = 1;
+	else
+		rctx = 0;
+
+	if (recursion[rctx])
+		return -1;
+
+	recursion[rctx]++;
+	barrier();
+
+	return rctx;
+}
+
+static inline void put_recursion_context(int *recursion, int rctx)
+{
+	barrier();
+	recursion[rctx]--;
+}
+
 #endif /* _KERNEL_EVENTS_INTERNAL_H */
Signature · 1 line
1.7.5.4
maintainer
#1 lore raw
Quoted 5 lines · Frederic Weisbecker

From: Borislav Petkov <[email protected]>

Split the callchain code from the perf events core into a new kernel/events/callchain.c file.

Quoted 8 lines

This simplifies a bit the big core.c

Cc Ingo Molnar <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Stephane Eranian <[email protected]>
[keep ctx recursion handling inline and use internal headers]

Thanks!

#2 lore raw
In reply to Frederic Weisbecker
Commit-ID:  9251f904f95175b4a1d8cbc0449e748f9edd7629
Gitweb:     http://git.kernel.org/tip/9251f904f95175b4a1d8cbc0449e748f9edd7629
Author:     Borislav Petkov <[email protected]>
AuthorDate: Sun, 16 Oct 2011 17:15:04 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Mon, 14 Nov 2011 13:31:26 +0100

perf: Carve out callchain functionality

Split the callchain code from the perf events core into a new kernel/events/callchain.c file.

This simplifies a bit the big core.c

Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Stephane Eranian <[email protected]>
[keep ctx recursion handling inline and use internal headers]
---
 kernel/events/Makefile    |    2 +-
 kernel/events/callchain.c |  191 +++++++++++++++++++++++++++++++++++++++++
 kernel/events/core.c      |  209 ---------------------------------------------
 kernel/events/internal.h  |   39 ++++++++-
 4 files changed, 230 insertions(+), 211 deletions(-)
kernel/events/Makefile +1 -1
index 89e5e8a..22d901f 100644
@@ -2,5 +2,5 @@ ifdef CONFIG_FUNCTION_TRACER
 CFLAGS_REMOVE_core.o = -pg
 endif
 
-obj-y := core.o ring_buffer.o
+obj-y := core.o ring_buffer.o callchain.o
 obj-$(CONFIG_HAVE_HW_BREAKPOINT) += hw_breakpoint.o
kernel/events/callchain.c new file +191 -0

191 lines not on this page · raw message

kernel/events/core.c +0 -209

215 lines not on this page · raw message

kernel/events/internal.h +38 -1
index 09097dd..be4a43f 100644
@@ -1,6 +1,10 @@
 #ifndef _KERNEL_EVENTS_INTERNAL_H
 #define _KERNEL_EVENTS_INTERNAL_H
 
+#include <linux/hardirq.h>
+
+/* Buffer handling */
+
 #define RING_BUFFER_WRITABLE		0x01
 
 struct ring_buffer {
@@ -64,7 +68,7 @@ static inline int page_order(struct ring_buffer *rb)
 }
 #endif
 
-static unsigned long perf_data_size(struct ring_buffer *rb)
+static inline unsigned long perf_data_size(struct ring_buffer *rb)
 {
 	return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
 }
@@ -93,4 +97,37 @@ __output_copy(struct perf_output_handle *handle,
 	} while (len);
 }
 
+/* Callchain handling */
+extern struct perf_callchain_entry *perf_callchain(struct pt_regs *regs);
+extern int get_callchain_buffers(void);
+extern void put_callchain_buffers(void);
+
+static inline int get_recursion_context(int *recursion)
+{
+	int rctx;
+
+	if (in_nmi())
+		rctx = 3;
+	else if (in_irq())
+		rctx = 2;
+	else if (in_softirq())
+		rctx = 1;
+	else
+		rctx = 0;
+
+	if (recursion[rctx])
+		return -1;
+
+	recursion[rctx]++;
+	barrier();
+
+	return rctx;
+}
+
+static inline void put_recursion_context(int *recursion, int rctx)
+{
+	barrier();
+	recursion[rctx]--;
+}
+
 #endif /* _KERNEL_EVENTS_INTERNAL_H */