diff --git a/drivers/gpu/nvgpu/common/linux/thread.c b/drivers/gpu/nvgpu/common/linux/thread.c index ef783bbe3..fe3906eb3 100644 --- a/drivers/gpu/nvgpu/common/linux/thread.c +++ b/drivers/gpu/nvgpu/common/linux/thread.c @@ -18,15 +18,28 @@ #include +int nvgpu_thread_proxy(void *threaddata) +{ + struct nvgpu_thread *thread = threaddata; + int ret = thread->fn(thread->data); + + thread->running = false; + return ret; +} + int nvgpu_thread_create(struct nvgpu_thread *thread, void *data, int (*threadfn)(void *data), const char *name) { - struct task_struct *task = kthread_create(threadfn, data, name); + struct task_struct *task = kthread_create(nvgpu_thread_proxy, + thread, name); if (IS_ERR(task)) return PTR_ERR(task); thread->task = task; + thread->fn = threadfn; + thread->data = data; + thread->running = true; wake_up_process(task); return 0; }; @@ -44,5 +57,5 @@ bool nvgpu_thread_should_stop(struct nvgpu_thread *thread) bool nvgpu_thread_is_running(struct nvgpu_thread *thread) { - return thread->task != NULL; + return ACCESS_ONCE(thread->running); }; diff --git a/drivers/gpu/nvgpu/include/nvgpu/linux/thread.h b/drivers/gpu/nvgpu/include/nvgpu/linux/thread.h index 13f295157..1355319c5 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/linux/thread.h +++ b/drivers/gpu/nvgpu/include/nvgpu/linux/thread.h @@ -21,6 +21,9 @@ struct task_struct; struct nvgpu_thread { struct task_struct *task; + bool running; + int (*fn)(void *); + void *data; }; #endif /* __NVGPU_THREAD_LINUX_H__ */