gpu: nvgpu: mark thread stopped when it independently quits

It's technically possible for a thread to exit without first calling
nvgpu_thread_stop() in another, so mark the thread exit status from the
thread after it has finished instead of in nvgpu_thread_stop(). Do this
by starting the thread as a proxy function which calls the actual thread
function and then sets the flag.

Also, add a new flag to actually signify the running state because the
thread->task going null abruptly would break nvgpu_thread_stop().

This does not guarantee that the kernel thread itself has stopped, but
the function which can be considered as an "nvgpu thread" will be.

Change-Id: Ib911b02bd51342ddeb8e6b9533ef7943f2606d2d
Signed-off-by: Konsta Holtta <kholtta@nvidia.com>
Reviewed-on: http://git-master/r/1501571
Reviewed-by: Mahantesh Kumbar <mkumbar@nvidia.com>
Reviewed-by: Alex Waterman <alexw@nvidia.com>
Reviewed-by: svccoveritychecker <svccoveritychecker@nvidia.com>
GVS: Gerrit_Virtual_Submit
Reviewed-by: Vijayakumar Subbu <vsubbu@nvidia.com>
This commit is contained in:
Konsta Holtta
2017-06-13 16:15:47 +03:00
committed by mobile promotions
parent 741e5c4517
commit 9d2e773051
2 changed files with 18 additions and 2 deletions

View File

@@ -18,15 +18,28 @@
#include <nvgpu/thread.h>
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);
};