aboutsummaryrefslogtreecommitdiff
path: root/notes/hardware.tex
blob: 0141944c703729948a3ad3865fdef2269eaddfb3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
\chapter{Hardware}

\begin{myquote}
Hardware is the wiring and other physical components of a computer.
\end{myquote}

Modern computers have several typical components. There is a
motherboard which has wiring printed on it in order to connect all of
the other components. The central processing unit (CPU) is the main
component that performs the instructions of computer programs.
Graphics and sound cards provide the user with graphics on screen and
sound through headphones or speakers. Input/output ports (I/O ports)
transfer data between input devices such as a mouse or keyboard and
output devices such as a printer or speakers.

A popular I/O connector is the Universal Serial Bus (USB). A bus is a
collection of parallel wires that transmit data as electrical signals.

\section{von Neumann architecture}

\footnote{Prof David Murray, University of Oxford, `A3 Computer
Architecture',
\url{https://www.robots.ox.ac.uk/~dwm/Courses/3CO_2000/3CO-L2.pdf}}
In the 1940s von Neumann's (pronounced Noy-Man, not New-Man) created a
design for general purpose computer, reliant on a CPU alongside
\textbf{a single memory unit for both instructions and data}.
Instructions are executed in series in the `fetch-decode-execute'
cycle. It is very successful due to its need for only one memory unit
and the ability to have general purpose rather than specific purpose
hardware, which early computers were and had to be rewired to change.

The design however does lead to the \textbf{`von Neumann bottleneck'}
as data and instructions must be fetched from the same memory unit
over the same bus.

\section{Boolean logic}

George Boole was able to devise a mathematical representation of
arithmetic using only 1 (True) and 0 (False). Computers use circuits
that can perform this logic by using on and off circuitry to represent
1s and 0s. We can represent these circuits as `gates' and describe the
logic in truth tables to show all possibilities.
Typically we consider:
\begin{itemize}
    \item `And' gates, where the result is true if and only if both of
        the two inputs are true.
    \item 'Or' gates, where the result is true if either of the two
        inputs are true.
    \item 'Not' gates where the result is the inverse of the one input,
        so a 1 becomes a 0 and a 0 becomes a 1.
\end{itemize}

\section{Central processing unit and performance}

The central processing unit (CPU) performs the instructions that we
ask of a computer. It controls data and instructions through the
\textit{fetch-decode-execute} cycle, where an instruction is fetched
from main memory, decoded by the CPU so that it can perform the
correct logic (such as adding two numbers), and then the instruction
is executed giving the output of the instruction (say the result of
the addition).

There are some critical components of the CPU that we typically consider:

\begin{itemize}
    \item The \textbf{control unit} `oversees' the operations of the CPU and
        organises the operations performed and the movement of data
        and instructions.
    \item The \textbf{arithmetic and logic unit} (ALU) carries out the boolean
        logic and mathematics via circuits that are designed to do so.
    \item \textit{Registers} are high speed, small memory locations which hold
        important data.
        \begin{itemize}
            \item The \textit{program counter} is a specific register
                which stores the location in memory of the next
                instruction to be executed.
        \end{itemize}
\end{itemize}

The CPU executes instructions at a rate dictated by the system
\textit{clock}. The \textit{clock speed} determines how many
\textit{clock cycles} (fetch-decode-execute cycles) occur per second.
This is measured in Hertz (Hz), which means times per second. A CPU
in a computer today cycles with a clock speed around 4 GHz or
around 4 billion clock cycles per second
\footnote{7-Zip LZMA Benchmark, Intel Ice Lake:
\url{https://www.7-cpu.com/cpu/Ice_Lake.html}}.

The performance of the CPU can be bettered by:

\begin{itemize}
    \item Increasing the clock speed, so that more clock cycles occur
        per second (overclocking). This does, however, increase power
        consumption and CPU heat production.
    \item Increasing the number of CPU cores. A \textit{multicore} CPU
        has the ability to do multiple cycles at the same time,
        depending on the number of cores and, for programs that have
        the functionality, can perform parallel processing where a
        large algorithm or calculation is distributed between cores,
        thus improving performance.
    \item Increasing cache size, to allow faster access to data and
        instructions.
    \item Increasing cache/memory speed, to allow faster access to data and
\end{itemize}

\section{Memory}

Volatile memory is erased when electrical power to the system is
turned off or interrupted, meaning that all data is lost. Random
access memory (RAM) is reasonably fast and is volatile. RAM holds
current application and operating system data, as well as instructions
for programs that need to be executed.

Read only memory (ROM) is not volatile and cannot be changed by the
system, as the name suggests. Modern computers use ROM to contain the
Basic Input/Output System (BIOS) and other instructions that are
required in the \textit{booting process} of a computer. This performs
tasks such as initialising hardware and initialising the operating
system.

Virtual memory might be necessary when there is insufficient RAM for
data and instructions. This stores data that would be stored in RAM in
secondary storage. \textit{Paging} is the process of swapping chunks
of data between RAM and storage. Because secondary storage is
significantly slower than RAM and due to the paging process, when
virtual memory is necessary, the computer is significantly slowed
down.

\section{Cache}

Cache is memory that is much smaller and more expensive than RAM, but
is significantly faster also. Cache is used to store current
instructions and data in order to increase CPU performance. There are
three levels of cache, each with varying size and speed
\footnote{7-Zip LZMA Benchmark, Apple M1:
\url{https://www.7-cpu.com/cpu/Apple_M1.html}; Intel Ice Lake:
\url{https://www.7-cpu.com/cpu/Ice_Lake.html}}:

\begin{itemize}
    \item Level 1 (L1) cache is very fast and small. It is located
        directly on CPU cores. It is in the range of 64kB.
    \item Level 2 (L2) cache is larger and slower than L1. It is
        shared between CPU cores but is still very close to them, It
        is in the range of 512kB.
    \item Level 3 (L3) cache is significantly slower and larger than
        L2, but is still much faster than normal RAM. It is in the
        range of 8MB.
\end{itemize}

\section{Storage media}

--intro

\subsection{Magnetic storage}

Magnetic storage relies on rotating \textit{platters} coated with
magnetic material. A \textit{read/write head} can move across the
platter. To write data the head contains electromagnets that can give
the magnetic particles a positive or negative charge, representing one
or zero in binary. A platter is divided into \textit{tracks} which are
concentric circles, and segments which are radial divisions. A single
segment on a single track is called a \textit{block}. Data is
generally organised by blocks.

Magnetic storage is high capacity with the highest available capacity
in 2021 being 20TB
\footnote{\url{https://www.tomshardware.com/news/seagate-ships-hamr-hdds-increases-dual-actuator-shipments}}.
Magnetic storage is reasonably cheap and fast. However, the read/write
head of a modern hard drive can be only 5 nm from the platter, which
can spin at up to 15,000 rpm
\footnote{\url{https://en.wikipedia.org/wiki/Hard_disk_drive};
\url{https://en.wikipedia.org/wiki/Flying_height}}. This can create a
lot of noise, power. The moving parts involved can fail and the
read/write head can \textit{crash} into the platter causing
significant data loss, particularly in the case the drive is impacted
when running, such as if a laptop is dropped.

\subsection{Solid state storage}

\textit{Flash} memory chips store data with transistors that can reain
their one or zero sate without power (non-volatile). As there are no
moving parts, they are durable, silent, and portable. They are,
however, very expensive per unit data and risk corruption of data in a
power interruption event.

\subsection{Optical storage}

Optical media (such as a DVD) contains an inwardly spiralling track
with pits and lands (small changes in height) to store data. A LASER
is aimed at the media, and the reflection is captured by a sensor. The
change from a pit to land can represent a zero or a one. This relies
on the laser to be moved very precisely by motors to align with the
track, and for the disc to be rotated at a precise speed (much like
magnetic storage) in order to read data at the correct rate.

Optical storage is very portable and can be read by many devices, but
requires that they have a compatible drive.  However, large quantities
of data are expensive to store and discs can very easily be scratched
or damaged, although error correcting methods are generally used
\footnote{3Blue1Brown, `How to send a self-correcting message':
\url{https://www.youtube.com/watch?v=X8jsijhllIA}}. Reading data from
an optical disc is slower than solid state or magnetic storage.

\subsection{Cloud storage}

Businesses and other organisations (such as schools) traditionally use
servers for data storage of all data and for running services such as
email and websites. This however, depends on skilled IT staff and
expensive equipment and maintenance. Cloud data storage involves the
use of offsite servers around the world, provided by large
organisations providing storage for a monthly cost. This can be
cheaper than an in house operation and provides the benefit of the
server model to individuals such as the ability to access data from
many devices and reliable backups. However, a cloud storage solution
requires a reliable internet connection to access data, can become
expensive for large amounts of data and due to the repeat cost, and
raises philosophical concerns such as those surrounding the ownership
of data.

\section{Embedded systems}

An embedded system
\footnote{\url{https://en.wikipedia.org/wiki/Embedded_system}} is
\textbf{custom built hardware} designed to perform a
\textbf{specific task as part of a wider system}, as opposed to a
general purpose computer.  Examples of embedded systems are visible
all around us, such as in common electricals appliances such as
printers, televisions, and cameras; in household appliances such as
dishwashers and microwaves; and in advanced situations such as engine
management in cars, guidance systems in aeroplanes, and medical
equipment such as an MRI scanner.

Embedded systems generally have no RAM and only have ROM which
contains the \textit{firmware} for the specific program the system
needs. They have \textbf{no operating system}. The have
\textit{sensors} to gather informations about their surroundings (such
as a thermometer or camera) and \textit{actuators} to act on or change
their surroundings (such as the shutter in a camera or the motor in a
washing machine).