From eac689291a4d424710378d90aa2a3d3fecbc78ca Mon Sep 17 00:00:00 2001 From: Felix Kuehling Date: Fri, 25 Nov 2022 13:53:31 -0500 Subject: [PATCH] libhsakmt: Fix and simplify debug_get_reg_status The NULL pointer check was the only way for that function to fail. And it was done after the pointer was accessed. Simplify this by just returning the result as a return value instead of using a pointer as output parameter. This way the function can never fail and the caller doesn't need to do any error handling. Declare the function in libhsakmt.h instead of duplicating the declaration in fmm.c. Signed-off-by: Felix Kuehling Change-Id: I91b90d66166fd3b5cdc47c73a9bbc369c45b51fe [ROCm/ROCR-Runtime commit: 2d53430ce3f332cd7c2f05f6a9606d75fb6d76b3] --- projects/rocr-runtime/src/debug.c | 17 +++++------------ projects/rocr-runtime/src/fmm.c | 5 ++--- projects/rocr-runtime/src/libhsakmt.h | 1 + 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/projects/rocr-runtime/src/debug.c b/projects/rocr-runtime/src/debug.c index 0b73c6ce8f..d225e0cc9a 100644 --- a/projects/rocr-runtime/src/debug.c +++ b/projects/rocr-runtime/src/debug.c @@ -33,8 +33,6 @@ static bool *is_device_debugged; -int debug_get_reg_status(uint32_t node_id, bool *is_debugged); - HSAKMT_STATUS init_device_debugging_memory(unsigned int NumNodes) { unsigned int i; @@ -57,6 +55,11 @@ void destroy_device_debugging_memory(void) } } +bool debug_get_reg_status(uint32_t node_id) +{ + return is_device_debugged[node_id]; +} + HSAKMT_STATUS HSAKMTAPI hsaKmtDbgRegister(HSAuint32 NodeId) { HSAKMT_STATUS result; @@ -262,16 +265,6 @@ HSAKMT_STATUS HSAKMTAPI hsaKmtDbgAddressWatch(HSAuint32 NodeId, return HSAKMT_STATUS_SUCCESS; } -int debug_get_reg_status(uint32_t node_id, bool *is_debugged) -{ - *is_debugged = NULL; - if (!is_device_debugged) - return -1; - - *is_debugged = is_device_debugged[node_id]; - return 0; -} - /* Get the major and minor version of the kernel debugger support. */ HSAKMT_STATUS HSAKMTAPI diff --git a/projects/rocr-runtime/src/fmm.c b/projects/rocr-runtime/src/fmm.c index 67d0d0bb09..847bd0ecfa 100644 --- a/projects/rocr-runtime/src/fmm.c +++ b/projects/rocr-runtime/src/fmm.c @@ -296,7 +296,6 @@ static inline HsaSharedMemoryHandle *to_hsa_shared_memory_handle( return (HsaSharedMemoryHandle *)SharedMemoryStruct; } -extern int debug_get_reg_status(uint32_t node_id, bool *is_debugged); static int __fmm_release(vm_object_t *object, manageable_aperture_t *aperture); static int _fmm_unmap_from_gpu_scratch(uint32_t gpu_id, manageable_aperture_t *aperture, @@ -2841,9 +2840,9 @@ static int _fmm_map_to_gpu_scratch(uint32_t gpu_id, manageable_aperture_t *apert VOID_PTR_ADD(address, size - 1) > aperture->limit) return -1; - ret = debug_get_reg_status(gpu_mem[gpu_mem_id].node_id, &is_debugger); + is_debugger = debug_get_reg_status(gpu_mem[gpu_mem_id].node_id); /* allocate object within the scratch backing aperture */ - if (!ret && !is_debugger) { + if (!is_debugger) { obj = fmm_allocate_memory_object( gpu_id, address, size, aperture, &mmap_offset, KFD_IOC_ALLOC_MEM_FLAGS_VRAM | diff --git a/projects/rocr-runtime/src/libhsakmt.h b/projects/rocr-runtime/src/libhsakmt.h index c9d6fcf46b..2e4b455cbf 100644 --- a/projects/rocr-runtime/src/libhsakmt.h +++ b/projects/rocr-runtime/src/libhsakmt.h @@ -191,6 +191,7 @@ HSAKMT_STATUS init_process_doorbells(unsigned int NumNodes); void destroy_process_doorbells(void); HSAKMT_STATUS init_device_debugging_memory(unsigned int NumNodes); void destroy_device_debugging_memory(void); +bool debug_get_reg_status(uint32_t node_id); HSAKMT_STATUS init_counter_props(unsigned int NumNodes); void destroy_counter_props(void); uint32_t *convert_queue_ids(HSAuint32 NumQueues, HSA_QUEUEID *Queues);