From: Frederic Weisbecker <fweisbec@gmail.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: linux-kernel@vger.kernel.org, Ingo Molnar <mingo@elte.hu>,
Andrew Morton <akpm@linux-foundation.org>,
Thomas Gleixner <tglx@linutronix.de>,
Peter Zijlstra <peterz@infradead.org>
Subject: Re: [PATCH 2/5] tracing/events: add startup tests for events
Date: Thu, 16 Apr 2009 17:41:33 +0200 [thread overview]
Message-ID: <20090416154132.GC6004@nowhere> (raw)
In-Reply-To: <20090416021928.239106997@goodmis.org>
On Wed, Apr 15, 2009 at 10:18:32PM -0400, Steven Rostedt wrote:
> From: Steven Rostedt <srostedt@redhat.com>
>
> As events start to become popular, and the new way to add tracing
> infrastructure into ftrace, it is important to catch any problems
> that might happen with a mistake in the TRACE_EVENT macro.
>
> This patch introduces a startup self test on the registered trace
> events. Note, it can only do a generic test, any type of testing that
> needs more involement is needed to be implemented by the tracepoint
> creators.
>
> The test goes down one by one enabling a trace point and running
> some random tasks (random in the sense that I just made them up).
> Those tasks are creating threads, grabbing mutexes and spinlocks
> and using workqueues.
>
> After testing each event individually, it does the same test after
> enabling each system of trace points. Like sched, irq, lockdep.
>
> Then finally it enables all tracepoints and performs the tasks again.
> The output to the console on bootup will look like this when everything
> works:
>
> Running tests on trace events:
> Testing event kfree_skb: OK
> Testing event kmalloc: OK
> Testing event kmem_cache_alloc: OK
> Testing event kmalloc_node: OK
> Testing event kmem_cache_alloc_node: OK
> Testing event kfree: OK
> Testing event kmem_cache_free: OK
> Testing event irq_handler_exit: OK
> Testing event irq_handler_entry: OK
> Testing event softirq_entry: OK
> Testing event softirq_exit: OK
> Testing event lock_acquire: OK
> Testing event lock_release: OK
> Testing event sched_kthread_stop: OK
> Testing event sched_kthread_stop_ret: OK
> Testing event sched_wait_task: OK
> Testing event sched_wakeup: OK
> Testing event sched_wakeup_new: OK
> Testing event sched_switch: OK
> Testing event sched_migrate_task: OK
> Testing event sched_process_free: OK
> Testing event sched_process_exit: OK
> Testing event sched_process_wait: OK
> Testing event sched_process_fork: OK
> Testing event sched_signal_send: OK
> Running tests on trace event systems:
> Testing event system skb: OK
> Testing event system kmem: OK
> Testing event system irq: OK
> Testing event system lockdep: OK
> Testing event system sched: OK
> Running tests on all trace events:
> Testing all events: OK
>
> Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
> ---
> kernel/trace/trace_events.c | 176 +++++++++++++++++++++++++++++++++++++++++++
> 1 files changed, 176 insertions(+), 0 deletions(-)
>
> diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
> index 6591d83..6d5b1bd 100644
> --- a/kernel/trace/trace_events.c
> +++ b/kernel/trace/trace_events.c
> @@ -8,6 +8,9 @@
> *
> */
>
> +#include <linux/workqueue.h>
> +#include <linux/spinlock.h>
> +#include <linux/kthread.h>
> #include <linux/debugfs.h>
> #include <linux/uaccess.h>
> #include <linux/module.h>
> @@ -920,3 +923,176 @@ static __init int event_trace_init(void)
> return 0;
> }
> fs_initcall(event_trace_init);
> +
> +#ifdef CONFIG_FTRACE_STARTUP_TEST
> +
> +static DEFINE_SPINLOCK(test_spinlock);
> +static DEFINE_SPINLOCK(test_spinlock_irq);
> +static DEFINE_MUTEX(test_mutex);
> +
> +static __init void test_work(struct work_struct *dummy)
> +{
> + spin_lock(&test_spinlock);
> + spin_lock_irq(&test_spinlock_irq);
> + udelay(1);
> + spin_unlock_irq(&test_spinlock_irq);
> + spin_unlock(&test_spinlock);
> +
> + mutex_lock(&test_mutex);
> + msleep(1);
> + mutex_unlock(&test_mutex);
> +}
> +
> +static __init int event_test_thread(void *unused)
> +{
> + void *test_malloc;
> +
> + test_malloc = kmalloc(1234, GFP_KERNEL);
> + if (!test_malloc)
> + pr_info("failed to kmalloc\n");
> +
> + schedule_on_each_cpu(test_work);
> +
> + kfree(test_malloc);
> +
> + while (!kthread_should_stop())
> + ;
> +
> + return 0;
> +}
> +
> +/*
> + * Do various things that may trigger events.
> + */
> +static __init void event_test_stuff(void)
> +{
> + struct task_struct *test_thread;
> +
> + test_thread = kthread_run(event_test_thread, NULL, "test-events");
> + msleep(1);
> + kthread_stop(test_thread);
> +}
> +
> +/*
> + * For every trace event defined, we will test each trace point separately,
> + * and then by groups, and finally all trace points.
> + */
> +static __init int event_trace_self_tests(void)
> +{
> + struct ftrace_event_call *call;
> + struct event_subsystem *system;
> + char *sysname;
> + int ret;
> +
> + pr_info("Running tests on trace events:\n");
> +
> + list_for_each_entry(call, &ftrace_events, list) {
> +
> + /* Only test those that have a regfunc */
> + if (!call->regfunc)
> + continue;
> +
> + pr_info("Testing event %s: ", call->name);
> +
> + /*
> + * If an event is already enabled, someone is using
> + * it and the self test should not be on.
> + */
> + if (call->enabled) {
> + pr_warning("Enabled event during self test!\n");
> + WARN_ON_ONCE(1);
> + continue;
> + }
> +
> + call->enabled = 1;
> + call->regfunc();
> +
> + event_test_stuff();
> +
> + call->unregfunc();
> + call->enabled = 0;
> +
> + pr_cont("OK\n");
> + }
> +
> + /* Now test at the sub system level */
> +
> + pr_info("Running tests on trace event systems:\n");
> +
> + list_for_each_entry(system, &event_subsystems, list) {
> +
> + /* the ftrace system is special, skip it */
> + if (strcmp(system->name, "ftrace") == 0)
> + continue;
> +
> + pr_info("Testing event system %s: ", system->name);
> +
> + /* ftrace_set_clr_event can modify the name passed in. */
> + sysname = kstrdup(system->name, GFP_KERNEL);
> + if (WARN_ON(!sysname)) {
> + pr_warning("Can't allocate memory, giving up!\n");
> + return 0;
> + }
> + ret = ftrace_set_clr_event(sysname, 1);
> + kfree(sysname);
> + if (WARN_ON_ONCE(ret)) {
> + pr_warning("error enabling system %s\n",
> + system->name);
> + continue;
> + }
> +
> + event_test_stuff();
> +
> + sysname = kstrdup(system->name, GFP_KERNEL);
> + if (WARN_ON(!sysname)) {
> + pr_warning("Can't allocate memory, giving up!\n");
> + return 0;
> + }
> + ret = ftrace_set_clr_event(sysname, 0);
> + kfree(sysname);
> +
> + if (WARN_ON_ONCE(ret))
> + pr_warning("error disabling system %s\n",
> + system->name);
> +
> + pr_cont("OK\n");
> + }
> +
> + /* Test with all events enabled */
> +
> + pr_info("Running tests on all trace events:\n");
> + pr_info("Testing all events: ");
> +
> + sysname = kmalloc(4, GFP_KERNEL);
> + if (WARN_ON(!sysname)) {
> + pr_warning("Can't allocate memory, giving up!\n");
> + return 0;
> + }
> + memcpy(sysname, "*:*", 4);
> + ret = ftrace_set_clr_event(sysname, 1);
> + if (WARN_ON_ONCE(ret)) {
> + kfree(sysname);
> + pr_warning("error enabling all events\n");
> + return 0;
> + }
> +
> + event_test_stuff();
> +
> + /* reset sysname */
> + memcpy(sysname, "*:*", 4);
Nano thing, because you are using it twice:
Why not strcpy?
Frederic.
> + ret = ftrace_set_clr_event(sysname, 0);
> + kfree(sysname);
> +
> + if (WARN_ON_ONCE(ret)) {
> + pr_warning("error disabling all events\n");
> + return 0;
> + }
> +
> + pr_cont("OK\n");
> +
> + return 0;
> +}
> +
> +late_initcall(event_trace_self_tests);
> +
> +#endif
> --
> 1.6.2.1
>
> --
next prev parent reply other threads:[~2009-04-16 15:41 UTC|newest]
Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-04-16 2:18 [PATCH 0/5] [GIT PULL] updates for tip Steven Rostedt
2009-04-16 2:18 ` [PATCH 1/5] ftrace: use module notifier for function tracer Steven Rostedt
2009-04-16 15:36 ` Frederic Weisbecker
2009-04-16 15:53 ` Steven Rostedt
2009-04-17 11:44 ` Steven Rostedt
2009-04-19 11:25 ` Rusty Russell
2009-04-20 13:57 ` Steven Rostedt
2009-04-21 5:15 ` Rusty Russell
2009-04-21 13:13 ` Steven Rostedt
2009-04-21 13:58 ` Ingo Molnar
2009-04-21 17:51 ` Tim Abbott
2009-04-21 18:17 ` Steven Rostedt
2009-04-21 18:47 ` Tim Abbott
2009-04-22 9:16 ` Ingo Molnar
2009-04-22 22:20 ` Tim Abbott
2009-04-22 22:57 ` Masami Hiramatsu
2009-04-23 19:40 ` Anders Kaseorg
2009-04-23 19:57 ` Mathieu Desnoyers
2009-04-23 22:31 ` Tim Abbott
2009-04-24 3:11 ` Masami Hiramatsu
2009-04-23 20:06 ` Masami Hiramatsu
2009-04-16 2:18 ` [PATCH 2/5] tracing/events: add startup tests for events Steven Rostedt
2009-04-16 8:39 ` [PATCH] tracing: add #include <linux/delay.h> to fix build failure in test_work() Ingo Molnar
2009-04-16 14:08 ` Steven Rostedt
2009-04-17 0:30 ` Ingo Molnar
2009-04-16 15:41 ` Frederic Weisbecker [this message]
2009-04-16 15:51 ` [PATCH 2/5] tracing/events: add startup tests for events Steven Rostedt
2009-04-16 16:02 ` Frederic Weisbecker
2009-04-16 2:18 ` [PATCH 3/5] tracing/events: add rcu locking around trace event prints Steven Rostedt
2009-04-17 14:08 ` Steven Rostedt
2009-04-17 15:20 ` Jeremy Fitzhardinge
2009-04-17 15:42 ` Steven Rostedt
2009-04-17 23:53 ` Jeremy Fitzhardinge
2009-04-17 16:18 ` Theodore Tso
2009-04-17 16:32 ` Jeremy Fitzhardinge
2009-04-17 16:41 ` Steven Rostedt
2009-05-07 2:10 ` Steven Rostedt
2009-05-07 11:32 ` Ingo Molnar
2009-05-07 13:10 ` Steven Rostedt
2009-04-16 2:18 ` [PATCH 4/5] tracing/events/ring-buffer: expose format of ring buffer headers to users Steven Rostedt
2009-04-16 2:18 ` [PATCH 5/5] tracing: add saved_cmdlines file to show cached task comms Steven Rostedt
2009-04-16 15:54 ` Frederic Weisbecker
2009-04-16 15:58 ` Steven Rostedt
2009-04-16 16:05 ` Frederic Weisbecker
2009-04-16 9:51 ` [PATCH 0/5] [GIT PULL] updates for tip Ingo Molnar
2009-04-16 9:53 ` Ingo Molnar
2009-04-16 13:52 ` Steven Rostedt
2009-04-16 16:12 ` Ingo Molnar
2009-04-16 16:22 ` Steven Rostedt
2009-04-17 0:29 ` Ingo Molnar
2009-04-16 16:30 ` Ingo Molnar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20090416154132.GC6004@nowhere \
--to=fweisbec@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).