W9 - Multiple Processor Systems

Why Multiple Processors?

Multiple Processor Systems

image-14.png439x174

From Single-Core to Multicore

A compact historical timeline:

Comparison of Multiple Processor Systems

image-15.png465

How many CPUs does my laptop have?

sysctl -n hw.physicalcpu
sysctl -n hw.logicalcpu
sysctl -n hw.memsize
sysctl -a | grep 'hw.perflevel'

Multiprocessor Hardware

Two CPUs, Two Caches, One Variable

What Happens When Two CPUs Cache the Same Variable?

image-16.png297x182

Question: CPU 1 modifies x to 20. How does CPU 2 discover the change?

Master-Slave Multiprocessors

image-17.png453x116

image-18.png455

How to avoid race conditions within the OS?

It is safe, but not efficient. Many parts of the OS are independent. Why not have one CPU run the scheduler while another one is handling a file-system request?

If CPU 1 is modifying the process table, why should CPU 2 necessarily be prevented from accessing an unrelated filesystem structure

Notes:

Two locks, one deadlock

image-19.png164x299

Multiple Locks

Notes:

One Big Lock vs. Multiple Locks

image-20.png367x82

Trade-off: Greater parallelism introduces synchronization complexity and possible deadlocks.

Mutexes in Multiprocessor Systems

Notes:

Locking the Bus

do {
	lock_bus();
	lock = TSL();
	unlock_bus();
} while (lock==1);
critical_region();

Solutions to Reduce Bus Locking

Test-and-test-and-set (TTAS)

while (true) {
	while (atomic_load(&lock) == 1) {
		// Wait using reads
	}
	
	if (atomic_exchange(&lock, 1) == 0)
		break; // Acquired
}

Spin or Switch

Notes:

Spin or Switch: Example

What would you choose?

  1. Lock expected to be released in 200 ns
  2. Lock may be held for 100 ms
  3. Unknown lock duration, varying contention

Would you keep the CPU busy waiting, or let the OS schedule another thread?

Hybrid Mutex: Example

Notes:

Three Things to Remember

  1. Multiple processors enable true parallelism, but shared resources introduce concurrency challenges.
  2. Synchronization ensures correctness, while lock granularity determines how much parallelism is possible.
  3. Efficient multiprocessor systems balance contention, cache behavior, and scheduling overhead.

Multiprocessor Scheduling

image-22.png487x217

Why CPU Affinity Matters

image-23.png242x113

Keeping a thread on the same CPU can improve cache locality, but strict affinity may reduce load-balancing flexibility.

Affinity Scheduling

Gang Scheduling

image-24.png409x224

Gang Scheduling: A Practical Example

image-25.png279x156

Notes:

Performance vs Efficiency Cores

image-26.png362x202

Multicomputers

A Short History of Computer Clusters

Notes:

Packet Switching vs Circuit Switching

Notes:

Networking Interfaces

image-27.png356x200

Notes:

Message Passing

Shared Memory vs Message Passing

image-28.png446x201

Shared memory Message passing
Common address space Separate address spaces
Shared loads/stores Send/receive
Synchronization for shared data Communication and coordination
Common in multicore systems Common in clusters

Blocking vs Non-Blocking Calls

image-29.png350x232

Blocking vs Non-Blocking in Practice

Server:

import socket
import time

with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as server:
	server.bind(("127.0.0.1", 50007))
	server.listen(1)
	
	print("Waiting for client...")
	conn, addr = server.accept()
	
	with conn:
		print("Connected:", addr)
		time.sleep(3)
		conn.sendall(b"Hello from the server!")

Client:

import socket
import time

with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as client:
	client.connect(("127.0.0.1", 50007))
	
	print("Waiting for response...")
	start = time.perf_counter()
	
	data = client.recv(1024)    # <- blocking
	
	print("Received:", data.decode())
	print("Elapsed:", round(time.perf_counter() - start, 2), "s")

Load Balancing

Load Balancing: Who Should Move?

You Are the Cluster Scheduler

Four nodes, unevenly distributed work

- Node A
	- 8 jobs
- Node B
	- 2 jobs
- Node C
	- 1 jobs
- Node D
	- 1 jobs

Which load-balancing strategy would you choose?

Distributed Systems

Notes:

image-30.png382x207

The OSI Layers and the TCP/IP Stack

Look at:

image-31.png471x224

Notes:

IP Addresses, Domain Names, and Ports

What Happens When I Open a Website?

image-32.png238x404

dig www.dtu.dk
curl -I https://www.dtu.dk

Output:

> dig www.dtu.dk

; <<>> DiG 9.10.6 <<>> www.dtu.dk
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 57914
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1220
;; QUESTION SECTION:
;www.dtu.dk.                    IN      A

;; ANSWER SECTION:
www.dtu.dk.             600     IN      CNAME   azure.sitecore.dtu.dk.
azure.sitecore.dtu.dk.  3600    IN      A       52.236.166.178

;; Query time: 37 msec
;; SERVER: 10.11.12.13#53(10.11.12.13)
;; WHEN: Thu Nov 05 10:22:07 CET 2026
;; MSG SIZE  rcvd: 90

> curl -I https://www.dtu.dk
HTTP/2 200
date: Thu, 05 Nov 2026 09:22:13 GMT
content-type: text/html; charset=utf-8
content-length: 208352
server: Microsoft-IIS/10.0
cache-control: no-cache, no-store
expires: -1
pragma: no-cache
set-cookie: shell#lang=en; path=/
x-frame-options: SAMEORIGIN

Sockets

image-33.png395x174

Protocol Stacks

image-34.png566x181

Services, Layering and Encapsulation

image-35.png566x243

TCP and UDP Sockets

TCP or UDP? You Decide

  1. Transferring a large file
  2. Real-time multiplayer game updates
  3. Sending an email
  4. Live interactive voice
  5. Traditional DNS query

Three Things to Remember

  1. Multiprocessor scheduling balances parallelism and locality.
  2. Independent computers coordinate through communication.
  3. Communication introduces trade-offs in latency, reliability, and overhead