public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/59177] New: steady_clock::now() and system_clock::now do not use the vdso (and are therefore very slow)
@ 2013-11-18 18:23 luto at mit dot edu
  2013-11-18 18:38 ` [Bug libstdc++/59177] " paolo.carlini at oracle dot com
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: luto at mit dot edu @ 2013-11-18 18:23 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59177

            Bug ID: 59177
           Summary: steady_clock::now() and system_clock::now do not use
                    the vdso (and are therefore very slow)
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: luto at mit dot edu

std::chrono::steady_clock::now() does this:

#ifdef _GLIBCXX_USE_CLOCK_GETTIME_SYSCALL
      syscall(SYS_clock_gettime, CLOCK_MONOTONIC, &tp);
#else
      clock_gettime(CLOCK_MONOTONIC, &tp);
#endif

I'm not sure what the intent of this condition is, but the effect is that
glibc's clock_gettime (which is very carefully optimized and avoids using
syscalls) is ignored in favor of using syscall(2) (which is very slow).

This appears to have been introduced by this commit:

http://gcc.gnu.org/ml/libstdc++/2013-05/txtfX2KusGj9C.txt

It's a serious slowdown:

steady_clock::now(): 0.0933114µs per iteration
clock_gettime: 0.0230129µs per iteration

as measured by:

#include <chrono>
#include <iostream>
#include <time.h>
using namespace std;

constexpr int iters = 10000;
typedef chrono::duration<double> dsecs;

int main()
{
  auto start = chrono::steady_clock::now();
  for (int i = 0; i < iters; i++)
    chrono::steady_clock::now();
  auto end = chrono::steady_clock::now();

  std::cout << "steady_clock::now(): " << 1e6 *
chrono::duration_cast<dsecs>(end-start).count() / iters << "µs per
iteration\n";

  start = chrono::steady_clock::now();
  timespec ts;
  for (int i = 0; i < iters; i++)
    clock_gettime(CLOCK_MONOTONIC, &ts);
  end = chrono::steady_clock::now();

  std::cout << "clock_gettime: " << 1e6 *
chrono::duration_cast<dsecs>(end-start).count() / iters << "µs per
iteration\n";
}

system_clock appears to behave identically.
>From gcc-bugs-return-434923-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Mon Nov 18 18:38:32 2013
Return-Path: <gcc-bugs-return-434923-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 12693 invoked by alias); 18 Nov 2013 18:38:32 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 12664 invoked by uid 48); 18 Nov 2013 18:38:29 -0000
From: "dominiq at lps dot ens.fr" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug testsuite/59160] The test c-c++-common/cilk-plus/PS/reduction-3.c fails on x86_64-apple-darwin1(0|3)*.
Date: Mon, 18 Nov 2013 18:38:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: testsuite
X-Bugzilla-Version: 4.9.0
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: dominiq at lps dot ens.fr
X-Bugzilla-Status: UNCONFIRMED
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields:
Message-ID: <bug-59160-4-gnjRCj3sYR@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-59160-4@http.gcc.gnu.org/bugzilla/>
References: <bug-59160-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2013-11/txt/msg01700.txt.bz2
Content-length: 202

http://gcc.gnu.org/bugzilla/show_bug.cgi?idY160

--- Comment #10 from Dominique d'Humieres <dominiq at lps dot ens.fr> ---
Patch submitted at http://gcc.gnu.org/ml/gcc-patches/2013-11/msg02098.html.


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2013-11-19  0:45 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-18 18:23 [Bug libstdc++/59177] New: steady_clock::now() and system_clock::now do not use the vdso (and are therefore very slow) luto at mit dot edu
2013-11-18 18:38 ` [Bug libstdc++/59177] " paolo.carlini at oracle dot com
2013-11-18 18:46 ` jakub at gcc dot gnu.org
2013-11-18 19:15 ` luto at mit dot edu
2013-11-18 19:25 ` jakub at gcc dot gnu.org
2013-11-18 19:46 ` luto at mit dot edu
2013-11-18 19:50 ` jakub at gcc dot gnu.org
2013-11-18 19:53 ` luto at mit dot edu
2013-11-18 19:58 ` jakub at gcc dot gnu.org
2013-11-18 20:03 ` luto at mit dot edu
2013-11-18 20:17 ` paolo.carlini at oracle dot com
2013-11-19  0:15 ` redi at gcc dot gnu.org
2013-11-19  0:45 ` luto at mit dot edu

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).