39
1 EE110300 電電電電電電電電 Lecture 3 電電電電電電 II ---- Operating Systems 電電電電電 電電 電電

1 EE110300 電機資訊工程實習 Lecture 3 個人電腦系統 II ---- Operating Systems 資訊工程系 黃泰一 教授

Embed Size (px)

Citation preview

Page 1: 1 EE110300 電機資訊工程實習 Lecture 3 個人電腦系統 II ---- Operating Systems 資訊工程系 黃泰一 教授

1

EE110300 電機資訊工程實習

Lecture 3 個人電腦系統 II ---- Operating Systems

資訊工程系 黃泰一 教授

Page 2: 1 EE110300 電機資訊工程實習 Lecture 3 個人電腦系統 II ---- Operating Systems 資訊工程系 黃泰一 教授

2

What is an operating system?Definition An operating system is the “permanent”

software that controls/abstracts hardware User applications can thus be simpler and

device-independent

physical machine interface

User Applications

Operating System

Architecture

virtual machine interface

Page 3: 1 EE110300 電機資訊工程實習 Lecture 3 個人電腦系統 II ---- Operating Systems 資訊工程系 黃泰一 教授

3

What is an operating system?Definition (con’t) Manages resources and processes to support

different user applications Provides Applications Programming

Interface (API) for user applications

User Application

Operating System

Architecture

User Application

Page 4: 1 EE110300 電機資訊工程實習 Lecture 3 個人電腦系統 II ---- Operating Systems 資訊工程系 黃泰一 教授

4

Modern operating systems

x86 platform– Linux– Windows

Mac platform – Mac OS Sun Solaris & Unix (Sun workstations) IBM AIX (mainframes) Embedded systems (special-purpose OS)

– Palm, PocketPC, etc– Xbox, etc

Page 5: 1 EE110300 電機資訊工程實習 Lecture 3 個人電腦系統 II ---- Operating Systems 資訊工程系 黃泰一 教授

5

Linus Torvalds

1991, Finland, Linux Project 1992, Linux Kernel 0.02

– Bash v1.08– GCC v1.40

1997, Moves to Transmeta 1998, Linux Kernel v2.2 2001, Linux Kernel v2.4 Pronunciation: “Linn-ucks”

Page 6: 1 EE110300 電機資訊工程實習 Lecture 3 個人電腦系統 II ---- Operating Systems 資訊工程系 黃泰一 教授

6

Windows 2000 & XP

1989: 10 developers left DEC VMS team and joined Microsoft Windows NT 1.0

1996: Windows NT 4.0 1999: Windows 2000 2001: Windows XP 2002: Microsoft .Net Server

Page 7: 1 EE110300 電機資訊工程實習 Lecture 3 個人電腦系統 II ---- Operating Systems 資訊工程系 黃泰一 教授

7

Linux vs. Windows NT

Linux is kernel only, free and open source Windows is full-loaded OS and pricy Linux requires minimum HW, Windows not Web server

– (Win2K + SWC ) beats (Linux + TUX) File server & printer server

– Windows supports a wider range of HW– Linux has more stable drivers

Page 8: 1 EE110300 電機資訊工程實習 Lecture 3 個人電腦系統 II ---- Operating Systems 資訊工程系 黃泰一 教授

8

Operating System Interfaces

Page 9: 1 EE110300 電機資訊工程實習 Lecture 3 個人電腦系統 II ---- Operating Systems 資訊工程系 黃泰一 教授

9

Software & hardware layer

User Program Executable Binary

Compiler Linker

System library

Architecture

user

compiler

OS interface

OS

Hardware

device driversOperating System

kernel

user mode

Page 10: 1 EE110300 電機資訊工程實習 Lecture 3 個人電腦系統 II ---- Operating Systems 資訊工程系 黃泰一 教授

10

Device Driver

Device driver 的唯一目的就是要將所有的硬體隱藏 .

他應該是整套軟體中唯一能和硬體溝通的窗口 .

他能直接讀取或寫入特定裝置控制及狀態暫存器 , 如果裝置發生中斷 ,那 ISR 也要整合到裝置驅動程式 .

Page 11: 1 EE110300 電機資訊工程實習 Lecture 3 個人電腦系統 II ---- Operating Systems 資訊工程系 黃泰一 教授

11

System service call (monitor)C Programs:

main() {

// call printf, provided

// by the C library, to

// print on the screen

printf(“Hello World!”);

}

