From 77c5e96ccbfc05beb3c02df6099cebd5d56fd09c Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 27 Sep 2016 17:52:41 +0100 Subject: [PATCH] Added DatabasePager::setProcessorAffinity(const OpenThreads::Affinity&) support to allow the database threads to have affinity to user controls sets of CPU cores. --- include/osgDB/DatabasePager | 6 ++++++ src/osgDB/DatabasePager.cpp | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/include/osgDB/DatabasePager b/include/osgDB/DatabasePager index b6ebfd86e..14388b503 100644 --- a/include/osgDB/DatabasePager +++ b/include/osgDB/DatabasePager @@ -126,6 +126,10 @@ class OSGDB_EXPORT DatabasePager : public osg::NodeVisitor::DatabaseRequestHandl }; + virtual void setProcessorAffinty(const OpenThreads::Affinity& affinity); + OpenThreads::Affinity& getProcessorAffinty() { return _affinity; } + const OpenThreads::Affinity& getProcessorAffinty() const { return _affinity; } + void setUpThreads(unsigned int totalNumThreads=2, unsigned int numHttpThreads=1); virtual unsigned int addDatabaseThread(DatabaseThread::Mode mode, const std::string& name); @@ -438,6 +442,8 @@ class OSGDB_EXPORT DatabasePager : public osg::NodeVisitor::DatabaseRequestHandl void addLoadedDataToSceneGraph(const osg::FrameStamp &frameStamp); + OpenThreads::Affinity _affinity; + bool _done; bool _acceptNewRequests; bool _databasePagerThreadPaused; diff --git a/src/osgDB/DatabasePager.cpp b/src/osgDB/DatabasePager.cpp index 28a2aff06..44ee17cd5 100644 --- a/src/osgDB/DatabasePager.cpp +++ b/src/osgDB/DatabasePager.cpp @@ -1107,6 +1107,9 @@ DatabasePager::DatabasePager() _dataToCompileList = new RequestQueue(this); _dataToMergeList = new RequestQueue(this); + // test of setting the database threads affinity. + // _affinity = OpenThreads::Affinity(4,4); + setUpThreads( osg::DisplaySettings::instance()->getNumOfDatabaseThreadsHint(), osg::DisplaySettings::instance()->getNumOfHttpDatabaseThreadsHint()); @@ -1187,6 +1190,8 @@ DatabasePager::DatabasePager(const DatabasePager& rhs) _databaseThreads.push_back(new DatabaseThread(**dt_itr,this)); } + setProcessorAffinty(rhs.getProcessorAffinty()); + _activePagedLODList = rhs._activePagedLODList->clone(); #if 1 @@ -1244,6 +1249,18 @@ DatabasePager* DatabasePager::create() new DatabasePager; } +void DatabasePager::setProcessorAffinty(const OpenThreads::Affinity& affinity) +{ + _affinity = affinity; + + for(DatabaseThreadList::iterator itr=_databaseThreads.begin(); + itr != _databaseThreads.end(); + ++itr) + { + (*itr)->setProcessorAffinity(_affinity); + } +} + void DatabasePager::setUpThreads(unsigned int totalNumThreads, unsigned int numHttpThreads) { _databaseThreads.clear(); @@ -1280,6 +1297,9 @@ unsigned int DatabasePager::addDatabaseThread(DatabaseThread::Mode mode, const s unsigned int pos = _databaseThreads.size(); DatabaseThread* thread = new DatabaseThread(this, mode,name); + + thread->setProcessorAffinity(_affinity); + _databaseThreads.push_back(thread); if (_startThreadCalled)