Skip to content

Unit 3 · The Von Neumann Architecture

3 h contact · 6 h self study Prerequisites: Units 1 and 2 CLO 2 · CLO 3

1. Setting the scene

Scenario: What is the CPU doing all night?

The C++ rewrite of the SensorGrid report is three times faster than Python, but still far from the 16× the team hoped for. Profiling shows the core is busy only a fraction of the time; the rest of the time it is waiting.

To understand where the time goes, we have to look inside: how the processor executes instructions, how a running program is organised in memory, and what the operating system means by a process and a thread.

Guiding questions

  1. What exactly happens when a processor executes a = b + c?
  2. Why did clock speeds stop rising?
  3. What is the difference between a program, a process and a thread, and which of them can run in parallel?

2. Intended learning outcomes

# Outcome Bloom CLO
ILO 3.1 Describe the Von Neumann architecture and its fetch, decode, execute cycle. UNDERSTAND 2
ILO 3.2 Identify opcode and operands of an instruction and data dependencies between instructions. APPLY 2
ILO 3.3 Explain instruction level parallelism, superscalar execution and the limits of a single core. UNDERSTAND 2
ILO 3.4 Explain why clock frequency stopped increasing, using the dynamic power equation. UNDERSTAND 2
ILO 3.5 Distinguish program, process and thread, and map variables to text, data, BSS, heap and stack. ANALYSE 3

3. The Von Neumann architecture

In 1945 John von Neumann described a machine in which instructions and data share the same memory. Almost every computer built since follows this design.

flowchart LR
    subgraph CPU["Central Processing Unit"]
      direction TB
      CU["Control unit<br/>program counter, instruction register"]
      ALU["Arithmetic logic unit"]
      REG["Registers"]
      CU <--> ALU
      ALU <--> REG
    end
    MEM[("Main memory<br/>instructions AND data")]
    IO["Input / Output"]
    CPU <-->|"system bus<br/>addresses, data, control"| MEM
    CPU <--> IO

An instruction

An instruction consists of two parts:

  • the opcode tells the processor what to do (add, subtract, load, store); in a + b, the + is the opcode;
  • the operands are the data the operation works on: a value, a register, or a memory location; in a + b, a and b are the operands.

If an operand is in memory, its address specifies where the data is found, and an address may also say where the result must be stored.

 opcode   destination   source 1   source 2
 ADD      R0            R0         R1          ; R0 ← R0 + R1

The instruction cycle

stateDiagram-v2
    [*] --> Fetch
    Fetch --> Decode : instruction in IR
    Decode --> FetchOperands : opcode known
    FetchOperands --> Execute : operands in registers
    Execute --> WriteBack : result ready
    WriteBack --> Fetch : PC ← PC + 1
  1. Fetch the next instruction from memory into the instruction register.
  2. Fetch the operands from memory into data registers.
  3. Execute the instruction.
  4. Store the result in memory.
  5. Repeat.

Parallelism was slowly introduced into this sequential scheme from very early on, and became a major force from the late 1980s.

Worked example: add R0 ← R0, R1

sequenceDiagram
    participant CU as Control unit
    participant R as Registers
    participant A as ALU
    CU->>CU: fetch and decode "add R0, R0, R1"
    CU->>R: read R0 and R1
    R-->>A: 32 and 64
    A->>A: 32 + 64 = 96
    A->>R: write 96 into R0

4. Clock speed and why it stopped rising

Clock speed is the number of cycles a CPU executes per second: \(1\ \text{Hz} = 1\) cycle/s, so \(3\ \text{GHz} = 3 \times 10^{9}\) cycles/s and one cycle lasts

\[ t_{\text{cycle}} = \frac{1}{f} = \frac{1}{3 \times 10^{9}\ \text{s}^{-1}} \approx 0.33\ \text{ns}. \]

Actual speed also depends on the number of cores, the efficiency of the instruction set, the cache size and parallelism.

Signals are waves

Inside a CPU, electrical signals switch billions of times per second and travel as electromagnetic waves. In 0.33 ns light travels only about 10 cm; on a chip, signals are slower still. And every switch costs energy.

The power wall

The dynamic power of a chip grows with the switched capacitance \(C\), the square of the supply voltage \(V\) and the frequency \(f\):

\[ P_{\text{dyn}} \approx \alpha\, C\, V^{2} f \]

