Permalink
Browse files

demmt: guess which buffers make sense as pushbufs

  • Loading branch information...
mslusarz committed Jul 1, 2014
1 parent cfe5c4c commit bb38cd81da0e6459fabc6f72c3e46defcad8699f
Showing with 42 additions and 10 deletions.
  1. +11 −8 rnn/demmt.c
  2. +7 −0 rnn/demmt.h
  3. +23 −2 rnn/demmt_pushbuf.c
  4. +1 −0 rnn/demmt_pushbuf.h
View
@@ -33,12 +33,6 @@
#include "rnndec.h"
#include "util.h"
-#define MMT_DEBUG 0
-
-#define mmt_debug(fmt, ...) do { if (MMT_DEBUG) fprintf(stderr, fmt, __VA_ARGS__); } while (0)
-#define mmt_log(fmt, ...) do { fprintf(stdout, "%64s" fmt, " ", __VA_ARGS__); } while (0)
-#define mmt_error(fmt, ...) do { fprintf(stderr, fmt, __VA_ARGS__); } while (0)
-
struct region
{
struct region *prev;
@@ -70,6 +64,7 @@ static int compress_clears = 1;
struct rnndomain *domain;
struct rnndb *rnndb;
int chipset;
+int guess_invalid_pushbuf = 1;
static void dump(int id)
{
@@ -149,8 +144,13 @@ static void dump_writes(int id)
if (left >= 4)
{
pushbuf_decode(&state, *(uint32_t *)(data + addr), pushbuf_desc);
+ if (guess_invalid_pushbuf && !state.pushbuf_invalid && state.size > left / 4)
+ {
+ mmt_log("command size (%d) is bigger than number of left possible commands (%d), marking this buffer invalid\n", state.size, left / 4);
+ state.pushbuf_invalid = 1;
+ }
- fprintf(stdout, "w %d:0x%04x, 0x%08x %s\n", id, addr, *(uint32_t *)(data + addr), pushbuf_desc);
+ fprintf(stdout, "w %d:0x%04x, 0x%08x %s%s\n", id, addr, *(uint32_t *)(data + addr), state.pushbuf_invalid ? "INVALID " : "", pushbuf_desc);
addr += 4;
left -= 4;
}
@@ -781,7 +781,8 @@ static void usage()
fprintf(stderr, "Usage: demmt [OPTION]\n"
"Decodes binary trace files generated by Valgrind MMT. Reads standard input.\n\n"
" -m 'chipset'\tset chipset version\n"
- " -c\t\tdo not \"compress\" obvious clears\n"
+ " -c\t\tdo not \"compress\" obvious buffer clears\n"
+ " -i\t\tdo not guess invalid pushbufs\n"
"\n");
exit(1);
}
@@ -805,6 +806,8 @@ int main(int argc, char *argv[])
}
else if (!strcmp(argv[i], "-c"))
compress_clears = 0;
+ else if (!strcmp(argv[i], "-i"))
+ guess_invalid_pushbuf = 0;
else
usage();
}
View
@@ -1,8 +1,15 @@
#ifndef DEMMT_H
#define DEMMT_H
+#define MMT_DEBUG 0
+
+#define mmt_debug(fmt, ...) do { if (MMT_DEBUG) fprintf(stderr, fmt, __VA_ARGS__); } while (0)
+#define mmt_log(fmt, ...) do { fprintf(stdout, "%64s" fmt, " ", __VA_ARGS__); } while (0)
+#define mmt_error(fmt, ...) do { fprintf(stderr, fmt, __VA_ARGS__); } while (0)
+
extern struct rnndomain *domain;
extern struct rnndb *rnndb;
extern int chipset;
+extern int guess_invalid_pushbuf;
#endif
View
@@ -213,11 +213,32 @@ void pushbuf_decode(struct pushbuf_decode_state *state, uint32_t data, char *out
}
decode_header(state, data, output);
+ if (guess_invalid_pushbuf && subchans[state->subchan] == NULL && state->addr != 0 && state->pushbuf_invalid == 0)
+ {
+ mmt_log("subchannel %d does not have bound object and first command does not bind it, marking this buffer invalid\n", state->subchan);
+ state->pushbuf_invalid = 1;
+ }
}
else
{
- if (state->addr == 0 && subchans[state->subchan] == NULL)
- subchans[state->subchan] = get_object(data);
+ if (state->addr == 0)
+ {
+ if (subchans[state->subchan] == NULL)
+ {
+ if (guess_invalid_pushbuf && state->pushbuf_invalid)
+ mmt_log("this is invalid buffer, not going to bind object 0x%08x to subchannel %d\n", data, state->subchan);
+ else
+ subchans[state->subchan] = get_object(data);
+ }
+ else
+ {
+ if (guess_invalid_pushbuf && data != subchans[state->subchan]->handle)
+ {
+ mmt_log("subchannel %d is already taken, marking this buffer invalid\n", state->subchan);
+ state->pushbuf_invalid = 1;
+ }
+ }
+ }
decode_method(state, data, output);
View
@@ -10,6 +10,7 @@ struct pushbuf_decode_state
int addr;
int size;
int skip;
+ int pushbuf_invalid;
};
void pushbuf_decode_start(struct pushbuf_decode_state *state);

0 comments on commit bb38cd8

Please sign in to comment.