<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">So we’re all on the same page, this is a release build with assertions disabled on Darwin x86_64.<div class=""><br class=""></div><div class="">—Owen</div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jan 27, 2015, at 11:59 AM, Owen Anderson <<a href="mailto:resistor@mac.com" class="">resistor@mac.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">To illustrate, the top of a profile.  I’m running a single .ll file through LLC, with -time-compilations 10000.  I’ve focused the profiler only on the call tree beneath llvm::legacy::PassManagerImpl::run(), and charged a few system library functions to their callers in order to make it more readable.<div class=""><br class=""></div><div class=""><span id="cid:6DB8F663-95E9-4FEA-B443-D37AF420C454@apple.com"><ThreadProfile.png></span></div><div class=""><br class=""></div><div class="">Notice that we’re spending almost 13% of our time in reader/writer locks plus memory fences.  I assume the remaining few percent of regression come from optimizations inhibited by the presence of the locks.</div><div class=""><br class=""></div><div class="">—Owen</div><div class=""><br class=""></div><div class=""><br class=""><div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Jan 27, 2015, at 11:41 AM, Sean Silva <<a href="mailto:chisophugis@gmail.com" class="">chisophugis@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><br class="Apple-interchange-newline"><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div class="gmail_quote" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">On Tue, Jan 27, 2015 at 7:13 PM, Owen Anderson<span class="Apple-converted-space"> </span><span dir="ltr" class=""><<a href="mailto:resistor@mac.com" target="_blank" class="">resistor@mac.com</a>></span><span class="Apple-converted-space"> </span>wrote:<br class=""><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;">Hi Chandler,<br class=""><br class="">I hate to revive an ancient thread, but our recent performance work has turned this up as a *massive* performance regression for compilation when the units of compilation are small.  I’m able to consistently measure slowdowns just within PassManager::run() on the order of 15-20%, with read-writer locks at the top of the profile.  Building without threading enabled is not an option, because some of our clients use LLVM in a multithreaded manner, while others do not.<br class=""></blockquote><div class=""><br class=""></div><div class="">Maybe I'm just out of the loop, but do you know what locks PassManager::run() would end up running up against? Off the top of my head I can't think of any.</div><div class=""><br class=""></div><div class="">-- Sean Silva</div><div class=""><br class=""></div><div class=""> </div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><span class="HOEnZb"><font color="#888888" class=""><br class="">—Owen<br class=""></font></span><div class="HOEnZb"><div class="h5"><br class=""><br class="">> On Jun 27, 2014, at 8:13 AM, Chandler Carruth <<a href="mailto:chandlerc@gmail.com" class="">chandlerc@gmail.com</a>> wrote:<br class="">><br class="">> Author: chandlerc<br class="">> Date: Fri Jun 27 10:13:01 2014<br class="">> New Revision: 211900<br class="">><br class="">> URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project?rev=211900&view=rev" target="_blank" class="">http://llvm.org/viewvc/llvm-project?rev=211900&view=rev</a><br class="">> Log:<br class="">> Re-apply r211287: Remove support for LLVM runtime multi-threading.<br class="">><br class="">> I'll fix the problems in libclang and other projects in ways that don't<br class="">> require <mutex> until we sort out the cygwin situation.<br class="">><br class="">> Modified:<br class="">>    llvm/trunk/docs/ProgrammersManual.rst<br class="">>    llvm/trunk/include/llvm-c/Core.h<br class="">>    llvm/trunk/include/llvm/Support/ManagedStatic.h<br class="">>    llvm/trunk/include/llvm/Support/Threading.h<br class="">>    llvm/trunk/lib/IR/Core.cpp<br class="">>    llvm/trunk/lib/Support/Threading.cpp<br class="">>    llvm/trunk/unittests/Support/ManagedStatic.cpp<br class="">><br class="">> Modified: llvm/trunk/docs/ProgrammersManual.rst<br class="">> URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/ProgrammersManual.rst?rev=211900&r1=211899&r2=211900&view=diff" target="_blank" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/ProgrammersManual.rst?rev=211900&r1=211899&r2=211900&view=diff</a><br class="">> ==============================================================================<br class="">> --- llvm/trunk/docs/ProgrammersManual.rst (original)<br class="">> +++ llvm/trunk/docs/ProgrammersManual.rst Fri Jun 27 10:13:01 2014<br class="">> @@ -2170,46 +2170,13 @@ compiler, consider compiling LLVM and LL<br class="">> using the resultant compiler to build a copy of LLVM with multithreading<br class="">> support.<br class="">><br class="">> -.. _startmultithreaded:<br class="">> -<br class="">> -Entering and Exiting Multithreaded Mode<br class="">> ----------------------------------------<br class="">> -<br class="">> -In order to properly protect its internal data structures while avoiding<br class="">> -excessive locking overhead in the single-threaded case, the LLVM must intialize<br class="">> -certain data structures necessary to provide guards around its internals.  To do<br class="">> -so, the client program must invoke ``llvm_start_multithreaded()`` before making<br class="">> -any concurrent LLVM API calls.  To subsequently tear down these structures, use<br class="">> -the ``llvm_stop_multithreaded()`` call.  You can also use the<br class="">> -``llvm_is_multithreaded()`` call to check the status of multithreaded mode.<br class="">> -<br class="">> -Note that both of these calls must be made *in isolation*.  That is to say that<br class="">> -no other LLVM API calls may be executing at any time during the execution of<br class="">> -``llvm_start_multithreaded()`` or ``llvm_stop_multithreaded``.  It is the<br class="">> -client's responsibility to enforce this isolation.<br class="">> -<br class="">> -The return value of ``llvm_start_multithreaded()`` indicates the success or<br class="">> -failure of the initialization.  Failure typically indicates that your copy of<br class="">> -LLVM was built without multithreading support, typically because GCC atomic<br class="">> -intrinsics were not found in your system compiler.  In this case, the LLVM API<br class="">> -will not be safe for concurrent calls.  However, it *will* be safe for hosting<br class="">> -threaded applications in the JIT, though :ref:`care must be taken<br class="">> -<jitthreading>` to ensure that side exits and the like do not accidentally<br class="">> -result in concurrent LLVM API calls.<br class="">> -<br class="">> .. _shutdown:<br class="">><br class="">> Ending Execution with ``llvm_shutdown()``<br class="">> -----------------------------------------<br class="">><br class="">> When you are done using the LLVM APIs, you should call ``llvm_shutdown()`` to<br class="">> -deallocate memory used for internal structures.  This will also invoke<br class="">> -``llvm_stop_multithreaded()`` if LLVM is operating in multithreaded mode.  As<br class="">> -such, ``llvm_shutdown()`` requires the same isolation guarantees as<br class="">> -``llvm_stop_multithreaded()``.<br class="">> -<br class="">> -Note that, if you use scope-based shutdown, you can use the<br class="">> -``llvm_shutdown_obj`` class, which calls ``llvm_shutdown()`` in its destructor.<br class="">> +deallocate memory used for internal structures.<br class="">><br class="">> .. _managedstatic:<br class="">><br class="">> @@ -2217,15 +2184,11 @@ Lazy Initialization with ``ManagedStatic<br class="">> ------------------------------------------<br class="">><br class="">> ``ManagedStatic`` is a utility class in LLVM used to implement static<br class="">> -initialization of static resources, such as the global type tables.  Before the<br class="">> -invocation of ``llvm_shutdown()``, it implements a simple lazy initialization<br class="">> -scheme.  Once ``llvm_start_multithreaded()`` returns, however, it uses<br class="">> +initialization of static resources, such as the global type tables.  In a<br class="">> +single-threaded environment, it implements a simple lazy initialization scheme.<br class="">> +When LLVM is compiled with support for multi-threading, however, it uses<br class="">> double-checked locking to implement thread-safe lazy initialization.<br class="">><br class="">> -Note that, because no other threads are allowed to issue LLVM API calls before<br class="">> -``llvm_start_multithreaded()`` returns, it is possible to have<br class="">> -``ManagedStatic``\ s of ``llvm::sys::Mutex``\ s.<br class="">> -<br class="">> .. _llvmcontext:<br class="">><br class="">> Achieving Isolation with ``LLVMContext``<br class="">><br class="">> Modified: llvm/trunk/include/llvm-c/Core.h<br class="">> URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm-c/Core.h?rev=211900&r1=211899&r2=211900&view=diff" target="_blank" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm-c/Core.h?rev=211900&r1=211899&r2=211900&view=diff</a><br class="">> ==============================================================================<br class="">> --- llvm/trunk/include/llvm-c/Core.h (original)<br class="">> +++ llvm/trunk/include/llvm-c/Core.h Fri Jun 27 10:13:01 2014<br class="">> @@ -2848,16 +2848,13 @@ void LLVMDisposePassManager(LLVMPassMana<br class="">>  * @{<br class="">>  */<br class="">><br class="">> -/** Allocate and initialize structures needed to make LLVM safe for<br class="">> -    multithreading. The return value indicates whether multithreaded<br class="">> -    initialization succeeded. Must be executed in isolation from all<br class="">> -    other LLVM api calls.<br class="">> -    @see llvm::llvm_start_multithreaded */<br class="">> +/** Deprecated: Multi-threading can only be enabled/disabled with the compile<br class="">> +    time define LLVM_ENABLE_THREADS.  This function always returns<br class="">> +    LLVMIsMultithreaded(). */<br class="">> LLVMBool LLVMStartMultithreaded(void);<br class="">><br class="">> -/** Deallocate structures necessary to make LLVM safe for multithreading.<br class="">> -    Must be executed in isolation from all other LLVM api calls.<br class="">> -    @see llvm::llvm_stop_multithreaded */<br class="">> +/** Deprecated: Multi-threading can only be enabled/disabled with the compile<br class="">> +    time define LLVM_ENABLE_THREADS. */<br class="">> void LLVMStopMultithreaded(void);<br class="">><br class="">> /** Check whether LLVM is executing in thread-safe mode or not.<br class="">><br class="">> Modified: llvm/trunk/include/llvm/Support/ManagedStatic.h<br class="">> URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/ManagedStatic.h?rev=211900&r1=211899&r2=211900&view=diff" target="_blank" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/ManagedStatic.h?rev=211900&r1=211899&r2=211900&view=diff</a><br class="">> ==============================================================================<br class="">> --- llvm/trunk/include/llvm/Support/ManagedStatic.h (original)<br class="">> +++ llvm/trunk/include/llvm/Support/ManagedStatic.h Fri Jun 27 10:13:01 2014<br class="">> @@ -103,9 +103,6 @@ void llvm_shutdown();<br class="">> /// llvm_shutdown() when it is destroyed.<br class="">> struct llvm_shutdown_obj {<br class="">>   llvm_shutdown_obj() { }<br class="">> -  explicit llvm_shutdown_obj(bool multithreaded) {<br class="">> -    if (multithreaded) llvm_start_multithreaded();<br class="">> -  }<br class="">>   ~llvm_shutdown_obj() { llvm_shutdown(); }<br class="">> };<br class="">><br class="">><br class="">> Modified: llvm/trunk/include/llvm/Support/Threading.h<br class="">> URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/Threading.h?rev=211900&r1=211899&r2=211900&view=diff" target="_blank" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/Threading.h?rev=211900&r1=211899&r2=211900&view=diff</a><br class="">> ==============================================================================<br class="">> --- llvm/trunk/include/llvm/Support/Threading.h (original)<br class="">> +++ llvm/trunk/include/llvm/Support/Threading.h Fri Jun 27 10:13:01 2014<br class="">> @@ -7,7 +7,8 @@<br class="">> //<br class="">> //===----------------------------------------------------------------------===//<br class="">> //<br class="">> -// TThis file defines llvm_start_multithreaded() and friends.<br class="">> +// This file declares helper functions for running LLVM in a multi-threaded<br class="">> +// environment.<br class="">> //<br class="">> //===----------------------------------------------------------------------===//<br class="">><br class="">> @@ -15,22 +16,8 @@<br class="">> #define LLVM_SUPPORT_THREADING_H<br class="">><br class="">> namespace llvm {<br class="">> -  /// llvm_start_multithreaded - Allocate and initialize structures needed to<br class="">> -  /// make LLVM safe for multithreading.  The return value indicates whether<br class="">> -  /// multithreaded initialization succeeded.  LLVM will still be operational<br class="">> -  /// on "failed" return, and will still be safe for hosting threading<br class="">> -  /// applications in the JIT, but will not be safe for concurrent calls to the<br class="">> -  /// LLVM APIs.<br class="">> -  /// THIS MUST EXECUTE IN ISOLATION FROM ALL OTHER LLVM API CALLS.<br class="">> -  bool llvm_start_multithreaded();<br class="">> -<br class="">> -  /// llvm_stop_multithreaded - Deallocate structures necessary to make LLVM<br class="">> -  /// safe for multithreading.<br class="">> -  /// THIS MUST EXECUTE IN ISOLATION FROM ALL OTHER LLVM API CALLS.<br class="">> -  void llvm_stop_multithreaded();<br class="">> -<br class="">> -  /// llvm_is_multithreaded - Check whether LLVM is executing in thread-safe<br class="">> -  /// mode or not.<br class="">> +  /// Returns true if LLVM is compiled with support for multi-threading, and<br class="">> +  /// false otherwise.<br class="">>   bool llvm_is_multithreaded();<br class="">><br class="">>   /// llvm_execute_on_thread - Execute the given \p UserFn on a separate<br class="">><br class="">> Modified: llvm/trunk/lib/IR/Core.cpp<br class="">> URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Core.cpp?rev=211900&r1=211899&r2=211900&view=diff" target="_blank" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Core.cpp?rev=211900&r1=211899&r2=211900&view=diff</a><br class="">> ==============================================================================<br class="">> --- llvm/trunk/lib/IR/Core.cpp (original)<br class="">> +++ llvm/trunk/lib/IR/Core.cpp Fri Jun 27 10:13:01 2014<br class="">> @@ -2708,11 +2708,10 @@ void LLVMDisposePassManager(LLVMPassMana<br class="">> /*===-- Threading ------------------------------------------------------===*/<br class="">><br class="">> LLVMBool LLVMStartMultithreaded() {<br class="">> -  return llvm_start_multithreaded();<br class="">> +  return LLVMIsMultithreaded();<br class="">> }<br class="">><br class="">> void LLVMStopMultithreaded() {<br class="">> -  llvm_stop_multithreaded();<br class="">> }<br class="">><br class="">> LLVMBool LLVMIsMultithreaded() {<br class="">><br class="">> Modified: llvm/trunk/lib/Support/Threading.cpp<br class="">> URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Threading.cpp?rev=211900&r1=211899&r2=211900&view=diff" target="_blank" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Threading.cpp?rev=211900&r1=211899&r2=211900&view=diff</a><br class="">> ==============================================================================<br class="">> --- llvm/trunk/lib/Support/Threading.cpp (original)<br class="">> +++ llvm/trunk/lib/Support/Threading.cpp Fri Jun 27 10:13:01 2014<br class="">> @@ -7,7 +7,8 @@<br class="">> //<br class="">> //===----------------------------------------------------------------------===//<br class="">> //<br class="">> -// This file implements llvm_start_multithreaded() and friends.<br class="">> +// This file defines helper functions for running LLVM in a multi-threaded<br class="">> +// environment.<br class="">> //<br class="">> //===----------------------------------------------------------------------===//<br class="">><br class="">> @@ -19,38 +20,14 @@<br class="">><br class="">> using namespace llvm;<br class="">><br class="">> -static bool multithreaded_mode = false;<br class="">> -<br class="">> -bool llvm::llvm_start_multithreaded() {<br class="">> +bool llvm::llvm_is_multithreaded() {<br class="">> #if LLVM_ENABLE_THREADS != 0<br class="">> -  assert(!multithreaded_mode && "Already multithreaded!");<br class="">> -  multithreaded_mode = true;<br class="">> -<br class="">> -  // We fence here to ensure that all initialization is complete BEFORE we<br class="">> -  // return from llvm_start_multithreaded().<br class="">> -  sys::MemoryFence();<br class="">>   return true;<br class="">> #else<br class="">>   return false;<br class="">> #endif<br class="">> }<br class="">><br class="">> -void llvm::llvm_stop_multithreaded() {<br class="">> -#if LLVM_ENABLE_THREADS != 0<br class="">> -  assert(multithreaded_mode && "Not currently multithreaded!");<br class="">> -<br class="">> -  // We fence here to insure that all threaded operations are complete BEFORE we<br class="">> -  // return from llvm_stop_multithreaded().<br class="">> -  sys::MemoryFence();<br class="">> -<br class="">> -  multithreaded_mode = false;<br class="">> -#endif<br class="">> -}<br class="">> -<br class="">> -bool llvm::llvm_is_multithreaded() {<br class="">> -  return multithreaded_mode;<br class="">> -}<br class="">> -<br class="">> #if LLVM_ENABLE_THREADS != 0 && defined(HAVE_PTHREAD_H)<br class="">> #include <pthread.h><br class="">><br class="">><br class="">> Modified: llvm/trunk/unittests/Support/ManagedStatic.cpp<br class="">> URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/ManagedStatic.cpp?rev=211900&r1=211899&r2=211900&view=diff" target="_blank" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/ManagedStatic.cpp?rev=211900&r1=211899&r2=211900&view=diff</a><br class="">> ==============================================================================<br class="">> --- llvm/trunk/unittests/Support/ManagedStatic.cpp (original)<br class="">> +++ llvm/trunk/unittests/Support/ManagedStatic.cpp Fri Jun 27 10:13:01 2014<br class="">> @@ -47,7 +47,6 @@ TEST(Initialize, MultipleThreads) {<br class="">>   void *p1 = test1::allocate_stack(a1);<br class="">>   void *p2 = test1::allocate_stack(a2);<br class="">><br class="">> -  llvm_start_multithreaded();<br class="">>   pthread_t t1, t2;<br class="">>   pthread_create(&t1, &a1, test1::helper, nullptr);<br class="">>   pthread_create(&t2, &a2, test1::helper, nullptr);<br class="">> @@ -55,7 +54,6 @@ TEST(Initialize, MultipleThreads) {<br class="">>   pthread_join(t2, nullptr);<br class="">>   free(p1);<br class="">>   free(p2);<br class="">> -  llvm_stop_multithreaded();<br class="">> }<br class="">> #endif<br class="">><br class="">><br class="">><br class="">> _______________________________________________<br class="">> llvm-commits mailing list<br class="">><span class="Apple-converted-space"> </span><a href="mailto:llvm-commits@cs.uiuc.edu" class="">llvm-commits@cs.uiuc.edu</a><br class="">><span class="Apple-converted-space"> </span><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank" class="">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br class=""><br class=""><br class="">_______________________________________________<br class="">llvm-commits mailing list<br class=""><a href="mailto:llvm-commits@cs.uiuc.edu" class="">llvm-commits@cs.uiuc.edu</a><br class=""><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank" class="">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a></div></div></blockquote></div></div></blockquote></div><br class=""></div></div></div>_______________________________________________<br class="">llvm-commits mailing list<br class=""><a href="mailto:llvm-commits@cs.uiuc.edu" class="">llvm-commits@cs.uiuc.edu</a><br class="">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits<br class=""></div></blockquote></div><br class=""></div></body></html>