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:date:from:to:subject:message-id:mime-version :content-type:content-id; q=dns; s=default; b=hMPQRhUpiRcfcbKUxu zUU6q4clzw3PU1TjSvQ6FRfQ32VaoD7aW68Q4FCCd/hcmnN8thQCS0CExmd1VrOx fqXuvQOngmCmC/4HDRlwyLuXVzv/WvsMYTVUjJhFq6SLO8Di5Hudfmw282E92RCh pKkOGnLga2kJzGHK8tdFkMBwM= 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:date:from:to:subject:message-id:mime-version :content-type:content-id; s=default; bh=UG4uf1fwqgBlQcN03JGA3i0t 4g8=; b=rhkk5JIqQLphrZ2OH63ak8Nc2YeNgeu5us/HQSGx99jYcG5zYZW3I+Z5 5TQIRpxZs5e0C8EpT8moBNKNaIIuc9q/BSsDRDiOn8dXWT3paSDk0wgr52jOqYwT YuPLmLvpNfA1XWVkvMCflJCxyAttvmunJOCBhtzEE2XT3YpnWKo= 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=0.9 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.1 spammy=UD:uk, extreme, EXTREME, H*F:D*ac.uk X-HELO: ppsw-42.csi.cam.ac.uk DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=cam.ac.uk; s=20180806.ppsw; h=Content-ID:Content-Type:MIME-Version:Message-ID:Subject: To:From:Date:Sender:Reply-To:Cc:Content-Transfer-Encoding:Content-Description :Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=GUsVPsR22xyxufUUJnD+ydvVOkCT/r/HIx0equtbovo=; b=GNgt3JQQ7zfro/xhjhB09dcCCa ONGEywQx+97Z2QVs+B6iWp5WyTwFpaKn5MwSPVvaMmW16aVSnvPh3Ycj4yzlFnwfQNwYlwPeyNBDH GsbmURGbNMHL0EVUmIgT5a9QKBOMZTY1vKYlPY3McRUZDUy20rFG7BHcydjT6KyXStMQ=; Date: Mon, 6 May 2019 08:09:17 +0100 (GMT Summer Time) From: Arthur Norman To: cygwin AT cygwin DOT com Subject: thread_local performance using g++ for cygwin Message-ID: User-Agent: Alpine 2.00 (WNT 1167 2008-08-23) MIME-Version: 1.0 Content-Type: MULTIPART/MIXED; BOUNDARY="2262781-27704-1557089932=:8112" Content-ID: X-IsSubscribed: yes --2262781-27704-1557089932=:8112 Content-Type: TEXT/PLAIN; FORMAT=flowed; CHARSET=US-ASCII Content-ID: 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 Arthur --2262781-27704-1557089932=:8112 Content-Type: TEXT/PLAIN; NAME=tltime.cpp Content-Transfer-Encoding: BASE64 Content-ID: Content-Description: Content-Disposition: ATTACHMENT; FILENAME=tltime.cpp I2luY2x1ZGUgPHRpbWUuaD4KI2luY2x1ZGUgPGlvc3RyZWFtPgp0aHJlYWRf bG9jYWwgaW50IHRsX3ZhciA9IDA7CmludCBzaW1wbGVfdmFyID0gMDsKdm9p ZCBzaW1wbGVfaW5jKCkgX19hdHRyaWJ1dGVfXyAoKG5vaW5saW5lKSk7CnZv aWQgc2ltcGxlX2luYygpCnsgICBzaW1wbGVfdmFyKys7Cn0Kdm9pZCB0bF9p bmMoKSBfX2F0dHJpYnV0ZV9fICgobm9pbmxpbmUpKTsKdm9pZCB0bF9pbmMo KQp7ICAgdGxfdmFyKys7Cn0KaW50IG1haW4oaW50IGFyZ2MsIGNoYXIgKmFy Z3ZbXSkKeyAgIGNsb2NrX3QgYzAgPSBjbG9jaygpOwogICAgZm9yICh1bnNp Z25lZCBpbnQgaT0wOyBpPDB4NDAwMDAwMDA7IGkrKykgc2ltcGxlX2luYygp OwogICAgc3RkOjpjb3V0IDw8ICJzaW1wbGUgIiA8PCAoKGNsb2NrKCktYzAp Lyhkb3VibGUpQ0xPQ0tTX1BFUl9TRUMpCiAgICAgICAgICAgICAgPDwgc3Rk OjpmbHVzaCA8PCBzdGQ6OmVuZGw7CiAgICBjMCA9IGNsb2NrKCk7CiAgICBm b3IgKHVuc2lnbmVkIGludCBpPTA7IGk8MHg0MDAwMDAwMDsgaSsrKSB0bF9p bmMoKTsKICAgIHN0ZDo6Y291dCA8PCAidGhyZWFkX2xvY2FsICIgPDwgKChj bG9jaygpLWMwKS8oZG91YmxlKUNMT0NLU19QRVJfU0VDKQogICAgICAgICAg ICAgIDw8IHN0ZDo6Zmx1c2ggPDwgc3RkOjplbmRsOwogICAgcmV0dXJuIDA7 Cn0K --2262781-27704-1557089932=:8112 Content-Type: text/plain; charset=us-ascii -- 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 --2262781-27704-1557089932=:8112--