[PATCH umr] switch over from ttm trace to iova debugfs entry
Tom St Denis
tom.stdenis at amd.com
Mon Sep 18 12:36:26 UTC 2017
Signed-off-by: Tom St Denis <tom.stdenis at amd.com>
---
src/lib/CMakeLists.txt | 1 -
src/lib/close_asic.c | 2 +-
src/lib/discover.c | 3 +
src/lib/free_maps.c | 44 -------------
src/lib/read_vram.c | 167 ++-----------------------------------------------
src/umr.h | 14 +----
6 files changed, 10 insertions(+), 221 deletions(-)
delete mode 100644 src/lib/free_maps.c
diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt
index 78d827ac1bf1..a21fdf8eea2d 100644
--- a/src/lib/CMakeLists.txt
+++ b/src/lib/CMakeLists.txt
@@ -14,7 +14,6 @@ add_library(umrcore STATIC
discover.c
dump_ib.c
find_reg.c
- free_maps.c
mmio.c
query_drm.c
read_sensor.c
diff --git a/src/lib/close_asic.c b/src/lib/close_asic.c
index d532a11fa671..a140409e617b 100644
--- a/src/lib/close_asic.c
+++ b/src/lib/close_asic.c
@@ -29,7 +29,6 @@
void umr_free_asic(struct umr_asic *asic)
{
int x;
- umr_free_maps(asic);
if (asic->pci.mem != NULL) {
// free PCI mapping
pci_device_unmap_range(asic->pci.pdevice, asic->pci.mem, asic->pci.pdevice->regions[asic->pci.region].size);
@@ -57,6 +56,7 @@ void umr_close_asic(struct umr_asic *asic)
cond_close(asic->fd.vram);
cond_close(asic->fd.gpr);
cond_close(asic->fd.drm);
+ cond_close(asic->fd.iova);
umr_free_asic(asic);
}
}
diff --git a/src/lib/discover.c b/src/lib/discover.c
index dcc212fc39e4..ff7950e4e6ba 100644
--- a/src/lib/discover.c
+++ b/src/lib/discover.c
@@ -222,6 +222,8 @@ struct umr_asic *umr_discover_asic(struct umr_options *options)
asic->fd.vram = open(fname, O_RDWR);
snprintf(fname, sizeof(fname)-1, "/sys/kernel/debug/dri/%d/amdgpu_gpr", asic->instance);
asic->fd.gpr = open(fname, O_RDWR);
+ snprintf(fname, sizeof(fname)-1, "/sys/kernel/debug/dri/%d/amdgpu_iova", asic->instance);
+ asic->fd.iova = open(fname, O_RDWR);
asic->fd.drm = -1; // default to closed
// if appending to the fd list remember to update close_asic() and discover_by_did()...
} else {
@@ -235,6 +237,7 @@ struct umr_asic *umr_discover_asic(struct umr_options *options)
asic->fd.vram = -1;
asic->fd.gpr = -1;
asic->fd.drm = -1;
+ asic->fd.iova = -1;
}
if (options->use_pci) {
diff --git a/src/lib/free_maps.c b/src/lib/free_maps.c
deleted file mode 100644
index e1d27cb177f7..000000000000
--- a/src/lib/free_maps.c
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright 2017 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"
-
-static void recurse_free(struct umr_map *map)
-{
- if (map->left)
- recurse_free(map->left);
- if (map->right)
- recurse_free(map->right);
- free(map);
-}
-
-void umr_free_maps(struct umr_asic *asic)
-{
- if (!asic->maps)
- return;
-
- recurse_free(asic->maps->maps);
- free(asic->maps);
- asic->maps = NULL;
-}
diff --git a/src/lib/read_vram.c b/src/lib/read_vram.c
index 6e8f1f931895..7890c90c51df 100644
--- a/src/lib/read_vram.c
+++ b/src/lib/read_vram.c
@@ -25,161 +25,13 @@
#include "umrapp.h"
#include <inttypes.h>
-// find a mapping or create node for it
-static struct umr_map *find_map(struct umr_dma_maps *maps, uint64_t dma_addr, int create)
-{
- struct umr_map *n = maps->maps, **nn;
- uint64_t key;
-
- // addresses aren't terribly random
- // so if we use an identity function on the search
- // key we'll end up with a really unbalanced tree
- // so mix up address a bit to randomize keys
- key = dma_addr ^ (dma_addr >> 11);
-
- if (!n) {
- maps->maps = calloc(1, sizeof(maps->maps[0]));
- maps->maps->key = key;
- return maps->maps;
- }
-
- while (n->dma_addr != dma_addr) {
- if (key > n->key)
- nn = &n->left;
- else
- nn = &n->right;
-
- if (*nn) {
- n = *nn;
- } else {
- if (!create) return NULL;
-
- // add the new node
- *nn = calloc(1, sizeof(maps->maps[0]));
- (*nn)->key = key;
- return *nn;
- }
- }
-
- return n;
-}
-
-// insert/replace mapping in array
-static int insert_map(struct umr_dma_maps *maps,
- uint64_t dma_addr, uint64_t phys_addr, int valid)
-{
- struct umr_map *map = find_map(maps, dma_addr, valid);
-
- // don't add a new node if we're marking it invalid
- if (map) {
- if (valid) {
- map->dma_addr = dma_addr;
- map->phys_addr = phys_addr;
- map->valid = valid;
- } else {
- struct umr_map *tmap = NULL;
-
- // if marking invalid see if we can prune
- // the tree a little if the node we're marking
- // as invalid only has one child
- if (map->left == NULL && map->right) {
- tmap = map->right;
- *map = *(map->right);
- } else if (map->right == NULL && map->left) {
- tmap = map->left;
- *map = *(map->left);
- }
- if (tmap)
- free(tmap);
- }
- }
-
- return 0;
-}
-
-static int check_trace = 0;
-
// try to convert a DMA address to physical via trace
static uint64_t dma_to_phys(struct umr_asic *asic, uint64_t dma_addr)
{
- struct umr_map *map = find_map(asic->maps, dma_addr, 0);
-
- if (map == NULL)
- return dma_addr;
-
- if (map->valid)
- return map->phys_addr;
- else
- return map->dma_addr;
-}
-
-static int parse_trace(struct umr_asic *asic)
-{
- FILE *f;
- uint64_t d, p;
- char *s, buf[512];
- int err = -1, valid;
- struct umr_dma_maps *maps = asic->maps;
-
- if (!check_trace) {
- check_trace = 1;
- f = fopen("/sys/kernel/debug/tracing/events/ttm/ttm_dma_map/enable", "r");
- if (!f) {
- fprintf(stderr, "[WARNING]: kernel does not support TTM mapping trace, please update kernel\n");
- } else {
- fgets(buf, sizeof(buf)-1, f);
- if (sscanf(buf, "%"SCNu64, &d) == 1) {
- if (d != 1) {
- fprintf(stderr,
- "[WARNING]: ttm_dma_map trace is not enabled, VM decoding may fail!\n"
- "[WARNING]: Enable with: 'echo 1 > /sys/kernel/debug/tracing/events/ttm/ttm_dma_map/enable'\n"
- "[WARNING]: Enable with: 'echo 1 > /sys/kernel/debug/tracing/events/ttm/ttm_dma_unmap/enable'\n");
- }
- } else {
- fprintf(stderr, "[ERROR]: could not read ttm_dma_map enable file\n");
- }
- fclose(f);
- }
- }
-
- // try to open ~/trace first
- snprintf(buf, sizeof(buf)-1, "%s/trace", getenv("HOME"));
- f = fopen(buf, "r");
- if (!f)
- f = fopen("/sys/kernel/debug/tracing/trace", "r");
- if (!f)
- goto error;
-
- while (fgets(buf, sizeof(buf)-1, f)) {
- valid = -1;
-
- s = strstr(buf, "ttm_dma_map");
- if (s) {
- s += strlen("ttm_dma_map");
- valid = 1;
- } else {
- s = strstr(buf, "ttm_dma_unmap");
- if (s) {
- s += strlen("ttm_dma_unmap");
- valid = 0;
- }
- }
-
- if (valid != -1) {
- s = strstr(s, asic->options.pci.name);
- if (s) {
- s += strlen(asic->options.pci.name) + 2;
- if (sscanf(s, "0x%"SCNx64" => 0x%"SCNx64, &d, &p) == 2) {
- if (insert_map(maps, d, p, valid))
- goto error;
- }
- }
- }
- }
- err = 0;
-error:
- fclose(f);
- return err;
+ uint64_t phys;
+ lseek(asic->fd.iova, dma_addr & ~0xFFFULL, SEEK_SET);
+ read(asic->fd.iova, &phys, 8);
+ return phys;
}
static void access_vram_via_mmio(struct umr_asic *asic, uint64_t address, uint32_t size, void *dst, int write_en)
@@ -825,17 +677,6 @@ int umr_access_vram(struct umr_asic *asic, uint32_t vmid, uint64_t address, uint
return 0;
}
- if (!asic->maps) {
- asic->maps = calloc(1, sizeof(asic->maps[0]));
- if (!asic->maps) {
- fprintf(stderr, "[ERROR]: Out of memory building dma maps\n");
- return -1;
- }
-
- if (parse_trace(asic))
- return -1;
- }
-
switch (asic->family) {
case FAMILY_SI:
case FAMILY_CIK:
diff --git a/src/umr.h b/src/umr.h
index 3d2252e35608..a374a0d23301 100644
--- a/src/umr.h
+++ b/src/umr.h
@@ -210,17 +210,6 @@ struct umr_options {
} pci;
};
-struct umr_dma_maps {
- struct umr_map {
- uint64_t
- dma_addr,
- phys_addr,
- key;
- int valid;
- struct umr_map *left, *right;
- } *maps;
-};
-
struct umr_asic {
char *asicname;
int no_blocks;
@@ -243,7 +232,8 @@ struct umr_asic {
drm,
wave,
vram,
- gpr;
+ gpr,
+ iova;
} fd;
struct {
struct pci_device *pdevice;
--
2.12.0
More information about the amd-gfx
mailing list