diff options
author | Terje Bergstrom <tbergstrom@nvidia.com> | 2017-04-25 12:00:47 -0400 |
---|---|---|
committer | mobile promotions <svcmobile_promotions@nvidia.com> | 2017-05-04 12:14:39 -0400 |
commit | fc95237cf08975983634fd6d3ad85634f80a8a55 (patch) | |
tree | 34d89a0301552fd4e0830e16f455d5c5514f0a81 /drivers/gpu | |
parent | aeb14da4a0432eb852cd99f733524fd7633529f5 (diff) |
gpu: nvgpu: Abstract threads
Add abstraction for threads. Implement them using kthreads in Linux kernel.
JIRA NVGPU-14
Change-Id: I26996d844db6bdc4b5e6f3230514a1dadb3fb07c
Signed-off-by: Terje Bergstrom <tbergstrom@nvidia.com>
Reviewed-on: http://git-master/r/1469636
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
Diffstat (limited to 'drivers/gpu')
-rw-r--r-- | drivers/gpu/nvgpu/Makefile.nvgpu | 1 | ||||
-rw-r--r-- | drivers/gpu/nvgpu/common/linux/thread.c | 42 | ||||
-rw-r--r-- | drivers/gpu/nvgpu/include/nvgpu/linux/thread.h | 26 | ||||
-rw-r--r-- | drivers/gpu/nvgpu/include/nvgpu/thread.h | 62 |
4 files changed, 131 insertions, 0 deletions
diff --git a/drivers/gpu/nvgpu/Makefile.nvgpu b/drivers/gpu/nvgpu/Makefile.nvgpu index 8ed7f125..08d939f0 100644 --- a/drivers/gpu/nvgpu/Makefile.nvgpu +++ b/drivers/gpu/nvgpu/Makefile.nvgpu | |||
@@ -37,6 +37,7 @@ nvgpu-y := \ | |||
37 | common/linux/soc.o \ | 37 | common/linux/soc.o \ |
38 | common/linux/driver_common.o \ | 38 | common/linux/driver_common.o \ |
39 | common/linux/firmware.o \ | 39 | common/linux/firmware.o \ |
40 | common/linux/thread.o \ | ||
40 | common/mm/nvgpu_allocator.o \ | 41 | common/mm/nvgpu_allocator.o \ |
41 | common/mm/bitmap_allocator.o \ | 42 | common/mm/bitmap_allocator.o \ |
42 | common/mm/buddy_allocator.o \ | 43 | common/mm/buddy_allocator.o \ |
diff --git a/drivers/gpu/nvgpu/common/linux/thread.c b/drivers/gpu/nvgpu/common/linux/thread.c new file mode 100644 index 00000000..d37b2a10 --- /dev/null +++ b/drivers/gpu/nvgpu/common/linux/thread.c | |||
@@ -0,0 +1,42 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved. | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify it | ||
5 | * under the terms and conditions of the GNU General Public License, | ||
6 | * version 2, as published by the Free Software Foundation. | ||
7 | * | ||
8 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
11 | * more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | */ | ||
16 | |||
17 | #include <linux/kthread.h> | ||
18 | |||
19 | #include <nvgpu/thread.h> | ||
20 | |||
21 | int nvgpu_thread_create(struct nvgpu_thread *thread, | ||
22 | void *data, | ||
23 | int (*threadfn)(void *data), const char *name) | ||
24 | { | ||
25 | struct task_struct *task = kthread_create(threadfn, data, name); | ||
26 | if (IS_ERR(task)) | ||
27 | return PTR_ERR(task); | ||
28 | |||
29 | thread->task = task; | ||
30 | wake_up_process(task); | ||
31 | return 0; | ||
32 | }; | ||
33 | |||
34 | void nvgpu_thread_stop(struct nvgpu_thread *thread) | ||
35 | { | ||
36 | kthread_stop(thread->task); | ||
37 | }; | ||
38 | |||
39 | bool nvgpu_thread_should_stop(struct nvgpu_thread *thread) | ||
40 | { | ||
41 | return kthread_should_stop(); | ||
42 | }; | ||
diff --git a/drivers/gpu/nvgpu/include/nvgpu/linux/thread.h b/drivers/gpu/nvgpu/include/nvgpu/linux/thread.h new file mode 100644 index 00000000..13f29515 --- /dev/null +++ b/drivers/gpu/nvgpu/include/nvgpu/linux/thread.h | |||
@@ -0,0 +1,26 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved. | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify it | ||
5 | * under the terms and conditions of the GNU General Public License, | ||
6 | * version 2, as published by the Free Software Foundation. | ||
7 | * | ||
8 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
11 | * more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | */ | ||
16 | |||
17 | #ifndef __NVGPU_THREAD_LINUX_H__ | ||
18 | #define __NVGPU_THREAD_LINUX_H__ | ||
19 | |||
20 | struct task_struct; | ||
21 | |||
22 | struct nvgpu_thread { | ||
23 | struct task_struct *task; | ||
24 | }; | ||
25 | |||
26 | #endif /* __NVGPU_THREAD_LINUX_H__ */ | ||
diff --git a/drivers/gpu/nvgpu/include/nvgpu/thread.h b/drivers/gpu/nvgpu/include/nvgpu/thread.h new file mode 100644 index 00000000..81dac7ca --- /dev/null +++ b/drivers/gpu/nvgpu/include/nvgpu/thread.h | |||
@@ -0,0 +1,62 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved. | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify it | ||
5 | * under the terms and conditions of the GNU General Public License, | ||
6 | * version 2, as published by the Free Software Foundation. | ||
7 | * | ||
8 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
11 | * more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | */ | ||
16 | |||
17 | #ifndef __NVGPU_THREAD_H__ | ||
18 | #define __NVGPU_THREAD_H__ | ||
19 | |||
20 | #ifdef __KERNEL__ | ||
21 | #include <nvgpu/linux/thread.h> | ||
22 | #endif | ||
23 | |||
24 | /** | ||
25 | * nvgpu_thread_create - Create and run a new thread. | ||
26 | * | ||
27 | * @thread - thread structure to use | ||
28 | * @data - data to pass to threadfn | ||
29 | * @threadfn - Thread function | ||
30 | * @name - name of the thread | ||
31 | * | ||
32 | * Create a thread and run threadfn in it. The thread stays alive as long as | ||
33 | * threadfn is running. As soon as threadfn returns the thread is destroyed. | ||
34 | * | ||
35 | * threadfn needs to continuously poll nvgpu_thread_should_stop() to determine | ||
36 | * if it should exit. | ||
37 | */ | ||
38 | int nvgpu_thread_create(struct nvgpu_thread *thread, | ||
39 | void *data, | ||
40 | int (*threadfn)(void *data), const char *name); | ||
41 | |||
42 | /** | ||
43 | * nvgpu_thread_stop - Destroy or request to destroy a thread | ||
44 | * | ||
45 | * @thread - thread to stop | ||
46 | * | ||
47 | * Request a thread to stop by setting nvgpu_thread_should_stop() to | ||
48 | * true and wait for thread to exit. | ||
49 | */ | ||
50 | void nvgpu_thread_stop(struct nvgpu_thread *thread); | ||
51 | |||
52 | /** | ||
53 | * nvgpu_thread_should_stop - Query if thread should stop | ||
54 | * | ||
55 | * @thread | ||
56 | * | ||
57 | * Return true if thread should exit. Can be run only in the thread's own | ||
58 | * context and with the thread as parameter. | ||
59 | */ | ||
60 | bool nvgpu_thread_should_stop(struct nvgpu_thread *thread); | ||
61 | |||
62 | #endif /* __NVGPU_THREAD_H__ */ | ||