diff --git a/arch/nvgpu-posix.yaml b/arch/nvgpu-posix.yaml index 2e076b824..e9d04b364 100644 --- a/arch/nvgpu-posix.yaml +++ b/arch/nvgpu-posix.yaml @@ -102,7 +102,8 @@ threads: timers: safe: yes owner: Ajesh K - sources: [ os/posix/timers.c ] + sources: [ os/posix/timers.c, + include/nvgpu/posix/timers.h ] deps: atomic: diff --git a/drivers/gpu/nvgpu/hal/fb/fb_mmu_fault_gv11b_fusa.c b/drivers/gpu/nvgpu/hal/fb/fb_mmu_fault_gv11b_fusa.c index 153c36b52..ea560a81c 100644 --- a/drivers/gpu/nvgpu/hal/fb/fb_mmu_fault_gv11b_fusa.c +++ b/drivers/gpu/nvgpu/hal/fb/fb_mmu_fault_gv11b_fusa.c @@ -692,7 +692,7 @@ int gv11b_fb_mmu_invalidate_replay(struct gk20a *g, } nvgpu_udelay(5); } while (nvgpu_timeout_expired_msg(&timeout, - "invalidate replay failed 0x%lx", + "invalidate replay failed 0x%x", invalidate_replay_val) == 0); if (err != 0) { nvgpu_err(g, "invalidate replay timedout"); diff --git a/drivers/gpu/nvgpu/hal/fb/fb_mmu_fault_tu104.c b/drivers/gpu/nvgpu/hal/fb/fb_mmu_fault_tu104.c index 31b720dcc..d33498774 100644 --- a/drivers/gpu/nvgpu/hal/fb/fb_mmu_fault_tu104.c +++ b/drivers/gpu/nvgpu/hal/fb/fb_mmu_fault_tu104.c @@ -231,7 +231,7 @@ int tu104_fb_mmu_invalidate_replay(struct gk20a *g, } nvgpu_udelay(5); } while (nvgpu_timeout_expired_msg(&timeout, - "invalidate replay failed on 0x%lx", + "invalidate replay failed on 0x%x", invalidate_replay_val) == 0); if (err != 0) { nvgpu_err(g, "invalidate replay timedout"); diff --git a/drivers/gpu/nvgpu/include/nvgpu/posix/timers.h b/drivers/gpu/nvgpu/include/nvgpu/posix/timers.h new file mode 100644 index 000000000..1809a4692 --- /dev/null +++ b/drivers/gpu/nvgpu/include/nvgpu/posix/timers.h @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#ifndef NVGPU_POSIX_TIMERS_H +#define NVGPU_POSIX_TIMERS_H + +#include +#include + +#include +#include + + +#define nvgpu_timeout_expired_msg_cpu(timeout, caller, fmt, arg...) \ +({ \ + struct nvgpu_timeout *t_ptr = (timeout); \ + int ret = 0; \ + if (nvgpu_current_time_ns() > t_ptr->time) { \ + if ((t_ptr->flags & NVGPU_TIMER_SILENT_TIMEOUT) == 0U) { \ + nvgpu_err(t_ptr->g, "Timeout detected @ %p" fmt, \ + caller, ##arg); \ + } \ + ret = -ETIMEDOUT; \ + } \ + (int)ret; \ +}) + +#define nvgpu_timeout_expired_msg_retry(timeout, caller, fmt, arg...) \ +({ \ + struct nvgpu_timeout *t_ptr = (timeout); \ + int ret = 0; \ + if (t_ptr->retries.attempted >= t_ptr->retries.max_attempts) { \ + if ((t_ptr->flags & NVGPU_TIMER_SILENT_TIMEOUT) == 0U) { \ + nvgpu_err(t_ptr->g, "No more retries @ %p" fmt, \ + caller, ##arg); \ + } \ + ret = -ETIMEDOUT; \ + } else { \ + t_ptr->retries.attempted++; \ + } \ + (int)ret; \ +}) + +#define nvgpu_timeout_expired_msg_impl(timeout, caller, fmt, arg...) \ +({ \ + int ret = 0; \ + if (((timeout)->flags & NVGPU_TIMER_RETRY_TIMER) != 0U) { \ + ret = nvgpu_timeout_expired_msg_retry((timeout), caller,\ + fmt, ##arg); \ + } else { \ + ret = nvgpu_timeout_expired_msg_cpu((timeout), caller, \ + fmt, ##arg); \ + } \ + (int)ret; \ +}) + +#endif diff --git a/drivers/gpu/nvgpu/include/nvgpu/timers.h b/drivers/gpu/nvgpu/include/nvgpu/timers.h index 28068d473..20d920016 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/timers.h +++ b/drivers/gpu/nvgpu/include/nvgpu/timers.h @@ -26,6 +26,10 @@ #include #include +#ifndef __KERNEL__ +#include +#endif + struct gk20a; /* @@ -89,15 +93,7 @@ bool nvgpu_timeout_peek_expired(struct nvgpu_timeout *timeout); nvgpu_timeout_expired_msg_impl(__timeout, NVGPU_GET_IP, "") #define nvgpu_timeout_expired_msg(__timeout, fmt, args...) \ - nvgpu_timeout_expired_msg_impl(__timeout, NVGPU_GET_IP, \ - fmt, ##args) - -/* - * Don't use this directly. - */ -int nvgpu_timeout_expired_msg_impl(struct nvgpu_timeout *timeout, - void *caller, const char *fmt, ...); - + nvgpu_timeout_expired_msg_impl(__timeout, NVGPU_GET_IP, fmt, ##args) /* * Waits and delays. @@ -117,4 +113,12 @@ u64 nvgpu_hr_timestamp_us(void); #endif u64 nvgpu_hr_timestamp(void); +#ifdef __KERNEL__ +/* + * Don't use this directly. + */ +int nvgpu_timeout_expired_msg_impl(struct nvgpu_timeout *timeout, + void *caller, const char *fmt, ...); +#endif + #endif /* NVGPU_TIMERS_H */ diff --git a/drivers/gpu/nvgpu/libnvgpu-drv_safe.export b/drivers/gpu/nvgpu/libnvgpu-drv_safe.export index 81541dcef..45bdfabe6 100644 --- a/drivers/gpu/nvgpu/libnvgpu-drv_safe.export +++ b/drivers/gpu/nvgpu/libnvgpu-drv_safe.export @@ -250,6 +250,7 @@ nvgpu_kmem_cache_destroy nvgpu_kmem_cache_free nvgpu_kmem_get_fault_injection nvgpu_kzalloc_impl +nvgpu_log_msg_impl nvgpu_memset nvgpu_mem_create_from_phys nvgpu_mem_iommu_translate @@ -327,7 +328,6 @@ nvgpu_readl nvgpu_readl_impl nvgpu_runlist_construct_locked nvgpu_rwsem_init -nvgpu_timeout_expired_msg_impl nvgpu_timeout_init nvgpu_timeout_peek_expired nvgpu_tsg_abort diff --git a/drivers/gpu/nvgpu/os/posix/timers.c b/drivers/gpu/nvgpu/os/posix/timers.c index c843d1b15..97d9abd2f 100644 --- a/drivers/gpu/nvgpu/os/posix/timers.c +++ b/drivers/gpu/nvgpu/os/posix/timers.c @@ -98,89 +98,6 @@ int nvgpu_timeout_init(struct gk20a *g, struct nvgpu_timeout *timeout, return 0; } -/* - * 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]; - - (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) -{ - if (timeout->retries.attempted >= timeout->retries.max_attempts) { - 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; - - if ((timeout->flags & NVGPU_TIMER_RETRY_TIMER) != 0U) { - 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); - -#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 - } - - return ret; -} - bool nvgpu_timeout_peek_expired(struct nvgpu_timeout *timeout) { if ((timeout->flags & NVGPU_TIMER_RETRY_TIMER) != 0U) {