fs shader debugging
cover fs shader debugging
Version 2 of the patch series is pretty much the same as version 1. 2 of the patches have already been picked up by the kernel and mesa so they are gone.
The only major change is in mesa where I no longer load a binary blob from an environment variable, but instead compile the bytes directly in to Mesa.
Ben
Mesa:
src/mesa/drivers/dri/i965/Makefile | 1 + src/mesa/drivers/dri/i965/brw_context.h | 6 + src/mesa/drivers/dri/i965/brw_eu.c | 6 + src/mesa/drivers/dri/i965/brw_eu.h | 1 + src/mesa/drivers/dri/i965/brw_fs_emit.cpp | 15 +- src/mesa/drivers/dri/i965/brw_misc_state.c | 13 +- src/mesa/drivers/dri/i965/brw_state.h | 6 +- src/mesa/drivers/dri/i965/brw_state_cache.c | 49 +- src/mesa/drivers/dri/i965/brw_state_upload.c | 18 +- src/mesa/drivers/dri/i965/brw_wm.c | 27 +- src/mesa/drivers/dri/i965/brw_wm.h | 2 + src/mesa/drivers/dri/i965/brw_wm_debug.c | 108 + src/mesa/drivers/dri/i965/brw_wm_emit.c | 2 + src/mesa/drivers/dri/i965/gen6_wm_sr.c | 31 + src/mesa/drivers/dri/i965/gen_wm_sr.g4a |32826 ++++++++++++++++++++++++++ 15 files changed, 33088 insertions(+), 23 deletions(-)
libdrm:
intel/Makefile.am | 3 ++- intel/intel_debug.h | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletions(-)
intel-gpu-tools:
configure.ac | 1 + debugger/Makefile.am | 12 + debugger/debug_rdata.c | 141 +++++++ debugger/eudb.c | 590 ++++++++++++++++++++++++++++++ debugger/system_routine/Makefile | 84 +++++ debugger/system_routine/eviction_macro.c | 48 +++ debugger/system_routine/pre_cpp.py | 123 +++++++ debugger/system_routine/sr.g4a | 277 ++++++++++++++ debugger/system_routine/test.g4a | 64 ++++ lib/Makefile.am | 1 + lib/debug.h | 92 +++++ lib/intel_chipset.h | 8 + lib/intel_gpu_tools.h | 27 ++ lib/intel_mmio.c | 178 +++++++++ lib/intel_reg.h | 5 + lib/intel_reg_map.c | 174 +++++++++ tools/Makefile.am | 1 + tools/forcewaked.c | 45 +++ 18 files changed, 1871 insertions(+), 0 deletions(-)
PATCH 1/10 intel: shared header for shader debugging
--- intel/Makefile.am | 3 ++- intel/intel_debug.h | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletions(-)
intel/Makefile.am +2 -1
@@ -45,6 +45,7 @@ libdrm_intel_la_SOURCES = \ mm.h libdrm_intelincludedir = ${includedir}/libdrm -libdrm_intelinclude_HEADERS = intel_bufmgr.h +libdrm_intelinclude_HEADERS = intel_bufmgr.h \ + intel_debug.h pkgconfig_DATA = libdrm_intel.pc
intel/intel_debug.h new file +44 -0
44 lines not on this page · raw message
Signature · 6 lines
1.7.6 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 01/10] intel: shared header for shader debugging
Quoted 58 lines · Ben Widawsky
Signed-off-by Ben Widawsky <[email protected]>--- intel/Makefile.am | 3 ++- intel/intel_debug.h | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletions(-)intel/Makefile.am +2
-1@@ -45,6 +45,7 @@ libdrm_intel_la_SOURCES = \ mm.h libdrm_intelincludedir = ${includedir}/libdrm -libdrm_intelinclude_HEADERS = intel_bufmgr.h +libdrm_intelinclude_HEADERS = intel_bufmgr.h \ + intel_debug.h pkgconfig_DATA = libdrm_intel.pcintel/intel_debug.h new file +32
-0@@ -0,0 +1,44 @@ +/* +* Copyright © 2011 Intel Corporation +* +* 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 (including the next +* paragraph) 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 AUTHORS OR COPYRIGHT HOLDERS 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: +* Ben Widawsky <[email protected]> +* +*/ + +#ifndef INTEL_DEBUG_H +#define INTEL_DEBUG_H + +#include <stdint.h> +
intel/intel_debug.h line 42
Quoted 10 lines
intel/intel_debug.h new file +10
-0+#define SHADER_DEBUG_SOCKET "/tmp/gen_debug" +#define DEBUG_HANDSHAKE_VERSION 0x2 +#define DEBUG_HANDSHAKE_ACK "okay" + +/* First byte must always be the 1 byte version */ +struct debug_handshake { +uint8_t version; +int flink_handle; +uint32_t per_thread_scratch; +} __attribute__((packed));
Let's use an intel_ namespace to avoid any potential confusion. Do you want to reserve the first uint32_t for your protocol header? Then it at least looks like the hole will be useful in future...
I'm not overly thrilled by intel_debug.h, it's so generic but I can't think of anything better.
-Chris
Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [Intel-gfx] [PATCH 01/10] intel: shared header for shader debugging
In reply to Ben WidawskyQuoted 1 line · Ben Widawsky
+#define
SHADER_DEBUG_SOCKET"/tmp/gen_debug"
Not sure what this is used for, but does it really need to be in /tmp?
Cheers,
Julien
Re: [PATCH 01/10] intel: shared header for shader debugging
Quoted 5 lines · Julien Cristau
Quoted 1 line · Ben Widawsky
+#define
SHADER_DEBUG_SOCKET"/tmp/gen_debug"Not sure what this is used for, but does it really need to be in /tmp?
It is the shared socket between a debug client (ie. Mesa) and the debugger. I don't care where it goes, do you have any recommendations?
Quoted 3 lines
Cheers,
Julien
Thanks.
Ben
Re: [Intel-gfx] [PATCH 01/10] intel: shared header for shader debugging
Quoted 10 lines · Ben Widawsky
Quoted 5 lines · Julien Cristau
Quoted 1 line · Ben Widawsky
+#define
SHADER_DEBUG_SOCKET"/tmp/gen_debug"Not sure what this is used for, but does it really need to be in /tmp?
It is the shared socket between a debug client (ie. Mesa) and the debugger. I don't care where it goes, do you have any recommendations?
Somewhere under $HOME is probably better than a predictable file name in /tmp.
Cheers,
Julien
Re: [Intel-gfx] [PATCH 01/10] intel: shared header for shader debugging
Quoted 7 lines · Julien Cristau
Quoted 5 lines · Ben Widawsky
Quoted 4 lines · Julien Cristau
Quoted 1 line · Ben Widawsky
+#define
SHADER_DEBUG_SOCKET"/tmp/gen_debug"
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Not sure what this is used for, but does it really need to be in /tmp?
It is the shared socket between a debug client (ie. Mesa) and the debugger. I don't care where it goes, do you have any recommendations?
Somewhere under $HOME is probably better than a predictable file name in /tmp.
$HOME is not great because it requires a little hackery to accomplish. The debugger will be running as root, and so if we put it in root's $HOME, mesa may not be able to reach it.
Quoted 3 lines
Cheers,
Julien
Ben
Re: [Intel-gfx] [PATCH 01/10] intel: shared header for shader debugging
Quoted 13 lines · Ben Widawsky
Quoted 12 lines · Julien Cristau
Quoted 10 lines · Ben Widawsky
Quoted 5 lines · Julien Cristau
Quoted 1 line · Ben Widawsky
+#define
SHADER_DEBUG_SOCKET"/tmp/gen_debug"Not sure what this is used for, but does it really need to be in /tmp?
It is the shared socket between a debug client (ie. Mesa) and the debugger. I don't care where it goes, do you have any recommendations?
Quoted 7 lines
Quoted 2 lines
Somewhere under $HOME is probably better than a predictable file name in /tmp.
$HOME is not great because it requires a little hackery to accomplish. The debugger will be running as root, and so if we put it in root's $HOME, mesa may not be able to reach it.
Ah, I didn't realise this would run as root. Would /run (or /var/run) be ok then? Alternately, use an abstract domain socket to not have to care about the underlying filesystem.
Cheers,
Julien
Re: [Intel-gfx] [PATCH 01/10] intel: shared header for shader debugging
Quoted 3 lines
Ah, I didn't realise this would run as root. Would /run (or
/var/run) be ok then? Alternately, use an abstract domain socket to not have to care about the underlying filesystem.
Abstract sockets are a bit of a Linux specific feature. You also don't want sockets in /home as it may well be NFS mounted on some configurations and AF_UNIX sockets don't mix with NFS.
/var/run would probably be a lot more sensible for a system debug interface I agree.
Alan
Re: [Intel-gfx] [PATCH 01/10] intel: shared header for shader debugging
In reply to Julien CristauQuoted 18 lines · Julien Cristau
Quoted 16 lines · Ben Widawsky
Quoted 14 lines · Julien Cristau
Quoted 10 lines · Ben Widawsky
Quoted 5 lines · Julien Cristau
Quoted 1 line · Ben Widawsky
+#define
SHADER_DEBUG_SOCKET"/tmp/gen_debug"Not sure what this is used for, but does it really need to be in /tmp?
It is the shared socket between a debug client (ie. Mesa) and the debugger. I don't care where it goes, do you have any recommendations?
Somewhere under $HOME is probably better than a predictable file name in /tmp.
Quoted 7 lines
Quoted 4 lines
$HOME is not great because it requires a little hackery to accomplish. The debugger will be running as root, and so if we put it in root's $HOME, mesa may not be able to reach it.
Ah, I didn't realise this would run as root. Would /run (or
/var/run) be ok then? Alternately, use an abstract domain socket to not have to care about the underlying filesystem.
I wasn't even aware of abstract domain sockets. Seems like fun, let me try that one first.
Ben
PATCH 2/10 i965: copy in system routine, reserve extra scratch
In reply to Ben WidawskyThe debugger shared memory needs to be a fixed size. Since this is scratch memory that is already used by register spilling, add appropriate hooks to do the right thing when debugging.
v2: Include the bytes for a known good system routine and upload it into the instruction state cache
--- src/mesa/drivers/dri/i965/Makefile | 1 + src/mesa/drivers/dri/i965/brw_context.h | 6 + src/mesa/drivers/dri/i965/brw_state.h | 6 +- src/mesa/drivers/dri/i965/brw_state_cache.c | 49 +- src/mesa/drivers/dri/i965/brw_state_upload.c | 18 +- src/mesa/drivers/dri/i965/brw_wm.c | 24 +- src/mesa/drivers/dri/i965/brw_wm.h | 2 + src/mesa/drivers/dri/i965/brw_wm_debug.c | 29 + src/mesa/drivers/dri/i965/gen6_wm_sr.c | 31 + src/mesa/drivers/dri/i965/gen_wm_sr.g4a |32826 ++++++++++++++++++++++++++ 10 files changed, 32975 insertions(+), 17 deletions(-)
src/mesa/drivers/dri/i965/Makefile +1 -0
@@ -98,6 +98,7 @@ DRIVER_SOURCES = \ gen6_urb.c \ gen6_viewport_state.c \ gen6_vs_state.c \ + gen6_wm_sr.c \ gen6_wm_state.c \ gen7_cc_state.c \ gen7_clip_state.c \
src/mesa/drivers/dri/i965/brw_context.h +6 -0
@@ -407,10 +407,12 @@ struct brw_cache {struct brw_context *brw;struct brw_cache_item **items; +struct brw_cache_item *debugger;drm_intel_bo *bo;GLuint size, n_items;uint32_t next_offset; +uint32_t persistent_size;bool bo_used_by_gpu; };
@@ -747,6 +749,10 @@ struct brw_context* Pre-gen6, push constants live in the CURBE. */ uint32_t push_const_offset; + +/** Debug the wm shaders with the system routine */ +bool debugging; +uint32_t sip_offset; } wm;
src/mesa/drivers/dri/i965/brw_state.h +4 -2
@@ -145,6 +145,9 @@ void brw_clear_validated_bos(struct brw_context *brw);* brw_state_cache.c */ +void brw_upload_debugger_cache (struct brw_context *brw, +void *sytem_routine, +uint32_t length); void brw_upload_cache(struct brw_cache *cache, enum brw_cache_id cache_id, const void *key,
@@ -161,8 +164,7 @@ bool brw_search_cache(struct brw_cache *cache,GLuint key_size, uint32_t *inout_offset, void *out_aux);void brw_state_cache_check_size (struct brw_context *brw ); - -void brw_init_caches (struct brw_context *brw ); +void brw_init_caches (struct brw_context *brw,uint32_t size );void brw_destroy_caches (struct brw_context *brw );/***********************************************************************
src/mesa/drivers/dri/i965/brw_state_cache.c +46 -3
81 lines not on this page · raw message
src/mesa/drivers/dri/i965/brw_state_upload.c +16 -2
@@ -33,9 +33,13 @@#include "brw_context.h" #include "brw_state.h" +#include "brw_wm.h" #include "intel_batchbuffer.h" #include "intel_buffers.h" +extern char *const gen_wm_debugger; +extern const int gen_wm_debugger_size; +/* This is used to initialize brw->state.atoms[]. We could use this * list directly except for a single atom, brw_constant_buffer, which * has a .dirty value which changes according to the parameters of the
@@ -239,8 +243,18 @@ void brw_init_state( struct brw_context *brw ) {const struct brw_tracked_state **atoms;int num_atoms; - -brw_init_caches (brw); +uint32_t rsvd_cache_space =0 ; +char *const shader_debug =getenv ("INTEL_SHADER_DEBUG" ); + +if (shader_debug) { +if (!strncmp ("wm" , shader_debug,2 )) { +brw_init_caches ( brw,4096 + gen_wm_debugger_size ); +brw_upload_debugger_cache ( brw, gen_wm_debugger, gen_wm_debugger_size ); +brw_wm_init_debug (brw); + } + }else { +brw_init_caches ( brw,4096 ); + }if (brw->intel.gen >=7 ) { atoms = gen7_atoms;
src/mesa/drivers/dri/i965/brw_wm.c +14 -10
@@ -194,6 +194,7 @@ bool do_wm_prog(struct brw_context *brw,struct brw_wm_compile *c;const GLuint *program;GLuint program_size; +uint32_t total_scratch =0 ; c = brw->wm.compile_data;if (c ==NULL ) {
@@ -239,18 +240,17 @@ bool do_wm_prog(struct brw_context *brw, c->prog_data.dispatch_width =16 ; } -/* Scratch space is used for register spilling */ -if (c->last_scratch) { -uint32_t total_scratch; - +/* Scratch space is used for register spilling and debugger shared memory. +* Since the debugger must know the size in advance, we try for a fixed size, +* and hope it's large enough +*/ +if (c->last_scratch && !brw->wm.debugging) {/* Per-thread scratch space is power-of-two sized. */ for (c->prog_data.total_scratch =1024 ; c->prog_data.total_scratch <= c->last_scratch; c->prog_data.total_scratch *=2 ) {/* empty */ } - total_scratch = c->prog_data.total_scratch * brw->wm_max_threads; -if (brw->wm.scratch_bo && total_scratch > brw->wm.scratch_bo->size) {drm_intel_bo_unreference (brw->wm.scratch_bo); brw->wm.scratch_bo =NULL ;
@@ -261,8 +261,12 @@ bool do_wm_prog(struct brw_context *brw, total_scratch, 4096); } - } -else { + }else if (brw->wm.debugging) { +uint32_t thread_scratch = brw->wm.scratch_bo->size / brw->wm_max_threads; +assert (brw->wm.scratch_bo); +assert (thread_scratch /2 >= c->last_scratch); + c->prog_data.total_scratch = thread_scratch; + }else { c->prog_data.total_scratch =0 ; }
@@ -284,8 +288,8 @@ bool do_wm_prog(struct brw_context *brw, -static void brw_wm_populate_key (struct brw_context *brw, -struct brw_wm_prog_key *key ) +void brw_wm_populate_key (struct brw_context *brw, +struct brw_wm_prog_key *key ) {struct gl_context *ctx = &brw->intel.ctx;/* BRW_NEW_FRAGMENT_PROGRAM */
src/mesa/drivers/dri/i965/brw_wm.h +2 -0
@@ -321,6 +321,8 @@ void brw_wm_print_insn( struct brw_wm_compile *c,void brw_wm_print_program (struct brw_wm_compile *c,const char *stage ); +void brw_wm_init_debug (struct brw_context *brw ); +void brw_wm_lookup_iz (struct intel_context *intel,struct brw_wm_compile *c);
src/mesa/drivers/dri/i965/brw_wm_debug.c +29 -0
@@ -31,8 +31,10 @@#include "brw_context.h" +#include "brw_state.h" #include "brw_wm.h" +extern char gen_wm_debugger[];void brw_wm_print_value (struct brw_wm_compile *c,struct brw_wm_value *value )
@@ -172,3 +174,30 @@ void brw_wm_print_program( struct brw_wm_compile *c,printf ("\n" ); } +#define SCRATCH_SIZE (512 * 1024) +void brw_wm_init_debug (struct brw_context *brw ) +{ +struct intel_context *intel = &brw->intel; +uint32_t name; +int ret; + +/* In the debug case, we allocate the buffer now because we'll need to attach +* with the debugger at a later time when flink will not work (the ring / +* struct_mutex are likely to be frozen). If we make the buffer visible early +* enough, the debugger can map it before the first breakpoint. +*/ + brw->wm.scratch_bo =drm_intel_bo_alloc (intel->bufmgr, +"wm scratch" , +SCRATCH_SIZE * brw->wm_max_threads, +4096 ); +assert (brw->wm.scratch_bo); + +drm_intel_bo_map (brw->wm.scratch_bo,0 ); +memset (brw->wm.scratch_bo->virtual,0xa5 ,SCRATCH_SIZE * brw->wm_max_threads); +drm_intel_bo_unmap (brw->wm.scratch_bo); + + ret =drm_intel_bo_flink (brw->wm.scratch_bo, &name); +assert (ret ==0 ); + + brw->wm.debugging = true; +}
src/mesa/drivers/dri/i965/gen6_wm_sr.c new file +31 -0
@@ -0,0 +1,31 @@ +/* +* Copyright © 2011 Intel Corporation +* +* 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 (including the next +* paragraph) 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 AUTHORS OR COPYRIGHT HOLDERS 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: +* Ben Widawsky <[email protected]> +* +*/ + +#include "gen_wm_sr.g4a" + +char *gen_wm_debugger = gen_eu_bytes; +const int gen_wm_debugger_size =sizeof (gen_eu_bytes);
src/mesa/drivers/dri/i965/gen_wm_sr.g4a new file +32826 -0
2,706 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 6 lines
1.7.6 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Part of the diff is not shown here. View the raw message.
Re: [PATCH 02/10] i965: copy in system routine, reserve extra scratch
Quoted 8 lines · Ben Widawsky
The debugger shared memory needs to be a fixed size. Since this is scratch memory that is already used by register spilling, add appropriate hooks to do the right thing when debugging.
v2: Include the bytes for a known good system routine and upload it into the instruction state cache
Signed-off-by Ben Widawsky <[email protected]>
Quoted 11 lines
--- src/mesa/drivers/dri/i965/Makefile | 1 + src/mesa/drivers/dri/i965/brw_context.h | 6 + src/mesa/drivers/dri/i965/brw_state.h | 6 +- src/mesa/drivers/dri/i965/brw_state_cache.c | 49 +- src/mesa/drivers/dri/i965/brw_state_upload.c | 18 +- src/mesa/drivers/dri/i965/brw_wm.c | 24 +- src/mesa/drivers/dri/i965/brw_wm.h | 2 + src/mesa/drivers/dri/i965/brw_wm_debug.c | 29 + src/mesa/drivers/dri/i965/gen6_wm_sr.c | 31 + src/mesa/drivers/dri/i965/gen_wm_sr.g4a |32826 ++++++++++++++++++++++++++
.g4a is the extension for assembly source, not for a compiled hex dump. I'd make it a .c file -- seems like you need just a touch more processing to generate that in place in gen6_wm_sr.c.
src/mesa/drivers/dri/i965/brw_state_cache.c brw_upload_item_data(struct brw_cache *cache, · line 268
Quoted 8 lines
src/mesa/drivers/dri/i965/brw_state_cache.c +8
-0+/** +* Upload a debugger to the instruction cache. Currently only 1 debugger at a +* time is supported. The debugger will live at the beginning of the state bo. +*/ +void +brw_upload_debugger_cache (struct brw_context *brw, +void *system_routine, +uint32_t length)
s/length/size/ to be consistent with the rest of the driver.
src/mesa/drivers/dri/i965/brw_state_cache.c brw_upload_item_data(struct brw_cache *cache, · line 280
Quoted 12 lines
src/mesa/drivers/dri/i965/brw_state_cache.c +12
-0+{ +uint32_t sip_size =0 ; +struct brw_cache *cache = &brw->cache; +/* It is useful to have an offset so we can see if the SIP is != 0 */ +const uint32_t sip_offset =64 ; +struct brw_cache_item *item; + +if (cache->debugger) { + cache->persistent_size -= cache->debugger->size; + cache->debugger =NULL ; + brw->wm.sip_offset =0 ; + }
Why check here? We're only called if cache->debugger, right?
src/mesa/drivers/dri/i965/brw_state_cache.c brw_upload_item_data(struct brw_cache *cache, · line 283
Quoted 3 lines
src/mesa/drivers/dri/i965/brw_state_cache.c +3
-0+ +if (!cache->persistent_size) + sip_size += sip_offset;
We're only called once, so we know if cache->persistent_size, right?
Quoted 24 lines
src/mesa/drivers/dri/i965/brw_state_cache.c +16
-0+ sip_size += length; + + item =CALLOC_STRUCT (brw_cache_item); +if (!item) +return ; + item->size = sip_size; + item->key = system_routine; + + brw->wm.sip_offset = cache->persistent_size + sip_offset; +drm_intel_bo_subdata (cache->bo, brw->wm.sip_offset, length, system_routine); + + cache->persistent_size += sip_size; + cache->debugger = item; +brw_upload_item_data (cache, item, system_routine); +} + void brw_upload_cache(struct brw_cache *cache, enum brw_cache_id cache_id,@@ -318,7 +357,7 @@ brw_upload_cache(struct brw_cache *cache, } static void
src/mesa/drivers/dri/i965/brw_state_cache.c brw_clear_cache(struct brw_context *brw, struct brw_cache *cache) · line 404
Quoted 10 lines
src/mesa/drivers/dri/i965/brw_state_cache.c +2
-1@@ -357,8 +396,9 @@ brw_clear_cache(struct brw_context *brw, struct brw_cache *cache)/* Start putting programs into the start of the BO again, since * we'll never find the old results. +* Save space at beginning for persistent items. */ - cache->next_offset =0 ; + cache->next_offset = cache->persistent_size;/* We need to make sure that the programs get regenerated, since * any offsets leftover in brw_context will no longer be valid.
You claim to hold on to persistent_size, but we don't actually copy the data to a new BO... Oh, my. It looks like I totally broke this function, by letting later uploads stomp over old programs if the cache was cleared mid-batchbuffer. Wonder if this is one of the P1 bugs.
src/mesa/drivers/dri/i965/brw_state_cache.c brw_destroy_cache(struct brw_context *brw, struct brw_cache *cache) · line 436
Quoted 10 lines
src/mesa/drivers/dri/i965/brw_state_cache.c +3
-0@@ -388,7 +428,10 @@ brw_destroy_cache(struct brw_context *brw, struct brw_cache *cache)brw_clear_cache (brw, cache);free (cache->items); +if (cache->debugger) +free (cache->debugger); cache->items =NULL ; + cache->debugger =NULL ; cache->size =0 ; }
You don't need to check non-NULL for free().
Quoted 19 lines
src/mesa/drivers/dri/i965/brw_state_upload.c +4
-0@@ -33,9 +33,13 @@#include "brw_context.h" #include "brw_state.h" +#include "brw_wm.h" #include "intel_batchbuffer.h" #include "intel_buffers.h" +extern char *const gen_wm_debugger; +extern const int gen_wm_debugger_size; +/* This is used to initialize brw->state.atoms[]. We could use this * list directly except for a single atom, brw_constant_buffer, which * has a .dirty value which changes according to the parameters of the
src/mesa/drivers/dri/i965/brw_state_upload.c void brw_init_state( struct brw_context *brw ) · line 246
Quoted 6 lines
src/mesa/drivers/dri/i965/brw_state_upload.c +1
-2@@ -239,8 +243,18 @@ void brw_init_state( struct brw_context *brw ) {const struct brw_tracked_state **atoms;int num_atoms; - -brw_init_caches (brw); +uint32_t rsvd_cache_space =0 ;
Set-but-unused variable?
Quoted 40 lines
src/mesa/drivers/dri/i965/brw_state_upload.c +0
-0if (brw->intel.gen >=7 ) { atoms = gen7_atoms;src/mesa/drivers/dri/i965/brw_wm.c +6
-6@@ -194,6 +194,7 @@ bool do_wm_prog(struct brw_context *brw,struct brw_wm_compile *c;const GLuint *program;GLuint program_size; +uint32_t total_scratch =0 ; c = brw->wm.compile_data;if (c ==NULL ) {@@ -239,18 +240,17 @@ bool do_wm_prog(struct brw_context *brw, c->prog_data.dispatch_width =16 ; } -/* Scratch space is used for register spilling */ -if (c->last_scratch) { -uint32_t total_scratch; - +/* Scratch space is used for register spilling and debugger shared memory. +* Since the debugger must know the size in advance, we try for a fixed size, +* and hope it's large enough +*/ +if (c->last_scratch && !brw->wm.debugging) {/* Per-thread scratch space is power-of-two sized. */ for (c->prog_data.total_scratch =1024 ; c->prog_data.total_scratch <= c->last_scratch; c->prog_data.total_scratch *=2 ) {/* empty */ } - total_scratch = c->prog_data.total_scratch * brw->wm_max_threads; -if (brw->wm.scratch_bo && total_scratch > brw->wm.scratch_bo->size) {drm_intel_bo_unreference (brw->wm.scratch_bo); brw->wm.scratch_bo =NULL ;@@ -261,8 +261,12 @@ bool do_wm_prog(struct brw_context *brw, total_scratch,
src/mesa/drivers/dri/i965/brw_wm.c bool do_wm_prog(struct brw_context *brw, · line 269
Quoted 10 lines
src/mesa/drivers/dri/i965/brw_wm.c +6
-24096); } - } -else { + }else if (brw->wm.debugging) { +uint32_t thread_scratch = brw->wm.scratch_bo->size / brw->wm_max_threads; +assert (brw->wm.scratch_bo); +assert (thread_scratch /2 >= c->last_scratch); + c->prog_data.total_scratch = thread_scratch; + }else {
This looks like it breaks the !brw->wm.debugging case by not setting total_scratch to nonzero. I'm not sure why the variable got moved out if you're shadowing it in the new branch in this last hunk.
Quoted 30 lines
src/mesa/drivers/dri/i965/brw_wm_debug.c +13
-0@@ -31,8 +31,10 @@#include "brw_context.h" +#include "brw_state.h" #include "brw_wm.h" +extern char gen_wm_debugger[];void brw_wm_print_value (struct brw_wm_compile *c,struct brw_wm_value *value )@@ -172,3 +174,30 @@ void brw_wm_print_program( struct brw_wm_compile *c,printf ("\n" ); } +#define SCRATCH_SIZE (512 * 1024) +void brw_wm_init_debug (struct brw_context *brw ) +{ +struct intel_context *intel = &brw->intel; +uint32_t name; +int ret; + +/* In the debug case, we allocate the buffer now because we'll need to attach +* with the debugger at a later time when flink will not work (the ring / +* struct_mutex are likely to be frozen). If we make the buffer visible early +* enough, the debugger can map it before the first breakpoint.
src/mesa/drivers/dri/i965/brw_wm_debug.c void brw_wm_print_program( struct brw_wm_compile *c, · line 197
Quoted 10 lines
src/mesa/drivers/dri/i965/brw_wm_debug.c +10
-0+*/ + brw->wm.scratch_bo =drm_intel_bo_alloc (intel->bufmgr, +"wm scratch" , +SCRATCH_SIZE * brw->wm_max_threads, +4096 ); +assert (brw->wm.scratch_bo); + +drm_intel_bo_map (brw->wm.scratch_bo,0 ); +memset (brw->wm.scratch_bo->virtual,0xa5 ,SCRATCH_SIZE * brw->wm_max_threads); +drm_intel_bo_unmap (brw->wm.scratch_bo);
If you're mapping the buffer to write it, you should be passing true to the second argument of the map. I'd just subdata this.
src/mesa/drivers/dri/i965/brw_wm_debug.c void brw_wm_print_program( struct brw_wm_compile *c, · line 203
Quoted 5 lines
src/mesa/drivers/dri/i965/brw_wm_debug.c +5
-0+ ret =drm_intel_bo_flink (brw->wm.scratch_bo, &name); +assert (ret ==0 ); + + brw->wm.debugging = true; +}
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 3/10 i965: Reserve scratch space for debugger communication
In reply to Ben WidawskySince the debug system routine will share scratch space with threads doing register spilling, we must offset the registers to accommodate. This is more easily accomplished (and less bug prone) in Mesa.
The debugger will only work with the new fragment shader backend.
--- src/mesa/drivers/dri/i965/brw_fs_emit.cpp | 15 +++++++++++++-- src/mesa/drivers/dri/i965/brw_wm_emit.c | 2 ++ 2 files changed, 15 insertions(+), 2 deletions(-)
src/mesa/drivers/dri/i965/brw_fs_emit.cpp +13 -2
@@ -455,6 +455,17 @@ fs_visitor::generate_discard(fs_inst *inst) } } +static GLuint +brw_get_scratch_offset(struct brw_context *brw, fs_inst *inst) +{ + /* Split buffer 50-50 */ + if (brw->wm.debugging) { + return inst->offset + (brw->wm.scratch_bo->size / brw->wm_max_threads) / 2; + } else { + return inst->offset; + } +} + void fs_visitor::generate_spill(fs_inst *inst, struct brw_reg src) {
@@ -464,7 +475,7 @@ fs_visitor::generate_spill(fs_inst *inst, struct brw_reg src) retype(brw_message_reg(inst->base_mrf + 1), BRW_REGISTER_TYPE_UD), retype(src, BRW_REGISTER_TYPE_UD)); brw_oword_block_write_scratch(p, brw_message_reg(inst->base_mrf), 1, - inst->offset); + brw_get_scratch_offset(brw, inst)); } void
@@ -486,7 +497,7 @@ fs_visitor::generate_unspill(fs_inst *inst, struct brw_reg dst) brw_MOV(p, brw_null_reg(), dst); brw_oword_block_read_scratch(p, dst, brw_message_reg(inst->base_mrf), 1, - inst->offset); + brw_get_scratch_offset(brw, inst)); if (intel->gen == 4 && !intel->is_g4x) { /* gen4 errata: destination from a send can't be used as a
src/mesa/drivers/dri/i965/brw_wm_emit.c +2 -0
@@ -1560,6 +1560,8 @@ static void emit_spill( struct brw_wm_compile *c,mov (1) r0.2<1>:d 0x00000080:d { Align1 NoMask } send (16) null.0<1>:uw m1 r0.0<8;8,1>:uw 0x053003ff:ud { Align1 } */ +if (p->brw->wm.debugging) +abort ();brw_oword_block_write_scratch (p,brw_message_reg (1 ),2 , slot); }
Signature · 1 line
1.7.6
PATCH 4/10 i965: setup system routine
In reply to Ben WidawskyUpload the system routine as part of the invariant state if debugging.
Remove SIP setting if not debugging to make it more friendly for others that may be debugging shaders or media kernels.
--- src/mesa/drivers/dri/i965/brw_misc_state.c | 13 +++++++++---- 1 files changed, 9 insertions(+), 4 deletions(-)
src/mesa/drivers/dri/i965/brw_misc_state.c +9 -4
@@ -652,10 +652,15 @@ static void upload_invarient_state( struct brw_context *brw ) } } -BEGIN_BATCH (2 ); -OUT_BATCH (CMD_STATE_SIP <<16 | (2 -2 )); -OUT_BATCH (0 ); -ADVANCE_BATCH (); +/* The system routine must be set after a change to Instruction base */ +if (brw->wm.debugging) { +assert (brw->wm.sip_offset !=0 ); +/* assert instruction base == 0 */ +BEGIN_BATCH (2 ); +OUT_BATCH (CMD_STATE_SIP <<16 | (2 -2 )); +OUT_BATCH (brw->wm.sip_offset); +ADVANCE_BATCH (); + }BEGIN_BATCH (1 ); OUT_BATCH(brw->CMD_VF_STATISTICS << 16 |
Signature · 1 line
1.7.6
Re: [Mesa-dev] [PATCH 04/10] i965: setup system routine
Quoted 16 lines · Ben Widawsky
Upload the system routine as part of the invariant state if debugging.
Remove SIP setting if not debugging to make it more friendly for others that may be debugging shaders or media kernels.
Signed-off-by Ben Widawsky <[email protected]>--- src/mesa/drivers/dri/i965/brw_misc_state.c | 13 +++++++++---- 1 files changed, 9 insertions(+), 4 deletions(-)src/mesa/drivers/dri/i965/brw_misc_state.c +0
-0@@ -652,10 +652,15 @@ static void upload_invarient_state( struct brw_context *brw ) }
src/mesa/drivers/dri/i965/brw_misc_state.c static void upload_invarient_state( struct brw_context *brw ) · line 658
Quoted 10 lines
src/mesa/drivers/dri/i965/brw_misc_state.c +4
-4} -BEGIN_BATCH (2 ); -OUT_BATCH (CMD_STATE_SIP <<16 | (2 -2 )); -OUT_BATCH (0 ); -ADVANCE_BATCH (); +/* The system routine must be set after a change to Instruction base */ +if (brw->wm.debugging) { +assert (brw->wm.sip_offset !=0 ); +/* assert instruction base == 0 */
Kill or correct the misleading comment.
-Chris
Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
PATCH 5/10 i965: emit breakpoints
In reply to Ben WidawskyProvide a function to allow emitting breakpoints in the instruction oword. Use breakpoints when debugging.
--- src/mesa/drivers/dri/i965/brw_eu.c | 6 ++++++ src/mesa/drivers/dri/i965/brw_eu.h | 1 + src/mesa/drivers/dri/i965/brw_wm.c | 3 +++ 3 files changed, 10 insertions(+), 0 deletions(-)
src/mesa/drivers/dri/i965/brw_eu.c +6 -0
@@ -150,6 +150,12 @@ void brw_set_acc_write_control(struct brw_compile *p, GLuint value) p->current->header.acc_wr_control = value; } +void brw_set_breakpoint (struct brw_compile *p) +{ +if (p->brw->intel.gen >=6 ) + p->current->header.debug_control =1 ; +} +void brw_push_insn_state (struct brw_compile *p ) {assert (p->current != &p->stack[BRW_EU_MAX_INSN_STACK -1 ]);
src/mesa/drivers/dri/i965/brw_eu.h +1 -0
@@ -793,6 +793,7 @@ void brw_set_predicate_control( struct brw_compile *p, GLuint pc );void brw_set_predicate_inverse (struct brw_compile *p,bool predicate_inverse);void brw_set_conditionalmod (struct brw_compile *p,GLuint conditional );void brw_set_acc_write_control (struct brw_compile *p,GLuint value); +void brw_set_breakpoint (struct brw_compile *p );void brw_init_compile (struct brw_context *,struct brw_compile *p,void *mem_ctx);
src/mesa/drivers/dri/i965/brw_wm.c +3 -0
@@ -229,6 +229,9 @@ bool do_wm_prog(struct brw_context *brw,brw_init_compile (brw, &c->func, c); +if (brw->wm.debugging) +brw_set_breakpoint (&c->func); +if (prog && prog->FragmentProgram) {if (!brw_wm_fs_emit (brw, c, prog))return false;
Signature · 1 line
1.7.6
PATCH 6/10 i965: attach to a listening debugger
In reply to Ben WidawskyUse unix domain sockets to connect to a debugger and send the information the debugger will use to properly handle debug events.
--- src/mesa/drivers/dri/i965/brw_wm_debug.c | 85 ++++++++++++++++++++++++++++- 1 files changed, 82 insertions(+), 3 deletions(-)
src/mesa/drivers/dri/i965/brw_wm_debug.c +82 -3
@@ -175,12 +175,82 @@ void brw_wm_print_program( struct brw_wm_compile *c, }#define SCRATCH_SIZE (512 * 1024) +#ifndef NO_DEBUGGER_LISTENING +#include <unistd.h> +#include <sys/un.h> +#include <sys/socket.h> +#include "intel_debug.h" + +static int +attach_to_debugger () +{ +struct sockaddr_un addr; +int fd, ret; + + fd =socket (AF_UNIX ,SOCK_STREAM ,0 ); +if (fd ==-1 ) +return -1 ; + +memset (&addr,0 ,sizeof (addr)); + addr.sun_family =AF_UNIX ; +strncpy (addr.sun_path,SHADER_DEBUG_SOCKET ,sizeof (addr.sun_path) -1 ); + + ret =connect (fd, &addr,sizeof (addr)); +if (ret) +return ret; + +return fd; +} + +static int +start_debugger (int fd,int flink_handle) +{ +struct debug_handshake dh; +int reply, ret; + + dh.version =DEBUG_HANDSHAKE_VERSION ; + dh.flink_handle = flink_handle; + dh.per_thread_scratch =SCRATCH_SIZE ; + ret =write (fd, &dh,sizeof (dh)); +if (ret !=sizeof (dh)) { + ret =-1 ; + goto done; + } + + ret =read (fd, &reply,sizeof (reply)); +if (ret !=sizeof (reply)) { + ret =-1 ; + goto done; + } + +if (strncmp (DEBUG_HANDSHAKE_ACK , (char *)&reply,strlen (DEBUG_HANDSHAKE_ACK ))) { + ret =1 ; + goto done; + } + + ret =0 ; + +done: +close (fd); +return ret; +} +#endif +void brw_wm_init_debug (struct brw_context *brw ) {struct intel_context *intel = &brw->intel;uint32_t name; +int debugger_fd;int ret; +/* Simple system routines do not need a debugger present */ +#ifndef NO_DEBUGGER_LISTENING +if ((debugger_fd =attach_to_debugger ()) <0 ) { +fprintf (stderr,"Failed to attach to debugger\n" ); +return ; + } +#endif +/* In the debug case, we allocate the buffer now because we'll need to attach * with the debugger at a later time when flink will not work (the ring / * struct_mutex are likely to be frozen). If we make the buffer visible early
@@ -192,12 +262,21 @@ void brw_wm_init_debug( struct brw_context *brw ) 4096);assert (brw->wm.scratch_bo); + ret =drm_intel_bo_flink (brw->wm.scratch_bo, &name); +assert (ret ==0 ); + +#ifndef NO_DEBUGGER_LISTENING + ret =start_debugger (debugger_fd, name); +if (ret !=0 ) { +drm_intel_bo_unreference (brw->wm.scratch_bo); +return ; + } +#endif + +/* Put a nice pattern in the buffer to hopefully help detect errors */ drm_intel_bo_map (brw->wm.scratch_bo,0 );memset (brw->wm.scratch_bo->virtual,0xa5 ,SCRATCH_SIZE * brw->wm_max_threads);drm_intel_bo_unmap (brw->wm.scratch_bo); - ret =drm_intel_bo_flink (brw->wm.scratch_bo, &name); -assert (ret ==0 ); - brw->wm.debugging = true; }
Signature · 1 line
1.7.6
PATCH 7/10 intel-gpu-tools: register range handling for forcewake hooks
In reply to Ben WidawskyWe can deprecate the old code by using the non-safe flag in the new API. The safe flag should allow the previous behavior to continue.
The code also adds some range checking on register access. This code is gives hooks to prevent tools from doing bad things.
--- lib/Makefile.am | 1 + lib/intel_chipset.h | 8 ++ lib/intel_gpu_tools.h | 27 ++++++++ lib/intel_mmio.c | 178 +++++++++++++++++++++++++++++++++++++++++++++++++ lib/intel_reg_map.c | 174 +++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 388 insertions(+), 0 deletions(-)
lib/Makefile.am +1 -0
@@ -8,6 +8,7 @@ libintel_tools_la_SOURCES = \ intel_mmio.c \ intel_pci.c \ intel_reg.h \ + intel_reg_map.c \ instdone.c \ instdone.h \ drmtest.h
lib/intel_chipset.h +8 -0
@@ -168,3 +168,11 @@#define HAS_BLT_RING (devid) (IS_GEN6(devid) || \ IS_GEN7(devid)) + +#define IS_BROADWATER (devid) (devid == PCI_CHIP_I946_GZ || \ + devid == PCI_CHIP_I965_G_1 || \ + devid == PCI_CHIP_I965_Q || \ + devid == PCI_CHIP_I965_G) + +#define IS_CRESTLINE (devid) (devid == PCI_CHIP_I965_GM || \ + devid == PCI_CHIP_I965_GME)
lib/intel_gpu_tools.h +27 -0
@@ -37,6 +37,33 @@extern void *mmio;void intel_get_mmio (struct pci_device *pci_dev); +/* New style register access API */ +int intel_register_access_init (struct pci_device *pci_dev,int safe); +void intel_register_access_fini (void ); +uint32_t intel_register_read (uint32_t reg); +void intel_register_write (uint32_t reg,uint32_t val); + +#define INTEL_RANGE_RSVD (0<<0)/* Shouldn't be read or written */ +#define INTEL_RANGE_READ (1<<0) +#define INTEL_RANGE_WRITE (1<<1) +#define INTEL_RANGE_RW (INTEL_RANGE_READ | INTEL_RANGE_WRITE) +#define INTEL_RANGE_END (1<<31) + +struct intel_register_range { +uint32_t base; +uint32_t size; +uint32_t flags; +}; + +struct intel_register_map { +struct intel_register_range *map; +uint32_t top; +uint32_t alignment_mask; +}; +struct intel_register_map intel_get_register_map (uint32_t devid); +struct intel_register_range *intel_get_register_range (struct intel_register_map map,uint32_t offset,int mode); + +static inline uint32_t INREG (uint32_t reg) {
lib/intel_mmio.c +178 -0
199 lines not on this page · raw message
lib/intel_reg_map.c new file +174 -0
174 lines not on this page · raw message
Signature · 1 line
1.7.6
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 07/10] intel-gpu-tools: register range handling for forcewake hooks
On Wed, 13 Jul 2011 13:51:49 -0700, Ben Widawsky <[email protected]> wrote:
Non-text part: multipart/mixed
Quoted 151 lines
We can deprecate the old code by using the non-safe flag in the new API. The safe flag should allow the previous behavior to continue.
The code also adds some range checking on register access. This code is gives hooks to prevent tools from doing bad things.
Signed-off-by Ben Widawsky <[email protected]>--- lib/Makefile.am | 1 + lib/intel_chipset.h | 8 ++ lib/intel_gpu_tools.h | 27 ++++++++ lib/intel_mmio.c | 178 +++++++++++++++++++++++++++++++++++++++++++++++++ lib/intel_reg_map.c | 174 +++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 388 insertions(+), 0 deletions(-)lib/Makefile.am +1
-0@@ -8,6 +8,7 @@ libintel_tools_la_SOURCES = \ intel_mmio.c \ intel_pci.c \ intel_reg.h \ + intel_reg_map.c \ instdone.c \ instdone.h \ drmtest.hlib/intel_chipset.h +8
-0@@ -168,3 +168,11 @@#define HAS_BLT_RING (devid) (IS_GEN6(devid) || \ IS_GEN7(devid)) + +#define IS_BROADWATER (devid) (devid == PCI_CHIP_I946_GZ || \ + devid == PCI_CHIP_I965_G_1 || \ + devid == PCI_CHIP_I965_Q || \ + devid == PCI_CHIP_I965_G) + +#define IS_CRESTLINE (devid) (devid == PCI_CHIP_I965_GM || \ + devid == PCI_CHIP_I965_GME)lib/intel_gpu_tools.h +27
-0@@ -37,6 +37,33 @@extern void *mmio;void intel_get_mmio (struct pci_device *pci_dev); +/* New style register access API */ +int intel_register_access_init (struct pci_device *pci_dev,int safe); +void intel_register_access_fini (void ); +uint32_t intel_register_read (uint32_t reg); +void intel_register_write (uint32_t reg,uint32_t val); + +#define INTEL_RANGE_RSVD (0<<0)/* Shouldn't be read or written */ +#define INTEL_RANGE_READ (1<<0) +#define INTEL_RANGE_WRITE (1<<1) +#define INTEL_RANGE_RW (INTEL_RANGE_READ | INTEL_RANGE_WRITE) +#define INTEL_RANGE_END (1<<31) + +struct intel_register_range { +uint32_t base; +uint32_t size; +uint32_t flags; +}; + +struct intel_register_map { +struct intel_register_range *map; +uint32_t top; +uint32_t alignment_mask; +}; +struct intel_register_map intel_get_register_map (uint32_t devid); +struct intel_register_range *intel_get_register_range (struct intel_register_map map,uint32_t offset,int mode); + +static inline uint32_t INREG (uint32_t reg) {lib/intel_mmio.c +42
-0@@ -22,12 +22,15 @@* * Authors: * Eric Anholt <[email protected]> +* Ben Widawsky <[email protected]> * */ #include <unistd.h> #include <stdlib.h> #include <stdio.h> +#include <stdint.h> +#include <stdbool.h> #include <string.h> #include <errno.h> #include <err.h> @@ -41,6 +44,16 @@void *mmio; +static struct _mmio_data { +int inited; +bool safe; +char debugfs_path[FILENAME_MAX ]; +char debugfs_forcewake_path[FILENAME_MAX ]; +uint32_t i915_devid; +struct intel_register_map map; +int key; +} mmio_data; +void intel_map_file (char *file) {@@ -89,3 +102,168 @@ intel_get_mmio(struct pci_device *pci_dev) } } +/* +* If successful, i915_debugfs_path and i915_debugfs_forcewake_path are both +* updated with the correct path. +*/ +static int +find_debugfs_path (char *dri_base) +{ +int i; +char buf[FILENAME_MAX ]; +char name[256 ]; +char pciid[256 ]; +FILE *file; + +for (i =0 ; i <16 ; i++) { +int n; +snprintf (buf,FILENAME_MAX ,"%s/%i/name" , dri_base, i); + + file =fopen (buf,"r" ); +if (file ==NULL ) +continue ; + +/* +*if (master->unique) { +* seq_printf(m, "%s %s %s\n", +* bus_name, +* dev_name(dev->dev), master->unique); +*} else { +* seq_printf(m, "%s %s\n", +* bus_name, dev_name(dev->dev));
lib/intel_mmio.c intel_get_mmio(struct pci_device *pci_dev) · line 143
Quoted 10 lines
lib/intel_mmio.c +10
-0+*} +*/ + n =fscanf (file,"%s %s " , name, pciid); +fclose (file); + +if (n !=2 ) +continue ; + +if (strncmp ("0000:00:02.0" , pciid,strlen ("0000:00:02.0" ))) +continue ;
We'd like to maintain the option of someday handling more than one adaptor. We have the pciid, that should be enough to identify it as a supported Intel gfx chipset?
lib/intel_mmio.c intel_get_mmio(struct pci_device *pci_dev) · line 149
Quoted 5 lines
lib/intel_mmio.c +5
-0+snprintf (mmio_data.debugfs_path,FILENAME_MAX , +"%s/%i/" , dri_base, i); +snprintf (mmio_data.debugfs_forcewake_path,FILENAME_MAX , +"%s/%i/i915_forcewake_user" , dri_base, i); +
And this file won't even exist otherwise... You need a stat here to confirm that it does.
Quoted 33 lines
lib/intel_mmio.c +33
-0+return 0 ; + } + +return -1 ; +} + +/* force wake locking is stubbed out until accepted upstream */ +static int +get_forcewake_lock (void ) +{ +return open (mmio_data.debugfs_forcewake_path,0 ); +} + +static void +release_forcewake_lock (int fd) +{ +close (fd); +} + +/* +* Initialize register access library. +* +* @pci_dev: pci device we're mucking with +* @safe: use safe register access tables +*/ +int +intel_register_access_init (struct pci_device *pci_dev,int safe) +{ +int ret; + +/* after old API is deprecated, remove this */ +if (mmio ==NULL ) +intel_get_mmio (pci_dev);
lib/intel_mmio.c intel_get_mmio(struct pci_device *pci_dev) · line 192
Quoted 10 lines
lib/intel_mmio.c +10
-0+ +assert (mmio !=NULL ); + +if (mmio_data.inited) +return -1 ; + + mmio_data.safe = safe !=0 ? true : false; + +/* Find where the forcewake lock is */ + ret =find_debugfs_path ("/sys/kernel/debug/dri" );
Need to try /debug afterwards, just because that's the other convention.
Quoted 30 lines
lib/intel_mmio.c +30
-0+if (ret) { +fprintf (stderr,"Couldn't find path to dri/debugfs entry\n" ); +return ret; + } + + mmio_data.i915_devid = pci_dev->device_id; +if (mmio_data.safe) + mmio_data.map =intel_get_register_map (mmio_data.i915_devid); + + mmio_data.key =get_forcewake_lock (); + mmio_data.inited++; +return 0 ; +} + +void +intel_register_access_fini (void ) +{ +release_forcewake_lock (mmio_data.key); + mmio_data.inited--; +} + +uint32_t +intel_register_read (uint32_t reg) +{ +struct intel_register_range *range; +uint32_t ret; + +assert (mmio_data.inited); + +if (IS_GEN6 (mmio_data.i915_devid))
lib/intel_mmio.c intel_get_mmio(struct pci_device *pci_dev) · line 232
Quoted 10 lines
lib/intel_mmio.c +10
-0+assert (mmio_data.key !=-1 ); + +if (!mmio_data.safe) + goto read_out; + + range =intel_get_register_range (mmio_data.map, + reg, +INTEL_RANGE_READ ); + +if (!range) {
if (!range) {Quoted 6 lines
lib/intel_mmio.c +6
-0+struct intel_register_map +intel_get_register_map (uint32_t devid) +{ +struct intel_register_map map; + +if (IS_GEN6 (devid)) {
lib/intel_mmio.c intel_get_mmio(struct pci_device *pci_dev) · line 247
Quoted 10 lines
lib/intel_mmio.c +10
-0+ map.map = gen6_gt_register_map; + map.top =0x180000 ; + }else if (IS_BROADWATER (devid) ||IS_CRESTLINE (devid)) { + map.map = gen_bwcl_register_map; + map.top =0x80000 ; + }else if (IS_GEN4 (devid) ||IS_GEN5 (devid)) { + map.map = gen4_register_map; + map.top =0x80000 ; + }else { +abort ();
Give us some warning that this function will die horribly on gen2/3! -Chris
Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
PATCH 8/10 intel-gpu-tools/forcewaked: simple forcewake app
In reply to Ben WidawskyThis app is required for debug features which seem to (undocumented) reset themselves if/when the GT goes to sleep.
--- tools/Makefile.am | 1 + tools/forcewaked.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 0 deletions(-)
tools/Makefile.am +1 -0
@@ -12,6 +12,7 @@ bin_PROGRAMS = \ intel_reg_snapshot \ intel_reg_write \ intel_reg_read \ + forcewaked \ $(NULL) noinst_PROGRAMS = \
tools/forcewaked.c new file +45 -0
45 lines not on this page · raw message
Signature · 6 lines
1.7.6 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 08/10] intel-gpu-tools/forcewaked: simple forcewake app
Quoted 2 lines · Ben Widawsky
This app is required for debug features which seem to (undocumented) reset themselves if/when the GT goes to sleep.
Can you make this run a command and exit normally, or if given no args simply pause()?
i.e. forcewake intel_reg_read 0x2028
(Not really sure this classifies as a daemon ;-)
-Chris
Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
PATCH 9/10 debugging: add important debug regs
In reply to Ben Widawsky--- lib/intel_reg.h | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-)
lib/intel_reg.h +5 -0
@@ -3488,5 +3488,10 @@ typedef enum {#define TRANS_DP_HSYNC_ACTIVE_HIGH (1<<3)#define TRANS_DP_HSYNC_ACTIVE_LOW 0 +/* Debug */ +#define INSTPM 0x20c0 +#define INSTPM_GLOBAL_DEBUG_EN (1<<4) +#define GEN6_TD_CTL 0x7000 +#define TD_CTL_FORCE_TD_BKPT (1<<4)#endif /* _I810_REG_H */
Signature · 1 line
1.7.6
Re: [PATCH 09/10] debugging: add important debug regs
Quoted 10 lines · Ben Widawsky
Signed-off-by Ben Widawsky <[email protected]>--- lib/intel_reg.h | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-)lib/intel_reg.h +0
-0
lib/intel_reg.h typedef enum { · line 3493
Quoted 6 lines
lib/intel_reg.h +3
-0@@ -3488,5 +3488,10 @@ typedef enum {#define TRANS_DP_HSYNC_ACTIVE_HIGH (1<<3)#define TRANS_DP_HSYNC_ACTIVE_LOW 0 +/* Debug */ +#define INSTPM 0x20c0 +#define INSTPM_GLOBAL_DEBUG_EN (1<<4)
This is a fun little reg that changes meaning on every generation. Might be worth putting in GENx prefixes from the beginning.
-Chris
Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
PATCH 10/10 debugging: shader debugging
In reply to Ben Widawskyhigh level summary of the files:
* debug_rdata - get current state from debug registers. Helpful when developing the debugger, and could serve some purpose in the future.
* eudb - the debugger itself
* eviction_macro - generate the proper macro to flush the EU render cache until I get control flow working
* pre_cpp - an evaluating c preprocesser like thing, to be used before cpp
* sr - the system routine, exception handler which runs on the EU
* test - a very basic test system routine
* debug.h
--- configure.ac | 1 + debugger/Makefile.am | 12 + debugger/debug_rdata.c | 141 +++++++ debugger/eudb.c | 590 ++++++++++++++++++++++++++++++ debugger/system_routine/Makefile | 84 +++++ debugger/system_routine/eviction_macro.c | 48 +++ debugger/system_routine/pre_cpp.py | 123 +++++++ debugger/system_routine/sr.g4a | 277 ++++++++++++++ debugger/system_routine/test.g4a | 64 ++++ lib/debug.h | 92 +++++ 10 files changed, 1432 insertions(+), 0 deletions(-)
configure.ac +1 -0
@@ -98,5 +98,6 @@ AC_CONFIG_FILES([ scripts/Makefile tests/Makefile tools/Makefile + debugger/Makefile ]) AC_OUTPUT
debugger/Makefile.am new file +12 -0
@@ -0,0 +1,12 @@ +SUBDIRS=system_routine + +bin_PROGRAMS = \ + eudb \ + debug_rdata \ + $(NULL) + +LDADD = ../lib/libintel_tools.la $(DRM_LIBS) $(PCIACCESS_LIBS) + +AM_CFLAGS = $(DRM_CFLAGS) $(PCIACCESS_CFLAGS) $(WARN_CFLAGS) \ + -I$(srcdir)/.. \ + -I$(srcdir)/../lib
debugger/debug_rdata.c new file +141 -0
141 lines not on this page · raw message
debugger/eudb.c new file +590 -0
590 lines not on this page · raw message
debugger/system_routine/Makefile new file +84 -0
84 lines not on this page · raw message
debugger/system_routine/eviction_macro.c new file +48 -0
48 lines not on this page · raw message
debugger/system_routine/pre_cpp.py new file +123 -0
123 lines not on this page · raw message
debugger/system_routine/sr.g4a new file +277 -0
277 lines not on this page · raw message
debugger/system_routine/test.g4a new file +64 -0
64 lines not on this page · raw message
lib/debug.h new file +92 -0
92 lines not on this page · raw message
Signature · 6 lines
1.7.6 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 11 lines · Ben Widawsky
Version 2 of the patch series is pretty much the same as version 1. 2 of the patches have already been picked up by the kernel and mesa so they are gone.
The only major change is in mesa where I no longer load a binary blob from an environment variable, but instead compile the bytes directly in to Mesa.
Ben
I forgot to mention that I'm still working on the readme for how this all works.