summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/nvgpu
diff options
context:
space:
mode:
authorAlex Waterman <alexw@nvidia.com>2016-11-11 17:35:54 -0500
committermobile promotions <svcmobile_promotions@nvidia.com>2016-12-05 19:16:16 -0500
commitd8fd0e64678997b535c3208ce8cc081b1cac7fa9 (patch)
tree25b93f0c10de6bfe2450b9e189bb4ee5bff28182 /drivers/gpu/nvgpu
parent37d4b649d43e1024859d56becfaaa25a0a41868c (diff)
gpu: nvgpu: Add timeout API
Add a timeout API to nvgpu since this is a common operation done all across the nvgpu driver. Also add two new directories for this common code: drivers/gpu/nvgpu/common drivers/gpu/nvgpu/include/nvgpu The common directory is for common C code. The include directory is for common include files. Bug 1799159 Change-Id: I8b710eecaa75c0707df83f859fb28484525185a6 Signed-off-by: Alex Waterman <alexw@nvidia.com> Reviewed-on: http://git-master/r/1255864 GVS: Gerrit_Virtual_Submit Reviewed-by: Terje Bergstrom <tbergstrom@nvidia.com>
Diffstat (limited to 'drivers/gpu/nvgpu')
-rw-r--r--drivers/gpu/nvgpu/Makefile.nvgpu6
-rw-r--r--drivers/gpu/nvgpu/common/linux/timers.c177
-rw-r--r--drivers/gpu/nvgpu/include/nvgpu/timers.h94
3 files changed, 275 insertions, 2 deletions
diff --git a/drivers/gpu/nvgpu/Makefile.nvgpu b/drivers/gpu/nvgpu/Makefile.nvgpu
index 96cdfb0a..71077386 100644
--- a/drivers/gpu/nvgpu/Makefile.nvgpu
+++ b/drivers/gpu/nvgpu/Makefile.nvgpu
@@ -1,10 +1,11 @@
1GCOV_PROFILE := y 1GCOV_PROFILE := y
2 2
3ccflags-y += -Idrivers/gpu/nvgpu 3ccflags-y += -Idrivers/gpu/nvgpu/include
4ccflags-y += -Idrivers/video/tegra/host 4ccflags-y += -Idrivers/video/tegra/host
5ccflags-y += -Idrivers/devfreq 5ccflags-y += -Idrivers/devfreq
6ccflags-y += -I../nvgpu/include 6ccflags-y += -I../nvgpu/include
7ccflags-y += -I../nvgpu/include/uapi 7ccflags-y += -I../nvgpu/include/uapi
8ccflags-y += -I../nvgpu/drivers/gpu/nvgpu/include
8ccflags-y += -Wno-multichar 9ccflags-y += -Wno-multichar
9ccflags-y += -Werror 10ccflags-y += -Werror
10ccflags-y += -Wno-error=cpp 11ccflags-y += -Wno-error=cpp
@@ -25,8 +26,9 @@ endif
25obj-$(CONFIG_GK20A) := nvgpu.o 26obj-$(CONFIG_GK20A) := nvgpu.o
26 27
27nvgpu-y := \ 28nvgpu-y := \
28 gk20a/gk20a.o \ 29 common/linux/timers.o \
29 nvgpu_common.o \ 30 nvgpu_common.o \
31 gk20a/gk20a.o \
30 gk20a/sched_gk20a.o \ 32 gk20a/sched_gk20a.o \
31 gk20a/as_gk20a.o \ 33 gk20a/as_gk20a.o \
32 gk20a/ctrl_gk20a.o \ 34 gk20a/ctrl_gk20a.o \
diff --git a/drivers/gpu/nvgpu/common/linux/timers.c b/drivers/gpu/nvgpu/common/linux/timers.c
new file mode 100644
index 00000000..e1e08f82
--- /dev/null
+++ b/drivers/gpu/nvgpu/common/linux/timers.c
@@ -0,0 +1,177 @@
1/*
2 * Copyright (c) 2016, 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/jiffies.h>
18
19#include <nvgpu/timers.h>
20
21#include "gk20a/gk20a.h"
22
23/*
24 * Returns 1 if the platform is pre-Si and should ignore the timeout checking.
25 * Setting %NVGPU_TIMER_NO_PRE_SI will make this always return 0 (i.e do the
26 * timeout check regardless of platform).
27 */
28static int nvgpu_timeout_is_pre_silicon(struct nvgpu_timeout *timeout)
29{
30 if (timeout->flags & NVGPU_TIMER_NO_PRE_SI)
31 return 0;
32
33 return !tegra_platform_is_silicon();
34}
35
36/**
37 * nvgpu_timeout_init - Init timer.
38 *
39 * @g - nvgpu device.
40 * @timeout - The timer.
41 * @duration - Timeout in milliseconds or number of retries.
42 * @flags - Flags for timer.
43 *
44 * This configures the timeout to start the timeout duration now, i.e: when this
45 * function is called. Available flags to pass to @flags:
46 *
47 * %NVGPU_TIMER_CPU_TIMER
48 * %NVGPU_TIMER_RETRY_TIMER
49 * %NVGPU_TIMER_NO_PRE_SI
50 * %NVGPU_TIMER_SILENT_TIMEOUT
51 *
52 * If neither %NVGPU_TIMER_CPU_TIMER or %NVGPU_TIMER_RETRY_TIMER is passed then
53 * a CPU timer is used by default.
54 */
55int nvgpu_timeout_init(struct gk20a *g, struct nvgpu_timeout *timeout,
56 int duration, unsigned long flags)
57{
58 if (flags & ~NVGPU_TIMER_FLAG_MASK)
59 return -EINVAL;
60
61 memset(timeout, 0, sizeof(*timeout));
62
63 timeout->g = g;
64 timeout->flags = flags;
65
66 if (flags & NVGPU_TIMER_RETRY_TIMER)
67 timeout->retries.max = duration;
68 else
69 timeout->time = jiffies + msecs_to_jiffies(duration);
70
71 return 0;
72}
73
74static int __nvgpu_timeout_check_msg_cpu(struct nvgpu_timeout *timeout,
75 void *caller,
76 const char *fmt, va_list args)
77{
78 struct gk20a *g = timeout->g;
79 unsigned long now = jiffies;
80
81 if (nvgpu_timeout_is_pre_silicon(timeout))
82 return 0;
83
84 if (time_after(now, (unsigned long)timeout->time)) {
85 if (!(timeout->flags & NVGPU_TIMER_SILENT_TIMEOUT)) {
86 char buf[128];
87
88 vsnprintf(buf, sizeof(buf), fmt, args);
89
90 dev_err(dev_from_gk20a(g),
91 "Timeout detected @ 0x%pF %s\n", caller, buf);
92 }
93
94 return -ETIMEDOUT;
95 }
96
97 return 0;
98}
99
100static int __nvgpu_timeout_check_msg_retry(struct nvgpu_timeout *timeout,
101 void *caller,
102 const char *fmt, va_list args)
103{
104 struct gk20a *g = timeout->g;
105
106 if (nvgpu_timeout_is_pre_silicon(timeout))
107 return 0;
108
109 if (timeout->retries.attempted >= timeout->retries.max) {
110 if (!(timeout->flags & NVGPU_TIMER_SILENT_TIMEOUT)) {
111 char buf[128];
112
113 vsnprintf(buf, sizeof(buf), fmt, args);
114
115 dev_err(dev_from_gk20a(g),
116 "No more retries @ 0x%pF %s\n", caller, buf);
117 }
118
119 return -ETIMEDOUT;
120 }
121
122 timeout->retries.attempted++;
123
124 return 0;
125}
126
127/**
128 * __nvgpu_timeout_check_msg - Check if a timeout has expired.
129 *
130 * @timeout - The timeout to check.
131 * @caller - Address of the caller of this function.
132 * @fmt - The fmt string.
133 *
134 * Returns -ETIMEDOUT if the timeout has expired, 0 otherwise.
135 *
136 * If a timeout occurs and %NVGPU_TIMER_SILENT_TIMEOUT is not set in the timeout
137 * then a message is printed based on %fmt.
138 */
139int __nvgpu_timeout_check_msg(struct nvgpu_timeout *timeout,
140 void *caller, const char *fmt, ...)
141{
142 int ret;
143 va_list args;
144
145 va_start(args, fmt);
146 if (timeout->flags & NVGPU_TIMER_RETRY_TIMER)
147 ret = __nvgpu_timeout_check_msg_retry(timeout, caller, fmt,
148 args);
149 else
150 ret = __nvgpu_timeout_check_msg_cpu(timeout, caller, fmt,
151 args);
152 va_end(args);
153
154 return ret;
155}
156
157/**
158 * nvgpu_timeout_peek - Check the status of a timeout.
159 *
160 * @timeout - The timeout to check.
161 *
162 * Returns non-zero if the timeout is expired, zero otherwise. In the case of
163 * retry timers this will not increment the underlying retry count. Also if the
164 * timer has expired no messages will be printed.
165 *
166 * This function honors the pre-Si check as well.
167 */
168int nvgpu_timeout_peek(struct nvgpu_timeout *timeout)
169{
170 if (nvgpu_timeout_is_pre_silicon(timeout))
171 return 0;
172
173 if (timeout->flags & NVGPU_TIMER_RETRY_TIMER)
174 return timeout->retries.attempted >= timeout->retries.max;
175 else
176 return time_after(jiffies, (unsigned long)timeout->time);
177}
diff --git a/drivers/gpu/nvgpu/include/nvgpu/timers.h b/drivers/gpu/nvgpu/include/nvgpu/timers.h
new file mode 100644
index 00000000..e46982c9
--- /dev/null
+++ b/drivers/gpu/nvgpu/include/nvgpu/timers.h
@@ -0,0 +1,94 @@
1/*
2 * Copyright (c) 2016, 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_TIMERS_H__
18#define __NVGPU_TIMERS_H__
19
20struct gk20a;
21
22/*
23 * struct nvgpu_timeout - define a timeout.
24 *
25 * There are two types of timer suported:
26 *
27 * o NVGPU_TIMER_CPU_TIMER
28 * Timer uses the CPU to measure the timeout.
29 *
30 * o NVGPU_TIMER_RETRY_TIMER
31 * Instead of measuring a time limit keep track of the number of times
32 * something has been attempted. After said limit, "expire" the timer.
33 *
34 * Available flags:
35 *
36 * o NVGPU_TIMER_NO_PRE_SI
37 * By default when the system is not running on silicon the timeout
38 * code will ignore the requested timeout. Specifying this flag will
39 * override that behavior and honor the timeout regardless of platform.
40 *
41 * o NVGPU_TIMER_SILENT_TIMEOUT
42 * Do not print any messages on timeout. Normally a simple message is
43 * printed that specifies where the timeout occurred.
44 */
45struct nvgpu_timeout {
46 struct gk20a *g;
47
48 unsigned int flags;
49
50 union {
51 unsigned long time;
52 struct {
53 int max;
54 int attempted;
55 } retries;
56 };
57};
58
59/*
60 * Bit 0 specifies the type of timer: CPU or retry.
61 */
62#define NVGPU_TIMER_CPU_TIMER (0x0)
63#define NVGPU_TIMER_RETRY_TIMER (0x1)
64
65/*
66 * Bits 1 through 7 are reserved; bits 8 and up are flags:
67 */
68#define NVGPU_TIMER_NO_PRE_SI (0x1 << 8)
69#define NVGPU_TIMER_SILENT_TIMEOUT (0x1 << 9)
70
71#define NVGPU_TIMER_FLAG_MASK (NVGPU_TIMER_RETRY_TIMER | \
72 NVGPU_TIMER_NO_PRE_SI | \
73 NVGPU_TIMER_SILENT_TIMEOUT)
74
75int nvgpu_timeout_init(struct gk20a *g, struct nvgpu_timeout *timeout,
76 int duration, unsigned long flags);
77int nvgpu_timeout_peek(struct nvgpu_timeout *timeout);
78
79#define nvgpu_timeout_check(__timeout) \
80 __nvgpu_timeout_check_msg(__timeout, \
81 __builtin_return_address(0), "")
82
83#define nvgpu_timeout_check_msg(__timeout, fmt, args...) \
84 __nvgpu_timeout_check_msg(__timeout, \
85 __builtin_return_address(0), \
86 fmt, ##args)
87
88/*
89 * Don't use this directly.
90 */
91int __nvgpu_timeout_check_msg(struct nvgpu_timeout *timeout,
92 void *caller, const char *fmt, ...);
93
94#endif