gpu: nvgpu: fix MISRA 17.1 in timeout_expired_msg

MISRA rule 17.1 forbids use of stdarg.h features defined for variable
arguments. This patch creates timers.h header for posix and QNX to
change nvgpu_timeout_expired_msg() to macro definition.

Jira NVGPU-4075

Change-Id: I8167f0ff7fdfb74adbbbed9c3021a9df2ad6401b
Signed-off-by: Vedashree Vidwans <vvidwans@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/2200885
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
This commit is contained in:
Vedashree Vidwans
2019-10-03 16:29:36 -07:00
committed by Alex Waterman
parent 7c98fbba42
commit d6fc9d176e
7 changed files with 94 additions and 96 deletions

View File

@@ -102,7 +102,8 @@ threads:
timers: timers:
safe: yes safe: yes
owner: Ajesh K owner: Ajesh K
sources: [ os/posix/timers.c ] sources: [ os/posix/timers.c,
include/nvgpu/posix/timers.h ]
deps: deps:
atomic: atomic:

View File

@@ -692,7 +692,7 @@ int gv11b_fb_mmu_invalidate_replay(struct gk20a *g,
} }
nvgpu_udelay(5); nvgpu_udelay(5);
} while (nvgpu_timeout_expired_msg(&timeout, } while (nvgpu_timeout_expired_msg(&timeout,
"invalidate replay failed 0x%lx", "invalidate replay failed 0x%x",
invalidate_replay_val) == 0); invalidate_replay_val) == 0);
if (err != 0) { if (err != 0) {
nvgpu_err(g, "invalidate replay timedout"); nvgpu_err(g, "invalidate replay timedout");

View File

@@ -231,7 +231,7 @@ int tu104_fb_mmu_invalidate_replay(struct gk20a *g,
} }
nvgpu_udelay(5); nvgpu_udelay(5);
} while (nvgpu_timeout_expired_msg(&timeout, } while (nvgpu_timeout_expired_msg(&timeout,
"invalidate replay failed on 0x%lx", "invalidate replay failed on 0x%x",
invalidate_replay_val) == 0); invalidate_replay_val) == 0);
if (err != 0) { if (err != 0) {
nvgpu_err(g, "invalidate replay timedout"); nvgpu_err(g, "invalidate replay timedout");

View File

@@ -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 <sys/time.h>
#include <time.h>
#include <nvgpu/types.h>
#include <nvgpu/log.h>
#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

View File

@@ -26,6 +26,10 @@
#include <nvgpu/types.h> #include <nvgpu/types.h>
#include <nvgpu/utils.h> #include <nvgpu/utils.h>
#ifndef __KERNEL__
#include <nvgpu/posix/timers.h>
#endif
struct gk20a; struct gk20a;
/* /*
@@ -89,15 +93,7 @@ bool nvgpu_timeout_peek_expired(struct nvgpu_timeout *timeout);
nvgpu_timeout_expired_msg_impl(__timeout, NVGPU_GET_IP, "") nvgpu_timeout_expired_msg_impl(__timeout, NVGPU_GET_IP, "")
#define nvgpu_timeout_expired_msg(__timeout, fmt, args...) \ #define nvgpu_timeout_expired_msg(__timeout, fmt, args...) \
nvgpu_timeout_expired_msg_impl(__timeout, NVGPU_GET_IP, \ nvgpu_timeout_expired_msg_impl(__timeout, NVGPU_GET_IP, fmt, ##args)
fmt, ##args)
/*
* Don't use this directly.
*/
int nvgpu_timeout_expired_msg_impl(struct nvgpu_timeout *timeout,
void *caller, const char *fmt, ...);
/* /*
* Waits and delays. * Waits and delays.
@@ -117,4 +113,12 @@ u64 nvgpu_hr_timestamp_us(void);
#endif #endif
u64 nvgpu_hr_timestamp(void); 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 */ #endif /* NVGPU_TIMERS_H */

View File

@@ -250,6 +250,7 @@ nvgpu_kmem_cache_destroy
nvgpu_kmem_cache_free nvgpu_kmem_cache_free
nvgpu_kmem_get_fault_injection nvgpu_kmem_get_fault_injection
nvgpu_kzalloc_impl nvgpu_kzalloc_impl
nvgpu_log_msg_impl
nvgpu_memset nvgpu_memset
nvgpu_mem_create_from_phys nvgpu_mem_create_from_phys
nvgpu_mem_iommu_translate nvgpu_mem_iommu_translate
@@ -327,7 +328,6 @@ nvgpu_readl
nvgpu_readl_impl nvgpu_readl_impl
nvgpu_runlist_construct_locked nvgpu_runlist_construct_locked
nvgpu_rwsem_init nvgpu_rwsem_init
nvgpu_timeout_expired_msg_impl
nvgpu_timeout_init nvgpu_timeout_init
nvgpu_timeout_peek_expired nvgpu_timeout_peek_expired
nvgpu_tsg_abort nvgpu_tsg_abort

View File

@@ -98,89 +98,6 @@ int nvgpu_timeout_init(struct gk20a *g, struct nvgpu_timeout *timeout,
return 0; 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) bool nvgpu_timeout_peek_expired(struct nvgpu_timeout *timeout)
{ {
if ((timeout->flags & NVGPU_TIMER_RETRY_TIMER) != 0U) { if ((timeout->flags & NVGPU_TIMER_RETRY_TIMER) != 0U) {