aboutsummaryrefslogtreecommitdiffstats
path: root/samples
diff options
context:
space:
mode:
Diffstat (limited to 'samples')
-rw-r--r--samples/Kconfig6
-rw-r--r--samples/Makefile2
-rw-r--r--samples/kprobes/kretprobe_example.c1
-rw-r--r--samples/markers/Makefile4
-rw-r--r--samples/markers/marker-example.c53
-rw-r--r--samples/markers/probe-example.c92
-rw-r--r--samples/trace_events/trace-events-sample.h39
-rw-r--r--samples/tracepoints/tracepoint-sample.c2
8 files changed, 24 insertions, 175 deletions
diff --git a/samples/Kconfig b/samples/Kconfig
index 428b065ba695..b92bde3c6a89 100644
--- a/samples/Kconfig
+++ b/samples/Kconfig
@@ -7,12 +7,6 @@ menuconfig SAMPLES
7 7
8if SAMPLES 8if SAMPLES
9 9
10config SAMPLE_MARKERS
11 tristate "Build markers examples -- loadable modules only"
12 depends on MARKERS && m
13 help
14 This build markers example modules.
15
16config SAMPLE_TRACEPOINTS 10config SAMPLE_TRACEPOINTS
17 tristate "Build tracepoints examples -- loadable modules only" 11 tristate "Build tracepoints examples -- loadable modules only"
18 depends on TRACEPOINTS && m 12 depends on TRACEPOINTS && m
diff --git a/samples/Makefile b/samples/Makefile
index 13e4b470b539..43343a03b1f4 100644
--- a/samples/Makefile
+++ b/samples/Makefile
@@ -1,3 +1,3 @@
1# Makefile for Linux samples code 1# Makefile for Linux samples code
2 2
3obj-$(CONFIG_SAMPLES) += markers/ kobject/ kprobes/ tracepoints/ trace_events/ 3obj-$(CONFIG_SAMPLES) += kobject/ kprobes/ tracepoints/ trace_events/
diff --git a/samples/kprobes/kretprobe_example.c b/samples/kprobes/kretprobe_example.c
index 4e764b317d61..1041b6731598 100644
--- a/samples/kprobes/kretprobe_example.c
+++ b/samples/kprobes/kretprobe_example.c
@@ -23,6 +23,7 @@
23#include <linux/kprobes.h> 23#include <linux/kprobes.h>
24#include <linux/ktime.h> 24#include <linux/ktime.h>
25#include <linux/limits.h> 25#include <linux/limits.h>
26#include <linux/sched.h>
26 27
27static char func_name[NAME_MAX] = "do_fork"; 28static char func_name[NAME_MAX] = "do_fork";
28module_param_string(func, func_name, NAME_MAX, S_IRUGO); 29module_param_string(func, func_name, NAME_MAX, S_IRUGO);
diff --git a/samples/markers/Makefile b/samples/markers/Makefile
deleted file mode 100644
index 6d7231265f0f..000000000000
--- a/samples/markers/Makefile
+++ /dev/null
@@ -1,4 +0,0 @@
1# builds the kprobes example kernel modules;
2# then to use one (as root): insmod <module_name.ko>
3
4obj-$(CONFIG_SAMPLE_MARKERS) += probe-example.o marker-example.o
diff --git a/samples/markers/marker-example.c b/samples/markers/marker-example.c
deleted file mode 100644
index e9cd9c0bc84f..000000000000
--- a/samples/markers/marker-example.c
+++ /dev/null
@@ -1,53 +0,0 @@
1/* marker-example.c
2 *
3 * Executes a marker when /proc/marker-example is opened.
4 *
5 * (C) Copyright 2007 Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
6 *
7 * This file is released under the GPLv2.
8 * See the file COPYING for more details.
9 */
10
11#include <linux/module.h>
12#include <linux/marker.h>
13#include <linux/sched.h>
14#include <linux/proc_fs.h>
15
16struct proc_dir_entry *pentry_example;
17
18static int my_open(struct inode *inode, struct file *file)
19{
20 int i;
21
22 trace_mark(subsystem_event, "integer %d string %s", 123,
23 "example string");
24 for (i = 0; i < 10; i++)
25 trace_mark(subsystem_eventb, MARK_NOARGS);
26 return -EPERM;
27}
28
29static struct file_operations mark_ops = {
30 .open = my_open,
31};
32
33static int __init example_init(void)
34{
35 printk(KERN_ALERT "example init\n");
36 pentry_example = proc_create("marker-example", 0444, NULL, &mark_ops);
37 if (!pentry_example)
38 return -EPERM;
39 return 0;
40}
41
42static void __exit example_exit(void)
43{
44 printk(KERN_ALERT "example exit\n");
45 remove_proc_entry("marker-example", NULL);
46}
47
48module_init(example_init)
49module_exit(example_exit)
50
51MODULE_LICENSE("GPL");
52MODULE_AUTHOR("Mathieu Desnoyers");
53MODULE_DESCRIPTION("Marker example");
diff --git a/samples/markers/probe-example.c b/samples/markers/probe-example.c
deleted file mode 100644
index 2dfb3b32937e..000000000000
--- a/samples/markers/probe-example.c
+++ /dev/null
@@ -1,92 +0,0 @@
1/* probe-example.c
2 *
3 * Connects two functions to marker call sites.
4 *
5 * (C) Copyright 2007 Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
6 *
7 * This file is released under the GPLv2.
8 * See the file COPYING for more details.
9 */
10
11#include <linux/sched.h>
12#include <linux/kernel.h>
13#include <linux/module.h>
14#include <linux/marker.h>
15#include <asm/atomic.h>
16
17struct probe_data {
18 const char *name;
19 const char *format;
20 marker_probe_func *probe_func;
21};
22
23void probe_subsystem_event(void *probe_data, void *call_data,
24 const char *format, va_list *args)
25{
26 /* Declare args */
27 unsigned int value;
28 const char *mystr;
29
30 /* Assign args */
31 value = va_arg(*args, typeof(value));
32 mystr = va_arg(*args, typeof(mystr));
33
34 /* Call printk */
35 printk(KERN_INFO "Value %u, string %s\n", value, mystr);
36
37 /* or count, check rights, serialize data in a buffer */
38}
39
40atomic_t eventb_count = ATOMIC_INIT(0);
41
42void probe_subsystem_eventb(void *probe_data, void *call_data,
43 const char *format, va_list *args)
44{
45 /* Increment counter */
46 atomic_inc(&eventb_count);
47}
48
49static struct probe_data probe_array[] =
50{
51 { .name = "subsystem_event",
52 .format = "integer %d string %s",
53 .probe_func = probe_subsystem_event },
54 { .name = "subsystem_eventb",
55 .format = MARK_NOARGS,
56 .probe_func = probe_subsystem_eventb },
57};
58
59static int __init probe_init(void)
60{
61 int result;
62 int i;
63
64 for (i = 0; i < ARRAY_SIZE(probe_array); i++) {
65 result = marker_probe_register(probe_array[i].name,
66 probe_array[i].format,
67 probe_array[i].probe_func, &probe_array[i]);
68 if (result)
69 printk(KERN_INFO "Unable to register probe %s\n",
70 probe_array[i].name);
71 }
72 return 0;
73}
74
75static void __exit probe_fini(void)
76{
77 int i;
78
79 for (i = 0; i < ARRAY_SIZE(probe_array); i++)
80 marker_probe_unregister(probe_array[i].name,
81 probe_array[i].probe_func, &probe_array[i]);
82 printk(KERN_INFO "Number of event b : %u\n",
83 atomic_read(&eventb_count));
84 marker_synchronize_unregister();
85}
86
87module_init(probe_init);
88module_exit(probe_fini);
89
90MODULE_LICENSE("GPL");
91MODULE_AUTHOR("Mathieu Desnoyers");
92MODULE_DESCRIPTION("SUBSYSTEM Probe");
diff --git a/samples/trace_events/trace-events-sample.h b/samples/trace_events/trace-events-sample.h
index 9977a756fb32..6af373236d73 100644
--- a/samples/trace_events/trace-events-sample.h
+++ b/samples/trace_events/trace-events-sample.h
@@ -1,23 +1,6 @@
1/* 1/*
2 * Notice that this file is not protected like a normal header.
3 * We also must allow for rereading of this file. The
4 *
5 * || defined(TRACE_HEADER_MULTI_READ)
6 *
7 * serves this purpose.
8 */
9#if !defined(_TRACE_EVENT_SAMPLE_H) || defined(TRACE_HEADER_MULTI_READ)
10#define _TRACE_EVENT_SAMPLE_H
11
12/*
13 * All trace headers should include tracepoint.h, until we finally
14 * make it into a standard header.
15 */
16#include <linux/tracepoint.h>
17
18/*
19 * If TRACE_SYSTEM is defined, that will be the directory created 2 * If TRACE_SYSTEM is defined, that will be the directory created
20 * in the ftrace directory under /debugfs/tracing/events/<system> 3 * in the ftrace directory under /sys/kernel/debug/tracing/events/<system>
21 * 4 *
22 * The define_trace.h below will also look for a file name of 5 * The define_trace.h below will also look for a file name of
23 * TRACE_SYSTEM.h where TRACE_SYSTEM is what is defined here. 6 * TRACE_SYSTEM.h where TRACE_SYSTEM is what is defined here.
@@ -34,11 +17,31 @@
34 * #define TRACE_INCLUDE_FILE trace-events-sample 17 * #define TRACE_INCLUDE_FILE trace-events-sample
35 * 18 *
36 * As we do an the bottom of this file. 19 * As we do an the bottom of this file.
20 *
21 * Notice that TRACE_SYSTEM should be defined outside of #if
22 * protection, just like TRACE_INCLUDE_FILE.
37 */ 23 */
38#undef TRACE_SYSTEM 24#undef TRACE_SYSTEM
39#define TRACE_SYSTEM sample 25#define TRACE_SYSTEM sample
40 26
41/* 27/*
28 * Notice that this file is not protected like a normal header.
29 * We also must allow for rereading of this file. The
30 *
31 * || defined(TRACE_HEADER_MULTI_READ)
32 *
33 * serves this purpose.
34 */
35#if !defined(_TRACE_EVENT_SAMPLE_H) || defined(TRACE_HEADER_MULTI_READ)
36#define _TRACE_EVENT_SAMPLE_H
37
38/*
39 * All trace headers should include tracepoint.h, until we finally
40 * make it into a standard header.
41 */
42#include <linux/tracepoint.h>
43
44/*
42 * The TRACE_EVENT macro is broken up into 5 parts. 45 * The TRACE_EVENT macro is broken up into 5 parts.
43 * 46 *
44 * name: name of the trace point. This is also how to enable the tracepoint. 47 * name: name of the trace point. This is also how to enable the tracepoint.
diff --git a/samples/tracepoints/tracepoint-sample.c b/samples/tracepoints/tracepoint-sample.c
index 9cf80a11e8b6..26fab33ffa8c 100644
--- a/samples/tracepoints/tracepoint-sample.c
+++ b/samples/tracepoints/tracepoint-sample.c
@@ -28,7 +28,7 @@ static int my_open(struct inode *inode, struct file *file)
28 return -EPERM; 28 return -EPERM;
29} 29}
30 30
31static struct file_operations mark_ops = { 31static const struct file_operations mark_ops = {
32 .open = my_open, 32 .open = my_open,
33}; 33};
34 34