From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 726 invoked by alias); 26 Jan 2014 10:33:41 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 716 invoked by uid 89); 26 Jan 2014 10:33:40 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.7 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-lb0-f172.google.com Received: from mail-lb0-f172.google.com (HELO mail-lb0-f172.google.com) (209.85.217.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Sun, 26 Jan 2014 10:33:39 +0000 Received: by mail-lb0-f172.google.com with SMTP id c11so3689946lbj.17 for ; Sun, 26 Jan 2014 02:33:36 -0800 (PST) MIME-Version: 1.0 X-Received: by 10.112.91.228 with SMTP id ch4mr13438616lbb.19.1390732416108; Sun, 26 Jan 2014 02:33:36 -0800 (PST) Received: by 10.112.143.70 with HTTP; Sun, 26 Jan 2014 02:33:36 -0800 (PST) In-Reply-To: References: Date: Sun, 26 Jan 2014 10:33:00 -0000 Message-ID: Subject: Re: Why does std::chrono now() uses slow syscall? From: Jonathan Wakely To: Keith Erickson Cc: gcc-help Content-Type: text/plain; charset=UTF-8 X-IsSubscribed: yes X-SW-Source: 2014-01/txt/msg00093.txt.bz2 On 26 January 2014 07:50, Keith Erickson wrote: > My questions, then, are.... why would I ever want to use the syscall > version? It seems that configure prefers it, and will use it if it's > available. It prefers to use clock_gettime and only uses the syscall if a configure test using clock_gettime(CLOCK_MONOTONIC, &tp) fails. > But it's stupidly slow, even on the fasted server CPU that > AMD sells (Opteron 6386 SE at the time of this writing). How do I not > use this slow method? Do I have to compile gcc specially? What are > the drawbacks to forcing configure to not set that #define? Is there > an approved way to tell configure to use a fast time? Prior to glibc 2.17 clock_gettime was in librt.so not libc.so, which is not used automatically by libstdc++. To tell configure to use it you need to build GCC with --enable-libstdcxx-time=rt, but that means that libstdc++.so will be linked to librt.so which depends on libpthread.so which means that the library always thinks it is part of a multithreaded application and so even single-threaded programs use atomic operations for internal reference-counting (e.g. in std::string and std::shared_ptr). That's why we don't use clock_gettime unless explicitly configured to do so. With glibc 2.17 or later clock_gettime will be used automatically, because the functions were moved out of librt.so. On my Fedora 20 system I get | #define HAVE_SYS_TIME_H 1 | #define _GLIBCXX_USE_GETTIMEOFDAY 1 | #define _GLIBCXX_USE_CLOCK_MONOTONIC 1 | #define _GLIBCXX_USE_CLOCK_REALTIME 1 | #define _GLIBCXX_USE_SCHED_YIELD 1 | #define _GLIBCXX_USE_NANOSLEEP 1 which means it doesn't need the syscall version.