home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / arch / 12244 < prev    next >
Encoding:
Internet Message Format  |  1993-01-12  |  8.3 KB

  1. Xref: sparky comp.arch:12244 comp.sys.ibm.pc.hardware:35573
  2. Path: sparky!uunet!haven.umd.edu!darwin.sura.net!gatech!psuvax1!rutgers!cbmvax!snark!esr
  3. From: esr@snark.thyrsus.com (Eric S. Raymond)
  4. Newsgroups: comp.arch,comp.sys.ibm.pc.hardware
  5. Subject: Request For Comments --- IBM-clone cache-design tutorial for Buyer's Guide
  6. Message-ID: <1k5rJG#1wnsqp9bCpVr2wtwkc4PyLSl=esr@snark.thyrsus.com>
  7. Date: 11 Jan 93 23:43:56 GMT
  8. Followup-To: poster
  9. Lines: 141
  10.  
  11. I want to add a section on cache design and its performance impact to my
  12. 386/486 Hardware Buyers' Guide.  This is the draft.  Please email your comments
  13. if you think you see an error or significant omission.
  14.  
  15. -------------------------------- CUT HERE ------------------------------------
  16. C. Cache Flow
  17.  
  18. The most obscure of the important factors in the performance of a UNIX 486
  19. system is the motherboard's memory cache size and design.  The two questions
  20. performance-minded buyers have to deal with are: (1) does the cache design
  21. of a given motherboard work with UNIX, and (2) how much cache SRAM should
  22. my system have?
  23.  
  24. Before normal clock speeds hit two digits in MHz, cache design wasn't a big
  25. issue.  But DRAM's memory-cycle times just aren't fast enough to keep up with
  26. today's processors.  Thus, your machine's memory controller caches memory
  27. references in faster static RAM, reading from main memory in chunks that the
  28. board designer hopes will be large enough to keep the CPU continuously fed
  29. under a typical job load.  If the cache system fails to work, the processor
  30. will be slowed down to less than the memory's real access speed --- which,
  31. given January 1993's typical 60ns DRAM parts, is about 16MHz.
  32.  
  33. The 486 includes an 8K cache right on the processor chip.  If memory accesses
  34. were reliably sequential and well-localized, this would be fine.
  35. Unfortunately, one side-effect of what's today considered "good programming
  36. practice", with high-level languages using a lot of subroutine calls, is that
  37. the program counter of a typical process hops around like crazy; locality is
  38. really poor.  This gives the cacheing system a workout.  UNIX makes the problem
  39. worse, because clock interrupts and other effects of multitasking design
  40. degrade locality still further.
  41.  
  42. Thus, the 486's 8K internal primary cache is typically supplemented with an
  43. external caching system using SRAM; in January 1993, 20ns SRAM is typical.
  44. The size and design of your motherboard cache is one of the most critical
  45. factors in your system's real performance.
  46.  
  47. Unfortunately, cache design is a complicated black art, and cache performance
  48. isn't easy to predict or measure, especially under the rapidly variable
  49. system loads characteristic of UNIX.  Thus, the best advice your humble editor
  50. can give is a collection of rules of thumb.  Your mileage may vary...
  51.  
  52. Rule 1: Buy only motherboards that have been tested with UNIX
  53.    One of DOS's many sins is that it licenses poor hardware design; it's too
  54. brain-dead to stretch the cache system much.  Thus, bad cache designs that
  55. will run DOS can completely hose UNIX, slowing the machine to a crawl or even
  56. (in extreme cases) causing frequent random panics.  Make sure your motherboard
  57. or system has been tested with some UNIX variant.
  58.  
  59. Rule 2: Be sure you get enough cache.
  60.    If your motherboard offers multiple cache sizes, make sure you how much is
  61. required to service the DRAM you plan to install.  If possible, fill the cache
  62. all the way -- cache-speed RAM is getting pretty cheap and this may save you
  63. many hassles later.
  64.    Bela Lubkin writes: "Excess RAM [over what your cache can support] is a very
  65. bad idea: most designs prevent memory outside the external cache's cachable
  66. range from being cached by the 486 internal cache either.  Code running from
  67. this memory runs up to 11 times slower than code running out of fully cached
  68. memory."
  69.  
  70. Rule 3: "Enough cache" is at least 64K per MB of DRAM
  71.    Hardware caches are usually designed to achieve effective 0 wait state
  72. status, rather than perform any significant buffering of data.  As a general
  73. rule applicable to all clones, 64Kb cache handles up to 16Mb memory; in a
  74. "direct-mapped" cache design (typical for clone hardware) more is redundant.
  75. We'll have more to say about cache sizes below.
  76.  
  77. Rule 4: If possible, max out the board's cache -- it wlll save hassles later
  78.    Bela continues: "Get the largest cache size your motherboard supports, even
  79. if you're not fully populating it with RAM.  The motherboard manufacturer buys
  80. cache chips in quantity, knows how to install them correctly, and you won't end
  81. up throwing out the small chips later when you upgrade your main RAM."
  82.  
  83. A lot of fast chips are held back by poor cache systems and slow memory.  The
  84. 50DX has a particular problem this way, because its cycle spead is as fast as
  85. that of a 20ns cache SRAM.  To avoid trouble, cloners often insert wait states
  86. at the cache, slowing down the 50DX to the effective speed of a 50DX/2.
  87.  
  88. Worse than this, a lot of cloners have taken the 50DX/2 and 66DX/2 as
  89. invitations to reuse old 25- and 33MHz board designs without change.  The
  90. trouble is that these chips take a double hit for each wait state, because
  91. the wait states are timed by *external* cycles.  And there can be lots of
  92. them; a look at the CMOS setup screen of most 33Mhz and 50MHz system will
  93. usually reveal many wait states.
  94.  
  95. Now for some basic cache-design terminology.
  96.  
  97.    "write-through" --- it wouldn't do to let your cache get out of sync with
  98. main memory.  The simplest and slowest way to handle this is to arrange that
  99. every write to cache generates the corresponding write to main store.  In
  100. effect, then, you only get cache speedup on reads.
  101.  
  102.    "write-back" --- for each cache address range in DRAM, writes are done to
  103. cache only until a new block has to be fetched due to out-of-range access (at
  104. which point the old one is flushed to DRAM).  This is much faster, because
  105. you get cache speedup on writes as well as reads.  It's also more expensive
  106. and trickier to get right.
  107.  
  108. To understand the next two terms, you need to think of main RAM as being
  109. divided into consecutive, non-overlapping segments we'll call "regions".  A
  110. typical region size is 16MB.  Think of cache SRAM as being divided into
  111. similar, but much smaller segments (typically 64K each) which we'll call
  112. "pages".  When the processor reads from an address in a given region, and that
  113. address is not already in core, the location and 64K around it is read into a
  114. page.
  115.  
  116.    "direct-mapped" --- describes a cache system in which each region has
  117. exactly one corresponding page (also called "one-way cache").  Typically,
  118. you get the page address in cache by throwing away the top 16 bits of the
  119. region address.
  120.  
  121.    "two-way set-associative" --- each region has *two* possible lots (the cache
  122. must be at least twice as large as a direct-mapped cache for the same amount of
  123. memory).  Because you can cache two sections of any given region, your odds of
  124. not having to fetch from DRAM (and, hence, your effective speed) go up.
  125.  
  126. There are also "four-way" caches. In general, an n-way cache has n pages per
  127. region and improves your effective speed by some factor proportional to n.
  128. However, for n > 1 you need some auxilliary SRAM storage for a beast called a
  129. 'tag table", and pay some computation overhead on each fetch.  Diminishing
  130. returns set in quickly, so one does not commonly see five-way or higher caches.
  131.  
  132. It follows from the above that a "two-way" cache will actually need 128K per
  133. 16MB, possibly plus some tag storage (typically around 2K, though the storage
  134. may be on the cache controller chip itself). And a 4-way cache would need 256K
  135. per 16MB.
  136.  
  137.    "MFA" --- Most Frequently Accessed.  A controller that supports MFA caching
  138. allocates cache pages in a fundamentally different way.  Instead of doing
  139. simple address-mapping, it tracks the frequency of reference to each section of
  140. main memory that it picks up.  When a new cache page is needed, the one
  141. occupying the least frequently used slot is tossed.  This is very similar to
  142. the way OSs like UNIX manage virtual memory, and it's quite effective.
  143.  
  144. The 8K primary cache on the 486 is write-back, four-way set-associative.  For
  145. UNIX use, try to get a write-back external cache, preferably with two- or
  146. four-way set associativity and/or MFA.  These features used to be quite
  147. expensive, but newer cache controllers like the SC82C348 are bringing them
  148. within everyone's reach.
  149. -------------------------------- CUT HERE ------------------------------------
  150. -- 
  151.                     Eric S. Raymond <esr@snark.thyrsus.com>
  152.