From 687bfb40c1fa9175100ed82ebc60d356e5a97686 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sun, 6 Aug 2006 16:49:48 +0000 Subject: [PATCH] Added preliminary support for process affinity support under Linux. --- src/osgProducer/OsgCameraGroup.cpp | 61 ++++++++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 3 deletions(-) diff --git a/src/osgProducer/OsgCameraGroup.cpp b/src/osgProducer/OsgCameraGroup.cpp index e433a80b5..acfe3404d 100644 --- a/src/osgProducer/OsgCameraGroup.cpp +++ b/src/osgProducer/OsgCameraGroup.cpp @@ -29,9 +29,15 @@ #define WGL_SAMPLES_ARB 0x2042 #endif +#if defined (__linux__) + #include +#endif + using namespace Producer; using namespace osgProducer; +static osg::ApplicationUsageProxy OsgCameraGroup_e0(osg::ApplicationUsage::ENVIRONMENTAL_VARIABLE, "OSG_PROCESSOR_AFFINTIY ", "ON | OFF - Where supported, switch on or off the processor affinity." ); + OsgCameraGroup::RealizeCallback::~RealizeCallback() { } @@ -42,11 +48,56 @@ public: RenderSurfaceRealizeCallback(OsgCameraGroup* cameraGroup,OsgSceneHandler* sceneHandler): _cameraGroup(cameraGroup), - _sceneHandler(sceneHandler) {} + _sceneHandler(sceneHandler), + _numberOfProcessors(1), + _sceneHandlerNumber(0), + _enableProccessAffinityHint(false) + { + const char* str = getenv("OSG_PROCESSOR_AFFINTIY"); + if (str && (strcmp(str,"ON")==0 || strcmp(str,"On")==0 || strcmp(str,"on")==0)) + { + _enableProccessAffinityHint = true; + } + else + { + _enableProccessAffinityHint = false; + } + + + #if defined (__linux__) + /* Determine the actual number of processors */ + _numberOfProcessors = sysconf(_SC_NPROCESSORS_CONF); + #endif + + const OsgCameraGroup::SceneHandlerList& shl = _cameraGroup->getSceneHandlerList(); + for(unsigned int i=0; i1) + { + cpu_set_t cpumask; + CPU_ZERO( &cpumask ); + CPU_SET( _sceneHandlerNumber % _numberOfProcessors, &cpumask ); + + if( sched_setaffinity( 0, sizeof(cpumask), &cpumask ) == -1 ) + { + osg::notify(osg::NOTICE)<<"WARNING: Could not set CPU Affinity for scene handler "<<_sceneHandlerNumber<