From b6dbb95dc94ffc990aaf65f71e69dff546c5cbe3 Mon Sep 17 00:00:00 2001 From: Tim Rowley Date: Sun, 19 Jun 2016 23:37:57 -0600 Subject: [PATCH] swr: [rasterizer] buckets cleanup Signed-off-by: Tim Rowley --- .../swr/rasterizer/common/rdtsc_buckets.cpp | 16 ++++++++- .../swr/rasterizer/common/rdtsc_buckets.h | 33 ++++++++++++++----- .../rasterizer/common/rdtsc_buckets_shared.h | 2 ++ .../drivers/swr/rasterizer/core/rdtsc_core.h | 4 +-- 4 files changed, 43 insertions(+), 12 deletions(-) diff --git a/src/gallium/drivers/swr/rasterizer/common/rdtsc_buckets.cpp b/src/gallium/drivers/swr/rasterizer/common/rdtsc_buckets.cpp index 412182f22aa..288b0719a04 100644 --- a/src/gallium/drivers/swr/rasterizer/common/rdtsc_buckets.cpp +++ b/src/gallium/drivers/swr/rasterizer/common/rdtsc_buckets.cpp @@ -40,6 +40,10 @@ THREAD UINT tlsThreadId = 0; +BucketManager::~BucketManager() +{ +} + void BucketManager::RegisterThread(const std::string& name) { // lazy evaluate threadviz knob @@ -51,7 +55,7 @@ void BucketManager::RegisterThread(const std::string& name) mThreadVizDir = str.str(); CreateDirectory(mThreadVizDir.c_str(), NULL); - mThreadViz = true; + mThreadViz = KNOB_BUCKETS_ENABLE_THREADVIZ; } BUCKET_THREAD newThread; @@ -207,12 +211,22 @@ void BucketManager::PrintReport(const std::string& filename) PrintThread(f, thread); fprintf(f, "\n"); } + mThreadMutex.unlock(); fclose(f); } } + +void BucketManager::StartCapture() +{ + + printf("Capture Starting\n"); + + mCapturing = true; +} + void BucketManager_StartBucket(BucketManager* pBucketMgr, uint32_t id) { pBucketMgr->StartBucket(id); diff --git a/src/gallium/drivers/swr/rasterizer/common/rdtsc_buckets.h b/src/gallium/drivers/swr/rasterizer/common/rdtsc_buckets.h index fe25e77832e..e50a8a546c4 100644 --- a/src/gallium/drivers/swr/rasterizer/common/rdtsc_buckets.h +++ b/src/gallium/drivers/swr/rasterizer/common/rdtsc_buckets.h @@ -36,6 +36,7 @@ #include "rdtsc_buckets_shared.h" + // unique thread id stored in thread local storage extern THREAD UINT tlsThreadId; @@ -48,6 +49,7 @@ class BucketManager { public: BucketManager() { } + ~BucketManager(); // removes all registered thread data void ClearThreads() @@ -92,11 +94,9 @@ public: // print report void PrintReport(const std::string& filename); + // start capturing - INLINE void StartCapture() - { - mCapturing = true; - } + void StartCapture(); // stop capturing INLINE void StopCapture() @@ -117,6 +117,9 @@ public: } } } + + mDoneCapturing = true; + printf("Capture Stopped\n"); } // start a bucket @@ -129,13 +132,15 @@ public: BUCKET_THREAD& bt = mThreads[tlsThreadId]; + uint64_t tsc = __rdtsc(); + // if threadviz is enabled, only need to dump start info to threads viz file if (mThreadViz) { SWR_ASSERT(bt.vizFile != nullptr); if (mBuckets[id].enableThreadViz) { - VIZ_START_DATA data{ VIZ_START, id, __rdtsc() }; + VIZ_START_DATA data{ VIZ_START, id, tsc }; Serialize(bt.vizFile, data); } } @@ -148,12 +153,13 @@ public: BUCKET &child = bt.pCurrent->children[id]; child.pParent = bt.pCurrent; child.id = id; - child.start = __rdtsc(); + child.start = tsc; // update thread's currently executing bucket bt.pCurrent = &child; } + bt.level++; } @@ -163,14 +169,19 @@ public: SWR_ASSERT(tlsThreadId < mThreads.size()); BUCKET_THREAD &bt = mThreads[tlsThreadId]; - if (bt.level == 0) return; + if (bt.level == 0) + { + return; + } + + uint64_t tsc = __rdtsc(); if (mThreadViz) { SWR_ASSERT(bt.vizFile != nullptr); if (mBuckets[id].enableThreadViz) { - VIZ_STOP_DATA data{ VIZ_STOP, __rdtsc() }; + VIZ_STOP_DATA data{ VIZ_STOP, tsc }; Serialize(bt.vizFile, data); } } @@ -179,7 +190,7 @@ public: if (bt.pCurrent->start == 0) return; SWR_ASSERT(bt.pCurrent->id == id, "Mismatched buckets detected"); - bt.pCurrent->elapsed += (__rdtsc() - bt.pCurrent->start); + bt.pCurrent->elapsed += (tsc - bt.pCurrent->start); bt.pCurrent->count++; // pop to parent @@ -224,11 +235,15 @@ private: // is capturing currently enabled volatile bool mCapturing{ false }; + // has capturing completed + volatile bool mDoneCapturing{ false }; + std::mutex mThreadMutex; // enable threadviz bool mThreadViz{ false }; std::string mThreadVizDir; + }; diff --git a/src/gallium/drivers/swr/rasterizer/common/rdtsc_buckets_shared.h b/src/gallium/drivers/swr/rasterizer/common/rdtsc_buckets_shared.h index 34c322e5a85..f6e75cda89d 100644 --- a/src/gallium/drivers/swr/rasterizer/common/rdtsc_buckets_shared.h +++ b/src/gallium/drivers/swr/rasterizer/common/rdtsc_buckets_shared.h @@ -58,6 +58,7 @@ struct BUCKET_DESC uint32_t color; }; + struct BUCKET_THREAD { // name of thread, used in reports @@ -78,6 +79,7 @@ struct BUCKET_THREAD // threadviz file object FILE* vizFile{ nullptr }; + BUCKET_THREAD() {} BUCKET_THREAD(const BUCKET_THREAD& that) { diff --git a/src/gallium/drivers/swr/rasterizer/core/rdtsc_core.h b/src/gallium/drivers/swr/rasterizer/core/rdtsc_core.h index 36f36ab1fc1..11b3eaed5f4 100644 --- a/src/gallium/drivers/swr/rasterizer/core/rdtsc_core.h +++ b/src/gallium/drivers/swr/rasterizer/core/rdtsc_core.h @@ -169,12 +169,12 @@ INLINE void rdtscEndFrame() { gCurrentFrame++; - if (gCurrentFrame == KNOB_BUCKETS_START_FRAME) + if (gCurrentFrame == KNOB_BUCKETS_START_FRAME && KNOB_BUCKETS_START_FRAME < KNOB_BUCKETS_END_FRAME) { gBucketMgr.StartCapture(); } - if (gCurrentFrame == KNOB_BUCKETS_END_FRAME) + if (gCurrentFrame == KNOB_BUCKETS_END_FRAME && KNOB_BUCKETS_START_FRAME < KNOB_BUCKETS_END_FRAME) { gBucketMgr.StopCapture(); gBucketMgr.PrintReport("rdtsc.txt"); -- 2.30.2