Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.

Determine the number of L2 caches

jimdempseyatthecove
Honored Contributor III
545 Views

On Windows XP Pro x64 running on Q6600 this has 4 cores and from my understanding this is constructes as two pairs of cores with each pair of cores containing a 4MB L2 cache. I am calling GetLogicalProcessorInformation, I can see the 4 cores however the table returned seems to imply all 4 cores (1111) are sharing one 4MB L2 cache as opposed to two pairs of processors (0011) and (1100) each pair sharing a4MB L2 (i.e. 2 x 4MB L2).

What is the proper way to ascertain the relationship betweens cores and caches?

This may be a bug in the VS 2005 runtime libraries.

Jim Dempsey

0 Kudos
1 Solution
levicki
Valued Contributor I
545 Views
Jim,
As you can see here:
GetLogicalProcessorInformation() API returns incorrect information. There isa hotfix (KB932370) available from Microsoft upon request for Windows XP x64 and Windows Server 2003:
Once you apply the hotfix you should be able to figure out correct topology by using it.
As for the CPUID leaf 0x04, its output is not reliable enough for what you want to accomplish -- for example if your code ever runs on a Dunnington 6-core CPU it will think that there are 8 cores unless you also check the newly introduced CPUID leaf0x0B(a.k.a. topology and cache).

View solution in original post

0 Kudos
5 Replies
jimdempseyatthecove
Honored Contributor III
545 Views


Now I can get the number of L2 caches. Ihad to write an ASM routine (MSVC x64 cannot perform inline assembly)

void __cpuidEX(int CPUinfo[4], int eax, int ecx);

Such that I could get the Deterministic Cache Parameters and now I can see that I have two L2 caches.

However...

The information provided does not indicate which cores share which L2 caches.

Does someone know how to make that determination (without running a timing test)

I know the system thread affinity bit mask is _loosly_ associated to the packages.

I wish to write a routine to determine if L2 caches are shared by affinity (0/1, 2/3) or (0/2, 1/3).

Jim Dempsey

0 Kudos
levicki
Valued Contributor I
546 Views
Jim,
As you can see here:
GetLogicalProcessorInformation() API returns incorrect information. There isa hotfix (KB932370) available from Microsoft upon request for Windows XP x64 and Windows Server 2003:
Once you apply the hotfix you should be able to figure out correct topology by using it.
As for the CPUID leaf 0x04, its output is not reliable enough for what you want to accomplish -- for example if your code ever runs on a Dunnington 6-core CPU it will think that there are 8 cores unless you also check the newly introduced CPUID leaf0x0B(a.k.a. topology and cache).
0 Kudos
jimdempseyatthecove
Honored Contributor III
545 Views
Quoting - Igor Levicki
Jim,
As you can see here:
GetLogicalProcessorInformation() API returns incorrect information. There isa hotfix (KB932370) available from Microsoft upon request for Windows XP x64 and Windows Server 2003:
Once you apply the hotfix you should be able to figure out correct topology by using it.
As for the CPUID leaf 0x04, its output is not reliable enough for what you want to accomplish -- for example if your code ever runs on a Dunnington 6-core CPU it will think that there are 8 cores unless you also check the newly introduced CPUID leaf0x0B(a.k.a. topology and cache).

Thanks for the links, I am waiting for the reply email from MS now.

Why MS keys the download to the machine you use to access the KB downloads I will never know. The computer I generally use for browsing and emailing is a 32-bit WinXP system and I could not get to the x64 download from that computer. I had to perform the Windows Explorer fromt he x64 system (which exposes it to the internet, which I would rather not do).

Also I will check the new CPUID leaf.

My basic interest is to write a function to determine which processor affinities share which levels of cache (through to and includingNUMA nodes).

0 Kudos
levicki
Valued Contributor I
545 Views
You are welcome Jim.

The reason why those downloads are keyed is so that the bad guys using pirated Windows copies couldn't get them (which of course doesn't work because the downloads can still be found on the Internet).

If you are trying to write such a function for the sake of optimal thread scheduling, you might want to take a look at the Thread Building Blocks librarybecause I heard it already takes careofthat for you and it comes with the Professional version of the compiler anyway. These days reinventing the wheel isn't so popular anymore ;-)
0 Kudos
richardbroadhurst
545 Views
That says server 2003 sp1/sp2, do you have links for xp32sp3 (if it needs one) and xp64sp3 (which does)?
0 Kudos
Reply