gpu: nvgpu: Add an nvgpu_assert macro

This macro helps us differentiate what to do with debugging
statements depending on OS. Different OSes have different
considerations for what to do when bad state in the driver
is detected.

JIRA NVGPU-1323

Change-Id: If435ef490146e87e809645453e8ac1065e13cace
Signed-off-by: Alex Waterman <alexw@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/1945144
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
This commit is contained in:
Alex Waterman
2018-11-07 11:19:18 -08:00
committed by mobile promotions
parent 88e374d5eb
commit e85752a468
2 changed files with 29 additions and 4 deletions

View File

@@ -30,4 +30,33 @@
#include <nvgpu_rmos/include/bug.h>
#endif
/*
* Define an assert macro that code within nvgpu can use.
*
* The goal of this macro is for debugging but what that means varies from OS
* to OS. On Linux wee don't want to BUG() for general driver misbehaving. BUG()
* is a very heavy handed tool - in fact there's probably no where within the
* nvgpu core code where it makes sense to use a BUG() when running under Linux.
*
* However, on QNX (and POSIX) BUG() will just kill the current process. This
* means we can use it for handling bugs in nvgpu.
*
* As a result this macro varies depending on platform.
*/
#if defined(__KERNEL__)
#define nvgpu_assert(cond) WARN_ON(!(cond))
#elif defined(__NVGPU_POSIX__)
/*
* A static inline for POSIX so that we can hide the branch in BUG_ON() from the
* branch analysis for users of this function. When this assert fails the
* function will not return.
*/
static inline void nvgpu_assert(bool cond)
{
BUG_ON(!cond);
}
#else
#define nvgpu_assert(cond) BUG_ON(!(cond))
#endif
#endif /* NVGPU_BUG_H */

View File

@@ -26,10 +26,6 @@
#include <nvgpu/types.h>
#include <setjmp.h>
/*
* TODO: make these actually useful!
*/
#define BUG() __bug("")
#define BUG_ON(cond) \
do { \