static uint64_t g_start_time;
static uint64_t g_hwc_offset;
-static int g_task_on;
+static struct task_struct *g_task;
static uint32_t g_err_count;
-static struct completion g_completion;
-
static int g_zlog_enable = 1;
module_param_named(zlog_enable, g_zlog_enable, int, 0644);
int tmp_bkt;
int blk;
- do {
+ while (!kthread_should_stop()) {
hash_for_each_safe(g_thread_table->data, tmp_bkt, tmp_iter, ptr, next) {
blk = ptr->blk;
// TODO: g_start_time should be under some kind of mutex.
}
}
- // TODO: This makes no sense.
- wait_for_completion_interruptible_timeout(&g_completion, msecs_to_jiffies(MS_PER_SEC * 5));
- } while (1);
-
- g_task_on = 0;
- do_exit(0);
-
- return 0;
-}
-
-static void run_task(void)
-{
- struct task_struct *task;
-
- if (!mutex_trylock(&g_task_mutex))
- return;
-
- if (g_task_on) {
- // TODO: this mutex is either incorrect or nonsensical,
- // since the other task will not end (it is an infinite loop after all).
- mutex_unlock(&g_task_mutex);
- complete(&g_completion);
- return;
+ schedule_timeout_interruptible(msecs_to_jiffies(MS_PER_SEC * 5));
}
- g_task_on = 1;
- mutex_unlock(&g_task_mutex);
- task = kthread_run(zlog_task, NULL, "zlog_task");
- if (IS_ERR(task)) {
- pr_err("Failed to run zlog_task\n");
- g_task_on = 0;
- }
+ return 0;
}
static struct thread_table_field *alloc_block_for_thread(bool is_stdout)
mutex_init(&g_block_mutex);
mutex_init(&g_task_mutex);
- init_completion(&g_completion);
-
queue_init(&g_free_q, "free", ZLOGGER_BLOCK_COUNT);
for (i = 1; i <= ZLOGGER_BLOCK_COUNT; i++)
queue_push(&g_free_q, i);
#ifdef CONFIG_TRACE_CLOCK
g_hwc_offset = trace_clock_local() - ktime_get_ns();
#endif
- run_task();
+ g_task = kthread_run(zlog_task, NULL, "zlog_task");
+ if (IS_ERR(g_task)) {
+ pr_err("Failed to run zlog_task\n");
+ goto out_free_g_thread_table_g_shm_ptr;
+ }
zlogger_device.minor = MISC_DYNAMIC_MINOR;
zlogger_device.name = ZLOGGER_DEVICE_NAME;
misc_deregister(&zlogger_device);
out_free_zlog_task:
- /* TODO: actually destroy this task.
- * We don't do so yet, even in zlogger_exit (see TODO there).
- */
+ kthread_stop(g_task);
out_free_g_thread_table_g_shm_ptr:
for (i = 0; i < g_shm_ptr_i; ++i) {
misc_deregister(&zlogger_dump_device);
misc_deregister(&zlogger_device);
- // TODO: What about the task that is running in the background?
+ kthread_stop(g_task);
queue_deinit(&g_free_q);
hash_for_each_safe(g_thread_table->data, tmp_bkt, tmp_iter, ptr, next) {