Time measurements - rdtsc

Hi,

I would like to know if it is safe to use TSC value for time measurements. There was an issue with TSC value on the systems with power management.
Yet, I see that on some new platforms with invariant TSC support, I can safely use rdtsc instruction to obtain TSC to calculate the time.

Am I missing something?
Thank you.

You wrote:

I would like to know if it is safe to use TSC value for time
measurements. There was an issue with TSC value on the systems with
power management.

Yet, I see that on some new platforms with invariant TSC support, I
can safely use rdtsc instruction to obtain TSC to calculate the time.

Am I missing something?

It depends on what kind of timing and how you define “safe”. Even with invariant TSC, the cycle counters can vary between different cores. So, unless you use affinity to lock yourself into a single processor, there are still issues.

But, in some cases that doesn’t matter. If you’re doing basic performance statistics for your own internal use, go for it.

Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

Thank you for your answer. Could you briefly explain to me how with invariant TSC, the cycle counters can vary between different cores?

I thought that they will all share the same value somehow. I guess I was wrong. Thanks.

You wrote:

Thank you for your answer. Could you briefly explain to me how with
invariant TSC, the cycle counters can vary between different cores?

I thought that they will all share the same value somehow. I guess I
was wrong. Thanks.

No, even in a hyperthreaded processor (which is really only one core), each processor has its own cycle counter.

The cycle counters are not synchronized at boot time, and the processors do not come out of reset at the same exact instant.

Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.