X-Recipient: archive-cygwin AT delorie DOT com DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:subject:reply-to:to:references:message-id :date:mime-version:in-reply-to:content-type :content-transfer-encoding; q=dns; s=default; b=s9nZpevvbWXnLq0U Wf0wZmz/yVK9A0oHNyY9RjeCVbGUKRjtJbyUxfrokzQEWkulSre+JYxo6VnmZpwv B7z8+iZEkyWTeDdwq3W8uaRB531cHtBPMhnEpqRC9KhD9CRxveWx6GwGfLpHgSfV vVEPlZsBx6reUfG7pGu3y0H5hYA= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:subject:reply-to:to:references:message-id :date:mime-version:in-reply-to:content-type :content-transfer-encoding; s=default; bh=zImCBcvfJ9mq/7cQaxdSfp 2t6iQ=; b=ac/jhImWsjaXURantvEAAsl1mvtsKCH2HeWdYfzgo1kyNJq5uHYx66 PJlujYu/IP5IrzAmdOmU5jzIvUr+a6NPKBxFHum4W5TcH6eoNYtpz5kt/SE8/l+N 5o8BjeJ+BMyD4MLaRlaSPnDkkDJcs3HdgZWPh0oWM9kkzWTpuGM4o= Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-3.2 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 spammy=Norman, norman, 1809, pst X-HELO: smtp-out-so.shaw.ca From: Brian Inglis Subject: Re: thread_local performance using g++ for cygwin Reply-To: Brian DOT Inglis AT SystematicSw DOT ab DOT ca To: cygwin AT cygwin DOT com References: Openpgp: preference=signencrypt Message-ID: <36b16ae1-fc0c-a598-480a-ffedad690a76@SystematicSw.ab.ca> Date: Mon, 6 May 2019 14:10:31 -0600 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-IsSubscribed: yes On 2019-05-06 01:09, Arthur Norman wrote: > The attached code tried two loops each of which just calls a function that > increments an integer variable. One loop is a simple variable, the other has the > thread_local qualifier. I put in ugly annotations to prevent g++ from inlining > the functions even though I compile with -O3, but in real cases separate > compilation forces each TL access to be independent. > The timing as between the two cases is EXTREME on cygwin (both 32 and 64-bit) > however g++ on Linux and the Microsoft compiler on Windows both manage to keep > the base of thread-local regions in a segment register in such a way that the > thread_local overhead is minimal. The cygwin thread_local overhead is large > enough to be very visible in my code as a whole. I can see that changing to use > a segment register might be a painful API change even if it was feasible, but > has there been any consideration of it? > Note that x86_64-w64-mingw32-g++ and clang also do not use the segment register > so suffer the significant speed penalty, so maybe it would be hard to match what > Microsoft manage? > > Sample output: >     simple 1.265 >     thread_local 33.219 See: https://cygwin.com/git/gitweb.cgi?p=newlib-cygwin.git;f=winsup/cygwin/how-cygtls-works.txt;a=blob and you may want to compare the gcc default options and -S assembler output for your test case on Linux and Cygwin, and perhaps also any glibc and newlib TLS support functions called: running your Linux tests under some WSL distro will even out OS kernel differences. My own tests on Win 10.0.17763.437 1809 are worse than yours: $ g++ -O3 -o tltime.{bin,cpp} $ ./tltime.bin simple 1.60938 thread_local 1.95312 $ uname -srvmo Linux 4.4.0-17763-Microsoft #379-Microsoft Wed Mar 06 19:16:00 PST 2019 x86_64 GNU/Linux $ head /etc/os-release PRETTY_NAME="Debian GNU/Linux 9 (stretch)" NAME="Debian GNU/Linux" VERSION_ID="9" VERSION="9 (stretch)" ID=debian HOME_URL="https://www.debian.org/" SUPPORT_URL="https://www.debian.org/support" BUG_REPORT_URL="https://bugs.debian.org/" $ g++ -O3 -o tltime.{exe,cpp} $ ./tltime.exe simple 1.608 thread_local 53.25 $ uname -srvmo CYGWIN_NT-10.0 3.0.7(0.338/5/3) 2019-04-30 18:08 x86_64 Cygwin $ head /etc/os-release PRETTY_NAME="Cygwin 64 3.0.7 2019-04-30" NAME=Cygwin ID=cygwin ID_LIKE=msys mingw VARIANT="64" VARIANT_ID="x86_64" VERSION="3.0.7 (0.338/5/3) 2019-04-30 18:08" VERSION_ID="3.0.7" BUILD_ID="0.338/5/3 2019-04-30 18:08" CPE_NAME="cpe:/a:cygwin:cygwin:3.0.7::~~~~x64~Windows%3e%3d6.0" -- Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada This email may be disturbing to some readers as it contains too much technical detail. Reader discretion is advised. -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple