Revision: 54969
          http://brlcad.svn.sourceforge.net/brlcad/?rev=54969&view=rev
Author:   brlcad
Date:     2013-03-29 15:51:34 +0000 (Fri, 29 Mar 2013)
Log Message:
-----------
stub in an implementation of thread affinity for mac os x, to the extent that 
mac supports the notion.  they don't really do affinity, but will let you 
group/ungroup threads to help/discourage cache sharing.  here we put every 
thread into their own group so the default affinity scheduling should help 
minimize cpu movement.

Modified Paths:
--------------
    brlcad/trunk/src/libbu/affinity.c

Modified: brlcad/trunk/src/libbu/affinity.c
===================================================================
--- brlcad/trunk/src/libbu/affinity.c   2013-03-29 15:47:25 UTC (rev 54968)
+++ brlcad/trunk/src/libbu/affinity.c   2013-03-29 15:51:34 UTC (rev 54969)
@@ -40,6 +40,11 @@
 #  include <pthread_np.h>
 #endif
 
+#ifdef HAVE_MACH_THREAD_POLICY_H
+#  include <mach/thread_policy.h>
+#  include <mach/mach.h>
+#endif
+
 #include "bu.h"
 
 
@@ -48,6 +53,8 @@
 {
 #if defined(HAVE_PTHREAD_H) && defined (CPU_ZERO)
 
+    /* Linux and BSD pthread affinity */
+
     pthread_t curr_thread = pthread_self();    /* Get current thread */
     int cpulim = bu_avail_cpus();              /* Max number of CPUs available 
for the process */
     int status;                                        /* Status of thread 
setting/getting */
@@ -97,9 +104,35 @@
        return -1;
     }
 
-#endif
+    return 0;
 
+#elif defined(HAVE_MACH_THREAD_POLICY_H)
+
+    /* Mac OS X mach thread affinity hinting */
+
+    thread_extended_policy_data_t epolicy;
+    thread_affinity_policy_data_t apolicy;
+    thread_t curr_thread = mach_thread_self();
+    kern_return_t ret;
+
+    epolicy.timeshare = FALSE;
+    ret = thread_policy_set(curr_thread, THREAD_EXTENDED_POLICY, 
(thread_policy_t) &epolicy, THREAD_EXTENDED_POLICY_COUNT);
+    if (ret != KERN_SUCCESS)
+       return -1;
+
+    apolicy.affinity_tag = curr_thread;
+    ret = thread_policy_set(curr_thread, THREAD_EXTENDED_POLICY, 
(thread_policy_t) &apolicy, THREAD_EXTENDED_POLICY_COUNT);
+    if (ret != KERN_SUCCESS)
+       return -1;
+
     return 0;
+
+#else
+
+    /* don't know how to set thread affinity on this platform */
+    return 0;
+
+#endif
 }
 
 

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Own the Future-Intel(R) Level Up Game Demo Contest 2013
Rise to greatness in Intel's independent game demo contest. Compete 
for recognition, cash, and the chance to get your game on Steam. 
$5K grand prize plus 10 genre and skill prizes. Submit your demo 
by 6/6/13. http://altfarm.mediaplex.com/ad/ck/12124-176961-30367-2
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to