summaryrefslogtreecommitdiff
path: root/doc/1.md
blob: b912a6bd2a0af178bb0e20c67ccdd8a0882a41f1 (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
# Chapter 1

> An operating system is a program that manages the computer hardware.

4 high level components:

* hardware
  * CPU, memory, I/O devices provide computing resources for the system.
* operating system
  * controls the hardware and coordinates its use among the various applicatoin programs for the various users.
* application programs
  * word processors, spreadsheets, compilers, web browsers define ways to use resources to solve users' computer problems.
* users

We can also view a computer system as:

* hardware
* software
* data

The OS provides the mans for proper use of these resources in the operation of the computer system.
The OS performs no useful function by itself.
It provides an environment within which other programs can do useful work.

## User View

Most computer users sit in front of a PC that has

* a monitor
* keyboard
* mouse
* and system unit

Another usage is where a user sits at a terminal connected to a mainframe
or a minicomputer. Other users access the same computer through other terminals.
These users share resources and may exchange information.

The operating system is the one program running at all times on the computer - usually called the kernel.
Along with the kernel there are systems programs, which are associated with the operating system but are not part of the kernel, and application programs, which include all programs not associated with the operation of the system.

1. bootstrap program stored in ROM or EEPROM known as firmware.
  * initializes CPU registers, device controllers, memory contents.
  * must know how to load the operating system
  * must load the operating system kernel
  * execute first process known as init.
* occurrence of an event is signaled by an interrupt from either hardware or software.
* hardware may send signal to CPU to trigger an interrupt via the system bus.
* software may trigger an interrupt by executing system calls.
* when a CPU is interrupted it stops what it is doing and immediately transfers execution to a fixed location.
The fixed location usually contains the starting address where the service routine for the interrupt is located.
Interrupts must be handled quickly so only a predefined # of interrupts is possible.

> Interrupt vector: table of interrupt addresses.

The CPU can load instructions only from memory, so any programs to run must be stored there.
All forms of memory provide an array of words. Each word has its own address.
Interaction is achieved through a sequence of `load` or `store` instructions to specific memory addresses.
The `load` instruction moves a word from main memory to an internal register within the CPU, whereas the
`store` instruction moves the content of a register to main memory.

von Neumann architecture:
1. fetch instruction from memory and store that instruction in the instruction register.
2. decode instruction. may cause operands to be fetched from memory and stored in some internal register.
3. execute instruction
4. store result back in register

Memory unit only sees a stream of memory addresses.

Ideally, we want programs and data to reside in main memory. This
is usually not possible because:

1. main memory is usually too small to store all needed programs and data permanently.
2. main memory is a volatile storage device that loses its contents when power is removed.

Most computer systems use secondary storage as an extension of main memory.
Secondary storage must be able to hold large quantities of data permanently.

The magnetic disk is a common secondary storage device.
Most programs are stored on disk until they are loaded into memory.

## Computer System Architecture

Single-Processor Systems: one main CPU
Multiprocessor System: have two or more processors in close communication sharing the computer bus, clock, memory and peripheral devices.

Multiprocessor systems have three main advantages:

1. Increased throughput: more work done in less time.
2. Economy of scale: can cost less because they share peripherals, storage, and power.
3. Increased reliability: failure of one processor will not halt the system. only slow it down

Symetric Multi Processor (SMP): Solaris is a commercial version of UNIX designed by Sun Microsystems. Many processors can run simultaneously.
Uniform Memory Access (UMA): access to any RAM from any CPU takes the same amount of time.
Non-uniform Memory Access (NUMA): some parts of memory may take longer to access than other parts.

Another trend is to include multiple cores on a single chip. These are like multiprocessor chips.
On chip communication is faster than a single core per chip.
One chip with multiple cores also uses less power than multiple single-core chips.


Dual core design:

```plaintext
   ------------------------------------
   | ---------------  --------------- |
   | | CPU core0   |  | CPU core1   | |
   | | ----------- |  | ----------- | |
   | | |registers| |  | |registers| | |
   | | ----------- |  | ----------- | |
   | |      |      |  |     |       | |
   | | ----------- |  | ----------- | |
   | | |  cache  | |  | |  cache  | | |
   | | -----|----- |  | -----|----- | |
   | -------|-------  -------|------- |
   ---------|----------------|---------
            ------------------
                    |
                ----------
                | memory |
                ----------
```

Job pool

```plaintext
 0   |------------------|
     | operating system |
     |------------------|
     | job 1            |
     |------------------|
     | job 2            |
     |------------------|
     | job 3            |
     |------------------|
     | job 4            |
512M |------------------|
```

Operating schedules a job to put into memory to execute.
When the job needs to wait for an I/O operation to complete
the operating system switches to another job and so on.
As long as at least one job needs to execute then the CPU is never idle.

In time-sharing systems, the CPU executes multiple jobs
by switching among them, but the switches occur so frequently that
the users can interact with each program while it is running.

A program laoded into memory and executing is called a process.
When a process executes, it typically executes for only a short time
before it either finishes or needs to perform I/O.