
The CPU timestamp counter is a high-resolution clock source useful for profiling code or controlling tight timing loops. AMD/Intel CPUs support this via the RDTSC opcode, and other CPUs often provide similar functionality. Apparently MS compilers support an __rdtsc() intrinsic, but I couldn't find one for gcc. The code at http://www-unix.mcs.anl.gov/~kazutomo/rdtsc.html seems to do a good job for gcc; it avoids a couple bugs in code found at other sites. Any possibility of a raw boost::rdtsc() or boost::readTSC()? Something that doesn't compile on unsupported architectures would be good. Other code can worry about whether this is an accurate time source[1]; I just want a portable way to access the raw counter itself. Thanks, Daniel [1] Search "rdtsc site:boost.org"

dherring@ll.mit.edu wrote:
The CPU timestamp counter is a high-resolution clock source useful for profiling code or controlling tight timing loops. AMD/Intel CPUs support this via the RDTSC opcode, and other CPUs often provide similar functionality.
Apparently MS compilers support an __rdtsc() intrinsic, but I couldn't find one for gcc.
MSVS 8.0 and higher have the __rdtsc intrinsic. Om earlier versions of MSVC you can use the following inline assembler: inline uint64_t clockCycleCount() { uint64_t ccc; __asm { cpuid // serialize processor rdtsc // read time stamp counter mov dword ptr [ccc + 0], eax mov dword ptr [ccc + 4], edx } return ccc; } I agree that a platform independent version would be useful. --Johan Råde

RDTSC is rather flawed in multi-core systems (see http://msdn.microsoft.com/en-us/library/bb173458(VS.85).aspx for some info on that). What would be really nice is a system independent high-resolution timer that works when the thread in question gets switched between multiple CPUs with power saving. The problem with such a timer, of course, is that it would be much more expensive to call. Jim
-----Original Message----- From: boost-bounces@lists.boost.org [mailto:boost-bounces@lists.boost.org] On Behalf Of Joel FALCOU Sent: 09 June 2008 20:42 To: boost@lists.boost.org Subject: Re: [boost] Request: RDTSC
I agree that a platform independent version would be useful.
--Johan Råde
Couldn't it be added to time/date ?
-- Joel FALCOU Research Engineer @ Institut d'Electronique Fondamentale Université PARIS SUD XI France
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
________________________________________________________________________ This e-mail, and any attachment, is confidential. If you have received it in error, do not use or disclose the information in any way, notify me immediately, and please delete it from your system. ________________________________________________________________________
participants (4)
-
dherring@ll.mit.edu
-
James Talbut
-
Joel FALCOU
-
Johan Råde