summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/nvgpu/common
diff options
context:
space:
mode:
authorAlex Waterman <alexw@nvidia.com>2017-03-27 13:41:53 -0400
committermobile promotions <svcmobile_promotions@nvidia.com>2017-04-04 19:04:31 -0400
commite3bd4ae2a59fef37a85fbca168fc479dd5514023 (patch)
tree17668f10101a756d02e695d2aa2f652129514d3b /drivers/gpu/nvgpu/common
parent0778d7f33181e4f945083e8e051d5f9476fe5968 (diff)
gpu: nvgpu: debugging API update
Update the debugging APIs in nvgpu to be more coherent and less dependent on Linux kernel APIs and data structures. The old API is maintained for backwards compatibility but the prints themselves are changed. The old API now prints stuff like this: [ 46.376077] nvgpu: gk20a_channel_suspend:3430 [DBG] suspend channel 508 [ 46.376242] nvgpu: gk20a_channel_suspend:3430 [DBG] suspend channel 509 [ 46.376359] nvgpu: gk20a_channel_suspend:3430 [DBG] suspend channel 510 [ 46.376466] nvgpu: gk20a_channel_suspend:3430 [DBG] suspend channel 511 [ 46.376604] nvgpu: gk20a_fifo_update_runlist_locked:3090 [DBG] runlist_id : 0, switch to new buffer 0x 4003a0000 [ 46.378348] nvgpu: gk20a_mm_l2_flush:5259 [DBG] l2_flush_dirty 0x2 [ 46.378562] nvgpu: clk_config_pll:170 [DBG] low_PL 1(div1), high_PL 2(div2) [ 46.378684] nvgpu: clk_config_pll:170 [DBG] low_PL 8(div8), high_PL 17(div17) Each line starts with 'nvgpu:' since this is the nvgpu driver. Then there's the function name which is is right justified and post-fixed with a line number. This keeps all statements lined up so long as the function name does not exceed the length of characters alloted for function names (33 currently). Lines are also left justified with 4 available spaces since there are currently no source files with over 9999 lines. The type of message (DBG, WRN, ERR) is then printed in brackets. Finally there's whatever message is to be printed. The new API will be largely the same except there will be an additional print of the GPU that the message has originated from in order to help debug cases where both an iGPU and dGPU are active. Also the implicit newline added in the legacy API has been removed. This is inline with essentially every other print function in the C world. There are numerous places where '\n' is added despite it not being needed which results in log files being littered with blank lines. This makes the logs much harder to read. Bug ... Change-Id: I7bc87f2dbbaebf6eb6c9de1a629a0e2963e1804c Signed-off-by: Alex Waterman <alexw@nvidia.com> Reviewed-on: http://git-master/r/1329487 Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com> Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
Diffstat (limited to 'drivers/gpu/nvgpu/common')
-rw-r--r--drivers/gpu/nvgpu/common/linux/log.c130
1 files changed, 130 insertions, 0 deletions
diff --git a/drivers/gpu/nvgpu/common/linux/log.c b/drivers/gpu/nvgpu/common/linux/log.c
new file mode 100644
index 00000000..9dd965ec
--- /dev/null
+++ b/drivers/gpu/nvgpu/common/linux/log.c
@@ -0,0 +1,130 @@
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#include <linux/kernel.h>
18#include <linux/device.h>
19
20#include <nvgpu/log.h>
21
22#include "gk20a/gk20a.h"
23
24/*
25 * Define a length for log buffers. This is the buffer that the 'fmt, ...' part
26 * of __nvgpu_do_log_print() prints into. This buffer lives on the stack so it
27 * needs to not be overly sized since we have limited kernel stack space. But at
28 * the same time we don't want it to be restrictive either.
29 */
30#define LOG_BUFFER_LENGTH 160
31
32/*
33 * Annoying quirk of Linux: this has to be a string literal since the printk()
34 * function and friends use the preprocessor to concatenate stuff to the start
35 * of this string when printing.
36 */
37#define LOG_FMT "nvgpu: %s %33s:%-4d [%s] %s"
38
39u32 nvgpu_dbg_mask = NVGPU_DEFAULT_DBG_MASK;
40
41static const char *log_types[] = {
42 "ERR",
43 "WRN",
44 "DBG"
45};
46
47int nvgpu_log_mask_enabled(struct gk20a *g, u32 log_mask)
48{
49 return !!(g->log_mask & log_mask);
50}
51
52static inline const char *nvgpu_log_name(struct gk20a *g)
53{
54 return dev_name(g->dev);
55}
56
57#ifdef CONFIG_GK20A_TRACE_PRINTK
58static void __nvgpu_trace_printk_log(u32 trace, const char *gpu_name,
59 const char *func_name, int line,
60 enum nvgpu_log_type type, const char *log)
61{
62 trace_printk(LOG_FMT, gpu_name, func_name, line, type, log);
63}
64#endif
65
66static void __nvgpu_really_print_log(u32 trace, const char *gpu_name,
67 const char *func_name, int line,
68 enum nvgpu_log_type type, const char *log)
69{
70 const char *name = gpu_name ? gpu_name : "";
71
72#ifdef CONFIG_GK20A_TRACE_PRINTK
73 if (trace)
74 return __nvgpu_trace_printk_log(trace, name, func_name,
75 line, type, log);
76#else
77 const char *log_type = log_types[type];
78
79 switch (type) {
80 case DEBUG:
81 /*
82 * We could use pr_debug() here but we control debug enablement
83 * separately from the Linux kernel. Perhaps this is a bug in
84 * nvgpu.
85 */
86 pr_info(LOG_FMT, name, func_name, line, log_type, log);
87 break;
88 case WARNING:
89 pr_warn(LOG_FMT, name, func_name, line, log_type, log);
90 break;
91 case ERROR:
92 pr_err(LOG_FMT, name, func_name, line, log_type, log);
93 break;
94 }
95#endif
96}
97
98__attribute__((format (printf, 5, 6)))
99void __nvgpu_log_msg(struct gk20a *g, const char *func_name, int line,
100 enum nvgpu_log_type type, const char *fmt, ...)
101{
102 char log[LOG_BUFFER_LENGTH];
103 va_list args;
104
105 va_start(args, fmt);
106 vsnprintf(log, LOG_BUFFER_LENGTH, fmt, args);
107 va_end(args);
108
109 __nvgpu_really_print_log(0, g ? nvgpu_log_name(g) : "",
110 func_name, line, type, log);
111}
112
113__attribute__((format (printf, 5, 6)))
114void __nvgpu_log_dbg(struct gk20a *g, u32 log_mask,
115 const char *func_name, int line,
116 const char *fmt, ...)
117{
118 char log[LOG_BUFFER_LENGTH];
119 va_list args;
120
121 if ((log_mask & g->log_mask) == 0)
122 return;
123
124 va_start(args, fmt);
125 vsnprintf(log, LOG_BUFFER_LENGTH, fmt, args);
126 va_end(args);
127
128 __nvgpu_really_print_log(g->log_trace, nvgpu_log_name(g),
129 func_name, line, DEBUG, log);
130}