Chapter 12: Multiprocessor Systems

Chapter 12: Multiprocessor Systems · Study Questions
Amdahl's lawNUMAOmega networkMESIFalse sharingTicket lockGang schedulingHypercubeRPCVirtualizationDistributed systems
Sercan KÜLCÜ

Output Question · Introduction

Question 1: The Limit of Adding Cores

80% of a program's running time can be parallelized and 20% must stay sequential.

  1. What is the speedup on 8 cores?
  2. What is the maximum speedup as the number of cores goes to infinity?
  3. How many cores are needed for a 4x speedup?
  4. What would the speedup be on 32 cores if the parallel part were 90%?
Show answer

Amdahl: S(n) = 1 / ((1 − p) + p / n), p = 0.8.

(a) 1 / (0.2 + 0.1) = 3.33.

(b) p / n → 0: 1 / 0.2 = 5.

(c) 0.2 + 0.8 / n = 0.25 → 0.8 / n = 0.05 → n = 16: going from 8 to 16 cores only takes you from 3.33 to 4.

(d) 1 / (0.1 + 0.9 / 32) = 1 / 0.128 ≈ 7.8 (ceiling 10).

The sequential part sets the ceiling; that is why, as core counts grow instead of clock speeds, enlarging the parallel part of the software matters so much.

Multiple Choice · Multiprocessor Hardware

Question 2: Why Does Memory Access Time Vary?

On a two-socket server, a thread reads memory attached to its own socket in 80 ns and memory of the other socket in 140 ns; both memories are reached with ordinary LOAD/STORE instructions. What is this architecture called?

C: In NUMA all CPUs see one address space and reach remote memory with ordinary instructions; only the time depends on which node holds the memory. That is why the OS tries to keep a process and its pages on the same node (first touch, automatic NUMA balancing). In a multicomputer, memory is not shared.

Output Question · Multiprocessor Hardware

Question 3: Average Latency on NUMA

On a NUMA system, a local memory access takes 80 ns and a remote one takes 200 ns.

  1. What is the average access time if 85% of a thread's accesses are local?
  2. What if the ratio drops to 40% because the scheduler moved the thread to another node?
  3. What can the operating system do to avoid this loss?
Show answer

Average = f · tlocal + (1 − f) · tremote.

(a) 0.85 × 80 + 0.15 × 200 = 68 + 30 = 98 ns.

(b) 0.40 × 80 + 0.60 × 200 = 32 + 120 = 152 ns: about 55% slower.

(c) Keep the thread on the node that holds its data (affinity, balancing load within a node first) or move the pages next to the thread (Linux automatic NUMA balancing); on the application side, bind with numactl.

Output Question · Multiprocessor Hardware

Question 4: Crossbar and Omega Network

n CPUs are to be connected to n memory modules.

  1. For n = 16 and n = 128, how many crosspoints does a crossbar need, and how many 2 × 2 switches does an omega network need?
  2. In an 8 × 8 omega network, CPU 101 wants to reach memory 010. Which switch output (upper/lower) is used at each stage?
  3. What does the omega network pay for this saving?
Show answer
ncrossbar n²omega (n/2)·log₂n
162568 × 4 = 32
12816.38464 × 7 = 448

(b) Each stage looks at one bit of the destination address (left to right): 0 → upper, 1 → lower. Destination 010: stage 1 upper, stage 2 lower, stage 3 upper. The source address plays no part in routing; the switches record the source bits so the reply can return.

(c) The omega network is blocking: if two requests want the same switch output, one waits; each request also passes through log₂n stages, so latency grows. The crossbar is non-blocking, but its cost grows as n².

Step-by-Step Trace · Multiprocessor Hardware

Question 5: Tracing MESI States

In a three-core system the following accesses are made in order to the same cache line (x). After each step, in which MESI state is the line in each of the three caches? How many invalidations are needed?

C0 cacheI—C1 cacheI—C2 cacheI—busmemory: fresh

Initially x = 0 is only in memory; the line is I (invalid) in all three caches.

C0 cacheEx=0C1 cacheI—C2 cacheI—busmemory: fresh

C0 reads: BusRd, no other copy → fetched from memory, E (exclusive and clean).

C0 cacheSx=0C1 cacheSx=0C2 cacheI—busmemory: fresh

C1 reads: C0 snoops the request and says “I have it” → both are S. Memory is still fresh.

