Skip to content

Commit

Permalink
backtracetest: Convert from tasklet to BH workqueue
Browse files Browse the repository at this point in the history
The only generic interface to execute asynchronously in the BH context is
tasklet; however, it's marked deprecated and has some design flaws. To
replace tasklets, BH workqueue support was recently added. A BH workqueue
behaves similarly to regular workqueues except that the queued work items
are executed in the BH context.

This patch converts backtracetest from tasklet to BH workqueue.

- Replace "irq" with "bh" in names and message to better reflect what's
  happening.

- Replace completion usage with a flush_work() call.

Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Arjan van de Ven <arjan@linux.intel.com>
  • Loading branch information
Tejun Heo committed Feb 5, 2024
1 parent 8eb17dc commit 7245d24
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions kernel/backtracetest.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,20 @@ static void backtrace_test_normal(void)
dump_stack();
}

static DECLARE_COMPLETION(backtrace_work);

static void backtrace_test_irq_callback(unsigned long data)
static void backtrace_test_bh_workfn(struct work_struct *work)
{
dump_stack();
complete(&backtrace_work);
}

static DECLARE_TASKLET_OLD(backtrace_tasklet, &backtrace_test_irq_callback);
static DECLARE_WORK(backtrace_bh_work, &backtrace_test_bh_workfn);

static void backtrace_test_irq(void)
static void backtrace_test_bh(void)
{
pr_info("Testing a backtrace from irq context.\n");
pr_info("Testing a backtrace from BH context.\n");
pr_info("The following trace is a kernel self test and not a bug!\n");

init_completion(&backtrace_work);
tasklet_schedule(&backtrace_tasklet);
wait_for_completion(&backtrace_work);
queue_work(system_bh_wq, &backtrace_bh_work);
flush_work(&backtrace_bh_work);
}

#ifdef CONFIG_STACKTRACE
Expand All @@ -65,7 +61,7 @@ static int backtrace_regression_test(void)
pr_info("====[ backtrace testing ]===========\n");

backtrace_test_normal();
backtrace_test_irq();
backtrace_test_bh();
backtrace_test_saved();

pr_info("====[ end of backtrace testing ]====\n");
Expand Down

0 comments on commit 7245d24

Please sign in to comment.