views:

1875

answers:

5

I am trying to profile and optimize algorithms and I would like to understand the specific impact of the caches on various processors. For recent Intel x86 processors (e.g. Q9300), it is very hard to find detailed information about cache structure. In particular, most web sites (including Intel.com) that post processor specs do not include any reference to L1 cache. Is this because the L1 cache does not exist or is this information for some reason considered unimportant? Are there any articles or discussions about the elimination of the L1 cache?

[edit] After running various tests and diagnostic programs (mostly those discussed in the answers below), I have concluded that my Q9300 seems to have a 32K L1 data cache. I still haven't found a clear explanation as to why this information is so difficult to come by. My current working theory is that the details of L1 caching are now being treated as trade secrets by Intel.

+2  A: 

L1 caches exist on these platforms. This will almost definitly remain true until memory and front side bus speeds exceed the speed of the CPU, which is a very likely a long way off.

On Windows, you can use the GetLogicalProcessorInformation to get some level of cache information (size, line size, associativity, etc.) The Ex version on Win7 will give even more data, like which cores share which cache. CpuZ also gives this information.

Michael
Thanks for the suggestions. I was able to run CpuZ -- it told me that my L1 data cache was 32K Bytes (per core). Now I just need to figure out whether or not I trust that information.
nobar
You can trust it.
Michael
Can you explain why you are so confident in the accuracy of CpuZ? It's nice that such a tool exists but my confidence is shaken by the fact that I can't find strong corroborating data.
nobar
I have seen data that indicates that the L2 cache runs at the CPU clock speed (2.5 GHz). To me this suggests that the front side bus speed is irrelevant to the question of L1 existence -- the L2 cache is faster than the FSB.
nobar
This post also spurred me to find similar Linux based programs: cpuid and x86info. x86info gave me data for L1 that matched what CpuZ said. However, various inconsistencies and warnings by the two programs still left me doubting.
nobar
+2  A: 

Locality of Reference has a major impact on performance of some algorithms; The size and speed of L1, L2 (and on newer CPUs L3) cache obviously play a large part in this. Matrix multiplication is one such algorithm.

Mitch Wheat
+10  A: 

It is damned near impossible to find specs on Intel caches. When I was teaching a class on caches last year, I asked friends inside Intel (in the compiler group) and they couldn't find specs.

But wait!!! Jed, bless his soul, tells us that on Linux systems, you can squeeze lots of information out of the kernel:

grep . /sys/devices/system/cpu/cpu0/cache/index*/*

This will give you associativity, set size, and a bunch of other information (but not latency). For example, I learned that although AMD advertises their 128K L1 cache, my AMD machine has a split I and D cache of 64K each.


Two suggestions which are now mostly obsolete thanks to Jed:

  • AMD publishes a lot more information about its caches, so you can at least got some information about a modern cache. For example, last year's AMD L1 caches delivered two words per cycle (peak).

  • The open-source tool valgrind has all sorts of cache models inside it, and it is invaluable for profiling and understanding cache behavior. It comes with a very nice visualization tool kcachegrind which is part of the KDE SDK.

As basic data: in Q3 2008 a cache line was 64 bytes, L1 cache was 2-way associative and latency was 1/2 cycle, L2 cache was 16-way associative and latency was about 10 cycles. (All data is from AMD, but trusted colleagues tell me that Intel's designs are similar. Jed's technique shows an split I and D cache at L1, 8-way associative, 32K each.)

Norman Ramsey
I've already started trying to use kcachegrind. As far as I have found so far, I have to tell the tool what my cache details are -- that's what led me to ask the question. You mentioned "cache models". Do you mean to say that valgrind might know the details that I'm looking for?
nobar
Yes definitely---valgrind queries the CPUID, and if it recognizes your CPU, it uses a model for that CPU.
Norman Ramsey
Like some of the other tools that I have run on Linux (cpuid and x86info), valgrind seems to be confused about my machine's cache configuration. Maybe this is just a matter of not recognizing my CPU or maybe it is an indication that the information being withheld by Intel.
nobar
Intel L1 is 8-way associative. On Linux, you can pull all the numbers from `/sys/devices/system/cpu/cpu*/index*/cache`. Also, systems with glibc usually have `getconf(1)`, use like `getconf LEVEL1_DCACHE_ASSOC`.
Jed
@Jed: you rock. Answer updated.
Norman Ramsey
@Jed: Thanks for posting those great suggestions! @Norman: Neat trick with grep -- thanks for updating your post! @getconf: Where've you been all my life? :-)
nobar
+5  A: 

You are looking at the consumer specifications, not the developer specifications. Here is the documentation you want. The cache sizes vary by processor family sub-models, so they typically are not in the IA-32 development manuals, but you can easily look them up on NewEgg and such.

Edit: More specifically: Chapter 10 of Volume 3A (Systems Programming Guide), Chapter 7 of the Optimization Reference Manual, and potentially something in the TLB page-caching manual, although I would assume that one is further out from the L1 than you care about.

Not Sure
I couldn't find real cache data in these manuals. Can you cite volume and page number?
Norman Ramsey
I'm not really sure what you mean by "real", but chapter 7 of the Optimization manual is one place that goes into some detail. There's also the entire manual on the TLB and page caching. It would help to know what *exactly* you're looking for.
Not Sure
There's also Chapter 10 of Volume 3A, the Systems programming guide.
Not Sure
I found Table 10-1 of Volume 3A. It doesn't list individual processors but it does give details (or at least numerical ranges) for cache information for various processor families. It is still a little bit ambiguous (Core 2 Quad isn't explicitly listed for L1), but it's something. Thanks!
nobar
Like most other resources, newegg doesn't list my Q9300 as having an L1 cache (I also didn't find it clearly indicated in the Intel documentation that you cited). I'm guessing that the L1 cache doesn't exist on that chip -- but I'm still just guessing.
nobar
My hope was that doing a google search with [q9300 "L1 cache" site:intel.com] would reveal the processor-specific data from "developer specifications". No such luck.
nobar
Your Q9300 definitely does have an L1 cache - just google "intel q9300 l1 cache" and you'll get specs from the hardware review sites. I can't think of any decent modern processor without an L1 and L2 cache - use CPU-z or somesuch to find out what it is on your machine.
Not Sure
+2  A: 

I did some more investigating. There is a group at ETH Zurich who built a memory-performance evaluation tool which might be able to get information about the size at least (and maybe also associativity) of L1 and L2 caches. The program works by trying different read patterns experimentally and measuring the resulting throughput. A simplified version was used for the popular textbook by Bryant and O'Hallaron.

Norman Ramsey
I tried these out (and I had written a similar program). The results suggest discontinuous performance results at 32K and 3M on my Q9300. Thanks for the help!
nobar