C0 cacheI—C1 cacheMx=1C2 cacheI—busmemory: stale

C1 writes: to write a line that is in S, an invalidation is broadcast → C0 goes to I, C1 to M; memory is now stale. (Invalidation 1)

C0 cacheSx=1C1 cacheSx=1C2 cacheI—busmemory: fresh

C0 reads: miss. C1 supplies the dirty line and writes it back to memory → both are S, memory is fresh.

C0 cacheI—C1 cacheI—C2 cacheMx=2busmemory: stale

C2 writes: it does not have the line; to fetch it exclusively, the other copies are invalidated → C0 and C1 go to I, C2 to M. (Invalidation 2)

C0 cacheI—C1 cacheI—C2 cacheMx=2busmemory: stale

C2 reads: M in its own cache → hit, no bus traffic.

C0 cacheMx=3C1 cacheI—C2 cacheI—busmemory: stale

C0 writes: the dirty copy in C2 is supplied and invalidated → C0 M, C2 I. Total 3 invalidations; memory is still stale.

C0: read(x);      // x = 0
C1: read(x);
C1: x = 1;
C0: read(x);
C2: x = 2;
C2: read(x);
C0: x = 3;

Multiple Choice · Multiprocessor Hardware

Question 6: Separate Counters, Slow Program

Two threads increment two independent counters (long counter[2], adjacent) millions of times; there is no shared data and no lock. The program runs slower than the single-threaded version. What is the most likely cause?

B: The unit of coherence is the line, not the variable. When C0 increments counter[0] it takes the line in M and C1's copy is invalidated; when C1 increments counter[1] the line moves back: “ping-pong”. Aligning each counter to its own line (padding, @Contended in Java) fixes it. Separate variables have no race condition; two adjacent longs are also on the same page, hence on the same node.

Multiple Choice · Multiprocessor Operating Systems

Question 7: The Problem with the Master-Slave Model

In a multiprocessor operating system, the kernel runs only on CPU 0; the other CPUs execute user processes and forward every system call to CPU 0. What is expected when a system-call-heavy workload scales to 16 CPUs?

A: In the master-slave model only one CPU touches kernel data: it is simple, needs no locks, and the single ready list balances load by itself. The price is that the master's capacity limits the whole system, and if the master crashes the system stops. B and D belong to the “each CPU has its own OS” model, and C is the problem of SMP.

Multiple Choice · Synchronization

Question 8: A Spinlock Floods the Bus

Eight cores spin on the same lock variable, constantly executing TSL, and the rest of the system slows down. Which change reduces this traffic most?

D: Every TSL is a write: it pulls the line into M and invalidates the other copies, so the line keeps bouncing between cores. In test-and-test-and-set, waiters spin reading the S copy in their own caches and use no bus; exponential backoff cuts collisions further. Disabling the cache sends every read to memory and increases traffic. More scalable solutions are the ticket lock and MCS.

Step-by-Step Trace · Synchronization

Question 9: The Ticket Lock

Three threads use a ticket lock. How do next and serving change, and in what order is the critical section entered? Why do the waiters not flood the bus?

next0serving0in critical section:nobodyspinning:—

Two counters: next hands out tickets, serving shows the ticket whose turn it is. The lock is free. T1, T0, T2 call lock in that order; then the owners release.

next1serving0in critical section:T1 (0)spinning:—

T1 locks: the atomic increment returns the old value (ticket 0), next = 1. serving == 0 → it enters the critical section without looping.

next2serving0in critical section:T1 (0)spinning:T0 (1)

T0 locks: ticket 1, next = 2. serving (0) ≠ 1 → it spins reading the S copy in its own cache; the bus is not occupied.

next3serving0in critical section:T1 (0)spinning:T0 (1)T2 (2)

T2 locks: ticket 2, next = 3. serving (0) ≠ 2 → it spins reading the S copy in its own cache; the bus is not occupied.

next3serving1in critical section:T0 (1)spinning:T2 (2)

T1 releases: serving = 1. This write invalidates the spinners' copies; T0 (ticket 1), which reads the new value, enters while the others keep spinning.

next3serving2in critical section:T2 (2)spinning:—

T0 releases: serving = 2. This write invalidates the spinners' copy; T2 (ticket 2), which reads the new value, enters; no one else is waiting.

next3serving3in critical section:nobodyspinning:—

T2 releases: serving = 3 = next. No one is waiting, the lock is free. The entry order is the order of the tickets: T1, T0, T2.

