Commit e7e733df authored by Alyssa Rosenzweig's avatar Alyssa Rosenzweig 💜

panwrap: Switch to direct tracing

Rather than dumping memory to the filesystem for analysis by an external
tool, we can link directly with the pandecode library built with mesa to
trace directly, which is significantly faster and more reliable.
Unfortunately, it makes building rather... complex... since we're still
out-of-tree.
Signed-off-by: Alyssa Rosenzweig's avatarAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
parent f729b62d
......@@ -37,10 +37,19 @@ m_dep = cc.find_library('m', required: true)
dl_dep = cc.find_library('dl', required: false)
pthread_dep = dependency('threads')
libpanfrost_decode_dep = cc.find_library('libpanfrost_decode', dirs : meson.current_source_dir() + '/../../../../build/src/panfrost/pandecode')
libpanfrost_midgard_dep = cc.find_library('libpanfrost_midgard', dirs : meson.current_source_dir() + '/../../../../build/src/panfrost/midgard')
libpanfrost_bifrost_dep = cc.find_library('libpanfrost_bifrost', dirs : meson.current_source_dir() + '/../../../../build/src/panfrost/bifrost')
util_dep = cc.find_library('libmesa_util', dirs : meson.current_source_dir() + '/../../../../build/src/util')
common_dep = [
m_dep,
dl_dep,
pthread_dep,
libpanfrost_decode_dep,
libpanfrost_midgard_dep,
libpanfrost_bifrost_dep,
util_dep
]
if not cc.has_argument('-Werror=attributes')
......@@ -69,7 +78,10 @@ foreach t: test_c_srcs
endif
endforeach
inc = include_directories('include')
inc = [
include_directories('include'),
include_directories('..'),
]
subdir('include')
subdir('panwrap')
......@@ -28,29 +28,11 @@
#include <linux/mman.h>
#endif
#include "public.h"
static LIST_HEAD(allocations);
static LIST_HEAD(mmaps);
extern char *log_base;
void replay_memory()
{
struct panwrap_mapped_memory *pos;
list_for_each_entry(pos, &mmaps, node) {
/* If we don't have write access, no replay */
if (!(pos->flags & MALI_MEM_PROT_CPU_WR)) continue;
if (pos->flags & MALI_MEM_GROW_ON_GPF) continue;
/* Dump to file */
char filename[128];
snprintf(filename, 128, "%s/%s.bin", log_base, pos->name);
FILE *fp = fopen(filename, "wb");
fwrite(pos->addr, 1, pos->length, fp);
fclose(fp);
}
}
void panwrap_track_allocation(mali_ptr addr, int flags, int number, size_t length)
{
struct panwrap_allocated_memory *mem = malloc(sizeof(*mem));
......@@ -68,8 +50,6 @@ void panwrap_track_allocation(mali_ptr addr, int flags, int number, size_t lengt
panwrap_track_mmap(addr, (void *) (uintptr_t) addr, length, PROT_READ | PROT_WRITE, MAP_SHARED);
}
extern FILE * log_output;
void panwrap_track_mmap(mali_ptr gpu_va, void *addr, size_t length,
int prot, int flags)
{
......@@ -97,56 +77,19 @@ void panwrap_track_mmap(mali_ptr gpu_va, void *addr, size_t length,
#define MEM_COOKIE_VA 0x41000
if (mem->flags & MALI_MEM_SAME_VA && gpu_va == MEM_COOKIE_VA) {
mapped_mem->gpu_va = (mali_ptr) (uintptr_t) addr;
} else {
mapped_mem->gpu_va = gpu_va;
}
mapped_mem->length = length;
mapped_mem->addr = addr;
mapped_mem->prot = prot;
mapped_mem->flags = mem->flags;
mapped_mem->allocation_number = mem->allocation_number;
list_add(&mapped_mem->node, &mmaps);
list_del(&mem->node);
free(mem);
if (mem->flags & MALI_MEM_SAME_VA && gpu_va == MEM_COOKIE_VA)
gpu_va = (mali_ptr) (uintptr_t) addr;
/* Generate somewhat semantic name for the region */
snprintf(mapped_mem->name, sizeof(mapped_mem->name),
char name[512];
snprintf(name, sizeof(name) -1,
"%s_%d",
mem->flags & MALI_MEM_PROT_GPU_EX ? "shader" : "memory",
mapped_mem->allocation_number);
mem->allocation_number);
/* Track it */
fprintf(log_output, "MMAP %" PRIx64" %s.bin\n", mapped_mem->gpu_va, mapped_mem->name);
}
pandecode_inject_mmap(gpu_va, addr, length, name);
void panwrap_track_munmap(void *addr)
{
struct panwrap_mapped_memory *mapped_mem =
panwrap_find_mapped_mem(addr);
if (!mapped_mem) {
printf("// Unknown mmap %p unmapped\n", addr);
return;
}
list_del(&mapped_mem->node);
free(mapped_mem);
}
struct panwrap_mapped_memory *panwrap_find_mapped_mem(void *addr)
{
struct panwrap_mapped_memory *pos;
list_for_each_entry(pos, &mmaps, node) {
if (pos->addr == addr)
return pos;
}
return NULL;
list_del(&mem->node);
free(mem);
}
......@@ -47,10 +47,7 @@ struct panwrap_mapped_memory {
void panwrap_track_allocation(mali_ptr gpu_va, int flags, int number, size_t length);
void panwrap_track_mmap(mali_ptr gpu_va, void *addr, size_t length,
int prot, int flags);
void panwrap_track_munmap(void *addr);
struct panwrap_mapped_memory *panwrap_find_mapped_mem(void *addr);
void replay_memory(void);
#endif /* __MMAP_TRACE_H__ */
......@@ -33,6 +33,7 @@
#include <mali-props.h>
#include <list.h>
#include "panwrap.h"
#include "public.h"
static pthread_mutex_t l;
static void __attribute__((constructor)) panloader_constructor(void) {
......@@ -173,7 +174,6 @@ close(int fd)
/* HW version */
static bool bifrost = false;
int allocation_number = 0;
extern FILE * log_output;
/* XXX: Android has a messed up ioctl signature */
int ioctl(int fd, int _request, ...)
......@@ -206,14 +206,10 @@ int ioctl(int fd, int _request, ...)
if (IOCTL_CASE(request) == IOCTL_CASE(MALI_IOCTL_JOB_SUBMIT)) {
const struct mali_ioctl_job_submit *js = ptr;
struct mali_jd_atom_v2 *atoms = js->addr;
for (unsigned i = 0; i < js->nr_atoms; ++i) {
unsigned core_req = atoms[i].core_req | atoms[i].compat_core_req;
fprintf(log_output, "JS %" PRIx64 " %X %d\n", atoms[i].jc, core_req, bifrost);
}
replay_memory();
for (unsigned i = 0; i < js->nr_atoms; ++i)
pandecode_jc(atoms[i].jc, bifrost);
}
mali_ptr alloc_va_pages = 0;
......@@ -307,25 +303,3 @@ void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset)
#endif
}
//#endif
int munmap(void *addr, size_t length)
{
int ret;
struct panwrap_mapped_memory *mem;
PROLOG(munmap);
if (!mali_fd)
return orig_munmap(addr, length);
LOCK();
ret = orig_munmap(addr, length);
mem = panwrap_find_mapped_mem(addr);
if (!mem)
goto out;
list_del(&mem->node);
free(mem);
out:
UNLOCK();
return ret;
}
......@@ -21,9 +21,7 @@
#include <time.h>
#include <ctype.h>
#include "panwrap.h"
FILE *log_output;
char *log_base;
#include "public.h"
/**
* Grab the location of a symbol from the system's libc instead of our
......@@ -54,19 +52,5 @@ __rd_dlsym_helper(const char *name)
}
static void __attribute__((constructor)) constructor_util(void) {
log_base = getenv("PANWRAP_OUTPUT");
if (!log_base) {
log_base = "/dev/shm";
}
char control_name[256];
snprintf(control_name, sizeof(control_name), "%s/control.log", log_base);
log_output = fopen(control_name, "w+");
if (!log_output) {
fprintf(stderr, "Failed to open %s: %s\n",
control_name, strerror(errno));
exit(1);
}
pandecode_initialize();
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment