자막
음성

Lec 5 · Exception 처리, R4000, static scheduling 과 decoupled execution

정밀 정리 · 검증 2026-09-24 00:06

1개요

1.104강 덱 뒷부분: exception·interrupt·trap 정의, precise interrupt, trap handler, 5-stage pipeline 의 exception 처리와 speculation 관점.
1.2MIPS R4000 8-stage pipeline(load-use, branch, FP)과 SPEC92 CPI 분석.
1.305강 덱: static scheduling(재배치, loop unrolling)과 decoupled execution, IBM Stretch·CDC 6600, complex pipeline 동기 (p18 까지, p19~38 은 다음 강의).

2섹션별 정리 상황·문제 → 원인 → 해결

2.10:31–2:02공지: project proposal 마감
상황·문제project proposal 은 이번 수요일까지 PDF 로 이메일 제출. 지난 강의 basic pipelining 에 이어 exception 부터 시작.
p.42
2.1.1 · p.42 · 0:31 · Exceptions 절 표지 (04강 마지막 쪽에서 이어짐)
2.22:02–4:42exception·interrupt·trap 용어 정의
상황·문제pipeline 실행 중 예상 밖 상황을 exception, trap, interrupt 로 부르는데 가리키는 대상이 다르다.
원인exception = program 실행 중 생기는 내부 이벤트(page fault, arithmetic overflow/underflow). 무엇이 exception 인지는 ISA 정의에 따름 (RISC-V 는 overflow 가 exception 이 아님).
해결interrupt = 외부 장치(keyboard, mouse, disk, network card) 신호. trap = exception·interrupt 로 supervisor(OS·hypervisor) 로 제어가 넘어가는 것. IEEE 754 floating point 예외처럼 trap 을 안 일으키는 경우는 FPU status 를 직접 확인.
  • exception: 내부·program 원인, interrupt: 외부 장치 원인
  • trap: supervisor 로의 control transfer
  • floating point divide-by-zero 는 반드시 trap 이 아님 → FPU status 확인
p.43
2.2.1 · p.43 · 2:12
2.2.r.1Interrupt — Wikipedia ↗ · hardware interrupt(비동기) vs fault/trap(동기) 구분
2.2.r.2IEEE 754 — Wikipedia ↗ · Exception handling 절: 5개 exception 과 status flag, 기본은 trap 없이 기본값 반환
2.34:42–7:32exception 처리의 역사: Analytical Engine → UNIVAC → DYSEAC
상황·문제초기 컴퓨터는 overflow 같은 예외와 I/O 이벤트를 어떻게 처리했나.
원인Babbage 의 Analytical Engine 에도 overflow exception 이 있었고, 첫 trap 시스템은 UNIVAC-I(1951): overflow 시 주소 0 의 2-instruction fix-up routine 실행 또는 정지.
해결후속 UNIVAC 에 external interrupt 추가(실시간 wind tunnel data). DYSEAC(1954) 는 첫 I/O interrupt 시스템: PC 2개(정상용·I/O 처리용), DMA 지원, 트럭 2대(20 ton)로 옮긴 미 육군용 이동식 컴퓨터.
  • UNIVAC-I 1951: 첫 trap
  • DYSEAC 1954: 첫 I/O interrupt, PC 2개, DMA
  • DYSEAC 는 tractor trailer 2대로 이동 (mobile computer)
p.44
2.3.1 · p.44 · 4:55
p.45
2.3.2 · p.45 · 6:57
2.3.r.1History of interrupts — Mark Smotherman (Clemson) ↗ · 슬라이드 출처. UNIVAC 1103, DYSEAC 첫 I/O interrupt 등 연대기
2.3.r.2DYSEAC — Wikipedia ↗ · 트럭에 실린 이동식 컴퓨터, 첫 I/O interrupt 구현
2.47:32–11:17asynchronous interrupt 와 precise interrupt
상황·문제I/O 장치가 priority 가 있는 interrupt request line 을 올리면 processor 가 실행 중인 program 을 멈추고 handler 로 가야 한다.
원인어디서 멈췄는지가 명확해야 handler 뒤에 정상 실행을 재개할 수 있다.
해결instruction Ii 에서 멈추고 Ii-1 까지 모두 완료, Ii 이후는 실행 안 된 것처럼 보이게 함 (precise interrupt). Ii 의 PC 를 EPC 에 저장, interrupt 를 끄고 supervisor mode 의 handler 로 점프, 끝나면 Ii 로 복귀.
  • higher priority line 이 먼저 처리
  • precise interrupt: Ii-1 까지 commit, Ii 이후 효과 없음
  • EPC = 중단된 instruction 의 PC