Borland C library:Int printf(…) {// call SysOutputString,// provided by NT // system library, to// print on the screenSysOutputString(…);}

NT library:Void SysOutputString(…) {// call NtOutputString, that in turn will call // video card driver to output strings to // the screenNtOutputString(…);}

Page 12: 1 EE110300 電機資訊工程實習 Lecture 3 個人電腦系統 II ---- Operating Systems 資訊工程系 黃泰一 教授

12

System service call (disk)C Programs:main() {// call CreateFile // by the C library, to// create a file on diskCreateFile(“a.txt”)}

Borland C library:Int CreateFile(…) {// call NtCreateFile,// provided by NT to// create a fileNtCreateFile(…);}

NT library:Void NtCreateFile(…) { // call NtInternalCreateFile, that in turn will // call the file system driver and the disk // driver to create a file on a disk NtInternalCreateFile(…);}

Page 13: 1 EE110300 電機資訊工程實習 Lecture 3 個人電腦系統 II ---- Operating Systems 資訊工程系 黃泰一 教授

13

System service calls (network)

C Programs:main() {so = createsocket();send(so, “text”);close(so);}

Borland C library:int createsocket(…) { … NtCreateSocket(…);}

int send(…) { … NtSocketSend(…);}

NT library:

Void NtCreateSocket(…) { … NtAfdCreateSocket(…);}

Page 14: 1 EE110300 電機資訊工程實習 Lecture 3 個人電腦系統 II ---- Operating Systems 資訊工程系 黃泰一 教授

14

Page 15: 1 EE110300 電機資訊工程實習 Lecture 3 個人電腦系統 II ---- Operating Systems 資訊工程系 黃泰一 教授

15

Virtual computer concept

C++ compiler

FORTRAN compiler

C compiler

Java compiler …

Assembler

OperatingSystem

Commandinterpreter

LISP interpreter

Operating system

Macroinstruction interpreter

Bare machine

Virtual CComputer

Virtual C++Computer

Page 16: 1 EE110300 電機資訊工程實習 Lecture 3 個人電腦系統 II ---- Operating Systems 資訊工程系 黃泰一 教授

16

Importance of operating system

System API are the only interface between user applications and hardware– API are designed for general-purpose, not

performance driven (e.g. network applications)

OS code cannot allow any bug– Any break (e.g. invalid access) causes reboot

The owner of OS technology controls the software industry

Page 17: 1 EE110300 電機資訊工程實習 Lecture 3 個人電腦系統 II ---- Operating Systems 資訊工程系 黃泰一 教授

17

What is Embedded System?

是電腦軟體與硬體的綜合體 , 亦可涵蓋機械或其他附屬裝置 ; 整個綜合體設計的目的 , 在於滿足某種特殊功能 .

例如 : PDA, 遊樂器 , 衛星導航系統 , 流程管理器 等 .

Page 18: 1 EE110300 電機資訊工程實習 Lecture 3 個人電腦系統 II ---- Operating Systems 資訊工程系 黃泰一 教授

18

Embedded system architecture

3-layered device– Palm, PocketPC

User Applications

Embedded OS

Hardware

2-layered device– XBox

Hardware

Application

Page 19: 1 EE110300 電機資訊工程實習 Lecture 3 個人電腦系統 II ---- Operating Systems 資訊工程系 黃泰一 教授

19

General-purpose & embedded OS

General-purpose Embedded OS

Examples Linux, Windows WinCE, Palm OS

Hardware General-purpose Special device

OS code size Large Small

Stability req. Strong Weak

Develop. cost Huge Medium

Page 20: 1 EE110300 電機資訊工程實習 Lecture 3 個人電腦系統 II ---- Operating Systems 資訊工程系 黃泰一 教授

20

Operating system concepts

Page 21: 1 EE110300 電機資訊工程實習 Lecture 3 個人電腦系統 II ---- Operating Systems 資訊工程系 黃泰一 教授

21

Process & Thread

How do different applications run on the same machine at the same time without interfering each other?– Protection between processes– Protection between a process and the OS

Process: an execution of a program, consisting of a virtual address space, one or more threads, and some OS states.

Page 22: 1 EE110300 電機資訊工程實習 Lecture 3 個人電腦系統 II ---- Operating Systems 資訊工程系 黃泰一 教授

22

Virtual memory (address space)

0

232 - 1

virtual address space (4GB)

page 0

page 1

page 2

page 220

vap0

vap1

x

page table

physical memory (16MB)

pp 0

pp 1

pp 2

pp N

paging filepp 212

x

Page 23: 1 EE110300 電機資訊工程實習 Lecture 3 個人電腦系統 II ---- Operating Systems 資訊工程系 黃泰一 教授

23

Virtual memory (address space)

0

232 - 1

virtual address space (4GB)

page 0

page 1

page 2

page 220

vap0

vap1

x

page table

physical memory (16MB)

pp 0

pp 1

pp 2

pp N

paging filepp 212

Page 24: 1 EE110300 電機資訊工程實習 Lecture 3 個人電腦系統 II ---- Operating Systems 資訊工程系 黃泰一 教授

24

Memory manager

physical memory

pp 0

pp 1

pp 2

pp N

paging filepp 212

process VA

process VA

PT

PT

Page 25: 1 EE110300 電機資訊工程實習 Lecture 3 個人電腦系統 II ---- Operating Systems 資訊工程系 黃泰一 教授

25

Memory manager

physical memory

pp 0

pp 1

pp 2

pp N

paging filepp 212

process VA

process VA

PT

PT

Page 26: 1 EE110300 電機資訊工程實習 Lecture 3 個人電腦系統 II ---- Operating Systems 資訊工程系 黃泰一 教授

26

Memory manager (w/ constraint)

physical memory

pp 0

pp 1

pp 2

pp N

paging filepp 212

process VA

process VA

PT

PT

x

memory manager

Page 27: 1 EE110300 電機資訊工程實習 Lecture 3 個人電腦系統 II ---- Operating Systems 資訊工程系 黃泰一 教授

27

Protectiondual mode operation Can application modify its own page table?

If it could, could get access to all physical memory.

Dual Mode– Kernel/protected model: no restriction, can

touch any physical memory page– User mode: where you program runs, can only

touch part of the virtual address space Applications can enter the kernel mode

through systems calls (traps)

Page 28: 1 EE110300 電機資訊工程實習 Lecture 3 個人電腦系統 II ---- Operating Systems 資訊工程系 黃泰一 教授

28

Mode change: system call trap

1. System call traps to the kernel (kernel mode)2. Kernel determines service routine required3. Kernel services the call.4. Control is returned to user program (user mode)

Page 29: 1 EE110300 電機資訊工程實習 Lecture 3 個人電腦系統 II ---- Operating Systems 資訊工程系 黃泰一 教授

29

Thread

A process starts with one thread (main thread), and can initialize more threads by CreateThread() calls

A thread represents an execution stream of instructions and its CPU register context

A thread is the unit used in the scheduler Kill a process kill its all threads

Page 30: 1 EE110300 電機資訊工程實習 Lecture 3 個人電腦系統 II ---- Operating Systems 資訊工程系 黃泰一 教授

30

Scheduler A component in OS that decides which

thread in the thread pool gets the CPU Priority-based scheduler Context switch

new thread

schedulerready

runningwaiting terminatingthreads

signalevents

Page 31: 1 EE110300 電機資訊工程實習 Lecture 3 個人電腦系統 II ---- Operating Systems 資訊工程系 黃泰一 教授

31

Synchronization

All threads in the same process share all global data

Synchronization among these threads is necessary to maintain data integrity

Resource lock is commonly used to guarantee thread mutual exclusive– abuse of such locks decreases scalability– ignorance of such locks decreases stability

Deadlock issues

Page 32: 1 EE110300 電機資訊工程實習 Lecture 3 個人電腦系統 II ---- Operating Systems 資訊工程系 黃泰一 教授

32

File Systems

A hard disk is just a raw media storage A hard disk device driver allows OS to

communicate with the hardware But, it is the responsibility of the OS to organize

disk sectors/tracks for storing files– such component is called the file system

E.g. A hard disk that stores NTFS information cannot be read with the FAT32 driver– example: paper with Moses code

Page 33: 1 EE110300 電機資訊工程實習 Lecture 3 個人電腦系統 II ---- Operating Systems 資訊工程系 黃泰一 教授

33

Operating Systems and System Software

Example: web server software

Page 34: 1 EE110300 電機資訊工程實習 Lecture 3 個人電腦系統 II ---- Operating Systems 資訊工程系 黃泰一 教授

34

User-mode web server architectureWeb Server

CM

web cache

network card

TCPIP

User Mode

Kernel ModeI/O module

SocketSystem Cache

FileSys

Page 35: 1 EE110300 電機資訊工程實習 Lecture 3 個人電腦系統 II ---- Operating Systems 資訊工程系 黃泰一 教授

35

User-mode web server commons

User-mode application architecture– e.g. Microsoft Internet Information Server (IIS),

Netscape Enterprise Server, Apache HTTP Server, etc.

Dependent on generally system API Stand-alone web content cache limited by

virtual address space Time-to-live cache replacement algorithm Memory-less dynamic code execution

Page 36: 1 EE110300 電機資訊工程實習 Lecture 3 個人電腦系統 II ---- Operating Systems 資訊工程系 黃泰一 教授

36

SWC web server architecture

User Mode

Kernel Mode

TCPIP -NTFS

CM

web cache

network card +

System Cache SWCmiss

I/O Module

TWC.LIBUser Code

VA<->PA

hit

Page 37: 1 EE110300 電機資訊工程實習 Lecture 3 個人電腦系統 II ---- Operating Systems 資訊工程系 黃泰一 教授

37

SPECWEB’99 Performance

15122694

4800*5600*

1638

4409

6371

12309

14400

5600

9016

2198222719

0

4,000

8,000

12,000

16,000

20,000

24,000

Requests/Sec

UP 4P 8P

Linux + ZeusW2K + IIS 5.0IBM-AIX + ZeusLinux + TUX W2K + SWC

*estimated scaling data

Page 38: 1 EE110300 電機資訊工程實習 Lecture 3 個人電腦系統 II ---- Operating Systems 資訊工程系 黃泰一 教授

38

Kernel vs. user-based web server

Increase peak capacity by five times Web cache size be limited by physical

memory size Web cache be shared by both static &

dynamic web requests Remove I/O overhead and Socket creation Fast TCPIP data transmission

Page 39: 1 EE110300 電機資訊工程實習 Lecture 3 個人電腦系統 II ---- Operating Systems 資訊工程系 黃泰一 教授

39

Summary

# persons

many

few

skills

easy

difficult

control

small

large

reward

low

high

Apps

EOS

A.D. 1492 Columbus discovers America--- The new and free land is on your grip!!