Additional question RE:Time measurements - rdtsc

This is a common problem. Even user mode code needing to query the
“perfomance counter” has no idea which core the value came from. Trying to
implement test threads with affinity leads to more delays and problems
making the exercise pretty worthless.

My question related to this is: Can the user pre-set the performance counter
(from user mode? or from kernel mode?). I am not thinking of trying to set
them all the same (though it would be nice) but if they could all be pre-set
to very different values, e.g each with a different top few bits, then
anyone reading them would be able to work out instantly which processor’s
counter they got, and easily build a map relating the processor cores after
a few tests.

Thanks, M

>>>>>>>>>>>>>>>>>>

----- Original Message -----
From: Tim Roberts
To: Windows System Software Devs Interest List
Sent: Tuesday, March 16, 2010 2:29 AM
Subject: Re: RE:[ntdev] Time measurements - rdtsc

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.


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

Mike Kemp wrote:

This is a common problem. Even user mode code needing to query the
“perfomance counter” has no idea which core the value came from.
Trying to
implement test threads with affinity leads to more delays and problems
making the exercise pretty worthless.

Well, the affinity solution doesn’t actually cost very much. There’s a
short delay if you need to transition to a different processor from the
one you’re on, but after that, you run at full speed. There is a hotfix
available that modifies QueryPerformanceCounter to set the thread
affinity to lock you into the current processor, thereby working around
the problem. It was advertised as being for Athlon X2 processors only,
so it was never pushed in an update, AFAIK.

My question related to this is: Can the user pre-set the performance
counter
(from user mode? or from kernel mode?). I am not thinking of trying to
set
them all the same (though it would be nice) but if they could all be
pre-set
to very different values, e.g each with a different top few bits, then
anyone reading them would be able to work out instantly which processor’s
counter they got, and easily build a map relating the processor cores
after
a few tests.

The cycle counters are part of the “machine-specific registers”, and as
such are writable using the wrmsr instruction. Attempting to do so
while Windows is running is probably not a good idea.


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