p.46
2.4.1 · p.46 · 7:29
p.47
2.4.2 · p.47 · 10:04
2.4.r.1Interrupt — Wikipedia ↗ · precise interrupt 정의와 조건
2.511:17–15:09trap handler: EPC 저장, masking, cause, ERET
상황·문제handler 실행 중에 또 interrupt 가 오면 EPC 가 덮여 원래 복귀 주소를 잃는다.
원인EPC 는 special register 라 일반 instruction 으로 접근 불가. lower priority interrupt 가 계속 오면 deadlock 가능.
해결privileged instruction 으로 EPC 를 GPR 로 옮겨 memory 에 저장한 뒤 interrupt 재허용(nested interrupt). 그동안 lower priority interrupt 는 mask. status(cause) register 로 원인 확인, ERET 로 interrupt 재허용·user mode 복귀·상태 복원.
  • EPC → GPR 이동은 privileged instruction
  • 저장 전까지 lower priority interrupt masking
  • ERET: interrupt enable + user mode 복귀
p.48
2.5.1 · p.48 · 11:17
2.615:09–18:27synchronous trap: page fault 와 system call
상황·문제특정 instruction 이 일으키는 exception (예: page table 에 없는 주소를 load → page fault).
원인그 instruction 은 완료될 수 없고, 뒤에 부분 실행된 instruction 의 효과도 되돌려야 한다.
해결handler 후 원인 instruction 에서 재시작 (접근 권한 위반이면 program 을 kill). 단 system call trap(printf 등)은 instruction 이 완료된 것으로 보고 다음 instruction 에서 재개 — 아니면 system call 을 무한 반복.
  • page fault: 원인 instruction 부터 재실행
  • 부분 실행된 후속 instruction 은 undo
  • system call: 완료 간주, 특권 모드 변경하는 jump
p.49
2.6.1 · p.49 · 15:15
2.718:27–25:395-stage pipeline 에서의 exception 처리
상황·문제IF(PC address exception), ID(illegal opcode), EX(overflow), MEM(data address exception) 각 stage 에서 exception 이 동시에 날 수 있고, asynchronous interrupt 도 들어온다.
원인앞선 instruction 은 정상 완료시키고, 뒤 instruction 은 없던 일로 만들어야 precise 하게 handler 로 갈 수 있다.
해결exception flag·PC 를 pipeline latch 로 commit point(M stage) 까지 전달. 한 instruction 에선 앞 stage 의 exception 이 우선. async interrupt 는 commit point 에 주입. commit 에서 trap 이면 Cause·EPC 갱신, 모든 stage kill, handler PC 를 fetch 에 주입.
  • exception 은 commit point 에서만 처리
  • earlier stage exception 이 later stage exception 을 override
  • async interrupt 는 commit point 에 inject
p.50
2.7.1 · p.50 · 18:27
p.51
2.7.2 · p.51 · 21:14
p.52
2.7.3 · p.52 · 23:29
2.7.r.1Classic RISC pipeline — Wikipedia ↗ · Exceptions 절: 5-stage pipeline 에서 exception 처리
2.825:39–30:31exception 을 speculation 으로 보기
상황·문제fetch 시점에는 그 instruction 이 나중에(예: MEM 의 page fault) exception 을 낼지 모른다.
원인그래도 실행을 계속하는 것은 '예외 없음' 을 예측하는 speculation. exception 은 드물고 I/O 는 processor 에 비해 매우 느려 예측이 거의 맞다.
해결예측 확인은 pipeline 끝에서, 복구는 architectural state 를 commit point 에서만 갱신해 부분 실행분을 버리고 flush 후 handler 시작. 결과는 bypass(forwarding)로 후속 instruction 이 쓰므로 성능 손해 없음.
  • prediction: no exception (매우 정확)
  • check: pipeline 끝에서 exception 감지
  • recovery: commit point 에서만 state 갱신 → flush
