성능 모델링 — Amdahl·Gustafson·Roofline Model 적용
#한 줄 요약
Serial 부분이 한계를 결정합니다 (Amdahl). Memory bandwidth가 한계가 됩니다 (Roofline).
#Amdahl의 법칙 (1967)
한 부분을 빠르게 해도 전체 개선은 나머지 부분에 의해 제한됩니다.
여기서 는 병렬화(또는 최적화) 가능한 비율, 는 그 부분의 speedup입니다.
#예
전체 100 ms 코드 중:
- 90 ms는 병렬화가 가능합니다 (P = 0.9)
- 10 ms는 serial입니다 (P = 0.1)
병렬화로 90ms → 0ms ()가 되어도 다음과 같습니다.
아무리 빠르게 해도 10× 가 한계입니다. 100 코어를 써도 마찬가지입니다.
#시사점
- 작은 serial 부분이 큰 영향을 미칩니다.
- 최적화는 hot path에 집중해야 합니다.
- Profiler로 시간 사용 분포를 먼저 확인합니다.
#Gustafson의 법칙 (1988) — Amdahl 보완
Amdahl은 고정 문제 크기를 가정합니다. 실제로는 큰 컴퓨터엔 큰 문제가 주어집니다.
문제가 N배 커지면 parallel 부분도 N배가 되어 효과적 speedup이 커집니다.
HPC와 과학계산에 적용됩니다. 임베디드에서는 문제 크기가 고정이라 Amdahl이 우세합니다.
#Roofline Model
Operational Intensity (OI), Peak FLOPS, Memory Bandwidth로 상한선을 결정합니다.
각 알고리즘이 1 byte memory access마다 몇 FLOP을 하는지 나타냅니다.
#Roofline 그래프
알고리즘의 OI가 ridge point보다 작으면 Memory-bound입니다. 알고리즘의 OI가 ridge point 이상이면 Compute-bound입니다.
#예 — STREAM Triad
for (i = 0; i < N; i++) a[i] = b[i] + c[i] * d;- 3 byte load와 1 byte store (assuming 1 byte per element)
- 2 FLOP (mul + add)
- OI = 2/16 = 0.125 FLOP/byte (assuming float = 4 byte, total 16 byte/iter)
Memory-bound입니다. 더 빠른 CPU는 의미가 없습니다. 메모리 BW를 늘리거나 cache locality를 개선해야 합니다.
#예 — Matrix Multiplication (Naive)
for (i) for (j) for (k) C[i][j] += A[i][k] * B[k][j];- 2 byte load + 1 store = 3 byte
- 2 FLOP
- OI = 2/12 = 0.17 (cold cache)
Naive matmul도 memory-bound입니다. Blocking·tiling으로 OI를 키우면 compute-bound 영역으로 옮길 수 있습니다.
#Roofline 활용
- 알고리즘의 OI를 계산합니다.
- CPU의 peak FLOPS와 memory BW를 확인합니다.
- Ridge point와 비교해 bound를 식별합니다.
- Memory-bound면 cache, prefetch, blocking을 활용합니다.
- Compute-bound면 SIMD, SMT, algorithm 개선을 시도합니다.
#Little’s Law
여기서 은 평균 in-system 수, 는 도착률, 는 평균 system 시간입니다.
concurrency 한계를 분석할 때 활용합니다.
DRAM access latency 100 ns 동안 1 KB pipeline을 채워야 최대 BW에 도달합니다.
#Universal Scalability Law (USL)
Neil Gunther가 제안했습니다. Amdahl에 coherency cost를 추가한 모델입니다.
여기서 는 contention, 는 coherency입니다.
- 가 큰 시스템은 적은 코어에서 plateau에 도달합니다.
- 가 큰 시스템은 적정 코어 수를 넘으면 *역효과 (negative scalability)*가 발생합니다.
Multicore는 무한히 scale되지 않습니다. Optimal core count가 존재합니다.
#임베디드 — Cycle Budgeting
1 ms PID @ 168 MHz Cortex-M4:Total cycles: 168,000
Allocation:- ISR latency: 200 cycle (0.1%)- Sensor read: 30,000 cycle (18%)- PID compute: 5,000 cycle (3%)- Filter: 10,000 cycle (6%)- Actuator write: 5,000 cycle (3%)Used: 50,200 cycle (30%)Free: 117,800 cycle (70%)각 컴포넌트에 cycle budget을 할당하고, 초과 시 해당 컴포넌트를 최적화합니다.
#Speedup Saturation
Multi-core 임베디드 (Cortex-A SMP)에서는 다음과 같습니다.
1 core: 100 ms2 core: 60 ms (1.67× — 좋음)4 core: 40 ms (2.5× — 감소)8 core: 35 ms (2.86× — 거의 한계)Cache와 bus contention 증가로 diminishing returns가 나타납니다.
#인터프리터 모델
Performance = Best of (memory, compute, control).
각 path가 독립적 maximum을 가집니다. 한 path가 saturate 되어도 다른 path는 idle일 수 있습니다.
OoO CPU의 ILP, MLP, TLP가 이걸 활용합니다.
#자주 하는 실수
⚠️ 모든 작업 병렬화 가정
Amdahl 법칙에서 작은 serial 부분이 한계를 결정합니다. 측정 후 분포 확인이 필요합니다.
⚠️ Memory-bound 코드를 CPU 최적화
Cache miss가 90% 시간을 차지하면 SIMD나 intrinsics는 의미가 없습니다. DRAM access를 줄여야 합니다.
⚠️ Roofline 무시
알고리즘 OI를 모르면 어디에 최적화 노력을 들일지 알 수 없습니다.
⚠️ Multicore 무조건 scale
USL의 coherency cost 때문에 2-4 core에서 plateau가 흔합니다.
#정리
- Amdahl: — serial 부분이 한계가 됩니다.
- Gustafson: 문제 크기 scaling 시 더 낙관적입니다.
- Roofline: OI, peak FLOPS, memory BW로 bound를 식별합니다.
- Little’s Law: BW × latency = bytes in flight입니다.
- USL: Multicore의 coherency cost로 무한 scale은 불가능합니다.
- 임베디드에서는 cycle budget으로 컴포넌트를 관리합니다.
다음 편은 프로파일링 개요입니다. Sampling과 Instrumentation을 비교합니다.
#관련 항목
Embedded Performance Engineering · 8 of 57
- 1Embedded Performance Engineering — 임베디드 성능 엔지니어링 시리즈 소개
- 2임베디드 성능 분석 방법론 — Measure → Analyze → Optimize 사이클
- 3성능 지표 정의 — Latency·Throughput·Utilization 분석
- 4성능 측정의 기본 — Wall-Clock·CPU Cycle·Instruction Count
- 5성능 데이터 통계적 분석 — Percentile·Histogram·평균의 함정
- 6실시간 성능 분석 — WCET·Jitter·Deadline Miss 측정
- 7임베디드 벤치마킹 기초 — 재현성·Warmup·노이즈 제거
- 8성능 모델링 — Amdahl·Gustafson·Roofline Model 적용
- 9프로파일링 기법 개요 — Sampling vs Instrumentation·PGO·LTO
- 10CPU 파이프라인 분석 — 5-stage·Cortex-M·Cortex-A 비교
- 11Pipeline Stall 분석 — Data·Structural·Control Hazard·Forwarding
- 12Branch Prediction 분석 — Static·2-bit·BTB·BHT·Mispredict 비용
- 13Speculative Execution 분석 — OoO·Reorder Buffer·Register Renaming
- 14CPU Cache 기초 — L1·L2·L3·Set Associative·Replacement Policy
- 15Cache Miss 3C Model 분석 — Compulsory·Capacity·Conflict
- 16Cache Line 최적화 — Alignment·Prefetch·False Sharing 처리
- 17메모리 대역폭 분석 — STREAM·Roofline·Bus Saturation 측정
- 18SIMD·NEON 활용 — 128-bit Vector·Auto-Vectorization·SVE/SVE2
- 19PMU·HPM 하드웨어 카운터 분석 — 정밀 성능 진단
- 20임베디드 Bus Architecture — AHB·AXI·CHI 진화와 5-Channel
- 21Bus Contention 진단 — Arbitration·QoS·Starvation 측정
- 22DMA 성능 최적화 — Burst·Scatter-Gather·Chain·Cache 일관성
- 23DMA vs CPU Copy 성능 비교 — Break-even·Setup Overhead 실측
- 24Interrupt Latency 분석 — 진입·종료·Tail-Chaining·Late Arrival
- 25Interrupt Storm 처리 — NAPI·Rate-Limit·Polling 전환
- 26MMIO 접근 성능 — Cache Policy·Write-Combining·Volatile·Barrier
- 27Peripheral Clock 분석 — PLL·Divider·Gating·DVFS
- 28Power vs Performance 트레이드오프 — DVFS·Race-to-Idle·Big.LITTLE
- 29Thermal Throttling 분석 — Junction Temp·Trip Point·냉각
- 30CXL Interconnect 분석 — AI 시대 메모리 대역폭 확장
- 31Concurrency 기초 — Concurrency vs Parallelism·Race·Memory Model
- 32False Sharing 진단 — Cache Line Ping-Pong·Padding·측정
- 33Lock Contention 분석 — Wait·Hold·Convoy·측정 기법
- 34Spinlock 성능 분석 — Spin-Wait vs Context Switch·Ticket·MCS
- 35Mutex 성능 분석 — Futex·Adaptive·Priority Inheritance
- 36Reader-Writer Lock 성능 — Reader/Writer Priority·RCU·Seqlock
- 37Lock-Free 자료구조 성능 — CAS·ABA·Hazard Pointer·Epoch Reclamation
- 38Memory Ordering 분석 — Acquire·Release·Seq-Cst·ARM Relaxed Model
- 39Cache Coherency 프로토콜 — MESI·MOESI·Snoop·Directory
- 40SMP 성능 분석 — Per-Core·Affinity·Load Balance·Scalability
- 41Linux perf 기초 — stat·record·report 활용
- 42Linux perf 고급 — Raw Event·Tracepoint·perf script
- 43ftrace 활용 — function·function_graph·latency tracer
- 44eBPF·bpftrace 동적 트레이싱 — 커널 무수정 관측
- 45Flamegraph 분석 — On-CPU·Off-CPU·Differential
- 46ARM DS·Lauterbach 분석 — Hardware Trace 전문 도구
- 47Bare-metal 프로파일링 — GPIO·DWT·SysTick·ITM 활용
- 48NVIDIA Nsight Systems — GPU·NPU 포함 시스템 분석
- 49모던 프로파일러 비교 — Tracy·Hotspot·uftrace·Coz
- 50연속 프로파일링 — Parca·Pixie·Pyroscope·Tetragon
- 51실전 사례 — ISR Latency 100µs Deadline Miss 추적
- 52실전 사례 — Matrix Multiply가 예상의 10배 느린 이유
- 53실전 사례 — 8-core가 4-core를 넘으면 throughput이 떨어지는 이유
- 54실전 사례 — 카메라 1080p 60fps가 30fps로 떨어지는 이유
- 55CXL.mem 지연·대역폭 실측 — Direct·Switch·Pooled 토폴로지 비교
- 56CXL 성능 프로파일링 도구 — cxl-cli·DAMON·perf-mem 활용
- 57실전 사례 — CXL.mem 추가로 LLM inference KV cache 처리량 회복
관련 글
메모리 대역폭 분석 — STREAM·Roofline·Bus Saturation 측정
STREAM benchmark (Copy·Scale·Add·Triad). Roofline. PMU BUS_ACCESS · DDR bandwidth.
실전 사례 — CXL.mem 추가로 LLM inference KV cache 처리량 회복
70B 모델 KV cache가 HBM 한계를 넘어 throughput이 무너졌을 때, CXL.mem 256 GB pool 추가로 회복한 실전 케이스.
CXL 성능 프로파일링 도구 — cxl-cli·DAMON·perf-mem 활용
CXL.mem 환경 성능 도구 — cxl-cli 토폴로지·DAMON page activity·perf-mem로 보는 CXL 트래픽·numastat 통계.
이 글을 참조하는 글 (5)
- 실전 사례 — CXL.mem 추가로 LLM inference KV cache 처리량 회복— Embedded Performance Engineering
- Ch 15: RAS·Performance·Compliance — 운용·검증의 마지막 단계— CXL 4.0 Internals
- 프로파일링 기법 개요 — Sampling vs Instrumentation·PGO·LTO— Embedded Performance Engineering
- 임베디드 벤치마킹 기초 — 재현성·Warmup·노이즈 제거— Embedded Performance Engineering
- 임베디드 성능 분석 방법론 — Measure → Analyze → Optimize 사이클— Embedded Performance Engineering