Questions tagged [rdtsc]

RDTSC is the x86 read time stamp counter instruction.

RDTSC is the x86 read time stamp counter instruction often used for high resolution timing.

See How to Benchmark Code Execution Times on Intel® IA-32 and IA-64 Instruction Set Architectures.

Get CPU cycle count? has info on various caveats of using it: on modern x86, it measures reference cycles, not actual core clock cycles. (And also shows how to access it from C++.)

The earliest CPUs to support RDTSC had fixed clock frequency, and some OSes found it was more useful as a low-overhead time source time-of-day functions, so CPU vendors eventually changed it to be how it is now: a fixed-frequency nonstop counter.

It can be out-of-sync across different cores. (Some CPUs avoid that for cores in the same physical package.)

137 questions
0
votes
1 answer

Calling cpuid before rdtsc to prevent out of order?

I am trying to call cpuid before my rdtsc function to prevent out of order. I initially used this rdtsc function to get 2 timestamps and often I get negative numbers, which is undesirable. This is the rdtsc function, how should I implement cpuid? Or…
0
votes
0 answers

How to convert RDTSC Clock ticks to Real Time in C or C++?

This is the code I am using in C to convert RDTSC clock ticks to time in usec. Assembly code to read the TSC. To covert RDTSC clock ticks to time, need to divide it with CPU clock frequency in GHz. CPU Frequency = 0.963 is in GHz. I don't know where…
Sobia Rind
  • 61
  • 1
  • 3
0
votes
0 answers

c++ how to write function to measure function performance using time stamp counter

i am not sure how a function that will read the Intelx86 Time stamp counter would look like. i'm trying to measure the performance of a single function so I assume that I would need 2 functions: 1 - void startFunctionCounter(int *cycleval) 2 - void…
Megan Darcy
  • 530
  • 5
  • 15
0
votes
0 answers

Measuring CPU cycles under qemu (x86_64)

I'm trying to more or less accurately determine for how many CPU cycles a function in a program running under QEMU (x86_64) (with the -enable-kvm flag set if that matters) executes for. Following the instructions in this Intel white paper, it seems…
Peter
  • 2,919
  • 1
  • 16
  • 35
0
votes
0 answers

Better understanding of timing and pipelining

In this code, I'm just looping through the set of instructions a bunch of times. Without regard to how many times (100, 1000, 1000000), the timing using RDTSC shows (outputs) 6 clock cycles for the loop. I'm on a Coffee Lake I9-9900K There are 13…
Veldaeven
  • 126
  • 5
0
votes
0 answers

Are these three functions equivalent?

I want to write a function to get the current timestamp. Because the __retscp(&addr) function is used directly, one parameter must be input every time. I want to write a function cutTime() in a .h file that returns the current timestamp each time.…
Gerrie
  • 736
  • 3
  • 18
0
votes
1 answer

rdtsc returns no results

i am attempting to use rdtsc for a timer, but both the eax and edx registers either remain empty or they form a number very different from the one given by the __rdtsc function from MS's instrin.h library. here's the assembly code: .model flat,…
tb044491
  • 144
  • 7
0
votes
1 answer

Is it worth using rdtsc() for speed measurements?

I have 4 test functions - foo1(), foo2(), foo3() and foo4(). For measurements I use following program: unsigned __int64 start; unsigned __int64 stop; unsigned __int64 sum; unsigned __int64 orig; sum = 0; for (int i = 0; i < 10000; i++) { start…
0
votes
0 answers

RDTSC : return the time before the loop ended

I'm trying to mesure the performance of a function. double microbenchmark_get_sqrt_latency() { myInt64 start, end; list cyclesList; int num_runs = 40; double cycles = 0.; double multiplier = 1.; double x = 500; …
truvaking
  • 347
  • 2
  • 10
0
votes
1 answer

Making a timer go off at a specific time in a C++ process for purposes of synchronizing two processes

I have two processes in C++ (these are not parent and child processes). Each has been pinned to a specific core using taskset. So, for instance, process 1 is pinned to core 0 and process 2 is pinned to core 1. I want to start running them at the…
fraiser
  • 929
  • 12
  • 28
0
votes
1 answer

When I test the cycle number of the module, the results of each test are quite different。

When I test the cycle number of the module, the results of each test are quite different? 1781344-->First test 1264558-->Second test 1388058-->Third test I use __rdtsc() to record cycles,and use AVX512 intrinsic。 Are there any methods to make the…
0
votes
1 answer

Perf Monitoring for rdtsc dynamically

Is there a way to monitor for assembly instructions in "real-time" dynamically using perf? I have seen that if I use perf record /perf top and then click on the recorded functions, I see the assembly instructions, but can I directly monitor…
0
votes
0 answers

How am I getting 0 clock ticks when measuring latency using rdtscp instruction?

I wanted to measure latency of a very small piece of code. So I added code to have the rdtscp instruction before and after it. The problem is, the latency I measure using that turns out to be 0. static inline __attribute__((always_inline)) uint64_t…
0
votes
1 answer

Using time stamp counter and clock_gettime for cache miss

As a follow-up to this topic, in order to calculate the memory miss latency, I have wrote the following code using _mm_clflush, __rdtsc and _mm_lfence (which is based on the code from this question/answer). As you can see in the code, I first load…
mahmood
  • 23,197
  • 49
  • 147
  • 242
0
votes
0 answers

How to use TSC/RDTSC

I am trying to measure the time taken to run certain functions in my code. Since using RDTSC is most efficient, I would like to use this. However, I couldn't understand how to implement this. Can someone please provide an example as to how we…
Sal
  • 15
  • 7