Skip to content

Commit 4e6a053

Browse files
vegardIngo Molnar
authored andcommitted
backtrace: replace timer with tasklet + completions
On qemu, the backtrace would show up _after_ the "end of backtrace testing" message. This patch changes it to use completions instead, which will guarantee that no such race exists. Cc: Arjan van de Ven <arjan@infradead.org> Signed-off-by: Vegard Nossum <vegard.nossum@gmail.com> Cc: Arjan van de Ven <arjan@infradead.org> Cc: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Ingo Molnar <mingo@elte.hu>
1 parent ad118c5 commit 4e6a053

1 file changed

Lines changed: 26 additions & 11 deletions

File tree

‎kernel/backtracetest.c‎

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,39 @@
1010
* of the License.
1111
*/
1212

13+
#include <linux/completion.h>
1314
#include <linux/delay.h>
15+
#include <linux/interrupt.h>
1416
#include <linux/module.h>
1517
#include <linux/sched.h>
1618
#include <linux/stacktrace.h>
1719

18-
static struct timer_list backtrace_timer;
20+
static void backtrace_test_normal(void)
21+
{
22+
printk("Testing a backtrace from process context.\n");
23+
printk("The following trace is a kernel self test and not a bug!\n");
24+
25+
dump_stack();
26+
}
27+
28+
static DECLARE_COMPLETION(backtrace_work);
29+
30+
static void backtrace_test_irq_callback(unsigned long data)
31+
{
32+
dump_stack();
33+
complete(&backtrace_work);
34+
}
35+
36+
static DECLARE_TASKLET(backtrace_tasklet, &backtrace_test_irq_callback, 0);
1937

20-
static void backtrace_test_timer(unsigned long data)
38+
static void backtrace_test_irq(void)
2139
{
2240
printk("Testing a backtrace from irq context.\n");
2341
printk("The following trace is a kernel self test and not a bug!\n");
24-
dump_stack();
42+
43+
init_completion(&backtrace_work);
44+
tasklet_schedule(&backtrace_tasklet);
45+
wait_for_completion(&backtrace_work);
2546
}
2647

2748
#ifdef CONFIG_STACKTRACE
@@ -51,17 +72,11 @@ static void backtrace_test_saved(void)
5172
static int backtrace_regression_test(void)
5273
{
5374
printk("====[ backtrace testing ]===========\n");
54-
printk("Testing a backtrace from process context.\n");
55-
printk("The following trace is a kernel self test and not a bug!\n");
56-
dump_stack();
5775

76+
backtrace_test_normal();
77+
backtrace_test_irq();
5878
backtrace_test_saved();
5979

60-
init_timer(&backtrace_timer);
61-
backtrace_timer.function = backtrace_test_timer;
62-
mod_timer(&backtrace_timer, jiffies + 10);
63-
64-
msleep(10);
6580
printk("====[ end of backtrace testing ]====\n");
6681
return 0;
6782
}

0 commit comments

Comments
 (0)