diff options
Diffstat (limited to 'samples/trace_events')
-rw-r--r-- | samples/trace_events/trace-events-sample.c | 14 | ||||
-rw-r--r-- | samples/trace_events/trace-events-sample.h | 11 |
2 files changed, 17 insertions, 8 deletions
diff --git a/samples/trace_events/trace-events-sample.c b/samples/trace_events/trace-events-sample.c index bc7fcf010a5b..5522692100ba 100644 --- a/samples/trace_events/trace-events-sample.c +++ b/samples/trace_events/trace-events-sample.c @@ -78,29 +78,37 @@ static int simple_thread_fn(void *arg) } static DEFINE_MUTEX(thread_mutex); +static int simple_thread_cnt; int foo_bar_reg(void) { + mutex_lock(&thread_mutex); + if (simple_thread_cnt++) + goto out; + pr_info("Starting thread for foo_bar_fn\n"); /* * We shouldn't be able to start a trace when the module is * unloading (there's other locks to prevent that). But * for consistency sake, we still take the thread_mutex. */ - mutex_lock(&thread_mutex); simple_tsk_fn = kthread_run(simple_thread_fn, NULL, "event-sample-fn"); + out: mutex_unlock(&thread_mutex); return 0; } void foo_bar_unreg(void) { - pr_info("Killing thread for foo_bar_fn\n"); - /* protect against module unloading */ mutex_lock(&thread_mutex); + if (--simple_thread_cnt) + goto out; + + pr_info("Killing thread for foo_bar_fn\n"); if (simple_tsk_fn) kthread_stop(simple_tsk_fn); simple_tsk_fn = NULL; + out: mutex_unlock(&thread_mutex); } diff --git a/samples/trace_events/trace-events-sample.h b/samples/trace_events/trace-events-sample.h index 76a75ab7a608..80b4a70315b6 100644 --- a/samples/trace_events/trace-events-sample.h +++ b/samples/trace_events/trace-events-sample.h @@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: GPL-2.0 */ /* * If TRACE_SYSTEM is defined, that will be the directory created * in the ftrace directory under /sys/kernel/tracing/events/<system> @@ -95,7 +96,7 @@ * __entry->bar.x = y; * __array: There are three fields (type, name, size). The type is the - * type of elements in teh array, the name is the name of the array. + * type of elements in the array, the name is the name of the array. * size is the number of items in the array (not the total size). * * __array( char, foo, 10) is the same as saying: char foo[10]; @@ -112,7 +113,7 @@ * type is the type of the element, name is the name of the array. * The size is different than __array. It is not a static number, * but the algorithm to figure out the length of the array for the - * specific instance of tracepoint. Again, size is the numebr of + * specific instance of tracepoint. Again, size is the number of * items in the array, not the total length in bytes. * * __dynamic_array( int, foo, bar) is similar to: int foo[bar]; @@ -125,9 +126,9 @@ * Notice, that "__entry" is not needed here. * * __string: This is a special kind of __dynamic_array. It expects to - * have a nul terminated character array passed to it (it allows + * have a null terminated character array passed to it (it allows * for NULL too, which would be converted into "(null)"). __string - * takes two paramenter (name, src), where name is the name of + * takes two parameter (name, src), where name is the name of * the string saved, and src is the string to copy into the * ring buffer. * @@ -444,7 +445,7 @@ DECLARE_EVENT_CLASS(foo_template, /* * Here's a better way for the previous samples (except, the first - * exmaple had more fields and could not be used here). + * example had more fields and could not be used here). */ DEFINE_EVENT(foo_template, foo_with_template_simple, TP_PROTO(const char *foo, int bar), |