[m-rev.] diff: Undo previous change to thread-pinning.

Paul Bone pbone at csse.unimelb.edu.au
Fri Apr 15 21:14:22 AEST 2011


Undo a previous change to thread pinning.

I enabled thread pinning by default in a previous commit except where -P is
explicitly specified.  But this left the programmer with no-way to specify
-P and have thread pinning.

This change reverts my previous change.

runtime/mercury_context.h:
runtime/mercury_context.c:
runtime/mercury_wrapper.c:
doc/user_guide.texi:
    As above.

diff --git a/doc/user_guide.texi b/doc/user_guide.texi
index 1e6c4c6..a89d68f 100644
--- a/doc/user_guide.texi
+++ b/doc/user_guide.texi
@@ -9980,14 +9980,17 @@ grade.
 @c parallel, threadscope grade.
 
 @sp 1
- at item --no-thread-pinning
- at findex --no-thread-pinning
-Prevent the runtime system from pinning Mercury engines (POSIX threads)
+ at item --thread-pinning
+ at findex --thread-pinning
+Request that the runtime system attempts to pin Mercury engines (POSIX threads)
 to CPU cores/hardware threads.
 This only has an effect if the executable was built in a parallel low-level C
 grade.
-Manually specifying -P will also disable thread pinning if it is not explicitly
-enabled.
+This is disabled by default but may be enabled by default in the future.
+ at c In case this is enabled by default the following comment is relevant.
+ at c This is disabled by default unless @samp{-P @var{num}} is not specified and the
+ at c runtime system is able to detect the number of processors enabled by the
+ at c operating system.
 
 @c @item -r @var{num}
 @c @findex -r (runtime option)
diff --git a/runtime/mercury_context.c b/runtime/mercury_context.c
index e0cc947..068ed2e 100644
--- a/runtime/mercury_context.c
+++ b/runtime/mercury_context.c
@@ -166,8 +166,7 @@ static MR_Integer       MR_profile_parallel_regular_context_kept = 0;
 */
 #ifdef MR_LL_PARALLEL_CONJ
 static MercuryLock      MR_next_cpu_lock;
-MR_bool                 MR_thread_pinning_configured = MR_TRUE;
-MR_bool                 MR_thread_pinning_in_use;
+MR_bool                 MR_thread_pinning = MR_FALSE;
 static MR_Unsigned      MR_next_cpu = 0;
 /* This is initialised the first the MR_pin_primordial_thread() is called */
 MR_Unsigned             MR_primordial_thread_cpu;
@@ -285,17 +284,23 @@ MR_init_context_stuff(void)
         if (result < 1) {
             /* We couldn't determine the number of processors. */
             MR_num_threads = 1;
-  #ifdef MR_LL_PARALLEL_CONJ
-            MR_thread_pinning_in_use = MR_FALSE;
-  #endif
         } else {
             MR_num_threads = result;
+            /*
+            ** On systems that don't support sched_setaffinity we don't try to
+            ** automatically enable thread pinning. This prevents a runtime
+            ** warning that could unnecessarily confuse the user.
+            **/
+    #if defined(MR_LL_PARALLEL_CONJ) && defined(MR_HAVE_SCHED_SETAFFINITY)
+            /*
+            ** Comment this back in to enable thread pinning by default if we
+            ** autodetected the correct number of CPUs.
+            */
+            /* MR_thread_pinning = MR_TRUE; */
+    #endif
         }
     #else /* ! defined(MR_HAVE_SYSCONF) && defined(_SC_NPROCESSORS_ONLN) */
         MR_num_threads = 1;
-  #ifdef MR_LL_PARALLEL_CONJ
-        MR_thread_pinning_in_use = MR_FALSE;
-  #endif
   #endif /* ! defined(MR_HAVE_SYSCONF) && defined(_SC_NPROCESSORS_ONLN) */
     }
   #ifdef MR_LL_PARALLEL_CONJ
