Download as pdf or txt
Download as pdf or txt
You are on page 1of 306

CPU

I/O

shell

Win 32 API

-
UNIX
Windows

POSIX

Peterson
TSL

Futexes
Pthreads
-

- -

TLB
LRU

inode

inode
I/O
I/O

I/O
I/O

DMA

IO
I/O

I/O
I/O
DMA I/O
I/O

I/O

I/O

RAID
-
RR

RAID
DMA
/
Windows Linux FreeBSD OS X
(Graphical User Interface, GUI)
Shell

(shell GUI)
Web
CPU I/O

CPU
CPU CPU

CPU x86 CPU ARM ARM


CPU x86
CPU

add

(program counter)

(stack pointer)

PSW(Program Status Word)


8 (64 ) long
PSW PSW PSW I/O

(time multiplexing) CPU

CPU CPU
CPU
CPU N N+1 N+2
(pipeline)
(superscalar) CPU CPU

CPU CPU
PSW
CPU

CPU
I/O
PSW

(system call)
TRAP
Intel Pentinum 4 (multithreading)
(hyperthreading, Intel ) x86 CPU
SSPARC Power5 Intel Xeon Intel Core CPU
(nanosecond)
( ) CPU

CPU
CPU CPU 4
CPU

CPU
CPU

L2 4
L2 4

GPU(Graphics Processing Unit) GPU

(
CPU )
CPU CPU CPU

(cache lines) 64
0 - 63 0 64 - 127 1
CPU CPU

(cache hit)

RAM

RAM

/home/ast/projects/minix3/src/kernel/clock.c
Web (URL) (IP
)

CPU

CPU L1 cache
CPU CPU
L1 cache L1 cache 16 KB
L2 cache L1 cache L2 cache
L1 cache L2 cache 1-2
CPU

Hz MHz GHz 4 GHz


4,000,000,000

CPU

RAM(Random Access
Memory) 1950 1960

RAM
ROM(Read Only Memory)
ROM
bootstrap ROM
I/O ROM

EEPROM(Electrically Erasable PROM,) (flash memory)


ROM RAM
ROM ROM

RAM

CMOS CMOS

( ) RAM
5400rpm 7200rpm 10800rpm
33

(track)
(cylinder)
512
1ms 5ms
10ms
50MB/s 160MB/s

(Solid State Disk, SSD)

RAM
CPU (Memory Management Unit, MMU)

MMU
(context switch)

I/O
CPU I/O
I/O

I/O
SATA SATA
ATA (AT Attachment) SATA
(Serial ATA)

AT IBM 1984 6MHz


80286

20

SATA

(device driver)

UNIX

Windows

USB IEEE 1394

I/O

I/O
I/O
IN OUT
I/O

I/O
I/O
(busy waiting)
CPU CPU I/O I/O

I/O
2

CPU 3

CPU

CPU
CPU PSW CPU

(interrupt vector)
PSW

I/O (Direct Memory Access, DMA)


CPU CPU DMA
DMA

CPU
CPU
CPU

IBM PC
IBM
PC I/O CPU
x86

x86 PCIe PCI USB SATA DMI

PCIe(Peripheral Component Interconnect Express)

Intel PCIe PCI PCI


ISA(Industry Standard Architecture) Gb/s
PCIe PCIe 2004
(shared bus architeture)
PCIe
PCI (parallel bus architecture)
PCI 32 32
PCIe (serial bus architecture)

32
32 32

CPU DDR3 PCIe GPU


DMI(Direct Media Interface)
USB SATA DVD PCIe

USB(Univversal Serial Bus) I/O


USB 1.0 12 Mb/s USB 2.0 480Mb/s USB 3.0
5Gb/s USB
SCSI(Small Computer System Interface)
640MB/s

BIOS I/O

(Basic Input Output System, BIOS) BIOS


I/O I/O
BIOS

(booted) BIOS RAM


PCIe PCI

BIOS CMOS

CMOS Complementary Metal Oxide Semiconductor

RAM BIOS

BIOS BIOS
BIOS BIOS
CMOS

BIOS
CD-ROM USB boots

BIOS
CD-ROM Internet

GUI
I/O 1000 G
Web

Web Internet Web


Web Solaris FreeBSD Linux Windows Server
201x

CPU

Windows Linux

Internet Linux FreeBSD Windows 7 Windows 8 OS X

PDA(Personal Digital Assistant)


Android IOS

DVD MP3
ROM
Linux QNX VxWorks
CPU RAM ROM

CPU
Java
ROM Java Java Virtual Machine, JVM

UNIX

(Process)
(address space) ( )

(registers)
(program counter) (stack pointer)

Web

CPU CPU

read

(process table)
core image

(command interpreter) shell


shell

A B C B
D E F

(interprocess
communication)

(alarm signal)
UID(User IDentification)
UID UID
GID(Group IDentification)

UNIX UID (superuser) Windows


(administrator)

32 64 2^32 2^64

I/O

(directory)
(Root directory)
(path name)
CS101
/Faculty/Prof.Brown/Courses/CS101 /

Windows \ Linux /

(working directory)
/Faculty/Prof.Brown
/Courses/CS101

(file descriptor)
UNIX (special file) I/O
I/O
(block special file) (character
special file)
4 4

/dev /devv/lp

(pipe)

A B A B
UNIX

UNIX UNIX 9 UNIX

rwx rwxr-x--x

shell

UNIX
shell shell

shell sh csh ksh bash shell


sh

shell
(prompt) ($) shell

1 date
shell date shell
shell

1 date > file

1 sort <file1> file2

sort file1 file2

1 cat file1 file2 file3 | sort > /dev/lp

cat sort sort


/dev/lp

CPU

read

C
read

1 count = read(fd,buffer,nbytes);

count nbytes

count -1
errno

read
read(fd, buffer, nbytes) 11

C C++ printf( )
&
C read

TRAP
TRAP

TRAP

TRAP
TRAP
8

TRAP dispatch

TRAP

(increment stackpointer)
read read
TRAP

POSIX POSIX 100

pid = fork()

pid = waitpid(pid, &statloc,options)

s = execve(name,argv,environp)

exit(status)

fd = open(file, how,...)

s = close(fd)

n = read(fd,buffer,nbytes)

n = write(fd,buffer,nbytes)

position = iseek(fd,offset,whence)

s = stat(name,&buf)

s = mkdir(nname,mode)

s = rmdir(name)

s = link(name1,name2) name2, name1

s = unlink(name)

s = mount(special,name,flag)

s = umount(special)
s = chdir(dirname)

s = chmod(name,mode)

s = kill(pid, signal)

seconds = time(&seconds) 1970 1 1

pid id fd n
position seconds

UNIX fork POSIX


fork fork

fork 0
(Process IDentified,PID) PID
fork

waitpid
waitpid -1
waitpid statloc

shell fork shell fork


execve
fork waitpid
execve

1 #define TRUE 1
2
3 /* */
4 while(TRUE){
5
6 /* */
7 type_prompt();
8
9 /* */
10 read_command(command,parameters)
11
12 /* fork */
13 if(fork() != 0){
14
15 /* */
16 /* */
17 waitpid(-1, &status, 0);
18 }else{
19
20 /* */
21 /* */
22 execve(command,parameters,0)
23 }
24 }

execve

shell

1 cp file1 file2

file1 file2 shell fork

cp C

1 main(argc,argv,envp)

argc argc 3
argv i i
argv[0] cp argv[1] file1 argv[2] file2 main
name = value

execve 0 execve 0

execve execve POSIX


exit
0 - 255 waitpid
statloc

UNIX text segment, data segment


stack segment
brk
POSIX
malloc malloc

O_RDONLY O_WRONLY O_RDWR


O_CREATE
close
open

read write read write read

Iseek read write

Iseek position = iseek(fd,offset,whence)

Iseek
UNIX
stat s = stat(name,&buf)

fstat

