[PATCH umr] Re-factor ring reading out of app side of build
Tom St Denis
tom.stdenis at amd.com
Wed May 9 11:45:26 UTC 2018
This will be used later on by the ring/ib decoder
library API that is coming.
Signed-off-by: Tom St Denis <tom.stdenis at amd.com>
---
src/app/ring_read.c | 24 ++++----------------
src/lib/CMakeLists.txt | 1 +
src/lib/umr_read_ring_data.c | 53 ++++++++++++++++++++++++++++++++++++++++++++
src/umr.h | 1 +
4 files changed, 59 insertions(+), 20 deletions(-)
create mode 100644 src/lib/umr_read_ring_data.c
diff --git a/src/app/ring_read.c b/src/app/ring_read.c
index 112e9f0414ad..e3ffd4aab277 100644
--- a/src/app/ring_read.c
+++ b/src/app/ring_read.c
@@ -27,8 +27,8 @@
void umr_read_ring(struct umr_asic *asic, char *ringpath)
{
- char fname[128], ringname[32], from[32], to[32];
- int fd, use_decoder, enable_decoder;
+ char ringname[32], from[32], to[32];
+ int use_decoder, enable_decoder;
uint32_t wptr, rptr, drv_wptr, ringsize, start, end, value,
*ring_data;
struct umr_ring_decoder decoder, *pdecoder, *ppdecoder;
@@ -42,13 +42,6 @@ void umr_read_ring(struct umr_asic *asic, char *ringpath)
return;
}
- snprintf(fname, sizeof(fname)-1, "/sys/kernel/debug/dri/%d/amdgpu_ring_%s", asic->instance, ringname);
- fd = open(fname, O_RDWR);
- if (fd < 0) {
- perror("Could not open ring debugfs file");
- return;
- }
-
// only decode PM4 packets on certain rings
memset(&decoder, 0, sizeof decoder);
if (!memcmp(ringname, "gfx", 3) ||
@@ -69,18 +62,9 @@ void umr_read_ring(struct umr_asic *asic, char *ringpath)
if (asic->options.halt_waves)
umr_sq_cmd_halt_waves(asic, UMR_SQ_CMD_HALT);
- /* determine file size */
- ringsize = lseek(fd, 0, SEEK_END) - 12;
- lseek(fd, 0, SEEK_SET);
-
- ring_data = calloc(1, ringsize + 12);
- if (!ring_data) {
- close(fd);
- perror("Could not allocate ring data");
+ ring_data = umr_read_ring_data(asic, ringname, &ringsize);
+ if (!ring_data)
goto end;
- }
- read(fd, ring_data, ringsize + 12);
- close(fd);
/* read pointers */
rptr = ring_data[0]<<2;
diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt
index fc87ab725370..7a04540b58c8 100644
--- a/src/lib/CMakeLists.txt
+++ b/src/lib/CMakeLists.txt
@@ -27,6 +27,7 @@ add_library(umrcore STATIC
wave_status.c
umr_apply_bank_address.c
umr_llvm_disasm.c
+ umr_read_ring_data.c
update.c
version.c
$<TARGET_OBJECTS:asic> $<TARGET_OBJECTS:ip>
diff --git a/src/lib/umr_read_ring_data.c b/src/lib/umr_read_ring_data.c
new file mode 100644
index 000000000000..cbdeab5f1d7b
--- /dev/null
+++ b/src/lib/umr_read_ring_data.c
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2018 Advanced Micro Devices, Inc.
+ *
+ * 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 COPYRIGHT HOLDER(S) OR AUTHOR(S) 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.
+ *
+ * Authors: Tom St Denis <tom.stdenis at amd.com>
+ *
+ */
+#include "umr.h"
+
+void *umr_read_ring_data(struct umr_asic *asic, char *ringname, uint32_t *ringsize)
+{
+ int fd;
+ void *ring_data;
+ char fname[128];
+
+ snprintf(fname, sizeof(fname)-1, "/sys/kernel/debug/dri/%d/amdgpu_ring_%s", asic->instance, ringname);
+ fd = open(fname, O_RDWR);
+ if (fd < 0) {
+ fprintf(stderr, "[ERROR]: Could not open ring debugfs file");
+ return NULL;
+ }
+
+ /* determine file size */
+ *ringsize = lseek(fd, 0, SEEK_END) - 12;
+ lseek(fd, 0, SEEK_SET);
+
+ ring_data = calloc(1, *ringsize + 12);
+ if (!ring_data) {
+ close(fd);
+ fprintf(stderr, "[ERROR]: Out of memory\n");
+ return NULL;
+ }
+ read(fd, ring_data, *ringsize + 12);
+ close(fd);
+ return ring_data;
+}
diff --git a/src/umr.h b/src/umr.h
index e4ae645cea62..290824b271f1 100644
--- a/src/umr.h
+++ b/src/umr.h
@@ -620,6 +620,7 @@ int umr_grbm_select_index(struct umr_asic *asic, uint32_t se, uint32_t sh, uint3
int umr_sq_cmd_halt_waves(struct umr_asic *asic, enum umr_sq_cmd_halt_resume mode);
/* IB/ring decoding/dumping/etc */
+void *umr_read_ring_data(struct umr_asic *asic, char *ringname, uint32_t *ringsize);
void umr_print_decode(struct umr_asic *asic, struct umr_ring_decoder *decoder, uint32_t ib);
void umr_dump_ib(struct umr_asic *asic, struct umr_ring_decoder *decoder);
void umr_dump_shaders(struct umr_asic *asic, struct umr_ring_decoder *decoder, struct umr_wave_data *wd);
--
2.14.3
More information about the amd-gfx
mailing list