diff options
author | Terje Bergstrom <tbergstrom@nvidia.com> | 2018-04-18 15:59:00 -0400 |
---|---|---|
committer | mobile promotions <svcmobile_promotions@nvidia.com> | 2018-06-15 20:47:31 -0400 |
commit | 2a2c16af5f9f1ccfc93a13e820d5381e5c881e92 (patch) | |
tree | 2e5d7b042270a649978e5bb540857012c85fb5b5 /drivers/gpu/nvgpu/common/linux/debug_fifo.c | |
parent | 98d996f4ffb0137d119b5849cae46d7b7e5693e1 (diff) |
gpu: nvgpu: Move Linux files away from common
Move all Linux source code files to drivers/gpu/nvgpu/os/linux from
drivers/gpu/nvgpu/common/linux. This changes the meaning of common
to be OS independent.
JIRA NVGPU-598
JIRA NVGPU-601
Change-Id: Ib7f2a43d3688bb0d0b7dcc48469a6783fd988ce9
Signed-off-by: Terje Bergstrom <tbergstrom@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/1747714
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
Diffstat (limited to 'drivers/gpu/nvgpu/common/linux/debug_fifo.c')
-rw-r--r-- | drivers/gpu/nvgpu/common/linux/debug_fifo.c | 378 |
1 files changed, 0 insertions, 378 deletions
diff --git a/drivers/gpu/nvgpu/common/linux/debug_fifo.c b/drivers/gpu/nvgpu/common/linux/debug_fifo.c deleted file mode 100644 index 2b5674c0..00000000 --- a/drivers/gpu/nvgpu/common/linux/debug_fifo.c +++ /dev/null | |||
@@ -1,378 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2017-2018 NVIDIA Corporation. All rights reserved. | ||
3 | * | ||
4 | * This software is licensed under the terms of the GNU General Public | ||
5 | * License version 2, as published by the Free Software Foundation, and | ||
6 | * may be copied, distributed, and modified under those terms. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | */ | ||
14 | |||
15 | #include "debug_fifo.h" | ||
16 | #include "os_linux.h" | ||
17 | |||
18 | #include <linux/debugfs.h> | ||
19 | #include <linux/seq_file.h> | ||
20 | |||
21 | #include <nvgpu/sort.h> | ||
22 | #include <nvgpu/timers.h> | ||
23 | |||
24 | void __gk20a_fifo_profile_free(struct nvgpu_ref *ref); | ||
25 | |||
26 | static void *gk20a_fifo_sched_debugfs_seq_start( | ||
27 | struct seq_file *s, loff_t *pos) | ||
28 | { | ||
29 | struct gk20a *g = s->private; | ||
30 | struct fifo_gk20a *f = &g->fifo; | ||
31 | |||
32 | if (*pos >= f->num_channels) | ||
33 | return NULL; | ||
34 | |||
35 | return &f->channel[*pos]; | ||
36 | } | ||
37 | |||
38 | static void *gk20a_fifo_sched_debugfs_seq_next( | ||
39 | struct seq_file *s, void *v, loff_t *pos) | ||
40 | { | ||
41 | struct gk20a *g = s->private; | ||
42 | struct fifo_gk20a *f = &g->fifo; | ||
43 | |||
44 | ++(*pos); | ||
45 | if (*pos >= f->num_channels) | ||
46 | return NULL; | ||
47 | |||
48 | return &f->channel[*pos]; | ||
49 | } | ||
50 | |||
51 | static void gk20a_fifo_sched_debugfs_seq_stop( | ||
52 | struct seq_file *s, void *v) | ||
53 | { | ||
54 | } | ||
55 | |||
56 | static int gk20a_fifo_sched_debugfs_seq_show( | ||
57 | struct seq_file *s, void *v) | ||
58 | { | ||
59 | struct gk20a *g = s->private; | ||
60 | struct fifo_gk20a *f = &g->fifo; | ||
61 | struct channel_gk20a *ch = v; | ||
62 | struct tsg_gk20a *tsg = NULL; | ||
63 | |||
64 | struct fifo_engine_info_gk20a *engine_info; | ||
65 | struct fifo_runlist_info_gk20a *runlist; | ||
66 | u32 runlist_id; | ||
67 | int ret = SEQ_SKIP; | ||
68 | u32 engine_id; | ||
69 | |||
70 | engine_id = gk20a_fifo_get_gr_engine_id(g); | ||
71 | engine_info = (f->engine_info + engine_id); | ||
72 | runlist_id = engine_info->runlist_id; | ||
73 | runlist = &f->runlist_info[runlist_id]; | ||
74 | |||
75 | if (ch == f->channel) { | ||
76 | seq_puts(s, "chid tsgid pid timeslice timeout interleave graphics_preempt compute_preempt\n"); | ||
77 | seq_puts(s, " (usecs) (msecs)\n"); | ||
78 | ret = 0; | ||
79 | } | ||
80 | |||
81 | if (!test_bit(ch->chid, runlist->active_channels)) | ||
82 | return ret; | ||
83 | |||
84 | if (gk20a_channel_get(ch)) { | ||
85 | tsg = tsg_gk20a_from_ch(ch); | ||
86 | |||
87 | if (tsg) | ||
88 | seq_printf(s, "%-8d %-8d %-8d %-9d %-8d %-10d %-8d %-8d\n", | ||
89 | ch->chid, | ||
90 | ch->tsgid, | ||
91 | ch->tgid, | ||
92 | tsg->timeslice_us, | ||
93 | ch->timeout_ms_max, | ||
94 | tsg->interleave_level, | ||
95 | tsg->gr_ctx.graphics_preempt_mode, | ||
96 | tsg->gr_ctx.compute_preempt_mode); | ||
97 | gk20a_channel_put(ch); | ||
98 | } | ||
99 | return 0; | ||
100 | } | ||
101 | |||
102 | static const struct seq_operations gk20a_fifo_sched_debugfs_seq_ops = { | ||
103 | .start = gk20a_fifo_sched_debugfs_seq_start, | ||
104 | .next = gk20a_fifo_sched_debugfs_seq_next, | ||
105 | .stop = gk20a_fifo_sched_debugfs_seq_stop, | ||
106 | .show = gk20a_fifo_sched_debugfs_seq_show | ||
107 | }; | ||
108 | |||
109 | static int gk20a_fifo_sched_debugfs_open(struct inode *inode, | ||
110 | struct file *file) | ||
111 | { | ||
112 | struct gk20a *g = inode->i_private; | ||
113 | int err; | ||
114 | |||
115 | if (!capable(CAP_SYS_ADMIN)) | ||
116 | return -EPERM; | ||
117 | |||
118 | err = seq_open(file, &gk20a_fifo_sched_debugfs_seq_ops); | ||
119 | if (err) | ||
120 | return err; | ||
121 | |||
122 | nvgpu_log(g, gpu_dbg_info, "i_private=%p", inode->i_private); | ||
123 | |||
124 | ((struct seq_file *)file->private_data)->private = inode->i_private; | ||
125 | return 0; | ||
126 | }; | ||
127 | |||
128 | /* | ||
129 | * The file operations structure contains our open function along with | ||
130 | * set of the canned seq_ ops. | ||
131 | */ | ||
132 | static const struct file_operations gk20a_fifo_sched_debugfs_fops = { | ||
133 | .owner = THIS_MODULE, | ||
134 | .open = gk20a_fifo_sched_debugfs_open, | ||
135 | .read = seq_read, | ||
136 | .llseek = seq_lseek, | ||
137 | .release = seq_release | ||
138 | }; | ||
139 | |||
140 | static int gk20a_fifo_profile_enable(void *data, u64 val) | ||
141 | { | ||
142 | struct gk20a *g = (struct gk20a *) data; | ||
143 | struct fifo_gk20a *f = &g->fifo; | ||
144 | |||
145 | |||
146 | nvgpu_mutex_acquire(&f->profile.lock); | ||
147 | if (val == 0) { | ||
148 | if (f->profile.enabled) { | ||
149 | f->profile.enabled = false; | ||
150 | nvgpu_ref_put(&f->profile.ref, | ||
151 | __gk20a_fifo_profile_free); | ||
152 | } | ||
153 | } else { | ||
154 | if (!f->profile.enabled) { | ||
155 | /* not kref init as it can have a running condition if | ||
156 | * we enable/disable/enable while kickoff is happening | ||
157 | */ | ||
158 | if (!nvgpu_ref_get_unless_zero(&f->profile.ref)) { | ||
159 | f->profile.data = nvgpu_vzalloc(g, | ||
160 | FIFO_PROFILING_ENTRIES * | ||
161 | sizeof(struct fifo_profile_gk20a)); | ||
162 | f->profile.sorted = nvgpu_vzalloc(g, | ||
163 | FIFO_PROFILING_ENTRIES * | ||
164 | sizeof(u64)); | ||
165 | if (!(f->profile.data && f->profile.sorted)) { | ||
166 | nvgpu_vfree(g, f->profile.data); | ||
167 | nvgpu_vfree(g, f->profile.sorted); | ||
168 | nvgpu_mutex_release(&f->profile.lock); | ||
169 | return -ENOMEM; | ||
170 | } | ||
171 | nvgpu_ref_init(&f->profile.ref); | ||
172 | } | ||
173 | atomic_set(&f->profile.get.atomic_var, 0); | ||
174 | f->profile.enabled = true; | ||
175 | } | ||
176 | } | ||
177 | nvgpu_mutex_release(&f->profile.lock); | ||
178 | |||
179 | return 0; | ||
180 | } | ||
181 | |||
182 | DEFINE_SIMPLE_ATTRIBUTE( | ||
183 | gk20a_fifo_profile_enable_debugfs_fops, | ||
184 | NULL, | ||
185 | gk20a_fifo_profile_enable, | ||
186 | "%llu\n" | ||
187 | ); | ||
188 | |||
189 | static int __profile_cmp(const void *a, const void *b) | ||
190 | { | ||
191 | return *((unsigned long long *) a) - *((unsigned long long *) b); | ||
192 | } | ||
193 | |||
194 | /* | ||
195 | * This uses about 800b in the stack, but the function using it is not part | ||
196 | * of a callstack where much memory is being used, so it is fine | ||
197 | */ | ||
198 | #define PERCENTILE_WIDTH 5 | ||
199 | #define PERCENTILE_RANGES (100/PERCENTILE_WIDTH) | ||
200 | |||
201 | static unsigned int __gk20a_fifo_create_stats(struct gk20a *g, | ||
202 | u64 *percentiles, u32 index_end, u32 index_start) | ||
203 | { | ||
204 | unsigned int nelem = 0; | ||
205 | unsigned int index; | ||
206 | struct fifo_profile_gk20a *profile; | ||
207 | |||
208 | for (index = 0; index < FIFO_PROFILING_ENTRIES; index++) { | ||
209 | profile = &g->fifo.profile.data[index]; | ||
210 | |||
211 | if (profile->timestamp[index_end] > | ||
212 | profile->timestamp[index_start]) { | ||
213 | /* This is a valid element */ | ||
214 | g->fifo.profile.sorted[nelem] = | ||
215 | profile->timestamp[index_end] - | ||
216 | profile->timestamp[index_start]; | ||
217 | nelem++; | ||
218 | } | ||
219 | } | ||
220 | |||
221 | /* sort it */ | ||
222 | sort(g->fifo.profile.sorted, nelem, sizeof(unsigned long long), | ||
223 | __profile_cmp, NULL); | ||
224 | |||
225 | /* build ranges */ | ||
226 | for (index = 0; index < PERCENTILE_RANGES; index++) { | ||
227 | percentiles[index] = nelem < PERCENTILE_RANGES ? 0 : | ||
228 | g->fifo.profile.sorted[(PERCENTILE_WIDTH * (index + 1) * | ||
229 | nelem)/100 - 1]; | ||
230 | } | ||
231 | return nelem; | ||
232 | } | ||
233 | |||
234 | static int gk20a_fifo_profile_stats(struct seq_file *s, void *unused) | ||
235 | { | ||
236 | struct gk20a *g = s->private; | ||
237 | unsigned int get, nelem, index; | ||
238 | /* | ||
239 | * 800B in the stack, but function is declared statically and only | ||
240 | * called from debugfs handler | ||
241 | */ | ||
242 | u64 percentiles_ioctl[PERCENTILE_RANGES]; | ||
243 | u64 percentiles_kickoff[PERCENTILE_RANGES]; | ||
244 | u64 percentiles_jobtracking[PERCENTILE_RANGES]; | ||
245 | u64 percentiles_append[PERCENTILE_RANGES]; | ||
246 | u64 percentiles_userd[PERCENTILE_RANGES]; | ||
247 | |||
248 | if (!nvgpu_ref_get_unless_zero(&g->fifo.profile.ref)) { | ||
249 | seq_printf(s, "Profiling disabled\n"); | ||
250 | return 0; | ||
251 | } | ||
252 | |||
253 | get = atomic_read(&g->fifo.profile.get.atomic_var); | ||
254 | |||
255 | __gk20a_fifo_create_stats(g, percentiles_ioctl, | ||
256 | PROFILE_IOCTL_EXIT, PROFILE_IOCTL_ENTRY); | ||
257 | __gk20a_fifo_create_stats(g, percentiles_kickoff, | ||
258 | PROFILE_END, PROFILE_ENTRY); | ||
259 | __gk20a_fifo_create_stats(g, percentiles_jobtracking, | ||
260 | PROFILE_JOB_TRACKING, PROFILE_IOCTL_ENTRY); | ||
261 | __gk20a_fifo_create_stats(g, percentiles_append, | ||
262 | PROFILE_APPEND, PROFILE_JOB_TRACKING); | ||
263 | nelem = __gk20a_fifo_create_stats(g, percentiles_userd, | ||
264 | PROFILE_END, PROFILE_APPEND); | ||
265 | |||
266 | seq_printf(s, "Number of kickoffs: %d\n", nelem); | ||
267 | seq_printf(s, "Perc \t ioctl(ns) \t kickoff(ns) \t pbcopy(ns) \t jobtrack(ns) \t userd(ns)\n"); | ||
268 | |||
269 | for (index = 0; index < PERCENTILE_RANGES; index++) | ||
270 | seq_printf(s, "[%2dpc]\t%8lld\t%8lld\t%8lld\t%8lld\t%8lld\n", | ||
271 | PERCENTILE_WIDTH * (index+1), | ||
272 | percentiles_ioctl[index], | ||
273 | percentiles_kickoff[index], | ||
274 | percentiles_append[index], | ||
275 | percentiles_jobtracking[index], | ||
276 | percentiles_userd[index]); | ||
277 | |||
278 | nvgpu_ref_put(&g->fifo.profile.ref, __gk20a_fifo_profile_free); | ||
279 | |||
280 | return 0; | ||
281 | } | ||
282 | |||
283 | static int gk20a_fifo_profile_stats_open(struct inode *inode, struct file *file) | ||
284 | { | ||
285 | return single_open(file, gk20a_fifo_profile_stats, inode->i_private); | ||
286 | } | ||
287 | |||
288 | static const struct file_operations gk20a_fifo_profile_stats_debugfs_fops = { | ||
289 | .open = gk20a_fifo_profile_stats_open, | ||
290 | .read = seq_read, | ||
291 | .llseek = seq_lseek, | ||
292 | .release = single_release, | ||
293 | }; | ||
294 | |||
295 | |||
296 | void gk20a_fifo_debugfs_init(struct gk20a *g) | ||
297 | { | ||
298 | struct nvgpu_os_linux *l = nvgpu_os_linux_from_gk20a(g); | ||
299 | struct dentry *gpu_root = l->debugfs; | ||
300 | struct dentry *fifo_root; | ||
301 | struct dentry *profile_root; | ||
302 | |||
303 | fifo_root = debugfs_create_dir("fifo", gpu_root); | ||
304 | if (IS_ERR_OR_NULL(fifo_root)) | ||
305 | return; | ||
306 | |||
307 | nvgpu_log(g, gpu_dbg_info, "g=%p", g); | ||
308 | |||
309 | debugfs_create_file("sched", 0600, fifo_root, g, | ||
310 | &gk20a_fifo_sched_debugfs_fops); | ||
311 | |||
312 | profile_root = debugfs_create_dir("profile", fifo_root); | ||
313 | if (IS_ERR_OR_NULL(profile_root)) | ||
314 | return; | ||
315 | |||
316 | nvgpu_mutex_init(&g->fifo.profile.lock); | ||
317 | g->fifo.profile.enabled = false; | ||
318 | atomic_set(&g->fifo.profile.get.atomic_var, 0); | ||
319 | atomic_set(&g->fifo.profile.ref.refcount.atomic_var, 0); | ||
320 | |||
321 | debugfs_create_file("enable", 0600, profile_root, g, | ||
322 | &gk20a_fifo_profile_enable_debugfs_fops); | ||
323 | |||
324 | debugfs_create_file("stats", 0600, profile_root, g, | ||
325 | &gk20a_fifo_profile_stats_debugfs_fops); | ||
326 | |||
327 | } | ||
328 | |||
329 | void gk20a_fifo_profile_snapshot(struct fifo_profile_gk20a *profile, int idx) | ||
330 | { | ||
331 | if (profile) | ||
332 | profile->timestamp[idx] = nvgpu_current_time_ns(); | ||
333 | } | ||
334 | |||
335 | void __gk20a_fifo_profile_free(struct nvgpu_ref *ref) | ||
336 | { | ||
337 | struct fifo_gk20a *f = container_of(ref, struct fifo_gk20a, | ||
338 | profile.ref); | ||
339 | nvgpu_vfree(f->g, f->profile.data); | ||
340 | nvgpu_vfree(f->g, f->profile.sorted); | ||
341 | } | ||
342 | |||
343 | /* Get the next element in the ring buffer of profile entries | ||
344 | * and grab a reference to the structure | ||
345 | */ | ||
346 | struct fifo_profile_gk20a *gk20a_fifo_profile_acquire(struct gk20a *g) | ||
347 | { | ||
348 | struct fifo_gk20a *f = &g->fifo; | ||
349 | struct fifo_profile_gk20a *profile; | ||
350 | unsigned int index; | ||
351 | |||
352 | /* If kref is zero, profiling is not enabled */ | ||
353 | if (!nvgpu_ref_get_unless_zero(&f->profile.ref)) | ||
354 | return NULL; | ||
355 | index = atomic_inc_return(&f->profile.get.atomic_var); | ||
356 | profile = &f->profile.data[index % FIFO_PROFILING_ENTRIES]; | ||
357 | |||
358 | return profile; | ||
359 | } | ||
360 | |||
361 | /* Free the reference to the structure. This allows deferred cleanups */ | ||
362 | void gk20a_fifo_profile_release(struct gk20a *g, | ||
363 | struct fifo_profile_gk20a *profile) | ||
364 | { | ||
365 | nvgpu_ref_put(&g->fifo.profile.ref, __gk20a_fifo_profile_free); | ||
366 | } | ||
367 | |||
368 | void gk20a_fifo_debugfs_deinit(struct gk20a *g) | ||
369 | { | ||
370 | struct fifo_gk20a *f = &g->fifo; | ||
371 | |||
372 | nvgpu_mutex_acquire(&f->profile.lock); | ||
373 | if (f->profile.enabled) { | ||
374 | f->profile.enabled = false; | ||
375 | nvgpu_ref_put(&f->profile.ref, __gk20a_fifo_profile_free); | ||
376 | } | ||
377 | nvgpu_mutex_release(&f->profile.lock); | ||
378 | } | ||