* [PATCH igt] intel_error_decode: Factor out common decoding code
@ 2013-12-16 12:02 Damien Lespiau
2014-01-06 13:42 ` Damien Lespiau
0 siblings, 1 reply; 2+ messages in thread
From: Damien Lespiau @ 2013-12-16 12:02 UTC (permalink / raw)
To: intel-gfx
4 pieces of code were looking very similar. Let's factor out a common
function in the not so unlikely case we need to tweak that code.
Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>
---
tools/intel_error_decode.c | 52 +++++++++++++++++++---------------------------
1 file changed, 21 insertions(+), 31 deletions(-)
diff --git a/tools/intel_error_decode.c b/tools/intel_error_decode.c
index a22ec7d..529ec54 100644
--- a/tools/intel_error_decode.c
+++ b/tools/intel_error_decode.c
@@ -39,6 +39,7 @@
*/
#define _GNU_SOURCE
+#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
@@ -319,6 +320,19 @@ static void print_batch(int is_batch, const char *ring_name, uint32_t gtt_offset
}
}
+static void decode(struct drm_intel_decode *ctx, bool is_batch,
+ const char *ring_name, uint32_t gtt_offset, uint32_t *data,
+ int *count)
+{
+ if (!*count)
+ return;
+
+ print_batch(is_batch, ring_name, gtt_offset);
+ drm_intel_decode_set_batch_pointer(ctx, data, gtt_offset, *count);
+ drm_intel_decode(ctx);
+ *count = 0;
+}
+
static void
read_data_file(FILE *file)
{
@@ -350,14 +364,8 @@ read_data_file(FILE *file)
matched = sscanf(dashes, "--- gtt_offset = 0x%08x\n",
&new_gtt_offset);
if (matched == 1) {
- if (count) {
- print_batch(is_batch, ring_name, gtt_offset);
- drm_intel_decode_set_batch_pointer(decode_ctx,
- data, gtt_offset,
- count);
- drm_intel_decode(decode_ctx);
- count = 0;
- }
+ decode(decode_ctx, is_batch, ring_name,
+ gtt_offset, data, &count);
gtt_offset = new_gtt_offset;
is_batch = 1;
free(ring_name);
@@ -368,14 +376,8 @@ read_data_file(FILE *file)
matched = sscanf(dashes, "--- ringbuffer = 0x%08x\n",
&new_gtt_offset);
if (matched == 1) {
- if (count) {
- print_batch(is_batch, ring_name, gtt_offset);
- drm_intel_decode_set_batch_pointer(decode_ctx,
- data, gtt_offset,
- count);
- drm_intel_decode(decode_ctx);
- count = 0;
- }
+ decode(decode_ctx, is_batch, ring_name,
+ gtt_offset, data, &count);
gtt_offset = new_gtt_offset;
is_batch = 0;
free(ring_name);
@@ -389,14 +391,8 @@ read_data_file(FILE *file)
unsigned int reg;
/* display reg section is after the ringbuffers, don't mix them */
- if (count) {
- print_batch(is_batch, ring_name, gtt_offset);
- drm_intel_decode_set_batch_pointer(decode_ctx,
- data, gtt_offset,
- count);
- drm_intel_decode(decode_ctx);
- count = 0;
- }
+ decode(decode_ctx, is_batch, ring_name, gtt_offset,
+ data, &count);
printf("%s", line);
@@ -464,13 +460,7 @@ read_data_file(FILE *file)
data[count-1] = value;
}
- if (count) {
- print_batch(is_batch, ring_name, gtt_offset);
- drm_intel_decode_set_batch_pointer(decode_ctx,
- data, gtt_offset,
- count);
- drm_intel_decode(decode_ctx);
- }
+ decode(decode_ctx, is_batch, ring_name, gtt_offset, data, &count);
free(data);
free(line);
--
1.8.3.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH igt] intel_error_decode: Factor out common decoding code
2013-12-16 12:02 [PATCH igt] intel_error_decode: Factor out common decoding code Damien Lespiau
@ 2014-01-06 13:42 ` Damien Lespiau
0 siblings, 0 replies; 2+ messages in thread
From: Damien Lespiau @ 2014-01-06 13:42 UTC (permalink / raw)
To: intel-gfx
On Mon, Dec 16, 2013 at 12:02:53PM +0000, Damien Lespiau wrote:
> 4 pieces of code were looking very similar. Let's factor out a common
> function in the not so unlikely case we need to tweak that code.
>
> Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>
Pushed.
--
Damien
> ---
> tools/intel_error_decode.c | 52 +++++++++++++++++++---------------------------
> 1 file changed, 21 insertions(+), 31 deletions(-)
>
> diff --git a/tools/intel_error_decode.c b/tools/intel_error_decode.c
> index a22ec7d..529ec54 100644
> --- a/tools/intel_error_decode.c
> +++ b/tools/intel_error_decode.c
> @@ -39,6 +39,7 @@
> */
>
> #define _GNU_SOURCE
> +#include <stdbool.h>
> #include <stdio.h>
> #include <stdlib.h>
> #include <stdarg.h>
> @@ -319,6 +320,19 @@ static void print_batch(int is_batch, const char *ring_name, uint32_t gtt_offset
> }
> }
>
> +static void decode(struct drm_intel_decode *ctx, bool is_batch,
> + const char *ring_name, uint32_t gtt_offset, uint32_t *data,
> + int *count)
> +{
> + if (!*count)
> + return;
> +
> + print_batch(is_batch, ring_name, gtt_offset);
> + drm_intel_decode_set_batch_pointer(ctx, data, gtt_offset, *count);
> + drm_intel_decode(ctx);
> + *count = 0;
> +}
> +
> static void
> read_data_file(FILE *file)
> {
> @@ -350,14 +364,8 @@ read_data_file(FILE *file)
> matched = sscanf(dashes, "--- gtt_offset = 0x%08x\n",
> &new_gtt_offset);
> if (matched == 1) {
> - if (count) {
> - print_batch(is_batch, ring_name, gtt_offset);
> - drm_intel_decode_set_batch_pointer(decode_ctx,
> - data, gtt_offset,
> - count);
> - drm_intel_decode(decode_ctx);
> - count = 0;
> - }
> + decode(decode_ctx, is_batch, ring_name,
> + gtt_offset, data, &count);
> gtt_offset = new_gtt_offset;
> is_batch = 1;
> free(ring_name);
> @@ -368,14 +376,8 @@ read_data_file(FILE *file)
> matched = sscanf(dashes, "--- ringbuffer = 0x%08x\n",
> &new_gtt_offset);
> if (matched == 1) {
> - if (count) {
> - print_batch(is_batch, ring_name, gtt_offset);
> - drm_intel_decode_set_batch_pointer(decode_ctx,
> - data, gtt_offset,
> - count);
> - drm_intel_decode(decode_ctx);
> - count = 0;
> - }
> + decode(decode_ctx, is_batch, ring_name,
> + gtt_offset, data, &count);
> gtt_offset = new_gtt_offset;
> is_batch = 0;
> free(ring_name);
> @@ -389,14 +391,8 @@ read_data_file(FILE *file)
> unsigned int reg;
>
> /* display reg section is after the ringbuffers, don't mix them */
> - if (count) {
> - print_batch(is_batch, ring_name, gtt_offset);
> - drm_intel_decode_set_batch_pointer(decode_ctx,
> - data, gtt_offset,
> - count);
> - drm_intel_decode(decode_ctx);
> - count = 0;
> - }
> + decode(decode_ctx, is_batch, ring_name, gtt_offset,
> + data, &count);
>
> printf("%s", line);
>
> @@ -464,13 +460,7 @@ read_data_file(FILE *file)
> data[count-1] = value;
> }
>
> - if (count) {
> - print_batch(is_batch, ring_name, gtt_offset);
> - drm_intel_decode_set_batch_pointer(decode_ctx,
> - data, gtt_offset,
> - count);
> - drm_intel_decode(decode_ctx);
> - }
> + decode(decode_ctx, is_batch, ring_name, gtt_offset, data, &count);
>
> free(data);
> free(line);
> --
> 1.8.3.1
>
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/intel-gfx
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-01-06 13:42 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-12-16 12:02 [PATCH igt] intel_error_decode: Factor out common decoding code Damien Lespiau
2014-01-06 13:42 ` Damien Lespiau
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.