mkdir
rmdir s = mkdir(nname,mode) s = rmdir(name)
s = link(name1,name2)
link link

ast jim ast

1 link("/usr/jim/memo", "/usr/ast/note");

jim memo ast note /usr/jim/memo


/usr/ast/note

/usr /user /home

link link UNIX


i - number i- i- i-nodes,i-
i
ASCII UNIX 16 2 i
- 14
i- ASCII mail i- 16 link
i- b
70 i- unlink
UNIX
i-

mount s = mount(special,name,flag)

USB

mount USB
a b

1 mount("/dev/sdb0","/mnt",0)

USB 0

umount

chdir chdir

1 chdir("/usr/ast/test");

xyz /usr/ast/test/xyz

UNIX - -
chmod

1 chmod("file",0644);

kill

POSIX time 0 1970 1 1


32 time (2^32) - 1 136
2106 32 UNIX 32 UNIX 2106 64

Win 32 API
UNIX Win 32 Windows UNIX
UNIX
Windows Windows
USB UNIX

Windows UNIX read


read Windows
Win32 (Application
Programming Interface) Windows
95 Windows

Win32 API
Win32 API
GUI

Win32 Win32 API UNIX


UNIX Win32

fork CreateProcess

waitpid WaitForSingleObject

execve none CraeteProcess = fork + servvice

exit ExitProcess

open CreateFile

close CloseHandle

read ReadFile

write WriteFile

lseek SetFilePointer

stat GetFileAttributesEx

mkdir CreateDirectory

rmdir RemoveDirectory

link none Win32 link

unlink DeleteFile

mount none Win32 mount

umount none Win32 mount mount

chdir SetCurrentDirectory

chmod none Win32

kill none Win32

time GetLocalTime

UNIX Win32 API CreateProcess


UNIX fork execve
Windows UNIX
WaitForSingleObject

ExitProcess

6 UNIX UNIX
SetFilePointer GetFileAttributesEx
Windows CreateDirectory RemoveDirectory API
SetCurrentDirectory GetLocalTime

Win32 mount umount stat Win32


UNIX GUI

I/O
UNIX (shared library)
Windows (Dynamic Link Library,DLL) .dll
C:\Windows\system32 1000 DLL C
E.W.Dijkstar THE

3 /

2 -

0 0
1
1

2 3 I/O
4 I/O
5
-

--- ---

MINIX 3

MINI 3

I/O I/O I/O


I/O

(reincarnation server)

-
-

PC web
PC Web Web
-
CPU CPU CPU
CPU
Web Web

CPU

PC

CD-ROM

CPU
CPU 1
(pseudoparallelism)
( CPU )

CPU CPU
CPU

(sequential
processes) (process)
CPU
CPU

4
4 4

CPU 2 CPU

CPU CPU
CPU CPU

CPU

CPU

init
fork
(numerous processes)

e-mail web
(daemons) UNIX ps
Windows

CPU

UNIX X Windows

web IDE

UNIX fork
fork
execve
shell sort shell fork
sort fork execve

Windows Win32 CreateProcess


10

CreateProcess Win
32 100 UNIX
Windows
UNIX Win32

fork CreateProcess

waitpid WaitForSingleObject

execve none CraeteProcess = fork + servvice

exit ExitProcess

open CreateFile

close CloseHandle

read ReadFile

write WriteFile

lseek SetFilePointer

stat GetFileAttributesEx

mkdir CreateDirectory

rmdir RemoveDirectory

link none Win32 link

unlink DeleteFile

mount none Win32 mount

umount none Win32 mount mount

chdir SetCurrentDirectory

chmod none Win32

kill none Win32

time GetLocalTime

UNIX Windows
UNIX
UNIX

(copy-on-write)

Windows
( )
( )
( )
( )

UNIX exit Windows ExitProcess


Internet

1 cc foo.c

foo.c

0 UNIX

UNIX
kill Win32 TerminateProcess

UNIX

UNIX

kill
UNIX
init init

shell
init

Windows

Windows Windows

UNIX
Windows

shell

1 cat chapter1 chapter2 chapter3 | grep tree

cat grep
tree CPU
grep
grep
1. CPU
2.
3.

CPU CPU

1
pause UNIX

2 3
2
CPU CPU
3

4
3 CPU
(process table)
text segment data segment stack segment

( )

CPU
I/O (interrupt vector)
3

1.
2.
3.
4.
5. C
6.
7. C
8.
10 - 100
CPU
I/O

web
Web
(cache)
CPU

web
web (dispatcher thread)

web
web read

web

TRUE 1 buf page


Web

1 while(TRUE){
2 get_next_request(&buf);
3 handoff_work(&buf);
4 }

1 while(TRUE){
2 wait_for_work(&buf);
3 look_for_page_in_cache(&buf,&page);
4 if(page_not_in_cache(&page)){
5 read_page_from_disk(&buf,&page);
6 }
7 return _page(&page);
8 }

Web Web

read read
I/O

(finite-state machine)

(thread)

CPU

(lightweight processes)
(multithreading)
CPU
thread_create

thread_exit
thread_join

thread_yield CPU
CPU

POSIX
IEEE IEEE 1003.1c
Pthreads UNIX 60

POSIX pthreads

POSIX Threads API

POSIX Threads POSIX FreeBSD NetBSD


OpenBSD Linux macOS Android Solaris Windows API
pthread

IEEE

pthread_create

pthread_exit

pthread_join

pthread_yield CPU

pthread_attr_init

pthread_attr_destory

Pthreads

pthread_create
UNIX fork PID

pthread_exit
pthread_join

pthread_yield

pthread_attr_init

pthread_attr_destroy

pthread

1 #include <pthread.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4
5 #define NUMBER_OF_THREADS 10
6
7 void *print_hello_world(vvoid *tid){
8 /* */
9 printf("Hello World. Greetings from thread %d\n",tid);
10 pthread_exit(NULL);
11 }
12
13 int main(int argc,char *argv[]){
14 /* 10 */
15 pthread_t threads[NUMBER_OF_THREADS];
16 int status,i;
17
18 for(int i = 0;i < NUMBER_OF_THREADS;i++){
19 printf("Main here. Creating thread %d\n",i);
20 status = pthread_create(&threads[i], NULL, print_hello_world, (void *)i);
21
22 if(status != 0){
23 printf("Oops. pthread_create returned error code %d\n",status);
24 exit(-1);
25 }
26 }
27 exit(NULL);
28 }

NUMBER_OF_THREADS
pthread_create, pthread_exit, pthread_join pthread_yield

(Runtime System)

(thread table)

pthread_yield
I/O

CPU
CPU
shell

(Inter Process Communication,


IPC)

A B B
A
(spooler directory)
(printer daemon)

(slot) 0 1 2 ...
out in
0
3 4 6 A B

(Murphy)

A in 7 7 next_free_slot
CPU A B B in 7
B 7 next_free_slot
7

B slot 7 in 8 B
A A next_free_slot slot 7
slot 7 in 8 slot 7 B
A B
B
(race condition)

(mutual exclusion)

A B

(critical region) (critical


section)

1.
2. CPU
3.
4.
t1 A t2
B A B t3
A B t4 B

CPU
CPU

disable CPU
CPU

0
0 0 1
1 0
0 1
0
1 0 1
1

set-before-check
C C
C C++ Java Modula3 Pascal Java
native C C++ C
Java
C C
C C++ Java

1 while(TRUE){
2 while(turn != 0){
3 /* */
4 critical_region();
5 turn = 1;
6 /* */
7 noncritical_region();
8 }
9 }

1 while(TRUE){
2 while(turn != 1){
3 critical_region();
4 turn = 0;
5 noncritical_region();
6 }
7 }

turn 0
0 turn 0 1 0
turn 1
(busywaiting) CPU

(spinlock)

0 turn 1 1 1
turn 0 0
turn 1 turn 1

0 turn
1 1 0 while 1 turn
0

3 0

