You are on page 1of 5

W Developer Zone

Development >

Tools >

Join Today >

Resources >

What can we help you find today?

TSC Synchronization Across Cores

Samuel M. Tue, 04/16/2013 - 20:00

In the Intel 64 and IA-32 Architectures Software Developers Manual Volume 3B Sec 17.13.1 it says:
"On processors with invariant TSC support, the OS may use the TSC for wall clock timer services."
Does this formally imply that the TSC is always synchronized across all cores?

Top RSS

Last post

19 posts / 0 new

For more complete information about compiler optimizations, see our Optimization Notice.

Patrick Fay (Intel) Tue, 04/16/2013 - 20:23

to post comments

Hello Samuel,
The 'Invariant TSC' means that the TSC runs at a fixed frequency and doesn't stop when the cpu halts.
The TSCs are not guaranteed to be synchronized although the OS usually does try to synchronize the TSC at boot time. This is one
reason for the rdtscp instruction. On Nehalem and later cpus, the rdtscp instruction returns the TSC and an identifier indicating on
which cpu you read the TSC. RDTSCP is a serializing instruction... unlike the regular rdtsc instruction.
Pat
Top

Samuel M. Tue, 04/16/2013 - 22:14

to post comments

Thank you for your reply Patrick. Could you please clarify: if it is established that the OS synchronizes the TSC at startup and that the
system has an invariant TSC, so that the TSC's on different cores will not be skewed by different cores having different instances of
SpeedStep/TurboBoost triggering, is there any way for the TSCs to get out of sync in the course of the system being up for a
significant period fo time?

Top

Patrick Fay (Intel) Wed, 04/17/2013 - 05:21

to post comments

An Invariant TSC won't vary with Speedstep nor TurboBoost. There shouldn't be any way for the TSCs to get out sync but I've never
actually checked this.

Log in

Top

Sergey Kostrov Wed, 04/17/2013 - 21:30

to post comments

The smallest difference in TSC values for two different cores I've measured was 708 nano-seconds. It should be less for fast 3rd
generation CPUs, like Ivy Bridge, etc, and take a look at:
Forum Topic: Synchronizing Time Stamp Counter
Web-link: software.intel.com/en-us/forums/topic/332570
Note: A test case is attached to my post dated on Tue, 11/06/2012 - 06:49
Top

Tim Prince Thu, 04/18/2013 - 03:33

to post comments