@@ -344,7 +349,7 @@ MR_pin_primordial_thread(void)
     if (temp == -1) {
         MR_primordial_thread_cpu = 0;
     #ifdef MR_HAVE_SCHED_SET_AFFINITY
-        if (MR_thread_pinning_configured && MR_thread_pinning_in_use) {
+        if (MR_thread_pinning) {
             perror("Warning: unable to determine the current CPU for "
                 "the primordial thread: ");
         }
@@ -385,7 +390,7 @@ MR_pin_thread(void)
     MR_UNLOCK(&MR_next_cpu_lock, "MR_pin_thread");
 
 #ifdef MR_HAVE_SCHED_SETAFFINITY
-    if (MR_thread_pinning_configured && MR_thread_pinning_in_use) {
+    if (MR_thread_pinning) {
         MR_do_pin_thread(cpu);
     }
 #endif
@@ -409,12 +414,12 @@ MR_do_pin_thread(int cpu)
             ** If this failed once, it will probably fail again, so we
             ** disable it.
             */
-            MR_thread_pinning_in_use = MR_FALSE;
+            MR_thread_pinning = MR_FALSE;
         }
     } else {
         perror("Warning: Couldn't set CPU affinity due to a static "
             "system limit: ");
-        MR_thread_pinning_in_use = MR_FALSE;
+        MR_thread_pinning = MR_FALSE;
     }
 }
 #endif
diff --git a/runtime/mercury_context.h b/runtime/mercury_context.h
index 1832faf..f83b707 100644
--- a/runtime/mercury_context.h
+++ b/runtime/mercury_context.h
@@ -357,8 +357,7 @@ extern      MR_Context  *MR_runqueue_tail;
   extern    MercuryCond MR_runqueue_cond;
 #endif
 #ifdef  MR_LL_PARALLEL_CONJ
-  extern    MR_bool         MR_thread_pinning_configured;
-  extern    MR_bool         MR_thread_pinning_in_use;
+  extern    MR_bool         MR_thread_pinning;
 #endif
 
 #ifdef MR_PROFILE_PARALLEL_EXECUTION_SUPPORT
diff --git a/runtime/mercury_wrapper.c b/runtime/mercury_wrapper.c
index e487174..3be930c 100644
--- a/runtime/mercury_wrapper.c
+++ b/runtime/mercury_wrapper.c
@@ -1393,7 +1393,7 @@ struct MR_option MR_long_opts[] = {
     { "max-contexts-per-thread",        1, 0, MR_MAX_CONTEXTS_PER_THREAD },
     { "runtime-granularity-wsdeque-length-factor", 1, 0,
         MR_RUNTIME_GRANULAITY_WSDEQUE_LENGTH_FACTOR },
-    { "no-thread-pinning",              0, 0, MR_THREAD_PINNING },
+    { "thread-pinning",                 0, 0, MR_THREAD_PINNING },
     { "profile-parallel-execution",     0, 0, MR_PROFILE_PARALLEL_EXECUTION },
     { "mdb-tty",                        1, 0, MR_MDB_TTY },
     { "mdb-in",                         1, 0, MR_MDB_IN },
@@ -1830,7 +1830,7 @@ MR_process_options(int argc, char **argv)
 
             case MR_THREAD_PINNING:
 #if defined(MR_LL_PARALLEL_CONJ) && defined(MR_HAVE_SCHED_SETAFFINITY)
-                MR_thread_pinning_configured = MR_FALSE;
+                MR_thread_pinning = MR_TRUE;
 #endif
                 break;
 
@@ -2254,7 +2254,6 @@ MR_process_options(int argc, char **argv)
                 if (MR_num_threads < 1) {
                     MR_usage();
                 }
-                MR_thread_pinning_in_use = MR_FALSE;
 #endif
                 break;
 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 489 bytes
Desc: Digital signature
URL: <http://lists.mercurylang.org/archives/reviews/attachments/20110415/610a0cc7/attachment.sig>


More information about the reviews mailing list