p.53
2.8.1 · p.53 · 25:39
2.8.r.1Speculative execution — Wikipedia ↗ · speculation 과 잘못된 경우의 되돌림 개념
2.930:31–35:41MIPS R4000: 8-stage pipeline 과 load-use delay
상황·문제memory access 를 1 cycle 로 두면 clock frequency 를 희생해야 한다.
원인R4000 은 I-cache·D-cache 접근을 여러 cycle 로 나눠 8 stage(IF IS RF EX DF DS TC WB). cache 접근은 3 cycle.
해결direct-mapped cache 라 tag check 전에 데이터를 쓸 수 있음: I-cache tag check 는 RF 에서 decode 와 병렬, D-cache 는 DS 끝에 데이터를 ALU 로 forward 하고 TC 에서 tag check. miss 면 kill/bubble 후 재실행. set-associative 면 더 까다로움.
  • 8 stage: memory 접근을 여러 stage 로 쪼갬
  • direct-mapped: tag check 와 데이터 사용을 병렬
  • miss 면 한 cycle back up / bubble 삽입
p.54
2.9.1 · p.54 · 30:35
p.55
2.9.2 · p.55 · 34:57
2.9.r.1R4000 — Wikipedia ↗ · 8-stage superpipelined integer pipeline
2.9.r.2Cache placement policies — Wikipedia ↗ · direct-mapped vs set-associative, tag 비교
2.1035:41–40:18R4000 branch 와 floating point pipeline
상황·문제branch 조건이 EX 에서 결정되어 3 cycle branch delay.
원인1개는 branch delay slot(항상 실행), 나머지 2개는 predict not-taken 으로 추측 → 틀리면 kill. 이후 MIPS 는 dynamic branch prediction 도입.
해결FPU 는 variable latency: 단순 연산 2~4 cycle, multiply/divide/sqrt 는 훨씬 김. initiation interval 때문에 divide 는 35 cycle, sqrt 는 111 cycle 후에야 다음 발행. S+A 는 두 stage 동시 사용, D28 은 D stage 28회 반복, 같은 stage 충돌 시 structural hazard stall.
  • 3-cycle branch delay = 1 delay slot + 2 predict-not-taken
  • FP divide 다음 발행까지 35 cycle, sqrt 111 cycle
  • S+A 표기, superscript = 반복 횟수
p.56
2.10.1 · p.56 · 35:38
p.57
2.10.2 · p.57 · 37:15
2.10.r.1Delay slot — Wikipedia ↗ · MIPS 의 single branch delay slot
2.1140:18–44:10R4000 SPEC92 CPI 분석
상황·문제perfect cache 가정에서 SPEC92 정수 5개·FP 5개의 pipeline CPI 를 stall 원인별로 분해.
원인base CPI 1 위에 load stall(직전 load 의존, forwarding 불가), branch stall, FP result stall(FP RAW), FP structural stall 이 더해짐.
해결정수 program 은 branch stall 이, FP program 은 FP result stall 이 주된 CPI 기여. 그림들은 교재 Appendix C 에서 가져옴.
  • single-issue 는 CPI 1 이 한계
  • integer: branch stall 우세
  • FP: result stall 우세
p.58
2.11.1 · p.58 · 40:16
2.11.r.1Computer Architecture: A Quantitative Approach, 6th ed. — Elsevier ↗ · R4000 그림(Figure C.36–C.47)과 SPEC92 결과의 출처 Appendix C
2.1244:10–53:15static instruction scheduling: 재배치와 loop unrolling
상황·문제vector add loop(fld×2, fadd.d, fsd, addi×3, bne)를 그대로 쓰면 긴 latency load 때문에 stall 이 생긴다.
원인scheduling 은 static(programmer·compiler) 과 dynamic(hardware) 두 가지. 한 iteration 안에는 병렬성이 적다.
해결독립인 pointer 증가 addi 를 load 뒤로 끌어올려 latency 를 가림 (fsd offset 은 -8). loop unrolling(2회) 으로 load 4, fadd 2, fsd 2 에 pointer 증가 16 → 병렬성 증가, dynamic instruction 수·branch 수 감소. 한계: architectural register 수(spill), I-cache footprint 증가, compiler 복잡도. software pipelining 도 비슷한 문제.
  • independent instruction 재배치로 load latency hiding
  • unrolling: pointer bump·branch 가 줄어 dynamic instruction count 감소
  • register spill·I-cache miss 로 오히려 느려질 수 있음