Peterson
T.Dekker
Dekker

G.L.Peterson

1 #define FALSE 0
2 #define TRUE 1
3 /* */
4 #define N 2
5
6 /* */
7 int turn;
8
9 /* 0 (FALSE) */
10 int interested[N];
11
12 /* 0 1 */
13 void enter_region(int process){
14
15 /* */
16 int other;
17
18 /* */
19 other = 1 - process;
20
21 /* */
22 interested[process] = TRUE;
23 turn = process;
24
25 /* */
26 while(turn == process
27 && interested[other] == true){}
28
29 }
30
31 void leave_region(int process){
32
33 /* */
34 interested[process] == FALSE;
35 }

0 1
enter_region
leave_region

0
enter_region turn 0 1
enter_region enter_region 1
interested[0] FALSE 0 leave_region
enter_region
turn
1 turn 1 while 0
1 0

TSL

1 TSL RX,LOCK

(test and set lock) lock RX

TSL CPU CPU

1 2 2
1

TSL lock lock 0


TSL 1 move lock
0

1 enter_region:
2 | 1
3 TSL REGISTER,LOCK
4 | 0
5 CMP REGISTER,#0
6 |
7 JNE enter_region
8 |
9 RET
10
11 leave_region:
12
13 | 0
14 MOVE LOCK,#0
15 |
16 RET

Peterson 4
lock lock 1 0

0
0 lock
enter_region
lock 1 lock 0
leave_region lock 0
enter_region leave_region

TSL XCHG

1 enter_region:
2 | 1
3 MOVE REGISTER,#1
4 |
5 XCHG REGISTER,LOCK
6 | 0
7 CMP REGISTER,#0
8 | 0
9 JNE enter_region
10 |
11 RET
12
13 leave_region:
14 | 0
15 MOVE LOCK,#0
16 |
17 RET

XCHG TSL Intel x86 CPU XCHG

Peterson TSL XCHG

CPU
H L
H H L H
I/O H H L
L H
(priority inversion problem)

CPU sleep wakeup Sleep


wakeup
wakeup sleep sleep wakeup

- (producer-consumer)
(bounded-buffer)
(producer) (consumer)
m n
count N count N
count count
0 0 count

1 /* slot */
2 #define N 100
3 /* */
4 int count = 0
5
6 //
7 void producer(void){
8 int item;
9
10 /* */
11 while(TRUE){
12 /* */
13 item = produce_item()
14 /* */
15 if(count == N){
16 sleep();
17 }
18
19 /* */
20 insert_item(item);
21 /* count */
22 count = count + 1;
23 if(count == 1){
24 /* */
25 wakeup(consumer);
26 }
27 }
28 }
29
30 //
31 void consumer(void){
32
33 int item;
34
35 /* */
36 while(TRUE){
37 /* */
38 if(count == 0){
39 sleep();
40 }
41 /* */
42 item = remove_item();
43 /* count */
44 count = count - 1
45 /* */
46 if(count == N - 1){
47 wakeup(producer);
48 }
49 /* */
50 consumer_item(item);
51 }
52
53 }

C sleep wakeup
C
insert_item remove_item

- count
count 0

count 1 count 0
wakeup wakeup
count 0

(wakeup waiting bit)


wakeup 1
1

2 4 6 8

E.W.Dijkstra 1965
(semaphore) 0
0

Dijkstra down up sleep wakeup


down 0 0 1 0
down
(atomic action)
up +1 down
down
up 0 1
up
wakeup

wakeup

1 /* */
2 #define N 100
3 /* int */
4 typedef int semaphore;
5 /* */
6 semaphore mutex = 1;
7 /* buffer */
8 semaphore empty = N;
9 /* buffer */
10 semaphore full = 0;
11
12 void producer(void){
13
14 int item;
15
16 /* TRUE 1 */
17 while(TRUE){
18 /* */
19 item = producer_item();
20 /* 1 */
21 down(&empty);
22 /* */
23 down(&mutex);
24 /* */
25 insert_item(item);
26 /* */
27 up(&mutex);
28 /* buffer + 1 */
29 up(&full);
30 }
31 }
32
33 void consumer(void){
34
35 int item;
36
37 /* */
38 while(TRUE){
39 /* - 1 */
40 down(&full);
41 /* */
42 down(&mutex);
43 /* */
44 item = remove_item();
45 /* */
46 up(&mutex);
47 /* + 1 */
48 up(&empty);
49 /* */
50 consume_item(item);
51 }
52
53 }

up down

CPU
TSL XCHG CPU

TSL XCHG CPU

full empty
mutex Full
0 empty mutex 1 1
(binary
semaphores) down up

1.
2.
3.
4.
5. C
6.
7. C
8.

I/O
0 I/O down
up
5 C
up 6

mutex
(synchronization) full empty

mutex

mutex( )

(unlocked) (locked)
(integer) 0
1

mutex mutex_lock

mutex
mutex_unlock mutex

mutex TSL XCHG


mutex_lock mutex_unlock XCHG
1 mutex_lock:
2 | 1
3 TSL REGISTER,MUTEX
4 | 0
5 CMP REGISTER,#0
6 | 0
7 JZE ok
8 |
9 CALL thread_yield
10 |
11 JMP mutex_lock
12 |
13 ok: RET
14
15 mutex_unlcok:
16 | mutex 0
17 MOVE MUTEX,#0
18 |
19 RET

mutex_lock enter_region

TSL TSL
TSL mutex
mutex/TSL
thread_yield CPU

enter_region mutex_lock thread_yield


mutex_lock mutex_unlock

mutex_trylock

Futexes

(synchronization) (locking)
(Spin lock)
CPU

futex
(fast user space mutex)

futex Linux
futex
(wait queue)

futex 32 (integer)
1
(decrement and test) decrement and set Linux C
futex

(increment and test)

Pthreads

Pthreads
mutex mutex
mutex
mutex

mutex Phread_mutex_init
Pthread_mutex_destroy mutex Pthread_mutex_lock
Pthread_mutex_trylock mutex

Pthread_mutex_unlock mutex

Pthreads (condition variables)


mutex

mutex
pthread

Pthread_cond_wait
Pthread_cond_signal

Pthread_cond_broadcast

1 #include <stdio.h>
2 #include <pthread.h>
3
4 /* */
5 #define MAX 1000000000
6 pthread_mutex_t the_mutex;
7 /* */
8 pthread_cond_t condc,condp;
9 int buffer = 0;
10
11 /* */
12 void *producer(void *ptr){
13
14 int i;
15
16 for(int i = 0;i <= MAX;i++){
17 /* mutex */
18 pthread_mutex_lock(&the_mutex);
19 while(buffer != 0){
20 pthread_cond_wait(&condp,&the_mutex);
21 }
22 /* */
23 buffer = i;
24 /* */
25 pthread_cond_signal(&condc);
26 /* */
27 pthread_mutex_unlock(&the_mutex);
28 }
29 pthread_exit(0);
30
31 }
32
33 /* */
34 void *consumer(void *ptr){
35
36 int i;
37
38 for(int i = 0;i <= MAX;i++){
39 /* mutex */
40 pthread_mutex_lock(&the_mutex);
41 while(buffer == 0){
42 pthread_cond_wait(&condc,&the_mutex);
43 }
44 /* */
45 buffer = 0;
46 /* */
47 pthread_cond_signal(&condp);
48 /* */
49 pthread_mutex_unlock(&the_mutex);
50 }
51 pthread_exit(0);
52
53 }

Brinch Hansen Hoare


(monitor)

Pascal
C C
1 monitor example
2 integer i;
3 condition c;
4
5 procedure producer();
6 ...
7 end;
8
9 procedure consumer();
10 .
11 end;
12 end monitor;

(mutex)
(binary semaphore)

(condition variables) wait signal


full
wait
pthread
signal

Brinch Hansen Hoare Hoare


Brinch Hansen signal Brinch
Hansen

