Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[Manta] r2069 - in trunk: Core/Thread Engine/Control


Chronological Thread 
  • From: "Solomon Boulos" <boulos@cs.utah.edu>
  • To: manta@sci.utah.edu
  • Subject: [Manta] r2069 - in trunk: Core/Thread Engine/Control
  • Date: Thu, 14 Feb 2008 15:32:43 -0700 (MST)

Author: boulos
Date: Thu Feb 14 15:32:42 2008
New Revision: 2069

Modified:
   trunk/Core/Thread/Thread_pthreads.cc
   trunk/Engine/Control/RTRT.cc
Log:
Core/Thread/Thread_pthreads.cc

 Cleaning up the double checking SigContext typedef.

 Adding thread affinity for Leopard if migrate was called to set the
 thread affinity. Sadly, this results in pretty poor performance
 overall and is probably a question for the Apple performance mailing
 list.

Engine/Control/RTRT.cc

 To enable testing of the update graph, set the #define
 USE_UPDATE_GRAPH to 1.

 Leaving some commented out code about thread affinity. I think for
 Linux we should add some CMake code to search for NPTL and use
 pthread_setaffinity_np when appropriate.


Modified: trunk/Core/Thread/Thread_pthreads.cc
==============================================================================
--- trunk/Core/Thread/Thread_pthreads.cc        (original)
+++ trunk/Core/Thread/Thread_pthreads.cc        Thu Feb 14 15:32:42 2008
@@ -96,12 +96,10 @@
 #  include <sys/sysctl.h>
 #endif
 
-#ifdef __APPLE__
-  #ifdef APPLE_LEOPARD
-    #define SigContext ucontext_t
-  #else
-    #define SigContext struct sigcontext
-  #endif
+#ifdef APPLE_LEOPARD
+  #include <mach/mach.h>
+  #include <mach/thread_policy.h>
+  #define SigContext ucontext_t
 #else
   #define SigContext struct sigcontext
 #endif
@@ -509,6 +507,24 @@
     // Always EAGAIN
     throw ThreadError("pthread_create:  Out of thread resources.");
   }
+#ifdef APPLE_LEOPARD
+  if (cpu_ != -1) {
+    thread_affinity_policy ap;
+    // NOTE(boulos): To allow people to specify processors using
+    // 0-based indexing, we don't want them to end up with 0 meaning
+    // no affinity. OS X also can tell you how many "logical
+    // processors" share an L2 cache (which is all that the affinity
+    // scheduler priority "respects" anyway) so we might be able to
+    // just convert the cpu_ field here into an affinity tag. This
+    // would allow a linux implementation that had NPTL to use
+    // pthread_setaffinity_np directly on the actual core desired.
+    ap.affinity_tag = cpu_ + 1;
+    thread_policy_set(pthread_mach_thread_np(priv_->threadid),
+                      THREAD_AFFINITY_POLICY,
+                      (integer_t*)&ap,
+                      THREAD_AFFINITY_POLICY_COUNT);
+  }
+#endif
   unlock_scheduler();
 }
 
@@ -892,9 +908,9 @@
 
 
 void
-Thread::migrate(int /*proc*/)
+Thread::migrate(int proc)
 {
-  // Nothing for now...
+  cpu_ = proc;
 }
 
 

Modified: trunk/Engine/Control/RTRT.cc
==============================================================================
--- trunk/Engine/Control/RTRT.cc        (original)
+++ trunk/Engine/Control/RTRT.cc        Thu Feb 14 15:32:42 2008
@@ -88,6 +88,7 @@
 using namespace std;
 
 #define RENDER_THREAD_STACKSIZE 8*1024*1024
+#define USE_UPDATE_GRAPH 0
 
 
///////////////////////////////////////////////////////////////////////////////
 
///////////////////////////////////////////////////////////////////////////////
@@ -512,6 +513,16 @@
       Thread* t = workers[i] =
         new Thread(new Worker(this, i, false), name.str().c_str(),
                    0, Thread::NotActivated);
+      // NOTE(boulos): It seems that the Mac OS X scheduler is
+      // actually much worse when you try to add priority. The docs
+      // claim that you should use affinity "groups" which basically
+      // means mapping thread ids to L2 caches. The i < 4 code should
+      // test this on 4-core processor systems. However, running
+      // bin/manta -np 8 on my 8-core mac pro, only 5 threads are
+      // running at peak.
+
+      //t->migrate((i < 4) ? 0 : 1);
+      //t->migrate(i);
       t->setStackSize(RENDER_THREAD_STACKSIZE);
       t->activate(false);
     }
@@ -642,9 +653,10 @@
 
///////////////////////////////////////////////////////////////////////////////
 
///////////////////////////////////////////////////////////////////////////////
 
+#if USE_UPDATE_GRAPH
 void PrintHello() {
-
 }
+#endif
 
 void RTRT::internalRenderLoop(int proc, bool lateComerFlag)
 {
@@ -681,8 +693,10 @@
   // ensure everything is thread-safe throughout the tree.
   if (proc == 0) {
     doPreprocess(proc, 1);
-    //#warning "Adding objects to the update graph"
-    //scene->getObject()->addToUpdateGraph(update_graph, NULL);
+#if USE_UPDATE_GRAPH
+    #warning "Adding objects to the update graph"
+    scene->getObject()->addToUpdateGraph(update_graph, NULL);
+#endif
     //update_graph->print(scene->getObject());
   }
 
@@ -734,7 +748,7 @@
 
     barrier1.wait(workersRendering);
 
-#if 1
+#if !(USE_UPDATE_GRAPH)
     doSerialAnimationCallbacks(changed, proc, workersAnimAndImage);
     doParallelAnimationCallbacks(changed, proc, workersAnimAndImage);
 #else
@@ -745,14 +759,12 @@
     barrier1.wait(workersRendering);
     if (proc == 0) {
       // NOTE(boulos): Use this code to rebuild the first Object in the 
group every frame
-#if 1
 #warning "Sending update transaction for first Object in group"
       // Temporary
       Group* top_level_group = dynamic_cast<Group*>(getScene()->getObject());
       addUpdateTransaction("Test Update Graph",
                            Callback::create(PrintHello),
                            top_level_group->get(0));
-#endif
     }
 #endif
 




  • [Manta] r2069 - in trunk: Core/Thread Engine/Control, Solomon Boulos, 02/14/2008

Archive powered by MHonArc 2.6.16.

Top of page