p.1
2.12.1 · p.1 · 44:10
p.3
2.12.2 · p.3 · 45:14
p.4
2.12.3 · p.4 · 47:23
p.5
2.12.4 · p.5 · 49:00
2.12.r.1Loop unrolling — Wikipedia ↗ · 장점과 register pressure·code size 증가 단점
2.12.r.2Software pipelining — Wikipedia ↗ · compiler 가 loop iteration 을 겹치는 기법
2.1353:15–1:01:08decoupled execution: memory access 와 computation 분리
상황·문제static scheduling 대신 microarchitecture 로 program 에 내재한 병렬성을 끌어낼 수 없나.
원인control·address 계산(addi, bne, load 주소)은 data 계산(fadd)에 의존하지 않아 먼저 진행할 수 있다.
해결integer pipeline 이 주소·branch 를 처리하고 load 를 memory 로 보냄, 데이터는 load data queue 로. fld/fadd/fsd 는 µop(load data writeback, compute, store data read)으로 µop queue 에 넣어 FP pipeline 이 데이터 도착 시 실행. load 는 store address queue 와 비교해 일치하면 store data queue 에서 값을 받음.
  • integer pipeline(주소·branch) ↔ FP pipeline(계산) 분리
  • queue: µop, load data, store address, store data
  • load address check: 앞선 store 와 주소 일치 확인
p.6
2.13.1 · p.6 · 53:15
p.7
2.13.2 · p.7 · 54:57
p.8
2.13.3 · p.8 · 57:14
2.13.r.1Decoupled architecture — Wikipedia ↗ · James Smith 의 decoupled access/execute 개념
2.141:01:08–1:03:16IBM 7030 Stretch
상황·문제decoupled execution 을 쓴 초기 기계의 사례.
원인목표는 IBM 704 대비 100배. 4-stage lookahead pipeline 으로 indexing·branch 를 data 연산보다 앞서 speculative 하게 실행, 단순 store buffer 보유.
해결실제 성능은 30배에 그쳐 고객 불만, 초기 납품 후 철수. 하지만 개발 기술은 이후 IBM 기계로 이전.
  • 목표 100× vs 실제 30× (IBM 704 대비)
  • lookahead = indexing·branch 선행 (decoupling)
  • 기술은 후속 IBM 기계로 이어짐
p.9
2.14.1 · p.9 · 1:01:09
2.14.r.1IBM 7030 Stretch — Wikipedia ↗ · 100× 목표, 30× 실측, 가격 인하 경위
2.14.r.2IBM Stretch lookahead — Mark Smotherman ↗ · Stretch 의 lookahead 구조 상세
2.151:03:16–1:14:27supercomputer 와 CDC 6600
상황·문제supercomputer 는 주어진 문제에서 가장 빠른 기계. top500.org 는 LINPACK 을 제출한 기계만 등재 (Google data center 는 없음). compute-bound 문제가 I/O-bound 로 바뀜.
원인Seymour Cray 의 CDC 6600(1964)이 첫 supercomputer 로 간주: 60-bit word, 128K word memory 32 bank, 10 functional unit(비pipeline), hardwired control, scoreboard 로 dynamic scheduling, I/O 용 peripheral processor 10개, 10 MHz, 750 ft², 5 ton, 150 kW.
해결load/store architecture(초기 RISC 형태): X 8개(60-bit), A 8개, B 8개. A1~A5 갱신 시 load, A6~A7 갱신 시 store 가 시작 → address/data register 분리로 decoupled 하게 다수의 outstanding load. IBM Watson 메모('청소부 포함 34명')에 Cray: '스스로 답했다'.
  • CDC 6600: scoreboard, hardwired control, 10 FU
  • A1–A5 쓰기 → load, A6–A7 쓰기 → store
  • 7600 전까지 5년간 세계 최고속
