chapter 1-linux outline - 國立中興大學osnet.cs.nchu.edu.tw/powpoint/embedded94_1/chapter...

24
Linux Introduction

Upload: others

Post on 02-Aug-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Chapter 1-Linux outline - 國立中興大學osnet.cs.nchu.edu.tw/powpoint/Embedded94_1/Chapter 1...Linux Introduction Paul LabLinux Revolution2 The Birth of Linux Linux緣起-Linus'sunix

Linux Introduction

Page 2: Chapter 1-Linux outline - 國立中興大學osnet.cs.nchu.edu.tw/powpoint/Embedded94_1/Chapter 1...Linux Introduction Paul LabLinux Revolution2 The Birth of Linux Linux緣起-Linus'sunix

Paul Lab Linux Revolution 2

The Birth of Linux

Page 3: Chapter 1-Linux outline - 國立中興大學osnet.cs.nchu.edu.tw/powpoint/Embedded94_1/Chapter 1...Linux Introduction Paul LabLinux Revolution2 The Birth of Linux Linux緣起-Linus'sunix

Linux緣起-Linus's unixv 1991年十月,一個名為Linus Torvalds的年輕芬蘭大學生在

comp.os.minix這個新聞群組上發表了這樣的一篇文章:”Hello everybody out there using minix -I'm doing a (free) operation system (just a hobby, won't be big and professional like gnu) for 386(486) AT clones.”,這個Linus的興趣(hobby)就是Linux核心程式0.02版的原始碼。

v 自這個0.02版的Linux核心程式公諸於世後,Internet上許多高手相繼地投注在Linux的相關開發,目前Linux已經成為非常受人歡迎的一個多人多工、免費、穩定、效率高的作業系統,可以在包括 i386、Sparc、Alpha、Mips、Power PC等等眾多不同電腦系統平台上執行,蔚為風潮。

Page 4: Chapter 1-Linux outline - 國立中興大學osnet.cs.nchu.edu.tw/powpoint/Embedded94_1/Chapter 1...Linux Introduction Paul LabLinux Revolution2 The Birth of Linux Linux緣起-Linus'sunix

開放性原始碼(Open Source)及GPL(General Public License)v 開放性原始碼很多,如BSD UNIX、X Window等等,Linux的原始碼可以輕易地取得,及自由地散佈。但是讓Linux能風行的原因,應該是基於GNU通用公共許可證(GPL,General Public License)的保護

v 任何根據開放性原始碼軟體所做的任何修改,都有義務要再開放這些修改後的原始碼。如此一來,使得軟體的智慧結晶能夠分享與累積,而開發者的努力也會有所保障,軟體也能更自由地散佈。

v Linux即是遵循GPL的精神,而Linux上的軟體,如Apache server、Netscape等等也都遵循GPL的精神,而軟體愈多,使用者就愈多,開發的人愈多,開發的速度就愈快,Linux也更加地完備,成為total solution,而蔚為風潮。

Page 5: Chapter 1-Linux outline - 國立中興大學osnet.cs.nchu.edu.tw/powpoint/Embedded94_1/Chapter 1...Linux Introduction Paul LabLinux Revolution2 The Birth of Linux Linux緣起-Linus'sunix

Linux Versionsv Linux distinguishes stable kernels from

development kernelsv Linux version: X.Y.Z�X.Y: Version number

v If the second number is even: stable kernelv If the second number is odd: development kernel

�Z: release numbervFix bugs reported by Users

Page 6: Chapter 1-Linux outline - 國立中興大學osnet.cs.nchu.edu.tw/powpoint/Embedded94_1/Chapter 1...Linux Introduction Paul LabLinux Revolution2 The Birth of Linux Linux緣起-Linus'sunix

Featuresv Freev Open systemv Open sourcev GNU GPL (General Public License)v POSIX standardv High portabilityv High performancev Robustv Large development toolsetv Large number of device driversv Large number of application programs

Page 7: Chapter 1-Linux outline - 國立中興大學osnet.cs.nchu.edu.tw/powpoint/Embedded94_1/Chapter 1...Linux Introduction Paul LabLinux Revolution2 The Birth of Linux Linux緣起-Linus'sunix

