<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>Hints for how m3core/libm3 should get time efficiently...<br><br> - Jay</div><div><br>Begin forwarded message:<br><br></div><blockquote type="cite"><div><b>From:</b> Jonathan Wakely <<a href="mailto:jwakely.gcc@gmail.com">jwakely.gcc@gmail.com</a>><br><b>Date:</b> January 26, 2014, 2:33:36 AM PST<br><b>To:</b> Keith Erickson <<a href="mailto:kerickso@pppl.gov">kerickso@pppl.gov</a>><br><b>Cc:</b> gcc-help <<a href="mailto:gcc-help@gcc.gnu.org">gcc-help@gcc.gnu.org</a>><br><b>Subject:</b> <b>Re: Why does std::chrono now() uses slow syscall?</b><br><br></div></blockquote><blockquote type="cite"><div><span>On 26 January 2014 07:50, Keith Erickson wrote:</span><br><blockquote type="cite"><span>My questions, then, are....  why would I ever want to use the syscall</span><br></blockquote><blockquote type="cite"><span>version?  It seems that configure prefers it, and will use it if it's</span><br></blockquote><blockquote type="cite"><span>available.</span><br></blockquote><span></span><br><span>It prefers to use clock_gettime and only uses the syscall if a</span><br><span>configure test using clock_gettime(CLOCK_MONOTONIC, &tp) fails.</span><br><span></span><br><blockquote type="cite"><span> But it's stupidly slow, even on the fasted server CPU that</span><br></blockquote><blockquote type="cite"><span>AMD sells (Opteron 6386 SE at the time of this writing).  How do I not</span><br></blockquote><blockquote type="cite"><span>use this slow method?  Do I have to compile gcc specially?  What are</span><br></blockquote><blockquote type="cite"><span>the drawbacks to forcing configure to not set that #define?  Is there</span><br></blockquote><blockquote type="cite"><span>an approved way to tell configure to use a fast time?</span><br></blockquote><span></span><br><span>Prior to glibc 2.17 clock_gettime was in librt.so not libc.so, which</span><br><span>is not used automatically by libstdc++. To tell configure to use it</span><br><span>you need to build GCC with --enable-libstdcxx-time=rt, but that means</span><br><span>that libstdc++.so will be linked to librt.so which depends on</span><br><span>libpthread.so which means that the library always thinks it is part of</span><br><span>a multithreaded application and so even single-threaded programs use</span><br><span>atomic operations for internal reference-counting (e.g. in std::string</span><br><span>and std::shared_ptr).  That's why we don't use clock_gettime unless</span><br><span>explicitly configured to do so.</span><br><span></span><br><span>With glibc 2.17 or later clock_gettime will be used automatically,</span><br><span>because the functions were moved out of librt.so.</span><br><span></span><br><span>On my Fedora 20 system I get</span><br><span></span><br><span>| #define HAVE_SYS_TIME_H 1</span><br><span>| #define _GLIBCXX_USE_GETTIMEOFDAY 1</span><br><span>| #define _GLIBCXX_USE_CLOCK_MONOTONIC 1</span><br><span>| #define _GLIBCXX_USE_CLOCK_REALTIME 1</span><br><span>| #define _GLIBCXX_USE_SCHED_YIELD 1</span><br><span>| #define _GLIBCXX_USE_NANOSLEEP 1</span><br><span></span><br><span>which means it doesn't need the syscall version.</span><br></div></blockquote></body></html>