linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jiri Olsa <jolsa@redhat.com>
To: acme@redhat.com, a.p.zijlstra@chello.nl, mingo@elte.hu,
	paulus@samba.org, cjashfor@linux.vnet.ibm.com,
	fweisbec@gmail.com
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH 5/5] unwind, test: Add backtrace unwind test code
Date: Fri, 10 Feb 2012 12:25:19 +0100	[thread overview]
Message-ID: <1328873119-21553-6-git-send-email-jolsa@redhat.com> (raw)
In-Reply-To: <1328873119-21553-1-git-send-email-jolsa@redhat.com>

Adding test code for backtrace unwinding. The debugfs file
'unwind_test' is created in debugfs root. Writing to this
file triggers backtrace from process and irq context.

Mostly stolen from kernel/backtracetest.c. Getting following
output in dmesg:

 # echo > ./unwind_test
 Testing unwind from process context.
 unwind backtrace:
     [0xffffffff810ef759] unw_backtrace+0x29/0x80
     [0xffffffff810ef7d4] test_write+0x24/0x90
     [0xffffffff81138940] vfs_write+0xd0/0x1a0
     [0xffffffff81138b14] sys_write+0x54/0xa0
     [0xffffffff814d7352] system_call_fastpath+0x16/0x1b
 Testing a unwind from irq context.
 unwind backtrace:
     [0xffffffff810ef759] unw_backtrace+0x29/0x80
     [0xffffffff810ef84e] unwind_test_irq_callback+0xe/0x20
     [0xffffffff8103d1c3] tasklet_action+0x143/0x150
     [0xffffffff8103d9bd] __do_softirq+0xdd/0x250
     [0xffffffff8103dc18] run_ksoftirqd+0xe8/0x200
     [0xffffffff8105a1b6] kthread+0xc6/0xd0
     [0xffffffff814d8564] kernel_thread_helper+0x4/0x10
---
 kernel/unwind.c |   44 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 44 insertions(+), 0 deletions(-)

diff --git a/kernel/unwind.c b/kernel/unwind.c
index f5191d5..5a8c5bb 100644
--- a/kernel/unwind.c
+++ b/kernel/unwind.c
@@ -178,3 +178,47 @@ void unw_backtrace(void)
 	} while (!unw_step(&unw));
 
 }
+
+static DECLARE_COMPLETION(unwind_work);
+
+static void unwind_test_irq_callback(unsigned long data)
+{
+	unw_backtrace();
+	complete(&unwind_work);
+}
+
+static DECLARE_TASKLET(unwind_tasklet, &unwind_test_irq_callback, 0);
+
+static void unw_test_irq(void)
+{
+        printk("Testing a unwind from irq context.\n");
+
+        init_completion(&unwind_work);
+        tasklet_schedule(&unwind_tasklet);
+        wait_for_completion(&unwind_work);
+}
+
+static ssize_t
+test_write(struct file *filp, const char __user *ubuf,
+	   size_t cnt, loff_t *ppos)
+{
+	printk("Testing unwind from process context.\n");
+	unw_backtrace();
+	unw_test_irq();
+	return cnt;
+}
+
+static const struct file_operations test_fops = {
+	.write = test_write,
+};
+
+static int __init unwind_init_test(void)
+{
+	if (!debugfs_create_file("unwind_test", 0644, NULL, NULL,
+				 &test_fops))
+		return -ENOMEM;
+
+	return 0;
+}
+
+late_initcall(unwind_init_test);
-- 
1.7.1


  parent reply	other threads:[~2012-02-10 11:25 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-10 11:25 [RFC 0/5] kernel: backtrace unwind support Jiri Olsa
2012-02-10 11:25 ` [PATCH 1/5] unwind, kconfig: Adding UNWIND* options Jiri Olsa
2012-02-10 11:25 ` [PATCH 2/5] unwind, x86: Generate exception frames data for UNWIND_EH_FRAME option Jiri Olsa
2012-02-10 11:25 ` [PATCH 3/5] unwind, dwarf: Add dwarf unwind support Jiri Olsa
2012-02-10 11:25 ` [PATCH 4/5] unwind, api: Add unwind interface and implementation for x86_64 Jiri Olsa
2012-02-10 11:25 ` Jiri Olsa [this message]
2012-02-10 17:43 ` [RFC 0/5] kernel: backtrace unwind support Peter Zijlstra
2012-02-10 18:59   ` Linus Torvalds
2012-02-10 19:27     ` Arnaldo Carvalho de Melo
2012-02-10 19:32       ` Linus Torvalds
2012-02-10 19:39         ` Arnaldo Carvalho de Melo
2012-02-10 19:42           ` Arnaldo Carvalho de Melo
2012-02-10 19:44       ` Ingo Molnar
2012-02-10 20:18         ` Jiri Olsa
2012-02-10 20:37           ` Linus Torvalds
2012-02-14  2:22             ` Benjamin Herrenschmidt
2012-02-11 14:38           ` Ingo Molnar
2012-02-11 23:36             ` Jiri Olsa
2012-02-11  3:25         ` Frederic Weisbecker

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=1328873119-21553-6-git-send-email-jolsa@redhat.com \
    --to=jolsa@redhat.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@redhat.com \
    --cc=cjashfor@linux.vnet.ibm.com \
    --cc=fweisbec@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=paulus@samba.org \
    /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).