signal

signal

wait
signal

Pascal -

1 monitor ProducerConsumer
2 condition full,empty;
3 integer count;
4
5 procedure insert(item:integer);
6 begin
7 if count = N then wait(full);
8 insert_item(item);
9 count := count + 1;
10 if count = 1 then signal(empty);
11 end;
12
13 function remove:integer;
14 begin
15 if count = 0 then wait(empty);
16 remove = remove_item;
17 count := count - 1;
18 if count = N - 1 then signal(full);
19 end;
20
21 count := 0;
22 end monitor;
23
24 procedure producer;
25 begin
26 while true do
27 begin
28 item = produce_item;
29 ProducerConsumer.insert(item);
30 end
31 end;
32
33 procedure consumer;
34 begin
35 while true do
36 begin
37 item = ProducerConsumer.remove;
38 consume_item(item);
39 end
40 end;

wait signal sleep wakeup


sleep wakeup

wait wait
wait

Pascal Java Java


Java
synchronized Java
synchronized synchronized
Java -

1 public class ProducerConsumer {


2 //
3 static final int N = 100;
4 //
5 static Producer p = new Producer();
6 //
7 static Consumer c = new Consumer();
8 //
9 static Our_monitor mon = new Our_monitor();
10
11 // run
12 static class Producer extends Thread{
13 public void run(){
14 int item;
15 //
16 while(true){
17 item = produce_item();
18 mon.insert(item);
19 }
20 }
21 //
22 private int produce_item(){...}
23 }
24
25 // run
26 static class consumer extends Thread {
27 public void run( ) {
28 int item;
29 while(true){
30 item = mon.remove();
31 consume_item(item);
32 }
33 }
34 //
35 private int produce_item(){...}
36 }
37
38 //
39 static class Our_monitor {
40 private int buffer[] = new int[N];
41 //
42 private int count = 0,lo = 0,hi = 0;
43
44 private synchronized void insert(int val){
45 if(count == N){
46 //
47 go_to_sleep();
48 }
49 //
50 buffer[hi] = val;
51 //
52 hi = (hi + 1) % N;
53 // 1
54 count = count + 1;
55 if(count == 1){
56 //
57 notify();
58 }
59 }
60
61 private synchronized void remove(int val){
62 int val;
63 if(count == 0){
64 //
65 go_to_sleep();
66 }
67 //
68 val = buffer[lo];
69 //
70 lo = (lo + 1) % N;
71 // 1
72 count = count - 1;
73 if(count = N - 1){
74 //
75 notify();
76 }
77 return val;
78 }
79
80 private void go_to_sleep() {
81 try{
82 wait( );
83 }catch(Interr uptedExceptionexc) {};
84 }
85 }
86
87 }

(outer class) ProducerConsumer p


c Producer Consumer
Our_monitor

Our_monitor
insert remove
count lo
hi lo = hi
0 N

Java Java Java wait


notify sleep wakeup

C Pascal

CPU
TSL XCHG
CPU CPU

(messaage passing)
send receive

1 send(destination, &message);
2
3 receive(source, &message);

send receive

(acknowledgement)
(authentication)

1 /* buffer */
2 #define N 100
3
4 void producer(void){
5
6 int item;
7 /* buffer */
8 message m;
9
10 while(TRUE){
11 /* */
12 item = produce_item();
13 /* */
14 receive(consumer,&m);
15 /* */
16 build_message(&m,item);
17 /* */
18 send(consumer,&m);
19 }
20
21 }
22
23 void consumer(void){
24
25 int item,i;
26 message m;
27
28 /* N */
29 for(int i = 0;i < N;i++){
30 /* N */
31 send(producer,&m);
32 }
33 while(TRUE){
34 /* */
35 receive(producer,&m);
36 /* */
37 item = extract_item(&m);
38 /* */
39 send(producer,&m);
40 /* */
41 consume_item(item);
42 }
43
44 }

N N N

(mailbox)

send receive
-

(barrier)

A B D
B C

- -

A B
A B
X
" " X
X A

B D A C A
C B D
B D
B D - -
(Ready-Copy-Update,RCU)

CPU
/ CPU
/ (scheduler)
(scheduling algorithm)

CPU

I/O
CPU I/O

CPU I/O
CPU
I/O

a CPU b I/O a
(compute-bound) CPU (CPU-bound) b I/O
I/O (I/O-bound) CPU I/O I/O
CPU I/O CPU
I/O I/O I/O
I/O

CPU I/O
CPU I/O
I/O

(system-supplied idle process) Microsoft windows

System Idle Process


System Idle Process
CPU Windows
Windows CPU
I/O
A B
B A

I/O I/O I/O


I/O
50 60 Hz k
(nonpreemptive)
I/O
CPU

CPU

(Batch)
(Interactive)
(Real time)

CPU
CPU

15
14
14

CPU I/O

CPU I/O
CPU I/O
CPU CPU
I/O CPU I/O
CPU
CPU (throughout)
50 40
(Turnaround time)

CPU (CPU utilization) CPU

CPU
CPU 100%

E-mail

(proportionality)

1
5 1

(first-come,first-
serverd) CPU
100 I/O
101 CPU 100 I/O CPU

(Shortest Job First)


1000
a 4 A B C D 8 4 4 4
A 8 B 12 C 16 D 20 14

4 b 4 8 12
20 11 4
a b c d a a+b (4a +
3b + 2c + d) / 4 a a b c
d

(Shortest Remaining Time Next)

(round-robin)
(quantum)
CPU
CPU
a b
(process switch) (context switch)
1ms 4 ms
CPU 4 ms CPU 1 ms CPU
20%

CPU 100 ms 1%
50 CPU
50 CP U
100 ms 5
5

CPU

CPU
20 - 50

(priority scheduling)
100 90 80 70 60 UNIX nice

I/O
I/O CPU CPU I/O
I/O I/O CPU
I/O 1/f f
50 ms 1 ms 50
25 ms 2 1

4
4
4 3 2

CTSS(Compatible TimeSharing System) CTSS


IBM 7094
IBM 1964 - 1968

CTSS CTSS
CPU

2 4

T0 T1
aT0+ (1- 1)T1 a
a = 1/2

T0 1/8

(aging)
n CPU 1/n n
1/n CPU

(lottery scheduling)

CPU
CPU 50
20 CPU

George Orwell
100
20 20% 20% CPU
40 f
f

buff buff 15%

1 9 2 1
90 % CPU 2 10 % CPU

CPU 50%
CPU CPU
(real-time)
CD

(hard real time) (soft real time)

( ) (
)
m i Pi Ci CPU

CPU CPU

100 ms 200 m 500 ms


50 ms 30 ms 100 ms CPU 0.5 +
0.15 + 0.2 < 1 1 150 ms
CPU

(scheduling mechanism) (scheduling policy)

A A A A1

A A1 A

A CPU 50 ms 5 ms
CPU B
A1,A2,A3,A1,A2,A3,A1,A2,A3,A1
50 ms 5 ms 30 ms
A1,B1,A2,B2,A3,B3
Java
I/O

A B A
(RAM) IBM
7094

(memory hierarchy)

(memory manager)

20 60 20
70 20 80

1 MOV REGISTER1, 1000

1000 REGISTER1
0 8

2000
2000
a RAM(Random Access Memory) b
ROM(Read-Only Memory) c ROM
RAM a b
ROM
BIOS (Basic Input Output System) a c
IBM 360

System/360 IBM 1964 4 7

IBM 360 2KB 4


CPU (SFR) 1 MB 512 4
256 ( ) PSW(Program Status Word, ) 4
PSW 360

16 KB
16KB a 24
MOV b 28 28 CMP
0
c 0 JMP 24

28 ADD
CMP

IBM 360
(static relocation)
16384 16384 JMP 28 JMP 16412

b JMP 28 MOV
REGISTER1,28 28 REGISTER (loader)
IBM 360 lock-and-key

