From 8bb1cea463645510f7a29927b500c7e8b172402a Mon Sep 17 00:00:00 2001 From: Christoph Bumiller Date: Thu, 3 Mar 2011 12:01:36 +0100 Subject: [PATCH] nouveau: trace --- nouveau/nouveau_channel.c | 16 ++++++++++++++++ nouveau/nouveau_private.h | 3 +++ nouveau/nouveau_pushbuf.c | 29 +++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 0 deletions(-) diff --git a/nouveau/nouveau_channel.c b/nouveau/nouveau_channel.c index 96fa03b..b131035 100644 --- a/nouveau/nouveau_channel.c +++ b/nouveau/nouveau_channel.c @@ -23,9 +23,22 @@ #include #include #include +#include #include "nouveau_private.h" +static void +nvchan_trace_init(struct nouveau_channel_priv *nvchan) +{ + char path[128]; + + snprintf(path, 128, "%s/ch%i.log", getenv("HOME"), nvchan->base.id); + + nvchan->trace_file = fopen(path, "w"); + if (nvchan->trace_file && nvchan->base.device->chipset >= 0xc0) + fprintf(nvchan->trace_file, "! 10000000 10000000\n"); +} + int nouveau_channel_alloc(struct nouveau_device *dev, uint32_t fb_ctxdma, uint32_t tt_ctxdma, int pushbuf_size, @@ -100,6 +113,9 @@ nouveau_channel_alloc(struct nouveau_device *dev, uint32_t fb_ctxdma, return ret; } + if (getenv("NOUVEAU_TRACE")) + nvchan_trace_init(nvchan); + *chan = &nvchan->base; return 0; } diff --git a/nouveau/nouveau_private.h b/nouveau/nouveau_private.h index 124fe87..59735cd 100644 --- a/nouveau/nouveau_private.h +++ b/nouveau/nouveau_private.h @@ -24,6 +24,7 @@ #define __NOUVEAU_PRIVATE_H__ #include +#include #include #include @@ -76,6 +77,8 @@ struct nouveau_channel_priv { struct nouveau_bo *notifier_bo; struct nouveau_pushbuf_priv pb; + + FILE *trace_file; }; #define nouveau_channel(n) ((struct nouveau_channel_priv *)(n)) diff --git a/nouveau/nouveau_pushbuf.c b/nouveau/nouveau_pushbuf.c index 90836bc..0cd0f7a 100644 --- a/nouveau/nouveau_pushbuf.c +++ b/nouveau/nouveau_pushbuf.c @@ -30,6 +30,33 @@ #define PB_BUFMGR_DWORDS (4096 / 2) #define PB_MIN_USER_DWORDS 2048 +static void +nvchan_pushbuf_log(struct nouveau_channel_priv *nvchan) +{ + uint32_t *ptr, *end; + struct nouveau_bo *bo = nvchan->pb.buffer[nvchan->pb.current]; + int unmap = 0; + + if (!nvchan->trace_file) + return; + if (!bo->map) { + unmap = 1; + nouveau_bo_map(bo, NOUVEAU_BO_RD); + } + + ptr = (uint32_t *)bo->map + nvchan->pb.current_offset; + end = (uint32_t *)bo->map + (nvchan->base.cur - nvchan->pb.pushbuf); + + for (; ptr < end; ++ptr) + fprintf(nvchan->trace_file, "%08x\n", *ptr); + fprintf(nvchan->trace_file, "# END\n"); + + if (unmap) + nouveau_bo_unmap(bo); + + fflush(nvchan->trace_file); +} + static int nouveau_pushbuf_space(struct nouveau_channel *chan, unsigned min) { @@ -228,6 +255,8 @@ nouveau_pushbuf_flush(struct nouveau_channel *chan, unsigned min) unsigned i; int ret; + nvchan_pushbuf_log(nvchan); + ret = nouveau_pushbuf_submit(chan, NULL, 0, 0); if (ret) return ret; -- 1.7.2.2