Presumably, the TSCs on a single CPU share internal resources. Even between CPUs, they are locked to a single time base, so they
should not drift apart after being started by a shared reset signal.
People are still getting tied in knots over this, particularly on Windows, where gfortran is now in the middle of a system_clock strategy
change (and ifort doesn't have consistent results for intervals less than 10 ms).
I'm expecting to go some rounds with an Intel expert on Ivy Bridge dual CPU next week. There may be a new round of questions to
resolve about synchronization between CPUs, with faster RAM, .... No, I don't intend to try Windows on it.
Top

Sergey Kostrov Thu, 04/18/2013 - 06:32

to post comments

Duplicate - deleted. There are strange performance issues today!

Top

Sergey Kostrov Thu, 04/18/2013 - 06:32

to post comments

>>...Does this formally imply that the TSC is always synchronized across all cores?
Every computer system has one Reset signal and how is it possible to have different TSC values for different cores? What I see is just
measurements errors and in a multi-threaded environment it is impossible to accurately measure all TSC values for all CPUs at the
same time.
Top

iliyapolak Thu, 04/18/2013 - 09:58

to post comments

MultiThreaded application measurement with TSC counters cannot be exactly precise because user mode code cannot be guaranteed
to take control of the executing core for the period of sampling.More priviledged code mainly ISR and its DPC can preeempt user mode
code in any moment and by doing this measurement inaccuracy can be large.

Top

Sergey Kostrov Thu, 04/18/2013 - 10:40

>>...I'm expecting to go some rounds with an Intel expert on Ivy Bridge dual CPU next week...
It would be nice to hear results of your discussion. Thanks in advance.

to post comments

Top

iliyapolak Tue, 04/23/2013 - 03:00

to post comments

There is a possiblity to spawn kernel mode thread run it on cpu while the others logical processors are spinning in busy-wait loop at
DPC level.So one can literally use the logical processor for performance sampling while other code is stalled.

Top

Sergey Kostrov Tue, 04/23/2013 - 06:41

to post comments

>>...Does this formally imply that the TSC is always synchronized across all cores?
Samuel, try to imaging if they are Not synchronized and what implications it would create on all the rest hardware subsystems.

Top

Samuel M. Tue, 04/23/2013 - 14:53

to post comments

>> Samuel, try to imaging if they are Not synchronized and what implications it would create on all the rest hardware subsystems.
Could you please elaborate?

Top

Tim Prince Wed, 04/24/2013 - 09:41

to post comments

Quote:

Sergey Kostrov wrote:


>>...I'm expecting to go some rounds with an Intel expert on Ivy Bridge dual CPU next week...
It would be nice to hear results of your discussion. Thanks in advance.

As you pointed out, this took it well off topic.


Top

iliyapolak Thu, 04/25/2013 - 01:13

to post comments

Hi Tim,
is not BIOS vendor free to implement any functionality he wants in his code?

Top

Sergey Kostrov Thu, 04/25/2013 - 05:49

to post comments

I wonder how Tim's response is relevant to the subject of the thread? I don't think it answers the original question or provides more
technical details. Thanks anyway.

Top

Tim Prince Thu, 04/25/2013 - 06:38

to post comments

Quote:

iliyapolak wrote:
Hi Tim,
is not BIOS vendor free to implement any functionality he wants in his code?

It's a difficult question, which I'm not in position to discuss in any depth. OEMs do have flexibility in their relationships with their BIOS
writers, if they choose not to use whichever BIOS Intel has chosen for a similar platform. I believe there are BIOS writers' guides,
which are very closely held, and of course I expect Intel to be passing requirements through OEMs when they are responsible for
developing initial versions of products.
Top

iliyapolak Fri, 04/26/2013 - 02:19

to post comments

Tim thanks for the answer.

Top

Sergey Kostrov Fri, 04/26/2013 - 20:49

to post comments

>>In the Intel(R) 64 and IA-32 Architectures Software Developers Manual Volume 3B Sec 17.13.1 it says:
>>
>>"On processors with invariant TSC support, the OS may use the TSC for wall clock timer services."
>>
>>Does this formally imply that the TSC is always synchronized across all cores?
By default the TSC is synchronized across all cores. However, the TSC value of a core could be changed by some software subsystem
using the WRMSR instruction. Take a look at quotes below and I hope they finally answer your question:
Intel(R) 64 and IA-32 Architectures Software Developers Manual Volume 3 (3A, 3B & 3C):
System Programming Guide
Order Number: 325384-044US
August 2012
Page 571
17.13 TIME-STAMP COUNTER
...
Constant TSC behavior ensures that the duration of each clock tick is uniform and supports the
use of the TSC as a wall clock timer even if the processor core changes frequency.
...
Page 572
17.13.3 Time-Stamp Counter Adjustment
...
Software can modify the value of the time-stamp counter (TSC) of a logical processor by using the WRMSR instruction
to write to the IA32_TIME_STAMP_COUNTER MSR (address 10H). Because such a write applies only to that
logical processor, software seeking to synchronize the TSC values of multiple logical processors must perform these
writes on each logical processor. It may be difficult for software to do this in a way than ensures that all logical
processors will have the same value for the TSC at a given point in time.
The synchronization of TSC adjustment can be simplified by using the 64-bit IA32_TSC_ADJUST MSR ( address
3BH ). Like the IA32_TIME_STAMP_COUNTER MSR, the IA32_TSC_ADJUST MSR is maintained separately for each
logical processor.
...

Top

Back to original post

Terms of Use (http://www.intel.com/content/www/us/en/legal/terms-of-use.html)


*Trademarks (http://www.intel.com/content/www/us/en/legal/trademarks.html)
Privacy (http://www.intel.com/content/www/us/en/privacy/intel-online-privacy-notice-summary.html)
Cookies (http://www.intel.com/content/www/us/en/privacy/intel-cookie-notice.html)

Publications

>