CPU

IBM
360

(the address space)


CPU

(dynamic relocation)
CDC 6600( ) Intel
8088( IBM PC ) CPU
(basic register) (limit register)

c
0 16384
16384 32768 16 KB
32768 16384

CPU

c
JMP 28 JMP 16412 CMP
CDC 6600
Intel 8088 Intel 8088

ADD CMP
CMP

RAM Windows OS X Linux


Boot 50 - 100 Windows

5 - 10MB

Photoshop 500 MB
GB
(swapping)

(virtual
memory)

A B C
d A A g A
(hole)
(memory compaction)
CPU 16GB 8ns 8
16s

data segment
data segment (
)

codesegment/textsegment

datasegment

static
bss bsssegment

static

bss

bss 0

rodata

printf
const int ival = 10 ival .rodata printf("Hello world %d\n", c);
"Hello world %d\n" .rodata

stack

( static )

heap

malloc/realloc

malloc/realloc free

Borland C++

1 _TEXT segment dword public use32 'CODE'


2 _TEXT ends
3 _DATA segment dword public use32 'DATA'
4 _DATA ends
5 _BSS segment dword public use32 'BSS'
6 _BSS ends

( segment ) segment
ends
( )
(data segment) (stack segment) b

(data segment
)

(bitmap)
(free lists)

0 1
a 5 3
0 b c

4
32 1 32n n 1
1/32

k
(memory manager) k 0
0

c
(H) (P)

(segment list)
(first
fit)

(next fit)

Bays(1997)

(best fit)

2 5
18
(worst
fit)

(quick fit)
n 4 KB
8 KB 12 KB
21 KB 20 KB
(managing bloatware)
1980 4 MB VAX
64 Windows 8 2 GB

xxx xxx
GB
SATA / 1 GB

SATA Serial ATA PC PATA

(virtual memory)
(page)

8088
text data

text data

CPU

(paging)

1 MOV REG,1000

1000 REG

(virtual addresses) (virtual


address space)

MMU(Memory Management Unit)


4096 4095
4K 8K 4096 - 8191 8K - 12K 8192 - 12287

16 0 - 64 K - 1
32 KB 64 KB
64 KB

(pages)
(page frames)
4KB 512 - 1G 64
KB 32 KB 16 8 RAM

1 MOV REG, 0

0 MMU MMU 0 0 - 4095


2 8192 - 12287 MMU 8192 8192
MMU 8192 MMU
0 - 4095 8192 - 12287

1 MOV REG, 8192

1 MOV REG, 24576

8192 2 24576 6

MMU 16 8

8 8 X
/ (Present/absent bit)

1 MOV REG, 32780

8 32768 12 MMU
X CPU (trap)
(page fault)
1 8 4096 MMU
1 4096 - 8191
8 1
32780 4096 + 12

MMU 2

8196 0010000000000100 MMU


16 4 12 4 16 12
4096

(page table) /
0 1 3
12 15
16 4 KB 4 16
12 0-4095

/
32 (Page frame
number) /
1 0
(page fault)

(Protection)
0 1

(Modified) (Referenced)

(dirty bit)

(Referenced)

I/O I/O

CPU

(virtual memory) (paging)


MOV ADD

1 ns 0.2 ns

32 64
4 KB 32 100 64

CPU

1 8085 8085 3
1-byte(1 ) 2-byte(2 ) 3-byte(3 )

1-byte 1 1
1-byte

MOV B,C LDAX B NOP HLT

2-byte: 2

MVI B, 26 H IN 56 H

3-byte: 3 16

LDA 2050 H JMP 2085 H


Page Table Entry(PTE)

(Translation Lookaside Buffer, TLB) (associate memory)

1 140 1 RW 31

1 20 0 RX 38

1 130 1 RW 29

1 129 1 RW 62

1 19 0 RX 50

1 21 0 RX 45

1 860 1 RW 14

1 861 1 RW 75

TLB

TLB MMU
TLB TLB
MMU TLB
(address-translation cache) TLB CPU CPU CPU
TLB

MMU TLB
TLB
TLB TLB
(protection fault)

TLB TLB MMU


TLB
TLB TLB
TLB
MMU TLB

TLB

TLB TLB
TLB (trap)

RISC SPARC MIPS HP


PA
RISC CPI
CISC

TLB TLB MMU


TLB
TLB TLB
TLB

TLB
TLB
TLB TLB TLB
TLB

TLB TLB TLB


(soft miss) TLB
I/O
(hard miss)
(page table walk)
(minor page fault)
(major page falut)
TLB
(segmentation fault)

(multi)
32 10 PT1 10 PT2 12 Offset
12 4KB 2^20

1 level 1
2 level 2 2 3 level 3

1024 10 PT1 MMU


MMU PT1 4 GB 32
4 KB 1024 4M
0
1 1023
PT2

(inverted page tables)


PowerPC UltraSPARC Itanium

n p p

TLB TLB

1
TLB

(page replacement
algorithms)
32
64

Web Web
Web Web
Web

10 100 1000

800
600

R M
R M

1
1

R ( ) READ ONLY
M READ/WRITE

R M
0 R

R M

0 R M
1 R M
2 R M
3 R M

R
M R M

NRU(Not Recently Used)


20 ms
NRU

FIFO(First-In,First-Out)
1
MISS 1
2 2
MISS
1 2 3 2
2 HIT
1 2 3 5
5 5 2
2 3 5

FIFO check

R 0
R 1

(second chance) A H
a b 20 A R

20 A 0 A R 0

R A
20 R B

FIFO a R
R A R
A
R 0
R 1 R
R 0
(clokc)

LRU(Least Recently Used)

LRU LRU

LRU
64 1

LRU
LRU
LRU NFU(Not Frequently
Used ) 0
R 0 1

NFU

NFU LRU

R
R

(aging)

0-5 R 1 0 1 0 1 1 0 1
1 0 2 1 0 1 0 2 4 5
R 1 0 R
a

CPU 100Mhz
100,000,000

4
0 3

LRU e
LRU

1 2

3 3 0-1 5

LRU 2 8
0
9 1000
20 ms 8
20 ms

CPU

(demand paging)

(locality of
reference)

(working set)

10 ms
(thrashing)

CPU

20 100 1000 CPU


CPU

(working set model)


(prepaging)

t
k w(k,t) k=1
k>1 w(k,t) k k
w(k,t)

k
CPU
t
R

R M
Referenced( )

R R 1

R 0
- t
t

R 0 t

R=0

R=1
WSClock( )

a) b) R=1 c) d) R=0

R M

R 1
R 0
b

R=0 c t

I/O
n
NRU( ) LRU

FIFO( )

FIFO

LRU( )

NFU( ) LRU

LRU

NRU R M
NRU
FIFO

FIFO

LRU (TLB)
LRU
NFU LRU
LRU

WSClock

WSClock LRU
(Magnetic disk)

k
k
-

(Files)

(file system)
1-8

UNIX MS-DOS
MS-DOS MS-DOS
UNIX maria Maria MARIA MS-
DOS

Windows 95 Windows 98 MS-DOS


FAT-16 Windows 98
FAT-16 FAT-32 Windows NT
Windows 2000 Windows XP Windows Vista Windows 7 Windows 8 FAT
(NTFS)
Unicode Windows 8
ReFS(Resilient File System) Windows 8
MS-DOS FAT Windows FAT-16
FAT-32 FAT exFAT
FAT 32 ExFAT OS X

. prog.c
(file extension) MS-DOS
1-8 1-3 UNIX

homepage.html.zip html web .zip homepage.html zip


bak

c c

gif

hlp

html WWW

jpg JPEG

mp3 MP3

mpg MPEG

pdf pdf

ps PostScript

tex TEX

txt

zip

UNIX

file.txt
C .c

C
C C
C

UNIX Windows ( )

file.docx Word file.docx


a) b) c)

a
(bytes) UNIX Windows

