And there was a time when it wasn't important at all. That same 20 or 25 years ago, many desktop processors simply didn't have a cache. For example, a Motorola 68000 had no data cache or instruction cache. (Later the Motorola 68010 came along with a very rudimentary kind of instruction cache that could only be used for "loop mode" and could only hold 2 instructions.)
They didn't have a cache mainly because they didn't need it. Memory ran at basically the same speed as the processor: you could run your processor at 8 MHz and your memory at 8 MHz too. On one of those old processors, main memory ran, in a relative sense, as fast as on-die cache runs today.
Now, processor cores run at 2 or 3 GHz but memory can't go that fast. And the speed of light isn't changing, so cache behavior gets more and more important.
So basically, 20 or 25 years ago, you needed to worry about instruction generation. Over time, that became almost irrelevant, but you started to have to worry about memory access patterns.
It's not even about how fast memory goes as much as it is the distance and what's in between.
For example, I can lock my CPU to 800MHz. Let's say my memory runs at 1600MHz.
I need to load data. There's a cache miss. So a request is sent. It gets processed through a few levels on the chip, then hits the memory controller, which has to send out the request through the bumps, through the package, onto the mother board, to the memory chips, which then have to obtain the signal, clean it up, and send it to be processed. Then the system essentially operates in reverse.
So even though the memory is twice as fast as my CPU, it still took a hundred cycles to get the data that was requested.
The thing is, memory isn't twice as fast as the CPU. 1600 MHz is the burst transfer rate, not the access time.
The basic cycle time on DRAM chips has stayed at about 5 ns (200 MHz) for many generations. DDR-400, DDR2-800 and DDR3-1600 all perform internal accesses at 200 MHz. But the access produces a 2-, 4- or 8-word burst, respectively.
The latency before that burst starts has stayed around 10 ns. DDR3-1600 operates at a clock speed of 800 MHz (double-pumped), and CL9 means 9 cycles between the read request and the first transfer in the burst. 3 more cycles to the end of the burst, so 12 cycles at 800 MHz or 15 ns total.
And that's if the DRAM has the right page open. If it doesn't, you need to add the second timing number, in cycles: tRCD, the row-to-column delay. And if the SDRAM bank happens to have a different page open, instead of being idle, then you have to add the third number as well, the row precharge time.
So your 9-9-9-x DDR3 will take 27 cycles (at 800, not 1600 MHz!) to get the first word of data. That's 34 ns. Remember that number: DDR3-1600 CL9 has a maximum random read rate of 30 MHz!
And in real life, add wait time for the data bus to be free (another burst might be in progress), time for the memory controller to figure out what's it should do, etc.
It's probably not 100 cycles at 800 MHz, but it could easily be >100 cycles at 4 GHz.
If the RAM chip is lucky and has the page open, then only the CAS latency matters: 9 cycles at 1600 MHz is 4.5 CPU clock cycles.
To add to this, the command rate of DDR3 is the base rate, so in DDR3-800, it's 100MHz, in DDR3-1600, it's 200MHz. The T-number specifies how many commands can be issued per cycle, but it's typically T1.
Er... no. The T number is the number of cycles between asserting CS and sending a command (1T is faster than 2T), but after that, commands can be sent each cycle.
There's rarely a need to send more than 2 commands per burst (bank open, read w/ auto-precharge), but they can be sent at 800 MHz.
That's definitely true on modern CPUs. But the math was a lot different on an older CPU like a 68000. Consider the numbers:
CPU clock runs at 8 MHz
RAM is 150 ns
Average instructions per cycle: waaaaay lower than 1
To expand on that last point, this isn't some kind of superscalar architecture with pipelining or branch prediction or speculative execution. It has no hope of achieving more than one instruction per clock cycle like some modern CPUs can. Instead, a register-to-register integer ADD instruction takes 4 clock cycles. That's 500 ns for the fastest instruction in the book (and here's a version of the book)! And RAM is 150 ns. So you can pull stuff from RAM if you need it without really slowing down much if at all.
But yeah, multiply all those numbers by around 1000 and things change massively. On a 2 GHz processor, if you're adding things, you're hoping to get two ADD instructions done per ns. The speed of light compels you to forget about round trips to RAM that fast. So cache here we come.
To be precise, on a 68000, the minimum instruction time is 4 cycles per memory word accessed, and 2 of them are used for the access itself. So you have about 250 ns per access, and at most one access per 500 ns.
(A a lot of 68000 hardware, like the original Macintosh and Amiga, took advaage of this to multiplex memory between the processor and the video frame buffer.)
Exactly. A few instructions are a multiple of 2 cycles long but not a multiple of 4, and they can get the processor "out of step", in which case it has to wait an extra 2 cycles when accessing chip memory.
6
u/adrianmonk Oct 04 '13
And there was a time when it wasn't important at all. That same 20 or 25 years ago, many desktop processors simply didn't have a cache. For example, a Motorola 68000 had no data cache or instruction cache. (Later the Motorola 68010 came along with a very rudimentary kind of instruction cache that could only be used for "loop mode" and could only hold 2 instructions.)
They didn't have a cache mainly because they didn't need it. Memory ran at basically the same speed as the processor: you could run your processor at 8 MHz and your memory at 8 MHz too. On one of those old processors, main memory ran, in a relative sense, as fast as on-die cache runs today.
Now, processor cores run at 2 or 3 GHz but memory can't go that fast. And the speed of light isn't changing, so cache behavior gets more and more important.
So basically, 20 or 25 years ago, you needed to worry about instruction generation. Over time, that became almost irrelevant, but you started to have to worry about memory access patterns.