[Beignet] [PATCH 2/5] runtime: add support for the interchange library of the debugger
Mircea Gherzan
mircea.gherzan at intel.com
Fri Jul 8 12:39:36 UTC 2016
This library provides routines that:
* tell if the debugger is active or not
* notify the debugger infrastructure about a shader to be debugged
* provide the Gen system routine for debug for a given HW generation
Signed-off-by: Mircea Gherzan <mircea.gherzan at intel.com>
---
src/CMakeLists.txt | 1 +
src/intel/intel_debugger.c | 158 +++++++++++++++++++++++++++++++++++++++++++++
src/intel/intel_debugger.h | 70 ++++++++++++++++++++
3 files changed, 229 insertions(+)
create mode 100644 src/intel/intel_debugger.c
create mode 100644 src/intel/intel_debugger.h
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index a002865..8ca2afd 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -89,6 +89,7 @@ set(OPENCL_SRC
cl_driver_defs.c
intel/intel_gpgpu.c
intel/intel_batchbuffer.c
+ intel/intel_debugger.c
intel/intel_driver.c
performance.c)
diff --git a/src/intel/intel_debugger.c b/src/intel/intel_debugger.c
new file mode 100644
index 0000000..e4cc810
--- /dev/null
+++ b/src/intel/intel_debugger.c
@@ -0,0 +1,158 @@
+/*
+ * Copyright 2016 Intel Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Mircea Gherzan <mircea.gherzan at intel.com>
+ */
+
+/**
+ * @file intel_debugger.c
+ *
+ * This file provides the communication with the shader debugger.
+ */
+
+#include <errno.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <dlfcn.h>
+
+#include "intel_debugger.h"
+
+struct dbg_request_sys_routine_binary3
+{
+ unsigned version;
+ unsigned bti;
+ unsigned char *sys_routine_binary; // set by the interchange
+ unsigned sys_routine_size; // set by the interchange
+ unsigned debug_surface_size; // set by the interchange
+ unsigned gen;
+};
+
+struct dbg_kernel_binary_data
+{
+ unsigned int version;
+ void *device;
+ void *program;
+ const char *kernel_name;
+ const void *kernel_bin_buffer;
+ unsigned int kernel_bin_size;
+ const void *dbg_gen_isa_buffer;
+ unsigned int dbg_gen_isa_size;
+ const char *dbg_info_file_name;
+};
+
+static const unsigned int IGFXDBG_CURRENT_VERSION = 3;
+
+static int (*pfn_is_debugger_active)(void);
+static int (*pfn_notify_kernel_binary_data)(struct dbg_kernel_binary_data *);
+static int (*pfn_req_sys_routine)(struct dbg_request_sys_routine_binary3 *);
+
+static void *
+sym_address(void *lib_handle, const char *sym_name)
+{
+ void *sym_ptr;
+ char *err_ptr;
+
+ dlerror();
+ sym_ptr = dlsym(lib_handle, sym_name);
+ err_ptr = dlerror();
+
+ if (err_ptr)
+ fprintf(stderr, "Could not find symbol %s: %s\n", sym_name, err_ptr);
+
+ return sym_ptr;
+}
+
+static void __attribute__((constructor))
+dbg_init(void)
+{
+#ifdef __x86_64__
+ static const char so_name[] = "libigfxdbgxchg64.so";
+#else
+ static const char so_name[] = "libigfxdbgxchg32.so";
+#endif
+ void *lib;
+
+ lib = dlopen(so_name, RTLD_NOW);
+ if (!lib)
+ return;
+
+ pfn_is_debugger_active = sym_address(lib, "isDebuggerActive");
+ pfn_notify_kernel_binary_data = sym_address(lib, "notifyKernelBinary");
+ pfn_req_sys_routine = sym_address(lib, "requestSipBinary");
+}
+
+int
+dbg_is_active(void)
+{
+ if (pfn_is_debugger_active == NULL)
+ return 0;
+
+ return pfn_is_debugger_active();
+}
+
+int
+dbg_notify_kernel_debug_data(const char *kernel_name,
+ const void *gen_binary,
+ unsigned gen_binary_size)
+{
+ struct dbg_kernel_binary_data dkbd;
+
+ if (!pfn_notify_kernel_binary_data)
+ return -1;
+
+ dkbd.version = IGFXDBG_CURRENT_VERSION;
+ dkbd.device = NULL;
+ dkbd.program = NULL;
+ dkbd.kernel_name = kernel_name;
+ dkbd.kernel_bin_buffer = gen_binary;
+ dkbd.kernel_bin_size = gen_binary_size;
+ dkbd.dbg_gen_isa_buffer = NULL;
+ dkbd.dbg_gen_isa_size = 0;
+ dkbd.dbg_info_file_name = NULL;
+
+ return (*pfn_notify_kernel_binary_data)(&dkbd);
+}
+
+int
+dbg_get_sys_routine_binary(unsigned gen, unsigned bti,
+ const unsigned char **p_sip,
+ unsigned *sip_size, unsigned *res_size)
+{
+ int ret;
+ struct dbg_request_sys_routine_binary3 rsrb = {
+ .version = IGFXDBG_CURRENT_VERSION,
+ .bti = bti,
+ .gen = gen,
+ };
+
+ if (!pfn_req_sys_routine)
+ return -1;
+
+ ret = (*pfn_req_sys_routine)(&rsrb);
+ if (ret) {
+ goto out;
+ }
+
+ *p_sip = rsrb.sys_routine_binary;
+ *sip_size = rsrb.sys_routine_size;
+ *res_size = rsrb.debug_surface_size;
+
+ ret = 0;
+out:
+ return ret;
+}
+
diff --git a/src/intel/intel_debugger.h b/src/intel/intel_debugger.h
new file mode 100644
index 0000000..054c33b
--- /dev/null
+++ b/src/intel/intel_debugger.h
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2016 Intel Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Mircea Gherzan <mircea.gherzan at intel.com>
+ */
+
+/**
+ * @file intel_debugger.h
+ *
+ * This header provides the communication interface with the shader debugger
+ * and with the debugger interchange library.
+ */
+
+#ifndef INTEL_DEBUGGER_H
+#define INTEL_DEBUGGER_H
+
+/**
+ * Alignment requirement (in bytes) for the system routine.
+ */
+#define INTEL_SYS_ROUTINE_ALIGN (1 << 12)
+
+/**
+ * Size (in bytes) of the debug surface used by the system routine.
+ */
+#define INTEL_DEBUG_SURFACE_SIZE (3 * (1 << 20))
+
+/**
+ * Check if the shader debugger is alive/active.
+ * @return Non-zero if the debugger is active, zero otherwise.
+ */
+int dbg_is_active(void);
+
+/**
+ * Notify the debugger that a shader binary is about to be submitted.
+ * @param[in] kernel_name String describing the shader.
+ * @param[in] gen_binary Gen ISA binary of the shader.
+ * @param[in] gen_binary_size Size of the binary in bytes.
+ * @return Zero on success, non-zero otherwise.
+ */
+int dbg_notify_kernel_debug_data(const char *kernel_name,
+ const void *gen_binary,
+ unsigned gen_binary_size);
+
+/**
+ * Get the system routine binary from the interchange library.
+ * @param[in] gen Render core generation (7 for HSW, 8 for BDW, etc).
+ * @param[in] bti Binding Table Index (BTI) of the debug surface.
+ * @param[out] p_sip Pointer to the binary returned by the interchange.
+ * @param[out] sip_sz Size of the system routine in bytes.
+ * @param[out] res_sz Minimum size of the debug surface (for all threads).
+ * @return Zero on success, non-zero otherwise.
+ */
+int dbg_get_sys_routine_binary(unsigned gen, unsigned bti,
+ const unsigned char **p_sip,
+ unsigned *sip_sz, unsigned *res_sz);
+
+#endif // INTEL_DEBUGGER_H
--
1.8.3.1
More information about the Beignet
mailing list