From e85752a468d5810922b80a7d8064585a0991fc02 Mon Sep 17 00:00:00 2001 From: Alex Waterman Date: Wed, 7 Nov 2018 11:19:18 -0800 Subject: [PATCH] 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 Reviewed-on: https://git-master.nvidia.com/r/1945144 Reviewed-by: mobile promotions Tested-by: mobile promotions --- drivers/gpu/nvgpu/include/nvgpu/bug.h | 29 +++++++++++++++++++++ drivers/gpu/nvgpu/include/nvgpu/posix/bug.h | 4 --- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/nvgpu/include/nvgpu/bug.h b/drivers/gpu/nvgpu/include/nvgpu/bug.h index 3d139b757..c458af58a 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/bug.h +++ b/drivers/gpu/nvgpu/include/nvgpu/bug.h @@ -30,4 +30,33 @@ #include #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 */ diff --git a/drivers/gpu/nvgpu/include/nvgpu/posix/bug.h b/drivers/gpu/nvgpu/include/nvgpu/posix/bug.h index b17447568..0dcb37a33 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/posix/bug.h +++ b/drivers/gpu/nvgpu/include/nvgpu/posix/bug.h @@ -26,10 +26,6 @@ #include #include -/* - * TODO: make these actually useful! - */ - #define BUG() __bug("") #define BUG_ON(cond) \ do { \