diff options
Diffstat (limited to 'drivers/gpu/nvgpu/common/linux/debug_allocator.c')
-rw-r--r-- | drivers/gpu/nvgpu/common/linux/debug_allocator.c | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/drivers/gpu/nvgpu/common/linux/debug_allocator.c b/drivers/gpu/nvgpu/common/linux/debug_allocator.c new file mode 100644 index 00000000..3d4a2bb2 --- /dev/null +++ b/drivers/gpu/nvgpu/common/linux/debug_allocator.c | |||
@@ -0,0 +1,80 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2017 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_allocator.h" | ||
16 | #include "gk20a/platform_gk20a.h" | ||
17 | |||
18 | #include <linux/debugfs.h> | ||
19 | #include <linux/seq_file.h> | ||
20 | |||
21 | #include <nvgpu/allocator.h> | ||
22 | |||
23 | u32 nvgpu_alloc_tracing_on; | ||
24 | |||
25 | void nvgpu_alloc_print_stats(struct nvgpu_allocator *__a, | ||
26 | struct seq_file *s, int lock) | ||
27 | { | ||
28 | __a->ops->print_stats(__a, s, lock); | ||
29 | } | ||
30 | |||
31 | static int __alloc_show(struct seq_file *s, void *unused) | ||
32 | { | ||
33 | struct nvgpu_allocator *a = s->private; | ||
34 | |||
35 | nvgpu_alloc_print_stats(a, s, 1); | ||
36 | |||
37 | return 0; | ||
38 | } | ||
39 | |||
40 | static int __alloc_open(struct inode *inode, struct file *file) | ||
41 | { | ||
42 | return single_open(file, __alloc_show, inode->i_private); | ||
43 | } | ||
44 | |||
45 | static const struct file_operations __alloc_fops = { | ||
46 | .open = __alloc_open, | ||
47 | .read = seq_read, | ||
48 | .llseek = seq_lseek, | ||
49 | .release = single_release, | ||
50 | }; | ||
51 | |||
52 | void nvgpu_init_alloc_debug(struct gk20a *g, struct nvgpu_allocator *a) | ||
53 | { | ||
54 | if (!g->debugfs_allocators) | ||
55 | return; | ||
56 | |||
57 | a->debugfs_entry = debugfs_create_file(a->name, S_IRUGO, | ||
58 | g->debugfs_allocators, | ||
59 | a, &__alloc_fops); | ||
60 | } | ||
61 | |||
62 | void nvgpu_fini_alloc_debug(struct nvgpu_allocator *a) | ||
63 | { | ||
64 | if (!IS_ERR_OR_NULL(a->debugfs_entry)) | ||
65 | debugfs_remove(a->debugfs_entry); | ||
66 | } | ||
67 | |||
68 | void nvgpu_alloc_debugfs_init(struct gk20a *g) | ||
69 | { | ||
70 | struct gk20a_platform *platform = dev_get_drvdata(g->dev); | ||
71 | |||
72 | g->debugfs_allocators = debugfs_create_dir("allocators", platform->debugfs); | ||
73 | if (IS_ERR_OR_NULL(g->debugfs_allocators)) { | ||
74 | g->debugfs_allocators = NULL; | ||
75 | return; | ||
76 | } | ||
77 | |||
78 | debugfs_create_u32("tracing", 0664, g->debugfs_allocators, | ||
79 | &nvgpu_alloc_tracing_on); | ||
80 | } | ||