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/nvgpu/include | |
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/nvgpu/include')
-rw-r--r-- | drivers/gpu/nvgpu/include/nvgpu/linux/thread.h | 26 | ||||
-rw-r--r-- | drivers/gpu/nvgpu/include/nvgpu/thread.h | 62 |
2 files changed, 88 insertions, 0 deletions
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__ */ | ||