gallium/swr: spin-lock performance improvement
authorTomasz Pyra <tomasz.pyra@intel.com>
Tue, 10 Mar 2020 12:00:03 +0000 (13:00 +0100)
committerMarge Bot <eric+marge@anholt.net>
Thu, 19 Mar 2020 11:11:26 +0000 (11:11 +0000)
Currently, the worker threads are very aggresively
polling for new tasks. If the work is not constantly
fed into the pipeline (which is a case for most of
interactive applications), this creates unnecessary
memory pressure and is using CPU cycles that
could otherwise be used by the applications.
The change implements simple back off mechanism
to help with this problem

Change by Tomasz Pyra (tomasz.pyra@intel.com)

Reviewed-by: Alok Hota <alok.hota@intel.com>
Reviewed-by: Jan Zielinski <jan.zielinski@intel.com>
Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4226>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4226>

src/gallium/drivers/swr/rasterizer/core/threads.cpp

index c75fb568431e720c6cdd579e423d777ebd07c510..556e02e99ef049c76106d22fa396cdb99d87516a 100644 (file)
@@ -592,17 +592,20 @@ bool WorkOnFifoBE(SWR_CONTEXT* pContext,
             pDC->pTileMgr->getTileIndices(tileID, x, y);
             if (((x ^ y) & numaMask) != numaNode)
             {
+                _mm_pause();
                 continue;
             }
 
             if (!tile->getNumQueued())
             {
+                _mm_pause();
                 continue;
             }
 
             // can only work on this draw if it's not in use by other threads
             if (lockedTiles.get(tileID))
             {
+                _mm_pause();
                 continue;
             }
 
@@ -663,6 +666,7 @@ bool WorkOnFifoBE(SWR_CONTEXT* pContext,
                 // This tile is already locked. So let's add it to our locked tiles set. This way we
                 // don't try locking this one again.
                 lockedTiles.set(tileID);
+                _mm_pause();
             }
         }
     }
@@ -750,7 +754,7 @@ void WorkOnFifoFE(SWR_CONTEXT* pContext, uint32_t workerId, uint32_t& curDrawFE)
         uint32_t      dcSlot = curDraw % pContext->MAX_DRAWS_IN_FLIGHT;
         DRAW_CONTEXT* pDC    = &pContext->dcRing[dcSlot];
 
-        if (!pDC->isCompute && !pDC->FeLock)
+        if (!pDC->FeLock && !pDC->isCompute)
         {
             if (CheckDependencyFE(pContext, pDC, lastRetiredFE))
             {
@@ -765,7 +769,16 @@ void WorkOnFifoFE(SWR_CONTEXT* pContext, uint32_t workerId, uint32_t& curDrawFE)
 
                 CompleteDrawFE(pContext, workerId, pDC);
             }
+            else
+            {
+                _mm_pause();
+            }
+        }
+        else
+        {
+            _mm_pause();
         }
+
         curDraw++;
     }
 }