Historically, higher frequencies also required higher voltages, so power grew roughly with \(f^{3}\). Doubling the clock would mean about eight times the heat. Around 2005 chips reached the limit of what can be cooled.

xychart-beta
    title "Relative power if voltage scales with frequency (P ∝ f³)"
    x-axis "Relative clock frequency" [1.0, 1.25, 1.5, 1.75, 2.0]
    y-axis "Relative power" 0 --> 9
    line [1, 1.95, 3.38, 5.36, 8]

Compare two ways to double performance:

Option Frequency Cores Relative power
Faster single core \(2f\) 1 \(\approx 8\)
Two cores at the old speed \(f\) 2 \(\approx 2\)

The industry chose cores. Performance now grows through parallel computing, not through GHz.

5. From program to instructions

flowchart LR
    SRC["Source code<br/>int x = 1;<br/>for (i=0;i<3;i++) x = x + x;"] --> COMP["Compiler"] --> INS["Instructions<br/>load · add · store ·<br/>compare · jump"]

The processor never sees C++ text. It sees an instruction stream, the ordered list of instructions it executes:

  1. load value of x
  2. add x + x
  3. store new value of x
  4. increase loop counter
  5. compare counter
  6. jump if the loop continues

Registers are tiny, very fast storage locations inside the core that hold the values instructions work on (addresses, current values, counters). Most instructions read registers, compute, and write a result to a register or to memory.

6. Parallelism inside one core

Dependencies

a = b + c;   // (1)
d = a * 2;   // (2) needs a from (1): must wait
e = x + y;   // (3) independent: may run any time
flowchart TB
    I1["(1) a = b + c"] -->|"true dependency on a"| I2["(2) d = a * 2"]
    I3["(3) e = x + y"]

Instruction level parallelism (ILP)

A modern core can execute independent instructions from one instruction stream at the same time.

gantt
    title Superscalar execution with two ALUs
    dateFormat X
    axisFormat cycle %s
    section ALU 1
    a = b + c :0, 1
    d = a * 2 :1, 2
    section ALU 2
    e = x + y :0, 1

Three instructions complete in two cycles instead of three. The instructions per cycle metric captures this:

\[ IPC = \frac{\text{instructions completed}}{\text{cycles}} = \frac{3}{2} = 1.5 \qquad CPI = \frac{1}{IPC} \approx 0.67 \]

A superscalar core issues several instructions per cycle because it has several execution units, but only when the instructions are independent, their inputs are ready, and they can use different units.

Why one core still has limits

  • Data dependencies: the next instruction may need an earlier result.
  • Memory delay: the core waits while data is loaded (Unit 4).
  • Branch uncertainty: the core may not yet know which instruction comes next.
  • Power and heat: a more complex core consumes more energy.

Instead of making one core endlessly more complex, processors now use multiple cores and parallel execution units.

7. Program, process and thread

Concept Definition
Program A passive file of instructions and data on disk
Process A program in execution, with its own address space, registers and operating system resources
Thread A unit of execution within a process; threads share the process's memory but each has its own stack and registers

The memory layout of a process

block-beta
  columns 1
  S["Stack · local variables, function calls · grows downward ↓"]
  F["free space"]
  H["Heap · new / malloc · grows upward ↑"]
  B["BSS · uninitialised globals (zeroed)"]
  D["Data · initialised globals"]
  T["Text · program instructions (read only)"]

Why the growth direction matters. Stack and heap grow towards each other, which uses the free space between them efficiently. If they meet, the program runs out of memory and crashes.

Stack Heap
Stores local variables, function calls objects shared across functions
Speed fast, cache friendly slower
Management automatic, last in first out manual (new/delete, malloc/free)
Size fixed at compile time: int nums[100]; flexible at run time: int *nums = malloc(100 * sizeof(int)); free(nums);

Code walkthrough: where do variables live?

#include <iostream>
#include <sys/wait.h>
#include <unistd.h>

int g_init = 10;      // initialised data segment
int g_uninit;         // BSS segment (zero initialised)