UNIX Linux OS X Windows

c
key key
key

key c
pony

UNIX OS X Windows
UNIX (character special file) (block
special file) (Regular files)

/ I/O
ASCII ASCII
ASCII 13 CR \r ASCII
10 LF \n Windows

ASCII
ASCII

ASCII
UNIX
(magic number)

TOPS-20
DECsystem 20
UNIX shell make

make make
Makefiles
Make
Unix Unix

(kernel driver)
(Directories)
Linux MS-DOS UNIX

Windows / DOS

cdn big C

(sequential access)
(random access file)

read
seek seek UNIX
Windows

(attributes)
(metadata) (set)
(clear)
ID

0 / 1

0 1

0 1

0 1

ASCII / 0 ASCII 1

0 1

0 1

0 1

File Protection

(flags)

(hidden flag)
(archive flag)

(temporary flag)

(record-length) (key-position) (key-length)

1. Create

2. Delete

3. Open

4. Close

5. Read

6. Write

7. append append
8. seek seek
seek
9. get attributes
10. set attributes
set attributes
11. rename rename

(directories) (folders)
(root
directory)

(Hierarchical Directory Systems)


A B C

(absolute path name)


/usr/ast/mailbox usr usr mailbox
/ UNIX / Windows
\ MULTICS >

1 Windows \usr\ast\mailbox
2 UNIX /usr/ast/mailbox
3 MULTICS >usr>ast>mailbox

(relative path name) (working


directory) (current directory)
/usr/ast /usr/ast/mailbox
mailbox /usr/ast UNIX

1 cp /usr/ast/mailbox /usr/ast/mailbox.bak

1 cp mailbox mailbox.bak
. .. dot
dotdot dot dotdot

/usr/ast ..

1 cp ../lib/dictionary .

usr/lib/dictionary usr
lib dictionary

. cp

1 cp /usr/lib/dictionary .

. dictionary

1 cp /usr/lib/dictionary dictionary
1 cp /usr/lib/dictionary /usr/lib/dictionary

UNIX

1. Create . ..
2. Delete . ..

3. opendir

4. closedir
5. readdir readdir read

readdir
6. rename
7. link

(hard link)
8. unlink
UNIX
unlink

(disk
partitioning) (disk slicing)
0 (Master Boot Record, MBR)
(boot) MBR (partition table)

MBR DOS Microsoft Windows Linux 2010


GUID GPT
GParted (active)

boot BIOS MBR

MBR (boot block)

4096 0

CPU
CPU

(rebooting)
(Superblock) 4096
4096

BitMap Bit vector

0 1 0
1 16
0000111000000110
(fragment)

Windows
inode

inode(index node)
inode inode

ls -lai

inode

/
ID
ID
inode

inode

inode

1KB
50 KB 50

40 0
0 4 A 6
B A

A 3 1/2
7
D F

word

CD-ROM

CD-ROM Compact Disc Read-Only Memory


DVD 90 4.5
GB UDF(Universal Disk Format) 30
1 GB DVD 3 4 1 GB
(extends)

CD-ROM DVD
2
2
A 4
7 2 10 12 B 6 3 11 14 A 4
A 6 B
-1
(File Application Table,FAT)

1TB 1KB
10 10 3
4 3GB 2.4GB
FAT MS-DOS
Windows

inode

inode( )
inode inode
inode

inode
inode n k inode
kn

FAT( )
n n
inode
100GB 4000GB 10000GB

inode

Windows NTFS inode

NTFS New Technology File System NTFS


FAT( ) HPFS( )

inode
ASCII
inode inode
inode

MS-DOS 1-8
1-3 UNIX 7 1 - 14

255
255
SPARC

(big-endian) (little-endian)

project-budget personnel foo


0
(hash table) n 0 n-
1 n

HashMap

C B
B (link)
(Directed Acyclic Graph, DAG)

google

C
B B C
UNIX inode
LINK B
B C B
B LINK
(symbolic linking)
B inode
C
a C C B
C +1 C
C inode B
inode B
inode
inode

C inode 1 c
c B C
C B 0

inode
inode

inode
inode
inode

CPU

Berkeley
(Log-structured File System,
LFS)

Rosenblum Ousterhout 90

I/O I/O

RAID

UNIX FFS FFS


5 Page cache
cache LFS
inode UNIX
inode inode inode inode
map(inode ) i i inode

Inode Inode Map Segment Segment Usage


Table

inode

inode

LFS (clean)
inode
inode inode
NTFS Linux ext3 OS X
UNIX

inode inode

Windows
inode

fsck

(idempotent)
inode k n
foobar
inode k

(atomic transaction)
Windows
NTFS Windows NTFS
FAT -32 FAT -16 CD-ROM
DVD Windows
C: D:
Windows

UNIX UNIX
Linux ext2 ext3 /usr Reiser
FS /home ISO 9660 CD - ROM /mnt

UNIX (Virtual File System, VFS)

VFS

POSIX
open read write seek VFS
POSIX

VFS VFS
VFS VFS
VFS
VFS

VFS
VFS VFS
VFS VFS
VFS VFS
/usr

1 open("/usr/include/unistd.h",O_RDONLY)

VFS /usr
include/unistd.h
VFS vnode inode
vnode vnode
read write close

vnode VFS vnode


VFS read write close

VFS vnode
read VFS
CD-ROM USB

vnode
n

1
1 KB 32
255 1 TB
255 400

(bitmap) n n 1
0 1 TB 10 130 000 1
KB 32 1

8
16 32

IO
a

I/O

I/O a-
b a-c
I/O

I/O

(enforcing disk
quotas)
1 0
Windows (recycle bin)

(incremental
dumps)

(physical dump) 0

(bad
blocks)
Windows (paging files) (hibernation files)

(logical dump)

UNIX

inode
inode (bitmap) inode

inode

inode 10 11 14 27 29 30
inode 5 6

b
inode

(skeleton)

UNIX (holes)
(inconsistent)

UNIX
fsck Windows sfc

inode
inode +1

1 1

2 (missing block)
4 2

5 5

+1

+1

inode
inode inode
0 inode

inode 1
inode 0 inode 0 inode
inode
32 10ns 100MB/S 32
5 - 10 ms

(block cache) (buffer


cache)

HashMap?
https://mp.weixin.qq.com/s/5-k2BJDgEp9sy
mxcSwoprw FIFO LRU

k
k+1 k+1

512 1 KB 2 2 4
2 KB 1 KB
1 KB

inode inode
inode inode

a inode b inode
inode inode

inode inode
inode
b

(SSD)

Windows defrag Windows


SSD

Linux ext2 ext3


Windows

I/O
I/O
I/O

I/O I/O
I/O

I/O

I/O I/O / /

I/O (I/O devices) (block devices) (character


devices)

512 - 65536

USB

I/O
CPU

(special purpose registers)


cs ds gs
eax ecx
ds eax ebx

eax ecx edx ebx esi edi ebp esp

cs ds ss es fs gs eip flag

I/O (mechanical component) (electronic component)


(device controller) (adapter)
PCIe

2 4 8

2,000,000
512 (preamble)
4096 ECC Error-Correcting
Code
I/O
CPU

(data buffer)
RAM RAM

CPU
I/O (I/O port) 8 16
I/O I/O
I/O

1 IN REG,PORT

CPU PORT CPU REG

1 OUT PORT,REG

CPU REG IBM 360

CPU

I/O
1 IN R0,4

1 MOV R0,4

I/O 4 R0 4
R0 4

PDP-11

PDP-11?
I/O CPU
IO IO
I/O I/O x86
IBM PC 0 64K - 1 I/O 640 K 1M - 1

CPU I/O
READ
I/O I/O
I/O I/O

I/O

I/O

I/O

I/O
C C++ IN OUT I/O
C
I/O I/O

I/O

I/O

I/O

(memory modules) I/O


I/O
x86 PCIe SCSI USB

