Merge branch 'master' of github.com:thomasabishop/computer_science
This commit is contained in:
commit
2da598d3d3
12 changed files with 89 additions and 44 deletions
|
@ -1,26 +1,26 @@
|
|||
---
|
||||
categories:
|
||||
- Electronics
|
||||
tags: [electricity, electrical-fcircuits]
|
||||
tags: [electricity, electrical-circuits]
|
||||
---
|
||||
|
||||
# Circuits
|
||||
|
||||
An electrical circuit is a set of electrical components connected in such a way that current flows in a loop from a voltage source, through the cirucit elements and back to the source.
|
||||
An electrical circuit is a set of electrical components connected in such a way that current flows in a loop from a voltage source, through the circuit elements and back to the voltage source.
|
||||
|
||||
Below is a basic circuit representing a 9-volt [battery]() with a 10,000$\Omega$ resistor attached accross its terminals. Through the application of [Ohm's Law](/Electronics/Physics_of_electricity/Ohms_Law.md) we can determine that the maximum current will be 0.9 miliamps.
|
||||
Below is a basic circuit representing a 9-volt [battery]() with a 10,000$\Omega$ [resistor](/Electronics/Resistance.md) attached accross its terminals. Through the application of [Ohm's Law](/Electronics/Physics_of_electricity/Ohms_Law.md) we can determine that the maximum current will be 0.9 miliamps.
|
||||
|
||||

|
||||
|
||||
## Open and short circuits
|
||||
|
||||
A circuit with a break in its loop is called an **open circuit**. When a circuit is open, no current flows.
|
||||
A circuit with a break in its loop is called an **open circuit**. When a circuit is open, no current flows. We can induce an open circuit through the use of a switch component that closes and breaks the circuit when invoked.
|
||||
|
||||
A **short circuit** is a path in a circuit that allows current to flow with little or no resistance. This is usually unintentional and results in excessive current flowing through the circuit. A short circuit is the opposite to an open circuit. With an open circuit there is an infinite resistance between the two terminals.
|
||||
|
||||
## Vertical circuit diagrams
|
||||
|
||||
Sometimes circuits can be represented in a vertical manner rather than in an actual circuit. In this approach current is represented as flowing in a straight line from the voltage source (represented with a circle) to ground.
|
||||
Sometimes circuits can be represented in a vertical manner rather than in an actual circuit. This is done to simplify the representation. In this approach current is represented as flowing in a straight line from the voltage source (represented with a circle) to ground.
|
||||
|
||||
The circuit below is functionally identical to the previous circuit but represented vertically:
|
||||
|
||||
|
|
|
@ -1,20 +1,17 @@
|
|||
---
|
||||
title: Switches and transistors
|
||||
categories:
|
||||
- Computer Architecture
|
||||
- Electronics
|
||||
- Hardware
|
||||
tags: [logic-gates, binary, memory]
|
||||
tags: [electrical-circuits]
|
||||
---
|
||||
|
||||
# Switches and transistors
|
||||
# Digital circuits
|
||||
|
||||
Ultimately every process in a computer is the product of a digital [circuit](/Electronics/Circuits.md) that is working on binary values. In contrast to electrical circuits, digital circuits are not represented in an [analogue](/Hardware/Analogue_and_digital.md) fashion.
|
||||
|
||||
Analogue circuits work on the basis of real continuous phenomena in the world: charges and currents. As a result, the key properties of a circuit - voltage, current and resistance - can vary over a wide range of values. This is the reason that we require components like batteries and resistors: to control the natural flow of current and ensure that it only runs within desired parameters.
|
||||
|
||||
In a standard electrical circuit, voltage, current and resistance can vary over a wide range of values however in the binary context we want to deal with discrete values (zeros and ones) which can be fed into the various [logic gates](/Hardware/Logic_Gates/Logic_gates.md).
|
||||
|
||||
We therefore need a way to represent 'on' and 'off' as single quantities. We do this by stipulating that a given voltage corresponds to 'on' (high) and another corresponds to 'off' (low). Of course these are not really discrete values since voltage is inherently analogue but we basically binary-encode them. Formally 'on' has a voltage of 1 and 'off' has a voltage of 0. In reality 'on' tends to be within 2-5V depending on the circuit design and anything between 0 - 0.8V is considered off.
|
||||
|
||||
## Implementing binary logic with mechanical switches
|
||||
|
||||
## Transistors
|
||||
The [transistor](/Electronics/Switches_and_transistors.md) is the electrical component that enables us to represent given voltage ranges as being 'on' or 'off'.
|
17
Electronics/LEDs.md
Normal file
17
Electronics/LEDs.md
Normal file
|
@ -0,0 +1,17 @@
|
|||
---
|
||||
categories:
|
||||
- Electronics
|
||||
tags: [electricity, electrical-circuits]
|
||||
---
|
||||
|
||||
# LEDs
|
||||
|
||||
LED' stands for **Light Emitting Diode**, a [circuit]() component that emits light. The symbol for an LED is displayed below:
|
||||
|
||||

|
||||
|
||||
A **diode** is a special kind of component that only permits current to flow through it in one direction. To achieve this it has very low resistance in one direction to allow current flow and high resistance in the other direction to impede current flow. This feature of diodes is clearly represented in the generic diode circuit symbol:
|
||||
|
||||

|
||||
|
||||
An LED diode lights up when the right amount of current flows through it. A standard LED has a maximum current of 20mA. An appropriate [resistor](/Electronics/Resistance.md#resistors) must therefore be added to the circuit to ensure the current doesn't exeedd this amount.
|
|
@ -43,3 +43,5 @@ The relationship between current, resistance and voltage is expressed in [Ohm's
|
|||
## Resistors
|
||||
|
||||
A resistor is an electrical component that can be used in circuits to introduce specific amounts to resistance where needed. This is typically done in order to temper the total voltage and so keep the current flowing within certain set parameters.
|
||||
|
||||
// TODO: Add image of different resistor types and further info on their differences and the physics behind how they work.
|
||||
|
|
24
Electronics/Switches_and_transistors.md
Normal file
24
Electronics/Switches_and_transistors.md
Normal file
|
@ -0,0 +1,24 @@
|
|||
---
|
||||
title: Switches and transistors
|
||||
categories:
|
||||
- Computer Architecture
|
||||
- Electronics
|
||||
- Hardware
|
||||
tags: [logic-gates, binary, memory]
|
||||
---
|
||||
|
||||
# Switches and transistors
|
||||
|
||||
In the discussion of [digital circuits](/Electronics/Digital_circuits.md) we noted that a digital circuit requires that electrical phenomena be treated as discrete rather than continuous values. Although a given voltage at a point in the circuit can vary widely, in order to represent the binary states of 'on' and 'off' we need it to remain fixed within certain narrow parameters. Typically a value between 2V - 5V for the 'on' state and 0V - 0.8V.
|
||||
|
||||
We will look at two ways to achieve this. Firstly with literal switches which are impractical but useful for understanding the concept and then with transistors which are what are actually used in computers.
|
||||
|
||||
## Implementing binary logic with mechanical switches
|
||||
|
||||
An electrical switch is inherently binary. When the switch is on, it acts like a simple copper wire through which current flows freely. When the switch is off, it acts like an open circuit and no current can flow.
|
||||
|
||||
We can combine switches in a circuit to create analogs to logic gates.
|
||||
|
||||
- Example of AND and OR
|
||||
|
||||
## Transistors
|
|
@ -6,6 +6,8 @@ tags: [CPU, electromagnetism]
|
|||
|
||||
# CPU architecture
|
||||
|
||||
At the core of a computer sits the Central Processing Unit. This is the assembly of chips that execute all computation. Instructions are passed to the CPU along the data bus part of the system bus from the memory. The [kernel](/Operating_Systems/The_Kernel.md), also residing in memory sequences and schedules the sending of data to the CPU and manages requests from the CPU for data in memory.
|
||||
|
||||
The CPU comprises three core components:
|
||||
|
||||
- Registers (a form of memory that are positioned on the same chip as the CPU )
|
||||
|
@ -16,9 +18,9 @@ The CPU comprises three core components:
|
|||
|
||||
## Registers
|
||||
|
||||
This is the part of the CPU that stores data. The memory cells that comprise it do not have capacitors (unlike RAM) so they cannot store very much data but they work faster, which is what is important.
|
||||
This is the part of the CPU that stores data. The memory cells that comprise it do not have [capacitors](/Hardware/Memory/Memory.md) (unlike RAM) so they cannot store very much data but they work faster, which is what is important.
|
||||
|
||||
In terms of speed, registers sit at the top part of the overall memory hierarchy...
|
||||
In terms of speed, registers sit at the top part of the overall [memory hierarchy](/Hardware/Memory/Memory.md#the-memory-hierarchy).
|
||||
|
||||
There are five main types of register in the CPU:
|
||||
|
||||
|
@ -32,9 +34,9 @@ There are five main types of register in the CPU:
|
|||
|
||||
## Arithmetic Logic Unit
|
||||
|
||||
This is the hub of the CPU, where the binary calculations occur. It comprises [logic gates](/Hardware/Logic_Gates/Logic_gates.md) that execute the instructions passed from memory. This is where the data stored by the registers is acted upon..
|
||||
This is the hub of the CPU, where the binary calculations occur. It comprises [logic gates](/Hardware/Logic_Gates/Logic_gates.md) that execute the instructions passed from memory. This is where the data stored by the registers is acted upon.
|
||||
|
||||
It can execute arithmetic on binary numbers and logical operations.
|
||||
It can execute arithmetic on binary numbers and logical operations. This is where you will find operations conducted by adders and half-adders etc.
|
||||
|
||||
This is the heart of the CPU; all the other components on the CPU chip are appendanges to the execution that occures within the ALU. It is also what is meant by the **core** processor that is referred to in hardware specs of computers, for instance _dual-core_, _quad core_ etc.
|
||||
|
||||
|
@ -52,11 +54,9 @@ With Intel processors the two main consumer processors are the i5 and i7. The la
|
|||
|
||||
The CPU's [controller](/Hardware/Chipset_and_controllers.md). It takes the instructions in binary form from RAM memory (separate from the CPU, but connected) and then signals to the to ALU and memory registers what it is supposed to do to execute the instructions. Think of it as the overseer that gets the ALU and registers to work together to run program instructions.
|
||||
|
||||
## Fetch, decode, execute
|
||||
|
||||
## The system clock
|
||||
|
||||
Whilst modern CPUs and threading make it appears as though the CPU is capable of running multiple processes at once, access to the CPU is in fact sequential. The illusion of simultaneous computation is due to the fact the processor is so fast that we do not detect the sequential changes. For this to happen, the CPU needs to have a means of scheduling and sequencing processes. This is made possible through the system clock, hence when talking about the speed of the CPU we do so with reference to _clock speeds_ and the _clock cycle_.
|
||||
Whilst modern CPUs and multithreading make it appear[] as though the CPU is capable of running multiple processes at once, access to the CPU is in fact sequential. The illusion of simultaneous computation is due to the fact the processor is so fast that we do not detect the sequential changes. For this to happen, the CPU needs to have a means of scheduling and sequencing processes. This is made possible through the system clock, hence when talking about the speed of the CPU we do so with reference to _clock speeds_ and the _clock cycle_.
|
||||
|
||||
The clock's circuitry is based on a quartz crystal system like that used in watches. At precisely timed intervals, the clock sends out pulses of electricity that cause bits to move from place to place within [logic gates](/Hardware/Logic_Gates/Logic_gates.md) or between logic gates and [registers](/Hardware/CPU/CPU_architecture.md#registers).
|
||||
|
||||
|
@ -64,12 +64,16 @@ Simple instructions such as add can often be executed in just one clock cycle, w
|
|||
|
||||
We measure the speed of a chip process within the CPU in **Hertz (Hz)**. One Hertz is equivalent to _1 cycle per second_ where a "cycle" is equivalent to a single clock **tick**. Thus a tick covers a period of 1 second.
|
||||
|
||||
A speed of 2GHz for example means two billion cycles per second. This would mean that the clock was completing two billion cycles at each tick.
|
||||
A speed of 2GHz for example means two billion cycles per second. This would mean that the clock was completing two billion cycles at each tick. It is clock speed that is being referred to when computers are marketed in terms of the number of Hz a processor possesses.
|
||||
|
||||
## Processing cycles
|
||||
|
||||
Each "cycle" is the execution of a process that commences once the [kernel](/Operating_Systems/The_Kernel.md) hands control to the CPU. Each cycle follows a sequence of events known as [fetch, decode, and execute](/Hardware/CPU/Fetch_decode_execute.md).
|
||||
|
||||
## Electromagnetism: broader scientific context
|
||||
|
||||
Hertz was the scientist who detected electromagentic waves and more broadly in science, we use Hertz to measure the number of electromatic waves (cycles) in a signal.
|
||||
Hertz was the scientist who detected electromagentic waves and more broadly in science, we use Hertz to measure the frequency of electromatic wave cycles in a signal.
|
||||
|
||||

|
||||
|
||||
As the diagram above shows, a cycle is equal to one ascending and one descending crest. The more cycles the greater the Hertz.
|
||||
As the diagram above shows, a cycle is equal to one ascending and one descending crest. The more cycles per time unit, the greater the Hertz. We see the Hz increase as the number of cycles increases over time.
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
---
|
||||
categories:
|
||||
- Computer Architecture
|
||||
tags: [CPU]
|
||||
---
|
||||
|
||||
# CPU: Introduction
|
||||
|
||||
At the core of a computer sits the Central Processing Unit. This is the assembly of chips that execute all computation. Instructions are passed to the CPU along the data bus part of the system bus from the memory. The [kernel](/Operating_Systems/The_Kernel.md), also residing in memory sequences and schedules the sending of data to the CPU and manages requests from the CPU for data in memory.
|
|
@ -5,13 +5,12 @@ categories:
|
|||
tags: [motherboard, chipset]
|
||||
---
|
||||
|
||||
|
||||
# Chipset and controllers
|
||||
|
||||
A **controller** is simply a circuit that controls a process. The **chipset** is a combination of controllers placed on the same piece of silicon.
|
||||
|
||||
The chipset manages the data flow between the different components that comprise the [motherboard](/Hardware/Motherboard.md): processor, [memory](/Hardware/Memory/RAM_types.md), [harddisk](/Operating_Systems/Disks/What_are_disks.md) and peripherals.
|
||||
The chipset manages the data flow between the different components that comprise the [motherboard](/Hardware/Motherboard.md): processor, [memory](/Hardware/Memory/Memory.md), [harddisk](/Operating_Systems/Disks/What_are_disks.md) and peripherals.
|
||||
|
||||
Buses run in and out of the chipset into these key motherboard components. The main chipset is a kind of junction that sits between the memory and CPU through which the [system bus](/Hardware/Bus.md#system-bus) passes.
|
||||
Buses run in and out of the chipset into these key motherboard components. The main chipset is a kind of junction that sits between the memory and CPU through which the [system bus](/Hardware/Bus.md#system-bus) passes.
|
||||
|
||||
The chipset is sometimes called the "glue" or "traffic controller" of the motherboard or _an intelligent intersection of buses_.
|
||||
|
|
|
@ -11,29 +11,39 @@ In essence the memory is just a temporary and volatile storage area for a series
|
|||
|
||||
> This is where the running kernal and processes reside - they're just big collections of bits. A CPU is just an operator on memory. It reads its instructions and data from the memory and writes back out to the memory. (Ward 2021)
|
||||
|
||||
Technically, the harddisk is also memory but nonvolatile although we typically distinguish "disk storage" from memory. We can think of memory as active storage that is utilised during runtime and disk memory as dormant storage that only becomes active once it is loaded into memory.
|
||||
Technically, the harddisk is also memory of a non-volatile sort however we typically distinguish "disk storage" from memory. We can think of memory as active storage that is utilised during the runtime of a program and disk memory as dormant storage that only becomes active once it is loaded into memory.
|
||||
|
||||
Programs that are executing are loaded into memory because the chips that comprise memory can read and store data much faster than the harddisk. It would be possible to run a program from the harddisk but it would be 500 - 1000 times slower than memory.
|
||||
|
||||
## Memory types
|
||||
|
||||
### DRAM
|
||||
|
||||
When we think of memory we generally think of the _main_ memory: the 8GB or 16GB+ slots of volatile, non-permanent storage that is utilised by the CPU during the runtime of programs. This is DRAM memory: Dynamic Random Access memory. DRAM uses capacitors that lose charge over time due to leaks. As a result DRAM is memory that needs to be refreshed (recharged) frequently. For this reason and because it only uses one transistor and capacitor per bit, DRAM is the less expensive form of volatile memory.
|
||||
When we think of memory we generally think of the _main_ memory: the 8GB or 16GB+ slots of volatile, non-permanent storage that is utilised by the CPU during the runtime of programs. This is DRAM memory: Dynamic Random Access memory. DRAM uses capacitors that lose [charge](/Electronics/Current.md) over time due to leaks. As a result DRAM is memory that needs to be refreshed (recharged) frequently. For this reason and because it only uses one transistor and capacitor per bit, DRAM is the less expensive form of volatile memory.
|
||||
|
||||
### SRAM
|
||||
// TODO: Add notes in Electronics on capacitors
|
||||
|
||||
### SRAM
|
||||
|
||||
SRAM (Static Random Access Memory) is also volatile memory but, in terms of the electronics, it is different in its implementation. In contrast to DRAM it doesn't use capacitors. As a result the transistors do not leak and therefore do not need to be refreshed, hence why SRAM is _static_ and DRAM is _dynamic_. It also uses multiple transistors per bit. This makes it faster than DRAM but more expensive. DRAM is at least ten times slower than SRAM. SRAM is used as [cache memory](/Hardware/Memory/Role_of_memory_in_computation.md#the-role-of-the-cache) on the [motherboard](/Hardware/Motherboard.md) of which there are two types: L1 (on the processor chip) and L2 (separate from the processor).
|
||||
|
||||
SRAM (Static Random Access Memory) is also volatile memory but, in terms of the electronics, it is different in its implementation. In contrast to DRAM it doesn't use capacitors. As a result the transistors do not leak and therefore do not need to be refreshed, hence why SRAM is _static_ and DRAM is _dynamic_. It also uses multiple transistors per bit. This makes it faster than DRAM but more expensive. DRAM is at least ten times slower than SRAM. SRAM is used as [cache memory](/Hardware/Memory/Role_in_computation.md#the-role-of-the-cache) on the [motherboard](/Hardware/Motherboard.md) of which there are two types: L1 (on the processor chip) and L2 (separate from the processor).
|
||||
### Relative speeds
|
||||
|
||||
The table below details the relative speeds of the different types of memory and those of other types of motherboard storage.
|
||||
|
||||
| Storage type | Access speed (clock cycles) | Relative times slower |
|
||||
|--------------|-----------------------------|-----------------------|
|
||||
| ------------ | --------------------------- | --------------------- |
|
||||
| CPU register | 2 | |
|
||||
| L1 cache | 4 | 2x |
|
||||
| L2 cache | 6-20 | 3-10x |
|
||||
| DRAM memory | 50 | 25x |
|
||||
| Harddisk | 2000 | 1000x |
|
||||
|
||||
## The memory hierarchy
|
||||
|
||||
The diagram below compares the different forms of memory within a computing device in terms of speed, monetary cost and capacity:
|
||||
|
||||

|
||||
|
||||
## References
|
||||
|
|
@ -11,7 +11,7 @@ The following steps outline the way in which memory interacts with the processor
|
|||
1. A file is loaded from the harddisk into memory.
|
||||
2. The instruction at the first address is sent to the CPU, travelling accross the data bus part of the [system bus](/Hardware/Bus.md#system-bus).
|
||||
3. The CPU processes this instruction and then sends a request accross the address bus part of the system bus for the next instruction to the memory controller within the [chipset](/Hardware/Chipset_and_controllers.md).
|
||||
4. The chipset finds where this instruction is stored within the [DRAM](/Hardware/Memory/RAM_types.md#dram) and issues a request to have it read out and send to the CPU over the data bus.
|
||||
4. The chipset finds where this instruction is stored within the [DRAM](/Hardware/Memory/Memory.md#dram) and issues a request to have it read out and send to the CPU over the data bus.
|
||||
|
||||
> This is a simplified account; it is not the case that only single requests are passed back and forth. This would be inefficient and time-wasting. The kernel sends to the CPU not just the first instruction in the requested file but also a number of instructions that immediately follow it.
|
||||
|
|
@ -77,8 +77,8 @@ procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
|
|||
- The core memory output distinguishing:
|
||||
- Total kbs swapped to disk
|
||||
- Total kbs free
|
||||
- Total kbs currently in [buffer](/Hardware/Memory/Role_in_computation.md#relation-between-cache-and-buffers) and not written
|
||||
- Total amount of virtual memory in the [cache](/Hardware/Memory/Role_in_computation.md#relation-between-cache-and-buffers)
|
||||
- Total kbs currently in [buffer](/Hardware/Memory/Role_of_memory_in_computation.md#relation-between-cache-and-buffers) and not written
|
||||
- Total amount of virtual memory in the [cache](/Hardware/Memory/Role_of_memory_in_computation.md#relation-between-cache-and-buffers)
|
||||
- `swap`
|
||||
- Distinguishes amount of memory [swapped](/Operating_Systems/Disks/Swap_space.md) in (`si`) to memory and swapped out (`so`) to disk
|
||||
- `io`
|
||||
|
@ -136,7 +136,7 @@ This will typically be the same for all Linux systems.
|
|||
|
||||
### `free` : available physical memory
|
||||
|
||||
`free` displays the total amount of free and¬used physical and swap memory in the system, as well as the [buffers and caches](/Hardware/Memory/Role_in_computation.md#relation-between-cache-and-buffers) used by the kernel.
|
||||
`free` displays the total amount of free and¬used physical and swap memory in the system, as well as the [buffers and caches](/Hardware/Memory/Role_of_memory_in_computation.md#relation-between-cache-and-buffers) used by the kernel.
|
||||
|
||||
```bash
|
||||
$ free
|
||||
|
|
1
Resources.md
Normal file
1
Resources.md
Normal file
|
@ -0,0 +1 @@
|
|||
https://runestone.academy/ns/books/published/welcomecs/index.html
|
Loading…
Add table
Reference in a new issue