System Featuresv Multi-taskingv Multi-userv Multi-processorv Virtual memoryv Monolithic kernelv Loadable kernel modulesv Networkingv Shared librariesv Support different file systemsv Support different executable file formatsv Support different networking protocolsv Support different processor architectures

Page 8: Chapter 1-Linux outline - 國立中興大學osnet.cs.nchu.edu.tw/powpoint/Embedded94_1/Chapter 1...Linux Introduction Paul LabLinux Revolution2 The Birth of Linux Linux緣起-Linus'sunix

Resourcesv Distributions�RedHat、Slackware、OpenLinux、SuSE、Debian、

TurboLinux、Mandrake、Corel、Embedixv Booksv Magazines�The Linux Journal, Linux Magazine

v Web sites�http://www.linux.org�http://www.linuxdevices.com/

Page 9: Chapter 1-Linux outline - 國立中興大學osnet.cs.nchu.edu.tw/powpoint/Embedded94_1/Chapter 1...Linux Introduction Paul LabLinux Revolution2 The Birth of Linux Linux緣起-Linus'sunix

User View of Linux OS

Hardware

Kernel

Shell

Applications

Page 10: Chapter 1-Linux outline - 國立中興大學osnet.cs.nchu.edu.tw/powpoint/Embedded94_1/Chapter 1...Linux Introduction Paul LabLinux Revolution2 The Birth of Linux Linux緣起-Linus'sunix

System Structure

System calls interface

File systemsext2fs xiafs proc

minix nfs msdos

iso9660

Task managementSchedulerSignalsLoadable modulesMemory management

Central kernel

Machine interface

ipv4ethernet

...

Network ManagerPeripheral managers

block character

sound card cdrom isdn

scsi pci network

Buffer Cache

Processes

Machine

Page 11: Chapter 1-Linux outline - 國立中興大學osnet.cs.nchu.edu.tw/powpoint/Embedded94_1/Chapter 1...Linux Introduction Paul LabLinux Revolution2 The Birth of Linux Linux緣起-Linus'sunix

Linux Kernel Architecture

Page 12: Chapter 1-Linux outline - 國立中興大學osnet.cs.nchu.edu.tw/powpoint/Embedded94_1/Chapter 1...Linux Introduction Paul LabLinux Revolution2 The Birth of Linux Linux緣起-Linus'sunix

Kernel Source Code Organization

v Source code web site:http://www.kernel.org

v Source code version:� X.Y.Z� 2.2.17� 2.4.18

Page 13: Chapter 1-Linux outline - 國立中興大學osnet.cs.nchu.edu.tw/powpoint/Embedded94_1/Chapter 1...Linux Introduction Paul LabLinux Revolution2 The Birth of Linux Linux緣起-Linus'sunix

Kernel Source Code Organization

Page 14: Chapter 1-Linux outline - 國立中興大學osnet.cs.nchu.edu.tw/powpoint/Embedded94_1/Chapter 1...Linux Introduction Paul LabLinux Revolution2 The Birth of Linux Linux緣起-Linus'sunix

Resources for Tracing Linux

v Source code browser�LXR (Source code navigator)

v Books�Understanding the Linux Kernel, D. P. Bovet and M.

Cesati, O'Reilly & Associates, 2000.�Linux Core Kernel – Commentary, In-Depth Code

Annotation, S. Maxwell, Coriolis Open Press, 1999.�The Linux Kernel, Version 0.8-3, D. A Rusling, 1998.�Linux Kernel Internals, 2nd edition, M. Beck et al.,

Addison-Wesley, 1998. �Linux Kernel, R. Card et al., John Wiley & Sons, 1998.

Page 15: Chapter 1-Linux outline - 國立中興大學osnet.cs.nchu.edu.tw/powpoint/Embedded94_1/Chapter 1...Linux Introduction Paul LabLinux Revolution2 The Birth of Linux Linux緣起-Linus'sunix

Reentrant KernelsvUnix kernels are reentrant�Several processes may be executing in

Kernel Mode at the same time�On uniprocessor systems, only one

process can progress, but many may be blocked in Kernel Mode waiting for some events

