Questions tagged [rdtsc]
RDTSC is the x86 read time stamp counter instruction.
142
questions
2
votes
0
answers
54
views
The overhead-free monitor codes in the AMD CPU significantly increases the total synchronization duration
I am conducting a test to measure the message synchronization latency between different cores of a CPU. Specifically, I am measuring how many clock cycles it takes for CPU2 to detect changes in the ...
0
votes
0
answers
17
views
rdtsc delta to nanosecond conversion [duplicate]
Recently, I have been trying to run some performance anlaysis on my program.
I want to measure the latency of some functions in cpu ticks and later convert the delta to nanosecond.
(I intentionally am ...
0
votes
0
answers
43
views
What am I doing wrong in measuring execution time using RDTSC and CPUID instructions? [duplicate]
I'm a C++ student and I was assigned to measure the time of memory allocation of 1.000.000 integers, using CPUID and RDTSC instructions in inline assembly for G++ compiler. Here is the code I came up ...
0
votes
0
answers
57
views
My GCC __rdtsc() method of calculating clock cycles returns me a totally different result than Microsoft inline assembly rdtsc
So my goal is to test how many clock cycles does it take to allocate one million integers with "malloc" function in C++.
I have 2 programs, one in Visual Studio, which calls RDTSC from ...
0
votes
0
answers
25
views
Using rte_rdtsc() function for accurate time calculations
By the following code:
#include "../common/common.dep"
// I expect rte_rdtsc() may be used for accurate time calculations, but it seems that it has incremental differentiation.
int main(...
5
votes
2
answers
150
views
Clang optimizes out RDTSC asm blocks thinking the repeated block yields the same as the previous block. Is this legal?
Supposed we have some repetitions of the same asm that contains RDTSC such as
volatile size_t tick1;
asm ( "rdtsc\n" // Returns the time in EDX:EAX.
"shl $32,...
1
vote
0
answers
93
views
how to use `__rdtsc` properly in linux x86 gcc
In linux, the gcc compiler has the intrinsic function __rdtsc to measure the cpu cycles. So I don't need to use inline asm code, which I am not familiar with.
On the other hand, when reading posts ...
1
vote
0
answers
121
views
rdtsc under WSL2 lacks nonstop_tsc?
I'm doing some microbenchmarking of short code snippets using the __rdtsc intrinsic inside WSL2 on Windows 11. I'm noticing that there is a lot more variance in the results than I'm used to from ...
0
votes
1
answer
204
views
Best practice of using __rdtsc
I am new to system programing, and I have some doubts about how to use __rdtsc.
Here is a quote from Microsoft Learn:
Generates the rdtsc instruction, which returns the processor time stamp. The ...
1
vote
0
answers
36
views
Why aren't mfence;RDTSCP timings closer to equal across repeated calls after warm-up? +-2% variation over ~3300 TSC counts
I am writing code to compare the execution times of different versions of a bigint add function, on AMD FX(tm)-8350 Eight-Core Processor 4.00 GHz.
I need help to make sense of the machine behaviour ...
1
vote
0
answers
170
views
Configure qemu KVM-SVM to not emulate rdtscp and get valid timestamp
I am trying to measure the cycle count of an instruction in a VM -- my code looks like this:
start = rdtscp();
//complex_sequence_of_instructions
end = rtdscp();
//complex_sequence_of_instructions ...
2
votes
2
answers
205
views
what is the C++ equivalent for this assembly code [duplicate]
I'm trying to figure out how to read this assembly code in C++.
This is the code:
unsigned __int64 high_perf_time;
unsigned __int64 *dest = &high_perf_time;
__asm
{
_emit 0xf // these ...
4
votes
1
answer
406
views
How to measure the ACTUAL number of clock cycles elapsed on modern x86?
On recent x86, RDTSC returns some pseudo-counter that measures time instead of clock cycles.
Given this, how do I measure actual clock cycles for the current thread/program?
Platform-wise, I prefer ...
1
vote
2
answers
518
views
Is there any way to fake __rdtsc on Windows
I just wonder to know, is there any change to manipulate it or break it on Windows?
For example ivgot a code like that:
while (1)
{
auto v6 = __rdtsc();
switch (v6 &...
1
vote
0
answers
97
views
C# executable (get rdtsc timestamp) crashes intermittently
I have copied this code that queries rdtsc timestamp in C#.
The equivalent in C++ is just __rdtsc()
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Security;
public static ...
0
votes
1
answer
740
views
How stable / constant is the timestamp counter (RDTSC) with temperature and over time?
x86-CPUs have invariant TSCs for a long time, i.e. they change the timestamp counter according to a constant frequency, usually the base-clock of the CPU.
If Windows detects an invariant TSC it ...
4
votes
1
answer
545
views
How to stop VC++ compiler from reordering code?
I have a code like that:
const uint64_t tsc = __rdtsc();
const __m128 res = computeSomethingExpensive();
const uint64_t elapsed = __rdtsc() - tsc;
printf( "%" PRIu64 " cycles", ...
1
vote
2
answers
207
views
In a busy loop, two continuously getting time encounters a big time gap
In a busy loop, some codes contiguously get the current time twice and count their time interval. The time interval is supposed to be small, since the codes belong to a SCHED_FIFO process with highest ...
0
votes
1
answer
124
views
Calling cpuid before rdtsc to prevent out of order? [duplicate]
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 ...
0
votes
0
answers
884
views
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. ...
0
votes
0
answers
153
views
c++ how to write function to measure function performance using time stamp counter [duplicate]
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 - ...
0
votes
0
answers
939
views
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 ...
1
vote
1
answer
263
views
How to specify %edx to be the output instead of conventional %eax in inline assembly in C?
I am trying to use the following inline assembly in C to read the high word (%edx) of Time Stamp Counter for time measurement:
unsigned int tsc;
asm volatile ("rdtscp; xchgl %%edx, %%eax" : &...
0
votes
0
answers
61
views
Better understanding of timing and pipelining [duplicate]
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 ...
5
votes
1
answer
1k
views
Does RDTSCP increment monotonically across multi-cores?
I'm confused whether rdtscp monotonically increments in a multi-core environment. According to the document: __rdtscp, rdtscp seems a processor-based instruction and can prevent reordering of ...
3
votes
1
answer
195
views
Failed to reproduce the high-precision time measuring kernel module from intel's white paper
I am trying to reproduce How to Benchmark Code Execution Times on Intel IA-32 and IA-64 Instruction Set Architectures White Paper. This white paper provides a kernel module to accurately measure the ...
1
vote
0
answers
77
views
What is the difference between inline assembly call and direct call? [duplicate]
What is the difference between using thet= __rdtsc() function directly and using
asm __volatile__ (
"rdtsc \n"
: "=a" (t));
I have seen on ...
2
votes
1
answer
249
views
x86_64 - Why is timing a program with rdtsc/rdtscp giving unreasonably large numbers?
I'm trying to time a subroutine using rdtscp. This is my procedure:
; Setting up time
rdtscp ; Getting time
push rax ; Saving timestamp
; for(r9=0; r9<...
0
votes
0
answers
74
views
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 ...
5
votes
1
answer
2k
views
Better than 100ns resolution timers in Windows
I work on programming language profiler and I am looking for a timer solution for Windows with better than 100 ns resolution.
QueryPerformanceCounter should be an answer, but the returned frequency ...
3
votes
1
answer
3k
views
Can constant non-invariant tsc change frequency across cpu states?
I used to benchmark Linux System Calls with rdtsc to get the counter difference before and after the system call. I interpreted the result as wall clock timer since TSC increments at constant rate and ...
0
votes
1
answer
246
views
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 ...
0
votes
1
answer
179
views
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;
...
4
votes
1
answer
2k
views
How stable is TSC (TimeStamp Counter) from user space for Intel x86-64 CPUs in 2020?
Some times I need a proper way to measure performance at nanosecond from my user space application in order to include the syscall delays in my measurement. I read many old (10yo) articles saying it ...
0
votes
0
answers
175
views
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<double> cyclesList;
int num_runs = 40;
double cycles = 0.;...
1
vote
0
answers
315
views
How to use the output of RDTSC [duplicate]
My code is very simple:
global start
extern printf, Sleep
section .data:
string db 'End: %llu', 0Ah, 'Start: %llu', 0
section .text:
start:
mfence
lfence
rdtsc
sub rsp, 8
...
1
vote
1
answer
130
views
Loop takes less than 1 cycle despite dependency between iterations
I wanted to benchmark the time needed to do a single addition on my Skylake (i5-6500) CPU. C is low-level enough for me, so I wrote the following code:
// Initializing stuffs
int a = rand();
int b = ...
5
votes
1
answer
2k
views
Is there any difference in between (rdtsc + lfence + rdtsc) and (rdtsc + rdtscp) in measuring execution time?
As far as I know, the main difference in runtime ordering in a processor with respect to rdtsc and rdtscp instruction is that whether the execution waits until all previous instructions are executed ...
1
vote
1
answer
2k
views
Why is nop not taking one clock cycle
I wrote a basic code to find out the amount of clock cycles taken by nop. We know nop takes one clock cycle.
#include <stdio.h>
#include <string.h>
#include <stdint.h>
int main(...
1
vote
0
answers
125
views
How to count cycles when TscInvariant = True?
The command rdtsc should be reliable source of time if the "TscInvariant" CPUID feature is enabled (see for example this link). On a dynamic frequency rescaling context, a reliable source of time ...
2
votes
0
answers
397
views
Why is row-major matrix access runs slower than column-major matrix access in my C code?
I'm implementing a C code to compare the effect of spatial locality when accessing a matrix in a row-major order and in a column-major order.
However, the row-major way got a slower result, which is ...
0
votes
1
answer
110
views
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 ...
4
votes
1
answer
1k
views
Multiple nop instructions do not consistently take longer than a single nop instruction
I am timing multiple NOP instructions and a single NOP instruction in C++, using rdtsc. However, I don't get an increase in the number of cycles it takes to execute NOPs in proportion to the number of ...
1
vote
1
answer
87
views
Program error that measures the parameters of matrix multiplication
I'm writing a program that measures the performance of matrix multiplication with rdtsc(), Read Time Stamp Counter.
However, when I combined the matrix multiplication program and performance ...
5
votes
1
answer
858
views
"rdtsc": "=a" (a0), "=d" (d0) what does this do? [duplicate]
I'm new to C++ and benchmarking
I don't understand what the this part of the code does?
So I found something about the edx, eax registers, but I don't fully understand how that plays into the code. ...
1
vote
1
answer
583
views
RDTSC and system calls, sys_read and sys_write
I'm trying to count, using rdtsc, how many cycles it takes write something using sys_write. I was able to test the printf and scanf functions. They worked correctly, and now I have a problem with ...
5
votes
1
answer
609
views
Can different processes run RDTSC at the same time?
Can different processes run RDTSC at the same time?
Or is this a resource that only one core can operate on at the same time?
TSC is in every core (at least you can adjust it separately for every core)...
0
votes
1
answer
42
views
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,...
2
votes
1
answer
1k
views
solution to rdtsc out of order execution?
I am trying to replace clock_gettime(CLOCK_REALTIME, &ts) with rdtsc to benchmark code execution time in terms of cpu cycles rather than server time. The execution time of the bench-marking code ...
5
votes
1
answer
1k
views
RDTSCP in NASM always returns the same value (timing a single instruction)
I am using RDTSC and RDTSCP in NASM to measure machine cycles for various assembly language instructions to help in optimization.
I read "How to Benchmark Code Execution Times on Intel IA-32 and IA-...