public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely.gcc@gmail.com>
To: Keith Erickson <kerickso@pppl.gov>
Cc: gcc-help <gcc-help@gcc.gnu.org>
Subject: Re: Why does std::chrono now() uses slow syscall?
Date: Sun, 26 Jan 2014 10:33:00 -0000	[thread overview]
Message-ID: <CAH6eHdSjowHv+AM=T7nKgyoVuthbg6dAVbBvP0+UBxg0w=_jgg@mail.gmail.com> (raw)
In-Reply-To: <CA+PNwRPnuYXy68x8LkPOZmbGD+4ZTHgU+NCtwSSrr3NnPnAMtg@mail.gmail.com>

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.

  reply	other threads:[~2014-01-26 10:33 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-26  7:50 Keith Erickson
2014-01-26 10:33 ` Jonathan Wakely [this message]
     [not found]   ` <CA+PNwROZe3T4FBn1Kv7MES=b9=X95X81VXEapeiMOi7R65Jh1Q@mail.gmail.com>
2014-01-27  0:12     ` Jonathan Wakely

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAH6eHdSjowHv+AM=T7nKgyoVuthbg6dAVbBvP0+UBxg0w=_jgg@mail.gmail.com' \
    --to=jwakely.gcc@gmail.com \
    --cc=gcc-help@gcc.gnu.org \
    --cc=kerickso@pppl.gov \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).