void lock(void) {
  int my = atomic_inc(&next); // old value
  while (serving != my)
    pause();           // spin locally
}
void unlock(void) {
  serving++;
}

Multiple Choice · Synchronization

Question 10: Spin or Sleep?

On one core, a context switch costs C = 4 µs (sleeping and coming back takes two switches). When is it smarter to wait for the lock by spinning?

A: Rule: if the expected wait is shorter than 2C (8 µs), spinning is cheaper; otherwise sleeping is. In a 1 µs critical section, spinning is cheaper than a context switch. On a single CPU, spinning is pointless: the owner cannot progress until the spinning thread gives up the CPU. A sleeping owner means a long spin. In practice, adaptive locks spin briefly first, then sleep.

Classic Question · Scheduling

Question 11: Placing Gangs into Time Slices

Five parallel applications will run with gang scheduling on a 6-CPU system; their thread counts are A: 4, B: 2, C: 3, D: 3, E: 5. All threads of a gang must run in the same slice, on different CPUs.

  1. What is the minimum number of slices in a round? Give an arrangement.
  2. What is the CPU utilization?
  3. What would happen under time sharing if two of A's threads exchanged messages?
Show answer
sliceCPU 0–5idle
0A A A A B B0
1C C C D D D0
2E E E E E —1

(a) 17 threads in total, 6 CPUs per slice → at least ⌈17 / 6⌉ = 3 slices; the arrangement is above. E (5) could only share a slice with a 1-thread gap; since no gang has 1 thread, 1 CPU stays idle in that slice.

(b) 17 / 18 ≈ 94%.

(c) A1 sees a message sent by A0 only when its own slice comes, and the reply waits another slice: every request–reply takes a whole slice. In a gang the members run at the same time, so messages are answered immediately.

Output Question · Multicomputers

Question 12: The Diameter of Interconnects

Four interconnects are considered for a 64-node multicomputer: a bidirectional ring, an 8 × 8 grid, an 8 × 8 torus, and a 6-dimensional hypercube. Find the diameter (hops between the two farthest nodes) and the number of links of each. What happens to the hypercube's diameter if the node count rises to 128?

Show answer
topologydiameterlinks
ring3264
8 × 8 grid14112
8 × 8 torus8128
6D hypercube6192

Ring: 64 / 2 = 32. Grid: (8 − 1) + (8 − 1) = 14, links 2 × 8 × 7. Torus: with wraparound links 4 + 4 = 8, links 2 × 64. Hypercube: diameter log₂64 = 6, links 64 × 6 / 2.

With 128 nodes the hypercube's diameter becomes only 7 (doubling the nodes adds 1 to the diameter), whereas for the ring it rises to 64. The price is that the number of links per node grows too.

Step-by-Step Trace · Multicomputers

Question 13: Routing in a Hypercube

In a 4-dimensional hypercube, a message from node 0110 to node 1001 proceeds by fixing the first differing bit from the left at each step. Which nodes does it pass through, and how many hops does it make?

0000000100110010010001010111011011001101111111101000100110111010

The 4D hypercube is drawn as a 4 × 4 torus (rows and columns in Gray code): neighbors differ in one bit, and dashed lines wrap around to the opposite edge. Source 0110, destination 1001.

0000000100110010010001010111011011001101111111101000100110111010

diff = 0110 ⊕ 1001 = 1111; the first differing bit from the left is bit 1 → 1110. (Hop 1)

0000000100110010010001010111011011001101111111101000100110111010

diff = 1110 ⊕ 1001 = 0111; the first differing bit from the left is bit 2 → 1010. (Hop 2)

0000000100110010010001010111011011001101111111101000100110111010

diff = 1010 ⊕ 1001 = 0011; the first differing bit from the left is bit 3 → 1000. (Hop 3)

0000000100110010010001010111011011001101111111101000100110111010

diff = 1000 ⊕ 1001 = 0001; the first differing bit from the left is bit 4 → 1001. (Hop 4) Destination reached: hop count = Hamming distance = 4, which is also the diameter of the 4D hypercube. Since the rule is local, no routing table is needed.

cur = source;               // 0110
while (cur != target) {      // target 1001
  diff = cur ^ target;
  bit = leftmost_one(diff);
  cur = cur ^ bit;          // forward to neighbor
}

Output Question · Multicomputers

