x86/mm/pat: Don't report PAT on CPUs that don't support it
[linux/fpc-iii.git] / samples / trace_events / trace-events-sample.c
blobbc7fcf010a5b4ccb7c25dcfd651e53c61ce80b1a
1 #include <linux/module.h>
2 #include <linux/kthread.h>
4 /*
5 * Any file that uses trace points, must include the header.
6 * But only one file, must include the header by defining
7 * CREATE_TRACE_POINTS first. This will make the C code that
8 * creates the handles for the trace points.
9 */
10 #define CREATE_TRACE_POINTS
11 #include "trace-events-sample.h"
13 static const char *random_strings[] = {
14 "Mother Goose",
15 "Snoopy",
16 "Gandalf",
17 "Frodo",
18 "One ring to rule them all"
21 static void simple_thread_func(int cnt)
23 int array[6];
24 int len = cnt % 5;
25 int i;
27 set_current_state(TASK_INTERRUPTIBLE);
28 schedule_timeout(HZ);
30 for (i = 0; i < len; i++)
31 array[i] = i + 1;
32 array[i] = 0;
34 /* Silly tracepoints */
35 trace_foo_bar("hello", cnt, array, random_strings[len],
36 &current->cpus_allowed);
38 trace_foo_with_template_simple("HELLO", cnt);
40 trace_foo_bar_with_cond("Some times print", cnt);
42 trace_foo_with_template_cond("prints other times", cnt);
44 trace_foo_with_template_print("I have to be different", cnt);
47 static int simple_thread(void *arg)
49 int cnt = 0;
51 while (!kthread_should_stop())
52 simple_thread_func(cnt++);
54 return 0;
57 static struct task_struct *simple_tsk;
58 static struct task_struct *simple_tsk_fn;
60 static void simple_thread_func_fn(int cnt)
62 set_current_state(TASK_INTERRUPTIBLE);
63 schedule_timeout(HZ);
65 /* More silly tracepoints */
66 trace_foo_bar_with_fn("Look at me", cnt);
67 trace_foo_with_template_fn("Look at me too", cnt);
70 static int simple_thread_fn(void *arg)
72 int cnt = 0;
74 while (!kthread_should_stop())
75 simple_thread_func_fn(cnt++);
77 return 0;
80 static DEFINE_MUTEX(thread_mutex);
82 int foo_bar_reg(void)
84 pr_info("Starting thread for foo_bar_fn\n");
86 * We shouldn't be able to start a trace when the module is
87 * unloading (there's other locks to prevent that). But
88 * for consistency sake, we still take the thread_mutex.
90 mutex_lock(&thread_mutex);
91 simple_tsk_fn = kthread_run(simple_thread_fn, NULL, "event-sample-fn");
92 mutex_unlock(&thread_mutex);
93 return 0;
96 void foo_bar_unreg(void)
98 pr_info("Killing thread for foo_bar_fn\n");
99 /* protect against module unloading */
100 mutex_lock(&thread_mutex);
101 if (simple_tsk_fn)
102 kthread_stop(simple_tsk_fn);
103 simple_tsk_fn = NULL;
104 mutex_unlock(&thread_mutex);
107 static int __init trace_event_init(void)
109 simple_tsk = kthread_run(simple_thread, NULL, "event-sample");
110 if (IS_ERR(simple_tsk))
111 return -1;
113 return 0;
116 static void __exit trace_event_exit(void)
118 kthread_stop(simple_tsk);
119 mutex_lock(&thread_mutex);
120 if (simple_tsk_fn)
121 kthread_stop(simple_tsk_fn);
122 simple_tsk_fn = NULL;
123 mutex_unlock(&thread_mutex);
126 module_init(trace_event_init);
127 module_exit(trace_event_exit);
129 MODULE_AUTHOR("Steven Rostedt");
130 MODULE_DESCRIPTION("trace-events-sample");
131 MODULE_LICENSE("GPL");