OS C1 Computer Organ Review
-
Assembly
-
Lecture notes / computer system concepts / Linux内核完全注释 /
-
Grading Policy:
- 50 final exam(3 A4± cheating sheet)
- 50 project: Linux 0.11/0.12-like OS on RSIC-Ⅴ
- Lab 0 - 6, 50 / Lab 7, 5 bonus
- tutorial
- individual / source code, detailed-report, on courses.zju.edu.cn / delay penalty 20% per day
- NO CHEATING: code similarity
- 0 homework(helpful to final)
Computer Architecture Review
Von Neumann architecture model
- A processor - performs operations and controls all that happens
- A memory - contains code and data
- I/O of some kind
Memory
Data Stored in Memory
- All information in the computer is in binary form
- Claude Shannon’s M.S. thesis
- 0 - zero / 1 - positive voltage
- bit: the smallest unit of information (0 or 1)
- byte: The basic unit of memory
1 Byte = 8 bits
- Each byte in memory is labeled by a unique address
- in 1 machine, all addresses has same length
Both Code and Data in Memory
Once a program is loaded in memory, its address space contains
both code and data.
CPU
-
Registers Files: a collection of word-size registers: the “variables” that hardware instructions work with
- load data from memory / store data from a register
- Operands and results of computations are in registers
- Accessing fast but number limited
-
ALU, Arithmetic and Logic Unit: compute a value
- based on current register values
- store the
+/-/*/÷/AND/OR/XOR/...
result back into a register
-
Program Counter: Points to the next instruction in main memory.
Somehow
pc
is initialized to some content, which is an
address. -
Current Instruction: Holds the instruction currently executed
-
Control Unit: Decodes instructions and make them happen
simplified Cycle: Fetch-Decode-Execute Cycle
- Fetch:
Control Unit
fetches the next instruction frommemory
, usingpc
. - Decode:
cu
decode the instruction and generate control signals to hardwares(e.g. regs/memory/…) and operands- fetch operands
- Execute:
ALU
execute computation and store (back) results.
- Multiple: There are multiple ALUs / caches / multiple CPUs in fact (“cores”).
- Pipelined: 5-stage pipelined cpu.
- Architrcture: Computer architecture research leads to staggering hardware complexity. – Smart things in hardware requires more logic gates and wires (processor cost)!
DMA, Direct Memory Access
DMA is a way for the CPU to let memory-I/O operations (data transfers) occur independently.
- CPU can still do works while
DMA controller
can make data transfer operations independently - CPU simply
- tells the
DMA controller
to initiate a transfer (done by writing to some registers of the DMA controller) - knows transfer completion by the interrupt generated by
DMA
- tells the
DMA
- not completely free, but generally making better performance
Memory BUS using of DMA
and code that CPU executed interfere !
- priority of DMA / CPU?
Cache
Levels of caches: L1 - on
CPU
/ L2 - a sapecialbus
/ L3
registers caches main memory disk complier hardware OS OS
- Hit: a data item is found in a level.
- Miss: a data item is not found in a level. – try next level until
hit
More Hit Rate:
- Temporal Locality: reference addresses recently referenced
- Spatial Locality: reference addresses next to addresses recently referenced
SMP Systems
- Multi-core Chips for Power/heat issue
- Multi-Core: private L1 cache and public L2
- Multi-Proc: public memory and multiple Multi-Cores
Reading material: CSAPP 1.1-1.6
A computer system consists of hardware and systems software that work together to run application programs.
Take hello.c
as instance.
1 |
|
a source program / source file: a sequence of
bits(0/1)
organized inbytes(8-bit chunks)
. Each byte represents some text character (ASCII standard
).text files: consist exclusively of ASCII characters. while All other files are binary files.
All information is represented in binary form, the ONLY way to distinguish is the context in which we view them.
executable object program / file: a sequence of low-level
machine-language instructions
. The high-level individual C statements must be translated by other programs(likecompiler driver
) into those instructions.
The translation may be complicated.
1 |
|
The gcc compiler driver reads source file
and translates it into an executable object file
by the compilation system:
pre-processor: according to directives that begin with
#
modifies the originalC program
, resulting in anotherC program
(text file
)hello.i
.compiler: translates
hello.i
into an assembly-language program(text file
)hello.s
.1
2
3
4
5
6
7main:
subq $8, %rsp
movl $.LC0, %edi
call puts
movl $0, %eax
addq $8, %rsp
retassembler: translates
hello.s
into machine-language instructions, which are packaged inrelocatable object program
and stored in theobject file
(binary file
)hello.o
.linker: handles merging of
.o
s, resulting inexecutable (object file)
hello
, which is ready to be loaded into memory and executed by the system.
Hardware organization
Buses: carry bytes of information back and forth between the components; designed for to transfer words.
word: fixed-size chunks of
bytes
word size: a fundamental system parameter, varying across systems. always
4 bytes/32 bits
or8 bytes/64 bits
.System BUS
/Memory BUS
/I/O BUS
I/O Devices: system’s connection to the external world like keyboard, mouse(input) and display, disk(output). connected to
I/O bus
by eithercontroller: chip sets in the device itself or on the system’s motherboard
motherboard: main printed circuit board
adapter: a card that plugs into a slot on
motherboard
main memory: a temporary storage device that holds both a program and the data it manipulates while the processor is executing the program.
- Physically, consists of a collection of DRAM
- Logically, organized as a linear array of
bytes
, each with its own uniqueaddress
(array index) starting at zero.
Processor: interprets / executes instructions stored in main memory.
- ISA, instruction set architecture: instruction execution model
Caches: designed for processor–memory gap, temporary staging areas for info that
CPU
is likely to need in the near future.Storage Devices: storage at one level serves as a
cache
for storage at the next lower level.shell: a command-line interpreter that cycles like
- prints a prompt
- waits to type a command line:
built-in cmd
/executable
- performs the command.
an application program to run the
executable
on a Unix system.1
linux> ./hello
type
./hello
:shell
reads each one character into a register and then stores in memory.hit the
enter
key:shell
knows the finish of cmd-typing, then loadshello
by executing a sequence of instructions that copies the code and data fromdisk
tomain memory
. (UsingDMA
)Once loading done:
processor
begins executing the instructions inhello program
’s main routine.- copy the
bytes
inhello, world\n
string frommemory
toregister file
- copy from there to the
display device
- copy the
NOTE: The direct access of keyboard/disk relys on the services provided by the operating system. –
Program
can’t access directly!- to protect the hardware from misuse
- to provide applications with simple and uniform mechanisms for manipulating complicated and different low-level hardware devices.
Overview
what is OS?
-
resource abstractor: abstract logical resources from hardware resources.
- Processes:
OS
’s abstraction for a running program. Eachprocess
appears to have exclusive use of the hardware while actually multiple processes run concurrently.
- Processes:
-
resource allocator: decide who and when get resources
OS connects between Hardware layer and App layer.
Start OS
- bootstrap program: stored in ROM, so-called bootloader
- s
Multi-programming
allow multiple jobs: context-switch, OS pick another job to run when one job is ‘waiting’.
- before: single-user mode
- batch processing:
Time-sharing
The running OS
kernel is not a running job
divide the instructions into
- protected instruction
- privileged instruction
1 extra bit to tell CPU the processing mode:
- unprivilege mode: only protected instructions
- privileged mode: all instructions
Modern modes
- RSIC-V: U,S,(Reserved),M
OS Events
Event: an ‘unusual’ change in control flow
OS is switch-likely