p.10
2.15.1 · p.10 · 1:03:22
p.11
2.15.2 · p.11 · 1:06:56
p.12
2.15.3 · p.12 · 1:08:49
p.14
2.15.4 · p.14 · 1:11:04
p.16
2.15.5 · p.16 · 1:14:03
2.15.r.1CDC 6600 — Wikipedia ↗ · Cray 설계, scoreboard, peripheral processor, Watson 메모
2.15.r.2Scoreboarding — Wikipedia ↗ · CDC 6600 에서 처음 쓴 dynamic scheduling
2.15.r.3TOP500 ↗ · HPL(LINPACK) 기준 supercomputer 순위
2.161:14:27–1:16:59complex pipeline 의 동기 (다음 강의 예고)
상황·문제오늘날 processor 는 decoupled 대신 functional unit 이 많은 단일 pipeline 에서 dynamic scheduling 으로 ILP 를 뽑는다.
원인long-latency load·FP unit, 가변·예측 불가 memory latency, 다수의 arithmetic·memory unit 이 pipeline 을 복잡하게 만든다.
해결execute·write-back stage 의 structural conflict, out-of-order write hazard, exception 처리 문제를 다음 강의(수요일)에서 계속. proposal 은 수요일까지 이메일 제출.
  • complex pipeline 동기: long/variable latency, 다수 unit
  • issue: structural conflict, OoO write hazard, exception
p.17
2.16.1 · p.17 · 1:14:25
p.18
2.16.2 · p.18 · 1:16:24
2.16.r.1Hazard (computer architecture) — Wikipedia ↗ · structural·data(RAW/WAR/WAW) hazard 정리

3핵심 개념

3.1precise interrupt(정확한 인터럽트)
Ii-1 까지 모두 완료, Ii 이후는 실행 안 된 상태로 handler 에 진입.
3.2EPC(exception program counter)
중단된 instruction 의 PC 를 저장하는 special register. nested interrupt 전에 memory 로 저장.
3.3ERET
handler 복귀용 특수 jump. interrupt 재허용, user mode 복귀.
3.4synchronous trap(동기 트랩)
특정 instruction 이 일으킴(page fault). system call 은 완료로 간주.
3.5commit point(커밋 지점)
architectural state 를 갱신하는 지점. exception·interrupt 를 여기서 처리.
3.6loop unrolling(루프 전개)
여러 iteration 을 한 번에 → 병렬성↑, branch·pointer 갱신↓. register·I-cache 부담.
3.7decoupled execution(분리 실행)
주소·control 계산과 data 계산을 queue 로 분리된 pipeline 에서 실행.
3.8scoreboard(스코어보드)
CDC 6600 의 instruction 의존성 검사·dynamic scheduling 장치.

4스스로 확인

4.1exception, interrupt, trap 의 차이는?
답
exception 은 program 내부 원인, interrupt 는 외부 장치 원인, trap 은 둘로 인한 supervisor 로의 제어 이동.
4.2page fault 와 system call 은 handler 후 어디서 재개하나?
답
page fault 는 원인 instruction 부터 재실행, system call 은 완료로 보고 다음 instruction 부터.
4.3여러 stage 에서 동시에 exception 이 나면?
답
commit point 에서 가장 오래된(앞선) instruction 의 exception 을 처리하고 나머지는 kill.
4.4state 를 commit point 에서만 갱신해도 성능이 괜찮은 이유는?
답
bypass(forwarding)로 후속 instruction 이 미커밋 결과를 바로 쓰기 때문.
4.5R4000 이 tag check 전에 데이터를 쓸 수 있는 이유는?
답
direct-mapped cache 라 읽을 line 이 하나뿐. miss 면 뒤에 undo.
4.6loop unrolling 이 dynamic instruction 수를 줄이는 이유와 한계는?
답
pointer 증가·branch 가 iteration 수만큼 줄어듦. register spill, I-cache footprint, compiler 복잡도.

5참고 자료

5.1Computer Architecture: A Quantitative Approach, 6th ed. — Elsevier ↗ · 교재. R4000 은 Appendix C, 05강 권장 읽기 Chapter 3.2 & C.7
5.2History of interrupts — Mark Smotherman ↗ · interrupt 의 역사 전반

7한국어판 강의자료

단축키
Ctrl K · s자료 검색
[ ]이전·다음 강의
Space영상 재생·정지
j k다음·이전 section
n p다음·이전 slide
b강의 목록 접기·펴기
t맨 위
/강의 검색
Esc닫기