Commit 4e6a0535dd036377961027262aecb138099f925d

Authored by Vegard Nossum
Committed by Ingo Molnar
1 parent ad118c54a3

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>

Showing 1 changed file with 26 additions and 11 deletions Side-by-side Diff

kernel/backtracetest.c
... ... @@ -10,18 +10,39 @@
10 10 * of the License.
11 11 */
12 12  
  13 +#include <linux/completion.h>
13 14 #include <linux/delay.h>
  15 +#include <linux/interrupt.h>
14 16 #include <linux/module.h>
15 17 #include <linux/sched.h>
16 18 #include <linux/stacktrace.h>
17 19  
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");
19 24  
20   -static void backtrace_test_timer(unsigned long data)
  25 + dump_stack();
  26 +}
  27 +
  28 +static DECLARE_COMPLETION(backtrace_work);
  29 +
  30 +static void backtrace_test_irq_callback(unsigned long data)
21 31 {
  32 + dump_stack();
  33 + complete(&backtrace_work);
  34 +}
  35 +
  36 +static DECLARE_TASKLET(backtrace_tasklet, &backtrace_test_irq_callback, 0);
  37 +
  38 +static void backtrace_test_irq(void)
  39 +{
22 40 printk("Testing a backtrace from irq context.\n");
23 41 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);
25 46 }
26 47  
27 48 #ifdef CONFIG_STACKTRACE
28 49  
29 50  
... ... @@ -51,17 +72,11 @@
51 72 static int backtrace_regression_test(void)
52 73 {
53 74 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();
57 75  
  76 + backtrace_test_normal();
  77 + backtrace_test_irq();
58 78 backtrace_test_saved();
59 79  
60   - init_timer(&backtrace_timer);
61   - backtrace_timer.function = backtrace_test_timer;
62   - mod_timer(&backtrace_timer, jiffies + 10);
63   -
64   - msleep(10);
65 80 printk("====[ end of backtrace testing ]====\n");
66 81 return 0;
67 82 }