Page 16: Chapter 1-Linux outline - 國立中興大學osnet.cs.nchu.edu.tw/powpoint/Embedded94_1/Chapter 1...Linux Introduction Paul LabLinux Revolution2 The Birth of Linux Linux緣起-Linus'sunix

Reentrant Kernels (Cont.)v Reentrant Functions � functions that only modify local variables but do

not alter global data structuresv To provide reentrant kernel� Implement the kernel as a collection of reentrant

functions� Instead, Linux uses the nonreentrant functions

and locking mechanismvTo ensure only one process can execute a nonreentrant

function at a time

Page 17: Chapter 1-Linux outline - 國立中興大學osnet.cs.nchu.edu.tw/powpoint/Embedded94_1/Chapter 1...Linux Introduction Paul LabLinux Revolution2 The Birth of Linux Linux緣起-Linus'sunix

Kernel Control Path

vA kernel control path denotes the sequence of instructions executed by the kernel to handle�System call�Exception�Interrupt

Page 18: Chapter 1-Linux outline - 國立中興大學osnet.cs.nchu.edu.tw/powpoint/Embedded94_1/Chapter 1...Linux Introduction Paul LabLinux Revolution2 The Birth of Linux Linux緣起-Linus'sunix

Synchronization and Critical Regions

v Implement a reentrant kernel requires synchronization�Different kernel control paths may access

the same kernel data structure�Called Race condition�This section of code is called a critical

region

Page 19: Chapter 1-Linux outline - 國立中興大學osnet.cs.nchu.edu.tw/powpoint/Embedded94_1/Chapter 1...Linux Introduction Paul LabLinux Revolution2 The Birth of Linux Linux緣起-Linus'sunix

Synchronization and Critical Regions (Cont.)

vPossible solution�Atomic operationvRead and decrement a variable with a single,

noninterruptible operation�However, many kernel data structures, e.g.

linked list, cannot be accessed with a single operation

Page 20: Chapter 1-Linux outline - 國立中興大學osnet.cs.nchu.edu.tw/powpoint/Embedded94_1/Chapter 1...Linux Introduction Paul LabLinux Revolution2 The Birth of Linux Linux緣起-Linus'sunix

Synchronization and Critical Regions (Cont.)

vSolutions�Nonpreemptive Kernels

�Interrupt disabling

�Spin locks

Page 21: Chapter 1-Linux outline - 國立中興大學osnet.cs.nchu.edu.tw/powpoint/Embedded94_1/Chapter 1...Linux Introduction Paul LabLinux Revolution2 The Birth of Linux Linux緣起-Linus'sunix

Nonpreemptive KernelsvWhen a process executes in Kernel Mode, it

cannot be arbitrarily suspended and substituted with another process

v Ineffective in multiprocessor system�Two kernel control paths running on different

CPUs may concurrently access the same data structure

Page 22: Chapter 1-Linux outline - 國立中興大學osnet.cs.nchu.edu.tw/powpoint/Embedded94_1/Chapter 1...Linux Introduction Paul LabLinux Revolution2 The Birth of Linux Linux緣起-Linus'sunix

Interrupt disablingvApproach�Disable interrupts �Enter critical section�Reenable interrupts

v Ineffective if the critical region is largevCannot work in a multiprocessor

system

Page 23: Chapter 1-Linux outline - 國立中興大學osnet.cs.nchu.edu.tw/powpoint/Embedded94_1/Chapter 1...Linux Introduction Paul LabLinux Revolution2 The Birth of Linux Linux緣起-Linus'sunix

Semaphoresv Semaphore

� A counter � Has two atomic operations

v Upv Down

v Each semaphore is associated with a list of waiting process� Link processes that are blocked

v Effective in both uniprocessor and multiprocessor

Page 24: Chapter 1-Linux outline - 國立中興大學osnet.cs.nchu.edu.tw/powpoint/Embedded94_1/Chapter 1...Linux Introduction Paul LabLinux Revolution2 The Birth of Linux Linux緣起-Linus'sunix

Spin Locksv In Multiprocessor, semaphores may be inefficient

if the time required to update the data structures is short� Insert a process into a semaphore list is relative

expensivev Spin lock�Executing a tight instruction loop until the lock becomes

openv Used in a multiprocessor system