I/O
I/O
CPU
I/O
I/O

CPU I/O CPU


I/O CPU
(Direct Memory Access) CPU
CPU I/O

DMA

DMA
DMA
DMA DMA

DMA CPU
CPU
I/O I/O I/O

DMA DMA

DMA
DMA CPU DMA
DMA DMA

DMA

DMA DMA
CPU DMA

DMA

DMA 0 2-
4 0 DMA CPU

DMA DMA

DMA DMA

DMA
DMA CPU
CPU CPU
(cycle stealing)

DMA
(burst mode)

CPU

(fly-by mode) DMA


DMA DMA
DMA

DMA
DMA DMA
DMA DMA MMU
MMU CPU
I/O

CPU

CPU CPU

CPU

I/O
CPU CPU

CPU
CPU

CPU

MMU
TLB
CPU
CPU ( )

PSW PSW

a
(precise interrupt)

PC
PC
PC
PC

(imprecise interrupt)

IO

I/O

I/O I/O (device


independence)
DVD
USB

1 sort
(uniform naming)
UNIX
ls
USB /usr/cxuan/backup
/usr/cxuan/backup/device

I/O (error handling)

I/O (synchronous) (asynchronous )


IO(physical I/O) I/O CPU CPU
CPU

I/O I/O I/O(Logical I/O)

I/O I/O

I/O (buffering)

I/O I/O

I/O I/O

I/O
I/O
DMA I/O

I/O
I/O I/O CPU
CPU I/O CPU
I/O I/O CPU
CPU (polling) (busy waiting)
I/O I/O
I/O

CPU I/O
I/O
I/O
CPU
I/O CPU
I/O CPU
CPU

I/O
I/O CPU I/O
I/O
CPU I/O CPU I/O

CPU
I/O CPU
I/O CPU
CPU
I/O

CPU I/O

DMA I/O
DMA CPU I/O CPU
DMA CPU DMA DMAC
DMA CPU
DMA CPU DMA

I/O

I/O

/
ISR(Interrupt Service Routines)

up
signal

ARM System Developer’s Guide

Designing and Optimizing System Software

TLB MMU
MMU TLB
PSW
I/O
I/O
(Device driver)

MINIX 3 MINI 3
UNIX
UNIX

I/O
MS-DOS
I/O I/O

CPU

CPU

CPU CPU

CPU

I/O
I/O
I/O

ADSL(
)

read
n n
(double buffering)

(circular buffer)
-> -> socket
-> ->

I/O

I/O
I/O

open
open
open
I/O
I/O I/O
I/O

(magnetic hard disks) hard


disk,HDD
8 - 32 1 - 16

(overlapped seek)

RAID

RAID

RAID

RAID 0 -
RAID 1 -
RAID 2 -
RAID 3 -
RAID 4 -
RAID 5 -
RAID 6 - P + Q

(low-levvel format)
512
ECC ECC error correction code
ECC ECC ECC
ECC
ECC 16

(cylinder skew)

0
(head skew)

ECC

(high-level
format)

BIOS
(boot sector)
(system kernel)

Master boot record


Volume boot record
-
-

(First-Come, First-served, FCFS)

(SSF)

6 11 , 2 , 4, 14, 8, 15, 3

5 + 9 + 2 + 10 + 6 + 7 + 12 = 51 51
4 + 1 + 1 + 4 + 3 + 3 + 1 = 17 51

(elevator
algorithm)

UP( ) DOWN( )
UP
DOWN

4 7 10 14 9 6 3 1
3 + 3 + 4 + 5 + 3 + 3 + 1 = 22

SSF

ECC
30 4
RAID
RAID

(stable storage)

(stable write)
(stable read)
(crash recovery)

1
2
1 ECC
ECC 2

ECC

CPU
CPU

CPU 1
2 1
1 2 1

1 2
RAM
(Clocks) (timers) /
CPU (clock software)

110 V 220 V
50 - 60 HZ

(one-shot mode)
-1
0 (square-
wave mode) 0
CPU

(soft timer)

TLB

I/O
CPU
(deadlock)

A R1 B R2 A B

(resource)

(preemptable resource)

(nonpreemtable resource)

request

open

(semaphore) 1
(Mutexes) :

(mutex)

1 typedef int semaphore;


2 semaphore aResource;
3
4 void processA(void){
5
6 down(&aResource);
7 useResource();
8 up(&aResource);
9
10 }

1 typedef int semaphore;


2 semaphore aResource;
3 semaphore bResource;
4
5 void processA(void){
6
7 down(&aResource);
8 down(&bResource);
9 useAResource();
10 useBResource();
11 up(&aResource);
12 up(&bResource);
13
14 }

A B

1 typedef int semaphore;


2 semaphore aResource;
3 semaphore bResource;
4
5 void processA(void){
6
7 down(&aResource);
8 down(&bResource);
9 useBothResource();
10 up(&bResource);
11 up(&aResource);
12
13 }
14
15 void processB(void){
16
17 down(&aResource);
18 down(&bResource);
19 useBothResource();
20 up(&bResource);
21 up(&aResource);
22
23 }

1 typedef int semaphore;


2 semaphore aResource;
3 semaphore bResource;
4
5 void processA(void){
6
7 down(&aResource);
8 down(&bResource);
9 useBothResource();
10 up(&bResource);
11 up(&aResource);
12
13 }
14
15 void processB(void){
16
17 down(&bResource); //
18 down(&aResource); //
19 useBothResource();
20 up(&aResource); //
21 up(&bResource); //
22
23 }

A A B B
(resource deadlock)

Holt 1972
R A

B S Holt
C T T D D
U U C

(A B C) (R S T)

A A
B B C

/ I/O
CPU
I/O

I/O
A S B T
C R

S B B A
C
S B A
C B S C
T
(ostrich algorithm)

P1 -
> Pn n

P1 Pn n m E1
1 E2 2 Ei i (1 <= i <= m) E
(existing resource vector)
C (current allocation matrix) R
(request matrix) Ci Pi Cij Pi
j Rij Pi j

j =

CPU
k CPU CPU
CPU

(memory image)
(resource state)
Dijkstra 1965

15 1k

A/B/C/D
13 15 A C B
D A C

15

2
(spooling
printer)
(two-phase locking)

A B A
B A B

A B

(communication
deadlock)

(timeout)

10

A B B D D
A
(livelock)

(starvvation)
CPU
CPU

Windows macOS Linux

I/O
UNIX (shared library)
Windows (Dynamic Link Library,DLL) .dll
C:\Windows\system32 1000 DLL C
--- ---

MINIX 3

MINI 3

I/O I/O I/O


I/O
-

-
boot loader

boot loader

boot loader
BIOS
(MBR)

RAM
Web shell
typora

CPU

http://courses.cs.vt.edu/csonline/OS/Lessons/Processes/index.html

tab
RR

RR(round-robin) RR
RR

(Mutual Exclusion)

(Hold and Wait)

(No Preemption)

(Circular Wait) {p0 p1 ..... pn} p0 p1


p1 p2 pn-1 pn pn p0

RAID

RAID

RAID

RAID 0 -
RAID 1 -
RAID 2 -
RAID 3 -
RAID 4 -
RAID 5 -
RAID 6 - P + Q

DMA

DMA CPU I/O CPU


DMA CPU DMA DMAC
DMA CPU
DMA CPU DMA

CPU CPU

P
Doug Lea

ps Doug Lea JUC


(race condition)

(mutual exclusion)

1.
2. CPU
3.
4.

Inter Process Communication IPC


1 cat chapter1 chapter2 chapter3 | grep tree
cat grep
tree CPU
grep
grep

1. CPU
2.
3.

CPU CPU

1
pause UNIX

2 3
2
CPU CPU
3
4
3 CPU

(first-come,first-
serverd) CPU
100 I/O
101 CPU 100 I/O CPU

(Shortest Job First)


1000

a 4 A B C D 8 4 4 4
A 8 B 12 C 16 D 20 14

