diff options
-rw-r--r-- | drivers/gpu/nvgpu/Makefile.nvgpu | 1 | ||||
-rw-r--r-- | drivers/gpu/nvgpu/common/linux/debug.c | 2 | ||||
-rw-r--r-- | drivers/gpu/nvgpu/common/linux/debug_hal.c | 95 | ||||
-rw-r--r-- | drivers/gpu/nvgpu/common/linux/debug_hal.h | 22 | ||||
-rw-r--r-- | drivers/gpu/nvgpu/common/linux/os_linux.h | 1 | ||||
-rw-r--r-- | drivers/gpu/nvgpu/gk20a/gk20a.h | 5 | ||||
-rwxr-xr-x | scripts/nvgpu_debug_hal.py | 123 |
7 files changed, 249 insertions, 0 deletions
diff --git a/drivers/gpu/nvgpu/Makefile.nvgpu b/drivers/gpu/nvgpu/Makefile.nvgpu index 2aa76497..dab9db92 100644 --- a/drivers/gpu/nvgpu/Makefile.nvgpu +++ b/drivers/gpu/nvgpu/Makefile.nvgpu | |||
@@ -129,6 +129,7 @@ nvgpu-$(CONFIG_DEBUG_FS) += \ | |||
129 | common/linux/debug_sched.o \ | 129 | common/linux/debug_sched.o \ |
130 | common/linux/debug_mm.o \ | 130 | common/linux/debug_mm.o \ |
131 | common/linux/debug_allocator.o \ | 131 | common/linux/debug_allocator.o \ |
132 | common/linux/debug_hal.o \ | ||
132 | common/linux/debug_kmem.o \ | 133 | common/linux/debug_kmem.o \ |
133 | common/linux/debug_clk.o | 134 | common/linux/debug_clk.o |
134 | 135 | ||
diff --git a/drivers/gpu/nvgpu/common/linux/debug.c b/drivers/gpu/nvgpu/common/linux/debug.c index 7dce74d6..abc8b907 100644 --- a/drivers/gpu/nvgpu/common/linux/debug.c +++ b/drivers/gpu/nvgpu/common/linux/debug.c | |||
@@ -21,6 +21,7 @@ | |||
21 | #include "debug_kmem.h" | 21 | #include "debug_kmem.h" |
22 | #include "debug_pmu.h" | 22 | #include "debug_pmu.h" |
23 | #include "debug_sched.h" | 23 | #include "debug_sched.h" |
24 | #include "debug_hal.h" | ||
24 | #include "os_linux.h" | 25 | #include "os_linux.h" |
25 | 26 | ||
26 | #include "gk20a/gk20a.h" | 27 | #include "gk20a/gk20a.h" |
@@ -386,6 +387,7 @@ void gk20a_debug_init(struct gk20a *g, const char *debugfs_symlink) | |||
386 | gk20a_cde_debugfs_init(g); | 387 | gk20a_cde_debugfs_init(g); |
387 | gk20a_ce_debugfs_init(g); | 388 | gk20a_ce_debugfs_init(g); |
388 | nvgpu_alloc_debugfs_init(g); | 389 | nvgpu_alloc_debugfs_init(g); |
390 | nvgpu_hal_debugfs_init(g); | ||
389 | gk20a_mm_debugfs_init(g); | 391 | gk20a_mm_debugfs_init(g); |
390 | gk20a_fifo_debugfs_init(g); | 392 | gk20a_fifo_debugfs_init(g); |
391 | gk20a_sched_debugfs_init(g); | 393 | gk20a_sched_debugfs_init(g); |
diff --git a/drivers/gpu/nvgpu/common/linux/debug_hal.c b/drivers/gpu/nvgpu/common/linux/debug_hal.c new file mode 100644 index 00000000..031e335e --- /dev/null +++ b/drivers/gpu/nvgpu/common/linux/debug_hal.c | |||
@@ -0,0 +1,95 @@ | |||
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_hal.h" | ||
16 | #include "os_linux.h" | ||
17 | |||
18 | #include <linux/debugfs.h> | ||
19 | #include <linux/seq_file.h> | ||
20 | |||
21 | /* Format and print a single function pointer to the specified seq_file. */ | ||
22 | static void __hal_print_op(struct seq_file *s, void *op_ptr) | ||
23 | { | ||
24 | seq_printf(s, "%pF\n", op_ptr); | ||
25 | } | ||
26 | |||
27 | /* | ||
28 | * Prints an array of function pointer addresses in op_ptrs to the | ||
29 | * specified seq_file | ||
30 | */ | ||
31 | static void __hal_print_ops(struct seq_file *s, void **op_ptrs, int num_ops) | ||
32 | { | ||
33 | int i; | ||
34 | |||
35 | for (i = 0; i < num_ops; i++) | ||
36 | __hal_print_op(s, op_ptrs[i]); | ||
37 | } | ||
38 | |||
39 | /* | ||
40 | * Show file operation, which generates content of the file once. Prints a list | ||
41 | * of gpu operations as defined by gops and the corresponding function pointer | ||
42 | * destination addresses. Relies on no compiler reordering of struct fields and | ||
43 | * assumption that all members are function pointers. | ||
44 | */ | ||
45 | static int __hal_show(struct seq_file *s, void *unused) | ||
46 | { | ||
47 | struct gpu_ops *gops = s->private; | ||
48 | |||
49 | __hal_print_ops(s, (void **)gops, sizeof(*gops) / sizeof(void *)); | ||
50 | |||
51 | return 0; | ||
52 | } | ||
53 | |||
54 | static int __hal_open(struct inode *inode, struct file *file) | ||
55 | { | ||
56 | return single_open(file, __hal_show, inode->i_private); | ||
57 | } | ||
58 | |||
59 | static const struct file_operations __hal_fops = { | ||
60 | .open = __hal_open, | ||
61 | .read = seq_read, | ||
62 | .llseek = seq_lseek, | ||
63 | .release = single_release, | ||
64 | }; | ||
65 | |||
66 | void nvgpu_hal_debugfs_fini(struct gk20a *g) | ||
67 | { | ||
68 | struct nvgpu_os_linux *l = nvgpu_os_linux_from_gk20a(g); | ||
69 | |||
70 | if (!(l->debugfs_hal == NULL)) | ||
71 | debugfs_remove_recursive(l->debugfs_hal); | ||
72 | } | ||
73 | |||
74 | void nvgpu_hal_debugfs_init(struct gk20a *g) | ||
75 | { | ||
76 | struct dentry *d; | ||
77 | struct nvgpu_os_linux *l = nvgpu_os_linux_from_gk20a(g); | ||
78 | |||
79 | if (!l->debugfs) | ||
80 | return; | ||
81 | l->debugfs_hal = debugfs_create_dir("hal", l->debugfs); | ||
82 | if (IS_ERR_OR_NULL(l->debugfs_hal)) { | ||
83 | l->debugfs_hal = NULL; | ||
84 | return; | ||
85 | } | ||
86 | |||
87 | /* Pass along reference to the gpu_ops struct as private data */ | ||
88 | d = debugfs_create_file("gops", S_IRUGO, l->debugfs_hal, | ||
89 | &g->ops, &__hal_fops); | ||
90 | if (!d) { | ||
91 | nvgpu_err(g, "%s: Failed to make debugfs node\n", __func__); | ||
92 | debugfs_remove_recursive(l->debugfs_hal); | ||
93 | return; | ||
94 | } | ||
95 | } | ||
diff --git a/drivers/gpu/nvgpu/common/linux/debug_hal.h b/drivers/gpu/nvgpu/common/linux/debug_hal.h new file mode 100644 index 00000000..eee6f234 --- /dev/null +++ b/drivers/gpu/nvgpu/common/linux/debug_hal.h | |||
@@ -0,0 +1,22 @@ | |||
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 | #ifndef __NVGPU_DEBUG_HAL_H__ | ||
16 | #define __NVGPU_DEBUG_HAL_H__ | ||
17 | |||
18 | struct gk20a; | ||
19 | void nvgpu_hal_debugfs_fini(struct gk20a *g); | ||
20 | void nvgpu_hal_debugfs_init(struct gk20a *g); | ||
21 | |||
22 | #endif /* __NVGPU_DEBUG_HAL_H__ */ | ||
diff --git a/drivers/gpu/nvgpu/common/linux/os_linux.h b/drivers/gpu/nvgpu/common/linux/os_linux.h index d7fdfa78..ed8364a9 100644 --- a/drivers/gpu/nvgpu/common/linux/os_linux.h +++ b/drivers/gpu/nvgpu/common/linux/os_linux.h | |||
@@ -102,6 +102,7 @@ struct nvgpu_os_linux { | |||
102 | struct dentry *debugfs_allocators; | 102 | struct dentry *debugfs_allocators; |
103 | struct dentry *debugfs_xve; | 103 | struct dentry *debugfs_xve; |
104 | struct dentry *debugfs_kmem; | 104 | struct dentry *debugfs_kmem; |
105 | struct dentry *debugfs_hal; | ||
105 | 106 | ||
106 | struct dentry *debugfs_force_preemption_cilp; | 107 | struct dentry *debugfs_force_preemption_cilp; |
107 | struct dentry *debugfs_force_preemption_gfxp; | 108 | struct dentry *debugfs_force_preemption_gfxp; |
diff --git a/drivers/gpu/nvgpu/gk20a/gk20a.h b/drivers/gpu/nvgpu/gk20a/gk20a.h index 15e81291..121dd962 100644 --- a/drivers/gpu/nvgpu/gk20a/gk20a.h +++ b/drivers/gpu/nvgpu/gk20a/gk20a.h | |||
@@ -130,6 +130,11 @@ enum gk20a_cbc_op { | |||
130 | 130 | ||
131 | enum nvgpu_unit; | 131 | enum nvgpu_unit; |
132 | 132 | ||
133 | /* | ||
134 | * gpu_ops should only contain function pointers! Non-function pointer members | ||
135 | * should go in struct gk20a or be implemented with the boolean flag API defined | ||
136 | * in nvgpu/enabled.h | ||
137 | */ | ||
133 | struct gpu_ops { | 138 | struct gpu_ops { |
134 | struct { | 139 | struct { |
135 | int (*determine_L2_size_bytes)(struct gk20a *gk20a); | 140 | int (*determine_L2_size_bytes)(struct gk20a *gk20a); |
diff --git a/scripts/nvgpu_debug_hal.py b/scripts/nvgpu_debug_hal.py new file mode 100755 index 00000000..a56d66e3 --- /dev/null +++ b/scripts/nvgpu_debug_hal.py | |||
@@ -0,0 +1,123 @@ | |||
1 | #!/usr/bin/env python3 | ||
2 | # | ||
3 | # Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved. | ||
4 | # | ||
5 | # This program is free software; you can redistribute it and/or modify it | ||
6 | # under the terms and conditions of the GNU General Public License, | ||
7 | # version 2, as published by the Free Software Foundation. | ||
8 | # | ||
9 | # This program is distributed in the hope it will be useful, but WITHOUT | ||
10 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
11 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
12 | # more details. | ||
13 | # | ||
14 | # usage: nvgpu_debug_hal.py [-h] [--csv] [--gk20a GK20A] [gops_filename] | ||
15 | # | ||
16 | # Analyze the HAL debugfs interface's output. With no arguments, prints out | ||
17 | # statistics on the gpu_ops struct based on analysis of gk20a.h | ||
18 | # | ||
19 | # positional arguments: | ||
20 | # gops_filename debugfs interface output file (from /d/gpu.0/hal/gops) | ||
21 | # | ||
22 | # optional arguments: | ||
23 | # -h, --help show this help message and exit | ||
24 | # --csv csv formatted output | ||
25 | # --gk20a GK20A path to gk20a.h | ||
26 | |||
27 | import argparse | ||
28 | import re | ||
29 | from os import environ | ||
30 | |||
31 | description_str = ('Analyze the HAL debugfs interface\'s output. ' | ||
32 | 'With no arguments, prints out statistics on the gpu_ops struct based on ' | ||
33 | 'analysis of gk20a.h') | ||
34 | |||
35 | parser = argparse.ArgumentParser(description=description_str); | ||
36 | parser.add_argument("--csv", help="csv formatted output", action="store_true"); | ||
37 | parser.add_argument("--gk20a", help="path to gk20a.h"); | ||
38 | parser.add_argument("gops_filename", help="debugfs interface output file (from /d/gpu.0/hal/gops)", nargs='?'); | ||
39 | args = parser.parse_args(); | ||
40 | |||
41 | if args.gk20a: | ||
42 | gk20a_h_path = args.gk20a | ||
43 | else: | ||
44 | top = environ.get('TOP'); | ||
45 | if top is None: | ||
46 | print("$TOP is undefined, unable to find gk20a.h"); | ||
47 | exit(-1); | ||
48 | gk20a_h_path = top + "/kernel/nvgpu/drivers/gpu/nvgpu/gk20a/gk20a.h" | ||
49 | |||
50 | def get_function_pointer_name(line): | ||
51 | matches = re.search('.*\(\*(?P<function_name>\w+)\)\(', line); | ||
52 | if matches is None: | ||
53 | return None | ||
54 | else: | ||
55 | return matches.group("function_name"); | ||
56 | |||
57 | # Build the list of gpu_ops member function pointers from gk20a.h | ||
58 | non_function_pointer_members = []; | ||
59 | formatted_members = []; | ||
60 | gops_members = dict(); | ||
61 | substruct_names = []; | ||
62 | lone_members = []; | ||
63 | with open(gk20a_h_path) as gk20a_h: | ||
64 | # Skip to start of gpu_ops struct | ||
65 | while gk20a_h.readline() != "struct gpu_ops {\n": | ||
66 | continue; | ||
67 | |||
68 | line = gk20a_h.readline(); | ||
69 | while line != "};\n": | ||
70 | # If this is a substruct | ||
71 | if re.match('\t+struct.+\{', line): | ||
72 | # Read the contents of the substruct | ||
73 | line = gk20a_h.readline(); | ||
74 | struct_contents = "" | ||
75 | while not re.match("\t*\} (\w+);", line): | ||
76 | struct_contents += line; | ||
77 | line = gk20a_h.readline(); | ||
78 | # Split out the substruct name and the function pointer names | ||
79 | struct_name = re.match("\t*\} (?P<struct_name>\w+);", line).group("struct_name"); | ||
80 | struct_members = re.findall(r".+?\(\s*\*\s*(\w+)\s*\).+?;", struct_contents, flags=re.DOTALL) | ||
81 | |||
82 | # Store the substruct as an entry | ||
83 | substruct_names.append(struct_name); | ||
84 | gops_members[struct_name] = struct_members; | ||
85 | # Format members | ||
86 | for member in struct_members: | ||
87 | formatted_members.append(struct_name + "." + member); | ||
88 | else: | ||
89 | # Lone members (function pointers or stuff not in a substruct) | ||
90 | match = re.match(".*\(\*(?P<function_name>\w+)\)\(", line); | ||
91 | if match is not None: | ||
92 | # It's a function pointer, keep track of it | ||
93 | lone_members.append(match.group("function_name")); | ||
94 | formatted_members.append(match.group("function_name")); | ||
95 | else: | ||
96 | # Not a function pointer, may also catch comments etc. | ||
97 | non_function_pointer_members.append(line.strip()); | ||
98 | line = gk20a_h.readline(); | ||
99 | if args.gops_filename: | ||
100 | # Interpret gops file | ||
101 | with open(args.gops_filename) as gops: | ||
102 | i = 0; | ||
103 | # Option for csv output | ||
104 | if args.csv: | ||
105 | format_string = '{0},{1}'; | ||
106 | else: | ||
107 | format_string = '{0:<60} = {1}'; | ||
108 | for line in gops: | ||
109 | print(format_string.format(formatted_members[i], line[:-1])); | ||
110 | i += 1; | ||
111 | else: | ||
112 | # Just print some stats on the gpu_ops struct | ||
113 | total = 0; | ||
114 | print("----- Lone Function Pointers -----"); | ||
115 | print("Count =", len(lone_members)); | ||
116 | total += len(lone_members); | ||
117 | for line in lone_members: | ||
118 | print(line); | ||
119 | print("----- Substruct Counts -----"); | ||
120 | for name in substruct_names: | ||
121 | print(name, "=", len(gops_members[name])); | ||
122 | total += len(gops_members[name]) | ||
123 | print("\n Total =", total); | ||