Changeset 20836

Show
Ignore:
Timestamp:
09/19/07 21:14:50 (1 year ago)
Author:
patrick
Message:

Merges from the trunk:

r20824: Added render thread CPU affinity capabilities. The default way

that this is utilized is by setting the new environment variable
VJ_DRAW_THREAD_AFFINITY to a space-separated list of zero-based
integer CPU identifiers. User-level code can change the mechanism
(for the OpenGL Draw Manager) by calling
vrj::GlDrawManager::setCpuAffinityStrategy(). For now, only the
OpenGL Draw Manager is utilizing this new feature. The Direct3D
Draw Manager does not appear to be multi-threaded at the moment,
so it has not use for it. I did not look into usage of this with
the Performer Draw Manager.

This version differs from the trunk in the following ways:

  • It is only available when VPR is compiled to use the POSIX
    subsystem
  • It is available to the OpenGL Draw Manager so that libvrj
    does not change in way that breaks binary compatibility

This is based on an idea proposed by Todd Furlong and refined
through discussion on the vrjuggler-devel mailing list.

r20832: Added new files to the build.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • juggler/branches/2.2/modules/vrjuggler/ChangeLog

    r20812 r20836  
    11DATE        AUTHOR      CHANGE 
    22----------- ----------- ------------------------------------------------------- 
     3Sep-19-2007 patrick     Added draw thread CPU affinity capabilities through the 
     4                        new environment variable VJ_DRAW_THREAD_AFFINITY. This 
     5                        is currently used only by the OpenGL Draw Manager. 
    36Sep-09-2007 patrick     Added vrjuggler-direct3d fpc file. 
    47Sep-07-2007 dshipton    Added vrjuggler-opengl and vrjuggler-performer fpc 
  • juggler/branches/2.2/modules/vrjuggler/vrj/Draw/OGL/CpuAffinityFromEnv.cpp

    r20824 r20836  
    2525 *************** <auto-copyright.pl END do not edit this line> ***************/ 
    2626 
    27 #include <vrj/vrjConfig.h> 
     27#include <vrj/Draw/OGL/Config.h> 
    2828 
    2929#include <algorithm> 
     
    3636 
    3737#include <vrj/Util/Debug.h> 
    38 #include <vrj/Draw/CpuAffinityFromEnv.h> 
     38#include <vrj/Draw/OGL/CpuAffinityFromEnv.h> 
    3939 
    4040 
  • juggler/branches/2.2/modules/vrjuggler/vrj/Draw/OGL/CpuAffinityFromEnv.h

    r20824 r20836  
    2525 *************** <auto-copyright.pl END do not edit this line> ***************/ 
    2626 
    27 #ifndef _VRJ_DRAW_CPU_AFFINITY_FROM_ENV_H_ 
    28 #define _VRJ_DRAW_CPU_AFFINITY_FROM_ENV_H_ 
     27#ifndef _VRJ_OGL_CPU_AFFINITY_FROM_ENV_H_ 
     28#define _VRJ_OGL_CPU_AFFINITY_FROM_ENV_H_ 
    2929 
    30 #include <vrj/vrjConfig.h> 
     30#include <vrj/Draw/OGL/Config.h> 
    3131 
    3232#include <string> 
     
    4848 * of the list. 
    4949 * 
    50  * @since 2.3.14 
     50 * @since 2.2.1 
    5151 */ 
    52 class VJ_CLASS_API CpuAffinityFromEnv 
     52class VJ_OGL_CLASS_API CpuAffinityFromEnv 
    5353{ 
    5454public: 
     
    8282}; 
    8383 
    84 } // end of opengl namespace 
     84} // end of vrj namespace 
    8585 
    8686 
    87 #endif /* _VRJ_DRAW_CPU_AFFINITY_FROM_ENV_H_ */ 
     87#endif /* _VRJ_OGL_CPU_AFFINITY_FROM_ENV_H_ */ 
  • juggler/branches/2.2/modules/vrjuggler/vrj/Draw/OGL/GlDrawManager.cpp

    r20098 r20836  
    5050#include <vrj/Draw/OGL/GlWindow.h> 
    5151#include <vrj/Draw/OGL/GlSimInterfaceFactory.h> 
     52#include <vrj/Draw/OGL/CpuAffinityFromEnv.h> 
    5253 
    5354#include <gmtl/Vec.h> 
     
    7273   , mControlThread(NULL) 
    7374{ 
     75   setCpuAffinityStrategy(vrj::CpuAffinityFromEnv()); 
    7476} 
    7577 
     
    8991} 
    9092 
    91 /** Sets the app the draw should interact with. */ 
     93// Sets the app the draw should interact with. 
    9294void GlDrawManager::setApp(App* _app) 
    9395{ 
     
    317319         GlPipe* new_pipe = new GlPipe(pipes.size(), this, 
    318320                                       &mCreateWindowMutex);  // Create a new pipe to use 
     321         // The size of pipes right now tells us the newly created pipe's 
     322         // identifier. 
     323         const unsigned int pipe_id = pipes.size(); 
    319324         pipes.push_back(new_pipe);                          // Add the pipe 
    320          new_pipe->start();                                  // Start the pipe running 
     325         new_pipe->start(getDrawThreadAffinity(pipe_id));    // Start the pipe running 
    321326                                                             // NOTE: Run pipe even if no windows.  Then it waits for windows. 
    322327      } 
     
    429434   boost::ignore_unused_variable_warning(element); 
    430435   return false; 
     436} 
     437 
     438void 
     439GlDrawManager::setCpuAffinityStrategy(const cpu_affinity_strategy_t& strategy) 
     440{ 
     441   getDrawThreadAffinity = strategy; 
    431442} 
    432443 
  • juggler/branches/2.2/modules/vrjuggler/vrj/Draw/OGL/GlDrawManager.h

    r19873 r20836  
    3030#include <vrj/Draw/OGL/Config.h> 
    3131#include <vector> 
     32#include <boost/function.hpp> 
    3233 
    3334#include <vpr/vpr.h> 
     
    157158 
    158159public: 
     160   typedef boost::function<int (const unsigned int)> cpu_affinity_strategy_t; 
     161 
     162   /** 
     163    * Changes the callable object used for determining the draw thread CPU 
     164    * affinity to use the given value. In order for this to have the 
     165    * desired effect, it must be called before any render threads have been 
     166    * started. 
     167    * 
     168    * @post \c getDrawThreadAffinity is assigned the value of \p strategy. 
     169    * 
     170    * @param strategy A callable (either a C function pointer, a value 
     171    *                 returned by boost::bind(), or an object whose class 
     172    *                 overloads operator()) that serves to map zero-based 
     173    *                 thread identifiers to zero-based CPU values in order 
     174    *                 to assign affinity. 
     175    * 
     176    * @see vpr::Thead::setRunOn() 
     177    * @see addDisplay() 
     178    * 
     179    * @since 2.2.1 
     180    */ 
     181   void setCpuAffinityStrategy(const cpu_affinity_strategy_t& strategy); 
     182 
    159183   /** 
    160184    * Gets pointer to the current user data.  Should be used in the draw 
     
    236260   void operator=(const GlDrawManager&) {;} 
    237261 
     262   cpu_affinity_strategy_t getDrawThreadAffinity; 
     263 
    238264   vprSingletonHeader(GlDrawManager); 
    239265}; 
  • juggler/branches/2.2/modules/vrjuggler/vrj/Draw/OGL/GlPipe.cpp

    r20661 r20836  
    7777} 
    7878 
    79 /** 
    80  * Starts the pipe running. 
    81  * @post The pipe has it's own thread of control and is ready to operate. 
    82  */ 
    83 int GlPipe::start() 
     79// Starts the pipe running. 
     80int GlPipe::start(const int cpuAffinity) 
    8481{ 
    8582   vprASSERT(mThreadRunning == false);        // We should not be running yet 
     
    9087   try 
    9188   { 
    92       mActiveThread = new vpr::Thread(boost::bind(&GlPipe::controlLoop, this)); 
     89      // mActiveThread is assigned at the start of controlLoop(). 
     90      vpr::Thread* thread = 
     91         new vpr::Thread(boost::bind(&GlPipe::controlLoop, this, cpuAffinity)); 
    9392      vprDEBUG(vrjDBG_DRAW_MGR, vprDBG_CONFIG_LVL) 
    94          << "[vrj::GlPipe::start()] Started control loop. " << mActiveThread 
     93         << "[vrj::GlPipe::start()] Started control loop. " << thread 
    9594         << std::endl << vprDEBUG_FLUSH; 
    9695      started = 1; 
     
    190189// - Signal swap completed <br> 
    191190// 
    192 void GlPipe::controlLoop() 
    193 
     191void GlPipe::controlLoop(const int cpuAffinity) 
     192
     193   vprASSERT(NULL != vpr::Thread::self()); 
     194   mActiveThread = vpr::Thread::self(); 
     195 
     196   if ( cpuAffinity >= 0 ) 
     197   { 
     198      // On this branch, vpr::Thread::setRunOn() is only available with 
     199      // POSIX threads. 
     200#if VPR_THREAD_DOMAIN_INCLUDE == VPR_DOMAIN_POSIX 
     201      vprDEBUG(vrjDBG_DRAW_MGR, vprDBG_STATE_LVL) 
     202         << "[vrj::GlPipe::controlLoop()] Setting CPU affinity for pipe " 
     203         << mPipeNum << " to " << cpuAffinity << std::endl << vprDEBUG_FLUSH; 
     204 
     205      try 
     206      { 
     207         mActiveThread->setRunOn(cpuAffinity); 
     208      } 
     209      catch (vpr::Exception& ex) 
     210      { 
     211         vprDEBUG(vrjDBG_DRAW_MGR, vprDBG_WARNING_LVL) 
     212            << clrOutBOLD(clrYELLOW, "WARNING") 
     213            << ": Failed to set draw thread affinity in vrj::GlPipe:\n" 
     214            << ex.what() << std::endl << vprDEBUG_FLUSH; 
     215      } 
     216#else 
     217      vprDEBUG(vrjDBG_DRAW_MGR, vprDBG_WARNING_LVL) 
     218         << "Setting CPU affinity for vrj::GlPipe is not supported on this " 
     219         << "platform." << std::endl << vprDEBUG_FLUSH; 
     220#endif 
     221   } 
     222 
    194223   mThreadRunning = true;     // We are running so set flag 
    195224   // Loop until flag set 
  • juggler/branches/2.2/modules/vrjuggler/vrj/Draw/OGL/GlPipe.h

    r20661 r20836  
    7373    * 
    7474    * @pre The pipe should not have a thread of control yet. 
    75     * @post The pipe has it's own thread of control and is ready to operate 
     75    * @post The pipe has its own thread of control and is ready to operate 
    7676    *       The Thread of control is running controlLoop. 
     77    * 
     78    * @param cpuAffinity The CPU affinity to assign for the rendering thread 
     79    *                    spawned by this method. A value less than 0 
     80    *                    indicates that no CPU affinity will be assigned to 
     81    *                    the rendering thread. 
     82    * 
    7783    * @note The pipe does NOT have to have any windows in order to run 
    7884    *       that way we can add windows to pipes at run-time. 
    79     */ 
    80    int start(); 
     85    * @note The signature of this method changed in version 2.3.14 to take the 
     86    *       CPU affinity value. 
     87    */ 
     88   int start(const int cpuAffinity); 
    8189 
    8290   /** 
    8391    * The main loop routine. 
    84     * -Checks for new windows <br> 
    85     * -renders all windows when triggered <br> 
    86     */ 
    87    void controlLoop(); 
     92    *  - Checks for new windows. 
     93    *  - Renders all windows when triggered. 
     94    * 
     95    * @param cpuAffinity The CPU affinity to assign for the rendering thread 
     96    *                    spawned by this method. A value less than 0 
     97    *                    indicates that no CPU affinity will be assigned to 
     98    *                    the rendering thread. 
     99    * 
     100    * @note The signature of this method changed in version 2.3.14 to take the 
     101    *       CPU affinity value. 
     102    * 
     103    * @see vpr::Thead::setRunOn() 
     104    */ 
     105   void controlLoop(const int cpuAffinity); 
    88106 
    89107   /** 
  • juggler/branches/2.2/modules/vrjuggler/vrj/Draw/OGL/Makefile.in

    r20092 r20836  
    4242SUBOBJDIR=      $(GL_LIBRARY) 
    4343 
    44 SRCS=           GlApp.cpp                       \ 
     44SRCS=           CpuAffinityFromEnv.cpp          \ 
     45                GlApp.cpp                       \ 
    4546                GlBasicSimulator.cpp            \ 
    4647                GlDrawManager.cpp               \ 
  • juggler/branches/2.2/vc7/VRJuggler/VRJuggler.vcproj

    r20500 r20836  
    198198                        </File> 
    199199                        <File 
     200                                RelativePath="..\..\modules\vrjuggler\vrj\Draw\CpuAffinityFromEnv.cpp"> 
     201                        </File> 
     202                        <File 
    200203                                RelativePath="..\..\modules\vrjuggler\vrj\Display\Display.cpp"> 
    201204                        </File> 
     
    272275                        <File 
    273276                                RelativePath="..\..\modules\vrjuggler\vrj\Display\CameraProjection.h"> 
     277                        </File> 
     278                        <File 
     279                                RelativePath="..\..\modules\vrjuggler\vrj\Draw\CpuAffinityFromEnv.h"> 
    274280                        </File> 
    275281                        <File 
  • juggler/branches/2.2/vc8/VRJuggler/VRJuggler.vcproj

    r20548 r20836  
    565565                        </File> 
    566566                        <File 
     567                                RelativePath="..\..\modules\vrjuggler\vrj\Draw\CpuAffinityFromEnv.cpp" 
     568                                > 
     569                        </File> 
     570                        <File 
    567571                                RelativePath="..\..\modules\vrjuggler\vrj\Display\Display.cpp" 
    568572                                > 
     
    666670                        </File> 
    667671                        <File 
     672                                RelativePath="..\..\modules\vrjuggler\vrj\Draw\CpuAffinityFromEnv.h" 
     673                                > 
     674                        </File> 
     675                        <File 
    668676                                RelativePath="..\..\modules\vrjuggler\vrj\Util\Debug.h" 
    669677                                >