diff --git a/drivers/gpu/nvgpu/Kconfig b/drivers/gpu/nvgpu/Kconfig index 5ad78492d..34ff6fbbb 100644 --- a/drivers/gpu/nvgpu/Kconfig +++ b/drivers/gpu/nvgpu/Kconfig @@ -181,3 +181,10 @@ config NVGPU_COMPRESSION default y help Support for compression + +config NVGPU_LOGGING + bool "Logging for non-safety build" + depends on GK20A + default y + help + Enable/Disable logging for non-safety builds diff --git a/drivers/gpu/nvgpu/Makefile b/drivers/gpu/nvgpu/Makefile index c11c7a45b..bd43a5887 100644 --- a/drivers/gpu/nvgpu/Makefile +++ b/drivers/gpu/nvgpu/Makefile @@ -42,6 +42,10 @@ ccflags-y += -DCONFIG_NVGPU_POWER_PG ccflags-y += -DCONFIG_NVGPU_CE ccflags-y += -DCONFIG_NVGPU_COMPRESSION +ifeq ($(CONFIG_NVGPU_LOGGING),y) +ccflags-y += -DCONFIG_NVGPU_LOGGING=1 +endif + obj-$(CONFIG_GK20A) := nvgpu.o # OS independent parts of nvgpu. The work to collect files here @@ -384,7 +388,6 @@ nvgpu-y += \ os/linux/ioctl_tsg.o \ os/linux/ioctl_dbg.o \ os/linux/ioctl_clk_arb.o \ - os/linux/log.o \ os/linux/cond.o \ os/linux/nvgpu_mem.o \ os/linux/linux-dma.o \ @@ -433,6 +436,8 @@ nvgpu-$(CONFIG_DEBUG_FS) += \ os/linux/debug_volt.o \ os/linux/debug_s_param.o +nvgpu-$(CONFIG_NVGPU_LOGGING) += os/linux/log.o + ifeq ($(CONFIG_NVGPU_TRACK_MEM_USAGE),y) nvgpu-$(CONFIG_DEBUG_FS) += \ os/linux/debug_kmem.o diff --git a/drivers/gpu/nvgpu/Makefile.shared.configs b/drivers/gpu/nvgpu/Makefile.shared.configs index 6deacf170..11782d463 100644 --- a/drivers/gpu/nvgpu/Makefile.shared.configs +++ b/drivers/gpu/nvgpu/Makefile.shared.configs @@ -34,9 +34,16 @@ profile := default # Decide whether to use the safety profile or the regular profile. ifeq ($(NV_BUILD_CONFIGURATION_IS_SAFETY),1) profile := safety +ifeq ($(NV_BUILD_CONFIGURATION_IS_DEBUG),1) +profile := safety_debug endif +endif + ifeq ($(NVGPU_FORCE_SAFETY_PROFILE),1) profile := safety +ifeq ($(NVGPU_FORCE_DEBUG_PROFILE),1) +profile := safety_debug +endif endif NVGPU_COMMON_CFLAGS := @@ -99,6 +106,12 @@ NVGPU_COMMON_CFLAGS += -DCONFIG_NVGPU_COMPRESSION # Flags enabled for only the regular build profile. # ifneq ($(profile),safety) +# Enable logging for non-safety builds +CONFIG_NVGPU_LOGGING := 1 +NVGPU_COMMON_CFLAGS += -DCONFIG_NVGPU_LOGGING + +ifneq ($(profile),safety_debug) + # ACR feature to enable old tegra ACR profile support CONFIG_NVGPU_ACR_LEGACY := 1 NVGPU_COMMON_CFLAGS += -DCONFIG_NVGPU_ACR_LEGACY @@ -133,4 +146,6 @@ NVGPU_COMMON_CFLAGS += -DCONFIG_NVGPU_LS_PMU # Enable elpg support for normal build CONFIG_NVGPU_POWER_PG := 1 NVGPU_COMMON_CFLAGS += -DCONFIG_NVGPU_POWER_PG + +endif endif diff --git a/drivers/gpu/nvgpu/Makefile.sources b/drivers/gpu/nvgpu/Makefile.sources index 42828bb88..3e4dd9089 100644 --- a/drivers/gpu/nvgpu/Makefile.sources +++ b/drivers/gpu/nvgpu/Makefile.sources @@ -24,7 +24,6 @@ srcs := ifdef NVGPU_POSIX srcs += os/posix/nvgpu.c \ - os/posix/log.c \ os/posix/posix-io.c \ os/posix/posix-nvgpu_mem.c \ os/posix/posix-dma.c \ @@ -51,6 +50,10 @@ endif ifeq ($(CONFIG_NVGPU_COMPRESSION),1) srcs += os/posix/posix-comptags.c endif + +ifeq ($(CONFIG_NVGPU_LOGGING),1) +srcs += os/posix/log.c +endif endif # POSIX sources shared between the POSIX and QNX builds. diff --git a/drivers/gpu/nvgpu/Makefile.tmk b/drivers/gpu/nvgpu/Makefile.tmk index 8ee24ad43..853ba00b0 100644 --- a/drivers/gpu/nvgpu/Makefile.tmk +++ b/drivers/gpu/nvgpu/Makefile.tmk @@ -57,6 +57,7 @@ NV_COMPONENT_CFLAGS += \ -D__NVGPU_UNIT_TEST__ NVGPU_FORCE_SAFETY_PROFILE := 1 +NVGPU_FORCE_DEBUG_PROFILE := 1 -include $(NV_COMPONENT_DIR)/Makefile.shared.configs NV_COMPONENT_CFLAGS += $(NVGPU_COMMON_CFLAGS) diff --git a/drivers/gpu/nvgpu/include/nvgpu/log.h b/drivers/gpu/nvgpu/include/nvgpu/log.h index 2e58a48e2..2c55f0aef 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/log.h +++ b/drivers/gpu/nvgpu/include/nvgpu/log.h @@ -39,6 +39,7 @@ enum nvgpu_log_type { * Each OS must implement these functions. They handle the OS specific nuances * of printing data to a UART, log, whatever. */ +#ifdef CONFIG_NVGPU_LOGGING __attribute__((format (printf, 5, 6))) void nvgpu_log_msg_impl(struct gk20a *g, const char *func_name, int line, enum nvgpu_log_type type, const char *fmt, ...); @@ -47,6 +48,18 @@ __attribute__((format (printf, 5, 6))) void nvgpu_log_dbg_impl(struct gk20a *g, u64 log_mask, const char *func_name, int line, const char *fmt, ...); +#else +static inline void nvgpu_log_msg_impl(struct gk20a *g, const char *func_name, + int line, enum nvgpu_log_type type, const char *fmt, ...) +{ +} + +static inline void nvgpu_log_dbg_impl(struct gk20a *g, u64 log_mask, + const char *func_name, int line, + const char *fmt, ...) +{ +} +#endif /* * Use this define to set a default mask. @@ -95,7 +108,14 @@ void nvgpu_log_dbg_impl(struct gk20a *g, u64 log_mask, * said prints would not happen. For example for-loops of log statements in * critical paths. */ +#ifdef CONFIG_NVGPU_LOGGING bool nvgpu_log_mask_enabled(struct gk20a *g, u64 log_mask); +#else +static inline bool nvgpu_log_mask_enabled(struct gk20a *g, u64 log_mask) +{ + return false; +} +#endif /** * nvgpu_log - Print a debug message diff --git a/drivers/gpu/nvgpu/include/nvgpu/posix/utils.h b/drivers/gpu/nvgpu/include/nvgpu/posix/utils.h index 817bc81cc..a0c326ca2 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/posix/utils.h +++ b/drivers/gpu/nvgpu/include/nvgpu/posix/utils.h @@ -131,6 +131,7 @@ * Caps return at the size of the buffer not what would have been written if buf * were arbitrarily sized. */ +#ifdef CONFIG_NVGPU_LOGGING static inline int scnprintf(char *buf, size_t size, const char *format, ...) { size_t ret; @@ -142,6 +143,12 @@ static inline int scnprintf(char *buf, size_t size, const char *format, ...) return ret <= size ? (int)ret : (int)size; } +#else +static inline int scnprintf(char *buf, size_t size, const char *format, ...) +{ + return 0; +} +#endif static inline u32 be32_to_cpu(u32 x) { diff --git a/drivers/gpu/nvgpu/libnvgpu-drv_safe.export b/drivers/gpu/nvgpu/libnvgpu-drv_safe.export index e54046f83..8f3102d83 100644 --- a/drivers/gpu/nvgpu/libnvgpu-drv_safe.export +++ b/drivers/gpu/nvgpu/libnvgpu-drv_safe.export @@ -103,8 +103,6 @@ nvgpu_kmem_cache_destroy nvgpu_kmem_cache_free nvgpu_kmem_get_fault_injection nvgpu_kzalloc_impl -nvgpu_log_dbg_impl -nvgpu_log_msg_impl nvgpu_memset nvgpu_mem_create_from_phys nvgpu_mem_iommu_translate diff --git a/drivers/gpu/nvgpu/os/posix/timers.c b/drivers/gpu/nvgpu/os/posix/timers.c index 2c159c1c6..8a9c11e23 100644 --- a/drivers/gpu/nvgpu/os/posix/timers.c +++ b/drivers/gpu/nvgpu/os/posix/timers.c @@ -95,65 +95,85 @@ int nvgpu_timeout_init(struct gk20a *g, struct nvgpu_timeout *timeout, return 0; } -static int nvgpu_timeout_expired_msg_cpu(struct nvgpu_timeout *timeout, - void *caller, +/* + * NOTE: Logging is disabled in safety release build. + * So, in safety release configuration, messages will not be printed or logged. + */ +#ifdef CONFIG_NVGPU_LOGGING +static void nvgpu_timeout_expired_msg_print(struct nvgpu_timeout *timeout, + bool retry, void *caller, const char *fmt, va_list args) { struct gk20a *g = timeout->g; + if ((timeout->flags & NVGPU_TIMER_SILENT_TIMEOUT) == 0U) { + char buf[128]; - if (get_time_ns() >= timeout->time) { - if ((timeout->flags & NVGPU_TIMER_SILENT_TIMEOUT) == 0U) { - char buf[128]; - - (void) vsnprintf(buf, sizeof(buf), fmt, args); + (void) vsnprintf(buf, sizeof(buf), fmt, args); + if (retry) { + nvgpu_err(g, "No more retries @ %p %s", caller, buf); + } else { nvgpu_err(g, "Timeout detected @ %p %s", caller, buf); } + } +} +#endif +static int nvgpu_timeout_expired_msg_cpu(struct nvgpu_timeout *timeout) +{ + if (get_time_ns() >= timeout->time) { return -ETIMEDOUT; } return 0; } -static int nvgpu_timeout_expired_msg_retry(struct nvgpu_timeout *timeout, - void *caller, - const char *fmt, va_list args) +static int nvgpu_timeout_expired_msg_retry(struct nvgpu_timeout *timeout) { - struct gk20a *g = timeout->g; - if (timeout->retries.attempted >= timeout->retries.max_attempts) { - if ((timeout->flags & NVGPU_TIMER_SILENT_TIMEOUT) == 0U) { - char buf[128]; - - (void) vsnprintf(buf, sizeof(buf), fmt, args); - - nvgpu_err(g, "No more retries @ %p %s", caller, buf); - } - return -ETIMEDOUT; } timeout->retries.attempted++; - return 0; } +/* + * NOTE: Logging is disabled in safety release build. + * So, in safety release configuration, messages will not be printed or logged. + */ int nvgpu_timeout_expired_msg_impl(struct nvgpu_timeout *timeout, void *caller, const char *fmt, ...) { int ret; - va_list args; - va_start(args, fmt); if ((timeout->flags & NVGPU_TIMER_RETRY_TIMER) != 0U) { - ret = nvgpu_timeout_expired_msg_retry(timeout, caller, fmt, - args); + ret = nvgpu_timeout_expired_msg_retry(timeout); + +#ifdef CONFIG_NVGPU_LOGGING + if (ret != 0) { + va_list args; + + va_start(args, fmt); + nvgpu_timeout_expired_msg_print(timeout, true, caller, + fmt, args); + va_end(args); + } +#endif } else { - ret = nvgpu_timeout_expired_msg_cpu(timeout, caller, fmt, - args); + ret = nvgpu_timeout_expired_msg_cpu(timeout); + +#ifdef CONFIG_NVGPU_LOGGING + if (ret != 0) { + va_list args; + + va_start(args, fmt); + nvgpu_timeout_expired_msg_print(timeout, false, caller, + fmt, args); + va_end(args); + } +#endif } - va_end(args); return ret; } diff --git a/userspace/Makefile b/userspace/Makefile index 711582782..119b0d38c 100644 --- a/userspace/Makefile +++ b/userspace/Makefile @@ -66,6 +66,7 @@ CONFIGS := -D__NVGPU_POSIX__ \ -D__NVGPU_UNIT_TEST__ NVGPU_FORCE_SAFETY_PROFILE := 1 +NVGPU_FORCE_DEBUG_PROFILE := 1 include $(NVGPU_SRC)/Makefile.shared.configs CONFIGS+=$(NVGPU_COMMON_CFLAGS) diff --git a/userspace/Makefile.tmk b/userspace/Makefile.tmk index 4c2141ad1..e9d31fac7 100644 --- a/userspace/Makefile.tmk +++ b/userspace/Makefile.tmk @@ -112,6 +112,7 @@ NV_COMPONENT_CFLAGS += \ -DNVGPU_UNITTEST_FAULT_INJECTION_ENABLEMENT NVGPU_FORCE_SAFETY_PROFILE := 1 +NVGPU_FORCE_DEBUG_PROFILE := 1 -include ../drivers/gpu/nvgpu/Makefile.shared.configs NV_COMPONENT_CFLAGS += $(NVGPU_COMMON_CFLAGS) diff --git a/userspace/units/Makefile.units.common.tmk b/userspace/units/Makefile.units.common.tmk index 93f81d53a..fe3f79543 100644 --- a/userspace/units/Makefile.units.common.tmk +++ b/userspace/units/Makefile.units.common.tmk @@ -55,6 +55,7 @@ NV_COMPONENT_CFLAGS += -D__NVGPU_UNIT_TEST__ endif NVGPU_FORCE_SAFETY_PROFILE := 1 +NVGPU_FORCE_DEBUG_PROFILE := 1 -include $(NV_SOURCE)/kernel/nvgpu/drivers/gpu/nvgpu/Makefile.shared.configs NV_COMPONENT_CFLAGS += $(NVGPU_COMMON_CFLAGS) diff --git a/userspace/units/fifo/nvgpu-fifo.c b/userspace/units/fifo/nvgpu-fifo.c index 8e38f592e..18e3d0b93 100644 --- a/userspace/units/fifo/nvgpu-fifo.c +++ b/userspace/units/fifo/nvgpu-fifo.c @@ -37,6 +37,8 @@ #include "nvgpu-fifo.h" #include "nvgpu-fifo-gv11b.h" +static struct unit_module *global_m; + bool test_fifo_subtest_pruned(u32 branches, u32 final_branches) { u32 match = branches & final_branches; @@ -93,7 +95,7 @@ static int stub_userd_setup_sw(struct gk20a *g) err = nvgpu_userd_init_slabs(g); if (err != 0) { - nvgpu_err(g, "failed to init userd support"); + unit_err(global_m, "failed to init userd support"); return err; } @@ -116,6 +118,7 @@ int test_fifo_init_support(struct unit_module *m, struct gk20a *g, void *args) g->ops.tsg.init_eng_method_buffers = NULL; #ifdef CONFIG_NVGPU_USERD + global_m = m; /* * Regular USERD init requires bar1.vm to be initialized * Use a stub in unit tests, since it will be disabled in diff --git a/userspace/units/mm/gmmu/page_table/page_table.c b/userspace/units/mm/gmmu/page_table/page_table.c index 042c3920d..0cf29da46 100644 --- a/userspace/units/mm/gmmu/page_table/page_table.c +++ b/userspace/units/mm/gmmu/page_table/page_table.c @@ -472,7 +472,7 @@ static int test_nvgpu_gmmu_map_unmap(struct unit_module *m, unit_return_fail(m, "Mapped VA is not 4KB-aligned\n"); } - nvgpu_log(g, gpu_dbg_map, "Mapped VA=%p", (void *) mem.gpu_va); + unit_info(m, "Mapped VA=%p", (void *) mem.gpu_va); /* * Based on the VA returned from gmmu_map, lookup the corresponding @@ -482,7 +482,7 @@ static int test_nvgpu_gmmu_map_unmap(struct unit_module *m, if (result != 0) { unit_return_fail(m, "PTE lookup failed with code=%d\n", result); } - nvgpu_log(g, gpu_dbg_map, "Found PTE=%08x %08x", pte[1], pte[0]); + unit_info(m, "Found PTE=%08x %08x", pte[1], pte[0]); /* Make sure PTE is valid */ if (!pte_is_valid(pte) && @@ -925,7 +925,7 @@ static int check_pte_valid(struct unit_module *m, struct gk20a *g, if (result != 0) { unit_return_fail(m, "PTE lookup failed with code=%d\n", result); } - nvgpu_log(g, gpu_dbg_map, "Found PTE=%08x %08x", pte[1], pte[0]); + unit_info(m, "Found PTE=%08x %08x", pte[1], pte[0]); /* Make sure PTE is valid */ if (!pte_is_valid(pte)) {