swr: [rasterizer] buckets cleanup
authorTim Rowley <timothy.o.rowley@intel.com>
Mon, 20 Jun 2016 05:37:57 +0000 (23:37 -0600)
committerTim Rowley <timothy.o.rowley@intel.com>
Tue, 12 Jul 2016 16:10:44 +0000 (11:10 -0500)
Signed-off-by: Tim Rowley <timothy.o.rowley@intel.com>
src/gallium/drivers/swr/rasterizer/common/rdtsc_buckets.cpp
src/gallium/drivers/swr/rasterizer/common/rdtsc_buckets.h
src/gallium/drivers/swr/rasterizer/common/rdtsc_buckets_shared.h
src/gallium/drivers/swr/rasterizer/core/rdtsc_core.h

index 412182f22aa8dc6c03db0150b47ba998486b589a..288b0719a047ff23175de5e8330b302460a01a26 100644 (file)
 
 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);
index fe25e77832e0bc5dbf04cc7330b9d16abc7e4e8c..e50a8a546c4bed657617992dd3ee403efa9b707a 100644 (file)
@@ -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;
+
 };
 
 
index 34c322e5a85d6c74b71f4b1d4561b3d57e62800f..f6e75cda89d23eab1613b90ab8ab314ffb43076b 100644 (file)
@@ -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)
     {
index 36f36ab1fc19a2525aa1eec97ca74bc0ea5de5f6..11b3eaed5f4b801076aab002d26f82d5e1f233c0 100644 (file)
@@ -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");