gpu: nvgpu: add BUG() callbacks

Add support for registering callbacks that will
be called on BUG().

Jira NVGPU-4512

Change-Id: I35c9b6c17db3b9fa5d098918223083f0b4aaace4
Signed-off-by: Thomas Fleury <tfleury@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2266391
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
This commit is contained in:
Thomas Fleury
2019-12-19 15:00:39 -05:00
committed by Alex Waterman
parent 569f34470e
commit 1f3f34b906
4 changed files with 123 additions and 3 deletions

View File

@@ -28,6 +28,7 @@
#include <nvgpu/posix/bug.h>
#endif
#include <nvgpu/cov_whitelist.h>
#include <nvgpu/list.h>
/*
* Define an assert macro that code within nvgpu can use.
@@ -92,4 +93,25 @@ struct gk20a;
nvgpu_do_assert(); \
} while (false)
struct nvgpu_bug_cb
{
void (*cb)(void *arg);
void *arg;
struct nvgpu_list_node node;
};
static inline struct nvgpu_bug_cb *
nvgpu_bug_cb_from_node(struct nvgpu_list_node *node)
{
return (struct nvgpu_bug_cb *)
((uintptr_t)node - offsetof(struct nvgpu_bug_cb, node));
};
#ifdef __KERNEL__
static inline void nvgpu_bug_exit(void) { }
static inline void nvgpu_bug_register_cb(struct nvgpu_bug_cb *cb) { }
static inline void nvgpu_bug_unregister_cb(struct nvgpu_bug_cb *cb) { }
#endif
#endif /* NVGPU_BUG_H */

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011-2019, NVIDIA CORPORATION. All rights reserved.
* Copyright (c) 2011-2020, NVIDIA CORPORATION. All rights reserved.
*
* GK20A Graphics
*
@@ -698,6 +698,7 @@ struct gk20a {
struct nvgpu_cond sw_quiesce_cond;
struct nvgpu_thread sw_quiesce_thread;
#endif
struct nvgpu_list_node bug_node;
/** Controls which messages are logged */
u64 log_mask;

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018-2019, NVIDIA CORPORATION. All rights reserved.
* Copyright (c) 2018-2020, 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"),
@@ -134,4 +134,33 @@ void bug_handler_cancel(void);
bug_result; \
})
#endif
struct nvgpu_bug_cb;
/**
* @brief Register callback to be invoked on BUG()
*
* @param cb [in] Pointer to callback structure
*
* Register a callback to be invoked on BUG().
* The nvgpu_bug_cb structure contains a function pointer
* and an argument to be passed to this function.
* This mechanism can be used to perform some emergency
* operations on a GPU before exiting the process.
*
* Note: callback is automatically unregistered before
* being invoked.
*/
void nvgpu_bug_register_cb(struct nvgpu_bug_cb *cb);
/**
* @brief Unregister a callback for BUG()
*
* @param cb [in] Pointer to callback structure
*
* Remove a callback from the list of callbacks to be
* invoked on BUG().
*/
void nvgpu_bug_unregister_cb(struct nvgpu_bug_cb *cb);
#endif /* NVGPU_POSIX_BUG_H */