4 b 4 8 12
20 11 4
a b c d a a+b (4a +
3b + 2c + d) / 4 a a b c
d

(Shortest Remaining Time Next)


(round-robin)
(quantum)
CPU
CPU
a b

(priority
scheduling)
T0
T1 aT0+ (1- 1)T1
a a = 1/2

T0 1/8

(aging)

(lottery
scheduling)
CPU 50

buff buff 15%

1 9 2
1 90 % CPU 2 10 % CPU

CPU 50%
CPU CPU
NRU( ) LRU

FIFO( )

FIFO

LRU( )

NFU( ) LRU

LRU

NRU R M
NRU
FIFO

FIFO

LRU (TLB)
LRU
NFU LRU
LRU

WSClock

WSClock LRU

CPU

CPU
1. Operating System OS

2. shell
Unix CLI
··
3. GUI (Graphical User Interface)

4. (kernel mode) : supervisor mode


CPU

5. (user node)

1 1 0

6. (computer architecture)
I/O
7. SATA(Serial ATA) ATA (Serial Advanced Technology Attachment)

8. (multiplexing)

9. (mainframes)
10. (batch system) :

11. OS/360 OS/360 IBM System / 360 IBM 1964


System/360

12. (Computer multitasking)

……

13. (Time-sharing)

14. (Compatible Time-Sharing System)

15. (cloud computing)


Internet

16. UNIX UNIX

17. UNIX System V UNIX

18. BSD(Berkeley Software Distribution) UNIX

19. POSIX IEEE UNIX API

20. MINIX Minix UNIX

21. Linux Linux


22. DOS (Disk Operating System) DOS

23. MS-DOS(MicroSoft Disk Operating System)


Intel x86 DOS Windows 95 DOS
IBM PC MS-DOS DOS

24. MacOS X macOS


Macintosh
25. Windows NT(Windows New Technology) 1993 32

26. Service Pack(SP)


Autodesk
Service Pack
27. DRM TPM

28. x86 x86 Intel Intel 8086 8088


16 32 x86
x86-64 x86 64 16 32
x86
29. FreeBSD FreeBSD UNIX FreeBSD
30. X Window System X X11 X UNIX
31. Gnome GNOME Linux
BSD GNOME

32. (network operating systems)


33. (distributed operating systems)
CPU

34. (Program counter) CPU


35. (stack pointer) CPU

36. (Program Status Word) : 8 64

37. (Pipeline) :

38. (superscalar) CPU


CPU CPU
39. (system call) :

IO
40. (multithreading)

41. CPU (core) CPU


CPU
42. (Graphics Processing Unit)

43.
44. (cache lines)

45. (cache hit)


CPU

46. L1 cache CPU L1

47. L2 cache : CPU L2


L1 L2 L1
48. L2 cache : CPU L3 L2
L2 L3 L2
L1
49. RAM((Random Access Memory) CPU
RAM
ROM RAM

50. ROM (Read Only Memory)

51. EEPROM (Electrically Erasable PROM)

52. (flash memory)

U
53. SSD(Solid State Disks)

54. (virtual memory)

RAM

55. MMU (Memory Management Unit)


CPU
56. context switch CPU
CPU CPU

57. (device driver) driver

58. (busy waiting)

59. (Interrupt)

interrupt request IRQ


context switch
CPU

60. (interrupt vector) IVT


61. DMA (Direct Memory Access)

CPU

62. (Bus) Bus

63. PCIe (Peripheral Component Interconnect Express) PCIe


PCI

64. DMI (Direct Media Interface)

65. USB(Universal Serial Bus)


66. BIOS(Basic Input Output System)

67. (hard real-time system)

68. (soft real-time system)

69. (Process)

70. (address space)


71. (process table)

72. (command-line interpreter)

73. (interprocess communication)

74. (superuser)
root administrator supervisor
75. (directory) :

76. (path name)

77. (root directory) Windows C


D Linux /
78. (Working directory)

79. (file descriptor)

80. inode UNIX

81. (shared library) a.out

82. DLLs (Dynamic-Link Libraries)


.DLL .OCX ActiveX
.DRV
83. (clients)
84. (servers)
85. (client-server) / C/S

86. (Virtual Machines)


87. Java (Jaav virtual Machines) Java
JVM Java
Java

88. (object file)

89. C preprocessor C å C C++


, , ,

90. (device controller) CPU

91. ECC(Error-Correcting Code)


92. I/O port : /
93. I/O(memory mapped I/O MMIO) : I/O
I/O I/O
94. I/O(Port-mapped I/O ,PMIO) PMIO I/O
I/O CPU I/O
95. DMA (Direct Memory Access)
CPU DMA CPU /
DMA CPU
DMA DMAC

96. (cycle stealing)


DMA DMA
CPU CPU
CPU DMA I/O
CPU RAM
97. (burst mode)
98. (interrupt vector table)

99. (precise interrupt)

PC
PC
PC
PC

100. (imprecise interrupt)

101. (device independence)

DVD USB

102. UNC(Uniform Naming Convention) UNC


MS-DOS
Microsoft Windows

1 \\computer\path

UNIX Linux

1 //computer/path

103. (mounting) CD-ROM

104. (Error handling)


105. (synchronous) CPU
106. (asynchronous) CPU

107. (buffering)
CPU
108. Programmed input–output,PIO CPU ATA

109. (polling)

110. (busy waiting)

111. (reentrant)

112. (major device number) (minor device number)


/

113. (double buffering)

114. (circular buffer)


115. (Spooling)

116. (Daemon)

117. (logical block addressing, LBA)

118. RAID Redundant Array of Inexpensive Disks

119. MBR(Master Boot Record) MBR


120. FCFS (First-Come, First-Served) CPU

121. SSF (Shortest Seek First)

122. (stable storage)

123. (Clocks) timers

124. QR Code
QR

125. (Video card)


126. GDI (Graphics Device Interface)

127. (device context) Windows

Windows API

128. (bitmap)

129. (Resistive touchscreens)

130. (capacitive touchscreen)


131. (deadlock)
132. (preemptable resource)

133. (nonpreemptable resource)

134. (system checkpointed) OS

135. (two-phase locking, 2PL)

136. (Livelock)

137. (starvation)
138. (sandboxing)

139. VMM (Virtual Machine Monitor) hypervisor

140. (virtualization) CPU

141. (cloud)
142. (interpreter)

143. (paravirtualization)

144. (full virtualization)


I/O

145. (guest operating system) :

146. (host operating system)

147. (Application Programming Interface,API) API

148. (Virtual Machine Interface, VMI)


VM
149. (Input–output memory management unit, I/O MMU)
IOMMU DMA I/O
MMU
150. (device pass through)
151. (device isolation) :
152. (IAAS (Infrastructure As A Service)) IaaS
Internet
SaaS PaaS

153. (PAAS (Platform As A Service)) PaaS


aPaaS

154. (SAAS(Software As A Service)) :


155. (live migration)

156. (copy on write)


callers

private copy

157. (master-slave) /

158. (distributed system)


159. (LANs, Local Area Networks) LAN

160. (WAN,Wide Area Network)

161. (Ethernet)

162. (bridge) LAN LAN

163. (host)

164. (router)

165. (Connection-oriented service)

TCP
166. (Connectionless service)

UDP

167. (quality of service, QoS)

168. (acknowledgement packet) ACK

169. - (request-reply service) -


170. (protocol stack)

171. IP IPv4 IPv6


172. (hyperlink)

173. Web (Web page)


174. Web Web Internet
Web Web

175. (vulnerability)
176. (exploit)

177. (virus)
178. CIA(Confidentiality,Integrity,Availability)

179. (cracker)

180. (portscan)

181. (botnets)

182. (domain)
183. (solt)
184. (logic bomb)

185. (time bomb)

186. (login spoofing)

187. (backdoor)

188. (firewall)

You might also like