Skip to content

Commit 10e9166

Browse files
committed
tune threading more
1 parent ad9d647 commit 10e9166

File tree

6 files changed

+255
-342
lines changed

6 files changed

+255
-342
lines changed

src/datacache/datacache.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ struct DataCacheItemData_t
4040
//-------------------------------------
4141

4242
#define DC_NO_NEXT_LOCKED ((DataCacheItem_t *)0xffffffff)
43-
#define DC_MAX_THREADS_FRAMELOCKED 4
43+
#define DC_MAX_THREADS_FRAMELOCKED 20
4444

4545
struct DataCacheItem_t : DataCacheItemData_t
4646
{

src/filesystem/filesystem_async.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,6 @@ void CBaseFileSystem::InitAsync()
668668
ThreadPoolStartParams_t params;
669669
params.iThreadPriority = TP_PRIORITY_LOW;
670670
params.bIOThreads = true;
671-
params.bHeavyLoad = true;
672671
if ( IsX360() )
673672
{
674673
// override defaults

src/materialsystem/cmaterialsystem.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3549,7 +3549,6 @@ IThreadPool *CMaterialSystem::CreateMatQueueThreadPool()
35493549
startParams.nThreads = 1;
35503550
startParams.nStackSize = 256*1024;
35513551
startParams.fDistribute = TRS_TRUE;
3552-
startParams.bHeavyLoad = true;
35533552

35543553
// The rendering thread has the GL context and the main thread is coming in and
35553554
// "helping" finish jobs - that breaks OpenGL, which requires TLS. This flag states

src/public/vstdlib/jobthread.h

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ enum JobPriority_t
102102
#define TP_MAX_POOL_THREADS 64
103103
struct ThreadPoolStartParams_t
104104
{
105-
ThreadPoolStartParams_t( bool bIOThreads = false, unsigned nThreads = -1, int *pAffinities = NULL, ThreeState_t fDistribute = TRS_NONE, unsigned nStackSize = -1, int iThreadPriority = SHRT_MIN, bool bHeavyLoad = false )
106-
: bIOThreads( bIOThreads ), nThreads( nThreads ), fDistribute( fDistribute ), nStackSize( nStackSize ), iThreadPriority( iThreadPriority ), nThreadsMax( -1 ), bHeavyLoad( bHeavyLoad )
105+
ThreadPoolStartParams_t( bool bIOThreads = false, unsigned nThreads = -1, int *pAffinities = NULL, ThreeState_t fDistribute = TRS_NONE, unsigned nStackSize = -1, int iThreadPriority = SHRT_MIN )
106+
: bIOThreads( bIOThreads ), nThreads( nThreads ), fDistribute( fDistribute ), nStackSize( nStackSize ), iThreadPriority( iThreadPriority ), nThreadsMax( -1 )
107107
{
108108
bExecOnThreadPoolThreadsOnly = false;
109109

@@ -129,7 +129,6 @@ struct ThreadPoolStartParams_t
129129
bool bIOThreads : 1;
130130
bool bUseAffinityTable : 1;
131131
bool bExecOnThreadPoolThreadsOnly : 1;
132-
bool bHeavyLoad : 1;
133132
};
134133

135134
//-----------------------------------------------------------------------------
@@ -930,7 +929,7 @@ class CParallelProcessor
930929

931930
if ( nJobs > 1 )
932931
{
933-
if ( m_iBatchSize != 1)
932+
if ( m_iBatchSize != 1 )
934933
{
935934
m_iBatchSize = nItems / nJobs;
936935
m_iLeftOver = nItems % nJobs;
@@ -940,7 +939,7 @@ class CParallelProcessor
940939
CJob **jobs = (CJob **)stackalloc( nJobs * sizeof(CJob **) );
941940
int i = nJobs;
942941

943-
while( i-- )
942+
while ( i-- )
944943
{
945944
#if 1
946945
jobs[i] = pThreadPool->QueueCall( this, &CParallelProcessor<ITEM_TYPE, ITEM_PROCESSOR_TYPE>::DoExecute );
@@ -959,7 +958,7 @@ class CParallelProcessor
959958
}
960959
else
961960
{
962-
m_iBatchSize = 1;
961+
m_iBatchSize = nItems;
963962
DoExecute();
964963
}
965964
#if MEASURE_PARALLEL_WORK
@@ -983,18 +982,26 @@ class CParallelProcessor
983982
{
984983
m_ItemProcessor.Begin();
985984

986-
int iBatchSize = m_iBatchSize;
987-
if (iBatchIndex == m_iBatchCount - 1)
988-
{
989-
iBatchSize += m_iLeftOver;
990-
}
991-
992-
for (int i = 0; i < iBatchSize; i++)
985+
while (true)
993986
{
987+
int iBatchSize = m_iBatchSize;
988+
if ( iBatchIndex == m_iBatchCount - 1 )
989+
{
990+
iBatchSize += m_iLeftOver;
991+
}
992+
993+
for ( int i = 0; i < iBatchSize; i++ )
994+
{
994995
#if MEASURE_PARALLEL_WORK
995-
++work;
996+
++work;
996997
#endif
997-
m_ItemProcessor.Process( *(m_pItems + (iBatchIndex * m_iBatchSize + i)) );
998+
m_ItemProcessor.Process( *( m_pItems + ( iBatchIndex * m_iBatchSize + i ) ) );
999+
}
1000+
iBatchIndex = m_iBatchIndex++;
1001+
if ( iBatchIndex >= m_iBatchCount )
1002+
{
1003+
break;
1004+
}
9981005
}
9991006

10001007
m_ItemProcessor.End();
@@ -1021,7 +1028,6 @@ inline void ParallelProcess( const char *pszDescription, ITEM_TYPE *pItems, unsi
10211028
CParallelProcessor<ITEM_TYPE, CFuncJobItemProcessor<ITEM_TYPE> > processor( pszDescription );
10221029
processor.m_ItemProcessor.Init( pfnProcess, pfnBegin, pfnEnd );
10231030
processor.Run( pItems, nItems, nMaxParallel );
1024-
10251031
}
10261032

10271033
template <typename ITEM_TYPE, typename OBJECT_TYPE, typename FUNCTION_CLASS >

0 commit comments

Comments
 (0)