Question 14: Store-and-Forward or Cut-Through

An 8 KiB packet travels from source to destination through 3 switches, i.e. 4 links. Each link runs at 25 Gb/s; each switch processes the header in 0.05 µs (ignore cable delay).

  1. How long does the packet take to cross one link?
  2. What is the total latency with store-and-forward?
  3. What is the total latency with cut-through?
  4. If the hop count doubles, which one is affected much more?
Show answer

(a) 8192 × 8 / 25 × 10⁹ s = 2.62 µs.

(b) Each switch receives the whole packet and then forwards it: 4 × 2.62 + 3 × 0.05 = 10.64 µs.

(c) Once the header arrives the path is set up and the packet flows like a pipeline: 2.62 + 3 × 0.05 = 2.77 µs.

(d) The latency of store-and-forward grows linearly with the hop count (about 21 µs for 8 links); with cut-through only the header processing times add up. That is why HPC networks and data-center switches use cut-through or wormhole routing.

Multiple Choice · Multicomputers

Question 15: The Stub in a Remote Procedure Call

A client writes the call total = compute(array, n) like an ordinary function, but the function runs on another machine. What is the job of the client stub, and which kind of parameter causes trouble in RPC?

B: The stub is called like a local procedure, packs the parameters into a message (marshalling), sends it to the server through the kernel, and unpacks and returns the reply. A pointer is meaningless in another address space: the array is sent by value and, if needed, copied back (copy-restore). Global variables, partial failures, and byte order must also be handled separately.

Multiple Choice · Virtualization

Question 16: Type 1 and Type 2 Hypervisors

A student runs Linux with VirtualBox on a Windows laptop, while a data center divides its servers with ESXi running directly on the hardware. Which types are these, respectively?

C: A Type 1 hypervisor manages the hardware directly and runs guest operating systems (ESXi, Xen, Hyper-V; KVM turns Linux into a hypervisor). A Type 2 runs like an ordinary application on a host operating system and leaves device access to it. Hardware support (VT-x) can be used by both types; the type is determined by where the hypervisor runs.

Output Question · Virtualization

Question 17: The Two-Dimensional Page Walk

The guest OS uses 4-level page tables; the host uses 5-level tables for EPT. A TLB miss occurs on a guest virtual address, and no page table entry is cached.

  1. In the worst case, how many memory accesses does EPT need (excluding the final data access)?
  2. How many accesses would the same miss need if the hypervisor used shadow page tables?
  3. Where does the shadow table's cost lie?
Show answer

(a) Each of the 4 levels of the guest table holds a guest physical address and must go through EPT (5 accesses); then the entry is read. The final guest physical address must also be translated: (4 + 1) × (5 + 1) − 1 = 29 accesses. (With 4 levels on both sides it would be 24.)

(b) The shadow table directly holds the guest virtual → host physical mapping: 4 accesses, a one-dimensional walk.

(c) The guest's tables must be made read-only; the guest traps (VM exit) on every table change and the hypervisor updates the shadow. EPT removes these exits, at the cost of a long miss walk; that is why large pages and VM-tagged TLBs matter.

Multiple Choice · Virtualization

Question 18: uname -r in a Container

On a server running a Linux 6.8 kernel, a Docker container based on Ubuntu 20.04 and a KVM virtual machine with Ubuntu 20.04 installed are running. If uname -r is run in both, which statement is correct?

D: Containers share the host's single kernel; only the user space (libraries, tools) is Ubuntu 20.04. Isolation is provided by namespaces, cgroups, and seccomp. A virtual machine boots its own guest kernel. That is why a container cannot run a different operating system (e.g. a Windows kernel on Linux).

Multiple Choice · Distributed Systems

Question 19: When Does a Change Become Visible?

Client 1 opens a file and appends “c” but has not closed it yet; meanwhile client 2 opens and reads the file. The file was “ab”. In a system with session semantics (e.g. AFS), what does client 2 see?

C: In session semantics, changes are visible only to the client that made them until the file is closed; after closing, those who open it see the new version. A is the UNIX semantics on a single machine: every write is visible immediately, but in a distributed system it is expensive because of caches. Immutable files and transactions are the other options; all are a trade-off between consistency and performance.

The End

Chapter 12: Multiprocessor Systems: Study Questions
Lecture slides: Chapter 12: Multiprocessor Systems · Lecture notes
1 / 1 Sercan KÜLCÜ. All rights reserved.