Skip to content

Computer Architecture

University Computer Science Topic 6 6:22 English narration · English and 中文 subtitles you can switch

space play · ←/→ 5s · j/l 10s · f fullscreen · c subtitles · ,/. speed

Chapters

Transcript
This course looks at the machine below the program, and how it earns its speed. 本课程探讨程序底层的机器,以及它如何实现高速运行。
The first two units are the contract, the instruction set, and the machine that honours it, the datapath. 前两个单元介绍约定,也就是指令集,以及遵守这一约定的机器,也就是数据通路。
The next two make it fast, with pipelining and the memory hierarchy. 接下来的两个单元介绍如何用流水线和存储层次结构提高速度。
The last two connect it, to input and output and to other processors. 最后两个单元介绍它如何连接输入输出设备和其他处理器。
Every timing claim is computed from stated parameters. 所有关于时间的结论都根据给定参数计算得出。
The instruction set is the stable contract between software and hardware. 指令集是软件和硬件之间稳定的约定。
Every instruction is 32 bits. 每条指令都是 32 位。
R-type instructions carry three registers and a function code; I-type instructions trade the third register for a 16-bit signed immediate, from minus 32,768 to 32,767, so 40,000 will not fit. R 型指令包含三个寄存器和一个功能码;I 型指令用一个 16 位有符号立即数代替第三个寄存器,取值范围从 -32,768 到 32,767,所以 40,000 无法装入。
Register zero is a wire that always reads zero. 零号寄存器相当于一根始终读出零的导线。
Read the fields first and the mnemonics second. 先看字段,再看助记符。
The R-type format splits its 32 bits into opcode, three register numbers, a shift amount and a function code. R 型格式将 32 位分为操作码、三个寄存器编号、移位量和功能码。
The I-type format keeps the opcode and two registers, then spends 16 bits on a constant. I 型格式保留操作码和两个寄存器,然后用 16 位存放常数。
Both formats are the same width, which keeps decoding simple and fast. 两种格式的宽度相同,这使译码简单而快速。
One shared datapath serves every instruction, and control bits choose the route. 所有指令共用一条数据通路,控制位决定具体路径。
A load walks the whole path: instruction memory, registers, ALU, data memory and write-back, 900 picoseconds in total. 加载指令要走完整条路径:指令存储器、寄存器、算术逻辑单元、数据存储器和写回,总共需要 900 皮秒。
Its control bits are register write 1, memory read 1, memory to register 1 and ALU source 1. 它的控制位分别是寄存器写入 1、存储器读取 1、存储器到寄存器 1,以及算术逻辑单元源 1。
In a single-cycle design, the clock must wait for this slowest instruction. 在单周期设计中,时钟必须等待这条最慢的指令完成。
Walk this single-cycle path and price it. 沿着这条单周期路径走一遍,计算它的耗时。
The program counter fetches an instruction, the registers are read, the ALU computes, data memory is touched if asked, and the result is written back while the next program counter is chosen. 程序计数器用于取指,接着读取寄存器,ALU 进行计算,需要时访问数据存储器,最后写回结果,同时选定下一个程序计数器的值。
Every instruction gets the same long clock cycle, so even a simple add waits as long as a load. 每条指令都使用同样长的时钟周期,所以即使是简单的加法,也要等待与加载指令一样长的时间。
The address in the program counter is copied to the memory address register, which sends it to memory. 程序计数器中的地址被复制到存储器地址寄存器,再由它发送给存储器。
The instruction returns to the memory data register, and is copied to the current instruction register. 指令返回到存储器数据寄存器,然后被复制到当前指令寄存器。
Meanwhile, the program counter is incremented, ready for the next fetch. 与此同时,程序计数器递增,为下一次取指做好准备。
Pipelining overlaps five stages like an assembly line. 流水线像装配线一样,让五个阶段重叠进行。
n instructions in k stages take n plus k minus 1 cycles: five instructions take 9, not 25. k 个阶段执行 n 条指令需要 n 加 k 减 1 个周期:五条指令需要 9 个周期,而不是 25 个。
The slowest stage sets the clock: 250 picoseconds instead of 900. 最慢的阶段决定时钟周期:250 皮秒,而不是 900 皮秒。
Forwarding removes most hazards, but a load followed by its use costs one stall, so a realistic CPI is about 1.13. 数据转发消除了大多数冒险,但加载指令后紧接着使用其结果会造成一次停顿,因此实际的每条指令周期数约为 1.13。
Count along the diagonal of this timeline. 沿着这条时间线的对角线数一数。
Each instruction starts one cycle after the one before, and moves through fetch, decode, execute, memory and write-back. 每条指令都比前一条晚一个周期开始,并依次经过取指、译码、执行、访存和写回。
The pipe fills once and drains once, so five instructions finish in 9 cycles. 流水线只需填满一次、排空一次,所以五条指令在 9 个周期内完成。
For a long program, almost one instruction completes every cycle. 对于长程序,几乎每个周期都能完成一条指令。
A cache splits each address into tag, index and offset. 高速缓存将每个地址分为标记、索引和偏移。
A 4 kilobyte cache with 16-byte lines has 256 lines, so 4 offset bits, 8 index bits and 20 tag bits. 一个容量为 4 千字节、缓存行大小为 16 字节的高速缓存有 256 行,因此需要 4 个偏移位、8 个索引位和 20 个标记位。
Average access time is 1 cycle plus the miss rate times the penalty: 2 per cent at 100 cycles gives 3. 平均访问时间等于 1 个周期加上缺失率乘以缺失代价:缺失率为 2%、缺失代价为 100 个周期时,结果是 3 个周期。
Walking memory row by row misses only one in four accesses. 按行遍历内存时,每四次访问只有一次缺失。
The cache geometry decides how the 32-bit address is split. 高速缓存的组织结构决定了如何划分 32 位 地址。
The line size sets the offset bits, the number of lines sets the index bits, and whatever remains is the tag. 缓存行大小决定偏移位数,缓存行数决定索引位数,剩下的就是标记。
For address 0x4A8, the offset is 8 and the line is 74. 对于地址 0x4A8,偏移是 8,行号是 74。
The tag stored in that line then tells you whether you have a hit. 该行中存储的标记会告诉你是否命中。
At the top of the pyramid are the registers, then cache, then RAM, then secondary storage at the base. 金字塔的顶端是寄存器,接着是高速缓存,然后是 RAM,底部是辅助存储器。
Towards the top, memory is faster, smaller and more expensive per byte; towards the base it is slower, larger and cheaper. 越往上,存储器速度越快、容量越小、每字节成本越高;越往下,速度越慢、容量越大、成本越低。
Each level holds the data the level above is most likely to need. 每一层都保存上一层最有可能需要的数据。
There are three ways to move a block of data. 传输一个数据块有三种方式。
Polling checks a flag over and over: about 8000 cycles of processor attention per word. 轮询反复检查标志位:每个字大约需要处理器花费 8000 个周期。
Interrupts cost about 200 cycles per word. 中断每个字大约需要 200 个周期。
Direct memory access, DMA, needs one setup and one completion for the whole block: under one cycle per word, nearly 300 times cheaper than interrupts. 直接存储器访问,即 DMA,整个数据块只需要一次设置和一次完成处理:平均每个字不到一个周期,开销比中断低近 300 倍。
Choose the method by the shape of the traffic. 根据数据流量的特点选择方法。
Polling burns the processor waiting, so use it only for things that must be sampled at fixed times. 轮询会让处理器消耗时间等待,所以只适用于必须在固定时间采样的情况。
Interrupts charge a fee per event, which suits occasional arrivals such as key presses. 中断对每个事件都有开销,适合按键等偶尔发生的事件。
DMA charges once per block, which suits streams such as disk or network transfers. DMA 每个数据块只产生一次开销,适合磁盘或网络传输这样的数据流。
Amdahl's law says the speedup is 1 over the serial part plus the parallel part divided by the number of processors. Amdahl 定律指出,加速比等于串行部分加上并行部分除以处理器数量,所得结果的倒数。
If 90 per cent is parallel, no machine can exceed 10 times. 如果 90% 的工作可并行,任何机器的加速比都不能超过 10 倍。
Eight processors give 4.71, and sixteen give only 6.40. 8 个处理器的加速比是 4.71,16 个处理器也只有 6.40。
Even with 99 per cent parallel, 99 processors give exactly 50 times. 即使 99% 的工作可并行,99 个处理器的加速比也恰好只有 50 倍。
The serial fraction dominates. 串行部分的比例起主导作用。
Every curve on this plot flattens out. 图中的每条曲线都逐渐趋于平缓。
Adding processors helps less and less, because the serial part never shrinks. 增加处理器的效果越来越小,因为串行部分始终不会缩短。
Only the parallel fraction f moves the ceiling, which is 1 over 1 minus f. 只有并行部分的比例 f 能改变上限,这个上限是 1 除以 1 减 f。
So before buying more cores, find and shrink the serial part of the program. 所以在购买更多核心之前,先找出并缩短程序中的串行部分。
Now test yourself from memory. 现在凭记忆自测。
What is the largest value a 16-bit signed immediate can hold? 16 位 有符号立即数能表示的最大值是多少?
How many cycles do five instructions take in a five-stage pipeline? 五级流水线执行五条指令需要多少个周期?
How many index bits does a 4 kilobyte cache with 16-byte lines need? 容量为 4 千字节、缓存行大小为 16 字节 的高速缓存需要多少个索引位?
What is the speedup ceiling when 90 per cent of the work is parallel? 当 90% 的工作可并行时,加速比的上限是多少?
Pause, answer, then check. 暂停,回答,然后核对。

Comments

    Log in or create account

    IGCSE, A-Level & AP