From e3bd4ae2a59fef37a85fbca168fc479dd5514023 Mon Sep 17 00:00:00 2001 From: Alex Waterman Date: Mon, 27 Mar 2017 10:41:53 -0700 Subject: 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 Reviewed-on: http://git-master/r/1329487 Reviewed-by: mobile promotions Tested-by: mobile promotions --- drivers/gpu/nvgpu/include/nvgpu/log.h | 170 ++++++++++++++++++++++++++++ drivers/gpu/nvgpu/include/nvgpu/semaphore.h | 1 + 2 files changed, 171 insertions(+) create mode 100644 drivers/gpu/nvgpu/include/nvgpu/log.h (limited to 'drivers/gpu/nvgpu/include') diff --git a/drivers/gpu/nvgpu/include/nvgpu/log.h b/drivers/gpu/nvgpu/include/nvgpu/log.h new file mode 100644 index 00000000..26738993 --- /dev/null +++ b/drivers/gpu/nvgpu/include/nvgpu/log.h @@ -0,0 +1,170 @@ +/* + * Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef __NVGPU_DEBUGGING_H__ +#define __NVGPU_DEBUGGING_H__ + +struct gk20a; + +enum nvgpu_log_type { + ERROR, + WARNING, + DEBUG +}; + +/* + * Each OS must implement these functions. They handle the OS specific nuances + * of printing data to a UART, log, whatever. + */ +__attribute__((format (printf, 5, 6))) +void __nvgpu_log_msg(struct gk20a *g, const char *func_name, int line, + enum nvgpu_log_type type, const char *fmt, ...); + +__attribute__((format (printf, 5, 6))) +void __nvgpu_log_dbg(struct gk20a *g, u32 log_mask, + const char *func_name, int line, + const char *fmt, ...); + +/* + * Use this define to set a default mask. + */ +#define NVGPU_DEFAULT_DBG_MASK (0) + +enum nvgpu_log_categories { + gpu_dbg_info = BIT(0), /* Lightly verbose info. */ + gpu_dbg_fn = BIT(1), /* Function name tracing. */ + gpu_dbg_reg = BIT(2), /* Register accesses; very verbose. */ + gpu_dbg_pte = BIT(3), /* GMMU PTEs. */ + gpu_dbg_intr = BIT(4), /* Interrupts. */ + gpu_dbg_pmu = BIT(5), /* gk20a pmu. */ + gpu_dbg_clk = BIT(6), /* gk20a clk. */ + gpu_dbg_map = BIT(7), /* Memory mappings. */ + gpu_dbg_map_v = BIT(8), /* Verbose mem mappings. */ + gpu_dbg_gpu_dbg = BIT(9), /* GPU debugger/profiler. */ + gpu_dbg_cde = BIT(10), /* cde info messages. */ + gpu_dbg_cde_ctx = BIT(11), /* cde context usage messages. */ + gpu_dbg_ctxsw = BIT(12), /* ctxsw tracing. */ + gpu_dbg_sched = BIT(13), /* Sched control tracing. */ + gpu_dbg_sema = BIT(14), /* Semaphore debugging. */ + gpu_dbg_sema_v = BIT(15), /* Verbose semaphore debugging. */ + gpu_dbg_pmu_pstate = BIT(16), /* p state controlled by pmu. */ + gpu_dbg_xv = BIT(17), /* XVE debugging. */ + gpu_dbg_shutdown = BIT(18), /* GPU shutdown tracing. */ + gpu_dbg_kmem = BIT(19), /* Kmem tracking debugging. */ + gpu_dbg_mem = BIT(31), /* memory accesses; very verbose. */ +}; + +/** + * nvgpu_log_mask_enabled - Check if logging is enabled + * + * @g - The GPU. + * @log_mask - The mask the check against. + * + * Check if, given the passed mask, logging would actually happen. This is + * useful for avoiding calling the logging function many times when we know that + * said prints would not happen. For example for-loops of log statements in + * critical paths. + */ +int nvgpu_log_mask_enabled(struct gk20a *g, u32 log_mask); + +/** + * nvgpu_log - Print a debug message + * + * @g - The GPU. + * @log_mask - A mask defining when the print should happen. See enum + * %nvgpu_log_categories. + * @fmt - A format string (printf style). + * @arg... - Arguments for the format string. + * + * Print a message if the log_mask matches the enabled debugging. + */ +#define nvgpu_log(g, log_mask, fmt, arg...) \ + __nvgpu_log_dbg(g, log_mask, __func__, __LINE__, fmt, ##arg); \ + +/** + * nvgpu_err - Print an error + * + * @g - The GPU. + * @fmt - A format string (printf style). + * @arg... - Arguments for the format string. + * + * Uncondtionally print an error message. + */ +#define nvgpu_err(g, fmt, arg...) \ + __nvgpu_log_msg(g, __func__, __LINE__, ERROR, fmt, ##arg) + +/** + * nvgpu_err - Print a warning + * + * @g - The GPU. + * @fmt - A format string (printf style). + * @arg... - Arguments for the format string. + * + * Uncondtionally print a warming message. + */ +#define nvgpu_warn(g, fmt, arg...) \ + __nvgpu_log_msg(g, __func__, __LINE__, WARNING, fmt, ##arg) + +/* + * Some convenience macros. + */ +#define nvgpu_log_fn(g, fmt, arg...) nvgpu_log(g, gpu_dbg_fn, fmt, ##arg) +#define nvgpu_log_info(g, fmt, arg...) nvgpu_log(g, gpu_dbg_info, fmt, ##arg) + +/****************************************************************************** + * The old legacy debugging API minus some parts that are unnecessary. * + * Please, please, please do not use this!!! This is still around to aid * + * transitioning to the new API. * + * * + * This changes up the print formats to be closer to the new APIs formats. * + * Also it removes the dev_warn() and dev_err() usage. Those arguments are * + * ignored now. * + ******************************************************************************/ + +/* + * This exist for backwards compatibility with the old debug/logging API. If you + * want ftrace support use the new API! + */ +extern u32 nvgpu_dbg_mask; + +#define gk20a_dbg(log_mask, fmt, arg...) \ + do { \ + if (((log_mask) & nvgpu_dbg_mask) != 0) \ + __nvgpu_log_msg(NULL, __func__, __LINE__, \ + DEBUG, fmt "\n", ##arg); \ + } while (0) + +#define gk20a_err(d, fmt, arg...) \ + do { \ + __nvgpu_log_msg(NULL, __func__, __LINE__, ERROR, \ + fmt "\n", ##arg); \ + (void)(d); \ + } while (0) + +#define gk20a_warn(d, fmt, arg...) \ + do { \ + __nvgpu_log_msg(NULL, __func__, __LINE__, WARNING, \ + fmt "\n", ##arg); \ + (void)(d); \ + } while (0) + +/* + * Some convenience macros. + */ +#define gk20a_dbg_fn(fmt, arg...) gk20a_dbg(gpu_dbg_fn, fmt, ##arg) +#define gk20a_dbg_info(fmt, arg...) gk20a_dbg(gpu_dbg_info, fmt, ##arg) + +#endif diff --git a/drivers/gpu/nvgpu/include/nvgpu/semaphore.h b/drivers/gpu/nvgpu/include/nvgpu/semaphore.h index 6c9b8118..ade48178 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/semaphore.h +++ b/drivers/gpu/nvgpu/include/nvgpu/semaphore.h @@ -18,6 +18,7 @@ #include #include +#include #include #include "gk20a/gk20a.h" -- cgit v1.2.2