~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/samples/trace_events/trace-events-sample.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /samples/trace_events/trace-events-sample.c (Version linux-6.11.5) and /samples/trace_events/trace-events-sample.c (Version linux-5.3.18)


  1 // SPDX-License-Identifier: GPL-2.0-only            1 // SPDX-License-Identifier: GPL-2.0-only
  2 #include <linux/module.h>                           2 #include <linux/module.h>
  3 #include <linux/kthread.h>                          3 #include <linux/kthread.h>
  4                                                     4 
  5 /*                                                  5 /*
  6  * Any file that uses trace points, must inclu      6  * Any file that uses trace points, must include the header.
  7  * But only one file, must include the header       7  * But only one file, must include the header by defining
  8  * CREATE_TRACE_POINTS first.  This will make       8  * CREATE_TRACE_POINTS first.  This will make the C code that
  9  * creates the handles for the trace points.        9  * creates the handles for the trace points.
 10  */                                                10  */
 11 #define CREATE_TRACE_POINTS                        11 #define CREATE_TRACE_POINTS
 12 #include "trace-events-sample.h"                   12 #include "trace-events-sample.h"
 13                                                    13 
 14 static const char *random_strings[] = {            14 static const char *random_strings[] = {
 15         "Mother Goose",                            15         "Mother Goose",
 16         "Snoopy",                                  16         "Snoopy",
 17         "Gandalf",                                 17         "Gandalf",
 18         "Frodo",                                   18         "Frodo",
 19         "One ring to rule them all"                19         "One ring to rule them all"
 20 };                                                 20 };
 21                                                    21 
 22 static void do_simple_thread_func(int cnt, con !!  22 static void simple_thread_func(int cnt)
 23 {                                                  23 {
 24         unsigned long bitmask[1] = {0xdeadbeef << 
 25         va_list va;                            << 
 26         int array[6];                              24         int array[6];
 27         int len = cnt % 5;                         25         int len = cnt % 5;
 28         int i;                                     26         int i;
 29                                                    27 
 30         set_current_state(TASK_INTERRUPTIBLE);     28         set_current_state(TASK_INTERRUPTIBLE);
 31         schedule_timeout(HZ);                      29         schedule_timeout(HZ);
 32                                                    30 
 33         for (i = 0; i < len; i++)                  31         for (i = 0; i < len; i++)
 34                 array[i] = i + 1;                  32                 array[i] = i + 1;
 35         array[i] = 0;                              33         array[i] = 0;
 36                                                    34 
 37         va_start(va, fmt);                     << 
 38                                                << 
 39         /* Silly tracepoints */                    35         /* Silly tracepoints */
 40         trace_foo_bar("hello", cnt, array, ran     36         trace_foo_bar("hello", cnt, array, random_strings[len],
 41                       current->cpus_ptr, fmt,  !!  37                       current->cpus_ptr);
 42                                                << 
 43         va_end(va);                            << 
 44                                                    38 
 45         trace_foo_with_template_simple("HELLO"     39         trace_foo_with_template_simple("HELLO", cnt);
 46                                                    40 
 47         trace_foo_bar_with_cond("Some times pr     41         trace_foo_bar_with_cond("Some times print", cnt);
 48                                                    42 
 49         trace_foo_with_template_cond("prints o     43         trace_foo_with_template_cond("prints other times", cnt);
 50                                                    44 
 51         trace_foo_with_template_print("I have      45         trace_foo_with_template_print("I have to be different", cnt);
 52                                                << 
 53         trace_foo_rel_loc("Hello __rel_loc", c << 
 54 }                                              << 
 55                                                << 
 56 static void simple_thread_func(int cnt)        << 
 57 {                                              << 
 58         do_simple_thread_func(cnt, "iter=%d",  << 
 59 }                                                  46 }
 60                                                    47 
 61 static int simple_thread(void *arg)                48 static int simple_thread(void *arg)
 62 {                                                  49 {
 63         int cnt = 0;                               50         int cnt = 0;
 64                                                    51 
 65         while (!kthread_should_stop())             52         while (!kthread_should_stop())
 66                 simple_thread_func(cnt++);         53                 simple_thread_func(cnt++);
 67                                                    54 
 68         return 0;                                  55         return 0;
 69 }                                                  56 }
 70                                                    57 
 71 static struct task_struct *simple_tsk;             58 static struct task_struct *simple_tsk;
 72 static struct task_struct *simple_tsk_fn;          59 static struct task_struct *simple_tsk_fn;
 73                                                    60 
 74 static void simple_thread_func_fn(int cnt)         61 static void simple_thread_func_fn(int cnt)
 75 {                                                  62 {
 76         set_current_state(TASK_INTERRUPTIBLE);     63         set_current_state(TASK_INTERRUPTIBLE);
 77         schedule_timeout(HZ);                      64         schedule_timeout(HZ);
 78                                                    65 
 79         /* More silly tracepoints */               66         /* More silly tracepoints */
 80         trace_foo_bar_with_fn("Look at me", cn     67         trace_foo_bar_with_fn("Look at me", cnt);
 81         trace_foo_with_template_fn("Look at me     68         trace_foo_with_template_fn("Look at me too", cnt);
 82 }                                                  69 }
 83                                                    70 
 84 static int simple_thread_fn(void *arg)             71 static int simple_thread_fn(void *arg)
 85 {                                                  72 {
 86         int cnt = 0;                               73         int cnt = 0;
 87                                                    74 
 88         while (!kthread_should_stop())             75         while (!kthread_should_stop())
 89                 simple_thread_func_fn(cnt++);      76                 simple_thread_func_fn(cnt++);
 90                                                    77 
 91         return 0;                                  78         return 0;
 92 }                                                  79 }
 93                                                    80 
 94 static DEFINE_MUTEX(thread_mutex);                 81 static DEFINE_MUTEX(thread_mutex);
 95 static int simple_thread_cnt;                      82 static int simple_thread_cnt;
 96                                                    83 
 97 int foo_bar_reg(void)                              84 int foo_bar_reg(void)
 98 {                                                  85 {
 99         mutex_lock(&thread_mutex);                 86         mutex_lock(&thread_mutex);
100         if (simple_thread_cnt++)                   87         if (simple_thread_cnt++)
101                 goto out;                          88                 goto out;
102                                                    89 
103         pr_info("Starting thread for foo_bar_f     90         pr_info("Starting thread for foo_bar_fn\n");
104         /*                                         91         /*
105          * We shouldn't be able to start a tra     92          * We shouldn't be able to start a trace when the module is
106          * unloading (there's other locks to p     93          * unloading (there's other locks to prevent that). But
107          * for consistency sake, we still take     94          * for consistency sake, we still take the thread_mutex.
108          */                                        95          */
109         simple_tsk_fn = kthread_run(simple_thr     96         simple_tsk_fn = kthread_run(simple_thread_fn, NULL, "event-sample-fn");
110  out:                                              97  out:
111         mutex_unlock(&thread_mutex);               98         mutex_unlock(&thread_mutex);
112         return 0;                                  99         return 0;
113 }                                                 100 }
114                                                   101 
115 void foo_bar_unreg(void)                          102 void foo_bar_unreg(void)
116 {                                                 103 {
117         mutex_lock(&thread_mutex);                104         mutex_lock(&thread_mutex);
118         if (--simple_thread_cnt)                  105         if (--simple_thread_cnt)
119                 goto out;                         106                 goto out;
120                                                   107 
121         pr_info("Killing thread for foo_bar_fn    108         pr_info("Killing thread for foo_bar_fn\n");
122         if (simple_tsk_fn)                        109         if (simple_tsk_fn)
123                 kthread_stop(simple_tsk_fn);      110                 kthread_stop(simple_tsk_fn);
124         simple_tsk_fn = NULL;                     111         simple_tsk_fn = NULL;
125  out:                                             112  out:
126         mutex_unlock(&thread_mutex);              113         mutex_unlock(&thread_mutex);
127 }                                                 114 }
128                                                   115 
129 static int __init trace_event_init(void)          116 static int __init trace_event_init(void)
130 {                                                 117 {
131         simple_tsk = kthread_run(simple_thread    118         simple_tsk = kthread_run(simple_thread, NULL, "event-sample");
132         if (IS_ERR(simple_tsk))                   119         if (IS_ERR(simple_tsk))
133                 return -1;                        120                 return -1;
134                                                   121 
135         return 0;                                 122         return 0;
136 }                                                 123 }
137                                                   124 
138 static void __exit trace_event_exit(void)         125 static void __exit trace_event_exit(void)
139 {                                                 126 {
140         kthread_stop(simple_tsk);                 127         kthread_stop(simple_tsk);
141         mutex_lock(&thread_mutex);                128         mutex_lock(&thread_mutex);
142         if (simple_tsk_fn)                        129         if (simple_tsk_fn)
143                 kthread_stop(simple_tsk_fn);      130                 kthread_stop(simple_tsk_fn);
144         simple_tsk_fn = NULL;                     131         simple_tsk_fn = NULL;
145         mutex_unlock(&thread_mutex);              132         mutex_unlock(&thread_mutex);
146 }                                                 133 }
147                                                   134 
148 module_init(trace_event_init);                    135 module_init(trace_event_init);
149 module_exit(trace_event_exit);                    136 module_exit(trace_event_exit);
150                                                   137 
151 MODULE_AUTHOR("Steven Rostedt");                  138 MODULE_AUTHOR("Steven Rostedt");
152 MODULE_DESCRIPTION("trace-events-sample");        139 MODULE_DESCRIPTION("trace-events-sample");
153 MODULE_LICENSE("GPL");                            140 MODULE_LICENSE("GPL");
154                                                   141 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php