How computers work

Workstation: the whole computer

A computer is more than the system unit. The monitor shows the result, the keyboard and mouse pass on commands, the speakers play sound, and cables carry energy and data between them. This is where the boundary between hardware and software lies: everything you see on the screen is the result of programs executed by the processor in the system unit. This level also shows how long the path from a key press to a letter on the screen takes.

Open in 3D →

Room and desk

A typical workstation: a 160 × 75 cm desk, 75 cm high, the monitor 60–80 cm from the eyes, the top edge of the screen roughly at eye level, the keyboard and mouse at elbow height. The scale of this level is meters; one step up is an apartment with a local network, one step down is the inside of the system unit.

A mouse pad is not decoration. The mouse’s optical sensor photographs the surface thousands of times a second and computes movement from the shift of the pattern. On a uniform surface — glass, a glossy white desk — the sensor has nothing to “grip,” while the fabric of a pad provides a fine, irregular texture on which it works reliably.

The room is also part of the thermal system. Everything the computer and monitor consume turns into heat: a gaming PC under load is like a 400–600 W heater. In a small closed room this adds several degrees over a couple of hours, and along with the room, the air entering the case heats up too.

Energy comes in from the wall, and data goes out to the neighboring level — the apartment: a network cable or Wi-Fi connects the computer to the router and on to the internet. Here the workstation is shown without the network so that the computer itself is visible.

Outlet and power

The outlet supplies 230 V AC at 50 Hz: the current changes direction 100 times a second, and the peak voltage is ≈ 325 V. A grounded outlet has a third contact — protective earth, connected to the building’s ground.

The power cable (a C13 connector on the cable end, a C14 inlet on the power supply) is rated for 10 A — with a big margin: a computer under load draws 300–700 W, which is 1.3–3 A. The monitor adds another 20–60 W. At idle and in sleep mode consumption drops to tens or single watts.

A power supply with active power factor correction draws current as a sine wave in step with the voltage (power factor ≈ 0.99) and usually works over a 100–240 V range — the same unit suits both 120 V in the US and 230 V in Europe. Inside the unit, the AC is rectified and turned into DC at 12, 5 and 3.3 V.

The ground contact is about safety, not about operation. If insulation inside the unit breaks down and the live wire touches the case, the current flows to ground and trips the circuit breaker or residual-current device (RCD) — instead of passing through a person. Without grounding, the computer works, but the case may give a slight “tingle”: the power supply’s interference filter is connected to the case through capacitors, so an ungrounded case carries a noticeable voltage at a very small current.

A surge protector guards against voltage spikes, and an uninterruptible power supply (UPS) against power outages: for a few minutes it powers the computer from a battery so you can save your work and shut down.

System unit

The system unit on the desk is the same model as on the “System unit” level: inside, the processor, memory, graphics card and drives are working, and the fans spin up under load. Double-click to go inside.

All the cables of the workstation converge on it: power from the outlet, DisplayPort to the monitor (from the graphics card), USB from the keyboard and mouse, audio to the speakers, the network. All the “logic” happens here, while the monitor, keyboard, mouse and speakers merely turn signals into light, sound and motion — and back.

The case needs free space in front and behind. Pushed with its back against a wall or tucked into a closed cabinet, it breathes its own hot air. On the floor, especially on carpet, the case collects dust faster, and its bottom vents get blocked.

Monitor, screen and DisplayPort cable

A 27″ monitor with a resolution of 2560 × 1440 has ≈ 3.7 million pixels, about 109 pixels per inch. Each pixel is three subpixels: red, green and blue. In an IPS panel, each subpixel has its own thin-film transistor (TFT) and a layer of liquid crystals between polarizers: voltage rotates the crystals and changes how much backlight gets through. In an OLED panel, each subpixel emits light itself, and black is truly black.

How the panel is refreshed. The monitor’s controller receives the frame line by line. The row driver opens the transistors of one row, the column drivers simultaneously set the voltages of all its 2560 × 3 subpixels, then the row is closed — it holds its charge until the next frame — and the next one is opened. At 165 Hz all 1,440 rows are covered in 6.06 ms, about 4 µs per row.

Refresh rate and response time are different things. The new voltages are set immediately, but the liquid crystals need 1–5 ms to rotate; while they are rotating, moving objects are slightly blurred. OLED switches in a fraction of a millisecond.

The DisplayPort cable carries the stream of pixels: 4 lanes of 8.1 Gbit/s (DisplayPort 1.4) or up to 20 Gbit/s per lane (DisplayPort 2.1). 2560 × 1440 at 165 Hz needs about 15 Gbit/s. Besides pixels, the cable carries audio, an auxiliary channel (through which the graphics card reads the monitor’s EDID — the list of supported modes) and a hot-plug detect signal. HDMI does the same thing and is more common on TVs.

The screen is the boundary with the software side. Double-clicking it opens what runs inside: the operating system, the browser, programming languages, neural networks and databases.

Keyboard, mouse and USB

Under the keys is a matrix: row and column wires with switches at the intersections. The keyboard’s microcontroller drives the rows one at a time and reads the columns; a closed switch connects its row to its column. Scanning the whole matrix takes a fraction of a millisecond and repeats continuously. Diodes on each switch (in good keyboards) prevent keys pressed at the same time from creating “ghost” connections.

