aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authorNeil Horman <nhorman@tuxdriver.com>2009-08-13 01:23:56 -0400
committerDavid S. Miller <davem@davemloft.net>2009-08-13 19:43:25 -0400
commit9ec04da7489d2c9ae01ea6e9b5fa313ccf3d35fb (patch)
tree487553ef03d65aa6821c2ea7685c5c5e1d430786 /kernel
parent5a165657bef7c47e5ff4cd138f7758ef6278e87b (diff)
net: skb ftracer - Add actual ftrace code to kernel (v3)
skb allocation / consumption correlator Add ftracer module to kernel to print out a list that correlates a process id, an skb it read, and the numa nodes on wich the process was running when it was read along with the numa node the skbuff was allocated on. Signed-off-by: Neil Horman <nhorman@tuxdriver.com> Makefile | 1 trace.h | 19 ++++++ trace_skb_sources.c | 154 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 174 insertions(+) Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/trace/Makefile1
-rw-r--r--kernel/trace/trace.h19
-rw-r--r--kernel/trace/trace_skb_sources.c154
3 files changed, 174 insertions, 0 deletions
diff --git a/kernel/trace/Makefile b/kernel/trace/Makefile
index 844164dca90a..ee5e5b1b9282 100644
--- a/kernel/trace/Makefile
+++ b/kernel/trace/Makefile
@@ -49,6 +49,7 @@ obj-$(CONFIG_BLK_DEV_IO_TRACE) += blktrace.o
49ifeq ($(CONFIG_BLOCK),y) 49ifeq ($(CONFIG_BLOCK),y)
50obj-$(CONFIG_EVENT_TRACING) += blktrace.o 50obj-$(CONFIG_EVENT_TRACING) += blktrace.o
51endif 51endif
52obj-$(CONFIG_SKB_SOURCES_TRACER) += trace_skb_sources.o
52obj-$(CONFIG_EVENT_TRACING) += trace_events.o 53obj-$(CONFIG_EVENT_TRACING) += trace_events.o
53obj-$(CONFIG_EVENT_TRACING) += trace_export.o 54obj-$(CONFIG_EVENT_TRACING) += trace_export.o
54obj-$(CONFIG_FTRACE_SYSCALLS) += trace_syscalls.o 55obj-$(CONFIG_FTRACE_SYSCALLS) += trace_syscalls.o
diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
index 8b9f4f6e9559..8a6281b2330b 100644
--- a/kernel/trace/trace.h
+++ b/kernel/trace/trace.h
@@ -11,6 +11,7 @@
11#include <trace/boot.h> 11#include <trace/boot.h>
12#include <linux/kmemtrace.h> 12#include <linux/kmemtrace.h>
13#include <trace/power.h> 13#include <trace/power.h>
14#include <trace/events/skb.h>
14 15
15#include <linux/trace_seq.h> 16#include <linux/trace_seq.h>
16#include <linux/ftrace_event.h> 17#include <linux/ftrace_event.h>
@@ -40,6 +41,7 @@ enum trace_type {
40 TRACE_KMEM_FREE, 41 TRACE_KMEM_FREE,
41 TRACE_POWER, 42 TRACE_POWER,
42 TRACE_BLK, 43 TRACE_BLK,
44 TRACE_SKB_SOURCE,
43 45
44 __TRACE_LAST_TYPE, 46 __TRACE_LAST_TYPE,
45}; 47};
@@ -171,6 +173,21 @@ struct trace_power {
171 struct power_trace state_data; 173 struct power_trace state_data;
172}; 174};
173 175
176struct skb_record {
177 pid_t pid; /* pid of the copying process */
178 int anid; /* node where skb was allocated */
179 int cnid; /* node to which skb was copied in userspace */
180 char ifname[IFNAMSIZ]; /* Name of the receiving interface */
181 int rx_queue; /* The rx queue the skb was received on */
182 int ccpu; /* Cpu the application got this frame from */
183 int len; /* length of the data copied */
184};
185
186struct trace_skb_event {
187 struct trace_entry ent;
188 struct skb_record event_data;
189};
190
174enum kmemtrace_type_id { 191enum kmemtrace_type_id {
175 KMEMTRACE_TYPE_KMALLOC = 0, /* kmalloc() or kfree(). */ 192 KMEMTRACE_TYPE_KMALLOC = 0, /* kmalloc() or kfree(). */
176 KMEMTRACE_TYPE_CACHE, /* kmem_cache_*(). */ 193 KMEMTRACE_TYPE_CACHE, /* kmem_cache_*(). */
@@ -323,6 +340,8 @@ extern void __ftrace_bad_type(void);
323 TRACE_SYSCALL_ENTER); \ 340 TRACE_SYSCALL_ENTER); \
324 IF_ASSIGN(var, ent, struct syscall_trace_exit, \ 341 IF_ASSIGN(var, ent, struct syscall_trace_exit, \
325 TRACE_SYSCALL_EXIT); \ 342 TRACE_SYSCALL_EXIT); \
343 IF_ASSIGN(var, ent, struct trace_skb_event, \
344 TRACE_SKB_SOURCE); \
326 __ftrace_bad_type(); \ 345 __ftrace_bad_type(); \
327 } while (0) 346 } while (0)
328 347
diff --git a/kernel/trace/trace_skb_sources.c b/kernel/trace/trace_skb_sources.c
new file mode 100644
index 000000000000..40eb071afdb4
--- /dev/null
+++ b/kernel/trace/trace_skb_sources.c
@@ -0,0 +1,154 @@
1/*
2 * ring buffer based tracer for analyzing per-socket skb sources
3 *
4 * Neil Horman <nhorman@tuxdriver.com>
5 * Copyright (C) 2009
6 *
7 *
8 */
9
10#include <linux/init.h>
11#include <linux/debugfs.h>
12#include <trace/events/skb.h>
13#include <linux/kallsyms.h>
14#include <linux/module.h>
15#include <linux/hardirq.h>
16#include <linux/netdevice.h>
17#include <net/sock.h>
18
19#include "trace.h"
20#include "trace_output.h"
21
22EXPORT_TRACEPOINT_SYMBOL_GPL(skb_copy_datagram_iovec);
23
24static struct trace_array *skb_trace;
25static int __read_mostly trace_skb_source_enabled;
26
27static void probe_skb_dequeue(const struct sk_buff *skb, int len)
28{
29 struct ring_buffer_event *event;
30 struct trace_skb_event *entry;
31 struct trace_array *tr = skb_trace;
32 struct net_device *dev;
33
34 if (!trace_skb_source_enabled)
35 return;
36
37 if (in_interrupt())
38 return;
39
40 event = trace_buffer_lock_reserve(tr, TRACE_SKB_SOURCE,
41 sizeof(*entry), 0, 0);
42 if (!event)
43 return;
44 entry = ring_buffer_event_data(event);
45
46 entry->event_data.pid = current->pid;
47 entry->event_data.anid = page_to_nid(virt_to_page(skb->data));
48 entry->event_data.cnid = cpu_to_node(smp_processor_id());
49 entry->event_data.len = len;
50 entry->event_data.rx_queue = skb->queue_mapping;
51 entry->event_data.ccpu = smp_processor_id();
52
53 dev = dev_get_by_index(sock_net(skb->sk), skb->iif);
54 if (dev) {
55 memcpy(entry->event_data.ifname, dev->name, IFNAMSIZ);
56 dev_put(dev);
57 } else {
58 strcpy(entry->event_data.ifname, "Unknown");
59 }
60
61 trace_buffer_unlock_commit(tr, event, 0, 0);
62}
63
64static int tracing_skb_source_register(void)
65{
66 int ret;
67
68 ret = register_trace_skb_copy_datagram_iovec(probe_skb_dequeue);
69 if (ret)
70 pr_info("skb source trace: Couldn't activate dequeue tracepoint");
71
72 return ret;
73}
74
75static void start_skb_source_trace(struct trace_array *tr)
76{
77 trace_skb_source_enabled = 1;
78}
79
80static void stop_skb_source_trace(struct trace_array *tr)
81{
82 trace_skb_source_enabled = 0;
83}
84
85static void skb_source_trace_reset(struct trace_array *tr)
86{
87 trace_skb_source_enabled = 0;
88 unregister_trace_skb_copy_datagram_iovec(probe_skb_dequeue);
89}
90
91
92static int skb_source_trace_init(struct trace_array *tr)
93{
94 int cpu;
95 skb_trace = tr;
96
97 trace_skb_source_enabled = 1;
98 tracing_skb_source_register();
99
100 for_each_cpu(cpu, cpu_possible_mask)
101 tracing_reset(tr, cpu);
102 return 0;
103}
104
105static enum print_line_t skb_source_print_line(struct trace_iterator *iter)
106{
107 int ret = 0;
108 struct trace_entry *entry = iter->ent;
109 struct trace_skb_event *event;
110 struct skb_record *record;
111 struct trace_seq *s = &iter->seq;
112
113 trace_assign_type(event, entry);
114 record = &event->event_data;
115 if (entry->type != TRACE_SKB_SOURCE)
116 return TRACE_TYPE_UNHANDLED;
117
118 ret = trace_seq_printf(s, " %d %d %d %s %d %d %d\n",
119 record->pid,
120 record->anid,
121 record->cnid,
122 record->ifname,
123 record->rx_queue,
124 record->ccpu,
125 record->len);
126
127 if (!ret)
128 return TRACE_TYPE_PARTIAL_LINE;
129
130 return TRACE_TYPE_HANDLED;
131}
132
133static void skb_source_print_header(struct seq_file *s)
134{
135 seq_puts(s, "# PID ANID CNID IFC RXQ CCPU LEN\n");
136 seq_puts(s, "# | | | | | | |\n");
137}
138
139static struct tracer skb_source_tracer __read_mostly =
140{
141 .name = "skb_sources",
142 .init = skb_source_trace_init,
143 .start = start_skb_source_trace,
144 .stop = stop_skb_source_trace,
145 .reset = skb_source_trace_reset,
146 .print_line = skb_source_print_line,
147 .print_header = skb_source_print_header,
148};
149
150static int init_skb_source_trace(void)
151{
152 return register_tracer(&skb_source_tracer);
153}
154device_initcall(init_skb_source_trace);