int main() {
    int stack_var = 1;                 // stack
    int* heap_var = new int(100);      // heap

    pid_t pid = fork();                // child gets a COPY of the address space
    if (pid == 0) {                    // child
        g_init += 1; stack_var += 1; *heap_var += 1;
        std::cout << "child : g_init=" << g_init << " stack=" << stack_var
                  << " heap=" << *heap_var << '\n';
    } else {                           // parent
        waitpid(pid, nullptr, 0);
        std::cout << "parent: g_init=" << g_init << " stack=" << stack_var
                  << " heap=" << *heap_var << '\n';
    }
    delete heap_var;
    return 0;
}
child : g_init=11 stack=2 heap=101
parent: g_init=10 stack=1 heap=100

Key idea: after fork(), each process has its own copy of the memory. Changing a variable in the child does not affect the parent. Processes communicate only explicitly (pipes, sockets, files), which is the model we meet again in distributed computing (Unit 5).

Process versus thread

flowchart TB
    subgraph P1["Process A"]
      C1["Code · Data · Heap<br/>(shared by its threads)"]
      T1["Thread 1<br/>stack + registers"]
      T2["Thread 2<br/>stack + registers"]
    end
    subgraph P2["Process B"]
      C2["Code · Data · Heap"]
      T3["Thread 1<br/>stack + registers"]
    end
    P1 <-.->|"inter process communication (explicit)"| P2
Process Thread
Memory own address space shares the address space of its process
Creation cost high low
Communication explicit (IPC) through shared variables
Failure isolation strong a crashing thread can bring down the process
Parallel programming model MPI, distributed systems OpenMP, pthreads (Unit 9)

The life of a thread or process as seen by the operating system:

stateDiagram-v2
    [*] --> New
    New --> Ready : admitted
    Ready --> Running : scheduled on a core
    Running --> Ready : time slice over
    Running --> Waiting : I/O or lock
    Waiting --> Ready : event done
    Running --> Terminated : exit
    Terminated --> [*]

8. Multitasking

Running multiple tasks at the same time can mean two different things:

  • Concurrency: tasks make progress by interleaving on one core (the operating system switches between them).
  • Parallelism: tasks run simultaneously on different cores.
gantt
    title One core: interleaving (concurrency)
    dateFormat X
    axisFormat %s
    section Core 0
    Task A :0, 2
    Task B :2, 4
    Task A :4, 6
    Task B :6, 8
gantt
    title Two cores: simultaneous (parallelism)
    dateFormat X
    axisFormat %s
    section Core 0
    Task A :0, 4
    section Core 1
    Task B :0, 4

9. Classwork

Dependencies and segments (20 min)

  1. For the code below, draw the dependency graph and the minimum number of cycles on a core with two ALUs (each instruction takes one cycle).
    p = a + b;  q = c + d;  r = p * q;  s = e + 1;  t = r - s;
    
  2. For each variable in the fork program, name its segment and predict the output if the child also did g_uninit = 5 and the parent printed g_uninit.
Solutions
  1. Cycle 1: p, q. Cycle 2: r, s. Cycle 3: t. Three cycles, \(IPC = 5/3 \approx 1.67\).
  2. g_init data, g_uninit BSS, stack_var stack, the pointer heap_var stack but the int it points to heap. The parent prints g_uninit = 0: the child changed only its own copy.

10. Check your understanding

What is the Von Neumann bottleneck?

Instructions and data share one path between CPU and memory, whose bandwidth is far below what the CPU can process. The CPU spends much of its time waiting for memory. Unit 4 is devoted to it.

Why does doubling the frequency cost about eight times the power?

\(P \propto C V^2 f\), and a higher frequency historically needed a proportionally higher voltage, so \(P \propto f \cdot f^2 = f^3\) and \(2^3 = 8\).

Two threads of the same process: which of stack, heap, globals do they share?

They share heap and globals (and code); each has its own stack and registers.

11. Key takeaways

  • Von Neumann machines keep instructions and data in the same memory and execute a fetch, decode, execute cycle.
  • ILP and superscalar cores run independent instructions together, but dependencies, memory stalls and branches limit them.
  • The power wall (\(P \propto C V^2 f\)) ended frequency scaling; the industry switched to multicore.
  • A process has its own address space; threads share it. This distinction separates distributed from shared memory programming.

Portfolio documentation must explain, for each experiment, whether parallelism comes from processes or threads and which memory is shared.

Further reading

  • K. Fatahalian, K. Olukotun, CS149 Parallel Computing, Stanford, lectures 1 and 2.
  • R. E. Bryant, D. R. O'Hallaron, Computer Systems: A Programmer's Perspective, ch. 1, 8 and 9.