A mechanical contact bounces when it closes — for a few milliseconds it opens and closes repeatedly. The controller filters this out; otherwise a single press would produce several letters. Then it builds a USB HID report: which modifiers are held (Shift, Ctrl, Alt) and the codes of the pressed keys — up to six at once in the simplest format.

An important detail: the keyboard sends not a letter but a key number — “the key in position Q.” Which letter that is — Q, the Cyrillic letter short I, or something else — is decided by the operating system according to the current layout. That is why the same keyboard can type both Russian and English, and the labels on the keys are only a hint for humans.

USB works by polling: a device cannot “speak up” on its own; the computer asks it on a schedule. An ordinary keyboard is polled 125 times a second (every 8 ms), gaming ones 1,000 times or more. A USB 2.0 cable has four wires: 5 V and ground to power the device, and a D+/D− differential pair for data; speeds up to 12 Mbit/s are plenty for a keyboard and mouse.

A mouse is a small camera with its own light: the sensor captures the surface thousands of times a second, compares neighboring frames and computes the displacement. Each report contains the dx and dy offsets, the buttons and the wheel. Sensitivity (CPI or DPI) is how many units of displacement correspond to an inch of movement. Wireless mice send the same reports over 2.4 GHz radio to a receiver in a USB port, or over Bluetooth.

Speakers and sound

In a computer, sound is a stream of numbers. The air pressure at a microphone was measured 48,000 times a second (a sampling rate of 48 kHz), each measurement 16 or 24 bits. By the sampling theorem (Nyquist–Shannon, known in Russia as Kotelnikov’s theorem), such a stream accurately carries all frequencies up to 24 kHz — above the limit of human hearing (≈ 20 kHz).

Programs — a game, a player, a browser — hand their sounds to the OS, which mixes them into a single stream and sends it to the audio codec on the motherboard. The codec’s digital-to-analog converter turns the numbers into a voltage changing 48,000 times a second, and a filter smooths out the steps — producing an analog signal at the jack.

Active speakers contain their own amplifier: it turns the weak signal from the jack (fractions of a volt) into several volts and amperes. Current through the voice coil in the field of a permanent magnet moves the cone — the same principle as the head actuator of a hard drive. The cone pushes the air, and a pressure wave reaches the ear — the very wave a microphone once measured.

Sound goes through a buffer, usually 5–20 ms: the OS prepares the next chunk in advance so there are no clicks if the processor gets distracted. There are other paths too: over USB to speakers or a headset with its own converter, over HDMI or DisplayPort to a monitor or TV, over Bluetooth to headphones, which adds compression and noticeable latency.

From a key press to a letter on the screen

The “Key press” mode follows the entire path of a single letter. 1. Matrix (≈ 1 ms): the keyboard controller scans the matrix, finds the closed key and filters out bounce. 2. USB polling (≈ 0.5 ms on average at 1,000 Hz): the report waits for the next poll and goes down the cable.

3. USB controller → memory (≈ 0.01 ms): the USB controller itself places the report into RAM via DMA, without involving the processor, and raises an interrupt. 4. Interrupt and driver (≈ 0.02 ms): a processor core sets aside its current work, the operating system calls the driver, and the driver turns the key code into a character according to the layout. 5. OS → window (≈ 0.2 ms): the window system puts the event into the queue of the window that currently has focus.

6. Application (≈ 2 ms): the editor inserts the letter into the text, lays out the line with the font again and asks for the window to be redrawn. 7. Graphics card (≈ 3 ms): the OS composes a new frame from the windows, the GPU draws it into the framebuffer, and the letter makes it into the next frame. 8. Monitor (≈ 4 ms): the frame goes out over DisplayPort, the panel updates its rows, the crystals rotate — and you see the letter.

The total in the model is ≈ 11 ms; in real systems it ranges from 10 to 50 ms. Look at how the time is distributed: the processor’s computation takes microseconds, while almost everything goes into waiting for polls, frames and panel physics. That is why latency is reduced by more frequent USB polling and a higher monitor refresh rate, not by a more powerful processor.

What the monitor shows at startup

Run “PC startup” on this level: the monitor goes from “No signal” to the desktop. Until the graphics card is set up, there is no video stream on the cable, and the monitor shows its own message — drawn by the monitor’s controller, not the computer.

Then the firmware sets up the graphics card, and the UEFI screen appears — the logo and POST messages. At this point the image is output by a simple graphics driver in the firmware, and the resolution may be lower than native.

Next come the boot loader and the OS kernel. The graphics driver reconfigures the mode, and the screen briefly goes dark or flickers — this is the switch to the native resolution and refresh rate. Then the desktop appears. In the model, a “Terminal” is open on it with the same teaching program as in the player below — you have seen its instructions inside the processor.

Common misconceptions

“The monitor stores the picture.” The monitor stores almost nothing: it displays a stream that the graphics card continuously sends 165 times a second. Pull out the cable and the image disappears at once.

“The keyboard knows which letter is on a key.” It doesn’t: it transmits the key number, and the layout in the OS chooses the letter.

“A computer reacts instantly.” Between a key press and the letter, 10–50 ms pass — mostly waiting for polls and frames. We don’t notice because we ourselves are slower: human reaction time is about 200 ms.

“A computer that is turned off uses no energy.” As long as the power supply is plugged into the outlet, the standby circuits keep working: 0.5–2 W for the system unit and a little for the monitor in standby mode.

Open in 3D →

All articles

Overviews

Logic: from transistor to arithmetic

Processor

Computer

Servers and data centers

Networks and the internet

Software