System Design · Concept Library · Free article
What a CPU Actually Does
Follow values through instructions, then find out why four cores can still wait on one calculation.
A CPU carries out instructions that move, calculate and store values. Registers hold values close to execution. A core can do work only when its required inputs are ready. Extra cores can overlap independent work, but a calculation that needs an earlier result must wait. CPU time adds the time spent executing across cores; elapsed time measures how long the job takes from start to finish.
A small job with two things to calculate
Your program needs to calculate (3 + 5) × (7 + 1) and write the answer to memory. You can add the left pair without knowing the right sum. You can also add the right pair without knowing the left sum. Multiplication needs both answers.
Before opening the workbench, predict what a second core could do. Could it work on the second sum while the first core handles the first? Could it multiply before either sum finishes? Those are different questions: one is about available hardware, the other about available information.
A CPU, the central processing unit, executes a program’s instructions. An instruction tells it to perform a supported operation, such as loading a value, adding values or storing a result. A core is an execution engine within the processor. Giving a job four cores offers more places to execute ready work; it does not create the missing inputs of a calculation.
Where does an addition find its values?
A register is a small storage location in a processor. Instructions use registers for values they need and results they produce. Main memory holds a much larger set of program instructions and data. A load copies a value from memory into a register. An arithmetic operation computes from available values. A store copies a result back to a memory location.
For 3 + 5, picture two input cells holding 3 and 5. Load them into registers named a and b, add those register values to produce left = 8, then retain that result for multiplication. Loading does not remove 3 or 5 from their original cells. Writing an output to ordinary memory also does not make it durable across power loss.
These names help us track data. The workbench retains one named result per load or arithmetic instruction, making earlier values inspectable throughout the run. A physical processor has a bounded register set and may reuse or rename registers; a compiler decides how program values map to instructions and storage. Our model does not simulate those allocation decisions.
| Operation | Reads | Produces |
|---|---|---|
| Load a | Input cell containing 3 | Named result a = 3 |
| Add left | Completed results a = 3 and b = 5 | Named result left = 8 |
| Store answer | Completed result product = 64 | Output cell answer = 64 |
Processors also need to fetch instructions and determine what those instructions request. The familiar fetch, decode, execute description names those responsibilities. It is a useful first explanation, but it does not mean a modern core completes only one whole instruction before starting the next. Hardware can overlap parts of several instructions and execute some independent operations together. This workbench groups execution into explicit operations so you can inspect dependencies; it does not recreate an instruction pipeline or predict clock cycles.
A load/store instruction set makes the movement distinction explicit: arithmetic uses registers and separate instructions access memory. The RISC-V instruction-set specification provides one concrete architecture. The workbench’s four operations are a teaching vocabulary, not executable RISC-V assembly.
A free core cannot multiply an unfinished sum
A data dependency means one operation needs a result produced by another. In this job, left depends on a and b; right depends on c and d; product depends on both sums; answer depends on the product.
Draw an arrow from each producer to the instruction that reads its result. The arrows form a directed acyclic graph, often shortened to DAG: each arrow has a direction, and no chain of arrows circles back to its starting point. A circle here would mean an instruction waits indirectly for itself. The workbench refuses that configuration before executing it.
a (3) ─┐ c (7) ─┐
b (5) ─┴→ left (8) d (1) ─┴→ right (8)
└────────→ product (64) ←──┘
↓
answer (64)An instruction becomes ready when every input and explicit ordering dependency has finished. Ready work can still wait if all cores are occupied. Work waiting for a missing result cannot use an idle core. When diagnosing a blank region on the core timeline, check which of these two situations applies.
The editor’s “Wait for” control adds an ordering constraint without changing the arithmetic. For example, make right wait for left. Both sums still produce 8, but they can no longer overlap. Such ordering can be required by a real program’s effects. Here it lets you isolate the cost of serialization. Removing a required input connection is never a valid optimization.
Predict, step, then add a core
- Start with “Two calculations” and one core. Write your prediction, then use Step to inspect assignments and completions. Values appear after execution finishes.
- Run the complete graph and pin it for comparison. Its eight instructions produce answer = 64.
- Change Cores to 2 and run again. Inspect the two sums, the final multiplication and the stored output. Find where work overlaps and where a core waits.
- Add a Wait for dependency from right to left. Predict the effect before running. Keep the inputs and operation costs unchanged so the comparison isolates the new dependency.
Open the CPU workbench to edit instructions and inspect dependency and core timelines. Interactive controls need JavaScript.
CPU time and elapsed time answer different questions
Each load costs one educational tick, each addition three, multiplication four, and the final store one. A tick is a unit defined by this model. It is not a nanosecond, a clock cycle or a measurement of your laptop. These particular costs make the dependency structure easy to inspect.
With one core, the four loads take four ticks, the two additions six, the multiplication four and the store one: 15 ticks elapsed. That core worked for all fifteen, so CPU time is 15 core-ticks.
With two cores, a and b load during ticks 0 to 1, then c and d during ticks 1 to 2. The sums run together from 2 to 5. Multiplication runs from 5 to 9; the final store runs from 9 to 10. The answer arrives after 10 ticks, while total CPU time is still 15 core-ticks. Five core-ticks of work were overlapped, not removed.
In the four-core run, all loads finish at tick 1, both sums at tick 4, multiplication at tick 8 and the store at tick 9. Total work remains fifteen core-ticks. More cores saved another tick here, not another half of the job.
For actual applications, CPU time sums processor time spent executing, while elapsed or wall time includes the entire observed interval, including waiting. Parallel execution can make total CPU time exceed elapsed time. Intel’s CPU metrics reference describes CPU activity and parallel overhead. Our model has no I/O waiting or context-switch overhead, so its work accounting covers only its declared operation costs.
Find the longest chain before buying more cores
Follow a load through its addition, the multiplication and the final store. That chain costs 1 + 3 + 4 + 1 = 9 ticks. Every operation on it needs its predecessor. The longest such path is the critical path. Even unlimited cores cannot finish this graph faster than that path under the declared costs.
There is another lower bound: total work divided by the number of cores. Fifteen core-ticks spread across two cores need at least 7.5 elapsed ticks, or eight whole ticks in this model. The critical path is nine, so the stronger lower bound is nine. Our two-core schedule takes ten. A lower bound rules out impossible results; it does not guarantee that a chosen schedule reaches it. The workbench picks ready instructions in list order, rather than searching for the fastest schedule.
Try “One dependent chain.” It starts with 2, doubles it to 4, squares that result to 16 and stores 16. Costs are 1 + 3 + 4 + 1 = nine ticks. Every operation waits for the previous one, so one core and four cores both finish at tick nine. The extra lanes remain idle for a reason the dependency graph explains.
For larger programs, Amdahl’s law expresses a related limit. If a fraction of a fixed job must remain serial, speeding up the other fraction leaves that serial time in place. Its familiar formula assumes a fixed workload and ideal parallel work; real coordination, copying, imbalance and contention can cost more. LLNL’s introduction to parallel computing explains this model and its assumptions. This workbench computes the graph’s own path and resource bounds instead of fitting a serial fraction to a run.
Doing less work is another kind of improvement
Choose “Compute once, use twice.” Both additions read the same 3 and 5, so the program calculates 8 twice and multiplies the two results. On one core, this takes thirteen ticks. Pin the completed run. Change product input 2 from right to left, then remove right. The product now reads the same completed sum twice. Run again: the output is still 64, and the graph takes ten ticks on one core. Three core-ticks of duplicate addition disappeared.
Try the same change with two cores. The duplicate sums could already overlap, so reducing total work need not reduce elapsed time by the same amount. Record both numbers. In the workbench, both versions finish in nine ticks on two cores.
Reuse has conditions. Both original computations must read the same values and have compatible effects. Reusing a calculation that reads changing input, updates state or must run separately can change the program’s meaning. Our inputs are immutable and arithmetic has no side effects; that is why this example is safe. Retaining and sharing results also consumes storage and may require communication in real programs. The workbench exposes named results but does not charge memory capacity or transfer costs.
Change one assumption and defend the result
Ungraded transfer checks
- Two calculations now use 10, 2, 4 and 1. What must the output be, and do the default schedules take longer?
- The result is (10 + 2) × (4 + 1) = 60. With unchanged dependencies and costs, elapsed times remain 15, 10 and 9 ticks on one, two and four cores. Input magnitude does not change operation costs in this model.
- What happens if multiplication costs eight ticks instead of four?
- The longest path becomes thirteen ticks. The default two-core schedule becomes fourteen ticks, and four cores take thirteen. More time was added to an operation both sums must feed, so extra cores cannot overlap it with its own inputs.
- Can a run with no store prove the required answer was written?
- No. It can finish all its arithmetic while producing no output cell. Inspect the stored result, not just a completed-instruction count.
- Why does reconnecting a product to an unfinished result not let it start early?
- The input connection itself adds a dependency. The producer must complete before the consuming instruction can use that value. A cycle is refused rather than assigned an invented result.
- An edited program stores the right answer for one input. Is it equivalent for every input?
- That run establishes agreement only for its supplied input. Check the algebra and vary inputs independently. In the reuse example, both removed and retained sums read the same immutable values, which supplies a stronger reason for equivalence.
Sources and model limits
- RISC-V base integer instruction set: register state, arithmetic and load/store operations.
- Intel CPU metrics reference: processor time and parallel-work overhead.
- LLNL parallel computing tutorial: dependencies, parallelism and Amdahl’s assumptions.
- Costs, dispatch order and zero-cost value transfer are explicit educational choices. The workbench supports at most 24 instructions and four cores, refuses dependency cycles, and stops on signed 32-bit result overflow. It does not execute arbitrary programs or predict physical CPU performance.
By GOAT Engineer. Back to Concept Library. Privacy Policy · Contact.